Course Outline

list Items Test Book

Book
  • Items Test Book

ckcode ⌲ chapter-b5-quantitative-explanatory

library(coursekata) # edit the Height2Group_model code to create Height_model Height2Group_model <- lm(Thumb ~ Height2Group, data = Fingers) # save the predictions of the Height_model as a new variable in Fingers Fingers$Height_predict <- # this code prints out the first 6 observations head(select(Fingers, Thumb, Height, Height_predict)) # edit the Height2Group_model code to create Height_model Height_model <- lm(Thumb ~ Height, data = Fingers) # save the predictions of the Height_model as a new variable in Fingers Fingers$Height_predict <- predict(Height_model) # this code prints out the first 6 observations for 3 columns head(select(Fingers, Thumb, Height, Height_predict)) ex() %>% { check_object(., "Height_model") %>% check_equal() check_object(., "Fingers") %>% check_column("Height_predict") %>% check_equal() }
CK Code: B5_Code_Quantitative_01
library(coursekata) # saves the Height model Height_model <- lm(Thumb ~ Height, data = Fingers) # print it out # saves the Height model Height_model <- lm(Thumb ~ Height, data = Fingers) # print it out Height_model ex() %>% check_output_expr("Height_model")
CK Code: B5_Code_Regression_01
require(coursekata) Fingers$SexNum <- as.numeric(Fingers$Sex) # fit a model of Thumb length based on Sex Sex_model <- lm() # fit a model of Thumb length based on SexNum SexNum_model <- lm() # this prints the parameter estimates from the two models Sex_model SexNum_model # fit a model of Thumb length based on Sex Sex_model <- lm(Thumb ~ Sex, data=Fingers) # fit a model of Thumb length based on SexNum SexNum_model <- lm(Thumb ~ SexNum, data=Fingers) # this prints the parameter estimates from the two models Sex_model SexNum_model ex() %>% { check_object(., "Sex_model") %>% check_equal() check_object(., "SexNum_model") %>% check_equal() check_output_expr(., "Sex_model SexNum_model") }
CK Code: B5_Code_Comparing_01
require(coursekata) # this calculates SST empty_model <- lm(Thumb ~ NULL, data=Fingers) print("SST") sum(resid(empty_model)^2) # this calculates SSE Height_model <- lm(Thumb ~ Height, data = Fingers) print("SSE") sum(resid(Height_model)^2) # no test ex() %>% check_error()
CK Code: B5_Code_Error_01
require(coursekata) # this saves the Height_model Height_model <- lm(Thumb ~ Height, data = Fingers) # print the ANOVA tables for this model # this saves the Height_model Height_model <- lm(Thumb ~ Height, data = Fingers) # print the ANOVA tables for this model supernova(Height_model) ex() %>% check_function("supernova") %>% check_result() %>% check_equal()
CK Code: B5_Code_Assessing_01
require(coursekata) Fingers <- filter(Fingers, Thumb >= 33 & Thumb <= 100) # this transforms all Thumb lengths into z-scores Fingers$zThumb <- zscore(Fingers$Thumb) # modify this to do the same for Height Fingers$zHeight <- # this transforms all Thumb lengths into z-scores Fingers$zThumb <- zscore(Fingers$Thumb) # modify this to do the same for Height Fingers$zHeight <- zscore(Fingers$Height) ex() %>% check_object("Fingers") %>% { check_column(., "zThumb") %>% check_equal() check_column(., "zHeight") %>% check_equal() }
CK Code: B5_Code_Correlation_01
require(coursekata) Fingers <- Fingers %>% filter(Thumb >= 33 & Thumb <= 100) %>% mutate( zThumb = zscore(Thumb), zHeight = zscore(Height) ) # this makes a scatterplot of the raw scores # size makes the points bigger or smaller gf_point(Thumb ~ Height, data = Fingers, size = 4) # zThumb and zHeight have already been created for you # modify the code below to make a scatterplot of the z-scores gf_point( , data = Fingers, size = 4, color = "navy") # this makes a scatterplot of the raw scores # size makes the points bigger or smaller gf_point(Thumb ~ Height, data = Fingers, size = 4) # zThumb and zHeight have already been created for you # modify the code below to make a scatterplot of the z-scores gf_point(zThumb ~ zHeight, data = Fingers, size = 4, color = "navy") ex() %>% { check_function(., "gf_point", index = 1) %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() } check_function(., "gf_point", index = 2) %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() } }
CK Code: B5_Code_Correlation_02
require(coursekata) Fingers <- Fingers %>% filter(Thumb >= 33 & Thumb <= 100) %>% mutate( zThumb = zscore(Thumb), zHeight = zscore(Height) ) Height_model <- lm(Thumb ~ Height, data = Fingers) # this fits a regression model of Thumb by Height lm(Thumb ~ Height, data = Fingers) # write code to fit a regression model predicting zThumb with zHeight # this fits a regression model of Thumb by Height lm(Thumb ~ Height, data = Fingers) # write code to fit a regression model predicting zThumb with zHeight lm(zThumb ~ zHeight, data = Fingers) ex() %>% check_function("lm", index = 2) %>% check_result() %>% check_equal()
CK Code: B5_Code_Correlation_03
require(coursekata) Fingers <- Fingers %>% filter(Thumb >= 33 & Thumb <= 100) %>% mutate( zThumb = zscore(Thumb), zHeight = zscore(Height) ) # this calculates the correlation of Thumb and Height cor(Thumb ~ Height, data = Fingers) cor(Thumb ~ Height, data = Fingers) ex() %>% check_function("cor") %>% check_result() %>% check_equal()
CK Code: B5_Code_Correlation_04
require(coursekata) Fingers <- Fingers %>% filter(Thumb >= 33 & Thumb <= 100) %>% mutate( zThumb = zscore(Thumb), zHeight = zscore(Height) ) Hand <- select(Fingers, Thumb, Index, Middle, Ring, Pinkie, Height) # run the cor() function with the Hand data frame cor(Hand) ex() %>% check_function("cor") %>% check_result() %>% check_equal()
CK Code: B5_Code_Pearsonsr_01
require(coursekata) Fingers <- Fingers %>% filter(Thumb >= 33 & Thumb <= 100) %>% mutate( zThumb = zscore(Thumb), zHeight = zscore(Height) ) # this code finds the square root of the PRE.1529 sqrt(.1529) # add code to calculate the correlation between Thumb and Height # this code finds the square root of .1529 sqrt(.1529) # add code to calculate the correlation between Thumb and Height cor(Thumb ~ Height, data = Fingers) ex() %>% check_output_expr("cor(Thumb ~ Height, data = Fingers)")
CK Code: B5_Code_Pearsonsr_02
require(coursekata) Fingers$ShuffThumb <- shuffle(Fingers$Thumb) shuffled_b1 <- b1(ShuffThumb ~ Height, data = Fingers) gf_point(ShuffThumb ~ Height, data = Fingers) %>% gf_lm(color = "purple") %>% gf_labs(title = paste("Shuffled Data / b1 = ", round(shuffled_b1, digits = 2))) # no solution; just submit the code from the prompt ex() %>% check_error()
CK Code: B5_Code_Fitting_01
require(coursekata) set.seed(42) # use do() to create 10 shuffled b1s # use do() to create 10 shuffled b1s do(10) * b1(shuffle(Thumb) ~ Height, data = Fingers) ex() %>% { check_function(., 'do') %>% check_arg('object') %>% check_equal() check_function(., 'b1') %>% { check_arg(., 'object') %>% check_equal(eval = FALSE) check_arg(., 'data') %>% check_equal() } }
CK Code: B5_Code_Fitting_02
require(coursekata) # run your code here
CK Code: B4_Code_Review2_01

Responses