set.seed(123) # This leads to the global solution
hspider[,1:6] <- scale(hspider[,1:6]) # Standardized environmental vars
p1 <- cqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
Trocterr, Zoraspin) ~
WaterCon + BareSand + FallTwig + CoveMoss + CoveHerb + ReflLux,
ITolerances = TRUE, fam = poissonff, data = hspider,
Crow1positive = TRUE, Bestof=3, trace = FALSE)
if (deviance(p1) > 1589.0) stop("suboptimal fit obtained")
set.seed(111)
up1 <- uqo(cbind(Alopacce, Alopcune, Alopfabr, Arctlute, Arctperi,
Auloalbi, Pardlugu, Pardmont, Pardnigr, Pardpull,
Trocterr, Zoraspin) ~ 1,
family = poissonff, data = hspider,
ITolerances = TRUE,
Crow1positive = TRUE, lvstart = -latvar(p1))
if (deviance(up1) > 1310.0) stop("suboptimal fit obtained")
nos <- ncol(depvar(up1)) # Number of species
clr <- (1:(nos+1))[-7] # Omit yellow
lvplot(up1, las = 1, y = TRUE, pch = 1:nos, scol = clr, lcol = clr,
pcol = clr, llty = 1:nos, llwd = 2)
legend(x = 2, y = 135, colnames(up1@y), col = clr, lty = 1:nos,
lwd = 2, merge = FALSE, ncol = 1, x.inter = 4.0, bty = "l", cex = 0.9)
# Compare the site scores between the two models
plot(latvar(p1), latvar(up1), xlim = c(-3, 4), ylim = c(-3, 4), las = 1)
abline(a = 0, b = -1, lty = 2, col = "blue", xpd = FALSE)
cor(latvar(p1, ITol = TRUE), latvar(up1))
# Another comparison between the constrained and unconstrained models
# The signs are not right so they are similar when reflected about 0
par(mfrow = c(2, 1))
persp(up1, main = "Red/Blue are the constrained/unconstrained models",
label = TRUE, col = "blue", las = 1)
persp(p1, add = FALSE, col = "red")
pchisq(deviance(p1) - deviance(up1), df = 52-30, lower.tail = FALSE)
Run the code above in your browser using DataLab