crossVal | R Documentation |
Test predictive accuracy of fitted models using several cross-validation approaches. The dataset is divided by site only into folds or testing and training datasets (i.e., encounter histories within sites are never split up).
## S4 method for signature 'unmarkedFit'
crossVal(
object, method=c("Kfold","holdout","leaveOneOut"),
folds=10, holdoutPct=0.25, statistic=RMSE_MAE, parallel=FALSE, ncores, ...)
## S4 method for signature 'unmarkedFitList'
crossVal(
object, method=c("Kfold","holdout","leaveOneOut"),
folds=10, holdoutPct=0.25, statistic=RMSE_MAE, parallel=FALSE, ncores,
sort = c("none", "increasing", "decreasing"), ...)
object |
A fitted model inheriting class |
method |
Cross validation method to use as string. Valid options are
|
folds |
Number of folds to use for k-fold cross validation |
holdoutPct |
Proportion of dataset (value between 0-1) to use as the "holdout" or "test" set, for the holdout method |
statistic |
Function that calculates statistics for each fold. The
function must take an |
parallel |
If |
ncores |
Number of parallel cores to use. |
sort |
If doing cross-validation on a |
... |
Other arguments passed to the statistic function. |
unmarkedCrossVal
or unmarkedCrossValList
object containing
calculated statistic values for each fold.
Ken Kellner contact@kenkellner.com
fitList
,
unmarkedFit
## Not run:
#Get data
data(frogs)
pferUMF <- unmarkedFrameOccu(pfer.bin)
siteCovs(pferUMF) <- data.frame(sitevar1 = rnorm(numSites(pferUMF)))
obsCovs(pferUMF) <- data.frame(obsvar1 = rnorm(numSites(pferUMF) * obsNum(pferUMF)))
#Fit occupancy model
fm <- occu(~ obsvar1 ~ 1, pferUMF)
#k-fold cross validation with 10 folds
(kfold = crossVal(fm, method="Kfold", folds=10))
#holdout method with 25
(holdout = crossVal(fm,method='holdout', holdoutPct=0.25))
#Leave-one-out method
(leave = crossVal(fm, method='leaveOneOut'))
#Fit a second model and combine into a fitList
fm2 <- occu(~1 ~1, pferUMF)
fl <- fitList(fm2,fm)
#Cross-validation for all fits in fitList using holdout method
(cvlist <- crossVal(fl, method='holdout'))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.