nullModel: Fit two-level null random intercept model

Description Usage Arguments Details Value References See Also Examples

View source: R/nullModel.R

Description

Fit a null two-level random intercept model using closed-form formulas provided by Snijders nd Bosker (1999)

Usage

1
2
3
4
nullModel(y, g, data = NULL)

## S3 method for class 'nullModel'
print(x, ...)

Arguments

y

numeric, dependent variable

g

numeric, grouping factor

data

data frame, optional dataset where the variables should be looked for

x

object of class "nullModel"

...

other arguments passed to/from other methods

Details

The function fits a random effect model of the form:

Y_ij = mu + U_j + R_ij

where Y_ij is the value of the dependent variable (y) for i-th object within j-th group, mu is the population mean, U_j is the effect specific to group j, and R_ij is the within-grup error.

The function estimates between-group and pooled within-group variances as well as the intra-class correlation coefficient. The closed-form expressions are provided by Snijders and Bosker (1999, p. 18–21).

Value

The function returns a list of S3 class "nullModel" which contains the following components:

yname

character, name of the dependent variable

gname

character, name of the grouping factor

n

numeric, number of groups

m

numeric, total number of observations

wgvar

numeric, pooled within-group variance

bgvar

numeric, between-group variance

tau

numeric, estimate of the population between-group variance

intcor

numeric, intra-class correlation coefficient

References

Snijders, T.A.B., Bosker, R. (1999) "Multilevel Analysis. An Introduction to Basic and Advanced Multilevel Modelling". London: Sage

See Also

lmer in package lme4 for general fitting of mixed-effects models.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
# fit null model with lmer
library(lme4)
system.time(mm <- lmer( Reaction ~ 1 | Subject, sleepstudy ))
# fit with closed-form formulas
system.time(m <- nullModel( sleepstudy$Reaction, sleepstudy$Subject ))
mm
m

## End(Not run)

mbojan/mbstats documentation built on Dec. 21, 2021, 3:56 p.m.