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

Error in ames_pairwise.R #109

Open
obgeneralao opened this issue Aug 22, 2022 · 0 comments
Open

Error in ames_pairwise.R #109

obgeneralao opened this issue Aug 22, 2022 · 0 comments

Comments

@obgeneralao
Copy link

obgeneralao commented Aug 22, 2022

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant