R/cv.erpath.R

Defines functions cv.erpath

Documented in cv.erpath

cv.erpath <- function(outlist, lambda, x, y, foldid, 
    pred.loss, delta, omega) {
    typenames <- c(misclass = "Misclassification Error", loss = "Expectile Loss")
    if (pred.loss == "default") 
        pred.loss <- "loss"
    if (!match(pred.loss, c("loss"), FALSE)) {
        warning("Only 'loss' available for expectile regression; 'loss' used")
        pred.loss <- "loss"
    }
    ###Turn y into c(0,1)
    y <- as.double(y)
    nfolds <- max(foldid)
    predmat <- matrix(NA, length(y), length(lambda))
    nlams <- double(nfolds)
    for (i in seq(nfolds)) {
        which <- foldid == i
        fitobj <- outlist[[i]]
        preds <- predict(fitobj, x[which, , drop = FALSE], type = "link")
        nlami <- length(outlist[[i]]$lambda)
        predmat[which, seq(nlami)] <- preds
        nlams[i] <- nlami
    }
    cvraw <- ercls(y-predmat, omega)
    N <- length(y) - apply(is.na(predmat), 2, sum)
    cvm <- apply(cvraw, 2, mean, na.rm = TRUE)
    cvsd <- sqrt(apply(scale(cvraw, cvm, FALSE)^2, 2, mean, na.rm = TRUE)/(N - 
        1))
    list(cvm = cvm, cvsd = cvsd, name = typenames[pred.loss])
} 

Try the gcdnet package in your browser

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

gcdnet documentation built on Nov. 20, 2017, 5:07 p.m.