prt-utilities | R Documentation |
The print
, summary
methods (including the
print
for the summary()
result) in lme4 are
modular, using about ten small utility functions. Other packages,
building on lme4 can use the same utilities for ease of
programming and consistency of output.
Notably see the Examples.
llikAIC()
extracts the log likelihood, AIC, and related
statics from a Fitted LMM.
formatVC()
“format()”s the VarCorr
matrix of the
random effects – for print()
ing and
show()
ing; it is also the “workhorse” of
.prt.VC()
, and returns a character
matrix.
.prt.*()
all use cat
and print
to
produce output.
llikAIC(object, devianceFUN = devCrit, chkREML = TRUE,
devcomp = object@devcomp)
methTitle(dims)
.prt.methTit(mtit, class)
.prt.family (famL)
.prt.resids (resids, digits, title = "Scaled residuals:", ...)
.prt.call (call, long = TRUE)
.prt.aictab (aictab, digits = 1)
.prt.grps (ngrps, nobs)
.prt.warn (optinfo, summary = FALSE, ...)
.prt.VC (varcor, digits, comp = "Std.Dev.", corr = any(comp == "Std.Dev."),
formatter = format, ...)
formatVC(varcor, digits = max(3, getOption("digits") - 2),
comp = "Std.Dev.", corr = any(comp == "Std.Dev."),
formatter = format,
useScale = attr(varcor, "useSc"), ...)
object |
a LMM model fit |
devianceFUN |
the function to be used for computing the deviance; should not be changed for lme4 created objects. |
chkREML |
optional logical indicating if |
devcomp |
for lme4 always the equivalent of
|
dims |
for lme4 always the equivalent of
|
mtit |
the result of |
class |
typically |
famL |
a |
resids |
numeric vector of model |
digits |
non-negative integer of (significant) digits to print minimally. |
title |
|
... |
optional arguments passed on, e.g., to |
call |
the |
long |
logical indicating if the output may be long, e.g.,
printing the |
aictab |
typically the |
varcor |
typically the result of |
comp |
optional |
corr |
|
formatter |
a |
ngrps |
integer (vector), typically the result of
|
nobs |
integer; the number of observations, e.g., the result
of |
optinfo |
typically |
summary |
logical |
useScale |
(logical) whether the parent model estimates a scale parameter. |
llikAIC()
returns a list
with components
logLik |
which is |
AICtab |
a “table” of |
## Create a few "lme4 standard" models ------------------------------
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
fmM <- update(fm1, REML=FALSE) # -> Maximum Likelihood
fmQ <- update(fm1, . ~ Days + (Days | Subject))
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
gmA <- update(gm1, nAGQ = 5)
(lA1 <- llikAIC(fm1))
(lAM <- llikAIC(fmM))
(lAg <- llikAIC(gmA))
(m1 <- methTitle(fm1 @ devcomp $ dims))
(mM <- methTitle(fmM @ devcomp $ dims))
(mG <- methTitle(gm1 @ devcomp $ dims))
(mA <- methTitle(gmA @ devcomp $ dims))
.prt.methTit(m1, class(fm1))
.prt.methTit(mA, class(gmA))
.prt.family(gaussian())
.prt.family(binomial())
.prt.family( poisson())
.prt.resids(residuals(fm1), digits = 4)
.prt.resids(residuals(fmM), digits = 2)
.prt.call(getCall(fm1))
.prt.call(getCall(gm1))
.prt.aictab ( lA1 $ AICtab ) # REML
.prt.aictab ( lAM $ AICtab ) # ML --> AIC, BIC, ...
V1 <- VarCorr(fm1)
m <- formatVC(V1)
stopifnot(is.matrix(m), is.character(m), ncol(m) == 4)
print(m, quote = FALSE) ## prints all but the first line of .prt.VC() below:
.prt.VC( V1, digits = 4)
## Random effects:
## Groups Name Std.Dev. Corr
## Subject (Intercept) 24.740
## Days 5.922 0.07
## Residual 25.592
p1 <- capture.output(V1)
p2 <- capture.output( print(m, quote=FALSE) )
pX <- capture.output( .prt.VC(V1, digits = max(3, getOption("digits")-2)) )
stopifnot(identical(p1, p2),
identical(p1, pX[-1])) # [-1] : dropping 1st line
(Vq <- VarCorr(fmQ)) # default print()
print(Vq, comp = c("Std.Dev.", "Variance"))
print(Vq, comp = c("Std.Dev.", "Variance"), corr=FALSE)
print(Vq, comp = "Variance")
.prt.grps(ngrps = ngrps(fm1),
nobs = nobs (fm1))
## --> Number of obs: 180, groups: Subject, 18
.prt.warn(fm1 @ optinfo) # nothing .. had no warnings
.prt.warn(fmQ @ optinfo) # (ditto)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.