Hi dear R users,

I am trying to write a script to compare models with the same fixed effects
but different random effects e.g.,

model1 = lmer(reaction_time ~ factorA * factorB + (1 + factorA *
factorB |subject)
model2 = lmer(reaction_time ~ factorA * factorB + (1 + factorA +
factorB |subject)
model3 = lmer(reaction_time ~ factorA * factorB + (1 + factorA |subject)
anova(model1, model2)

The idea is that I can input a full model (e.g., model1), and the script
will compare it with model2, if the p-value is above a user-defined level
(e.g., 0.1), model2 will be selected. Then the script will compare model2
with model3. etc.

Since sometimes certain models fail to converge or have singular
convergence, I would like the script to be able to note that and decide
what to do next accordingly.

For example, in the case of failure to converge (e.g., if model1 fails to
converge), I would like the script to choose a simpler model (e.g., Model2)
and compare it with an even simpler model (e.g., model3).

I am not sure if this is doable within my capacity. So far, I've been able
to write a script to do a series of comparisons, but problems arise when
there are errors such as failure to converge.

Thank you in advance for your help!!!

Best,
Xiao

	[[alternative HTML version deleted]]

