[R-sig-ME] Multilevel weighted regression

Brant Inman brant.inman at me.com
Mon Oct 27 02:17:04 CET 2008


Hi,

I would like to use lmer to perform a meta-regression using a  
multilevel weighted regression.  I am having difficulty understanding  
how to use weights appropriately with lmer.  I have attached some code  
to demonstrate the type of problem that I will be modeling.

---------------

 > sessionInfo()
R version 2.7.2 (2008-08-25)
i386-apple-darwin8.11.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
  [1] nlme_3.1-89        foreign_0.8-29     car_1.2-8           
arm_1.1-15
  [5] R2WinBUGS_2.1-8    coda_0.13-2        MASS_7.2-44         
lme4_0.999375-24
  [9] Matrix_0.999375-11 lattice_0.17-13    meta_0.8-2

loaded via a namespace (and not attached):
[1] grid_2.7.2

--------------

Here is the example code for the BCG dataset of Colditz.

--------------

# Get dataset and format it appropriately into wide (BCG) and long  
(BCG.long) datasets

data('BCG', package='HSAUR')

logrr      <- log((BCG[,2] / BCG[,3]) / (BCG[,4] / BCG[,5]))
logrr.var  <- (1/BCG[,2]) + (1/BCG[,4]) - (1/BCG[,3]) - (1/BCG[,5])
logor	   <- log((BCG[,2]*(BCG[,5]-BCG[,4])) / (BCG[,4]*(BCG[,3]-BCG[, 
2])))
logor.var  <- sqrt((1/BCG[,2]) + (1/BCG[,4]) + (1/(BCG[,3]-BCG[,2])) +  
(1/(BCG[,5]-BCG[,4])))

BCG.long		 <- rbind(BCG[,c(1,6,7)], BCG[,c(1,6,7)])
	BCG.long$vaccine <- c(rep(1,13), rep(0,13))	
	BCG.long$event	 <- c(BCG[,2], BCG[,4])
	BCG.long$atrisk	 <- c(BCG[,3], BCG[,5])

# Fixed effects model using 'lm', RR scale, 2 explanatory variables
f1 <- lm(logrr ~ Latitude + Year, weights = (1/logrr.var), data=BCG)
	summary(f1)		
	mse <- sqrt(sum(f1$weights * f1$residuals^2) / f1$df.residual)
	sqrt(diag(vcov(f1))) / mse			# Adjust parameter SEs for weighting

# Fixed effects model using 'lmer', OR scale, no explanatory variables
f2 <- lmer(cbind(event,atrisk) ~ vaccine + (1 | study), data=BCG.long,  
family=binomial)
	summary(f2)

# Random effects model using 'lmer', OR scale, no explanatory variables
f3 <- lmer(cbind(event,atrisk) ~ vaccine + (vaccine | study),  
data=BCG.long, family=binomial)
	summary(f3)

---------------

What I would like to ask help for is:
1) How do I do write a weighted model like model 'f1' but using lmer  
so that I can fit a random effects model with covariates on RR scale?

2) How do I correctly specify the random effects model 'f3' to  
incorporate the covariates 'Latitude' and 'Year' on the OR scale?


I appreciate any time that any of you spare for this.

Brant Inman
Chapel Hill, NC




More information about the R-sig-mixed-models mailing list