Course Outline
-
segmentLearnosity
-
segmentCKCode
-
ckcode-chapter-b3-adding-explanatory
list Items Test Book
Book
ckcode ⌲ chapter-b3-adding-explanatory
require(coursekata)
# find best fitting model
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# add code to visualize the new model on the jitter plot
gf_jitter(Thumb ~ Sex, data = Fingers, width = .1)
# find best fitting model
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# add code to visualize the new model on the jitter plot
gf_jitter(Thumb ~ Sex, data = Fingers, width = .1) %>%
gf_model(Sex_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(Thumb ~ Sex, data = Fingers) %>% gf_model(Thumb ~ Sex)") %>%
check_function(., "gf_model") %>%
check_arg("model") %>%
check_equal()
)
}
CK Code: B3_Code_RtoFit_01
require(coursekata)
# we have saved the Sex model for you
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# write code to generate predictions using this model
# no need to save the predictions
# we have saved the Sex model for you
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# write code to generate predictions using this model
# no need to save the predictions
predict(Sex_model)
ex() %>%
check_function("predict") %>%
check_result() %>%
check_equal()
CK Code: B3_Code_RtoFit_02
require(coursekata)
# we have saved the Sex model for you
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# print out the best fitting parameter estimates
# we have saved the Sex model for you
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# print out the best fitting parameter estimates
Sex_model
ex() %>% check_output_expr("Sex_model")
CK Code: B3_Code_RtoFit_03
require(coursekata)
# this creates the residuals from the Sex_model
Sex_model <- lm(Fingers$Thumb ~ Fingers$Sex)
Fingers$Sex_resid <- resid(Sex_model)
# this creates histograms of Thumb for each Sex
# modify it to create histograms of Sex_resid for each Sex
gf_histogram(~Thumb, data = Fingers) %>%
gf_facet_grid(Sex ~ .)
# this creates the residuals from the Sex_model
Sex_model <- lm(Fingers$Thumb ~ Fingers$Sex)
Fingers$Sex_resid <- resid(Sex_model)
# this creates histograms of Thumb for each Sex
# modify it to create histograms of Sex_resid for each Sex
gf_histogram(~Sex_resid, data = Fingers) %>%
gf_facet_grid(Sex ~ .)
ex() %>% {
check_or(.,
check_function(., "gf_histogram") %>% {
check_arg(., "object") %>% check_equal()
check_arg(., "data") %>% check_equal()
},
override_solution(., "gf_histogram(Fingers, ~ Sex_resid)") %>%
check_function("gf_histogram") %>% {
check_arg(., "object") %>% check_equal()
check_arg(., "gformula") %>% check_equal()
}
)
check_function(., "gf_facet_grid") %>%
check_arg("...") %>%
check_equal(incorrect_msg = "Make sure you keep the code to create a grid faceted by `Sex`")
}
CK Code: B3_Code_Graphing_01
require(coursekata)
# This codes saves the best fitting models
empty_model <- lm(Thumb ~ NULL, data=Fingers)
Sex_model <- lm(Thumb ~ Sex, data=Fingers)
# 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 Sex model
# This codes saves the best fitting models
empty_model <- lm(Thumb ~ NULL, data=Fingers)
Sex_model <- lm(Thumb ~ Sex, data=Fingers)
# 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 Sex model
sum(resid(Sex_model)^2)
ex() %>% {
check_function(., "sum", 1) %>%
check_result() %>% check_equal()
check_function(., "sum", 2) %>%
check_result() %>% check_equal()
}
CK Code: B3_Code_UsingSS_01
require(coursekata)
empty_model <- lm(Thumb ~ NULL, data = Fingers)
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
# try running the code as is
# then modify to create the ANOVA table for Sex_model
supernova(empty_model)
empty_model <- lm(Thumb ~ NULL, data = Fingers)
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
supernova(Sex_model)
ex() %>% {
check_function(., "lm") %>% check_result() %>% check_equal()
check_object(., "Sex_model") %>% check_equal()
check_function(., "supernova") %>% check_result() %>% check_equal()
}
CK Code: B3_Code_UsingSS_02
require(coursekata)
empty_model <- lm(Thumb ~ NULL, data=Fingers)
Sex_model <- lm(Thumb ~ Sex, data=Fingers)
# creates the differences between the two predictions
error_reduced <- predict(Sex_model) - predict(empty_model)
# modify this line of code to square and sum these differences
error_reduced
# creates the differences between the two predictions
error_reduced <- predict(Sex_model) - predict(empty_model)
# modify this line of code to square and sum these differences
sum(error_reduced ^ 2)
ex() %>% check_output(1334.2)
CK Code: B3_Code_Partitioning_01
require(coursekata)
# run your code here
CK Code: B3_Code_Review2_01
require(coursekata)
# run your code here
CK Code: B3_Code_Review2_02
require(coursekata)
# run your code here
CK Code: B3_Code_Review2_03
require(coursekata)
# run your code here
CK Code: B3_Code_Review2_04
require(coursekata)
# run your code here
CK Code: B3_Code_Review2_05