compCoef.RdComparing regression coefficients between models when one model is nested within another for clustered data.
compCoef(fit0, fit1)a list of two components:
estimated difference
in the coefficients of common covariates from fit0 and
fit1
estimated variance matrix of delta
Allison, P. D. (1995). The impact of random predictors on comparisons of coefficients between models: Comment on Clogg, Petkova, and Haritou. American Journal of Sociology, 100(5), 1294–1305.
Clogg, C. C., Petkova, E., and Haritou, A. (1995). Statistical methods for comparing regression coefficients between models. American Journal of Sociology, 100(5), 1261–1293.
Yan, J., Aseltine, R., and Harel, O. (2011). Comparing Regression Coefficients Between Nested Linear Models for Clustered Data with Generalized Estimating Equations. Journal of Educational and Behaviorial Statistics, Forthcoming.
## generate clustered data
gendat <- function(ncl, clsz) {
## ncl: number of clusters
## clsz: cluster size (all equal)
id <- rep(1:ncl, each = clsz)
visit <- rep(1:clsz, ncl)
n <- ncl * clsz
x1 <- rbinom(n, 1, 0.5) ## within cluster varying binary covariate
x2 <- runif(n, 0, 1) ## within cluster varying continuous covariate
## the true correlation coefficient rho for an ar(1)
## correlation structure is 2/3
rho <- 2/3
rhomat <- rho ^ outer(1:4, 1:4, function(x, y) abs(x - y))
chol.u <- chol(rhomat)
noise <- as.vector(sapply(1:ncl, function(x) chol.u %*% rnorm(clsz)))
y <- 1 + 3 * x1 - 2 * x2 + noise
dat <- data.frame(y, id, visit, x1, x2)
dat
}
simdat <- gendat(100, 4)
fit0 <- geese(y ~ x1, id = id, data = simdat, corstr = "un")
fit1 <- geese(y ~ x1 + x2, id = id, data = simdat, corstr = "un")
compCoef(fit0, fit1)
#> $delta
#> (Intercept) x1
#> -1.02293803 0.04506944
#>
#> $variance
#> beta_(Intercept) beta_x1
#> beta_(Intercept) 0.010715045 -0.002740304
#> beta_x1 -0.002740304 0.005926041
#>