Skip to contents

This function calculates vector of predictions on the scale of the response or link.

Usage

# S3 method for gamMRSea
predict(newdata = NULL, g2k = NULL, object, type = "response", coeff = NULL)

Arguments

newdata

Data frame of covariate values to make predictions to

g2k

Matrix of distances between prediction locations and knot locations (n x k). May be Euclidean or geodesic distances.

object

Object from a GEE or GLM model

type

Type of predictions required. (default=response, may also use link).

coeff

Vector of coefficients (default = NULL). To be used when bootstrapping and sampling coefficients from a distribution e.g. in do.bootstrap.cress.

Value

Returns a vector of predictions on either the response or link scale

Details

Calculate predictions for a model whilst centering the CReSS bases in the same way as the fitted model. Note, if there is an offset in the model it must be called 'area'.

Examples


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# offshore redistribution data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
data(dis.data.re)
data(predict.data.re)
data(knotgrid.off)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# distance sampling
dis.data.re$survey.id<-paste(dis.data.re$season,dis.data.re$impact,sep="")
result<-ddf(dsmodel=~mcds(key="hn", formula=~1), data=dis.data.re, method="ds",
        meta.data=list(width=250))
#> Error in ddf(dsmodel = ~mcds(key = "hn", formula = ~1), data = dis.data.re,     method = "ds", meta.data = list(width = 250)): could not find function "ddf"
dis.data.re<-create.NHAT(dis.data.re,result)
#> Error in which(data$distance <= ddf.obj$meta.data$width): object 'result' not found
count.data<-create.count.data(dis.data.re)
#> Error in `$<-.data.frame`(`*tmp*`, "NHAT", value = numeric(0)): replacement has 0 rows, data has 10951

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# spatial modelling
splineParams<-makesplineParams(data=count.data, varlist=c('depth'))
#> Error in makesplineParams(data = count.data, varlist = c("depth")): object 'count.data' not found
#set some input info for SALSA
count.data$response<- count.data$NHAT
#> Error in eval(expr, envir, enclos): object 'count.data' not found
# make distance matrices for datatoknots and knottoknots
distMats<-makeDists(cbind(count.data$x.pos, count.data$y.pos), na.omit(knotgrid.off))
#> Error in cbind(count.data$x.pos, count.data$y.pos): object 'count.data' not found
# choose sequence of radii
r_seq<-getRadiiChoices(8,distMats$dataDist)
#> Error in getRadiiChoices(8, distMats$dataDist): object 'distMats' not found
# set initial model without the spatial term
initialModel<- glm(response ~ as.factor(season) + as.factor(impact) + offset(log(area)),
                family='quasipoisson', data=count.data)
#> Error in is.data.frame(data): object 'count.data' not found
# make parameter set for running salsa2d
salsa2dlist<-list(fitnessMeasure = 'QICb', knotgrid = knotgrid.off, 
                 knotdim=c(26,14), startKnots=4, minKnots=4,
                 maxKnots=20, r_seq=r_seq, gap=4000, interactionTerm="as.factor(impact)")
#> Error in eval(expr, envir, enclos): object 'r_seq' not found
salsa2dOutput_k6<-runSALSA2D(initialModel, salsa2dlist, d2k=distMats$dataDist,
                   k2k=distMats$knotDist, splineParams=splineParams)
#> Error in runSALSA2D(initialModel, salsa2dlist, d2k = distMats$dataDist,     k2k = distMats$knotDist, splineParams = splineParams): object 'initialModel' not found


# make predictions on response scale
preds<-predict.gamMRSea(newdata=predict.data.re, g2k=dists, object=salsa2dOutput_k6$bestModel)
#> Error in predict.gamMRSea(newdata = predict.data.re, g2k = dists, object = salsa2dOutput_k6$bestModel): object 'salsa2dOutput_k6' not found