R/predict.npmr.R

Defines functions predict.npmr

Documented in predict.npmr

predict.npmr <-
function(object, newx, ...) {

    if (ncol(newx) != nrow(object$B)) {
        stop('Number of variables in newx does not match model fit')
    }

    nlambda = ncol(object$b)
    eta = P = array(NA, c(nrow(newx), dim(object$B)[2], nlambda))
    for (l in 1:nlambda) {
        eta[, , l] = as.matrix(matrix(1, nrow(newx), 1) %*% t(object$b[, l]) +
            newx %*% object$B[, , l])
        P[, , l] = exp(eta[, , l])/rowSums(exp(eta[, , l]))
    }
    P
}

Try the npmr package in your browser

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

npmr documentation built on Nov. 12, 2023, 1:08 a.m.