FES icon indicating copy to clipboard operation
FES copied to clipboard

Error in ames_pairwise.R

Open obgeneralao opened this issue 2 years ago • 0 comments

In the section 7_04_The_Brute-Force_Approach_to_Identifying_Predictive_Interactions, the code ames_pairwise.R the particular chunk of codes as shown below are throwing some errors,

for (i in 1:nrow(interactions)) {
  tmp_vars <- c("Class", interactions$var1[i], interactions$var2[i])
  
  int <-
    as.formula(paste0(
      "~ starts_with('",
      interactions$var1[i],
      "'):starts_with('",
      interactions$var2[i],
      "')"
    ))
  
  int_rec <- 
    ames_rec %>% 
    step_interact(int) %>% 
    step_zv(all_predictors())
  
  set.seed(2691)
  main_int <- train(int_rec, 
                    data = ames_train, 
                    method = "lm", 
                    metric = "RMSE",
                    trControl = int_ctrl)  
  
  tmp_diff <- compare_models_1way(main_int, main_eff, alternative = "less")
  interactions$RMSE[i] <- getTrainPerf(main_eff)[1, "TrainRMSE"]
  interactions$Reduction[i] <- -tmp_diff$estimate
  interactions$Pvalue[i] <- tmp_diff$p.value
  
  a1 <- 
    anova(main_eff$finalModel, main_int$finalModel) %>% 
    tidy() %>% 
    slice(2) %>% 
    pull(p.value)
  
  interactions$anova_p[i] <- a1
}
Error in data.frame(..., check.names = FALSE): arguments imply differing number of rows: 19, 2
Traceback:

1. anova(main_eff$finalModel, main_int$finalModel) %>% tidy() %>% 
 .     slice(2) %>% pull(p.value)
2. pull(., p.value)
3. slice(., 2)
4. tidy(.)
5. tidy.anova(.)
6. cbind(term = mods, ret)
7. cbind(deparse.level, ...)
8. data.frame(..., check.names = FALSE)
9. stop(gettextf("arguments imply differing number of rows: %s", 
 .     paste(unique(nrows), collapse = ", ")), domain = NA)

obgeneralao avatar Aug 22 '22 15:08 obgeneralao