[R-lang] Simple effects in mixed logit models

T. Florian Jaeger tiflo at csli.stanford.edu
Wed Dec 30 00:43:42 PST 2009


Hi Roger,

sorry for the prolonged silence. deadlines ...

The correlation between my two independent variables (language and prime) is
> very low (after treatment coding):
>
>
>
> > cor(L2prim$LangSwe, L2prim$PrimePP)
>
> [1] 0.00292528
>
>
>
> Does this make sense?
>

yes, the independent variables themselves won't be correlated within a
balanced data set. They will, however, be correlated with their interaction

cor(L2prim$LangSwe, L2prim$LangSwe * L2prim$PrimePP)
cor(L2prim$PrimePP, L2prim$LangSwe * L2prim$PrimePP)

should be high.

>   Given that there is no correlation, I can perhaps just report the
> analyses with treatment coding.  But you said that it should be around
> .33, and somehow it’s much lower.  I guess I still don’t understand what
> you meant.
>

does the above help?

>
>
> I have done the model comparisons as you suggest.  When I use the
> following model:
>
> primanaleng=lmer(score ~LangEng+LangEng:PrimePP + (1|PID) + (1|ITEM),
> data=L2prim, family = "binomial")
>
> I appear to get both simple effects (simple effect of prime on English
> LangEng0:PrimePP2, and simple effect on Swedish LangEng1:PrimePP2).  See
> APPENDIX 1.
>
>
>
> I then compare this model with:
>
> primanalengnoint=lmer(score ~LangEng+PrimePP + (1|PID) + (1|ITEM),
> data=L2prim, family = "binomial")
>
>
>
> The comparison shows that the models don’t significantly differ (APPENDIX
> 2).  So I think I should conclude that the model with the simple effects
> is no better than without.
>
>
>
> My question is: The model with the simple effects contains BOTH simple
> effects (effect of prime on English, and effect on Swedish).  But I’d like
> to know whether ONE of the simple effects is significant/improves the model
> (e.g., effect of prime on English only).  How do I get this with a model
> comparison?
>

hmmm, verflixt ;). I gotta admit the ANOVA approach is more intuitive to me
for this question, too. After I thought about it some more (though probably
still not long enough), I know think that another way is better, though I
hope other people may chime in (for practical purposes you may consider just
running the analyses on the half-data sets and presenting this to the
reviewers since the whole thing doesn't really make that much sense given
that you don't have any sign of an interaction).

you could just code a contrast that only contrasts the simple effect, e.g.

d$lang0prim <- ifelse(d$lang == 0, ifelse(d$prim == 0, -1, 1), 0)

now what I am not so sure of is, if you would want to include the main
effect that you're not interested in. so whether it should be

l.lang0prim <- lmer(score ~ lang + lang0prim + (1|s) + (1|i), d,
family="binomial")
compared against
lmer(score ~ lang + (1|s) + (1|i), d, family="binomial")

or

l.lang0prim <- lmer(score ~ lang0prim + (1|s) + (1|i), d, family="binomial")
compare against
lmer(score  ~ 1 + (1|s) + (1|i), d, family="binomial")

in the test I run they come out pretty much the same, but that isn't really
satisfying. unfortunately, i don't have to time to go back to look at the
logic of simple effects right so as compare the results to see whether any
of what i say above makes a grain of sense (it's late in the year, you
know). but if you feel like it you could use my code below and add the stuff
above and compare it against a simple effect anova analyses (for a
continuous variable). and hopefully some other people have some thoughts,
too. sorry to have given you probably misleading information before! I think
about it some more after my next deadline, but i didn't want to wait forever
to answer =).

here's some code that I used to create data like yours. it may be useful in
order to understand the relation between sum and treatment coding, though I
now think it's not relevant to your question.

# number of items and subjects
ni= 32
ns= 40

# predictors
s= sort(rep(1:ns, ni))
l= rep(c(rep(1,ni), rep(2,ni), rep(3,ni), rep(4,ni)), ns/4)
i= rep(1:ni, ns)
lang=rep(c(1,0),(ni/2)*ns)
prim=rep(c(1,1,0,0),(ni/4)*ns)

