[R-sig-ME] Model failed to converge when a factor is centered or releveled

Chao Han h@nch@o @end|ng |rom ude|@edu
Fri Mar 15 01:33:50 CET 2019


Thank you all for your comments.
I tried both c(0.5, -0.5) and contr.helmert contrast setting, and they both
give "failed to converge" warnings. I'm concerned if I should trust the
model with default coding.

Best,
Chao

On Tue, Mar 12, 2019 at 12:49 PM Douglas Bates <bates using stat.wisc.edu> wrote:

> For a 2-level factor like Memory I prefer to use contr.helmert rather than
> hard-coding levels like c(-0.5, 0.5).  In general statisticians code
> factors in a 2-level factorial experiment using (-1, 1), not (-0.5, 0.5)
> because the (-1, 1) levels are propagated to interactions at any level.  If
> you use (-0.5, 0.5) then 2-level interactions end up being coded as (-0.25,
> 0.25), 3-level interactions as (-0.125, 0.125), etc.  If you just assign
> the contrasts as contr.helmert to two-level factors at the beginning things
> proceed smoothly, in my opinion.
>
> On Tue, Mar 12, 2019 at 11:21 AM Phillip Alday <phillip.alday using mpi.nl>
> wrote:
>
>> A few general comments without looking at your data:
>>
>> 1. It generally doesn't make sense to "center" a categorical variable.
>> For a two-level, dummy-coded variable you could in theory do this, but
>> it would lead to a rather odd balance-weighted contrast coding.
>>
>> 2. I have occasionally seen weird behavior in complex binomial models
>> where the choice of reference-level makes a difference in convergence. I
>> suspect this has to do with the whether the model is able to "pull away"
>> from a "solution" where the model just predicts the same response for
>> everything, but I have not investigated this rigorously nor I have
>> checked that my hand-waving explanation makes sense in terms of the
>> actual behavior of the optimizer.
>>
>> If you really want to reverse your contrast labels, what happens when
>> you do that directly instead of releveling?
>> i.e.
>>
>> c1 <- c(-0.5, 0.5)
>> contrasts(df$Memory) = cbind(c1)
>> model_center <- glmer(ACC ~ Memory * Group + (1|Subject) +
>> (1+Memory|item), family = "binomial", data = df)
>>
>> c2 <- c(0.5, -0.5)
>> contrasts(df$Memory) = cbind(c2)
>> model_relevel <- glmer(ACC ~ Memory * Group + (1|Subject) + ...
>>
>>
>> Best,
>> Phillip
>>
>> On 10/3/19 3:26 am, Chao Han wrote:
>> > Hi all,
>> >
>> > I'm running a mixed-effects model using lmer4::glmer() function. The
>> > modeling works with R's default dummy coding. But if I center or
>> relevel a
>> > factor of 2 levels, the model failed to converge. I am wondering why.
>> >
>> > Here is the data:
>> > https://www.dropbox.com/s/ysw5rvxowamucoh/example.csv?dl=0
>> >
>> > Here is the code for the model without centering or releveling the
>> factor
>> > "Memory":
>> >
>> >> model_default <- glmer(ACC ~ Memory * Group + (1|Subject) +
>> > (1+Memory|item), family = "binomial", data = df)
>> >
>> > The model converges with the above code. But the following model failed
>> to
>> > converge after centering the factor "Memory":
>> >
>> >> c1 <- c(-0.5, 0.5)
>> >> contrasts(df$Memory) = cbind(c1)
>> >> model_center <- glmer(ACC ~ Memory * Group + (1|Subject) +
>> > (1+Memory|item), family = "binomial", data = df)
>> >
>> > If I relevel the factor "Memory", the following model failed to converge
>> > either:
>> >
>> >> df$Memory <- factor(df$Memory, levels = c("Y", "X"))
>> >> model_relevel <- glmer(ACC ~ Memory * Group + (1|Subject) +
>> > (1+Memory|item), family = "binomial", data = df)
>> >
>> > Why would centering or releveling a factor make a difference in terms of
>> > convergence? Which result should I trust?
>> >
>> > Thank you in advance for your help.
>> >
>> > Best,
>> > Chao
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > _______________________________________________
>> > R-sig-mixed-models using r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>> >
>>
>> _______________________________________________
>> R-sig-mixed-models using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>

	[[alternative HTML version deleted]]



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