Title: | Analyze Nominal Response Data with the Multinomial-Poisson Trick |
---|---|
Description: | Dichotomous responses having two categories can be analyzed with stats::glm() or lme4::glmer() using the family=binomial option. Unfortunately, polytomous responses with three or more unordered categories cannot be analyzed similarly because there is no analogous family=multinomial option. For between-subjects data, nnet::multinom() can address this need, but it cannot handle random factors and therefore cannot handle repeated measures. To address this gap, we transform nominal response data into counts for each categorical alternative. These counts are then analyzed using (mixed) Poisson regression as per Baker (1994) <doi:10.2307/2348134>. Omnibus analyses of variance can be run along with post hoc pairwise comparisons. For users wishing to analyze nominal responses from surveys or experiments, the functions in this package essentially act as though stats::glm() or lme4::glmer() had a family=multinomial option. |
Authors: | Jacob O. Wobbrock [aut, cre, cph] |
Maintainer: | Jacob O. Wobbrock <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.0 |
Built: | 2024-11-21 05:52:32 UTC |
Source: | https://github.com/wobbrock/multpois |
Get ANOVA-style results for a model returned by glm.mp
or glmer.mp
.
The output table contains chi-square results for the main effects and interactions indicated by
the given model.
Anova.mp(model, type = c(3, 2, 1, "III", "II", "I"))
Anova.mp(model, type = c(3, 2, 1, "III", "II", "I"))
model |
A model built by |
type |
In the case of a type II or type III ANOVA, this value will be the |
For type II or III ANOVAs, the Anova.mp
function uses Anova
behind the scenes to
produce an ANOVA-style table with chi-square results. For type I ANOVAs, it uses
anova.glm
or anova.merMod
.
Users wishing to verify the correctness of these results can compare Anova
results
for dichotomous response models built with glm
or glmer
(using
family=binomial
) to Anova.mp
results for models built with glm.mp
or
glmer.mp
, respectively. The results should generally match, or be very similar.
Users can also compare Anova
results for polytomous response models built with
multinom
to Anova.mp
results for models built with glm.mp
.
Again, the results should generally match, or be very similar.
There is no similarly easy comparison for polytomous response models with repeated measures. The
lack of options was a key motivation for developing glmer.mp
in the first place.
An ANOVA-style table of chi-square results for models built by glm.mp
or
glmer.mp
. See the return values for Anova
, anova.glm
,
or anova.merMod
.
Jacob O. Wobbrock
Baker, S.G. (1994). The multinomial-Poisson transformation. The Statistician 43 (4), pp. 495-504. doi:10.2307/2348134
Chen, Z. and Kuo, L. (2001). A note on the estimation of the multinomial logit model with random effects. The American Statistician 55 (2), pp. 89-95. https://www.jstor.org/stable/2685993
Guimaraes, P. (2004). Understanding the multinomial-Poisson transformation. The Stata Journal 4 (3), pp. 265-273. https://www.stata-journal.com/article.html?article=st0069
Lee, J.Y.L., Green, P.J.,and Ryan, L.M. (2017). On the “Poisson trick” and its extensions for fitting multinomial regression models. arXiv preprint available at doi:10.48550/arXiv.1707.08538
glm.mp()
, glm.mp.con()
, glmer.mp()
, glmer.mp.con()
, car::Anova()
## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m1 = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m1, type=3) ## within-subjects factors (X1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m2, type=3)
## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m1 = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m1, type=3) ## within-subjects factors (X1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m2, type=3)
This generic synthetic dataset has a dichotomous response Y
and two factors
X1
and X2
. The response has categories {yes,no}
.
Factor X1
has levels {a,b}
, and factor X2
has levels
{c,d}
. It also has a PId
column for participant identifier.
Each participant is on only one row.
A data frame with 60 observations on the following 4 variables:
a subject identifier with levels "1"
... "40"
a between-subjects factor with levels "a"
, "b"
a between-subjects factor with levels "c"
, "d"
a dichotomous response with categories "yes"
, "no"
See glm.mp
and glm.mp.con
for complete examples.
data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m = glm.mp(Y ~ X1*X2, data=bs2) Anova.mp(m, type=3) glm.mp.con(m, pairwise ~ X1*X2, adjust="holm")
data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m = glm.mp(Y ~ X1*X2, data=bs2) Anova.mp(m, type=3) glm.mp.con(m, pairwise ~ X1*X2, adjust="holm")
This generic synthetic dataset has a polytomous response Y
and two factors
X1
and X2
. The response has categories {yes,no,maybe}
.
Factor X1
has levels {a,b}
, and factor X2
has levels
{c,d}
. It also has a PId
column for participant identifier.
Each participant is on only one row.
A data frame with 60 observations on the following 4 variables:
a subject identifier with levels "1"
... "60"
a between-subjects factor with levels "a"
, "b"
a between-subjects factor with levels "c"
, "d"
a polytomous response with categories "yes"
, "no"
, and "maybe"
See glm.mp
and glm.mp.con
for complete examples.
data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m, type=3) glm.mp.con(m, pairwise ~ X1*X2, adjust="holm")
data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m, type=3) glm.mp.con(m, pairwise ~ X1*X2, adjust="holm")
This function uses the multinomial-Poisson trick to analyze nominal response data using a Poisson generalized linear model (GLM). The nominal response should be a factor with two or more unordered categories. The independent variables should be between-subjects factors and/or numeric predictors.
glm.mp(formula, data, ...)
glm.mp(formula, data, ...)
formula |
A formula object in the style of, e.g., |
data |
A data frame in long-format. See the |
... |
Additional arguments to be passed to |
This function should be used for nominal response data with only between-subjects factors or predictors.
In essence, it provides for the equivalent of glm
with family=multinomial
,
were that option to exist. (That option does not exist, but multinom
serves the same
purpose.)
For data with repeated measures, use glmer.mp
, which can take random factors and thus handle
correlated responses.
Users wishing to verify the correctness of glm.mp
should compare its Anova.mp
results
to Anova
results for models built with glm
using
family=binomial
(for dichotomous responses) or multinom
(for polytomous
responses). The results should generally match, or be very similar.
A Poisson regression model of type glm
. See the return value for
glm
.
Jacob O. Wobbrock
Baker, S.G. (1994). The multinomial-Poisson transformation. The Statistician 43 (4), pp. 495-504. doi:10.2307/2348134
Guimaraes, P. (2004). Understanding the multinomial-Poisson transformation. The Stata Journal 4 (3), pp. 265-273. https://www.stata-journal.com/article.html?article=st0069
Lee, J.Y.L., Green, P.J.,and Ryan, L.M. (2017). On the “Poisson trick” and its extensions for fitting multinomial regression models. arXiv preprint available at doi:10.48550/arXiv.1707.08538
Anova.mp()
, glm.mp.con()
, glmer.mp()
, glmer.mp.con()
, stats::glm()
, nnet::multinom()
library(car) library(nnet) ## between-subjects factors (X1,X2) with dichotomous response (Y) data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m1 = glm(Y ~ X1*X2, data=bs2, family=binomial) Anova(m1, type=3) m2 = glm.mp(Y ~ X1*X2, data=bs2) # compare Anova.mp(m2, type=3) ## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m3 = multinom(Y ~ X1*X2, data=bs3, trace=FALSE) Anova(m3, type=3) m4 = glm.mp(Y ~ X1*X2, data=bs3) # compare Anova.mp(m4, type=3)
library(car) library(nnet) ## between-subjects factors (X1,X2) with dichotomous response (Y) data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m1 = glm(Y ~ X1*X2, data=bs2, family=binomial) Anova(m1, type=3) m2 = glm.mp(Y ~ X1*X2, data=bs2) # compare Anova.mp(m2, type=3) ## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m3 = multinom(Y ~ X1*X2, data=bs3, trace=FALSE) Anova(m3, type=3) m4 = glm.mp(Y ~ X1*X2, data=bs3) # compare Anova.mp(m4, type=3)
This function conducts post hoc pairwise comparisons on generalized linear models (GLMs) built
with glm.mp
. Such models have nominal response types, i.e., factor
s with
unordered categories.
glm.mp.con( model, formula, adjust = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"), ... )
glm.mp.con( model, formula, adjust = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"), ... )
model |
A multinomial-Poisson generalized linear model created by |
formula |
A formula object in the style of, e.g., |
adjust |
A string indicating the p-value adjustment to use. Defaults to |
... |
Additional arguments to be passed to |
Post hoc pairwise comparisons should be conducted only after a statistically significant
omnibus test using Anova.mp
. Comparisons are conducted in the style of
emmeans
but not using this function; rather, the multinomial-Poisson trick is used
on a subset of the data relevant to each pairwise comparison.
Users wishing to verify the correctness of glm.mp.con
should compare its results to
emmeans
results for models built with glm
using
family=binomial
for dichotomous responses. The results should be similar.
Pairwise comparisons for all levels indicated by the factors in formula
.
Jacob O. Wobbrock
Baker, S.G. (1994). The multinomial-Poisson transformation. The Statistician 43 (4), pp. 495-504. doi:10.2307/2348134
Guimaraes, P. (2004). Understanding the multinomial-Poisson transformation. The Stata Journal 4 (3), pp. 265-273. https://www.stata-journal.com/article.html?article=st0069
Lee, J.Y.L., Green, P.J.,and Ryan, L.M. (2017). On the “Poisson trick” and its extensions for fitting multinomial regression models. arXiv preprint available at doi:10.48550/arXiv.1707.08538
Anova.mp()
, glm.mp()
, glmer.mp()
, glmer.mp.con()
, emmeans::emmeans()
library(car) library(nnet) library(emmeans) ## between-subjects factors (X1,X2) with dichotomous response (Y) data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m1 = glm(Y ~ X1*X2, data=bs2, family=binomial) Anova(m1, type=3) emmeans(m1, pairwise ~ X1*X2, adjust="holm") m2 = glm.mp(Y ~ X1*X2, data=bs2) Anova.mp(m2, type=3) glm.mp.con(m2, pairwise ~ X1*X2, adjust="holm") # compare ## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m3 = multinom(Y ~ X1*X2, data=bs3, trace=FALSE) Anova(m3, type=3) e0 = emmeans(m3, ~ X1*X2 | Y, mode="latent") c0 = contrast(e0, method="pairwise", ref=1) test(c0, joint=TRUE, by="contrast") m4 = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m4, type=3) glm.mp.con(m4, pairwise ~ X1*X2, adjust="holm") # compare
library(car) library(nnet) library(emmeans) ## between-subjects factors (X1,X2) with dichotomous response (Y) data(bs2, package="multpois") bs2$PId = factor(bs2$PId) bs2$Y = factor(bs2$Y) bs2$X1 = factor(bs2$X1) bs2$X2 = factor(bs2$X2) contrasts(bs2$X1) <- "contr.sum" contrasts(bs2$X2) <- "contr.sum" m1 = glm(Y ~ X1*X2, data=bs2, family=binomial) Anova(m1, type=3) emmeans(m1, pairwise ~ X1*X2, adjust="holm") m2 = glm.mp(Y ~ X1*X2, data=bs2) Anova.mp(m2, type=3) glm.mp.con(m2, pairwise ~ X1*X2, adjust="holm") # compare ## between-subjects factors (X1,X2) with polytomous response (Y) data(bs3, package="multpois") bs3$PId = factor(bs3$PId) bs3$Y = factor(bs3$Y) bs3$X1 = factor(bs3$X1) bs3$X2 = factor(bs3$X2) contrasts(bs3$X1) <- "contr.sum" contrasts(bs3$X2) <- "contr.sum" m3 = multinom(Y ~ X1*X2, data=bs3, trace=FALSE) Anova(m3, type=3) e0 = emmeans(m3, ~ X1*X2 | Y, mode="latent") c0 = contrast(e0, method="pairwise", ref=1) test(c0, joint=TRUE, by="contrast") m4 = glm.mp(Y ~ X1*X2, data=bs3) Anova.mp(m4, type=3) glm.mp.con(m4, pairwise ~ X1*X2, adjust="holm") # compare
This function uses the multinomial-Poisson trick to analyze nominal response data using a Poisson generalized linear mixed model (GLMM). The nominal response should be a factor with two or more unordered categories. The independent variables should have at least one within-subjects factor or numeric predictor. There also must be a repeated subject identifier to be used as a random factor.
glmer.mp(formula, data, ...)
glmer.mp(formula, data, ...)
formula |
A formula object in the style of, e.g., |
data |
A data frame in long-format. See the |
... |
Additional arguments to be passed to |
This function should be used for nominal response data with repeated measures. In essence, it provides
for the equivalent of glmer
with family=multinomial
, were that option to
exist. (That option does not exist, which was a key motivation for developing this function.)
For polytomous response data with only between-subjects factors, use glm.mp
or
multinom
.
Users wishing to verify the correctness of glmer.mp
should compare its Anova.mp
results to Anova
results for models built with glmer
using
family=binomial
for dichotomous responses. The results should generally match, or be very similar.
A mixed-effects Poisson regression model of type merMod
, specifically
of subclass glmerMod
. See the return value for glmer
.
It is common to receive a boundary (singular) fit
message. This generally can be ignored
provided the test output looks sensible. Less commonly, the procedure can fail to converge, which
can happen when counts of one or more categories are very small or zero in some conditions. In such
cases, any results should be regarded with caution.
Jacob O. Wobbrock
Baker, S.G. (1994). The multinomial-Poisson transformation. The Statistician 43 (4), pp. 495-504. doi:10.2307/2348134
Chen, Z. and Kuo, L. (2001). A note on the estimation of the multinomial logit model with random effects. The American Statistician 55 (2), pp. 89-95. https://www.jstor.org/stable/2685993
Guimaraes, P. (2004). Understanding the multinomial-Poisson transformation. The Stata Journal 4 (3), pp. 265-273. https://www.stata-journal.com/article.html?article=st0069
Lee, J.Y.L., Green, P.J.,and Ryan, L.M. (2017). On the “Poisson trick” and its extensions for fitting multinomial regression models. arXiv preprint available at doi:10.48550/arXiv.1707.08538
Anova.mp()
, glmer.mp.con()
, glm.mp()
, glm.mp.con()
, lme4::glmer()
library(car) library(lme4) library(lmerTest) ## within-subjects factors (x1,X2) with dichotomous response (Y) data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m1 = glmer(Y ~ X1*X2 + (1|PId), data=ws2, family=binomial) Anova(m1, type=3) m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) # compare Anova.mp(m2, type=3) ## within-subjects factors (x1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m3 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m3, type=3)
library(car) library(lme4) library(lmerTest) ## within-subjects factors (x1,X2) with dichotomous response (Y) data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m1 = glmer(Y ~ X1*X2 + (1|PId), data=ws2, family=binomial) Anova(m1, type=3) m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) # compare Anova.mp(m2, type=3) ## within-subjects factors (x1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m3 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m3, type=3)
This function conducts post hoc pairwise comparisons on generalized linear mixed models (GLMMs)
built with glmer.mp
. Such models have nominal response types, i.e., factor
s
with unordered categories.
glmer.mp.con( model, formula, adjust = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"), ... )
glmer.mp.con( model, formula, adjust = c("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"), ... )
model |
A multinomial-Poisson generalized linear mixed model created by |
formula |
A formula object in the style of, e.g., |
adjust |
A string indicating the p-value adjustment to use. Defaults to |
... |
Additional arguments to be passed to |
Post hoc pairwise comparisons should be conducted only after a statistically significant
omnibus test using Anova.mp
. Comparisons are conducted in the style of
emmeans
but not using this function; rather, the multinomial-Poisson trick is used
on a subset of the data relevant to each pairwise comparison.
Users wishing to verify the correctness of glmer.mp.con
should compare its results to
emmeans
results for models built with glmer
using
family=binomial
for dichotomous responses. The results should be similar.
Pairwise comparisons for all levels indicated by the factors in formula
.
It is common to receive boundary (singular) fit
messages. These generally can be ignored
provided the test outputs look sensible. Less commonly, the procedures can fail to converge, which
can happen when counts of one or more categories are very small or zero in some conditions. In such
cases, any results should be regarded with caution.
Jacob O. Wobbrock
Baker, S.G. (1994). The multinomial-Poisson transformation. The Statistician 43 (4), pp. 495-504. doi:10.2307/2348134
Chen, Z. and Kuo, L. (2001). A note on the estimation of the multinomial logit model with random effects. The American Statistician 55 (2), pp. 89-95. https://www.jstor.org/stable/2685993
Guimaraes, P. (2004). Understanding the multinomial-Poisson transformation. The Stata Journal 4 (3), pp. 265-273. https://www.stata-journal.com/article.html?article=st0069
Lee, J.Y.L., Green, P.J.,and Ryan, L.M. (2017). On the “Poisson trick” and its extensions for fitting multinomial regression models. arXiv preprint available at doi:10.48550/arXiv.1707.08538
Anova.mp()
, glmer.mp()
, glm.mp()
, glm.mp.con()
, emmeans::emmeans()
library(car) library(lme4) library(lmerTest) library(emmeans) ## within-subjects factors (x1,X2) with dichotomous response (Y) data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m1 = glmer(Y ~ X1*X2 + (1|PId), data=ws2, family=binomial) Anova(m1, type=3) emmeans(m1, pairwise ~ X1*X2, adjust="holm") m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) Anova.mp(m2, type=3) glmer.mp.con(m2, pairwise ~ X1*X2, adjust="holm") # compare ## within-subjects factors (x1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m3 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m3, type=3) glmer.mp.con(m3, pairwise ~ X1*X2, adjust="holm")
library(car) library(lme4) library(lmerTest) library(emmeans) ## within-subjects factors (x1,X2) with dichotomous response (Y) data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m1 = glmer(Y ~ X1*X2 + (1|PId), data=ws2, family=binomial) Anova(m1, type=3) emmeans(m1, pairwise ~ X1*X2, adjust="holm") m2 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) Anova.mp(m2, type=3) glmer.mp.con(m2, pairwise ~ X1*X2, adjust="holm") # compare ## within-subjects factors (x1,X2) with polytomous response (Y) data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m3 = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m3, type=3) glmer.mp.con(m3, pairwise ~ X1*X2, adjust="holm")
This synthetic dataset represents a survey of 40 respondents about their favorite ice cream flavor. Twenty of the respondents were adults and 20 were children. They were queried four times over the course of a year, once in the middle of each season (fall, winter, spring, summer).
This dataset has a polytomous response Pref
and two factors,
Age
and Season
. The response has the unordered categories
{vanilla, chocolate, strawberry, other}
. Factor Age
has levels
{adult, child}
, and factor Season
has levels {fall, winter, spring, summer}
.
It also has a PId
column for participant identifier. Each participant identifier is repeated
four times, once per season.
A data frame with 160 observations on the following 4 variables:
a subject identifier with levels "1"
... "40"
a between-subjects factor with levels "adult"
, "child"
a within-subjects factor with levels "fall"
, "winter"
, "spring"
, "summer"
a polytomous response with categories "vanilla"
, "chocolate"
, "strawberry"
, "other"
See vignette("multpois", package="multpois")
for a complete analysis of this data set.
data(icecream, package="multpois") icecream$PId = factor(icecream$PId) icecream$Pref = factor(icecream$Pref) icecream$Age = factor(icecream$Age) icecream$Season = factor(icecream$Season) contrasts(icecream$Age) <- "contr.sum" contrasts(icecream$Season) <- "contr.sum" m = glmer.mp(Pref ~ Age*Season + (1|PId), data=icecream) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ Age*Season, adjust="holm")
data(icecream, package="multpois") icecream$PId = factor(icecream$PId) icecream$Pref = factor(icecream$Pref) icecream$Age = factor(icecream$Age) icecream$Season = factor(icecream$Season) contrasts(icecream$Age) <- "contr.sum" contrasts(icecream$Season) <- "contr.sum" m = glmer.mp(Pref ~ Age*Season + (1|PId), data=icecream) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ Age*Season, adjust="holm")
This generic synthetic dataset has a dichotomous response Y
and two factors
X1
and X2
. The response has categories {yes,no}
.
Factor X1
has levels {a,b}
, and factor X2
has levels
{c,d}
. It also has a PId
column for participant identifier.
Participant identifiers are repeated across rows.
A data frame with 60 observations on the following 4 variables:
a subject identifier with levels "1"
... "10"
a within-subjects factor with levels "a"
, "b"
a within-subjects factor with levels "c"
, "d"
a dichotomous response with categories "yes"
, "no"
See glmer.mp
and glmer.mp.con
for complete examples.
data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ X1*X2, adjust="holm")
data(ws2, package="multpois") ws2$PId = factor(ws2$PId) ws2$Y = factor(ws2$Y) ws2$X1 = factor(ws2$X1) ws2$X2 = factor(ws2$X2) contrasts(ws2$X1) <- "contr.sum" contrasts(ws2$X2) <- "contr.sum" m = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws2) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ X1*X2, adjust="holm")
This generic synthetic dataset has a polytomous response Y
and two factors
X1
and X2
. The response has categories {yes,no,maybe}
.
Factor X1
has levels {a,b}
, and factor X2
has levels
{c,d}
. It also has a PId
column for participant identifier.
Participant identifiers are repeated across rows.
A data frame with 60 observations on the following 4 variables:
a subject identifier with levels "1"
... "15"
a within-subjects factor with levels "a"
, "b"
a within-subjects factor with levels "c"
, "d"
a polytomous response with categories "yes"
, "no"
, "maybe"
See glmer.mp
and glmer.mp.con
for complete examples.
data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ X1*X2, adjust="holm")
data(ws3, package="multpois") ws3$PId = factor(ws3$PId) ws3$Y = factor(ws3$Y) ws3$X1 = factor(ws3$X1) ws3$X2 = factor(ws3$X2) contrasts(ws3$X1) <- "contr.sum" contrasts(ws3$X2) <- "contr.sum" m = glmer.mp(Y ~ X1*X2 + (1|PId), data=ws3) Anova.mp(m, type=3) glmer.mp.con(m, pairwise ~ X1*X2, adjust="holm")