lattice theme set by effectsTheme()
See ?effectsTheme for details.
plot(lizardsObs ~ earth , data = volcanoisland)
fit<-glm(lizardsObs ~ earth + windObs , data = volcanoisland, family = binomial)
Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(fit)
Call:
glm(formula = lizardsObs ~ earth + windObs, family = binomial,
data = volcanoisland)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.20221 -0.50521 -0.15234 -0.00544 3.03979
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.16640 0.21592 5.402 6.59e-08 ***
earth -0.21692 0.02982 -7.273 3.51e-13 ***
windObs -0.61135 0.05763 -10.608 < 2e-16 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 889.22 on 999 degrees of freedom
Residual deviance: 562.65 on 997 degrees of freedom
AIC: 568.65
Number of Fisher Scoring iterations: 8
plot(allEffects(fit))
However, there is something wrong with the model
library(DHARMa)
This is DHARMa 0.4.6. For overview type '?DHARMa'. For recent changes, type news(package = 'DHARMa')
res <-simulateResiduals(fit)plot(res)
Suspicion - the lizards atually depend on the altitude, but they don’t like wind and therefore hide when there is a lot of wind, and wind also correlates with altitude.
plot(windObs ~ sAltitude, data = volcanoisland)
Could we find out what’s the true effect of the environmental predictors? let’s build an occupancy model where we model the true presence of the lizzard as a latent variable.
Iterations = 1001:6000
Thinning interval = 1
Number of chains = 3
Sample size per chain = 5000
1. Empirical mean and standard deviation for each variable,
plus standard error of the mean:
Mean SD Naive SE Time-series SE
SoilL -0.32036 0.08307 0.0006783 0.001047
altL 0.04013 0.25479 0.0020803 0.003181
intL 0.23622 0.26860 0.0021931 0.003652
intO 5.66535 0.65717 0.0053657 0.038296
windO -4.14582 0.42957 0.0035074 0.025122
2. Quantiles for each variable:
2.5% 25% 50% 75% 97.5%
SoilL -0.4928 -0.37404 -0.31692 -0.2632 -0.1663
altL -0.4540 -0.13044 0.03736 0.2078 0.5453
intL -0.2759 0.05005 0.23318 0.4088 0.7863
intO 4.4430 5.20658 5.65008 6.1011 6.9961
windO -5.0138 -4.43041 -4.13413 -3.8423 -3.3544
dic = dic =dic.samples(jagsModel, n.iter =5000, type ="pD")dic
Mean deviance: 261
penalty NaN
Penalized deviance: NaN
Inspecting the occupancy results
para.names <-c("LizzardTrue")Samples <-coda.samples(jagsModel, variable.names = para.names, n.iter =5000)library(BayesianTools)x =getSample(Samples)# there was no Lizard observed on plot 3 on all 10 replicatesvolcanoisland$lizardsObs[21:30]
[1] 0 0 0 0 0 0 0 0 0 0
# Still, occupancy probability that the species is there is 22 percentbarplot(table(x[,3]))
# fix for a bug in DHARMa, will be correctedsim$simulatedResponse =t(x)sim$refit = Fsim$integerResponse = Tres2 =recalculateResiduals(sim, group =as.factor(volcanoisland$plot))plot(res2)
testDispersion(res2)
DHARMa nonparametric dispersion test via sd of residuals fitted vs.
simulated
data: simulationOutput
dispersion = 0.93804, p-value = 0.834
alternative hypothesis: two.sided
x = volcanoisland$x[seq(1, 999, by =10)]y = volcanoisland$y[seq(1, 999, by =10)]testSpatialAutocorrelation(res2, x = x, y = y)
DHARMa Moran's I test for distance-based autocorrelation
data: res2
observed = 0.115750, expected = -0.010101, sd = 0.017233, p-value =
2.818e-13
alternative hypothesis: Distance-based autocorrelation