Course Outline

list Items Test Book

Book
  • Items Test Book

ckcode ⌲ chapter-d3-models-with-interactions

require(coursekata) # color the dots by condition gf_jitter(later_anxiety ~ base_anxiety, data = er) # color the dots by condition gf_jitter(later_anxiety ~ base_anxiety, data = er, color=~condition) ex() %>% check_function("gf_jitter") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() check_arg(., "color") %>% check_equal() }
CK Code: D3_Code_ER_01
require(coursekata) # Find the best-fitting additive model of this word equation # later anxiety = condition + base anxiety + other stuff additive_model <- lm() # print out the ANOVA table additive_model <- lm(later_anxiety ~ condition + base_anxiety, data = er) supernova(additive_model) ex() %>% { check_object(., "additive_model") %>% check_equal() check_output_expr(., "supernova(additive_model)") }
CK Code: D3_Code_ER_02
require(coursekata) # find the best-fitting parameter estimates for this model # later anxiety = condition + base anxiety + other stuff # find the best-fitting parameter estimates for this model # later anxiety = condition + base anxiety + other stuff lm(later_anxiety ~ condition + base_anxiety, data = er) ex() %>% check_function("lm") %>% check_result() %>% check_equal()
CK Code: D3_Code_ER_03
require(coursekata) # add code to fit the interaction model interaction_model <- # add code to print out the model estimates # add code to fit the interaction model interaction_model <- lm(later_anxiety ~ condition + base_anxiety + condition*base_anxiety, data = er) # add code to print out the model estimates interaction_model ex() %>% { check_object(., "interaction_model") %>% check_equal() check_output_expr(., "interaction_model") }
CK Code: D4_Code_Interaction_01
require(coursekata) # code to fit and save the interaction model interaction_model <- lm(later_anxiety ~ condition + base_anxiety + condition*base_anxiety, data = er) # add the model's predictions to the plot gf_jitter(later_anxiety ~ base_anxiety, color = ~condition, data = er) # code to fit and save the interaction model interaction_model <- lm(later_anxiety ~ condition + base_anxiety + condition*base_anxiety, data = er) # add the model's predictions to the plot gf_jitter(later_anxiety ~ base_anxiety, color = ~condition, data = er) %>% gf_model(interaction_model) ex() %>% check_function("gf_model") %>% { check_arg(., "object") %>% check_equal() check_arg(., "model") %>% check_equal() }
CK Code: D4_Code_Interaction_02
require(coursekata) set.seed(4) small_set_ids <- rbind( sample(filter(er, condition == "Dog" & base_anxiety == 3), 1), sample(filter(er, condition == "Dog" & base_anxiety == 4), 1), sample(filter(er, condition == "Dog" & base_anxiety == 8), 1), sample(filter(er, condition == "Control" & base_anxiety == 2), 1), sample(filter(er, condition == "Control" & base_anxiety == 5), 1), sample(filter(er, condition == "Control" & base_anxiety == 9), 1) )$id er <- er %>% mutate(small_set = id %in% small_set_ids) %>% arrange(desc(small_set)) # this code fits and saves the interaction model interaction_model <- lm(later_anxiety ~ condition + base_anxiety + condition*base_anxiety, data = er) # write code to save the model predictions as a new variable in er er$interaction_predict <- # this code will print out the first 6 rows of the data frame head(select(er, condition, base_anxiety, later_anxiety, interaction_predict)) # this code fits and saves the interaction model interaction_model <- lm(later_anxiety ~ condition + base_anxiety + condition*base_anxiety, data = er) # write code to save the model predictions as a new variable in er er$interaction_predict <- predict(interaction_model) # this code will print out the first 6 rows of the data frame head(select(er, condition, base_anxiety, later_anxiety, interaction_predict)) ex() %>% check_object("er") %>% check_column("interaction_predict") %>% check_equal()
CK Code: D4_Code_Interaction_03
require(coursekata) # this codes centers base anxiety at its mean er$base_0 <- er$base_anxiety - mean(er$base_anxiety) # write code to generate the favstats for base_anxiety and base_0 # this codes centers base anxiety at its mean er$base_0 <- er$base_anxiety - mean(er$base_anxiety) # write code to generate the favstats for base_anxiety and base_0 favstats(~base_anxiety, data=er) favstats(~base_0, data=er) ex() %>% { check_function(., "favstats", index = 1) %>% check_result() %>% check_equal() check_function(., "favstats", index = 2) %>% check_result() %>% check_equal() }
CK Code: D3_Code_Centering_01
require(coursekata) # fits old interaction model and prints estimates lm(later_anxiety ~ condition * base_anxiety, data = er) # creates a new variable for base anxiety centered at 0 er$base_0 <- er$base_anxiety - mean(er$base_anxiety) # write code to fit and print estimates # for an interaction model substituting base_0 for base_anxiety # fits old interaction model and prints estimates lm(later_anxiety ~ condition * base_anxiety, data = er) # creates a new variable for base anxiety centered at 0 er$base_0 <- er$base_anxiety - mean(er$base_anxiety) # write code to fit and print estimates # for an interaction model substituting base_0 for base_anxiety lm(later_anxiety ~ condition * base_0, data = er) ex() %>% check_function("lm", index = 2) %>% check_result() %>% check_equal()
CK Code: D3_Code_Centering_02
require(coursekata) er$base_0 <- er$base_anxiety - mean(er$base_anxiety) # this saves the best-fitting interaction model interaction_model <- lm(later_anxiety ~ condition * base_0, data = er) # generate the ANOVA table # this saves the best-fitting interaction model interaction_model <- lm(later_anxiety ~ condition * base_0, data = er) # generate the ANOVA table supernova(interaction_model) ex() %>% check_function("supernova") %>% check_result() %>% check_equal()
CK Code: D3_Code_Comparing_01

Responses