How to Interpret binomial GLMM results - r

I have a large dataset (24765 obs)
I am trying to look at how does cleaning method effect emergence success(ES).
I have several factors: beach(4 levels), cleaning method(3 levels) -->fixed
I also have a few random variables: Zone (128 levels),Year(18 years) and Index(24765)
This is an ORLE model to account for overdispersion.
My best fit model based on AIC scores is:
mod8a<-glmer(ES.test~beach+method+(1|Year)+(1|index),data=y5,weights=egg.total,family=binomial)
The summary showed:
summary(mod8a)#AIC=216732.9, same affect at every beach
Generalized linear mixed model fit by maximum likelihood (LaplaceApproximation) ['glmerMod']
Family: binomial ( logit )
Formula: ES.test ~ beach + method + (1 | Year) + (1 | index)
Data: y5
Weights: egg.total
AIC BIC logLik deviance df.resid
214834.2 214891.0 -107410.1 214820.2 24758
Scaled residuals:
Min 1Q Median 3Q Max
-1.92900 -0.09344 0.00957 0.14682 1.62327
Random effects:
Groups Name Variance Std.Dev.
index (Intercept) 1.6541 1.286
Year (Intercept) 0.6512 0.807
Number of obs: 24765, groups: index, 24765; Year, 19
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.65518 0.18646 3.514 0.000442 ***
beachHillsboro -0.06770 0.02143 -3.159 0.001583 **
beachHO/HA 0.31927 0.03716 8.591 < 2e-16 ***
methodHTL only 0.18106 0.02526 7.169 7.58e-13 ***
methodno clean 0.05989 0.03170 1.889 0.058853 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
(Intr) bchHll bHO/HA mtHTLo
beachHllsbr -0.002
beachHO/HA -0.054 0.047
mthdHTLonly -0.107 -0.242 0.355
methodnclen -0.084 -0.060 0.265 0.628
What is my "intercept" (as seen above)? I am missing levels of fixed factors, is that because R could not compute it?
I tested for Overdispersion:
overdisp_fun <- function(mod8a) {
+ ## number of variance parameters in
+ ## an n-by-n variance-covariance matrix
+ vpars <- function(m) {
+ nrow(m)*(nrow(m)+1)/2
+ }
+
+ model8a.df <- sum(sapply(VarCorr(mod8a),vpars))+length(fixef(mod8a))
+ rdf <- nrow(model.frame(mod8a))-model8a.df
+ rp <- residuals(mod8a,type="pearson")
+ Pearson.chisq <- sum(rp^2)
+ prat <- Pearson.chisq/rdf
+ pval <- pchisq(Pearson.chisq, df=rdf, lower.tail=FALSE)
+ c(chisq=Pearson.chisq,ratio=prat,rdf=rdf,p=pval)
+ }
> overdisp_fun(mod8a)
chisq ratio rdf p
2.064765e+03 8.339790e-02 2.475800e+04 1.000000e+00
This shows the plot of mod8a
I would like to know why I am getting such a curve and what it means
Lastly I did a multicomparion analysis using multcomp
ls1<- glht(mod8a, mcp(beach = "Tukey"))$linfct
ls2 <- glht(mod8a, mcp(method= "Tukey"))$linfct
summary(glht(mod8a, linfct = rbind(ls1, ls2)))
Simultaneous Tests for General Linear Hypotheses
Fit: glmer(formula = ES.test ~ beach + method + (1 | Year) + (1 |
index), data = y5, family = binomial, weights = egg.total)
Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
Hillsboro - FTL/P == 0 -0.06770 0.02143 -3.159 0.00821 **
HO/HA - FTL/P == 0 0.31927 0.03716 8.591 < 0.001 ***
HO/HA - Hillsboro == 0 0.38696 0.04201 9.211 < 0.001 ***
HTL only - HTL and SB == 0 0.18106 0.02526 7.169 < 0.001 ***
no clean - HTL and SB == 0 0.05989 0.03170 1.889 0.24469
no clean - HTL only == 0 -0.12117 0.02524 -4.800 < 0.001 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- single-step method)
At this point help with interpreting for analysis would help and be greatly appreciated. (Especially with that sigmoid curve for my residuals)

Related

Marginal Effects of conditional logit model in R using, "clogit," function

