tpairs: calculate pairwise t-tests

Description Usage Arguments Details Value Note Author(s) See Also Examples

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

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

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. You can also specify "CHECK" and the function check if using paired t-tests or not (see the details)

...

Arguments passed to t.test.

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.

Value

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

Note

The means for the combinations of the variables taken into account are computed internally by tpairs, according to the specification in vars, dep, wid. The function is not able to deal with mixed within and between t-tests. Please, perform the two kinds of t-tests separately and take into consideration if the variables specified in vars are mixed (both within and between). If paired = "CHECK" is specified, than the functions will check if all wid are duplicated. If they are, data are sorted and paired t-tests are performed. If not, between t-tests are performed. This option is useful if all contrasts include both paired and unpaired comparisons.

Author(s)

Giorgio Arcara

See Also

t.test, p.adjust

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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)	

erpR documentation built on June 7, 2019, 3 a.m.