Independent samples t-test
Convenience function that runs an independent samples t-test. This is a wrapper function intended to be used for pedagogical purposes only.
independentSamplesTTest( formula, data=NULL, var.equal=FALSE, one.sided=FALSE, conf.level=.95 )
- Formula specifying the outcome and the groups (required).
- Optional data frame containing the variables.
- Should the test assume equal variances (default =
- One sided or two sided hypothesis test (default =
- The confidence level for the confidence interval (default = .95).
independentSamplesTTest function runs an independent-samples t-test and prints the results in a format that is easier for novices to handle than the output of
t.test. All the actual calculations are done by the
cohensD functions. The
formula argument must be a two-sided formula of the form
outcome ~ group. When
var.equal=TRUE, a Student's t-test is run and the estimate of Cohen's d uses a pooled estimate of standard deviation. When
var.equal=FALSE, the Welch test is used, and the estimate of Cohen's d uses the "unequal" method.
As with the
t.test function, the default test is two sided, corresponding to a default value of
one.sided = FALSE. To specify a one sided test, the
one.sided argument must specify the name of the factor level that is hypothesised (under the alternative) to have the larger mean. For instance, if the outcome for "group2" is expected to be higher than for "group1", then the corresponding one sided test is specified by
one.sided = "group2".
This package is under development, and has been released only due to teaching constraints. Until this notice disappears from the help files, you should assume that everything in the package is subject to change. Backwards compatibility is NOT guaranteed. Functions may be deleted in future versions and new syntax may be inconsistent with earlier versions. For the moment at least, this package should be treated with extreme caution.
df <- data.frame( rt = c(451, 562, 704, 324, 505, 600, 829), cond = factor( x=c(1,1,1,2,2,2,2), labels=c("group1","group2"))) # Welch t-test independentSamplesTTest( rt ~ cond, df ) # Student t-test independentSamplesTTest( rt ~ cond, df, var.equal=TRUE ) # one sided test independentSamplesTTest( rt ~ cond, df, one.sided="group1" ) # missing data df$rt <- NA df$cond <- NA independentSamplesTTest( rt ~ cond, df )