Skip to contents

This function calculates the estimated K-fold cross-validation prediction error for gamMRSea models. It has been adapted from the cv.glm function from the boot library

Usage

cv.gamMRSea(
  data,
  modelobject,
  cost = function(y, yhat) mean((y - yhat)^2),
  K = n,
  replicate = FALSE,
  s.eed = NULL
)

Arguments

data

A matrix or data frame containing the data. The rows should be cases and the columns correspond to variables, one of which is the response.

modelobject

An object of class "gamMRSea" containing the results of a gamMRSea model fitted to data.

cost

A function of two vector arguments specifying the cost function for the cross-validation. The first argument to cost should correspond to the observed responses and the second argument should correspond to the predicted or fitted responses from the generalized linear model. cost must return a non-negative scalar value. The default is the average squared error function.

K

The number of groups into which the data should be split to estimate the cross-validation prediction error. The value of K must be such that all groups are of approximately equal size. If the supplied value of K does not satisfy this criterion then it will be set to the closest integer which does and a warning is generated specifying the value of K used. The default is to set K equal to the number of observations in data which gives the usual leave-one-out cross-validation.

replicate

(default=FALSE). When using the replicate function, and panels are specified in the model object, replicate=TRUE will change the seed and select new panel based folds for each iteration.

s.eed

(default = NULL). If NULL then a seed is randomly generated and stored in the attributes of the output. If specified, the value for s.eed is used and also stored in the attributes of the output.

Details

For more information please see the cv.glm function in the boot library

Examples


# load data
data(ns.data.re)
ns.data.re$foldid<-getCVids(ns.data.re, folds=5)
 
model<-gamMRSea(birds ~ observationhour + as.factor(floodebb) + as.factor(impact),  
              family='poisson', data=ns.data.re)
cv.gamMRSea(data=ns.data.re, modelobject = model, K=5)$delta
#> Loading required package: splines
#> [1] 34.56007 34.55760