Learn R Programming

RAD (version 0.3)

predict.truncMod: predict

Description

Predict values for S and E(S) given a model for S and new covariates.

Usage

## S3 method for class 'truncMod' "predict"(object,new.obs,N=NA, offset=1,dist="NB",...)

Arguments

object
a fitted model from truncMod, of class truncMod
new.obs
new covariates used to predict S. Must contain the same names as in the formula for truncMod
N
if S is conditional on N, then N is the predicted values returned from predict.N
offset
offset for sampling
dist
distribution used for S, either negative binomial ("NB") or poisson ("poisson")
...
additional arguments to be passed to predict

Value

S
predicted S
expect.S
expected S

Authors

Piers Dunstan and Scott Foster

Details

Uses mvtnorm to obtain new parameters for the glm using calculated variance-covariance matrix, assuming multivariate normal for parameters.

new.obs will be automatically scaled using details in model.S if scale.covar==TRUE

Examples

Run this code
N.form <- N~1  + depth + O2_AV + temp_AV + offset(log(area))
model.N <- negBinMod(N.form,data=fish.data,est.var=TRUE,scale.covar =FALSE)
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)
new.obs <- as.data.frame(t(apply(fish.data,2,mean)))
N.pred <- rep(NA,100)
S.pred <- rep(NA,100)
for(n in 1:100){
  N.pred[n] <- predict(model.N,new.obs,offset=10)$N
  # insert estimate for N into data frame for it is used, not the original value
  new.obs$N.scale <- N.pred[n]/10
  S.pred[n] <- predict(model.S,new.obs,N.pred[n],offset=10)$S
}
hist(S.pred)

Run the code above in your browser using DataLab