data(spider)
spider = list(abund=spider$abund, x = as.matrix(spider$x))
## To fit a log-linear model assuming counts are negative binomial, via manyglm:
spidNB <- manyany(abund~x,"manyglm",data=spider,family="negative.binomial")
logLik(spidNB) # a number of generic functions are applible to manyany objects
## To fit a glm with complementary log-log link to presence/absence data:
PAdat = pmin(as.matrix(spider$abund),1) #constructing presence/absence dataset
spidPA <- manyany(PAdat~x,"glm",data=spider,family=binomial("cloglog"))
plot(spidPA)
# There are some wild values in there for the Pardmont variable (residuals >5 or <-8).
#The Pardmont model didn't converge, coefficients are a bit crazy:
coef(spidPA)
# could try again using the glm2 package to fit the models, this fixes things up:
if (FALSE) library(glm2)
if (FALSE) spidPA2<-manyany(PAdat~x,"glm",data=spider,family=binomial("cloglog"),method="glm.fit2")
if (FALSE) plot(spidPA2) #looks much better.
## To simultaneously fit models to ordinal data using the ordinal package:
if (FALSE) library(ordinal)
## First construct an ordinal dataset:
if (FALSE) spidOrd = spider$abund
if (FALSE) spidOrd[spider$abund>1 & spider$abund<=10]=2
if (FALSE) spidOrd[spider$abund>10]=3
## Now fit a model using the clm function:
if (FALSE) manyOrd=manyany(spidOrd~bare.sand+fallen.leaves,"clm",data=data.frame(spider$x))
if (FALSE) plot(manyOrd)
Run the code above in your browser using DataLab