jpfitzinger / tidyfit

An extension to the R tidyverse for automated ML. The package allows fitting and cross validation of linear regression and classification algorithms on grouped data.
https://tidyfit.residualmetrics.com
13 stars 1 forks source link

Column naming issue. Stems from 'gaselect' package. #1

Closed Rossouwvj closed 1 year ago

Rossouwvj commented 1 year ago

I discovered a small issue that appears to be coming from the 'gaselect' package.

For a quick replication I ran the following estimation code:

models_df <-  Factor_Industry_Returns %>% 
  group_by(Industry) %>%
  filter(Industry=="Enrgy") %>% 
  mutate(Weight = 0.96^seq(n(), 1)) %>%        
  regress(
    Return ~ .,
    m("genetic"),
    .cv = "initial_time_split",                
    .mask = "Date",                           
    .weights = "Weight"                        
  )

The above code runs without any errors. The problem is when using the predict function: predict(models_df, Factor_Industry_Returns)

Which gives the error:

"Error in `map()`:
ℹ In index: 1.
Caused by error:
! object 'Mkt-RF' not found"

My first instinct was that the reduced-form model was potentially eliminating the 'Mkt-RF' variable. However, evaluating coef(models_df, Factor_Industry_Returns) proved this not to be the case.

The issue is actually with the column name 'Mkt-RF'. I suspect the package does not like the hyphen? To show that might be the case the code below - where I re-named the column - works without giving the same error.

test_data <- Factor_Industry_Returns %>% 
  rename(Check = `Mkt-RF`)

models_df <-  test_data %>% 
  group_by(Industry) %>%
  filter(Industry=="Enrgy") %>% 
  mutate(Weight = 0.96^seq(n(), 1)) %>%        
  regress(
    Return ~ .,
    m("genetic"),
    .cv = "initial_time_split",                
    .mask = "Date",                           
    .weights = "Weight"                        
  )

predict(models_df, test_data)
jpfitzinger commented 1 year ago

Thanks for pointing this out! The issue was indeed caused by syntactically invalid names for that method. I've pushed a fix and will include in the upcoming release on CRAN.