lmme: Linear mixed model estimation

Description Usage Arguments Details Value Examples

View source: R/lmme.R

Description

Estimation of fixed and random effects in linear mixed models

Usage

1
lmme(data,Y,z,grp,D,step,showit)

Arguments

data

Input matrix of dimension n * p; each row is an observation vector. The intercept should be included in the first column as (1,...,1). If not, it is added.

Y

Response variable of length n.

z

Random effects matrix. Of size n*q.

grp

Grouping variable of length n.

D

Logical value. If TRUE, the random effects are considered to be independent, i.e. Psi is a diagonal matrix. D=TRUE should be used with nested grouping factors.

step

The algorithm performs at most step iterations. Default is 3000.

showit

Logical value. If TRUE, shows the convergence process of the algorithm. Default is FALSE.

Details

lmme performs an ML-estimation of fixed and random effects in linear mixed models when no selection is involved. Two algorithms are available: one when the random effects are assumed to be independent (D=TRUE) and one when they are not (D=FALSE).

Value

data

List of the user-data: the scaled matrix used in the algorithm, the first column being (1,...,1); Y; z and grp.

beta

Estimation of the selected fixed effects.

Psi

Variance of the random effects. Matrix of dimension q*q.

sigma_e

Variance of the noise.

fitted.values

Fitted values calculated with the fixed effects and the random effects.

it

Number of iterations of the algorithm.

converge

Did the algorithm converge?

u

Vector of the concatenation of the estimated random effects (u_1',...,u_q')'.

call

The call that produced this object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
N <- 20           # number of groups
p <- 80            # number of covariates (including intercept)
q <- 2            # number of random effect covariates
ni <- rep(6,N)    # observations per group
n <- sum(ni)   # total number of observations

grp <- factor(rep(1:N,ni)) # grouping variable
grp=rbind(grp,grp)

beta <- c(1,2,4,3,rep(0,p-3)) # fixed-effects coefficients
x <- cbind(1,matrix(rnorm(n*p),nrow=n)) # design matrix

u1=rnorm(N,0,sd=sqrt(2))
u2=rnorm(N,0,sd=sqrt(2))
bi1 <- rep(u1,ni) 
bi2 <- rep(u2,ni)
bi <- rbind(bi1,bi2)

z=x[,1:2,drop=FALSE]
   
epsilon=rnorm(120)
y <- numeric(n)
for (k in 1:n) y[k] <- x[k,]%*%beta + t(z[k,])%*%bi[,k] + epsilon[k]

########
fit=lmme(x,y,z,grp)

## End(Not run)

MMS documentation built on May 17, 2018, 9:05 a.m.