Learn R Programming

RAD (version 0.3)

truncMod: truncMod

Description

truncMod fits a truncated negative bionomial model to data. Use to fit Species Richness (S\_i)

Usage

truncMod(trunc.form, trunc.pts, data, dist = 'NB', scale.covar=FALSE, est.var = TRUE, trace = TRUE)

Arguments

trunc.form
an object of class "formula" (or one that can be coerced to that class):a symbolic description of the model to be fitted. An offset in the form offset(log(area sampled)) should be included in the model formula to adjust for differences in area sampled between sites.
trunc.pts
A vector of truncation points of model. Must be of length equal to the numbers of rows(sites) of data. Set to N for fitting truncated species richness
data
a data frame containing the variables in the formula including the offset and the response. Each row should be a different site.
dist
one of either NB (negative binomial) or poission
scale.covar
Should the model matrix be scaled (TRUE/FALSE)? Useful if models do not converge. Setting this to TRUE will save the column means and sd for later prediction.
est.var
estimate the variance-covariance matrix using newton-raphson
trace
print model trace

Value

coef
coefficents
vcov
variance-covariance matrix
logl
log-likelihood
AIC
AIC
residuals
model residuals, calculated using PIT
fitted
fitted values
sds
dfdf
sums
model sums
mean.X
column means for model matrix if scale.covar is TRUE
sd.X
column sds for model matrix if scale.covar is TRUE
formula
model formula

Authors

Piers Dunstan and Scott Foster

Details

truncMod used glm.nb (MASS) or glm to get initial parameters for untruncated likelihoood & then uses nlminb to fit truncated model. Allows calculation of se for overdispersion parameter.

Examples

Run this code
fish.data$N.scale <- fish.data$N/fish.data$area
S.form <- S~1 + N.scale + depth + O2_AV + temp_AV + offset(log(area))
model.S <- truncMod(S.form,fish.data$N,data=fish.data,est.var=TRUE,scale.covar=TRUE)
plot(model.S$fitted,model.S$residuals)
abline(h=0)

Run the code above in your browser using DataLab