lsr (version 0.5)

independentSamplesTTest: Independent samples t-test

Description

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

Usage

independentSamplesTTest( 
	formula, data=NULL, var.equal=FALSE, 
	one.sided=FALSE, conf.level=.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).

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)

Warning

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.

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

See Also

t.test, oneSampleTTest, pairedSamplesTTest, cohensD

Examples

Run this code
# NOT RUN {
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 )

# }

Run the code above in your browser using DataCamp Workspace