loocv {spmodel} | R Documentation |
Perform leave-one-out cross validation
Description
Perform leave-one-out cross validation with options for computationally efficient approximations for big data.
Usage
loocv(object, ...)
## S3 method for class 'splm'
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)
## S3 method for class 'spautor'
loocv(object, cv_predict = FALSE, se.fit = FALSE, local, ...)
## S3 method for class 'spglm'
loocv(
object,
cv_predict = FALSE,
type = c("link", "response"),
se.fit = FALSE,
local,
...
)
## S3 method for class 'spgautor'
loocv(
object,
cv_predict = FALSE,
type = c("link", "response"),
se.fit = FALSE,
local,
...
)
Arguments
object |
A fitted model object from |
... |
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 |
se.fit |
A logical indicating whether the leave-one-out
prediction standard errors should be returned. Defaults to |
local |
A list or logical. If a list, specific list elements described
in |
type |
The scale ( |
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 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). Generally,
bias should be near zero 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 is not returned when object
was fit using
spglm()
or spgautor()
, as it is only applicable here for linear models.
Value
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
).
Examples
spmod <- splm(z ~ water + tarp,
data = caribou,
spcov_type = "exponential", xcoord = x, ycoord = y
)
loocv(spmod)
loocv(spmod, cv_predict = TRUE, se.fit = TRUE)