I am trying to figure out how to calculate the marginal effects of my model using the, "clogit," function in the survival package. The margins package does not seem to work with this type of model, but does work with "multinom" and "mclogit." However, I am investigating the affects of choice characteristics, and not individual characteristics, so it needs to be a conditional logit model. The mclogit function works with the margins package, but these results are widely different from the results using the clogit function, why is that? Any help calculating the marginal effects from the clogit function would be greatly appreciated.
mclogit output:
Call:
mclogit(formula = cbind(selected, caseID) ~ SysTEM + OWN + cost +
ENVIRON + NEIGH + save, data = atl)
Estimate Std. Error z value Pr(>|z|)
SysTEM 0.139965 0.025758 5.434 5.51e-08 ***
OWN 0.008931 0.026375 0.339 0.735
cost -0.103012 0.004215 -24.439 < 2e-16 ***
ENVIRON 0.675341 0.037104 18.201 < 2e-16 ***
NEIGH 0.419054 0.031958 13.112 < 2e-16 ***
save 0.532825 0.023399 22.771 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Null Deviance: 18380
Residual Deviance: 16670
Number of Fisher Scoring iterations: 4
Number of observations: 8364
clogit output:
Call:
coxph(formula = Surv(rep(1, 25092L), selected) ~ SysTEM + OWN +
cost + ENVIRON + NEIGH + save + strata(caseID), data = atl,
method = "exact")
n= 25092, number of events= 8364
coef exp(coef) se(coef) z Pr(>|z|)
SysTEM 0.133184 1.142461 0.034165 3.898 9.69e-05 ***
OWN -0.015884 0.984241 0.036346 -0.437 0.662
cost -0.179833 0.835410 0.005543 -32.442 < 2e-16 ***
ENVIRON 1.186329 3.275036 0.049558 23.938 < 2e-16 ***
NEIGH 0.658657 1.932195 0.042063 15.659 < 2e-16 ***
save 0.970051 2.638079 0.031352 30.941 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
exp(coef) exp(-coef) lower .95 upper .95
SysTEM 1.1425 0.8753 1.0685 1.2216
OWN 0.9842 1.0160 0.9166 1.0569
cost 0.8354 1.1970 0.8264 0.8445
ENVIRON 3.2750 0.3053 2.9719 3.6091
NEIGH 1.9322 0.5175 1.7793 2.0982
save 2.6381 0.3791 2.4809 2.8053
Concordance= 0.701 (se = 0.004 )
Rsquare= 0.103 (max possible= 0.688 )
Likelihood ratio test= 2740 on 6 df, p=<2e-16
Wald test = 2465 on 6 df, p=<2e-16
Score (logrank) test = 2784 on 6 df, p=<2e-16
margins output for mclogit
margins(model2A)
SysTEM OWN cost ENVIRON NEIGH save
0.001944 0.000124 -0.001431 0.00938 0.00582 0.0074
margins output for clogit
margins(model2A)
Error in match.arg(type) :
'arg' should be one of “risk”, “expected”, “lp”

How can I fit the randon effect in the gamm (or gamm4) in r?

I would like to know if my response variable (y) is significantly affected by a categorical variable ("x"), with two discrete values ("high" and "low").
This response value "y" has spatial autocorrelation, which are numerical spatial eigenvector, named as "MEM2" and "MEM5". I'm trying to fix these spatial eigenvectors into the function using a gamm4. But I don't know where I fit them into the formula.
I've made by two ways:
(1) First:
m2 <- gamm(y ~ x, random=list(MEM2=~1, MEM5=~1), family=poisson )
summary(m2)
summary(m2$gam)
The output
Family: poisson
Link function: log
Formula:
y ~ x
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.4574 0.2029 2.254 0.0300 *
xbaixa -0.6330 0.3338 -1.897 0.0655 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = 0.0625
Scale est. = 1 n = 40
(2) Second:
m2 <- gamm(y ~ x +s(MEM2) + s(MEM5),
random=list(MEM2=~1, MEM5=~1), family=poisson )
summary(m2)
summary(m2$gam)
The output:
Family: poisson
Link function: log
Formula:
y ~ x + s(MEM2) + s(MEM5)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.3434 0.2275 1.509 0.140
xbaixa -0.4438 0.3689 -1.203 0.237
Approximate significance of smooth terms:
edf Ref.df F p-value
s(MEM2) 1 1 1.343 0.254
s(MEM5) 1 1 0.994 0.325
R-sq.(adj) = 0.0567
Scale est. = 1 n = 40
Anyone knows if it's right? And which I should use?

How to do r square for glmmTMB negative binomial mixed model with zero-inflation in r

