ll_vclogit: Log likelihood for varying choice mlogit

View source: R/vc_mlogit.R

ll_vclogitR Documentation

Log likelihood for varying choice mlogit

Description

Computes the observed log likelihood for a multinomial logit with varying choice sets and weights. ll_vclogit implements by Rcpp. ll_vclogit_R implements in R, and is slower.

Usage

ll_vclogit(par, y_j, zeta_k, m_j)

Arguments

par

The parameter of interest. A (L)-length vector of mlogit coefficients for cluster k and office j. The coefficient for the reference category, corresponding to abstention, is abbreviated here. That coefficient is constrained to be 0. Therefore, the log likelihood appends 0 to the beginning each time.

y_j

N length vector of outcomes

zeta_k

N-length vector of posterior for membership in cluster k

m_j

N by (L + 1) matrix of missingness indicators

Value

When used via optim, the par command returns the MLE parameter. See example.

Examples


# fit data from mlogit and compare

fit <- optim(par = c(1, -2, 1),
             fn = ll_vclogit,
             y_j = canada_mlogit_y,
             zeta_k = canada_mlogit_w,
             m_j = canada_mlogit_m,
             method = 'BFGS')
fit$par


# mlogit replication ----
## Not run: 
library(mlogit)
data("ModeCanada")
MC_mlogit <- mlogit.data(ModeCanada,
                         chid.var = "case",
                         alt.var = "alt",
                         drop.index = TRUE)

fit_mlogit_pkg <- mlogit(choice ~ 1,
                         data = MC_mlogit,
                         weights = dist,
                         reflevel = "train")
coef(fit_mlogit_pkg)

## End(Not run)


kuriwaki/clusterCVR documentation built on July 31, 2024, 8:28 p.m.