Course Outline

list Items Test Book

Book
  • Items Test Book

ckcode ⌲ chapter-c3-confidence-intervals

require(coursekata) # run this a few times b1(Tip ~ Condition, data = TipExperiment) b1(Tip ~ Condition, data = resample(TipExperiment)) # no solution; commenting for submit button ex() %>% check_error()
CK Code: ch11-02-01-code
require(coursekata) # modify this to make 1000 bootstrapped b1s sdob1_boot <- do( ) * b1(Tip ~ Condition, data = resample(TipExperiment)) # visualize sdob1_boot with a histogram # modify this to make 1000 bootstrapped b1s sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) # visualize sdob1_boot with a histogram gf_histogram(~b1, data = sdob1_boot) ex() %>% { check_function(., "do") %>% check_arg("object") %>% check_equal() check_or(., check_function(., "gf_histogram") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal(eval = FALSE) }, override_solution(., '{ sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) gf_histogram(sdob1_boot, ~b1) }') %>% check_function("gf_histogram") %>% { check_arg(., "object") %>% check_equal(eval = FALSE) check_arg(., "gformula") %>% check_equal() }, override_solution(., '{ sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) gf_histogram(~sdob1_boot$b1) }') %>% check_function("gf_histogram") %>% check_arg("object") %>% check_equal(eval = FALSE) ) }
CK Code: ch11-02-02-code
require(coursekata) # we have created the sampling distribution for you sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) # run favstats to check out the mean of the sampling distribution # we have created the sampling distribution for you sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) # run favstats to check out the mean of the sampling distribution favstats(~b1, data = sdob1_boot) ex() %>% check_function("favstats") %>% check_result() %>% check_equal()
CK Code: ch11-02-03-code
require(coursekata) sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) sdob1_boot <- arrange(sdob1_boot, b1) # we’ve written code to print the 26th b1 sdob1_boot$b1[26] # write code to print the 975th b1 # we’ve written code to print the 26th b1 sdob1_boot$b1[26] # write code to print the 975th b1 sdob1_boot$b1[975] ex() %>% { check_output_expr(., "sdob1_boot$b1[26]") check_output_expr(., "sdob1_boot$b1[975]") }
CK Code: ch11-02-04-code
require(coursekata) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) # use favstats to find the standard error of these sampling distributions favstats( ) favstats( ) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) sdob1_boot <- do(1000) * b1(Tip ~ Condition, data = resample(TipExperiment)) # use favstats to find the standard error of these sampling distributions favstats(~ b1, data = sdob1) favstats(~ b1, data = sdob1_boot) ex() %>% { check_function(., "favstats", index = 1) %>% check_result() %>% check_equal() check_function(., "favstats", index = 2) %>% check_result() %>% check_equal() }
CK Code: ch11-03-01-code
require(coursekata) # create the condition model of tip and save it as Condition_model Condition_model <- confint(Condition_model) # create the condition model of tip and save it as Condition_model Condition_model <- lm(Tip ~ Condition, data = TipExperiment) confint(Condition_model) ex() %>% check_function("lm") %>% check_result() %>% check_equal()
CK Code: ch11-03-02-code
require(coursekata) # we’ve created the model for you Condition_model <- lm(Tip ~ Condition, data = TipExperiment) # use confint to find the 95% confidence intervals for both parameters # we’ve created the model for you Condition_model <- lm(Tip ~ Condition, data = TipExperiment) # use confint to find the 95% confidence intervals for both parameters confint(Condition_model) ex() %>% check_function("confint") %>% check_result() %>% check_equal()
CK Code: ch11-05-01-code
require(coursekata) # here’s code to find the best-fitting empty model of Tip empty_model <- lm(Tip ~ NULL, data = TipExperiment) # use confint with the empty model (instead of Condition_model) confint(Condition_model) # here’s code to find the best-fitting empty model of Tip empty_model <- lm(Tip ~ NULL, data = TipExperiment) # use confint with the empty model (instead of Condition_model) confint(empty_model) ex() %>% check_function("confint") %>% check_result() %>% check_equal()
CK Code: ch11-05-02-code
require(coursekata) # Simulate Check set.seed(22) x <- round(rnorm(1000, mean=15, sd=10), digits=1) y <- x[x > 5 & x < 30] TipPct <- sample(y, 44) TipExperiment$Check <- (TipExperiment$Tip / TipPct) * 100 # we’ve created the Check model for you Check_model <- lm(Tip ~ Check, data = TipExperiment) # find the confidence interval around the slope # we’ve created the Check model for you Check_model <- lm(Tip ~ Check, data = TipExperiment) # find the confidence interval around the slope confint(Check_model) ex() %>% check_function("confint") %>% check_result() %>% check_equal()
CK Code: ch11-05-03-code
require(coursekata) # Simulate Check set.seed(22) x <- round(rnorm(1000, mean=15, sd=10), digits=1) y <- x[x > 5 & x < 30] TipPct <- sample(y, 44) TipExperiment$Check <- (TipExperiment$Tip / TipPct) * 100 # make a bootstrapped sampling distribution sdob1_boot <- # we’ve added some code to visualize this distribution in a histogram gf_histogram(~ b1, data = sdob1_boot, fill = ~middle(b1, .95), bins = 100) # make a bootstrapped sampling distribution sdob1_boot <- do(1000) * b1(Tip ~ Check, data = resample(TipExperiment)) # we’ve added some code to visualize this distribution in a histogram gf_histogram(~ b1, data = sdob1_boot, fill = ~middle(b1, .95), bins = 100) ex() %>% check_object("sdob1_boot") %>% check_equal()
CK Code: ch11-05-04-code
require(coursekata) # Simulate Check set.seed(22) x <- round(rnorm(1000, mean=15, sd=10), digits=1) y <- x[x > 5 & x < 30] TipPct <- sample(y, 44) TipExperiment$Check <- (TipExperiment$Tip / TipPct) * 100 # we have made a bootstrapped sampling distribution sdob1_boot <- do(1000) * b1(Tip ~ Check, data = resample(TipExperiment)) # modify the code below to arrange the sampling distribution in order by b1 sdob1_boot <- arrange() # find the 26th and 975th b1 sdob1_boot$b1[ ] sdob1_boot$b1[ ] # we have made a bootstrapped sampling distribution sdob1_boot <- do(1000) * b1(Tip ~ Check, data = resample(TipExperiment)) # modify the code below to arrange the sampling distribution in order by b1 sdob1_boot <- arrange(sdob1_boot, b1) # find the 26th and 975th b1 sdob1_boot$b1[26] sdob1_boot$b1[975] ex() %>% { check_output_expr(., "sdob1_boot$b1[26]") check_output_expr(., "sdob1_boot$b1[975]") }
CK Code: ch11-05-05-code
require(coursekata) # import game_data students_per_game <- 35 game_data <- data.frame( outcome = c(16,8,9,9,7,14,5,7,11,15,11,9,13,14,11,11,12,14,11,6,13,13,9,12,8,6,15,10,10,8,7,1,16,18,8,11,13,9,8,14,11,9,13,10,18,12,12,13,16,16,13,13,9,14,16,12,16,11,10,16,14,13,14,15,12,14,8,12,10,13,17,20,14,13,15,17,14,15,14,12,13,12,17,12,12,9,11,19,10,15,14,10,10,21,13,13,13,13,17,14,14,14,16,12,19), game = c(rep("A", students_per_game), rep("B", students_per_game), rep("C", students_per_game)) ) # we have fit and saved game_model for you game_model <- lm(outcome ~ game, data = game_data) # add plot = TRUE pairwise(game_model) # we have fit and saved game_model for you game_model <- lm(outcome ~ game, data = game_data) # add plot = TRUE pairwise(game_model, plot = TRUE) ex() %>% check_function(., "pairwise") %>% check_arg("plot") %>% check_equal()
CK Code: ch11-05-06-code
require(coursekata) # here we have saved the Condition model Condition_model <- lm(Tip ~ Condition, data=TipExperiment) # modify these to find the 90% and 99% CI confint(Condition_model) confint(Condition_model) # here we have saved the Condition model Condition_model <- lm(Tip ~ Condition, data=TipExperiment) # modify these to find the 90% and 99% CI confint(Condition_model, level = .90) confint(Condition_model, level = .99) ex() %>% { check_function(., "confint", index = 1) %>% check_result() %>% check_equal() check_function(., "confint", index = 2) %>% check_result() %>% check_equal() }
CK Code: ch11-06-01-code
require(coursekata) TipExp2 <- rbind(TipExperiment, TipExperiment) # this calculates the confidence interval from the original 44 tables confint(lm(Tip ~ Condition, data = TipExperiment)) # calculate the confidence interval for TipExp2 containing 88 tables # this calculates the confidence interval from the original 44 tables confint(lm(Tip ~ Condition, data = TipExperiment)) # calculate the confidence interval for TipExp2 containing 88 tables confint(lm(Tip ~ Condition, data = TipExp2)) ex() %>% { check_function(., "confint", index = 1) %>% check_result() %>% check_equal() check_function(., "confint", index = 2) %>% check_result() %>% check_equal() }
CK Code: ch11-06-02-code

Responses