testInteractions: Test Contrasts of Factor Interactions

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

View source: R/testInteractions.R

Description

Calculates and tests different types of contrasts for factor interactions, in linear, generalized and mixed linear models: simple main effects, interaction contrasts, residual effects, and others.

Usage

1
2
3
testInteractions(model, pairwise=NULL, fixed=NULL, residual=NULL, across=NULL,
  custom=NULL, slope=NULL, adjustment=NULL, label.factors=FALSE,
  abbrev.levels=FALSE, ...)

Arguments

model

fitted model. Currently supported classes include "lm", "glm", "mlm", "lme", and "mer" or "merMod" (excluding models fitted by nlmer).

pairwise

character vector with the names of factors represented by pairwise contrasts.

fixed

character vector with the names of factors represented by fixed levels.

residual

character vector with the names of factors represented by residuals effects.

across

character vector with the names of factors represented by a full set of independent contrasts.

custom

list with custom contrasts for other factors. See the Details for more information.

slope

character vector with the names of the covariates associated to the slope that will tested; if it is NULL (the default value), the function will test the adjusted mean values.

adjustment

adjustment method for p-values, as defined in p.adjust.

label.factors

If true, the rownames for each row in the resulting table include the name(s) of the factor(s) involved, followed by the level values. Otherwise, the rownames include only the levels of the factor(s), with multiple factors separated by ‘:’.

abbrev.levels

Either a logical or an integer, specifying whether the levels values of the factors in the term are to be abbreviated in constructing the rownames. An integer specifies the minimum length of the abbreviation for each factor in the term.

...

further arguments passed down to testFactors.

Details

Each factor of the model can at most be contained in one of the arguments pairwise, fixed, residual, across, or custom; redundant assignment of factors is not allowed. If none of these arguments is defined, the default behavior is as if pairwise contained all the factors of the model. The result will show a set of tests on the model adjusted mean, at different combinations of factor levels. If there are covariates defined in slope, the test will apply to the slope for the interaction of such covariates. Each row will contain a different combination of factor levels or contrasts, depending on the argument wherein the factor has been defined:

Ommitted factors will be averaged across all their levels. Thus, to test the overall adjusted means or slopes, use pairwise=NULL (or do the same with any of the arguments of the previous list).

Other combinations of factor levels can be defined by custom. This argument should be a list of numeric matrices or vectors, named as the model factors. Each matrix must have as many rows as the number of levels of the corresponding factor, so that each column represents a linear combination of such levels that will be tested, crossed with the combinations of the other factors. Vectors will be treated as column matrices.

In multivariate linear models it is possible to define an intra-subjects design, with the argument idata passed down to testFactors (see Anova or linearHypothesis in package car for further details). The factors defined by that argument can be included as any other factor of the model.

Value

An anova table with one row for each different combination of levels and contrasts defined in pairwise, fixed, across, and custom. The rownames represent the specific levels or contrasts used for the different factors, separated by ‘:’. These names can be tweaked by the arguments label.factors and abbrev.levels, as done by termMeans in package heplots.

Note

The tests of mixed models are done under the assumption that the estimation of the random part of the model is exact.

Author(s)

Helios De Rosario-Martinez, helios.derosario@gmail.com

See Also

testFactors, interactionMeans. Use contrastCoefficients as a facility to create matrices of custom contrasts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Tests of the interactions described in Boik (1979)
# See ?Boik for a description of the data set

mod.boik <- lm(edr ~ therapy * medication, data=Boik)
Anova(mod.boik)
cntrl.vs.T1 <- list(therapy = c(1, -1, 0))
cntrl.vs.T2 <- list(therapy = c(1, 0, -1))
plcb.vs.doses <- list(medication = c(1, -1/3, -1/3, -1/3))
testInteractions(mod.boik, pairwise="therapy", adjustment="none")
testInteractions(mod.boik, custom=plcb.vs.doses, adjustment="none")
testInteractions(mod.boik, custom=cntrl.vs.T1, across="medication", adjustment="none")
testInteractions(mod.boik, custom=c(cntrl.vs.T1, plcb.vs.doses), adjustment="none")
testInteractions(mod.boik, custom=cntrl.vs.T2, across="medication", adjustment="none")
testInteractions(mod.boik, custom=plcb.vs.doses, across="therapy", adjustment="none")

Example output

Loading required package: car
Anova Table (Type II tests)

Response: edr
                   Sum Sq Df F value    Pr(>F)    
therapy            2444.1  2  63.813 1.399e-15 ***
medication         2370.9  3  41.269 1.342e-14 ***
therapy:medication 1376.4  6  11.979 8.539e-09 ***
Residuals          1149.0 60                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
             Value Df Sum of Sq       F    Pr(>F)    
control-T1 13.9997  1   2351.89 122.813 3.788e-16 ***
control-T2  9.4002  1   1060.35  55.370 4.414e-10 ***
     T1-T2 -4.5995  1    253.87  13.257 0.0005675 ***
Residuals          60   1149.01                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
             Value Df Sum of Sq      F    Pr(>F)    
medication1 11.333  1      1734 90.546 1.353e-13 ***
Residuals          60      1149                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
          medication1 medication2 medication3 Df Sum of Sq      F    Pr(>F)    
therapy1      -28.599     -19.602     -11.401  3    1332.1 23.187 4.341e-10 ***
Residuals                                     60    1149.0                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
                         Value Df Sum of Sq      F    Pr(>F)    
therapy1 : medication1 -18.265  1    750.64 39.197 4.488e-08 ***
Residuals                      60   1149.01                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
          medication1 medication2 medication3 Df Sum of Sq      F  Pr(>F)  
therapy1      -10.699     -6.8005     -5.7007  3    175.95 3.0627 0.03481 *
Residuals                                     60   1149.01                 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
F Test: 
P-value adjustment method: none
            therapy1 therapy2 Df Sum of Sq      F    Pr(>F)    
medication1   -6.532   11.733  2    770.93 20.128 2.047e-07 ***
Residuals                     60   1149.01                     
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

phia documentation built on May 2, 2019, 8:23 a.m.