I made a zero-inflated negative binomial model with glmTMB as below
M2<- glmmTMB(psychological100~ (1|ID) + time*MNM01, data=mnmlong,
ziformula=~ (1|ID) + time*MNM01, family=nbinom2())
summary(M2)
Here is the output
Family: nbinom2 ( log )
Formula: psychological100 ~ (1 | ID) + time * MNM01
Zero inflation: ~(1 | ID) + time * MNM01
Data: mnmlong
AIC BIC logLik deviance df.resid
3507.0 3557.5 -1742.5 3485.0 714
Random effects:
Conditional model:
Groups Name Variance Std.Dev.
ID (Intercept) 0.2862 0.535
Number of obs: 725, groups: ID, 337
Zero-inflation model:
Groups Name Variance Std.Dev.
ID (Intercept) 0.5403 0.7351
Number of obs: 725, groups: ID, 337
Overdispersion parameter for nbinom2 family (): 3.14
Conditional model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 2.89772 0.09213 31.451 < 2e-16 ***
time -0.08724 0.01796 -4.858 1.18e-06 ***
MNM01 0.02094 0.12433 0.168 0.866
time:MNM01 -0.01193 0.02420 -0.493 0.622
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Zero-inflation model:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.29940 0.17298 -1.731 0.083478 .
time 0.12204 0.03338 3.656 0.000256 ***
MNM01 0.06771 0.24217 0.280 0.779790
time:MNM01 -0.02821 0.04462 -0.632 0.527282
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
I wanted to know the R square of the model and tried the following 2 methods but not successful
MuMIn::r.squaredGLMM(M2)
Error in r.squaredGLMM.glmmTMB(M2) : r.squaredGLMM cannot (yet)
handle 'glmmTMB' object with zero-inflation
performance::r2_zeroinflated(M2)
Error in residuals.glmmTMB(model, type = "pearson") : pearson
residuals are not implemented for models with zero-inflation or
variable dispersion
what do you advise me?
Try with the pseudo-R^2 based on a likelihood-ratio (MuMIn::r.squaredLR). You may need to provide a null model for comparison explicitly.

How to obtain the p-value of random variable in a lme4 mixed model?

I use lme4 in R to fit the mixed model
model <- glmer(responcevariable ~ fixedvariable1 + fixedvariable2 + fixedvariable3 + fixedvariable + (1|randomvariable1) + (1|randomvariable2) + (1|randomvariable3), data=Dataset, family=binomial)
And I get
Data: Dataset
AIC BIC logLik deviance df.resid
5005.8 5072.2 -2492.9 4985.8 5612
Scaled residuals:
Min 1Q Median 3Q Max
-3.5750 -0.4896 -0.2675 0.5618 11.6250
Random effects:
Groups Name Variance Std.Dev.
randomvariable1 (Intercept) 0.007826 0.08847
randomvariable2 (Intercept) 1.366346 1.16891
randomvariable3 (Intercept) 0.011879 0.10899
Number of obs: 5622, groups: randomvariable1, 49; randomvariable2, 5; randomvariable3, 4
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -11.98557 0.66851 -17.929 < 2e-16 ***
fixedvariable1a -0.31754 0.09732 -3.263 0.00110 **
fixedvariable1b 0.26805 0.08614 3.112 0.00186 **
fixedvariable2a -0.61098 0.09521 -6.417 1.39e-10 ***
fixedvariable2b -0.50402 0.10526 -4.788 1.68e-06 ***
fixedvariable3 7.57652 0.26308 28.799 < 2e-16 ***
fixedvariable4 -0.30746 0.07852 -3.915 9.03e-05 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
How can I know that the effect of random variable is significant?

How does plot(allEffects(mod)) in r treat categorical variables not included in the graphed interaction?

If I use the code:
plot(allEffects(AP18), multiline = TRUE, rescale.axis = FALSE, main = NULL)
for the following model:
AP18<-glmer(cbind(NPP,NPC)~Cond+OTTM+SlopeAp+EssCondEnd+SlopeAp*Cond+SlopeAp*OTTM+(1|Ind)+(1|Groupe),family=binomial, data=SElearn)
I get the following:
Cond has 3 levels (A, B and C). In the third plot, of the interaction between OTTM and SlopeAP, what is it doing with Cond? I ask because I am trying to recreate the graphs using predict. With a continuous variable that wasn't included in the model I would set it to 0, but with the categorical I don't know what to do. It is not set to the reference value (in this case A), because doing that does not give the same graph.
For reference, the model summary is:
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial ( logit )
Formula: cbind(NPP, NPC) ~ Cond + OTTM + SlopeAp + EssCondEnd + SlopeAp *
Cond + SlopeAp * OTTM + (1 | Ind) + (1 | Groupe)
Data: SElearn
Control: glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
AIC BIC logLik deviance df.resid
1023.1 1063.8 -500.5 1001.1 287
Scaled residuals:
Min 1Q Median 3Q Max
-3.4584 -0.9527 0.0458 0.8498 3.5794
Random effects:
Groups Name Variance Std.Dev.
Ind (Intercept) 3.338e-01 5.777e-01
Groupe (Intercept) 1.997e-15 4.468e-08
Number of obs: 298, groups: Ind, 20; Groupe, 4
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -1.535316 0.618425 -2.483 0.013042 *
CondB 0.937548 0.411961 2.276 0.022857 *
CondC 2.415791 0.402306 6.005 1.92e-09 ***
OTTMCBA 3.610364 1.085016 3.327 0.000876 ***
SlopeAp 15.657892 7.896060 1.983 0.047367 *
EssCondEnd 0.019554 0.006844 2.857 0.004275 **
CondB:SlopeAp -6.188813 4.297260 -1.440 0.149817
CondC:SlopeAp -14.062097 4.117263 -3.415 0.000637 ***
OTTMCBA:SlopeAp -35.422102 11.157396 -3.175 0.001500 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Thanks in advance!

Resources