## Course Outline

• segmentLearnosity
• segmentCKCode

### list Items Test Book

Book
• Items Test Book

## ckcode ⌲ chapter-c1-logic-inference

require(coursekata) b1(shuffle(Tip) ~ Condition, data = TipExperiment) do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) ex() %>% check_function("do") %>% check_arg("object") %>% check_equal()
CK Code: ch09-02-01-code
require(coursekata) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) head(sdob1) # the instructions in the text above the exercise say that they can change the name of the object (sdob1) if they want, and the sdob1 contents are shuffled, so the easiest thing here is to just check that they called head ex() %>% check_function("head")
CK Code: ch09-03-01-code
require(coursekata) # we created the sampling distribution of b1s for you sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) # visualize that distribution in a histogram # we created the sampling distribution of b1s for you sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) # visualize that distribution in a histogram gf_histogram(~b1, data = sdob1) ex() %>% check_or( check_function(., "gf_histogram") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal(eval = FALSE) }, override_solution(., '{ sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) gf_histogram(sdob1, ~b1) }') %>% check_function(., "gf_histogram") %>% { check_arg(., "object") %>% check_equal(eval = FALSE) check_arg(., "gformula") %>% check_equal() }, override_solution(., '{ sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) gf_histogram(~sdob1$b1) }') %>% check_function(., "gf_histogram") %>% { check_arg(., "object") %>% check_equal(eval = FALSE) } ) CK Code: ch09-03-02-code require(coursekata) # this saves the sample b1 and creates a sampling distribution using shuffle sample_b1 <- b1(Tip ~ Condition, data = TipExperiment) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) # change the code below to calculate the *proportion* of b1s # as extreme (positive or negative) as the sample b1 tally(sdob1$b1 > sample_b1 | sdob1$b1 < -sample_b1) # this saves the sample b1 and creates a sampling distribution using shuffle sample_b1 <- b1(Tip ~ Condition, data = TipExperiment) sdob1 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) # change the code below to calculate the *proportion* of b1s # as extreme (positive or negative) as the sample b1 tally(sdob1$b1 > sample_b1 | sdob1$b1 < -sample_b1, format="proportion") ex() %>% check_function("tally") %>% { check_arg(., "format") %>% check_equal() check_result(.) %>% check_equal() } CK Code: ch09-04-01-code require(coursekata) # This code finds the best-fitting Condition model Condition_model <- lm(Tip ~ Condition, data = TipExperiment) # Generate the ANOVA table for this model # This code finds the best-fitting Condition model Condition_model <- lm(Tip ~ Condition, data = TipExperiment) # Generate the ANOVA table for this model supernova(Condition_model) ex() %>% check_function("supernova") %>% check_result() %>% check_equal() CK Code: ch09-05-01-code require(coursekata) TipExp2 <- rbind(TipExperiment, TipExperiment) # these lines run favstats for Tip for both data frames favstats(~ Tip, data = TipExperiment) favstats(~ Tip, data = TipExp2) # now fit the Condition model of Tip for both data frames lm() lm() # these lines run favstats for Tip for both data frames favstats(~ Tip, data = TipExperiment) favstats(~ Tip, data = TipExp2) # now fit the Condition model of Tip for both data frames lm(Tip ~ Condition, data = TipExperiment) lm(Tip ~ Condition, data = TipExp2) ex() %>% { check_function(., "lm", index = 1) %>% check_arg("formula") %>% check_equal() check_function(., "lm", index = 2) %>% check_arg("formula") %>% check_equal() } CK Code: ch09-06-01-code require(coursekata) TipExp2 <- rbind(TipExperiment, TipExperiment) # these 2 lines will create sampling distributions of b1 from 44 and 88 tables respectively sdob44 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) sdob88 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExp2) # This calculates the standard error of the first sampling distribution (sdob44) sd(~ b1, data = sdob44) # Use sd() to calculate the standard error for sdob88 # these 2 lines will create sampling distributions of b1 from 44 and 88 tables respectively sdob44 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExperiment) sdob88 <- do(1000) * b1(shuffle(Tip) ~ Condition, data = TipExp2) # This calculates the standard error of the first sampling distribution (sdob44) sd(~ b1, data = sdob44) # Use sd() to calculate the standard error for sdob88 sd(~ b1, data = sdob88) ex() %>% check_function("sd", index = 2) %>% check_result() %>% check_equal() CK Code: ch09-06-02-code require(coursekata) TipExp2 <- rbind(TipExperiment, TipExperiment) # Produces ANOVA table for model fit from original data (n = 44) supernova(lm(Tip ~ Condition, data = TipExperiment)) # Write code for the ANOVA table for the model fit from TipExp2 (n = 88) # Produces ANOVA table for model fit from original data (n = 44) supernova(lm(Tip ~ Condition, data = TipExperiment)) # Write code for the ANOVA table for the model fit from TipExp2 (n = 88) supernova(lm(Tip ~ Condition, data = TipExp2)) ex() %>% { check_function(., "supernova", index = 1) %>% check_result() %>% check_equal() check_function(., "supernova", index = 2) %>% check_result() %>% check_equal() } CK Code: ch09-06-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 # fit a regression model in which Check is used to explain Tip # fit a regression model in which Check is used to explain Tip lm(Tip ~ Check, data = TipExperiment) ex() %>% check_function("lm") %>% check_result() %>% check_equal() CK Code: ch09-07-01-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 set.seed(NULL) # modify this to shuffle the data gf_point(Tip ~ Check, data = TipExperiment, color = "orangered") %>% gf_lm() # modify this to shuffle the data gf_point(shuffle(Tip) ~ Check, data = TipExperiment, color = "orangered") %>% gf_lm() ex() %>% { # can't check outcomes because gf_point produces an unreliable result check_function(., "gf_lm") check_or(., check_function(., "gf_point") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() }, override_solution_code(., "gf_point(Tip ~ shuffle(Check), data = TipExperiment)") %>% check_function(., "gf_point") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() }, override_solution_code(., "gf_point(shuffle(Tip) ~ shuffle(Check), data = TipExperiment)") %>% check_function(., "gf_point") %>% { check_arg(., "object") %>% check_equal() check_arg(., "data") %>% check_equal() } ) } CK Code: ch09-07-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 sample_b1 <- b1(Tip ~ Check, data = TipExperiment) # generate a sampling distribution of 1000 b1s from the shuffled data sdob1 <- do() * b1() # histogram of the 1000 b1s gf_histogram(~ b1, data = sdob1, fill = ~middle(b1, .95), bins = 100, show.legend = FALSE) %>% gf_point(x = sample_b1, y = 0, show.legend = FALSE) # generate a sampling distribution of 1000 b1s from the shuffled data sdob1 <- do(1000) * b1(shuffle(Tip) ~ Check, data = TipExperiment) # histogram of the 1000 b1s gf_histogram(~ b1, data = sdob1, fill = ~middle(b1, .95), bins = 100, show.legend = FALSE) %>% gf_point(x = sample_b1, y = 0, show.legend = FALSE) ex() %>% check_or(., check_function(., 'b1') %>% { check_arg(., 1) %>% check_equal(eval = FALSE) check_arg(., 2) %>% check_equal() }, override_solution_code(., "sdob1 <- do(1000) * b1(Tip ~ shuffle(Check), data = TipExperiment)") %>% check_function(., 'b1') %>% { check_arg(., 1) %>% check_equal(eval = FALSE) check_arg(., 2) %>% check_equal() } ) CK Code: ch09-07-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 # here's the best-fitting Check model Check_model <- lm(Tip ~ Check, data = TipExperiment) # create the ANOVA table for this model Check_model <- lm(Tip ~ Check, data = TipExperiment) supernova(Check_model) # Or # supernova(lm(Tip ~ Check, data = TipExperiment)) ex() %>% check_function("supernova") %>% check_result() %>% check_equal()
CK Code: ch09-07-03-code