Does a 2-sample t-test for clustered data.

t.test.cluster(y, cluster, group, conf.int = 0.95)
# S3 method for class 't.test.cluster'
print(x, digits, ...)

Arguments

y

normally distributed response variable to test

cluster

cluster identifiers, e.g. subject ID

group

grouping variable with two values

conf.int

confidence coefficient to use for confidence limits

x

an object created by t.test.cluster

digits

number of significant digits to print

...

unused

Value

a matrix of statistics of class t.test.cluster

References

Donner A, Birkett N, Buck C, Am J Epi 114:906-914, 1981.

Donner A, Klar N, J Clin Epi 49:435-439, 1996.

Hsieh FY, Stat in Med 8:1195-1201, 1988.

Author

Frank Harrell

See also

Examples

set.seed(1)
y <- rnorm(800)
group <- sample(1:2, 800, TRUE)
cluster <- sample(1:40, 800, TRUE)
table(cluster,group)
#>        group
#> cluster  1  2
#>      1   4  7
#>      2  10  8
#>      3   9 10
#>      4   8 11
#>      5  14  6
#>      6   8 10
#>      7   7 14
#>      8  10 10
#>      9   6 11
#>      10 11 12
#>      11 12  3
#>      12 10 13
#>      13 12 11
#>      14 13 11
#>      15  8  4
#>      16  9  8
#>      17 11 16
#>      18  8 14
#>      19 11 12
#>      20  7 12
#>      21 11 14
#>      22  8  7
#>      23 12 10
#>      24 14 11
#>      25  7 12
#>      26 10 14
#>      27 10  8
#>      28 18 13
#>      29 11 14
#>      30  7 11
#>      31  2 12
#>      32 14  6
#>      33  6 11
#>      34 12 12
#>      35 14  4
#>      36  6 10
#>      37 11  8
#>      38  8  9
#>      39  5 15
#>      40 15  7
t.test(y ~ group)   # R only
#> 
#> 	Welch Two Sample t-test
#> 
#> data:  y by group
#> t = 3, df = 788, p-value = 0.01
#> alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
#> 95 percent confidence interval:
#>  0.0436 0.3282
#> sample estimates:
#> mean in group 1 mean in group 2 
#>          0.0792         -0.1067 
#> 
t.test.cluster(y, cluster, group)
#>                                     1       2      
#> N                                   389     411    
#> Clusters                            40      40     
#> Mean                                 0.0792 -0.1067
#> SS among clusters within groups     43.5    40.6   
#> SS within clusters within groups    388     363    
#> MS among clusters within groups     1.08           
#> d.f.                                78             
#> MS within clusters within groups    1.04           
#> d.f.                                720            
#> Na                                  9.85           
#> Intracluster correlation            0.00347        
#> Variance Correction Factor          1.03    1.04   
#> Variance of effect                  0.0054         
#> Variance without cluster adjustment 0.00522        
#> Design Effect                       1.03           
#> Effect (Difference in Means)        -0.186         
#> S.E. of Effect                      0.0735         
#> 0.95 Confidence limits              -0.3300 -0.0419
#> Z Statistic                         -2.53          
#> 2-sided P Value                     0.0114         
# Note: negate estimates of differences from t.test to
# compare with t.test.cluster