Description Usage Arguments Details Value See Also Examples
View source: R/independentSamplesTTest.R
Convenience function that runs an independent samples t-test. This is a wrapper function intended to be used for pedagogical purposes only.
1 2 3 4 5 6 7 |
formula |
Formula specifying the outcome and the groups (required). |
data |
Optional data frame containing the variables. |
var.equal |
Should the test assume equal variances (default = |
one.sided |
One sided or two sided hypothesis test (default = |
conf.level |
The confidence level for the confidence interval (default = .95). |
The 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 t.test
and 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"
.
An object of class 'TTest'. When printed, the output is organised into five short sections. The first section lists the name of the test and the variables included. The second provides means and standard deviations. The third states explicitly what the null and alternative hypotheses were. The fourth contains the test results: t-statistic, degrees of freedom and p-value. The final section includes the relevant confidence interval and an estimate of the effect size (i.e., Cohen's d)
t.test
,
oneSampleTTest
,
pairedSamplesTTest
,
cohensD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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[1] <- NA
df$cond[7] <- NA
independentSamplesTTest( rt ~ cond, df )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.