# noise
snoise= rnorm(ns, sd=2.5^0.5)
inoise= rnorm(ni, sd=2.3^0.5)

# assumed effects under sum-coding
sum.int  = -0.95
sum.lang =  0.0
sum.prim =  0.34
sum.lp  = -0.1

# get effects for dummy coding
# under assumption of perfectly balanced sample
dum.int=   sum.int - sum.lang - sum.prim + sum.lp
dum.lang= 2 * sum.lang - 2 * sum.lp
dum.prim= 2 * sum.prim - 2 * sum.lp
dum.lp= 2 * sum.lp

fixed= dum.int + dum.lang * lang + dum.prim * prim + dum.lp * lang * prime
score= rbinom(ns*ni, 1, plogis(fixed + snoise[s] + inoise[i]))

# test
lapply(split(score, paste("x=",lang,",z=",prime)), mean)

# dataframe
d <- as.data.frame(cbind(s,i,lang,prim,score))
d$s= as.factor(d$s)
d$i= as.factor(d$i)
d$lang = as.factor(d$lang)
d$prim = as.factor(d$prim)

# analysis
library(lme4)
contrasts(d$lang) <- c(-1,1)
contrasts(d$prim) <- c(-1,1)
l.sum <- lmer(score ~ lang * prim + (1|s) + (1|i), d, family="binomial")
summary(l.sum)


contrasts(d$lang) <- c(0,1)
contrasts(d$prim) <- c(0,1)
l.treat <- lmer(score ~ lang * prim + (1|s) + (1|i), d, family="binomial")
summary(l.treat)





>
> I have to admit that I don’t quite understand why treatment coding results
> in an analysis of simple effects.  I am sure you are right, but it’s
> difficult for me to conceptualise.
>
>
>
> Thanks for all your help.
>
>
>
> Roger
>
>
>
>
>
> APPENDIX 1
>
>
>
> primanaleng=lmer(score ~LangEng+LangEng:PrimePP + (1|PID) + (1|ITEM),
> data=L2prim, family = "binomial")
>
> summary(primanalengnoint)
>
>
>
> Generalized linear mixed model fit by the Laplace approximation
>
> Formula: score ~ LangEng + LangEng:PrimePP + (1 | PID) + (1 | ITEM)
>
>    Data: L2prim
>
>    AIC   BIC logLik deviance
>
>  650.5 677.2 -319.2    638.5
>
> Random effects:
>
>  Groups Name        Variance Std.Dev.
>
>  ITEM   (Intercept) 1.9705   1.4038
>
>  PID    (Intercept) 2.2791   1.5097
>
> Number of obs: 632, groups: ITEM, 40; PID, 32
>
>
>
> Fixed effects:
>
>                   Estimate Std. Error z value Pr(>|z|)
>
> (Intercept)        -0.5915     0.4153  -1.424  0.15437
>
> LangEng2           -0.1875     0.3022  -0.621  0.53486
>
> LangEng0:PrimePP2  -0.9496     0.3095  -3.068  0.00215 **
>
> LangEng1:PrimePP2  -0.5252     0.3100  -1.694  0.09026 .
>
> ---
>
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
>
>
> Correlation of Fixed Effects:
>
>             (Intr) LngEn2 LE0:PP
>
> LangEng2    -0.363
>
> LngEn0:PPP2 -0.354  0.507
>
> LngEn1:PPP2 -0.008 -0.477  0.012
>
>
>
>
>
> APPENDIX 2
>
>
>
> Data: L2prim
>
> Models:
>
> primanalengnoint: score ~ LangEng + PrimePP + (1 | PID) + (1 | ITEM)
>
> primanaleng: score ~ LangEng + LangEng:PrimePP + (1 | PID) + (1 | ITEM)
>
>                  Df    AIC    BIC  logLik  Chisq Chi Df Pr(>Chisq)
>
> primanalengnoint  5 649.33 671.57 -319.66
>
> primanaleng       6 650.46 677.15 -319.23 0.8714      1     0.3506
>
>
>
>  The University of Dundee is a registered Scottish charity, No: SC015096
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.ucsd.edu/pipermail/r-lang/attachments/20091230/18b917f2/attachment-0001.htm>


More information about the R-lang mailing list