Linear Statistical Models

Two-Group Independent t-test

Updated for Stata 11


This unit reviews the two-group t-test for independent groups.

t-test Hypotheses

  • 2-tail - H0: μ1 = μ2     H1: μ1 <> μ2
  • 1-tail - H0: μ1 <= μ2    H1: μ1 > μ2
  • 1-tail - H0: μ1 >= μ2    H1: μ1 < μ2

    t-test Assumptions

  • Independence
  • Normality
  • Homogeneity of Variance (Homoscedasicity)

    t-test Formulas

  • Pooled Variance

  • Standard Error of Differences between Means

  • t-test

    Example

    Consider an example using the hsb2 dataset with write as the outcome variable and schtyp as the two-group categorical variable.

    use http://www.philender.com/courses/data/hsbdemo, clear
    
    ttest write, by(schtyp)
    
    Two-sample t test with equal variances
    
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
      public |     168       52.25    .7549735    9.785575    50.75948    53.74052
     private |      32    55.53125    1.269195     7.17965    52.94271    58.11979
    ---------+--------------------------------------------------------------------
    combined |     200      52.775    .6702372    9.478586    51.45332    54.09668
    ---------+--------------------------------------------------------------------
        diff |            -3.28125    1.817938               -6.866256     .303756
    ------------------------------------------------------------------------------
    Degrees of freedom: 198
    
                     Ho: mean(public) - mean(private) = diff = 0
    
         Ha: diff < 0               Ha: diff ~= 0              Ha: diff > 0
           t =  -1.8049                t =  -1.8049              t =  -1.8049
       P < t =   0.0363          P > |t| =   0.0726          P > t =   0.9637
    
    anova write schtyp
    
                               Number of obs =     200     R-squared     =  0.0162
                               Root MSE      = 9.42527     Adj R-squared =  0.0112
    
                      Source |  Partial SS    df       MS           F     Prob > F
                  -----------+----------------------------------------------------
                       Model |   289.40625     1   289.40625       3.26     0.0726
                             |
                      schtyp |   289.40625     1   289.40625       3.26     0.0726
                             |
                    Residual |  17589.4687   198  88.8357008   
                  -----------+----------------------------------------------------
                       Total |   17878.875   199   89.843593
    
    regress write i.schtyp
    
          Source |       SS       df       MS              Number of obs =     200
    -------------+------------------------------           F(  1,   198) =    3.26
           Model |   289.40625     1   289.40625           Prob > F      =  0.0726
        Residual |  17589.4688   198  88.8357008           R-squared     =  0.0162
    -------------+------------------------------           Adj R-squared =  0.0112
           Total |   17878.875   199   89.843593           Root MSE      =  9.4253
    
    ------------------------------------------------------------------------------
           write |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
        2.schtyp |    3.28125   1.817938     1.80   0.073    -.3037561    6.866256
           _cons |      52.25   .7271753    71.85   0.000       50.816      53.684
    ------------------------------------------------------------------------------
    
    test 2.schtyp
    
     ( 1)  2.schtyp = 0
    
           F(  1,   198) =    3.26
                Prob > F =    0.0726

    There is also a version of the two-group independent t-test without the assumption that the population variances are equal.

    ttest write, by(schtyp) unequal
    
    Two-sample t test with unequal variances
    
    ------------------------------------------------------------------------------
       Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
    ---------+--------------------------------------------------------------------
      public |     168       52.25    .7549735    9.785575    50.75948    53.74052
     private |      32    55.53125    1.269195     7.17965    52.94271    58.11979
    ---------+--------------------------------------------------------------------
    combined |     200      52.775    .6702372    9.478586    51.45332    54.09668
    ---------+--------------------------------------------------------------------
        diff |            -3.28125    1.476767               -6.240124   -.3223763
    ------------------------------------------------------------------------------
    Satterthwaite's degrees of freedom:  55.5288
    
                     Ho: mean(public) - mean(private) = diff = 0
    
         Ha: diff < 0               Ha: diff ~= 0              Ha: diff > 0
           t =  -2.2219                t =  -2.2219              t =  -2.2219
       P < t =   0.0152          P > |t| =   0.0304          P > t =   0.9848
    
    regress write i.schtyp, robust
    
    Linear regression                                      Number of obs =     200
                                                           F(  1,   198) =    5.01
                                                           Prob > F      =  0.0263
                                                           R-squared     =  0.0162
                                                           Root MSE      =  9.4253
    
    ------------------------------------------------------------------------------
                 |               Robust
           write |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
        2.schtyp |    3.28125   1.465809     2.24   0.026       .39065     6.17185
           _cons |      52.25   .7565153    69.07   0.000     50.75814    53.74186
    ------------------------------------------------------------------------------


    Linear Statistical Models Course

    Phil Ender, 17sep10, 2apr02; 12feb98