These methods tidy the coefficients of mixed effects models
of the lme
class from functions of the nlme
package.
# S3 method for lme
tidy(
x,
effects = c("var_model", "ran_pars", "fixed"),
scales = NULL,
conf.int = FALSE,
conf.level = 0.95,
...
)
# S3 method for lme
augment(x, data = x$data, newdata, ...)
# S3 method for lme
glance(x, ...)
# S3 method for gls
tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
# S3 method for gls
augment(x, data = nlme::getData(x), newdata, ...)
An object of class lme
, such as those from lme
or nlme
One or more of "var_model", "ran_pars", "fixed", "ran_vals", and/or "ran_coefs".
scales on which to report the variables: for random effects, the choices are ‘"sdcor"’ (standard deviations and correlations: the default if scales
is NULL
) or ‘"vcov"’ (variances and covariances). NA
means no transformation, appropriate e.g. for fixed effects.
whether to include a confidence interval
confidence level for CI
extra arguments (not used)
original data this was fitted on; if not given this will attempt to be reconstructed
new data to be used for prediction; optional
All tidying methods return a data.frame
without rownames.
The structure depends on the method chosen.
tidy
returns one row for each estimated effect, either
random or fixed depending on the effects
parameter. If
effects = "ran_vals"
(or "ran_pars"
), it contains the columns
the group within which the random effect is being estimated
level within group
term being estimated
estimated coefficient
This column is only included if some parameters are fixed. TRUE if the residual error is estimated and FALSE if the residual error is fixed.
If effects="fixed"
, tidy
returns the columns
fixed term being estimated
estimate of fixed effect
standard error
t-statistic
P-value computed from t-statistic
If effects="var_model"
(the weights
argument to the model),
tidy
returns the columns defined in the help for tidy.varFunc
.
augment
returns one row for each original observation,
with columns (each prepended by a .) added. Included are the columns
predicted values
residuals
predicted values with no random effects
glance
returns one row with the columns
the square root of the estimated residual variance
the data's log-likelihood under the model
the Akaike Information Criterion
the Bayesian Information Criterion
returned as NA. To quote Brian Ripley on R-help https://stat.ethz.ch/pipermail/r-help/2006-May/104744.html, "McCullagh & Nelder (1989) would be the authorative [sic] reference, but the 1982 first edition manages to use 'deviance' in three separate senses on one page."
When the modeling was performed with na.action = "na.omit"
(as is the typical default), rows with NA in the initial data are omitted
entirely from the augmented data frame. When the modeling was performed
with na.action = "na.exclude"
, one should provide the original data
as a second argument, at which point the augmented data will contain those
rows (typically with NAs in place of the new columns). If the original data
is not provided to augment
and na.action = "na.exclude"
, a
warning is raised and the incomplete rows are dropped.
if (require("nlme") && require("lme4")) {
data("sleepstudy", package="lme4")
## original model
if (FALSE) {
lmm1 <- lme(Reaction ~ Days, random=~ Days|Subject, sleepstudy)
}
## load stored object
load(system.file("extdata","nlme_example.rda", package="broom.mixed"))
tidy(lmm1)
tidy(lmm1, effects = "fixed")
tidy(lmm1, conf.int = TRUE)
tidy(lmm1, effects = "ran_pars")
tidy(lmm1, effects = "ran_vals")
tidy(lmm1, effects = "ran_coefs")
head(augment(lmm1, sleepstudy))
glance(lmm1)
startvec <- c(Asym = 200, xmid = 725, scal = 350)
nm1 <- nlme(circumference ~ SSlogis(age, Asym, xmid, scal),
data = Orange,
fixed = Asym + xmid + scal ~1,
random = Asym ~1,
start = startvec)
tidy(nm1)
tidy(nm1, effects = "fixed")
head(augment(nm1, Orange))
glance(nm1)
gls1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary,
correlation = corAR1(form = ~ 1 | Mare))
tidy(gls1)
glance(gls1)
head(augment(gls1))
}
#> Loading required package: nlme
#>
#> Attaching package: ‘nlme’
#> The following object is masked from ‘package:lme4’:
#>
#> lmList
#> The following object is masked from ‘package:dplyr’:
#>
#> collapse
#> Warning: ran_pars not yet implemented for nonlinear models
#> # A tibble: 6 × 5
#> Mare Time follicles .fitted .resid
#> <ord> <dbl> <dbl> <dbl> <dbl>
#> 1 1 -0.136 20 13.7 6.28
#> 2 1 -0.0909 15 13.0 2.04
#> 3 1 -0.0455 19 12.1 6.87
#> 4 1 0 16 11.3 4.68
#> 5 1 0.0455 13 10.6 2.43
#> 6 1 0.0909 10 9.96 0.0405