independentSamplesTTest: Independent samples t-test

Description Usage Arguments Details Value See Also Examples

View source: R/independentSamplesTTest.R

Description

Convenience function that runs an independent samples t-test. This is a wrapper function intended to be used for pedagogical purposes only.

Usage

1
2
3
4
5
6
7
independentSamplesTTest(
  formula,
  data = NULL,
  var.equal = FALSE,
  one.sided = FALSE,
  conf.level = 0.95
)

Arguments

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 = FALSE).

one.sided

One sided or two sided hypothesis test (default = FALSE)

conf.level

The confidence level for the confidence interval (default = .95).

Details

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".

Value

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)

See Also

t.test, oneSampleTTest, pairedSamplesTTest, cohensD

Examples

 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 )

lsr documentation built on Dec. 11, 2021, 9:10 a.m.