Skip to contents

Perform leave-one-out cross validation with options for computationally efficient approximations for big data.

Usage

loocv(object, ...)

# S3 method for splm
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)

# S3 method for spautor
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)

# S3 method for spglm
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)

# S3 method for spgautor
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)

Arguments

object

A fitted model object from splm(), spautor(), spglm(), or spgautor().

...

Other arguments. Not used (needed for generic consistency).

cv_predict

A logical indicating whether the leave-one-out fitted values should be returned. Defaults to FALSE. If object is from spglm() or spgautor(), the fitted values returned are on the link scale.

se.fit

A logical indicating whether the leave-one-out prediction standard errors should be returned. Defaults to FALSE. If object is from spglm() or spgautor(), the standard errors correspond to the fitted values returned on the link scale.

local

A list or logical. If a list, specific list elements described in predict.spmodel() control the big data approximation behavior. If a logical, TRUE chooses default list elements for the list version of local as specified in predict.spmodel(). Defaults to FALSE, which performs exact computations.

Value

If cv_predict = FALSE and se.fit = FALSE, a numeric vector indicating the mean-squared-prediction leave-one-out cross validation error. If cv_predict = TRUE or se.fit = TRUE, a list with elements: mspe, a numeric vector indicating the mean-squared-prediction leave-one-out cross validation error; cv_predict, a numeric vector with leave-one-out predictions for each observation (if cv_predict = TRUE); and se.fit, a numeric vector with leave-one-out prediction standard errors for each observation (if se.fit = TRUE).

Details

Each observation is held-out from the data set and the remaining data are used to make a prediction for the held-out observation. This is compared to the true value of the observation and a mean-squared error is computed across all observations. The lower the mean squared error, the better the model fit (according to the leave-one-out criterion).

Examples

spmod <- splm(z ~ water + tarp,
  data = caribou,
  spcov_type = "exponential", xcoord = x, ycoord = y
)
loocv(spmod)
#> [1] 0.03526886
loocv(spmod, cv_predict = TRUE, se.fit = TRUE)
#> $mspe
#> [1] 0.03526886
#> 
#> $cv_predict
#>  [1] 1.976891 2.279097 2.104800 2.001062 2.252981 2.081761 2.036528 1.906351
#>  [9] 2.209990 1.920595 1.953973 2.197366 1.941609 2.149225 2.029657 2.073248
#> [17] 2.148203 2.023779 2.100568 1.929728 2.000196 1.782930 1.907800 2.191920
#> [25] 1.915703 1.917835 2.269514 1.941046 1.801330 2.120519
#> 
#> $se.fit
#>  [1] 0.1948550 0.1908319 0.1902988 0.1966091 0.2011680 0.1929935 0.1896957
#>  [8] 0.1828196 0.1827176 0.1901259 0.1852316 0.1842182 0.1836098 0.1843557
#> [15] 0.1869189 0.1852316 0.1842182 0.1836098 0.1843557 0.1869189 0.1929935
#> [22] 0.1896957 0.1828196 0.1827176 0.1901259 0.1948550 0.1908319 0.1902988
#> [29] 0.1966091 0.2011680
#>