if (FALSE) {
df_selects_withoutNA = selects2015 |>
dplyr::filter(vote_choice != "other") |>
dplyr::mutate(vote_choice = factor(vote_choice)) |>
dplyr::select(age, gender, vote_choice, starts_with("lr_")) |>
na.omit()
mlogit_data = dfidx::dfidx(df_selects_withoutNA, varying = 5:11,
sep = "_", shape = "wide",
choice = "vote_choice")
mlogit_data$distance = abs(mlogit_data$lr - mlogit_data$lr_self)
model1 = mlogit::mlogit(vote_choice ~ distance | lr_self +
gender, data = mlogit_data)
summary(model1)
# predicted probability of a left male person with a distance of 2
basepredict(model1, list(1, c(2, 5, 5, 5, 5, 5), 0, 0))
}
Run the code above in your browser using DataLab