R/CalcR2.R

Defines functions CalcR2

CalcR2 <- function(fit, sel = NULL) {
    ests <- ExtractEsts(fit, sel = sel)
    y <- fit$y

    ## http://en.wikipedia.org/wiki/Coefficient_of_determination
    preds <- with(ests, h[, "mean"] + fit$X %*% beta[, "mean"])
    SStot <- sum((y - mean(y))^2)
    SSres <- sum((y - preds)^2)
    R2 <- 1 - SSres/SStot
    R2
}

Try the bkmr package in your browser

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

bkmr documentation built on March 28, 2022, 9:11 a.m.