prob_multinomial: Calculate Probabilities from Multinomial Regression

View source: R/prob_multinomial.R

prob_multinomialR Documentation

Calculate Probabilities from Multinomial Regression

Description

Uses design matrix and parameter estimates to calculate probabilities for each class for each subject.

Usage

prob_multinomial(x, b, a0, classify = TRUE)

Arguments

x

Design, or input, matrix, of dimension nobs x nvars; each row is an observation vector. It is recommended that x have user-defined column names for ease of identifying variables. If missing, then colnames are internally assigned x1, x2, ... and so forth.

b

A list whose elements are vectors of parameter estimates and whose names correspond to the values of y. If fitted.model is obtained from ssnet, then these estimates are stored in fitted.model$coefficients.

a0

A matrix of with nrow equal the number of class and a single column containing the intercept estimates for each class. If fitted.model is obtained from ssnet, then these estimates are stored in fitted.model$a0. Note that the row names should correspond to the class labels from y.

classify

Logical. When TRUE (default), appends a column containing the class with the largest predicted probability.

Details

The parameterization employed here is as in Friedman (2010), i.e., over-parameterized, which under the elastic net penalty allows for unique parameter estimates. Thus, there is not a reference class, but each class has an associated set of parameter estimates. Probabilities are then obtained by Pr(Y_i = k | X_i) = \exp(X_i^T B_k) / \sum_{v=1}^V \exp(X_i^T B_v) where X_i is a the design matrix for subject i, V is the number of classes, and B_v is the vector of parameters associated with class v.

Value

A data frame where each column contains predicted class probabilities for each subject.

References

\insertRef

Friedman:2010ssnet

Examples

x <- matrix(rnorm(10*5), nrow = 10, ncol = 5)
colnames(x) <- paste0("x", seq_len(ncol(x)))
x0 <- cbind(x0 = 1, x)
b <- list(a = runif(5), b = runif(5), c = runif(5))
for (i in seq_len(length(b))) {
    names(b[[i]]) <- colnames(x)
}
a0 <- matrix(runif(3), nrow = 3, ncol= 1)
prob_multinomial(x = x, b = b, a0 = a0)


jmleach-bst/ssnet documentation built on March 4, 2024, 5:04 p.m.