# NOT RUN {
library(mlogit)
data("Fishing", package = "mlogit")
Fish <- mlogit.data(Fishing, varying = c(2:9), shape = "wide", choice = "mode")
## a pure "conditional" model
mres <- summary(mlogit(mode ~ price + catch, data = Fish))
data <- prepare_data(Fish %>% data.frame %>% dplyr::select(-idx),
choice="alt", dummy="mode", PeID="chid", mode_spec_var = c("price", "catch"),
type="long")
eq_d <- c("a1 + p1 * price_1 + p2 * catch_2", "a2 + p1 * price_2 + p2 * catch_2",
"a3 + p1 * price_3 + p2 * catch_3", "a4 + p1 * price_4 + p2 * catch_4")
par_d <- c(paste0("a", 1:4), paste0("p", 1:2))
res <- nmm(data, eq_d=eq_d, par_d = par_d, eq_type="disc", fixed_term=FALSE,
best_method=FALSE)
pseudoR(res, which = c("McFadden"))
ncf <- c(mres$coefficients)
names(ncf) <- par_d[-1]
mress <- in2nmm(res, new_coef = ncf)
pseudoR(mress, which = c("McFadden"))
pseudoR(mress)
# }
Run the code above in your browser using DataLab