Learn R Programming

erpR (version 0.2.0)

tpairs: calculate pairwise t-tests

Description

An utility function to perform a series of t-tests on several combinations of levels of one or more variables. P-value correction methods can be specified.

Usage

tpairs(dat, vars, contr, dep, wid, p.adjust.methods = "none", paired = FALSE, ...)

Arguments

dat
a data.frame including all variables for the t-test computation.
vars
a vector of characters indicating the names of the independent variables to be considered for the t-tests. If length vars > 1, a new variable will be created by combining the levels of the variables specified in vars.
contr
a list specifying the t-test to be performed. If "all" is specified, t-tests on all possible combinations are performed. See Details for further specification information.
dep
a string specifying the name of the dependent variable (a column in dat).
wid
optional: a string specifying the variable that encodes the repeated measure identifier.
p.adjust.methods
p-value correction methods as in p.adjust.
paired
logical. If TRUE, paired t-tests are performed.
...
Arguments passed to t.test.

Value

A data.frame with the results of the t-tests specified.

Details

The contr argument allows to specify a subset of combinations of levels of the variables listed in vars to be performed. The contrasts have to be specified as a list of lists. Each list within the main list contains two vectors with strings. The strings specify the levels of the variables in vars that have to be compared. The convention is to specify the levels separated by an underscore. For example suppose that vars=c("height", "color"), and contr=list(list(c("high_red"), c("low_red")), list(c("high_green", "low_green"))) will perform two t-tests. The first t-test it will compare the mean for height=="high" and color=="red" with the mean of height=="low", and color=="red". The second t-test will compare the mean of height=="high", and color=="green" with the mean of height=="low" and color=="green". If a p-value correction method is specified, only p-values of the t-test carried out will be taken into account.

See Also

t.test, p.adjust

Examples

Run this code

# simulate some subjects
subjRT=rnorm(20, 500, 100)

#simulate the effects of three experimental conditions for each subject
condA=rnorm(20, 50, 10)
condB=rnorm(20, -40, 10)
condC=rnorm(20, 20, 10)

#create a data frame
dat=data.frame(Subject=rep(1:20,3), 
condition=c(rep("A", 20), rep("B", 20), rep("C", 20)), 
RT=c(subjRT+condA, subjRT+condB, subjRT+condC ))

#perform pairwise t.test
tpairs(dat, "condition", "all", "RT", "Subject", var.equal=TRUE)	


Run the code above in your browser using DataLab