The estimated random effects at level \(i\) are represented as a data frame with rows given by the different groups at that level and columns given by the random effects. If a single level of grouping is specified, the returned object is a data frame; else, the returned object is a list of such data frames. Optionally, the returned data frame(s) may be augmented with covariates summarized over groups.

# S3 method for class 'lme'
ranef(object, augFrame, level, data, which, FUN,
      standard, omitGroupingFactor, subset, ...)

Arguments

object

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

augFrame

an optional logical value. If TRUE, the returned data frame is augmented with variables defined in data; else, if FALSE, only the coefficients are returned. Defaults to FALSE.

level

an optional vector of positive integers giving the levels of grouping to be used in extracting the random effects from an object with multiple nested grouping levels. Defaults to all levels of grouping.

data

an optional data frame with the variables to be used for augmenting the returned data frame when augFrame = TRUE. Defaults to the data frame used to fit object.

which

an optional positive integer vector specifying which columns of data should be used in the augmentation of the returned data frame. Defaults to all columns in data.

FUN

an optional summary function or a list of summary functions to be applied to group-varying variables, when collapsing data by groups. Group-invariant variables are always summarized by the unique value that they assume within that group. If FUN is a single function it will be applied to each non-invariant variable by group to produce the summary for that variable. If FUN is a list of functions, the names in the list should designate classes of variables in the frame such as ordered, factor, or numeric. The indicated function will be applied to any group-varying variables of that class. The default functions to be used are mean for numeric factors, and Mode for both factor and ordered. The Mode function, defined internally in gsummary, returns the modal or most popular value of the variable. It is different from the mode function that returns the S-language mode of the variable.

standard

an optional logical value indicating whether the estimated random effects should be "standardized" (i.e. divided by the estimate of the standard deviation of that group of random effects). Defaults to FALSE.

omitGroupingFactor

an optional logical value. When TRUE the grouping factor itself will be omitted from the group-wise summary of data but the levels of the grouping factor will continue to be used as the row names for the returned data frame. Defaults to FALSE.

subset

an optional expression indicating for which rows the random effects should be extracted.

...

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

Value

a data frame, or list of data frames, with the estimated random effects at the grouping level(s) specified in level and, optionally, other covariates summarized over groups. The returned object inherits from classes random.effects.lme and data.frame.

References

Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.

Author

José Pinheiro and Douglas Bates bates@stat.wisc.edu

Examples

fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject)
ranef(fm1)
#>     (Intercept)          age
#> M16  -0.1877570 -0.068853738
#> M05  -1.1766674  0.025600303
#> M02  -0.7275013  0.014507811
#> M11   0.8904899 -0.118825905
#> M07  -0.6079721  0.034900000
#> M08   0.8602971 -0.094736219
#> M03  -0.1739024  0.035852351
#> M12  -0.9979944  0.114564052
#> M13  -4.1295439  0.413668516
#> M14   0.9043445 -0.014119816
#> M09  -0.4443954  0.135908591
#> M15  -0.5349736  0.208177649
#> M06   1.2176432  0.083191278
#> M04   3.0004528 -0.065884778
#> M01   1.0515831  0.215684551
#> M10   2.6532362  0.211146609
#> F10  -2.2813818 -0.250590641
#> F09  -0.2909482 -0.218041702
#> F06  -0.6205850 -0.186557022
#> F01  -0.4859593 -0.178209676
#> F05   0.5168057 -0.167957628
#> F07  -0.1877570 -0.068853738
#> F02  -1.0118490  0.009857963
#> F08   1.2503194 -0.174400272
#> F03  -0.7727905  0.050642340
#> F04   1.0691629 -0.029862156
#> F11   1.2176432  0.083191278
random.effects(fm1)             # same as above
#>     (Intercept)          age
#> M16  -0.1877570 -0.068853738
#> M05  -1.1766674  0.025600303
#> M02  -0.7275013  0.014507811
#> M11   0.8904899 -0.118825905
#> M07  -0.6079721  0.034900000
#> M08   0.8602971 -0.094736219
#> M03  -0.1739024  0.035852351
#> M12  -0.9979944  0.114564052
#> M13  -4.1295439  0.413668516
#> M14   0.9043445 -0.014119816
#> M09  -0.4443954  0.135908591
#> M15  -0.5349736  0.208177649
#> M06   1.2176432  0.083191278
#> M04   3.0004528 -0.065884778
#> M01   1.0515831  0.215684551
#> M10   2.6532362  0.211146609
#> F10  -2.2813818 -0.250590641
#> F09  -0.2909482 -0.218041702
#> F06  -0.6205850 -0.186557022
#> F01  -0.4859593 -0.178209676
#> F05   0.5168057 -0.167957628
#> F07  -0.1877570 -0.068853738
#> F02  -1.0118490  0.009857963
#> F08   1.2503194 -0.174400272
#> F03  -0.7727905  0.050642340
#> F04   1.0691629 -0.029862156
#> F11   1.2176432  0.083191278
random.effects(fm1, augFrame = TRUE)
#>     (Intercept)          age distance    Sex
#> M16  -0.1877570 -0.068853738   23.000   Male
#> M05  -1.1766674  0.025600303   23.000   Male
#> M02  -0.7275013  0.014507811   23.375   Male
#> M11   0.8904899 -0.118825905   23.625   Male
#> M07  -0.6079721  0.034900000   23.750   Male
#> M08   0.8602971 -0.094736219   23.875   Male
#> M03  -0.1739024  0.035852351   24.250   Male
#> M12  -0.9979944  0.114564052   24.250   Male
#> M13  -4.1295439  0.413668516   24.250   Male
#> M14   0.9043445 -0.014119816   24.875   Male
#> M09  -0.4443954  0.135908591   25.125   Male
#> M15  -0.5349736  0.208177649   25.875   Male
#> M06   1.2176432  0.083191278   26.375   Male
#> M04   3.0004528 -0.065884778   26.625   Male
#> M01   1.0515831  0.215684551   27.750   Male
#> M10   2.6532362  0.211146609   29.500   Male
#> F10  -2.2813818 -0.250590641   18.500 Female
#> F09  -0.2909482 -0.218041702   21.125 Female
#> F06  -0.6205850 -0.186557022   21.125 Female
#> F01  -0.4859593 -0.178209676   21.375 Female
#> F05   0.5168057 -0.167957628   22.625 Female
#> F07  -0.1877570 -0.068853738   23.000 Female
#> F02  -1.0118490  0.009857963   23.000 Female
#> F08   1.2503194 -0.174400272   23.375 Female
#> F03  -0.7727905  0.050642340   23.750 Female
#> F04   1.0691629 -0.029862156   24.875 Female
#> F11   1.2176432  0.083191278   26.375 Female