mnl_fd_ova {MNLpred} | R Documentation |
Multinomial First Differences Prediction (Observed Value Approach)
Description
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.
Usage
mnl_fd_ova(
model,
data,
x,
z,
z_values,
xvari,
scenname,
scenvalues,
by = NULL,
nsim = 1000,
seed = "random",
probs = c(0.025, 0.975)
)
Arguments
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: |
Details
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.
Value
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'.
Examples
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)