#TREE DENSITY MODEL OPTIONS ##OPTION 1: Glmer, with negative binomial(theta = 1). Chose this orignally because this is what Kayleigh had done, but there are differences in random effect when compared to glmer.nb below
#OPTION 1#runnning a linear mixed model to test the effect of green space type on tree abundance, including logged sample area as a covariate because abudance is not rarefied modelgst_den0 <-glmer(tree_density_plant_ha ~ GreenSpace + (1|Plot), data= subsite_table, family ="negative.binomial"(theta =1))
boundary (singular) fit: see help('isSingular')
print(modelgst_den0) #Random effect is zero
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(1) ( log )
Formula: tree_density_plant_ha ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
1302.5191 1323.4401 -643.2596 1286.5191 93
Random effects:
Groups Name Std.Dev.
Plot (Intercept) 0
Number of obs: 101, groups: Plot, 22
Fixed Effects:
(Intercept) GreenSpaceInstitutional
5.11818 -0.20067
GreenSpacePark GreenSpacePublic Right-Of-Way
-0.05607 0.98157
GreenSpaceResidential GreenSpaceVacant Lot
0.24508 0.24802
optimizer (Nelder_Mead) convergence code: 0 (OK) ; 0 optimizer warnings; 1 lme4 warnings
#boundary (singular) fit: see help('isSingular') - the random effect variance is near-zeroVarCorr(modelgst_den0) #near-zero, so random effect is not contributing meaningfully
Groups Name Std.Dev.
Plot (Intercept) 0
lme4::isSingular(modelgst_den0, tol =1e-4)
[1] TRUE
#Random effect is singular, so remove#Diagnosticsplot(modelgst_den0, which =1)
shapiro.test(resid(modelgst_den0))
Shapiro-Wilk normality test
data: resid(modelgst_den0)
W = 0.98574, p-value = 0.3519
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.den0 <-emmeans(modelgst_den0, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.den0)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 167 43.3 Inf 100.5 277
Institutional 137 32.3 Inf 86.0 217
Park 158 42.3 Inf 93.4 267
Public Right-Of-Way 446 95.1 Inf 293.4 677
Residential 213 45.6 Inf 140.4 324
Vacant Lot 214 67.8 Inf 115.0 398
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 1.222 0.4290 Inf 1 0.572 0.9928
Commercial / Park 1.058 0.3940 Inf 1 0.150 1.0000
Commercial / (Public Right-Of-Way) 0.375 0.1260 Inf 1 -2.925 0.0403
Commercial / Residential 0.783 0.2630 Inf 1 -0.730 0.9783
Commercial / Vacant Lot 0.780 0.3190 Inf 1 -0.606 0.9906
Institutional / Park 0.865 0.3090 Inf 1 -0.404 0.9986
Institutional / (Public Right-Of-Way) 0.307 0.0977 Inf 1 -3.711 0.0028
Institutional / Residential 0.640 0.2040 Inf 1 -1.398 0.7282
Institutional / Vacant Lot 0.638 0.2530 Inf 1 -1.134 0.8671
Park / (Public Right-Of-Way) 0.354 0.1210 Inf 1 -3.028 0.0297
Park / Residential 0.740 0.2540 Inf 1 -0.878 0.9518
Park / Vacant Lot 0.738 0.3060 Inf 1 -0.732 0.9780
(Public Right-Of-Way) / Residential 2.089 0.6310 Inf 1 2.438 0.1431
(Public Right-Of-Way) / Vacant Lot 2.082 0.7960 Inf 1 1.920 0.3900
Residential / Vacant Lot 0.997 0.3810 Inf 1 -0.008 1.0000
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
##OPTION 2: Glmer.nb, where theta is set by package. I do not get the singularity warnings with this model.
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.den <-emmeans(modelgst_den, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.den)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 165 29.1 Inf 117.0 234
Institutional 135 21.7 Inf 98.5 185
Park 159 28.9 Inf 111.4 227
Public Right-Of-Way 433 66.3 Inf 320.7 584
Residential 212 30.6 Inf 159.8 282
Vacant Lot 214 45.8 Inf 140.4 325
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 1.224 0.2860 Inf 1 0.867 0.9543
Commercial / Park 1.039 0.2600 Inf 1 0.154 1.0000
Commercial / (Public Right-Of-Way) 0.382 0.0873 Inf 1 -4.212 0.0004
Commercial / Residential 0.779 0.1740 Inf 1 -1.114 0.8756
Commercial / Vacant Lot 0.774 0.2120 Inf 1 -0.938 0.9368
Institutional / Park 0.849 0.2040 Inf 1 -0.681 0.9841
Institutional / (Public Right-Of-Way) 0.312 0.0671 Inf 1 -5.414 <.0001
Institutional / Residential 0.637 0.1350 Inf 1 -2.132 0.2707
Institutional / Vacant Lot 0.632 0.1670 Inf 1 -1.737 0.5073
Park / (Public Right-Of-Way) 0.367 0.0874 Inf 1 -4.210 0.0004
Park / Residential 0.750 0.1720 Inf 1 -1.255 0.8096
Park / Vacant Lot 0.744 0.2070 Inf 1 -1.062 0.8963
(Public Right-Of-Way) / Residential 2.041 0.4170 Inf 1 3.492 0.0064
(Public Right-Of-Way) / Vacant Lot 2.026 0.5280 Inf 1 2.710 0.0733
Residential / Vacant Lot 0.993 0.2540 Inf 1 -0.028 1.0000
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
##OPTION 3: glm.nb - Finally, here is the model without random effecs, which I was using before, but now that glmer.nb does show random effects, I am not sure. I also get the warning because this is negative binomial on non-count data.
modelgst_den1 <-glm.nb(tree_density_plant_ha ~ GreenSpace, data = subsite_table)summary(modelgst_den1)
Call:
glm.nb(formula = tree_density_plant_ha ~ GreenSpace, data = subsite_table,
init.theta = 2.237817151, link = log)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 5.11818 0.17375 29.457 < 2e-16 ***
GreenSpaceInstitutional -0.20067 0.23542 -0.852 0.394
GreenSpacePark -0.05607 0.25012 -0.224 0.823
GreenSpacePublic Right-Of-Way 0.98157 0.22495 4.363 1.28e-05 ***
GreenSpaceResidential 0.24508 0.22520 1.088 0.276
GreenSpaceVacant Lot 0.24802 0.27449 0.904 0.366
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for Negative Binomial(2.2378) family taken to be 1)
Null deviance: 151.48 on 100 degrees of freedom
Residual deviance: 108.17 on 95 degrees of freedom
AIC: 1270.7
Number of Fisher Scoring iterations: 1
Theta: 2.238
Std. Err.: 0.299
2 x log-likelihood: -1256.717
# MODEL DIAGNOSTICSplot(modelgst_den1, which =1)
shapiro.test(resid(modelgst_den1))
Shapiro-Wilk normality test
data: resid(modelgst_den1)
W = 0.98557, p-value = 0.3421
#When comparing with the glmer.nb, this looks a bit better? But similar, so let me know what you think#check effect of green space type on tree density using model outputsAnova(modelgst_den1)
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.den1 <-emmeans(modelgst_den1, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.den1)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 167 29.0 Inf 119 235
Institutional 137 21.7 Inf 100 187
Park 158 28.4 Inf 111 225
Public Right-Of-Way 446 63.7 Inf 337 590
Residential 213 30.6 Inf 161 283
Vacant Lot 214 45.5 Inf 141 325
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 1.222 0.2880 Inf 1 0.852 0.9575
Commercial / Park 1.058 0.2650 Inf 1 0.224 0.9999
Commercial / (Public Right-Of-Way) 0.375 0.0843 Inf 1 -4.363 0.0002
Commercial / Residential 0.783 0.1760 Inf 1 -1.088 0.8863
Commercial / Vacant Lot 0.780 0.2140 Inf 1 -0.904 0.9457
Institutional / Park 0.865 0.2080 Inf 1 -0.602 0.9909
Institutional / (Public Right-Of-Way) 0.307 0.0655 Inf 1 -5.534 <.0001
Institutional / Residential 0.640 0.1370 Inf 1 -2.084 0.2957
Institutional / Vacant Lot 0.638 0.1690 Inf 1 -1.691 0.5376
Park / (Public Right-Of-Way) 0.354 0.0814 Inf 1 -4.516 0.0001
Park / Residential 0.740 0.1700 Inf 1 -1.309 0.7800
Park / Vacant Lot 0.738 0.2050 Inf 1 -1.092 0.8847
(Public Right-Of-Way) / Residential 2.089 0.4230 Inf 1 3.640 0.0037
(Public Right-Of-Way) / Vacant Lot 2.082 0.5330 Inf 1 2.865 0.0479
Residential / Vacant Lot 0.997 0.2560 Inf 1 -0.011 1.0000
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
#In conclusion, for tree density, I am leaning towards glmer.nb. Anova/pairwise results are similar for all, although glm.nb is the most significant
#TREE ABUNDANCE MODEL OPTIONS ##OPTION 1: Glmer, with negative binomial(theta = 1). Chose this orignally because this is what Kayleigh had done, but there are differences in random effect when compared to glmer.nb below
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(1) ( log )
Formula: tree_count ~ GreenSpace + log(area_ha) + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
1186.7657 1210.3018 -584.3829 1168.7657 92
Random effects:
Groups Name Std.Dev.
Plot (Intercept) 1.43e-05
Number of obs: 101, groups: Plot, 22
Fixed Effects:
(Intercept) GreenSpaceInstitutional
3.7386 0.4249
GreenSpacePark GreenSpacePublic Right-Of-Way
0.8049 1.0076
GreenSpaceResidential GreenSpaceVacant Lot
1.4172 0.8651
log(area_ha)
0.8226
optimizer (Nelder_Mead) convergence code: 0 (OK) ; 0 optimizer warnings; 1 lme4 warnings
#boundary (singular) fit: see help('isSingular') - the random effect variance is near-zeroVarCorr(modelgst_abu0) #near-zero, so random effect is not contributing meaningfully
Groups Name Std.Dev.
Plot (Intercept) 1.4298e-05
lme4::isSingular(modelgst_abu0, tol =1e-4) #Random effect is singular
[1] TRUE
#Diagnosticsplot(modelgst_abu0, which =1)
shapiro.test(resid(modelgst_abu0))
Shapiro-Wilk normality test
data: resid(modelgst_abu0)
W = 0.98318, p-value = 0.2275
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.abu0 <-emmeans(modelgst_abu0, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.abu0)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 94.6 35.3 Inf 45.5 196
Institutional 144.6 37.3 Inf 87.3 240
Park 211.5 67.7 Inf 112.9 396
Public Right-Of-Way 259.0 56.1 Inf 169.3 396
Residential 390.1 91.7 Inf 246.0 619
Vacant Lot 224.6 105.0 Inf 90.1 560
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 0.654 0.258 Inf 1 -1.077 0.8905
Commercial / Park 0.447 0.175 Inf 1 -2.058 0.3094
Commercial / (Public Right-Of-Way) 0.365 0.166 Inf 1 -2.222 0.2276
Commercial / Residential 0.242 0.120 Inf 1 -2.858 0.0489
Commercial / Vacant Lot 0.421 0.180 Inf 1 -2.021 0.3301
Institutional / Park 0.684 0.252 Inf 1 -1.031 0.9076
Institutional / (Public Right-Of-Way) 0.558 0.194 Inf 1 -1.677 0.5471
Institutional / Residential 0.371 0.139 Inf 1 -2.643 0.0872
Institutional / Vacant Lot 0.644 0.301 Inf 1 -0.940 0.9360
Park / (Public Right-Of-Way) 0.817 0.329 Inf 1 -0.503 0.9961
Park / Residential 0.542 0.237 Inf 1 -1.398 0.7282
Park / Vacant Lot 0.942 0.427 Inf 1 -0.133 1.0000
(Public Right-Of-Way) / Residential 0.664 0.205 Inf 1 -1.330 0.7686
(Public Right-Of-Way) / Vacant Lot 1.153 0.620 Inf 1 0.265 0.9998
Residential / Vacant Lot 1.737 1.010 Inf 1 0.949 0.9338
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
##OPTION 2: Glmer.nb, where theta is set by package. I do not get the singularity warnings with this model
modelgst_abu <-glmer.nb(tree_count ~ GreenSpace + (1|Plot), data = subsite_table)print(modelgst_abu)
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(1.3138) ( log )
Formula: tree_count ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
1219.348 1240.269 -601.674 1203.348 93
Random effects:
Groups Name Std.Dev.
Plot (Intercept) 0.1591
Number of obs: 101, groups: Plot, 22
Fixed Effects:
(Intercept) GreenSpaceInstitutional
3.051 1.566
GreenSpacePark GreenSpacePublic Right-Of-Way
1.550 2.767
GreenSpaceResidential GreenSpaceVacant Lot
3.585 0.203
summary(modelgst_abu)
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(1.3138) ( log )
Formula: tree_count ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
1219.3 1240.3 -601.7 1203.3 93
Scaled residuals:
Min 1Q Median 3Q Max
-1.1402 -0.7221 -0.1814 0.3948 3.3922
Random effects:
Groups Name Variance Std.Dev.
Plot (Intercept) 0.02531 0.1591
Number of obs: 101, groups: Plot, 22
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.0508 0.2448 12.461 < 2e-16 ***
GreenSpaceInstitutional 1.5660 0.3150 4.971 6.65e-07 ***
GreenSpacePark 1.5502 0.3438 4.509 6.50e-06 ***
GreenSpacePublic Right-Of-Way 2.7670 0.3055 9.057 < 2e-16 ***
GreenSpaceResidential 3.5846 0.3020 11.871 < 2e-16 ***
GreenSpaceVacant Lot 0.2030 0.3716 0.546 0.585
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) GrnSpI GrnSpP GSPR-O GrnSpR
GrnSpcInstt -0.695
GreenSpcPrk -0.710 0.487
GrnSpPR-O-W -0.783 0.556 0.563
GrnSpcRsdnt -0.768 0.571 0.548 0.617
GrnSpcVcntL -0.589 0.463 0.418 0.473 0.485
#Error - potentially due to adding log(area_ha)? When I remove area, the model runs without warnings.#I want to stay consistent with other models, so what do you suggest?# Abundance MODEL DIAGNOSTICSplot(modelgst_abu, which =1)
shapiro.test(resid(modelgst_abu))
Shapiro-Wilk normality test
data: resid(modelgst_abu)
W = 0.99151, p-value = 0.7794
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.abu <-emmeans(modelgst_abu, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.abu)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 21.1 5.17 Inf 13.1 34.1
Institutional 101.2 23.10 Inf 64.7 158.2
Park 99.6 24.10 Inf 62.0 160.0
Public Right-Of-Way 336.2 63.90 Inf 231.7 488.0
Residential 761.6 148.00 Inf 520.9 1113.5
Vacant Lot 25.9 7.81 Inf 14.3 46.7
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio
Commercial / Institutional 0.2089 0.06580 Inf 1 -4.971
Commercial / Park 0.2122 0.07300 Inf 1 -4.509
Commercial / (Public Right-Of-Way) 0.0629 0.01920 Inf 1 -9.057
Commercial / Residential 0.0277 0.00838 Inf 1 -11.871
Commercial / Vacant Lot 0.8163 0.30300 Inf 1 -0.546
Institutional / Park 1.0159 0.34000 Inf 1 0.047
Institutional / (Public Right-Of-Way) 0.3009 0.08800 Inf 1 -4.108
Institutional / Residential 0.1328 0.03800 Inf 1 -7.056
Institutional / Vacant Lot 3.9079 1.40000 Inf 1 3.797
Park / (Public Right-Of-Way) 0.2962 0.09040 Inf 1 -3.985
Park / Residential 0.1308 0.04040 Inf 1 -6.580
Park / Vacant Lot 3.8467 1.49000 Inf 1 3.485
(Public Right-Of-Way) / Residential 0.4415 0.11700 Inf 1 -3.074
(Public Right-Of-Way) / Vacant Lot 12.9874 4.58000 Inf 1 7.279
Residential / Vacant Lot 29.4188 10.20000 Inf 1 9.742
p.value
<.0001
0.0001
<.0001
<.0001
0.9942
1.0000
0.0006
<.0001
0.0020
0.0010
<.0001
0.0065
0.0258
<.0001
<.0001
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
##OPTION 3: glm.nb - Finally, here is the model without random effecs, which I was using before, but now that glmer.nb does show random effects, I am not sure
modelgst_abu1 <-glm.nb(tree_count ~ GreenSpace +log(area_ha), data = subsite_table)summary(modelgst_abu1)
Call:
glm.nb(formula = tree_count ~ GreenSpace + log(area_ha), data = subsite_table,
init.theta = 2.211662881, link = log)
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.71208 0.18812 19.732 < 2e-16 ***
GreenSpaceInstitutional 0.46022 0.24957 1.844 0.065179 .
GreenSpacePark 0.82848 0.26084 3.176 0.001492 **
GreenSpacePublic Right-Of-Way 1.03564 0.27231 3.803 0.000143 ***
GreenSpaceResidential 1.44621 0.28783 5.025 5.05e-07 ***
GreenSpaceVacant Lot 0.89869 0.31329 2.869 0.004123 **
log(area_ha) 0.82140 0.07792 10.541 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for Negative Binomial(2.2117) family taken to be 1)
Null deviance: 483.90 on 100 degrees of freedom
Residual deviance: 108.21 on 94 degrees of freedom
AIC: 1157.6
Number of Fisher Scoring iterations: 1
Theta: 2.212
Std. Err.: 0.311
2 x log-likelihood: -1141.618
# Abundance MODEL DIAGNOSTICSplot(modelgst_abu1, which =1)
shapiro.test(resid(modelgst_abu1))
Shapiro-Wilk normality test
data: resid(modelgst_abu1)
W = 0.98413, p-value = 0.2681
#tukey test to check pairwise comparisons of abundances of each green space typePairwise.abu1 <-emmeans(modelgst_abu1, pairwise ~ GreenSpace, type ="response")#summarizing pairwise differences across green space typessummary(Pairwise.abu1)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 92 20.0 Inf 60.1 141
Institutional 146 26.5 Inf 102.1 208
Park 211 43.8 Inf 140.1 317
Public Right-Of-Way 259 37.8 Inf 194.7 345
Residential 391 59.7 Inf 289.5 527
Vacant Lot 226 72.9 Inf 120.0 425
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 0.631 0.1580 Inf 1 -1.844 0.4373
Commercial / Park 0.437 0.1140 Inf 1 -3.176 0.0187
Commercial / (Public Right-Of-Way) 0.355 0.0967 Inf 1 -3.803 0.0020
Commercial / Residential 0.235 0.0678 Inf 1 -5.025 <.0001
Commercial / Vacant Lot 0.407 0.1280 Inf 1 -2.869 0.0474
Institutional / Park 0.692 0.1710 Inf 1 -1.489 0.6713
Institutional / (Public Right-Of-Way) 0.562 0.1350 Inf 1 -2.389 0.1599
Institutional / Residential 0.373 0.0948 Inf 1 -3.882 0.0015
Institutional / Vacant Lot 0.645 0.2050 Inf 1 -1.377 0.7412
Park / (Public Right-Of-Way) 0.813 0.2140 Inf 1 -0.788 0.9697
Park / Residential 0.539 0.1490 Inf 1 -2.229 0.2243
Park / Vacant Lot 0.932 0.2990 Inf 1 -0.219 0.9999
(Public Right-Of-Way) / Residential 0.663 0.1360 Inf 1 -2.000 0.3419
(Public Right-Of-Way) / Vacant Lot 1.147 0.4240 Inf 1 0.371 0.9991
Residential / Vacant Lot 1.729 0.6730 Inf 1 1.406 0.7235
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
#NOTE: Pairwise comparisons are very different for glmer vs. glmer.nb vs glm.nb, I am very confused
#SPECIES RICHNESS MODEL OPTIONS ##Since species richness is rarefied, it is not count data. Am I still able to do negative binomial? ##OPTION 1: with negative binomial(theta = 1) ##do not need to include area as a covariate because we already calculated rarefied diversity metrics based on sample completeness
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(1) ( log )
Formula: Cov_rich ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
875.7234 896.6444 -429.8617 859.7234 93
Random effects:
Groups Name Std.Dev.
Plot (Intercept) 0
Number of obs: 101, groups: Plot, 22
Fixed Effects:
(Intercept) GreenSpaceInstitutional
2.0492 1.0454
GreenSpacePark GreenSpacePublic Right-Of-Way
0.9426 1.9757
GreenSpaceResidential GreenSpaceVacant Lot
2.0732 -0.1994
optimizer (Nelder_Mead) convergence code: 0 (OK) ; 0 optimizer warnings; 1 lme4 warnings
#boundary (singular) fit: see help('isSingular') - the random effect variance is near-zeroVarCorr(modelgst_sr0) #near-zero, so random effect is not contributing meaningfully
Groups Name Std.Dev.
Plot (Intercept) 0
lme4::isSingular(modelgst_sr0, tol =1e-4) #Random effect is singular
[1] TRUE
plot(modelgst_sr0, which =1)
shapiro.test(resid(modelgst_sr0))
Shapiro-Wilk normality test
data: resid(modelgst_sr0)
W = 0.97559, p-value = 0.05772
Pairwise.ens <-emmeans(modelgst_ens, pairwise ~ GreenSpace, type ="response")summary(Pairwise.ens)
$emmeans
GreenSpace emmean SE df lower.CL upper.CL
Commercial 5.19 2.03 94.2 1.162 9.22
Institutional 14.63 1.85 93.2 10.949 18.30
Park 11.20 2.10 94.6 7.037 15.37
Public Right-Of-Way 17.93 1.67 91.4 14.607 21.26
Residential 14.97 1.67 91.4 11.643 18.29
Vacant Lot 5.45 2.48 95.0 0.522 10.38
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Commercial - Institutional -9.437 2.62 78.2 -3.596 0.0072
Commercial - Park -6.015 2.81 82.0 -2.137 0.2790
Commercial - (Public Right-Of-Way) -12.744 2.52 79.2 -5.059 <.0001
Commercial - Residential -9.780 2.52 79.2 -3.882 0.0028
Commercial - Vacant Lot -0.262 3.09 80.5 -0.085 1.0000
Institutional - Park 3.422 2.71 83.5 1.263 0.8039
Institutional - (Public Right-Of-Way) -3.307 2.38 77.1 -1.390 0.7327
Institutional - Residential -0.343 2.38 77.1 -0.144 1.0000
Institutional - Vacant Lot 9.174 2.99 82.1 3.065 0.0338
Park - (Public Right-Of-Way) -6.729 2.58 79.6 -2.612 0.1062
Park - Residential -3.765 2.58 79.6 -1.462 0.6894
Park - Vacant Lot 5.753 3.17 85.3 1.816 0.4610
(Public Right-Of-Way) - Residential 2.964 2.24 74.5 1.321 0.7725
(Public Right-Of-Way) - Vacant Lot 12.482 2.90 82.7 4.308 0.0006
Residential - Vacant Lot 9.518 2.90 82.7 3.285 0.0181
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 6 estimates
##OPTION 2: Glmer.nb, where theta is set by package. I do not get the singularity warnings with this model, but do get the warnings for non-count data
modelgst_ens_glmernb <-glmer.nb(Cov_q1 ~ GreenSpace + (1|Plot), data = subsite_table)#Again, warnings due to non count datasummary(modelgst_ens_glmernb) #random effects are not zero
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Negative Binomial(3.9374) ( log )
Formula: Cov_q1 ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
673.5 694.4 -328.8 657.5 93
Scaled residuals:
Min 1Q Median 3Q Max
-1.6036 -0.6572 -0.1372 0.6647 2.5985
Random effects:
Groups Name Variance Std.Dev.
Plot (Intercept) 0.04965 0.2228
Number of obs: 101, groups: Plot, 22
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.56506 0.18446 8.485 < 2e-16 ***
GreenSpaceInstitutional 1.08677 0.22384 4.855 1.20e-06 ***
GreenSpacePark 0.80937 0.24067 3.363 0.000771 ***
GreenSpacePublic Right-Of-Way 1.29374 0.21467 6.027 1.67e-09 ***
GreenSpaceResidential 1.11093 0.21580 5.148 2.63e-07 ***
GreenSpaceVacant Lot 0.01055 0.28434 0.037 0.970401
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) GrnSpI GrnSpP GSPR-O GrnSpR
GrnSpcInstt -0.761
GreenSpcPrk -0.712 0.582
GrnSpPR-O-W -0.802 0.659 0.617
GrnSpcRsdnt -0.795 0.649 0.615 0.686
GrnSpcVcntL -0.601 0.482 0.446 0.512 0.507
Pairwise.ensnb <-emmeans(modelgst_ens_glmernb, pairwise ~ GreenSpace, type ="response")summary(Pairwise.ensnb)
$emmeans
GreenSpace response SE df asymp.LCL asymp.UCL
Commercial 4.78 0.882 Inf 3.33 6.87
Institutional 14.18 2.070 Inf 10.66 18.87
Park 10.74 1.820 Inf 7.71 14.98
Public Right-Of-Way 17.44 2.250 Inf 13.55 22.45
Residential 14.53 1.910 Inf 11.22 18.80
Vacant Lot 4.83 1.100 Inf 3.09 7.55
Confidence level used: 0.95
Intervals are back-transformed from the log scale
$contrasts
contrast ratio SE df null z.ratio p.value
Commercial / Institutional 0.337 0.0755 Inf 1 -4.855 <.0001
Commercial / Park 0.445 0.1070 Inf 1 -3.363 0.0100
Commercial / (Public Right-Of-Way) 0.274 0.0589 Inf 1 -6.027 <.0001
Commercial / Residential 0.329 0.0711 Inf 1 -5.148 <.0001
Commercial / Vacant Lot 0.990 0.2810 Inf 1 -0.037 1.0000
Institutional / Park 1.320 0.2810 Inf 1 1.302 0.7839
Institutional / (Public Right-Of-Way) 0.813 0.1470 Inf 1 -1.141 0.8641
Institutional / Residential 0.976 0.1800 Inf 1 -0.131 1.0000
Institutional / Vacant Lot 2.934 0.7740 Inf 1 4.079 0.0006
Park / (Public Right-Of-Way) 0.616 0.1240 Inf 1 -2.413 0.1516
Park / Residential 0.740 0.1490 Inf 1 -1.496 0.6666
Park / Vacant Lot 2.223 0.6200 Inf 1 2.865 0.0479
(Public Right-Of-Way) / Residential 1.201 0.2050 Inf 1 1.072 0.8925
(Public Right-Of-Way) / Vacant Lot 3.608 0.9160 Inf 1 5.054 <.0001
Residential / Vacant Lot 3.005 0.7670 Inf 1 4.311 0.0002
P value adjustment: tukey method for comparing a family of 6 estimates
Tests are performed on the log scale
##OPTION 3: try Gamma GLMM with log link
modelgst_ens_gamma <-glmer(Cov_q1 ~ GreenSpace + (1| Plot), data = subsite_table, family =Gamma(link ="log"))summary(modelgst_ens_gamma) #Random effect is small
Generalized linear mixed model fit by maximum likelihood (Laplace
Approximation) [glmerMod]
Family: Gamma ( log )
Formula: Cov_q1 ~ GreenSpace + (1 | Plot)
Data: subsite_table
AIC BIC logLik -2*log(L) df.resid
668.4 689.3 -326.2 652.4 93
Scaled residuals:
Min 1Q Median 3Q Max
-1.5899 -0.6317 -0.1469 0.6302 2.5609
Random effects:
Groups Name Variance Std.Dev.
Plot (Intercept) 0.07615 0.2759
Residual 0.33569 0.5794
Number of obs: 101, groups: Plot, 22
Fixed effects:
Estimate Std. Error t value Pr(>|z|)
(Intercept) 1.50418 0.17866 8.419 < 2e-16 ***
GreenSpaceInstitutional 1.13054 0.21241 5.322 1.02e-07 ***
GreenSpacePark 0.82831 0.22831 3.628 0.000286 ***
GreenSpacePublic Right-Of-Way 1.34044 0.20232 6.625 3.47e-11 ***
GreenSpaceResidential 1.14824 0.20208 5.682 1.33e-08 ***
GreenSpaceVacant Lot 0.06252 0.25014 0.250 0.802620
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) GrnSpI GrnSpP GSPR-O GrnSpR
GrnSpcInstt -0.648
GreenSpcPrk -0.612 0.492
GrnSpPR-O-W -0.695 0.578 0.540
GrnSpcRsdnt -0.688 0.557 0.547 0.613
GrnSpcVcntL -0.543 0.436 0.405 0.484 0.476
#Residualsresid_gamma <-residuals(modelgst_ens_gamma, type ="pearson")qqnorm(resid_gamma); qqline(resid_gamma)
Pairwise.eve <-emmeans(modelgst_eve, pairwise ~ GreenSpace, type ="response")summary(Pairwise.eve)
$emmeans
GreenSpace emmean SE df lower.CL upper.CL
Commercial 0.622 0.0589 94.3 0.505 0.739
Institutional 0.790 0.0537 93.4 0.683 0.896
Park 0.802 0.0609 94.6 0.681 0.923
Public Right-Of-Way 0.864 0.0486 91.8 0.767 0.960
Residential 0.748 0.0486 91.8 0.651 0.844
Vacant Lot 0.593 0.0721 95.0 0.450 0.736
Degrees-of-freedom method: kenward-roger
Confidence level used: 0.95
$contrasts
contrast estimate SE df t.ratio p.value
Commercial - Institutional -0.1680 0.0763 78.2 -2.201 0.2492
Commercial - Park -0.1801 0.0819 82.1 -2.200 0.2490
Commercial - (Public Right-Of-Way) -0.2421 0.0733 79.3 -3.304 0.0173
Commercial - Residential -0.1260 0.0733 79.3 -1.720 0.5229
Commercial - Vacant Lot 0.0289 0.0897 80.6 0.322 0.9995
Institutional - Park -0.0121 0.0788 83.6 -0.153 1.0000
Institutional - (Public Right-Of-Way) -0.0741 0.0692 77.2 -1.071 0.8914
Institutional - Residential 0.0420 0.0692 77.2 0.606 0.9903
Institutional - Vacant Lot 0.1969 0.0871 82.3 2.261 0.2219
Park - (Public Right-Of-Way) -0.0620 0.0749 79.7 -0.828 0.9615
Park - Residential 0.0541 0.0749 79.7 0.721 0.9788
Park - Vacant Lot 0.2090 0.0921 85.5 2.269 0.2184
(Public Right-Of-Way) - Residential 0.1161 0.0653 74.6 1.778 0.4860
(Public Right-Of-Way) - Vacant Lot 0.2710 0.0843 82.8 3.216 0.0221
Residential - Vacant Lot 0.1549 0.0843 82.8 1.838 0.4475
Degrees-of-freedom method: kenward-roger
P value adjustment: tukey method for comparing a family of 6 estimates
##OPTION 2: glmmTMBm with logit link
#Try beta regression, mixed effects# Small constant to shrink 0s and 1s inward, because beta regression only handles values between 0 and 1. eps <-0.001subsite_table$Cov_pie_adj <- subsite_table$Cov_pie# Shrink 0s up to epssubsite_table$Cov_pie_adj[subsite_table$Cov_pie_adj ==0] <- epsmodelgst_eve_beta <-glmmTMB(Cov_pie_adj ~ GreenSpace + (1| Plot), family =beta_family(link ="logit"), data = subsite_table)summary(modelgst_eve_beta) #Random effects not zero
#Check model fit# Simulate residuals from the beta GLMMsim_res1 <-simulateResiduals(fittedModel = modelgst_eve_beta)# Plot residual diagnosticsplot(sim_res1)
# Perform formal tests for uniformity, dispersion, zero-inflation etc.testUniformity(sim_res1)
Asymptotic one-sample Kolmogorov-Smirnov test
data: simulationOutput$scaledResiduals
D = 0.25719, p-value = 3.149e-06
alternative hypothesis: two-sided
testDispersion(sim_res1)
DHARMa nonparametric dispersion test via sd of residuals fitted vs.
simulated
data: simulationOutput
dispersion = 0.72351, p-value = 0.008
alternative hypothesis: two.sided
# Diagnostics with DHARMasim_res <-simulateResiduals(modelgst_eve_beta_01)plot(sim_res)
testUniformity(sim_res)
Asymptotic one-sample Kolmogorov-Smirnov test
data: simulationOutput$scaledResiduals
D = 0.13406, p-value = 0.05301
alternative hypothesis: two-sided
testDispersion(sim_res)
DHARMa nonparametric dispersion test via sd of residuals fitted vs.
simulated
data: simulationOutput
dispersion = 1.0927, p-value = 0.672
alternative hypothesis: two.sided