Course Outline
-
segmentLearnosity
-
segmentCKCode
-
ckcode-chapter-x3-modeling-relationships
list Items Test Book
Book
ckcode ⌲ chapter-x3-modeling-relationships
require(coursekata)
# find best-fitting model
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# add code to visualize the new model on the jitter plot
gf_jitter(PriceK ~ Neighborhood, data = Ames, width = .1)
# find best-fitting model
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# add code to visualize the new model on the jitter plot
gf_jitter(PriceK ~ Neighborhood, data = Ames, width = .1) %>%
gf_model(Neighborhood_model)
ex() %>% {
check_function(., "gf_model") %>%
check_arg("object") %>%
check_equal()
check_or(.,
check_function(., "gf_model") %>%
check_arg("model") %>%
check_equal(),
override_solution(., "gf_jitter(PriceK ~ Neighborhood, data = Ames) %>% gf_model(PriceK ~ Neighborhood)") %>%
check_function(., "gf_model") %>%
check_arg("model") %>%
check_equal()
)
}
CK Code: X3_Code_RtoFit_01
require(coursekata)
# we have saved the Neighborhood model for you
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# write code to generate predictions using this model
# no need to save the predictions
# we have saved the Neighborhood model for you
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# write code to generate predictions using this model
# no need to save the predictions
predict(Neighborhood_model)
ex() %>% check_function("predict") %>%
check_result() %>% check_equal()
CK Code: X3_Code_RtoFit_02
require(coursekata)
# we have saved the Neighborhood model for you
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# print out the best-fitting parameter estimates
# we have saved the Neighborhood model for you
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# print out the best-fitting parameter estimates
Neighborhood_model
ex() %>% check_output_expr("Neighborhood_model")
CK Code: X3_Code_RtoFit_03
require(coursekata)
# This codes saves the best-fitting models
empty_model <- lm(PriceK ~ NULL, data=Ames)
Neighborhood_model <- lm(PriceK ~ Neighborhood, data=Ames)
# This code squares and sums the residuals from the empty model
sum(resid(empty_model)^2)
# Write code to square and sum the residuals from the Neighborhood model
# This codes saves the best-fitting models
empty_model <- lm(PriceK ~ NULL, data=Ames)
Neighborhood_model <- lm(PriceK ~ Neighborhood, data=Ames)
# This code squares and sums the residuals from the empty model
sum(resid(empty_model)^2)
# Write code to square and sum the residuals from the Neighborhood model
sum(resid(Neighborhood_model)^2)
ex() %>% {
check_function(., "sum", 1) %>%
check_result() %>% check_equal()
check_function(., "sum", 2) %>%
check_result() %>% check_equal()
}
CK Code: X3_Code_ErrorR_01
library(coursekata)
# edit the Neighborhood_model code to create HomeSizeK_model
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# save the predictions of the HomeSizeK_model as a new variable in Ames
Ames$HomeSizeK_predict <-
# this code prints out the first 6 observations
head(select(Ames, PriceK, HomeSizeK, HomeSizeK_predict))
# edit the Neighborhood_model code to create HomeSizeK_model
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
# save the predictions of the HomeSizeK_model as a new variable in Ames
Ames$HomeSizeK_predict <- predict(HomeSizeK_model)
# this code prints out the first 6 observations
head(select(Ames, PriceK, HomeSizeK, HomeSizeK_predict))
ex() %>% {
check_object(., "HomeSizeK_model") %>%
check_equal()
check_object(., "Ames") %>%
check_column("HomeSizeK_predict") %>%
check_equal()
}
CK Code: X3_Code_Quantitative_01
library(coursekata)
# saves the home size model
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
# print it out
# saves the home size model
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
# print it out
HomeSizeK_model
ex() %>% check_output_expr("HomeSizeK_model")
CK Code: X3_Code_Interpreting_01
require(coursekata)
# this calculates SST
empty_model <- lm(PriceK ~ NULL, data=Ames)
print("SST")
sum(resid(empty_model)^2)
# this calculates SSE
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
print("SSE")
sum(resid(HomeSizeK_model)^2)
# no test
ex() %>% check_error()
CK Code: X3_Code_ErrorH_01
library(coursekata)
empty_model <- lm(PriceK ~ NULL, data = Ames)
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# modify this line of code
supernova(empty_model)
empty_model <- lm(PriceK ~ NULL, data = Ames)
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# modify this line of code
supernova(Neighborhood_model)
ex() %>% check_function("supernova") %>%
check_result() %>% check_equal()
CK Code: X3_Code_ANOVA_01
require(coursekata)
empty_model <- lm(PriceK ~ NULL, data=Ames)
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
# This generates predictions from empty model
Ames$empty_predict <- predict(empty_model)
# This generates predictions from Neighborhood model
Ames$Neighborhood_predict <- predict(Neighborhood_model)
# Here are the differences
# Square and sum these differences to calculate SSM
(Ames$empty_predict - Ames$Neighborhood_predict)
# This generates predictions from empty model
Ames$empty_predict <- predict(empty_model)
# This generates predictions from Neighborhood model
Ames$Neighborhood_predict <- predict(Neighborhood_model)
# Here are the differences
# Square and sum these differences to calculate SSM
sum((Ames$empty_predict - Ames$Neighborhood_predict)^2)
ex() %>% check_function('sum') %>%
check_result() %>% check_equal()
CK Code: X3_Code_Conceptualizing_01
require(coursekata)
# Produces ANOVA table for Neighborhood model
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
supernova(Neighborhood_model)
# Write additional code to produce ANOVA table for HomeSizeK model
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
# Produces ANOVA table for Neighborhood model
Neighborhood_model <- lm(PriceK ~ Neighborhood, data = Ames)
supernova(Neighborhood_model)
# Write additional code to produce ANOVA table for HomeSizeK model
HomeSizeK_model <- lm(PriceK ~ HomeSizeK, data = Ames)
supernova(HomeSizeK_model)
ex() %>% check_function("supernova", 2) %>%
check_result() %>% check_equal()
CK Code: X3_Code_Conceptualizing_02