I have seen questions about this on this forum, and I have also asked it myself in a previous post but I still haven't been able to solve my problem. Therefore I am trying again, formulating the question as clearly as I can this time, with as much detailed information as possible.
My data set has a binomial dependent variable, 3 categorical fixed effects and 2 categorical random effects (item and subject). I am using a mixed effects model using glmer. Here is what I entered in R:
modelall<- glmer(moodR ~ group*context*condition + (1|subject) + ``(1|item), data=RprodHSNS, family="binomial")`
I get 2 warnings:
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.02081 (tol = 0.001, component 11)
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model is nearly unidentifiable: large eigenvalue ratio
- Rescale variables?`
My summary looks like this:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: moodR ~ group * context * condition + (1 | subject) + (1 | item)
Data: RprodHSNS`
AIC BIC logLik deviance df.resid
1400.0 1479.8 -686.0 1372.0 2195 `
Scaled residuals:
Min 1Q Median 3Q Max
-8.0346 -0.2827 -0.0152 0.2038 20.6578 `
Random effects:
Groups Name Variance Std.Dev.
item (Intercept) 1.475 1.215
subject (Intercept) 1.900 1.378
Number of obs: 2209, groups: item, 54; subject, 45
Fixed effects:`
Estimate Std. Error z value Pr(>|z|)`
(Intercept) -0.61448 42.93639 -0.014 0.988582
group1 -1.29254 42.93612 -0.030 0.975984
context1 0.09359 42.93587 0.002 0.998261
context2 -0.77262 0.22894 -3.375 0.000739***
condition1 4.99219 46.32672 0.108 0.914186
group1:context1 -0.17781 42.93585 -0.004 0.996696
group1:context2 -0.10551 0.09925 -1.063 0.287741
group1:condition1 -3.07516 46.32653 -0.066 0.947075
context1:condition1 -3.47541 46.32648 -0.075 0.940199
context2:condition1 -0.07293 0.22802 -0.320 0.749087
group1:context1:condition1 2.47882 46.32656 0.054 0.957328
group1:context2:condition1 0.30360 0.09900 3.067 0.002165 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) group1 cntxt1 cntxt2 cndtn1 grp1:cnt1 grp1:2 grp1:cnd1 cnt1:1 cnt2:1 g1:1:1
group1 -1.000
context1 -1.000 1.000
context2 0.001 0.000 -0.001
condition1 -0.297 0.297 0.297 0.000
grp1:cntxt1 1.000 -1.000 -1.000 0.001 -0.297
grp1:cntxt2 0.001 0.000 0.000 -0.123 0.000 0.000
grp1:cndtn1 0.297 -0.297 -0.297 -0.001 -1.000 0.297 0.000
cntxt1:cnd1 0.297 -0.297 -0.297 -0.001 -1.000 0.297 0.001 1.000
cntxt2:cnd1 0.000 0.000 -0.001 0.011 0.001 0.000 -0.197 -0.001 -0.001
grp1:cnt1:1 -0.297 0.297 0.297 0.001 1.000 -0.297 -0.001 -1.000 -1.000 0.001
grp1:cnt2:1 0.000 0.000 0.001 -0.198 0.000 -0.001 0.252 0.000 0.001 -0.136 0.000
Extremely high p-values, which does not seem to be possible.
In a previous post I read that one of the problems could be fixed by increasing the amount of iterations by inserting the following in the command: glmerControl(optimizer="bobyqa", optCtrl = list(maxfun = 100000))
So that's what I did:
modelall<- glmer(moodR ~ group*context*condition + (1|subject) + (1|item), data=RprodHSNS, family="binomial", glmerControl(optimizer="bobyqa", optCtrl = list(maxfun = 100000)))
Now, the second warning is gone, but the first one is still there:
> Warning message:
In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.005384 (tol = 0.001, component 7)
The summary also still looks odd:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: moodR ~ group * context * condition + (1 | subject) + (1 | item)
Data: RprodHSNS
Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 1e+05))`
AIC BIC logLik deviance df.resid
1400.0 1479.8 -686.0 1372.0 2195
Scaled residuals:
Min 1Q Median 3Q Max
-8.0334 -0.2827 -0.0152 0.2038 20.6610
Random effects:
Groups Name Variance Std.Dev.
item (Intercept) 1.474 1.214
subject (Intercept) 1.901 1.379
Number of obs: 2209, groups: item, 54; subject, 45
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.64869 26.29368 -0.025 0.980317
group1 -1.25835 26.29352 -0.048 0.961830
context1 0.12772 26.29316 0.005 0.996124
context2 -0.77265 0.22886 -3.376 0.000735 ***
condition1 4.97325 22.80050 0.218 0.827335
group1:context1 -0.21198 26.29303 -0.008 0.993567
group1:context2 -0.10552 0.09924 -1.063 0.287681
group1:condition1 -3.05629 22.80004 -0.134 0.893365
context1:condition1 -3.45656 22.80017 -0.152 0.879500
context2:condition1 -0.07305 0.22794 -0.320 0.748612
group1:context1:condition1 2.45996 22.80001 0.108 0.914081
group1:context2:condition1 0.30347 0.09899 3.066 0.002172 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) group1 cntxt1 cntxt2 cndtn1 grp1:cnt1 grp1:2 grp1:cnd1 cnt1:1 cnt2:1 g1:1:1
group1 -1.000
context1 -1.000 1.000
context2 0.000 0.000 0.000
condition1 0.123 -0.123 -0.123 -0.001
grp1:cntxt1 1.000 -1.000 -1.000 0.001 0.123
grp1:cntxt2 0.001 0.000 0.000 -0.123 0.001 0.000
grp1:cndtn1 -0.123 0.123 0.123 0.000 -1.000 -0.123 -0.001
cntxt1:cnd1 -0.123 0.123 0.123 0.000 -1.000 -0.123 0.000 1.000
cntxt2:cnd1 0.000 0.000 0.000 0.011 -0.001 0.000 -0.197 0.001 0.001
grp1:cnt1:1 0.123 -0.123 -0.123 0.000 1.000 0.123 0.000 -1.000 -1.000 -0.001
grp1:cnt2:1 0.000 -0.001 0.001 -0.198 0.001 -0.001 0.252 -0.001 0.000 -0.136 0.000
What I can do to solve this? Or can anyone tell me what this warning even means? (in a way that an R-newbie like myself can understand) Any help is much appreciated!
Related
Hello everyone, I'm looking to calculate the over dispersion in the following model :
lmer(R_ger_b~espece*traitement+(1|pop), data=d)
Here "espece" means species, "traitement" means treatment and "pop" means population. My variable called R_ger_b come from a binary variable on which I took the residu out (R_ger_b) to correct this variable from an other one (that was a 0 (non sprouted), 1 (sprouted) variable).
By doing the summary of this model I have this output :
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: R_ger_b ~ espece * traitement + (1 | pop)
Data: d
REML criterion at convergence: 2381.2
Scaled residuals:
Min 1Q Median 3Q Max
-2.0555 -0.8182 0.2951 0.6854 1.6788
Random effects:
Groups Name Variance Std.Dev.
pop (Intercept) 0.05762 0.24
Residual 1.12301 1.06
Number of obs: 800, groups: pop, 4
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 0.40383 0.20010 3.20699 2.018 0.13097
especemac -0.88576 0.28298 3.20699 -3.130 0.04756 *
traitementmi 0.16897 0.14987 790.00000 1.127 0.25989
traitementpeu -0.06180 0.14987 790.00000 -0.412 0.68018
traitementtemoin -0.06635 0.14987 790.00000 -0.443 0.65811
especemac:traitementmi -0.13861 0.21194 790.00000 -0.654 0.51330
especemac:traitementpeu 0.18556 0.21194 790.00000 0.876 0.38155
especemac:traitementtemoin 0.74192 0.21194 790.00000 3.501 0.00049 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) espcmc trtmntm trtmntp trtmntt espcmc:trtmntm espcmc:trtmntp
especemac -0.707
traitementm -0.374 0.265
traitementp -0.374 0.265 0.500
traitmnttmn -0.374 0.265 0.500 0.500
espcmc:trtmntm 0.265 -0.374 -0.707 -0.354 -0.354
espcmc:trtmntp 0.265 -0.374 -0.354 -0.707 -0.354 0.500
espcmc:trtmntt 0.265 -0.374 -0.354 -0.354 -0.707 0.500 0.500
But I don't really know how to calculate over dispersion there, I saw a solution about this problem on a poisson lmer but not in the case I'm working on.
Thank you for your help, I hope I asked my question well
Germain VITAL
I am trying to predict and graph models with species presence as the response. However I've run into the following problem: the ggpredict outputs are wildly different for the same data in glmer and glmmTMB. However, the estimates and AIC are very similar. These are simplified models only including date (which has been centered and scaled), which seems to be the most problematic to predict.
yntest<- glmer(MYOSOD.P~ jdate.z + I(jdate.z^2) + I(jdate.z^3) +
(1|area/SiteID), family = binomial, data = sodpYN)
> summary(yntest)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) + (1 | area/SiteID)
Data: sodpYN
AIC BIC logLik deviance df.resid
1260.8 1295.1 -624.4 1248.8 2246
Scaled residuals:
Min 1Q Median 3Q Max
-2.0997 -0.3218 -0.2013 -0.1238 9.4445
Random effects:
Groups Name Variance Std.Dev.
SiteID:area (Intercept) 1.6452 1.2827
area (Intercept) 0.6242 0.7901
Number of obs: 2252, groups: SiteID:area, 27; area, 9
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.96778 0.39190 -7.573 3.65e-14 ***
jdate.z -0.72258 0.17915 -4.033 5.50e-05 ***
I(jdate.z^2) 0.10091 0.08068 1.251 0.21102
I(jdate.z^3) 0.25025 0.08506 2.942 0.00326 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) jdat.z I(.^2)
jdate.z 0.078
I(jdat.z^2) -0.222 -0.154
I(jdat.z^3) -0.071 -0.910 0.199
The glmmTMB model + summary:
Tyntest<- glmmTMB(MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) +
(1|area/SiteID), family = binomial("logit"), data = sodpYN)
> summary(Tyntest)
Family: binomial ( logit )
Formula: MYOSOD.P ~ jdate.z + I(jdate.z^2) + I(jdate.z^3) + (1 | area/SiteID)
Data: sodpYN
AIC BIC logLik deviance df.resid
1260.8 1295.1 -624.4 1248.8 2246
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
SiteID:area (Intercept) 1.6490 1.2841
area (Intercept) 0.6253 0.7908
Number of obs: 2252, groups: SiteID:area, 27; area, 9
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -2.96965 0.39638 -7.492 6.78e-14 ***
jdate.z -0.72285 0.18250 -3.961 7.47e-05 ***
I(jdate.z^2) 0.10096 0.08221 1.228 0.21941
I(jdate.z^3) 0.25034 0.08662 2.890 0.00385 **
---
ggpredict outputs
testg<-ggpredict(yntest, terms ="jdate.z[all]")
> testg
# Predicted probabilities of MYOSOD.P
# x = jdate.z
x predicted std.error conf.low conf.high
-1.95 0.046 0.532 0.017 0.120
-1.51 0.075 0.405 0.036 0.153
-1.03 0.084 0.391 0.041 0.165
-0.58 0.072 0.391 0.035 0.142
-0.14 0.054 0.390 0.026 0.109
0.35 0.039 0.399 0.018 0.082
0.79 0.034 0.404 0.016 0.072
1.72 0.067 0.471 0.028 0.152
Adjusted for:
* SiteID = 0 (population-level)
* area = 0 (population-level)
Standard errors are on link-scale (untransformed).
testgTMB<- ggpredict(Tyntest, "jdate.z[all]")
> testgTMB
# Predicted probabilities of MYOSOD.P
# x = jdate.z
x predicted std.error conf.low conf.high
-1.95 0.444 0.826 0.137 0.801
-1.51 0.254 0.612 0.093 0.531
-1.03 0.136 0.464 0.059 0.280
-0.58 0.081 0.404 0.038 0.163
-0.14 0.054 0.395 0.026 0.110
0.35 0.040 0.402 0.019 0.084
0.79 0.035 0.406 0.016 0.074
1.72 0.040 0.444 0.017 0.091
Adjusted for:
* SiteID = NA (population-level)
* area = NA (population-level)
Standard errors are on link-scale (untransformed).
The estimates are completely different and I have no idea why.
I did try to use both the ggeffects package from CRAN and the developer version in case that changed anything. It did not. I am using the most up to date version of glmmTMB.
This is my first time asking a question here so please let me know if I should provide more information to help explain the problem.
I checked and the issue is the same when using predict instead of ggpredict, which would imply that it is a glmmTMB issue?
GLMER:
dayplotg<-expand.grid(jdate.z=seq(min(sodp$jdate.z), max(sodp$jdate.z), length=92))
Dfitg<-predict(yntest, re.form=NA, newdata=dayplotg, type='response')
dayplotg<-data.frame(dayplotg, Dfitg)
head(dayplotg)
> head(dayplotg)
jdate.z Dfitg
1 -1.953206 0.04581691
2 -1.912873 0.04889584
3 -1.872540 0.05195598
4 -1.832207 0.05497553
5 -1.791875 0.05793307
6 -1.751542 0.06080781
glmmTMB:
dayplot<-expand.grid(jdate.z=seq(min(sodp$jdate.z), max(sodp$jdate.z), length=92),
SiteID=NA,
area=NA)
Dfit<-predict(Tyntest, newdata=dayplot, type='response')
head(Dfit)
dayplot<-data.frame(dayplot, Dfit)
head(dayplot)
> head(dayplot)
jdate.z SiteID area Dfit
1 -1.953206 NA NA 0.4458236
2 -1.912873 NA NA 0.4251926
3 -1.872540 NA NA 0.4050944
4 -1.832207 NA NA 0.3855801
5 -1.791875 NA NA 0.3666922
6 -1.751542 NA NA 0.3484646
I contacted the ggpredict developer and figured out that if I used poly(jdate.z,3) rather than jdate.z + I(jdate.z^2) + I(jdate.z^3) in the glmmTMB model, the glmer and glmmTMB predictions were the same.
I'll leave this post up even though I was able to answer my own question in case someone else has this question later.
I ran an experiment in which participants were asked to pass a story along a 4 person 'transmission chain', a bit like the game Chinese Whispers. Person 1 reads the story and re-writes it for person 2, who does the same and it continues until all four people in the chain have read and reproduced the story. I'm interested it whether positive or negative information 'survives' better in the reproductions. I have modeled this two ways: one approach was to code each item in the original story as being either present (1) or absent (0) in the reproductions and model this using a logistic model:
survival.logit <- glmer(Present ~ Posn.c*mood.c*Valence.c + (1+Valence.c|mood.c/Chain.) + (1|Item), data = Survival.Analysis_restructureddata, family = binomial, glmerControl(optimizer="bobyqa", check.conv.grad=.makeCC("warning", 2e-3)))
The other approach is to count the number of each type of statement that is lost across the chains and model this data using a poisson or negative binomial model.
survival.count <- glmer.nb(Loss_across.Chain ~ Posn.c*mood.c*Valence.c + (1 + Valence.c|mood.c/Chain), data = FinalData_forpoisson, control = glmerControl(optimizer = "bobyqa", check.conv.grad = .makeCC("warning", 0.05)))
The fixed factors in each model are:
Posn.c - position in the chain (centered)
mood.c - mood condition (a between-groups factor, centered)
Valence.c - valence of the item (positive or negative, centered)
Both models return similar results with one key exception - the interaction between position in the chain and valence is not significant in the logistic model but is highly significant in the negative binomial model. Why might this be the case?? Graphing the data suggests that there is indeed an interaction, such that positive information is lost at a faster rate than negative across the chain.
Any help would be greatly appreciated!
Edit: Please see below the model output for the both models:
Logistic:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: Present ~ Posn.c * mood.c * Valence.c + (1 + Valence.c | mood.c/Chain.) + (1 | Item)
Data: Survival.Analysis_restructureddata
Control: glmerControl(optimizer = "bobyqa", check.conv.grad = .makeCC("warning", 0.002))
AIC BIC logLik deviance df.resid
5795.2 5895.4 -2882.6 5765.2 5873
Scaled residuals:
Min 1Q Median 3Q Max
-7.7595 -0.5744 0.1876 0.5450 5.5047
Random effects:
Groups Name Variance Std.Dev. Corr
Chain.:mood.c (Intercept) 7.550e-01 8.689e-01
Valence.c 1.366e+00 1.169e+00 0.47
Item (Intercept) 1.624e+00 1.274e+00
mood.c (Intercept) 3.708e-18 1.926e-09
Valence.c 7.777e-14 2.789e-07 1.00
Number of obs: 5888, groups: Chain.:mood.c, 92; Item, 16; mood.c, 2
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.43895 0.33331 1.317 0.1879
Posn.c -0.54789 0.03153 -17.378 <2e-16 ***
mood.c -0.23004 0.19436 -1.184 0.2366
Valence.c 1.64397 0.65245 2.520 0.0117 *
Posn.c:mood.c -0.07000 0.06141 -1.140 0.2543
Posn.c:Valence.c 0.06144 0.06301 0.975 0.3295
mood.c:Valence.c -0.05999 0.28123 -0.213 0.8311
Posn.c:mood.c:Valence.c 0.01498 0.12276 0.122 0.9029
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) Posn.c mood.c Vlnc.c Psn.:. Ps.:V. md.:V.
Posn.c -0.009
mood.c -0.001 0.009
Valence.c 0.025 -0.019 -0.002
Posn.c:md.c 0.001 0.007 -0.014 -0.001
Psn.c:Vlnc. -0.018 0.054 -0.002 -0.009 -0.024
md.c:Vlnc.c -0.002 -0.002 0.399 -0.001 -0.065 0.012
Psn.c:m.:V. -0.001 -0.024 -0.046 0.001 0.060 0.007 -0.019
Negative Binomial:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: Negative Binomial(5.0188) ( log )
Formula: Loss_across.Chain ~ Posn.c * mood.c * Valence.c + (1 + Valence.c | mood.c/Chain)
Data: FinalData_forpoisson
Control: ..3
AIC BIC logLik deviance df.resid
1901.3 1970.4 -935.7 1871.3 721
Scaled residuals:
Min 1Q Median 3Q Max
-1.3727 -0.7404 -0.5037 0.4609 7.3896
Random effects:
Groups Name Variance Std.Dev. Corr
Chain:mood.c (Intercept) 1.989e-13 4.46e-07
Valence.c 3.589e-13 5.99e-07 1.00
mood.c (Intercept) 0.000e+00 0.00e+00
Valence.c 1.690e-14 1.30e-07 NaN
Number of obs: 736, groups: Chain:mood.c, 92; mood.c, 2
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.19375 0.04797 -4.039 5.37e-05 ***
Posn.c -0.61020 0.04124 -14.798 < 2e-16 ***
mood.c 0.04862 0.09597 0.507 0.61242
Valence.c -0.27487 0.09594 -2.865 0.00417 **
Posn.c:mood.c -0.04232 0.08252 -0.513 0.60803
Posn.c:Valence.c 0.38080 0.08247 4.617 3.89e-06 ***
mood.c:Valence.c 0.13272 0.19194 0.691 0.48929
Posn.c:mood.c:Valence.c 0.05143 0.16504 0.312 0.75534
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) Posn.c mood.c Vlnc.c Psn.:. Ps.:V. md.:V.
Posn.c 0.491
mood.c -0.014 0.007
Valence.c 0.030 -0.090 -0.036
Posn.c:md.c 0.007 -0.008 0.492 -0.021
Psn.c:Vlnc. -0.090 0.063 -0.021 0.491 -0.030
md.c:Vlnc.c -0.036 -0.021 0.027 -0.014 -0.091 0.007
Psn.c:m.:V. -0.021 -0.030 -0.091 0.007 0.060 -0.008 0.492
I have seen questions about this on this forum (and have asked it myself before) but I haven't been able to solve my problem still, so I wil try again with more detailed information:
I have a data set with a binomial dependent variable, 3 categorical fixed effects and 2 categorical random effects (item and subject). I want to to a mixed effects model using glmer. Here is what I entered in R:
modelall<- glmer(moodR ~ group*context*condition + (1|subject) + ``(1|item), data=RprodHSNS, family="binomial")`
I then get the following warnings:
Warning messages:
1: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.02081 (tol = 0.001, component 11)
2: In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model is nearly unidentifiable: large eigenvalue ratio
- Rescale variables?`
This is what my summary looks like:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: moodR ~ group * context * condition + (1 | subject) + (1 | item)
Data: RprodHSNS`
AIC BIC logLik deviance df.resid
1400.0 1479.8 -686.0 1372.0 2195 `
Scaled residuals:
Min 1Q Median 3Q Max
-8.0346 -0.2827 -0.0152 0.2038 20.6578 `
Random effects:
Groups Name Variance Std.Dev.
item (Intercept) 1.475 1.215
subject (Intercept) 1.900 1.378
Number of obs: 2209, groups: item, 54; subject, 45
Fixed effects:`
Estimate Std. Error z value Pr(>|z|)`
(Intercept) -0.61448 42.93639 -0.014 0.988582
group1 -1.29254 42.93612 -0.030 0.975984
context1 0.09359 42.93587 0.002 0.998261
context2 -0.77262 0.22894 -3.375 0.000739***
condition1 4.99219 46.32672 0.108 0.914186
group1:context1 -0.17781 42.93585 -0.004 0.996696
group1:context2 -0.10551 0.09925 -1.063 0.287741
group1:condition1 -3.07516 46.32653 -0.066 0.947075
context1:condition1 -3.47541 46.32648 -0.075 0.940199
context2:condition1 -0.07293 0.22802 -0.320 0.749087
group1:context1:condition1 2.47882 46.32656 0.054 0.957328
group1:context2:condition1 0.30360 0.09900 3.067 0.002165 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) group1 cntxt1 cntxt2 cndtn1 grp1:cnt1 grp1:2 grp1:cnd1 cnt1:1 cnt2:1 g1:1:1
group1 -1.000
context1 -1.000 1.000
context2 0.001 0.000 -0.001
condition1 -0.297 0.297 0.297 0.000
grp1:cntxt1 1.000 -1.000 -1.000 0.001 -0.297
grp1:cntxt2 0.001 0.000 0.000 -0.123 0.000 0.000
grp1:cndtn1 0.297 -0.297 -0.297 -0.001 -1.000 0.297 0.000
cntxt1:cnd1 0.297 -0.297 -0.297 -0.001 -1.000 0.297 0.001 1.000
cntxt2:cnd1 0.000 0.000 -0.001 0.011 0.001 0.000 -0.197 -0.001 -0.001
grp1:cnt1:1 -0.297 0.297 0.297 0.001 1.000 -0.297 -0.001 -1.000 -1.000 0.001
grp1:cnt2:1 0.000 0.000 0.001 -0.198 0.000 -0.001 0.252 0.000 0.001 -0.136 0.000
Extremely high p-values, which does not seem to be possible.
In a previous post I read that one of the problems could be fixed by increasing the amount of iterations by inserting this bit in the command: glmerControl(optimizer="bobyqa", optCtrl = list(maxfun = 100000))
So here's the new command:
modelall<- glmer(moodR ~ group*context*condition + (1|subject) + (1|item), data=RprodHSNS, family="binomial", glmerControl(optimizer="bobyqa", optCtrl = list(maxfun = 100000)))
I get one less warning, but the other one is still there:
> Warning message:
In checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.005384 (tol = 0.001, component 7)
The summary still looks weird:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: moodR ~ group * context * condition + (1 | subject) + (1 | item)
Data: RprodHSNS
Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 1e+05))`
AIC BIC logLik deviance df.resid
1400.0 1479.8 -686.0 1372.0 2195
Scaled residuals:
Min 1Q Median 3Q Max
-8.0334 -0.2827 -0.0152 0.2038 20.6610
Random effects:
Groups Name Variance Std.Dev.
item (Intercept) 1.474 1.214
subject (Intercept) 1.901 1.379
Number of obs: 2209, groups: item, 54; subject, 45
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.64869 26.29368 -0.025 0.980317
group1 -1.25835 26.29352 -0.048 0.961830
context1 0.12772 26.29316 0.005 0.996124
context2 -0.77265 0.22886 -3.376 0.000735 ***
condition1 4.97325 22.80050 0.218 0.827335
group1:context1 -0.21198 26.29303 -0.008 0.993567
group1:context2 -0.10552 0.09924 -1.063 0.287681
group1:condition1 -3.05629 22.80004 -0.134 0.893365
context1:condition1 -3.45656 22.80017 -0.152 0.879500
context2:condition1 -0.07305 0.22794 -0.320 0.748612
group1:context1:condition1 2.45996 22.80001 0.108 0.914081
group1:context2:condition1 0.30347 0.09899 3.066 0.002172 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) group1 cntxt1 cntxt2 cndtn1 grp1:cnt1 grp1:2 grp1:cnd1 cnt1:1 cnt2:1 g1:1:1
group1 -1.000
context1 -1.000 1.000
context2 0.000 0.000 0.000
condition1 0.123 -0.123 -0.123 -0.001
grp1:cntxt1 1.000 -1.000 -1.000 0.001 0.123
grp1:cntxt2 0.001 0.000 0.000 -0.123 0.001 0.000
grp1:cndtn1 -0.123 0.123 0.123 0.000 -1.000 -0.123 -0.001
cntxt1:cnd1 -0.123 0.123 0.123 0.000 -1.000 -0.123 0.000 1.000
cntxt2:cnd1 0.000 0.000 0.000 0.011 -0.001 0.000 -0.197 0.001 0.001
grp1:cnt1:1 0.123 -0.123 -0.123 0.000 1.000 0.123 0.000 -1.000 -1.000 -0.001
grp1:cnt2:1 0.000 -0.001 0.001 -0.198 0.001 -0.001 0.252 -0.001 0.000 -0.136 0.000
Does anyone have an idea what I can do to solve this? Or tell me what this warning even means? Please explain in a way that an R-newbie like myself can understand!
Any help is much appreciated!
I have an example mixed lmer model with 8 predictors and I want to extract the names of the covariates, their coefficients, their standard errors and their p-values and place them into a matrix so I can write them out to a .csv.
I've extracted the first 3 into columns fine, but I can't figure out how to extract the p values. How do you do this? Is it a variation of vcov or getME()?
Here is what the model and summary look like:
mod <- lmer(outcome ~ predictor1 + etc...
summary(mod)
Generalized linear mixed model fit by the Laplace approximation
Formula: Freq ~ pm.lag0 + pm.lag1 + pm.lag2 + pm.lag3 + pm.lag4 + pm.lag5
+ temp13 + temp013 + rh13 + rh013 + (1 | county)
Data: dt
AIC BIC logLik deviance
3574 3636 -1775 3550
Random effects:
Groups Name Variance Std.Dev.
county (Intercept) 1.6131 1.2701
Number of obs: 1260, groups: county, 28
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.9356504 0.2614892 11.227 < 2e-16 ***
pm.lag0 0.0012996 0.0005469 2.376 0.017494 *
pm.lag1 0.0005021 0.0005631 0.892 0.372568
pm.lag2 0.0009126 0.0005596 1.631 0.102893
pm.lag3 -0.0007073 0.0005678 -1.246 0.212896
pm.lag4 0.0031566 0.0005316 5.939 2.88e-09 ***
pm.lag5 0.0019598 0.0005359 3.657 0.000255 ***
temp13 -0.0028040 0.0007315 -3.833 0.000126 ***
temp013 -0.0023532 0.0009683 -2.430 0.015087 *
rh13 0.0058769 0.0009909 5.931 3.01e-09 ***
rh013 -0.0028568 0.0006070 -4.706 2.52e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) pm.lg0 pm.lg1 pm.lg2 pm.lg3 pm.lg4 pm.lg5 temp13 tmp013 rh13
pm.lag0 -0.025
pm.lag1 -0.032 -0.154
pm.lag2 -0.021 0.044 -0.179
pm.lag3 0.002 0.003 0.033 -0.176
pm.lag4 0.016 0.102 -0.016 0.041 -0.176
pm.lag5 0.008 0.027 0.090 -0.002 0.040 -0.186
temp13 -0.316 0.026 0.027 0.004 -0.019 -0.055 -0.035
temp013 0.030 -0.015 0.051 0.015 -0.015 0.002 -0.069 -0.205
rh13 -0.350 0.043 0.078 0.056 -0.012 -0.042 -0.030 0.430 0.055
rh013 0.193 -0.008 -0.021 0.011 0.030 0.101 -0.028 -0.278 0.025 -0.524
I've gone ahead here and left a space for the p-value column and entered a colname for it, so this sample of code isn't operational:
mixed.results <- mod
cbind(names(fixef(mod)),as.numeric(fixef(mod)),sqrt(diag(vcov(mod))), ???? )
mixed.results
colnames(mixed.results) <- c("Pred", "Coef", "St. Error", "Pr(>|z|)")
mixed.results
write.csv(mixed.results, file="mixedmod1.csv")
Thank you!
This is just coef(summary(model)), I believe:
gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
data = cbpp, family = binomial)
cc <- coef(summary(gm1))
str(cc)
# num [1:4, 1:4] -1.376 -1.058 -1.196 -1.638 0.205 ...
# - attr(*, "dimnames")=List of 2
# ..$ : chr [1:4] "(Intercept)" "period2" "period3" "period4"
# ..$ : chr [1:4] "Estimate" "Std. Error" "z value" "Pr(>|z|)"
cc[,4] ## or cc[,"Pr(>|z)"] to be more explicit
# (Intercept) period2 period3 period4
#1.907080e-11 1.996120e-41 4.634385e-43 4.657952e-47
I used the development version of lme4 but I think this has worked for a while.