Chapter3 Is This
Chapter3 Is This
approximation
INFERENCE FOR LINEAR REGRESSION IN R
Jo Hardin
Professor, Pomona College
INFERENCE FOR LINEAR REGRESSION IN R
Sampling distribution of slope: good t fit
ggplot(starFatCal, aes(x = statistic)) +
geom_histogram(aes(y = ..density..), bins = 50) +
stat_function(fun = dt, color = "red", args = list(df = nrow(starbucks) - 2))
Jo Hardin
Professor, Pomona College
INFERENCE FOR LINEAR REGRESSION IN R
INFERENCE FOR LINEAR REGRESSION IN R
alpha = 0.05
crit_val <- qt((1-alpha/2), df = nrow(starbucks) - 2)
lm(Calories ~ Fat, data=starbucks) %>%
tidy(conf.int = TRUE, conf.level = 1-alpha)
A tibble: 1 x 2
low high
<dbl> <dbl>
1 11.16712 14.34817
Jo Hardin
Professor, Pomona College
INFERENCE FOR LINEAR REGRESSION IN R
INFERENCE FOR LINEAR REGRESSION IN R
Predicting average calories at specific fat
library(broom)
alpha <- .05
crit_val <- qt((1-alpha/2), df = nrow(starbucks) - 2)
newfood <- data.frame(Fat = c(0,10,20,30))
augment(lm(Calories ~ Fat, data=starbucks), newdata = newfood) %>%
mutate(lowMean = .fitted - crit_val*.se.fit,
upMean = .fitted + crit_val*.se.fit)
A tibble: 113 x 12
Calories Fat .fitted .se.fit .resid .hat .sigma
<int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 300 5 211.7763 11.473843 88.223722 0.025567957 71.57640
2 380 6 224.5349 10.823741 155.465125 0.022752704 70.50502
3 410 22 428.6724 8.176354 -18.672436 0.012983674 72.05959
... with 103 more rows, and 5 more variables: .cooksd <dbl>, .std.resid <dbl>, .se.pred <dbl>,
lowResp <dbl>, upResp bl>