Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indicators = FALSE behavior #37

Closed
DavisVaughan opened this issue Feb 16, 2019 · 5 comments
Closed

indicators = FALSE behavior #37

DavisVaughan opened this issue Feb 16, 2019 · 5 comments

Comments

@DavisVaughan
Copy link
Member

DavisVaughan commented Feb 16, 2019

These should all throw warnings of some kind.

Maybe when checking the formula RHS with indicators = FALSE, we should look for only + and names, and warn about anything else! (rather than special casing everything)

library(hardhat)
library(gapminder)
gapminder <- gapminder[1:5,]
mold(year ~ year*continent, gapminder, indicators = FALSE)
#> $predictors
#> # A tibble: 5 x 2
#>    year continent
#>   <int> <fct>    
#> 1  1952 Asia     
#> 2  1957 Asia     
#> 3  1962 Asia     
#> 4  1967 Asia     
#> 5  1972 Asia     
#> 
#> $outcomes
#> # A tibble: 5 x 1
#>    year
#>   <int>
#> 1  1952
#> 2  1957
#> 3  1962
#> 4  1967
#> 5  1972
#> 
#> $preprocessor
#> Formula Preprocessor: 
#>  
#> # Predictors: 2 
#>   # Outcomes: 1 
#>    Intercept: FALSE 
#>   Indicators: FALSE 
#> 
#> $offset
#> NULL
mold(year ~ year*continent - year, gapminder, indicators = FALSE)
#> $predictors
#> # A tibble: 5 x 2
#>    year continent
#>   <int> <fct>    
#> 1  1952 Asia     
#> 2  1957 Asia     
#> 3  1962 Asia     
#> 4  1967 Asia     
#> 5  1972 Asia     
#> 
#> $outcomes
#> # A tibble: 5 x 1
#>    year
#>   <int>
#> 1  1952
#> 2  1957
#> 3  1962
#> 4  1967
#> 5  1972
#> 
#> $preprocessor
#> Formula Preprocessor: 
#>  
#> # Predictors: 2 
#>   # Outcomes: 1 
#>    Intercept: FALSE 
#>   Indicators: FALSE 
#> 
#> $offset
#> NULL
mold(year ~ (year+continent+pop)^2, gapminder, indicators = FALSE)
#> $predictors
#> # A tibble: 5 x 3
#>    year continent      pop
#>   <int> <fct>        <int>
#> 1  1952 Asia       8425333
#> 2  1957 Asia       9240934
#> 3  1962 Asia      10267083
#> 4  1967 Asia      11537966
#> 5  1972 Asia      13079460
#> 
#> $outcomes
#> # A tibble: 5 x 1
#>    year
#>   <int>
#> 1  1952
#> 2  1957
#> 3  1962
#> 4  1967
#> 5  1972
#> 
#> $preprocessor
#> Formula Preprocessor: 
#>  
#> # Predictors: 3 
#>   # Outcomes: 1 
#>    Intercept: FALSE 
#>   Indicators: FALSE 
#> 
#> $offset
#> NULL

Created on 2019-02-16 by the reprex package (v0.2.1.9000)

@DavisVaughan
Copy link
Member Author

Maybe not because we still want to do things like log(var)

@DavisVaughan
Copy link
Member Author

Hard because you might want to allow I(x * y) to be computed algebraically and not represent interactions

@DavisVaughan
Copy link
Member Author

DavisVaughan commented Feb 20, 2019

Adding some notes on what led me to the right answer:

when indicators = FALSE:

  • check that factor columns are only by themselves (factorcol + x) not factorcol:x or paste0(factorcol)
    • uses terms() directly on the formula, along with original factor classes to determine this
    • throws error if factor columns are used not by themselves
  • remove the factor columns from the data
  • remove the factor columns from the formula? (append - factorcol)
  • run model.matrix(formula_no_factors, data_no_factors)
  • matrix -> tibble
  • add the factor columns back onto the data
    • Original positions are not kept, but this seems ok

@DavisVaughan
Copy link
Member Author

Closed by #42

@github-actions
Copy link

github-actions bot commented Jul 1, 2021

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant