contrastmeans: Linear Contrast Tests for a Linear Model

View source: R/contrastmeans.R

contrastmeansR Documentation

Linear Contrast Tests for a Linear Model

Description

Performs t-tests (or permuted t-tests) of specified contrasts for linear models obtained from functions aov, lm, glm, gls, lme, or lmer.

Usage

  contrastmeans(model, modelterm, ctrmatrix, ctrnames=NULL, adj="none", Df, permlist)

Arguments

model

Model object returned by aov, lm, glm, gls, lme, and lmer.

modelterm

Name (in "quotes") for indicating which factor term's contrast to be calculated. The modelterm must be given exactly as it appears in the printed model, e.g. "A" or "A:B".

ctrmatrix

A specified contrast matrix. If ctrmatrix is missing, the programe will ask user to enter it.

ctrnames

Names of the specified contrasts, e.g. c("A vs D", "C vs B", ...)

adj

Name (in "quote") for indicating a method for adjusting p-values of pairwise comparisons. The choices are "none", "tukey", "holm", "hochberg", "hommel", "bonferroni", "BH", "BY" and "fdr". The default method is "none".

Df

A denominator degree of freedom for modelterm. (For glmer models the Df needs to be specified, while for the other models, Df is obtained from the fitted model automatically).

permlist

A model parameter list containing nsim parameters produced by the function permmodels. When permlist != NULL, the option Df will be non-functional. This is a key option for the permutation test.

Value

There are two components in the output which are

Table

A table showing t-test results for the specified linear contrasts.

K

A contrast matrix.

Author(s)

Dongwen Luo, Siva Ganesh and John Koolaard

References

Torsten Hothorn, Frank Bretz and Peter Westfall (2008), Simultaneous Inference in General Parametric Models. Biometrical, Journal 50(3), 346–363.

Examples

library(predictmeans)
# ftable(xtabs(yield ~ Block+Variety+nitro, data=Oats))
Oats$nitro <- factor(Oats$nitro)
fm <- lme(yield ~ nitro*Variety, random=~1|Block/Variety, data=Oats)
# library(lme4)
# fm <- lmer(yield ~ nitro*Variety+(1|Block/Variety), data=Oats)

## Not run: 
## The contrast has a contrast matrix as follows:
#     0:Golden Rain 0:Marvellous 0:Victory 
#[1,]            -1            0         1 
#[2,]             0            0         1 
#     0.2:Golden Rain 0.2:Marvellous 0.2:Victory 
#[1,]               0              0           0 
#[2,]               0              0           0 
#     0.4:Golden Rain  0.4:Marvellous 0.4:Victory
#[1,]               0               0           0
#[2,]               0              -1           0
#      0.6:Golden Rain 0.6:Marvellous 0.6:Victory
#[1,]                0              0           0
#[2,]                0              0           0

# 1. Enter above contrast matrix into a pop up window, then close the window
# contrastmeans(fm, "nitro:Variety")
 
# 2. Construct the contrast matrix directly
cm <- rbind(c(-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), 
            c(0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0))
contrastmeans(fm, "nitro:Variety", ctrmatrix=cm)

predictmeans documentation built on May 29, 2024, 9:49 a.m.