Title: | Simulated Predicted Probabilities for Multinomial Logit Models |
---|---|
Description: | Functions to easily return simulated predicted probabilities and first differences for multinomial logit models. It takes a specified scenario and a multinomial model to predict probabilities with a set of coefficients, drawn from a simulated sampling distribution. The simulated predictions allow for meaningful plots with means and confidence intervals. The methodological approach is based on the principles laid out by King, Tomz, and Wittenberg (2000) <doi:10.2307/2669316> and Hanmer and Ozan Kalkan (2016) <doi:10.1111/j.1540-5907.2012.00602.x>. |
Authors: | Manuel Neumann [aut, cre] |
Maintainer: | Manuel Neumann <[email protected]> |
License: | GPL-3 |
Version: | 0.0.8 |
Built: | 2025-02-26 03:29:55 UTC |
Source: | https://github.com/manuelneumann/mnlpred |
A sample of 1,000 respondents in the Rolling Cross Sectional study in the German Longitudinal Election Study in 2017.
data(gles)
data(gles)
An data frame with 1,000 observations and 6 variables:
Voting decision for party
Ego-position toward immigration (0 = very open to 10 = very restrictive )
Dummy for respondents from Eastern Germany (= 1)
Measurement for political interst (0 = low, 4 = high)
Self-reported income satisfaction (0 = low, 4 = high)
Self-reported gender (binary coding with 1 = female)
Roßteutscher, Sigrid et al. 2019. “Rolling Cross-Section-Wahlkampfstudie mit Nachwahl-Panelwelle (GLES 2017).” ZA6803 Datenfile Version 4.0.1. (GESIS Datenarchiv).
data(gles) table(gles$vote)
data(gles) table(gles$vote)
This function predicts values for two different scenarios over a range of values. It then takes the differences between the different simulations to return first differences for each value.
mnl_fd_ova( model, data, x, z, z_values, xvari, scenname, scenvalues, by = NULL, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
mnl_fd_ova( model, data, x, z, z_values, xvari, scenname, scenvalues, by = NULL, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
model |
the multinomial model, from a |
data |
the data with which the model was estimated |
x |
the name of the variable that should be varied (the x-axis variable in prediction plots) |
z |
define the variable for which you want to compute the difference. |
z_values |
determine the two values at which value you want to fix the scenario ( |
xvari |
former argument for |
scenname |
former argument for |
scenvalues |
former argument for |
by |
define the steps of |
nsim |
numbers of simulations |
seed |
set a seed for replication purposes. |
probs |
a vector with two numbers, defining the significance levels. Default to 5% significance level: |
The function uses the mnl_pred_ova
function for each scenario.
The results of these predictions are also returned and can therefore be
easily accessed. If you need predictions for multiple scenarios, you can use
this function to both plot the predictions for each scenario and the
differences between them.
The function returns a list with several elements. Most importantly the list includes the simulated draws 'S', the simulated predictions 'P', and a data set for plotting 'plotdata'.
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) fdif <- mnl_fd_ova(model = mod, data = dataset, x = "x1", z = "x3", z_values = c(min(dataset$x3), max(dataset$x3)), nsim = 10)
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) fdif <- mnl_fd_ova(model = mod, data = dataset, x = "x1", z = "x3", z_values = c(min(dataset$x3), max(dataset$x3)), nsim = 10)
Multinomial First Differences Predictions For Two Values (Observed Value Approach)
mnl_fd2_ova( model, data, x, value1, value2, xvari, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
mnl_fd2_ova( model, data, x, value1, value2, xvari, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
model |
the multinomial model, from a |
data |
the data with which the model was estimated |
x |
the name of the variable that should be varied |
value1 |
first value for the difference |
value2 |
second value for the difference |
xvari |
former argument for |
nsim |
numbers of simulations |
seed |
set a seed for replication purposes. |
probs |
a vector with two numbers, defining the significance levels. Default to 5% significance level: |
The function returns a list with several elements. Most importantly the list includes the simulated draws 'S', the simulated predictions 'P', the first differences of the predictions 'P_fd', a data set for plotting 'plotdata' the predicted probabilities, and one for the first differences 'plotdata_fd'.
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) fdi1 <- mnl_fd2_ova(model = mod, data = dataset, x = "x1", value1 = min(dataset$x1), value2 = max(dataset$x1), nsim = 10)
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) fdi1 <- mnl_fd2_ova(model = mod, data = dataset, x = "x1", value1 = min(dataset$x1), value2 = max(dataset$x1), nsim = 10)
This function predicts probabilities for all choices of a multinomial logit model over a specified span of values.
mnl_pred_ova( model, data, x, by = NULL, z = NULL, z_value = NULL, xvari, scenname, scenvalue, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
mnl_pred_ova( model, data, x, by = NULL, z = NULL, z_value = NULL, xvari, scenname, scenvalue, nsim = 1000, seed = "random", probs = c(0.025, 0.975) )
model |
the multinomial model, from a |
data |
the data with which the model was estimated |
x |
the name of the variable that should be varied (the x-axis variable in prediction plots) |
by |
define the steps of |
z |
if you want to hold a specific variable stable over all scenarios, you can name it here (optional). |
z_value |
determine at which value you want to fix the |
xvari |
former argument for |
scenname |
former argument for |
scenvalue |
former argument for |
nsim |
numbers of simulations |
seed |
set a seed for replication purposes. |
probs |
a vector with two numbers, defining the significance levels. Default to 5% significance level: |
The function returns a list with several elements. Most importantly the list includes the simulated draws 'S', the simulated predictions 'P', and a data set for plotting 'plotdata'.
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) pred <- mnl_pred_ova(model = mod, data = dataset, x = "x1", nsim = 10)
library(nnet) library(MASS) dataset <- data.frame(y = c(rep("a", 10), rep("b", 10), rep("c", 10)), x1 = rnorm(30), x2 = rnorm(30, mean = 1), x3 = sample(1:10, 30, replace = TRUE)) mod <- multinom(y ~ x1 + x2 + x3, data = dataset, Hess = TRUE) pred <- mnl_pred_ova(model = mod, data = dataset, x = "x1", nsim = 10)