opm_mcp {opm} | R Documentation |
This function provides linear-hypothesis testing and multiple comparisons for group means of curve parameters based on the multcomp package.
## S4 method for signature 'MOPMX' opm_mcp(object, model, linfct = 1L, m.type = "glm", rhs = 0, alternative = "two.sided", glht.args = list(), ops = "+", output = "mcp", sep = opm_opt("comb.value.join"), ...) ## S4 method for signature 'OPMS' opm_mcp(object, model, linfct = 1L, m.type = "glm", rhs = 0, alternative = "two.sided", glht.args = list(), ops = "+", output = "mcp", sep = opm_opt("comb.value.join"), ...) ## S4 method for signature 'data.frame' opm_mcp(object, model, linfct = 1L, m.type = c("glm", "lm", "aov"), rhs = 0, alternative = "two.sided", glht.args = list(), ops = "+", output = c("mcp", "data", "model", "linfct", "contrast"), sep = opm_opt("comb.value.join"), split.at = param_names("split.at"))
object |
Either an |
model |
A model formula, or a character vector or a
list containing the names of factors to be included in
the model for fitting. In order to join two or more
metadata-variables into one factor use pseudo-function
If If the |
linfct |
A specification of the linear hypotheses to
be tested analogously to
After the conversions, if any, this argument is passed
to If the |
m.type |
Character scalar indicating which of the following model types to use in model fitting: glm, aov or lm. See the eponymous functions in the stats package for details. |
rhs |
Numeric vector passed to |
alternative |
Character scalar also passed to that
function (but only if |
glht.args |
List of additional arguments for the
multiple comparison procedure passed to |
ops |
Character vector. |
output |
Character scalar determining the main output mode. See below under ‘Value’. |
split.at |
Character vector. See
|
sep |
Character scalar (comprising a single
character) passed to |
... |
Optional arguments passed to
|
This function internally reshapes the data in
object
into a ‘flat’ data frame the
structure of which is described under ‘value’. In
the default output
mode, glht
from the
multcomp package is applied to this data frame.
This causes (general linear) models and, by indicating a
contrast type, user-defined simultaneous multiple testing
procedures to be inferred.
Since either the user or this function itself makes use
of mcp
, we refer to the ‘Details’ section
of the glht
function. The mcp
function must
be used with care when defining parameters of interest in
two-way ANOVA or ANCOVA models. The
definition of treatment differences might be
problem-specific. An automated determination of the
parameters of interest would be impossible and thus only
comparisons for the main effects (ignoring covariates and
interactions) would be generated and a warning issued.
The kind of object returned by this function are
determined by the output
argument:
The default. An object of class glht
as
the result of the multiple comparison of means. Methods
for print
, summary
, confint
,
coef
and vcov
are available for this class.
See glht
in the multcomp package for
details.
Reshaped (‘flattened’) data
frame of the class OPM_MCP_OUT
. It contains
one column for the measured values, one factorial
variable determining the well, one factorial variable for
the curve parameter (see param_names
) and
additional factorial variables selected by model
as factors. The column names are converted to syntactical
names. Such a data frame might be of use for
model-building approaches not covered by this function.
The model
argument after the
conversions conducted by opm_mcp
, if any.
The linfct
argument after the
conversions conducted by opm_mcp
, if any.
A list of contrast matrices as specified
by model
and linfct
. As these matrices
would be guaranteed to fit to object
, they could
serve as template matrices to be further specified by the
user. Note that this only works if linfct
either
is an object of class mcp
or convertible to such
an object, and if its values are character scalars that
can be passed as type
argument to contrMat
from the multcomp package.
Lea A.I. Vaas, Markus Goeker
multcomp::glht multcomp::contrMat stats::lm stats::formula
Other multcomp-functions: annotated
# helper function for plotting with better suitable margins
plot_with_margin <- function(x, mar, ...) {
old.mar <- par(mar = mar)
on.exit(par(old.mar)) # tidy up
plot(x, ...)
}
do.plot <- FALSE # change this to see the plots
## OPMS method
# return the intermediary data frame, do not conduct statistical tests
head(x <- opm_mcp(vaas_4, model = list("Species", "Strain"),
output = "data"))
## Species Strain Parameter Well
## 1 Escherichia coli DSM18039 A A01 (Negative Control)
## 2 Escherichia coli DSM30083T A A01 (Negative Control)
## 3 Pseudomonas aeruginosa DSM1707 A A01 (Negative Control)
## 4 Pseudomonas aeruginosa 429SC1 A A01 (Negative Control)
## 5 Escherichia coli DSM18039 A A02 (Dextrin)
## 6 Escherichia coli DSM30083T A A02 (Dextrin)
## Value
## 1 57.66618
## 2 123.45581
## 3 61.35526
## 4 55.74738
## 5 131.67996
## 6 248.18087
stopifnot(is.data.frame(x), dim(x) == c(384, 5))
# watch the converted 'model' argument
(x <- opm_mcp(vaas_4, model = list("Species", "Strain"),
output = "model"))
## Value ~ Species + Strain
## <environment: 0xbad0a48>
stopifnot(inherits(x, "formula")) # left side is set automatically
# watch the converted 'linfct' argument
(x <- opm_mcp(vaas_4, model = list("Species", "Strain"),
linfct = c(Dunnett = 1), output = "linfct"))
## $Species
## [1] "Dunnett"
##
## attr(,"interaction_average")
## [1] FALSE
## attr(,"covariate_average")
## [1] FALSE
## attr(,"class")
## [1] "mcp"
stopifnot(inherits(x, "mcp"))
# create a template contrast matrix
(x <- opm_mcp(vaas_4, model = list("Species", "Strain"),
linfct = c(Dunnett = 1), output = "contrast"))
## $Species
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
## Escherichia coli
## Pseudomonas aeruginosa - Escherichia coli -1
## Pseudomonas aeruginosa
## Pseudomonas aeruginosa - Escherichia coli 1
stopifnot(is.list(x), sapply(x, inherits, "contrMat"),
names(x) == "Species") # the selection is as specified by 'linfct'
# comparison using specified model comparing 'Species' pooled over
# complete plates
(x <- opm_mcp(vaas_4, model = list("Species"), m.type = "lm",
linfct = c(Dunnett = 1))) # refers to 'Species'
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
##
## Linear Hypotheses:
## Estimate
## Pseudomonas aeruginosa - Escherichia coli == 0 -23.34
stopifnot(inherits(x, "glht"), length(coef(x)) == 1)
if (do.plot)
plot_with_margin(x, c(3, 20, 3, 2), main = "Species")
# comparison of only A01 - A04 against each other, Tukey style
# note that the left side of the model is set automatically
(x <- opm_mcp(vaas_4[, , 1:4],
model = ~ Well + Species, m.type = "lm",
linfct = c(Tukey = 1))) # the number refers to 'Well'
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Tukey Contrasts
##
##
## Linear Hypotheses:
## Estimate
## A02 (Dextrin) - A01 (Negative Control) == 0 55.697
## A03 (D-Maltose) - A01 (Negative Control) == 0 25.084
## A04 (D-Trehalose) - A01 (Negative Control) == 0 32.960
## A03 (D-Maltose) - A02 (Dextrin) == 0 -30.614
## A04 (D-Trehalose) - A02 (Dextrin) == 0 -22.737
## A04 (D-Trehalose) - A03 (D-Maltose) == 0 7.876
stopifnot(inherits(x, "glht"), length(coef(x)) == 6)
if (do.plot)
plot_with_margin(x, c(3, 18, 3, 2), main = "Tukey, A01 - A04")
# Dunnett-type comparison of selected wells
(x <- opm_mcp(vaas_4[, , 1:4], model = ~ Well,
m.type = "lm", linfct = c(Dunnett = 1)))
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
##
## Linear Hypotheses:
## Estimate
## A02 (Dextrin) - A01 (Negative Control) == 0 55.70
## A03 (D-Maltose) - A01 (Negative Control) == 0 25.08
## A04 (D-Trehalose) - A01 (Negative Control) == 0 32.96
stopifnot(inherits(x, "glht"), length(coef(x)) == 3)
if (do.plot)
plot_with_margin(x, c(3, 20, 3, 2), main = "Dunnett, A01 vs. A02 - A04")
# by default 'Dunnett' uses first level as reference
# Dunnett-type comparison with selected control-group
(x <- opm_mcp(vaas_4[, , 1:5], output = "mcp", model = ~ Well,
linfct = c(`Dunnett.A05 (D-Cellobiose)` = 1)))
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: User-defined Contrasts
##
##
## Linear Hypotheses:
## Estimate
## A01 (Negative Control) - A05 (D-Cellobiose) == 0 1.577
## A02 (Dextrin) - A05 (D-Cellobiose) == 0 57.275
## A03 (D-Maltose) - A05 (D-Cellobiose) == 0 26.661
## A04 (D-Trehalose) - A05 (D-Cellobiose) == 0 34.537
if (do.plot)
plot_with_margin(x, c(3, 20, 3, 2), main = "Dunnett, vs. A05")
# manually defined contrast matrix
(contr <- opm_mcp(vaas_4[, , 1:4], linfct = c(Tukey = 1),
model = ~ Well, output = "contrast")) # create template, Tukey style
## $Well
##
## Multiple Comparisons of Means: Tukey Contrasts
##
## A01 (Negative Control)
## A02 (Dextrin) - A01 (Negative Control) -1
## A03 (D-Maltose) - A01 (Negative Control) -1
## A04 (D-Trehalose) - A01 (Negative Control) -1
## A03 (D-Maltose) - A02 (Dextrin) 0
## A04 (D-Trehalose) - A02 (Dextrin) 0
## A04 (D-Trehalose) - A03 (D-Maltose) 0
## A02 (Dextrin) A03 (D-Maltose)
## A02 (Dextrin) - A01 (Negative Control) 1 0
## A03 (D-Maltose) - A01 (Negative Control) 0 1
## A04 (D-Trehalose) - A01 (Negative Control) 0 0
## A03 (D-Maltose) - A02 (Dextrin) -1 1
## A04 (D-Trehalose) - A02 (Dextrin) -1 0
## A04 (D-Trehalose) - A03 (D-Maltose) 0 -1
## A04 (D-Trehalose)
## A02 (Dextrin) - A01 (Negative Control) 0
## A03 (D-Maltose) - A01 (Negative Control) 0
## A04 (D-Trehalose) - A01 (Negative Control) 1
## A03 (D-Maltose) - A02 (Dextrin) 0
## A04 (D-Trehalose) - A02 (Dextrin) 1
## A04 (D-Trehalose) - A03 (D-Maltose) 1
contr <- contr$Well[c(1:3, 6), ] # select comparisons of interest
(x <- opm_mcp(vaas_4[, , 1:4],
model = ~ Well, m.type = "lm", linfct = contr)) # run tests
##
## General Linear Hypotheses
##
## Linear Hypotheses:
## Estimate
## A02 (Dextrin) - A01 (Negative Control) == 0 -18.859
## A03 (D-Maltose) - A01 (Negative Control) == 0 -49.472
## A04 (D-Trehalose) - A01 (Negative Control) == 0 -41.596
## A04 (D-Trehalose) - A03 (D-Maltose) == 0 7.876
if (do.plot)
plot_with_margin(x, c(3, 20, 3, 2), main = "My own contrasts")
# joining of selected metadata using pseudofunction J
(x <- opm_mcp(vaas_4[, , 1:4], model = ~ J(Well + Species),
linfct = c(Dunnett = 1), full = FALSE)) # use short well names
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
##
## Linear Hypotheses:
## Estimate
## A01/Pseudomonas aeruginosa - A01/Escherichia coli == 0 -32.01
## A02/Escherichia coli - A01/Escherichia coli == 0 99.37
## A02/Pseudomonas aeruginosa - A01/Escherichia coli == 0 -19.98
## A03/Escherichia coli - A01/Escherichia coli == 0 72.72
## A03/Pseudomonas aeruginosa - A01/Escherichia coli == 0 -54.56
## A04/Escherichia coli - A01/Escherichia coli == 0 69.62
## A04/Pseudomonas aeruginosa - A01/Escherichia coli == 0 -35.71
if (do.plot)
plot_with_margin(x, c(3, 22, 3, 2), main = "Dunnett, Well/Species joined")
# comparing wells pairwise regarding the tested species
(x <- opm_mcp(vaas_4[, , 1:4], model = ~ J(Well + Species),
linfct = c(Pairs.Well = 1), full = FALSE)) # use short well names
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: User-defined Contrasts
##
##
## Linear Hypotheses:
## Estimate
## `A01/Pseudomonas aeruginosa` - `A01/Escherichia coli` == 0 -32.01
## `A02/Pseudomonas aeruginosa` - `A02/Escherichia coli` == 0 -119.35
## `A03/Pseudomonas aeruginosa` - `A03/Escherichia coli` == 0 -127.28
## `A04/Pseudomonas aeruginosa` - `A04/Escherichia coli` == 0 -105.34
if (do.plot)
plot_with_margin(x, c(3, 22, 3, 2),
main = "Wells compared between species")
# i.e. 'Pairs.Well' means 'Pairs' type of comparison for each 'Well'
# separately within a joined factor (the first one in 'model', hence
# 'c(Pairs.Well = 1)', with '1' referring to the elements of 'model').
# pairwise comparison of Species regarding the tested strains
xx <- c(vaas_4, vaas_4) # temporary test data
(x <- opm_mcp(xx[, , 1:4], model = ~ J(Strain + Species),
linfct = c(Pairs.Species = 1), full = FALSE)) # use short well names
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: User-defined Contrasts
##
##
## Linear Hypotheses:
## Estimate
## `DSM30083T/Escherichia coli` - `DSM18039/Escherichia coli` == 0 160.768
## `429SC1/Pseudomonas aeruginosa` - `DSM1707/Pseudomonas aeruginosa` == 0 2.645
if (do.plot)
plot_with_margin(x, c(3, 22, 3, 2),
main = "Strains compared within species")
# i.e. 'Pairs.Species' means 'Pairs' type of comparison for each 'Species'
# separately within a joined factor (the first one in 'model', hence
# 'c(Pairs.Species = 1)', with '1' referring to the elements of 'model').
## one could check the number of calculated tests as follows:
#if (nrow(confint(result)$confint) > 20L)
# warning("number of performed comparisons exceeds 20")
## data-frame method (usually unnecessary to directly apply it)
x <- extract(vaas_4, as.labels = list("Species", "Strain"), subset = "A",
dataframe = TRUE)
# without the tests, returning the converted data frame
head(y <- opm_mcp(x, output = "data", model = list("Species", "Strain")))
## Species Strain Parameter Well
## 1 Escherichia coli DSM18039 A A01 (Negative Control)
## 2 Escherichia coli DSM30083T A A01 (Negative Control)
## 3 Pseudomonas aeruginosa DSM1707 A A01 (Negative Control)
## 4 Pseudomonas aeruginosa 429SC1 A A01 (Negative Control)
## 5 Escherichia coli DSM18039 A A02 (Dextrin)
## 6 Escherichia coli DSM30083T A A02 (Dextrin)
## Value
## 1 57.66618
## 2 123.45581
## 3 61.35526
## 4 55.74738
## 5 131.67996
## 6 248.18087
stopifnot(is.data.frame(y), dim(y) == c(384, 5)) # same result as above
# now with conducting the tests
(y <- opm_mcp(x, model = "Species", m.type = "lm",
linfct = c(Dunnett = 1)))
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
##
## Linear Hypotheses:
## Estimate
## Pseudomonas aeruginosa - Escherichia coli == 0 -23.34
stopifnot(inherits(y, "glht"), length(coef(y)) == 1)
if (do.plot)
plot_with_margin(y, c(3, 20, 3, 2), main = "Species (from data frame)")
# testing for subsets of object
(y <- opm_mcp(subset(x, x$Species == "Escherichia coli"),
linfct = c(Dunnett = 1), model = "Strain", m.type = "lm"))
##
## General Linear Hypotheses
##
## Multiple Comparisons of Means: Dunnett Contrasts
##
##
## Linear Hypotheses:
## Estimate
## DSM30083T - DSM18039 == 0 84.99
stopifnot(inherits(y, "glht"), length(coef(y)) == 1)
if (do.plot)
plot_with_margin(y, c(3, 15, 3, 2), main = "Dunnett (from data frame)")