R/LOOCV.R

Defines functions `LOOCV`

`LOOCV` <-
function(X, y){
#LOOCV (equivalent to PRESS)
n <- length(y)
if (n != nrow(X))
    stop(paste("error: X must have ", n, "rows"))
p <- ncol(X) #if zero, handle separately
Xy<- data.frame(as.data.frame(X), y=y)
ans<-lm(y~., data=Xy)
Errs <- (resid(ans)^2) / ((1 - lm.influence(ans)$hat)^2)
sdCV <- sd(Errs)
CVErr <- mean(Errs)
c(CVErr, sdCV)
}

Try the bestglm package in your browser

Any scripts or data that you put into this service are public.

bestglm documentation built on March 26, 2020, 7:25 p.m.