Description Usage Arguments Examples
Generic interfaces that allows Type III tests of model terms (i.e., main
effects and interactions) via nested model comparisons using a
user-supplied estimation/fitting function and user-supplied function for
comparing two models. The default function for testing model terms is
anova
which returns likelihood-ratio tests.
1 2 3 |
formula |
Two-sided formula. Separate formulas (i.e., nested models) will be created for each model term on right side of this formula. For example, for mixed-effects models this should be the response (i.e., dependent) variable plus the fixed-effects. |
data |
|
extra_formula |
Optional one-sided formula that will be added to the resulting formulas. No separate formulas will be built based on this formula. For example, for mixed-effects model this should contain the random-effects. |
fit_fun |
Fitting/estimation function. For example, |
fit_arg |
|
test_fun |
Function comparing two models. Needs to return a
|
test_arg |
additional argument passed to |
type |
Type of sums of squares. Currently only Type III (i.e., |
test_intercept |
Logical. Should test for intercept be included in output? Default is |
na.action |
how |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | set_sum_contrasts() ## quite important, currently coding is not checked
data("Machines", package = "MEMSS")
# ignoring repeated-measures
m1 <- test_terms(score ~ Machine, data=Machines,
fit_fun = lm)
m1
nice(m1)
anova(m1)
## fixed-effects model
m2 <- test_terms(score ~ Machine*Worker, data=Machines,
fit_fun = lm)
m2
# simple model with random-slopes for repeated-measures factor
m3 <- test_terms(score ~ Machine, data=Machines,
extra_formula = ~ (Machine|Worker),
fit_fun = lme4::lmer, fit_arg = list(REML = FALSE),
test_arg = list(model.names=c("f", "r")))
m3
anova(m3)
## specify colnames in anova() output by hand instead of automatically:
m3b <- test_terms(score ~ Machine, data=Machines,
extra_formula = ~ (Machine|Worker),
fit_fun = lme4::lmer, fit_arg = list(REML = FALSE),
test_arg = list(model.names=c("f", "r"),
colnames = list("Chi Df", "Chisq", "Pr(>Chisq)")))
m3b
## Not run:
# using an example from afex
data("sk2011.2", package = "afex")
# use only affirmation problems (S&K also splitted the data like this)
sk2_aff <- droplevels(sk2011.2[sk2011.2$what == "affirmation",])
library("lme4")
# not a particularly reasonable non-maximal model
sk_m1 <- test_terms(response ~ instruction*inference*type,
sk2_aff,
extra_formula = ~(inference|id),
fit_fun = lmer, fit_arg = list(REML = FALSE),
test_arg = list(model.names=c("f", "r")))
nice(sk_m1)
anova(sk_m1)
### matches:
afex::mixed(response ~ instruction*inference*type + (inference|id),
sk2_aff, method = "LRT")
## if corresponding method exist, emmeans support is provided automatically:
emmeans::emmeans(sk_m1, c("instruction", "type"))
## End(Not run)
## Not run:
## It works also with glmmTMB
## see: https://cran.r-project.org/web/packages/glmmTMB/vignettes/glmmTMB.pdf
Owls <- transform(glmmTMB::Owls,
Nest=reorder(Nest,NegPerChick),
NCalls=SiblingNegotiation,
FT=FoodTreatment)
zipp_test <- test_terms(formula = NCalls~(FT+ArrivalTime)*SexParent,
data = Owls,
extra_formula = ~ offset(log(BroodSize)) + (1|Nest),
fit_fun = glmmTMB::glmmTMB,
fit_arg = list(ziformula=~1, family=poisson)
)
zipp_test
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.