residuals.lme: Extract lme Residuals

Description Usage Arguments Value Author(s) See Also Examples

View source: R/lme.R

Description

The residuals at level i are obtained by subtracting the fitted levels at that level from the response vector (and dividing by the estimated within-group standard error, if type="pearson"). The fitted values at level i are obtained by adding together the population fitted values (based only on the fixed effects estimates) and the estimated contributions of the random effects to the fitted values at grouping levels less or equal to i.

Usage

1
2
3
## S3 method for class 'lme'
residuals(object, level = Q,
          type = c("response", "pearson", "normalized"), asList = FALSE, ...)

Arguments

object

an object inheriting from class "lme", representing a fitted linear mixed-effects model.

level

an optional integer vector giving the level(s) of grouping to be used in extracting the residuals from object. Level values increase from outermost to innermost grouping, with level zero corresponding to the population residuals. Defaults to the highest or innermost level of grouping.

type

an optional character string specifying the type of residuals to be used. If "response", as by default, the “raw” residuals (observed - fitted) are used; else, if "pearson", the standardized residuals (raw residuals divided by the corresponding standard errors) are used; else, if "normalized", the normalized residuals (standardized residuals pre-multiplied by the inverse square-root factor of the estimated error correlation matrix) are used. Partial matching of arguments is used, so only the first character needs to be provided.

asList

an optional logical value. If TRUE and a single value is given in level, the returned object is a list with the residuals split by groups; else the returned value is either a vector or a data frame, according to the length of level. Defaults to FALSE.

...

some methods for this generic require additional arguments. None are used in this method.

Value

if a single level of grouping is specified in level, the returned value is either a list with the residuals split by groups (asList = TRUE) or a vector with the residuals (asList = FALSE); else, when multiple grouping levels are specified in level, the returned object is a data frame with columns given by the residuals at different levels and the grouping factors. For a vector or data frame result the naresid method is applied.

Author(s)

José Pinheiro and Douglas Bates [email protected]

See Also

lme, fitted.lme

Examples

1
2
3
4
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
head(residuals(fm1, level = 0:1))
summary(residuals(fm1) /
        residuals(fm1, type = "p")) # constant scaling factor 1.432

Example output

       fixed    Subject
1  3.0118056  0.6076280
2  0.6914352 -1.7127424
3  3.3710648  0.9668872
4  4.0506944  1.6465169
5 -1.4881944 -0.1105197
6 -1.8085648 -0.4308900
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  1.432   1.432   1.432   1.432   1.432   1.432 

nlme documentation built on April 7, 2018, 5:03 p.m.