R/estimate_p_xi.R

Defines functions p_xi

#' @title Estimate P(xi | Z, C)
#' @description Estimate P(xi = k | Zi, Ci)
#' @param alpha regression coefficient for multinomial logistic regression model (xi).
#' @param Z wide-format variables of interest.
#' @return A vector of estimated P(xi = k | Zi, Ci).
#' @noRd
p_xi <- function(alpha, Z) {
  exp_Zalpha <- exp(Z %*% t(alpha)) # n*p %*% p*k ==> n*k
  return(t(apply(exp_Zalpha, 1, function(x) x / sum(x))))
}

Try the SLCARE package in your browser

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

SLCARE documentation built on June 24, 2024, 5:08 p.m.