Learn R Programming

gss (version 2.2-8)

mkran: Generating Random Effects in Mixed-Effect Models

Description

Generate entries representing random effects in mixed-effect models.

Usage

mkran(formula, data)
mkran1(ran1, ran2)

Value

A list of three elements.

z

Z matrix.

sigma

Sigma matrix to be evaluated through sigma$fun(para,sigma$env).

init

Initial parameter values.

Arguments

formula

Symbolic description of the random effects.

data

Data frame containing the variables in the model.

ran1

Random effects in the form of the value of mkran

.

ran2

Random effects in the form of the value of mkran

.

Details

mkran generates random effect terms from simple grouping variables, for use in nonparametric mixed-effect models as described in Gu and Ma (2005a, b). The syntax of the formula resembles that of similar utilities for linear and nonlinear mixed-effect models, as described in Pinheiro and Bates (2000).

Currently, mkran takes only two kinds of basic formulas, ~1|grp2 or ~grp1|grp2. Both grp1 and grp2 should be factors, and for the second formula, the levels of grp2 should be nested under those of grp1.

The Z matrix is determined by grp2. When observations are ordered according to the levels of grp2, the Z matrix is block diagonal of 1 vectors.

The Sigma matrix is diagonal. For ~1|grp2, it has one tuning parameter. For ~grp1|grp2, the number of parameters equals the number of levels of grp1, with each parameter shared by the grp2 levels nested under the same grp1 level.

mkran1 adds together two independent random effects, and can be used recursively to add more than two terms. The arguments are of the form of the value of mkran or mkran1, which may or may not be created by mkran or mkran1.

Multiple terms of random effects can also be specified via the likes of mkran(~1|grp1+1|grp2,data), which is equivalent to mkran1(mkran(~1|grp1,data),mkran(~1|grp2,data)).

References

Gu, C. and Ma, P. (2005), Optimal smoothing in nonparametric mixed-effect models. The Annals of Statistics, 33, 1357--1379.

Gu, C. and Ma, P. (2005), Generalized nonparametric mixed-effect models: computation and smoothing parameter selection. Journal of Computational and Graphical Statistics, 14, 485--504.

Pinheiro and Bates (2000), Mixed-Effects Models in S and S-PLUS. New York: Springer-Verlag.

Examples

Run this code
## Toy data
test <- data.frame(grp=as.factor(rep(1:2,c(2,3))))
## First formula
ran.test <- mkran(~1|grp,test)
ran.test$z
ran.test$sigma$fun(2,ran.test$sigma$env) # diag(10^(-2),2)
## Second formula
ran.test <- mkran(~grp|grp,test)
ran.test$z
ran.test$sigma$fun(c(1,2),ran.test$sigma$env) # diag(10^(-1),10^(-2))
## Clean up
if (FALSE) rm(test,ran.test)

Run the code above in your browser using DataLab