## Course Outline

• segmentLearnosity
• segmentCKCode

### list Items Test Book

Book
• Items Test Book

## ckcode ⌲ chapter-b4-digging-deeper

require(coursekata) Fingers <- Fingers %>% mutate( Height2Group = factor(ntile(Height, 2), 1:2, c("short", "tall")) ) # fit a model for Thumb ~ Height2Group Height2Group_model <- # this prints out the estimates Height2Group_model Height2Group_model <- lm(formula = Thumb ~ Height2Group, data = Fingers) Height2Group_model ex() %>% { check_function(., "lm") %>% check_arg("formula") %>% check_equal() check_object(., "Height2Group_model") %>% check_equal() check_output_expr(., "Height2Group_model") }
CK Code: B4_Code_Extending_02
require(coursekata) Fingers <- Fingers %>% mutate( Height2Group = factor(ntile(Height, 2), 1:2, c("short", "tall")) ) Height2Group.model <- lm(Thumb ~ Height2Group, data = Fingers) # modify these two lines of code to create 3 Height groups with the labels "short", "medium", and "tall" # make sure you save to a new variable in Fingers called Height3Group Fingers$Height2Group <- ntile(Fingers$Height, 2) Fingers$Height2Group <- factor(Fingers$Height2Group, levels = c(1,2), labels = c("short", "tall")) # this prints out 10 rows of Fingers for selected columns head(select(Fingers, Thumb, Height, Height3Group), 10) Fingers$Height3Group <- ntile(Fingers$Height, 3) Fingers$Height3Group <- factor(Fingers$Height3Group, levels = c(1,2,3), labels = c("short", "medium", "tall")) head(select(Fingers, Thumb, Height, Height3Group), 10) ex() %>% { check_object(., "Fingers") %>% check_column("Height3Group") %>% check_equal() check_output_expr(., "head(select(Fingers, Thumb, Height, Height3Group),10)") }
CK Code: B4_Code_Extending_03
require(coursekata) Fingers <- Fingers %>% mutate( Height2Group = factor(ntile(Height, 2), 1:2, c("short", "tall")), Height3Group = factor(ntile(Height, 3), 1:3, c("short", "medium", "tall")) ) # use favstats() to print the group means of Thumb length for the three height groups you created earlier favstats() favstats(Thumb ~ Height3Group, data = Fingers) ex() %>% check_function("favstats") %>% check_result() %>% check_equal()
CK Code: B4_Code_Extending_04
require(coursekata) Fingers <- Fingers %>% mutate( Height2Group = factor(ntile(Height, 2), 1:2, c("short", "tall")), Height3Group = factor(ntile(Height, 3), 1:3, c("short", "medium", "tall")) ) Height2Group_model <- lm(Thumb ~ Height2Group, data = Fingers) # modify this code to fit the model Height3Group_model <- lm(Thumb ~ ) # this prints out the estimates Height3Group_model Height3Group_model <- lm(Thumb ~ Height3Group, data = Fingers) Height3Group_model ex() %>% { check_function(., "lm") %>% check_arg("formula") %>% check_equal() check_object(., "Height3Group_model") %>% check_equal() check_output_expr(., "Height3Group_model") }
CK Code: B4_Extending_05
require(coursekata) Fingers <- Fingers %>% mutate( Height2Group = factor(ntile(Height, 2), 1:2, c("short", "tall")), Height3Group = factor(ntile(Height, 3), 1:3, c("short", "medium", "tall")) ) Height2Group_model <- lm(Thumb ~ Height2Group, data = Fingers) # creates best fitting Height3Group_model Height3Group_model <- lm(Thumb ~ Height3Group, data = Fingers) # use supernova() to print the ANOVA table for this model # creates best fitting Height3Group_model Height3Group_model <- lm(Thumb ~ Height3Group, data = Fingers) # use supernova() to print the ANOVA table for this model supernova(Height3Group_model) ex() %>% check_output_expr("supernova(Height3Group_model)")
CK Code: B4_Extending_06
require(coursekata) # change the function lm(Tip ~ Condition, data = TipExperiment) b1(Tip ~ Condition, data = TipExperiment) ex() %>% check_or( check_function(., "b1") %>% check_result() %>% check_equal, override_solution(., 'b0(Tip ~ Condition, data = TipExperiment)') %>% check_function("b0") %>% check_result() %>% check_equal() )
CK Code: B4_EffectSize_01
require(coursekata) # run this code Condition_model <- lm(Tip ~ Condition, data = TipExperiment) supernova(Condition_model) # run this code Condition_model <- lm(Tip ~ Condition, data = TipExperiment) PRE(Condition_model) ex() %>% check_function("PRE") %>% check_result() %>% check_equal()
CK Code: B4_EffectSize_02
require(coursekata) # run this code cohensD(Tip ~ Condition, data = TipExperiment) cohensD(Tip ~ Condition, data = TipExperiment) ex() %>% check_function("cohensD") %>% check_result() %>% check_equal()
CK Code: B4_EffectSize_03
require(coursekata) # this code calculate b1 for the actual data b1(Tip ~ Condition, data = TipExperiment) # this code shuffles the Tip variable before calculating b1 b1(shuffle(Tip) ~ Condition, data = TipExperiment) # shuffle the Tip variable b1(Tip ~ Condition, data = TipExperiment) b1(shuffle(Tip) ~ Condition, data = TipExperiment) ex() %>% check_or( check_function(., 'b1') %>% check_arg('object') %>% check_equal(), override_solution_code(., "b1(shuffle(Tip) ~ shuffle(Condition), data = TipExperiment)") %>% check_function(., 'b1') %>% check_arg('object') %>% check_equal(), override_solution_code(., "b1(Tip ~ shuffle(Condition), data = TipExperiment)") %>% check_function(., 'b1') %>% check_arg('object') %>% check_equal() )
CK Code: B4_Shuffle_02
require(coursekata) # modify to produce 10 shuffled b1s do( ) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) # modify to produce 10 shuffled b1s do(10) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) ex() %>% check_function('do') %>% check_arg('object') %>% check_equal()
CK Code: B4_Shuffle_03