if (FALSE) {
#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'))
}
Run the code above in your browser using DataLab