Course Outline

• segmentLearnosity
• segmentCKCode

list Items Test Book

Book
• Items Test Book

ckcode ⌲ chapter-d1-intro-multivariate-models

require(coursekata) # This code saves the two models Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Smallville) HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Smallville) # Generate the ANOVA tables for these two models # This code saves the two models Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Smallville) HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Smallville) # Generate the ANOVA tables for these two models supernova(Neighborhood_model) supernova(HomeSizeK_model) ex() %>% { check_function(., "supernova", index = 1) %>% check_result() %>% check_equal() check_function(., "supernova", index = 1) %>% check_result() %>% check_equal() }
CK Code: D1_Code_Intro_01
require(coursekata) # Make a horizontal grid of scatterplots using Neighborhood gf_point(PriceK~ HomeSizeK, data = Smallville) # Make a horizontal grid of scatterplots using Neighborhood gf_point(PriceK~ HomeSizeK, data = Smallville) %>% gf_facet_grid(. ~ Neighborhood) ex() %>% check_function("gf_facet_grid") %>% { check_arg(., "object") %>% check_equal() check_arg(., 2) %>% check_equal() }
CK Code: D1_Code_Visualizing_01
require(coursekata) # Add in the color argument gf_point(PriceK ~ HomeSizeK, data = Smallville) # Add in the color argument gf_point(PriceK ~ HomeSizeK, data = Smallville, color = ~ Neighborhood) ex() %>% check_function("gf_point") %>% check_arg("color") %>% check_equal()
CK Code: D1_Code_Visualizing_02
require(coursekata) # use lm() to find the best-fitting coefficients for our multivariate model # use lm() to find the best-fitting coefficients for our multivariate model lm(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) ex() %>% check_function("lm") %>% check_result() %>% check_equal()
CK Code: D1_Code_Specifying_01
require(coursekata) # save the multivariate model here multi_model <- # this puts the model predictions on the scatterplot gf_point(PriceK ~ HomeSizeK, color = ~Neighborhood, data = Smallville) %>% gf_point(predict(multi_model) ~ HomeSizeK, color = "black", shape = 2) # save the multivariate model here multi_model <- lm(PriceK~ Neighborhood + HomeSizeK, data = Smallville) # this puts the model predictions on the scatterplot gf_point(PriceK ~ HomeSizeK, color = ~Neighborhood, data = Smallville) %>% gf_point(predict(multi_model) ~ HomeSizeK, color = "black", shape = 2) ex() %>% check_object("multi_model") %>% check_equal()
CK Code: D1_Code_Predictions_01
require(coursekata) # saves multivariate model multi_model <- lm(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # generate the ANOVA table # saves multivariate model multi_model <- lm(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # generate the ANOVA table supernova(multi_model) ex() %>% check_function("supernova") %>% check_result() %>% check_equal()
CK Code: D1_Code_Residuals_01
require(coursekata) # use R to add the two numbers that should add up to SS Total # use R to add the two numbers that should add up to SS Total 124403.028 + 104774.465 # accept anything between 220000 and 240000 just in case students round or something eq_fun <- function(x, y) x > 220000 && x < 240000 ex() %>% check_or(., check_operator(., "+") %>% check_result() %>% check_equal(eq_fun = eq_fun), override_solution(., "sum(124403.028, 104774.465)") %>% check_function("sum") %>% check_result() %>% check_equal(eq_fun = eq_fun) )
CK Code: D1_Code_Residuals_02
require(coursekata) # modify this to generate an F from the empty model of the DGP f(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # modify this to generate an F from the empty model of the DGP f(shuffle(PriceK) ~ Neighborhood + HomeSizeK, data = Smallville) ex() %>% check_function("f") %>% check_arg("object") %>% check_equal()
CK Code: D1_Code_Logic_01
require(coursekata) # add do() to generate a sampling distribution of 1000 Fs from the empty model of the DGP sdof <- f(shuffle(PriceK) ~ Neighborhood + HomeSizeK, data = Smallville) # this will depict the sdof in a histogram gf_histogram(~ f, data = sdof) # add do() to generate a sampling distribution of 1000 Fs from the empty model of the DGP sdof <- do(1000) * f(shuffle(PriceK)~ Neighborhood + HomeSizeK, data = Smallville) # this will depict the sdof in a histogram gf_histogram(~ f, data = sdof) ex() %>% { check_function(., "do") %>% check_arg("object") %>% check_equal() check_operator(., "*") }
CK Code: D1_Code_Logic_02
require(coursekata) # this calculates sample_f sample_f <- f(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # this generates a sampling distribution of fs sdof <- do(1000) * f(shuffle(PriceK) ~ Neighborhood + HomeSizeK, data = Smallville) # use tally to calculate p-value from the sdof # remember to set the format as proportion # this calculates sample_f sample_f <- f(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # this generates a sampling distribution of fs sdof <- do(1000) * f(shuffle(PriceK) ~ Neighborhood + HomeSizeK, data = Smallville) # use tally to calculate p-value from the sdof # remember to set the format as proportion tally(~ f > sample_f, data = sdof, format = "proportion") ex() %>% check_function("tally") %>% check_result() %>% check_equal()
CK Code: D1_Code_DistF_01
require(coursekata) # this saves the multivariate model multi_model <- lm(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # write one line of code that will calculate # confidence intervals for all parameters # this saves the multivariate model multi_model <- lm(PriceK ~ Neighborhood + HomeSizeK, data = Smallville) # write one line of code that will calculate # confidence intervals for all parameters confint(multi_model) ex() %>% check_function("confint") %>% check_result() %>% check_equal()
CK Code: D1_Code_DistF_02