test.contr: t-test for a custom contrast

Description Usage Arguments Details Value Author(s) Examples

View source: R/functions.R

Description

Perform a t-test for custom contrast

Usage

1
test.contr(cont, d = NULL, n = NULL, scale = NULL, y = NULL, x = NULL)

Arguments

cont

contrast codes as a numeric vector with length=k

d

effect size index to test

n

group size required if d is provided (n per cell)

scale

scaling method used to compute d. Required if d is provided

y

numeric vector of the dependent variable

x

numeric vector of the independent variable with k-groups, with k being length(cont). It must be coercible to a factor

Details

The test can be performed either on raw data on a d coefficient. When d is provided, also the total sample size n and the scaling method scale should be provided.

The parameter scale controls the method used to scale the effect size d.

  1. scale="g" assumes scaling by dividing 2*d by the sum of absolute coefficients

  2. scale="z" assumes scaling by dividing d by the square-root of the sum of squares of the contrast weigths

  3. numeric any constant that multiplies the unscaled d to obtain the scaled d

Value

t-test for the contrast. The Estimate is the contrast value estimate from the data and the Std. Error is expressed in the same scale of the estimate. It is assumed that the cells have the same size.

Author(s)

Marcello Gallucci, mcfanda@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
cont<-c(-3,-1,1,3)
means<-c(10,12,10,12)
y<-rep(means,1000)+rnorm(4000,0,10)
x<-factor(rep(1:4,1000))

test.contr(cont=cont,y = y,x = x)

# check the contrast value
observed<-tapply(y,x,mean)
observed%*%cont

# check the t-test and p-value
contrasts(x)<-contr.custom(cont)
summary(lm(y~x))

mcfanda/cpower documentation built on May 28, 2019, 1 p.m.