29.3: The t-test as a Linear Model (Section 28.3)

Statistical Thinking for the 21st Century · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC 4.0, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    29.3: The t-test as a Linear Model (Section 28.3)

    We can also use lm() to implement these t-tests.

    The one-sample t-test is basically a test for whether the intercept is different from zero, so we use a model with only an intercept and apply this to the data after subtracting the null hypothesis mean (so that the expectation under the null hypothesis is an intercept of zero):

    NHANES_BP_sample <- NHANES_BP_sample %>%
      mutate(BPSysAveDiff = BPSysAve-120)
    lm_result <- lm(BPSysAveDiff ~ 1, data=NHANES_BP_sample)
    summary(lm_result)
    ## 
    ## Call:
    ## lm(formula = BPSysAveDiff ~ 1, data = NHANES_BP_sample)
    ## 
    ## Residuals:
    ##    Min     1Q Median     3Q    Max 
    ## -36.11 -13.11  -1.11   9.39  67.89 
    ## 
    ## Coefficients:
    ##             Estimate Std. Error t value Pr(>|t|)  
    ## (Intercept)     3.11       1.41     2.2    0.029 *
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## Residual standard error: 18 on 154 degrees of freedom

    You will notice that this p-value is twice as big as the one obtained from the one-sample t-test above; this is because that was a one-tailed test, while lm() is performing a two-tailed test.

    We can also run the two-sample t-test using lm():

    lm_ttest_result <- lm(BPSysAve ~ SmokeNow, data=sample_df)
    summary(lm_ttest_result)
    ## 
    ## Call:
    ## lm(formula = BPSysAve ~ SmokeNow, data = sample_df)
    ## 
    ## Residuals:
    ##    Min     1Q Median     3Q    Max 
    ## -45.16 -11.16  -2.16   8.84 101.18 
    ## 
    ## Coefficients:
    ##             Estimate Std. Error t value Pr(>|t|)    
    ## (Intercept)  125.160      0.897  139.54  < 2e-16 ***
    ## SmokeNowYes   -5.341      1.269   -4.21  2.8e-05 ***
    ## ---
    ## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    ## 
    ## Residual standard error: 18 on 784 degrees of freedom
    ## Multiple R-squared:  0.0221, Adjusted R-squared:  0.0209 
    ## F-statistic: 17.7 on 1 and 784 DF,  p-value: 2.84e-05

    This gives the same p-value for the SmokeNowYes variable as it did for the two-sample t-test above.


    This page titled 29.3: The t-test as a Linear Model (Section 28.3) was last modified on Mon, 11 Jan 2021 05:14:02 GMT and is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform.