Perform leave-one-out cross validation with options for computationally efficient approximations for big data.
loocv(object, ...)
# S3 method for class 'splm'
loocv(
object,
cv_predict = FALSE,
se.fit = FALSE,
local,
interval = c("none", "prediction"),
level = 0.95,
...
)
# S3 method for class 'spautor'
loocv(
object,
cv_predict = FALSE,
se.fit = FALSE,
local,
interval = c("none", "prediction"),
level = 0.95,
...
)
# S3 method for class 'spglm'
loocv(
object,
cv_predict = FALSE,
type = c("link", "response"),
se.fit = FALSE,
delta = FALSE,
local,
...
)
# S3 method for class 'spgautor'
loocv(
object,
cv_predict = FALSE,
type = c("link", "response"),
se.fit = FALSE,
delta = FALSE,
local,
...
)A fitted model object from splm(), spautor(), spglm(), or spgautor().
Other arguments. Not used (needed for generic consistency).
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.
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.
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.
Whether to also report empirical leave-one-out prediction
interval coverage in the returned fit statistics. "none" (the
default) omits it; "prediction" reports it (see Details). Only
available for splm()/spautor() objects.
The prediction interval level (e.g. 0.95) used to compute
prediction interval coverage when interval = "prediction". Ignored otherwise. The
default is 0.95.
The scale (response or link) of predictions obtained
when cv_predict = TRUE and using spglm() or spgautor objects.
A logical indicating whether to return delta method standard errors
on the response scale when se.fit = TRUE and type = "response". The default is FALSE.
If cv_predict = FALSE and se.fit = FALSE,
a fit statistics tibble (with bias, MSPE, RMSPE, and cor2; see Details).
If cv_predict = TRUE or se.fit = TRUE,
a list with elements: stats, a fit statistics tibble
(with bias, MSPE, RMSPE, and cor2; see Details); 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). When object is from
splm() or spautor() and interval = "prediction", the fit
statistics tibble also has a cover.XX column (e.g. cover.95
for level = 0.95; see 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 several fit statistics are (sometimes optionally) computed:
bias, mean-squared-prediction error (MSPE), root-mean-squared-prediction
error (RMSPE), and the squared correlation (cor2) between the observed data
and leave-one-out predictions (regarded as a prediction version of r-squared
appropriate for comparing across spatial and nonspatial models), and
prediction interval coverage (cover.XX). Generally,
bias should be near zero and prediction interval coverage at the
intended level for well-fitting models. The lower the MSPE and RMSPE,
the better the model fit (according to the leave-out-out criterion).
The higher the cor2, the better the model fit (according to the leave-out-out
criterion). cor2 and cover.XX are not returned when object was fit using
spglm() or spgautor() because we do not observe the underlying latent mean.
spmod <- splm(z ~ water + tarp,
data = caribou,
spcov_type = "exponential", xcoord = x, ycoord = y
)
loocv(spmod)
#> # A tibble: 1 × 4
#> bias MSPE RMSPE cor2
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0.00375 0.0353 0.188 0.219
loocv(spmod, cv_predict = TRUE, se.fit = TRUE)
#> $stats
#> # A tibble: 1 × 4
#> bias MSPE RMSPE cor2
#> <dbl> <dbl> <dbl> <dbl>
#> 1 0.00375 0.0353 0.188 0.219
#>
#> $cv_predict
#> [1] 1.978139 2.280002 2.104862 2.000554 2.253466 2.082967 2.037058 1.905427
#> [9] 2.209731 1.920353 1.953703 2.197089 1.940796 2.148495 2.030212 2.073714
#> [17] 2.147453 2.023614 2.099895 1.929836 1.999964 1.782125 1.907520 2.191863
#> [25] 1.915546 1.917932 2.270373 1.940667 1.801009 2.121204
#>
#> $se.fit
#> [1] 0.1948501 0.1907239 0.1902286 0.1964758 0.2011452 0.1928919 0.1896041
#> [8] 0.1826513 0.1825524 0.1900351 0.1851119 0.1840579 0.1834773 0.1842208
#> [15] 0.1867929 0.1851119 0.1840579 0.1834773 0.1842208 0.1867929 0.1928919
#> [22] 0.1896041 0.1826513 0.1825524 0.1900351 0.1948501 0.1907239 0.1902286
#> [29] 0.1964758 0.2011452
#>