[R] dummy encoding in metafor

Michael Dewey info at aghmed.fsnet.co.uk
Sun Jan 20 12:52:40 CET 2013


At 17:14 19/01/2013, Alma Wilflinger wrote:
>Hi,
>
>I am quite new to R and in need of some advice. I am trying to 
>conduct a meta regression over a some studies with about 7 mod 
>variables which I have to dummy encode.

Alma, although you can generate your own dummy variables by hand you 
do not have to as R will do it for you. See below for more comments.


>I have found the following piece of code in the manual for the 
>metafor library:
>
>### manual dummy coding of the allocation factor
>alloc.random <- ifelse(dat$alloc == "random", 1, 0)
>alloc.alternate <- ifelse(dat$alloc == "alternate", 1, 0)
>alloc.systematic <- ifelse(dat$alloc == "systematic", 1, 0)

If you look a bit further down the manual page you will see
### using a model formula to specify the same model
rma(yi, vi, mods=~factor(alloc)+year+ablat, data=dat, method="REML", 
btt=c(2,3))

which is much easier.

>### test the allocation factor (in the presence of the other moderators)
>### note: "alternate" is the reference level of the allocation factor
>### note: the intercept is the first coefficient, so btt=c(2,3)
>rma(yi, vi, mods=cbind(alloc.random, alloc.systematic, year, ablat), 
>data=dat, method="REML", btt=c(2,3))
>
>What I do not understand is the following:
>How does R know which columns in my data.frame are related to the 
>dummy encoded variables?

If you code them yourself R does not know. You know.


>It is clear that in the call of cbind I just do not use the 
>reference variable as a parameter but I do not get it how R knows 
>that alloc.random and alloc.systematic refer to the column alloc in 
>the data frame.
>
>Thank you very much in advance for your help,
>

You say you have seven moderator variables. Unless you have a shed 
load of studies you will not be able to look at them simultaneously. 
Apologies if you already knew that.

>kind regards,
>Alma
>         [[alternative HTML version deleted]]

Michael Dewey
info at aghmed.fsnet.co.uk
http://www.aghmed.fsnet.co.uk/home.html



More information about the R-help mailing list