Htest: Test for homoskedasticity at level one

View source: R/Htest.R

HtestR Documentation

Test for homoskedasticity at level one

Description

Based on Raudenbush and Bryk (2002) and Hoffman (2007). A statistically significant Chisq indicates heteroskedasticity. Output shows the H statistic, degrees of freedom, and p value.

Usage

Htest(newdata, fml, group)

Arguments

newdata

data to be used.

fml

level 1 formula.

group

grouping variable (in quotes).

Value

Returns a data frame which contains:

H

The computed H statistic.

df

The degrees of freedom.

p

The p-value (< .05 indicates heteroskedasticity is present).

References

Hoffman, L. (2007). Multilevel models for examining individual differences in within-person variation and covariation over time. Multivariate Behavioral Research, 42(4), 609–629.

Raudenbush, S., & Bryk, A. (2002). Hierarchical linear models: Applications and data analysis methods (2nd ed.). Sage.

Examples

set.seed(123)
x1 <- rnorm(400)
y <- x1 * .3 + rnorm(400)
gr <- rep(1:20, each = 20)
dat <- data.frame(x1, y, gr)
Htest(dat, y ~ x1, 'gr') #no violation
y <- x1 * .3 + rnorm(400, 0, sqrt(x1^2)) #add violation
dat <- data.frame(x1, y, gr)
Htest(dat, y ~ x1, 'gr')

MLMusingR documentation built on May 29, 2024, 7:35 a.m.