Research question

Inference for Linear Regression in R

Jo Hardin

Professor, Pomona College

Consider possible research questions for the Starbucks data
  • Are protein and carbohydrates linearly associated in the population? (two-sided research question)
  • Are protein and carbohydrates linearly associated in a positive direction in the population? (one-sided research question)
head(starbucks)
A tibble: 6 x 6
                                    Item Calories   Fat Carbs
                                   <chr>    <int> <dbl> <int>
1                           Chonga Bagel      300     5    50
2                           8-Grain Roll      380     6    70
3                       Almond Croissant      410    22    45
4                          Apple Fritter      460    23    56
5                       Banana Nut Bread      420    22    52
6 Blueberry Muffin with Yogurt and Honey      380    16    53
# ... with 2 more variables: Fiber <int>, Protein <int>
Inference for Linear Regression in R
summary(lm(Carbs ~ Protein, data = starbucks))
Call:
lm(formula = Carbs ~ Protein, data = starbucks)
Residuals:
    Min      1Q  Median      3Q     Max 
-35.360 -11.019   0.125   9.970  35.640 
Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  37.1116     2.4680   15.04   <2e-16 ***
Protein       0.3815     0.1734    2.20   0.0299 *  
 ---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
...
lm(Carbs ~ Protein, data = starbucks) %>% tidy()
         term   estimate std.error statistic      p.value
1 (Intercept) 37.1116401 2.4680349 15.036919 1.539345e-28
2     Protein  0.3814696 0.1734226  2.199654 2.990434e-02
Inference for Linear Regression in R
Call:
lm(formula = Carbs ~ Protein,
   data = starbucks)

Residuals:
    Min      1Q  Median      3Q      Max
-35.360 -11.019   0.125   9.970   35.640

Coefficients:
summary(lm(Carbs ~ Protein,
        data = starbucks))
Std. Error
2.4680   
0.1734
            Estimate Std. Error
(Intercept)  37.1116     2.4680
Protein       0.3815     0.1734
            t value Pr(>|t|)    
(Intercept)   15.04   <2e-16 ***
Protein        2.20   0.0299 *  
--
Signif. codes:  
  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lm(Carbs ~ Protein, 
   data = starbucks) %>% 
  tidy()
std.error
2.4680349
0.1734226
Inference for Linear Regression in R
Call:
lm(formula = Carbs ~ Protein,
   data = starbucks)

Residuals:
    Min      1Q  Median      3Q      Max
-35.360 -11.019   0.125   9.970   35.640

Coefficients:
summary(lm(Carbs ~ Protein,
        data = starbucks))
t value
15.04
2.20
            Estimate Std. Error
(Intercept)  37.1116     2.4680
Protein       0.3815     0.1734
            t value Pr(>|t|)    
(Intercept)   15.04   <2e-16 ***
Protein        2.20   0.0299 *  
--
Signif. codes:  
  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lm(Carbs ~ Protein, 
   data = starbucks) %>% 
  tidy()
statistic
15.036919
 2.199654
Inference for Linear Regression in R
Call:
lm(formula = Carbs ~ Protein,
   data = starbucks)

Residuals:
    Min      1Q  Median      3Q      Max
-35.360 -11.019   0.125   9.970   35.640

Coefficients:
summary(lm(Carbs ~ Protein,
        data = starbucks))
Pr(>|t|)
<2e-16 *** 
0.0299 *
            Estimate Std. Error
(Intercept)  37.1116     2.4680
Protein       0.3815     0.1734
            t value Pr(>|t|)    
(Intercept)   15.04   <2e-16 ***
Protein        2.20   0.0299 *  
--
Signif. codes:  
  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lm(Carbs ~ Protein, 
   data = starbucks) %>% 
  tidy()
p.value
1.539345e-28
2.990434e-02
Inference for Linear Regression in R

Let's practice!

Inference for Linear Regression in R

Preparing Video For Download...