cmiacov: Contrast matrices for treatments over a grid of covariate...

Description Usage Arguments Details Value Author(s) Examples

Description

Compute suitable contrast matrix for pairwise comparisons of treatment levels over grids of covariates given a fitted model object of class 'lm' or 'glm' Restricted to ONE factor variable and pairwise comparisons of treatments ("Dunnett", "Tukey", or user defined subsets of Tukey-type comparisons). More than one covariate, quadratic terms etc. are possible

Usage

1
cmiacov(modelfit, treatment, treatcon = "Dunnett", covset, ...)

Arguments

modelfit

a fitted model of class "lm" or "glm", right hand side of the model formula should contain one factor variable, and one (or several) covariate(s), etc.

treatment

a single character string, identifying the factor variable in the model

treatcon

either a matrix with integer entries, or a single character string. If a matrix: number of columns must be = number of treatment levels in the factor variable rows specifies contrasts between treatments: only coefficients 1,0,-1 are allowed, all contrasts must define pairwise treatment differences: if a character string: "Dunnett" or "Tukey", will be passed to the type-argument in contrMat (package multcomp)

covset

a named list with numeric vectors: names of list elements must be the names of the covariates in the model, vector in each element is supposed to contain the covariate values at which contrasts sould be computed

...

further arguments to be passed to internal functions, currently only: base a single integer indicating the control level, if treatcon is a character string, passed to contrMat digits a single integer, defining the number of visible non-zero digits when rounding covariate values in contrast names

Details

Based on the call and data set in the model object, matrices are contructed that allow to compute predictions over the grid of covariate values specified in covset and the factor variable specified in treatment. These matrices are then combined to define pairwise differences between the levels in treatment, over the grid of covariate values. The pairwise differences can be defined in the argument treatcon.

Value

A list with items

linfct

a matrix of linear combinations of the model parameters, for plugging into the linfct-argument of glht, package multcomp

datadiff

a data set with names for the differences between treatment levels, the treatment levels contributing as minuend and subtrahend of the differences, and the covariate(s); rows of the data set are ordered as are the rows in the matrix linfct

Xpos

model matrix for those predictions used as minuend to compute linfct

Xneg

model matrix for those predictions used as subtrahend to compute linfct

datapos
dataneg

Author(s)

Frank Schaarschmidt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Data set simulated acc. to Milliken and Johnson (2002), see ?pc for details

data(pc)

# A model including treatment interaction with the quadratic term

fitpc<-lm(yield ~ x + I(x^2) + additive + additive:I(x^2), data=pc)

cmpc <- cmiacov(fitpc, treatment="additive", 
 covset=list("x" = seq(from=1, to=9, by=1)), treatcon="Dunnett")
str(cmpc)


# treatment interaction with the linear term

fitpclin<-lm(yield ~ x + I(x^2) + additive + additive:x, data=pc)

cmpclin <- cmiacov(fitpc, treatment="additive",
 covset=list("x" = seq(from=1, to=9, by=1)), treatcon="Dunnett")
str(cmpclin)


# daphnids data from package drc
# no: counted no. of immobile daphnids
# mob: corresponding no. mobile daphnids

if(require("drc")){

data(daphnids, package="drc")

daphnids$mob <- daphnids$total - daphnids$no
daphnids$l10dose <- log10(daphnids$dose)

ggplot(daphnids, aes(y=no/total, x=l10dose)) + geom_point(aes(color=time))

fitda <- glm(cbind(no, mob) ~ time * l10dose, data=daphnids, family=quasibinomial())
anova(fitda, test="F")

cmda <- cmiacov(fitda, treatment="time", 
covset=list("l10dose" = seq(from=2, to=4, by=0.5)), treatcon="Dunnett")
str(cmda, max.level=1)
cmda$linfct

confint(glht(fitda, linfct=cmda$linfct))

}

schaarschmidt/statintcov documentation built on May 29, 2019, 3:26 p.m.