Predict method for the mnl function

# S3 method for mnl
predict(
  object,
  pred_data = NULL,
  pred_cmd = "",
  pred_names = "",
  dec = 3,
  envir = parent.frame(),
  ...
)

Arguments

object

Return value from mnl

pred_data

Provide the dataframe to generate predictions (e.g., ketchup). The dataset must contain all columns used in the estimation

pred_cmd

Generate predictions using a command. For example, `pclass = levels(pclass)` would produce predictions for the different levels of factor `pclass`. To add another variable, create a vector of prediction strings, (e.g., c('pclass = levels(pclass)', 'age = seq(0,100,20)')

pred_names

Names for the predictions to be stored. If one name is provided, only the first column of predictions is stored. If empty, the levels in the response variable of the mnl model will be used

dec

Number of decimals to show

envir

Environment to extract data from

...

further arguments passed to or from other methods

Details

See https://radiant-rstats.github.io/docs/model/mnl.html for an example in Radiant

See also

mnl to generate the result

summary.mnl to summarize results

Examples

result <- mnl( ketchup, rvar = "choice", evar = c("price.heinz28", "price.heinz32", "price.heinz41", "price.hunts32"), lev = "heinz28" )
#> Warning: NaNs produced
predict(result, pred_cmd = "price.heinz28 = seq(3, 5, 0.1)")
#> Multinomial logistic regression (MNL) #> Data : ketchup #> Response variable : choice #> Level(s) : heinz28, heinz32, heinz41, hunts32 in choice #> Explanatory variables: price.heinz28, price.heinz32, price.heinz41, price.hunts32 #> Prediction command : price.heinz28 = seq(3, 5, 0.1) #> Rows shown : 10 of 21 #> #> price.heinz32 price.heinz41 price.hunts32 price.heinz28 heinz28 heinz32 #> 3.143 4.634 3.355 3.000 0.621 0.304 #> 3.143 4.634 3.355 3.100 0.596 0.325 #> 3.143 4.634 3.355 3.200 0.570 0.348 #> 3.143 4.634 3.355 3.300 0.544 0.370 #> 3.143 4.634 3.355 3.400 0.517 0.393 #> 3.143 4.634 3.355 3.500 0.491 0.416 #> 3.143 4.634 3.355 3.600 0.464 0.439 #> 3.143 4.634 3.355 3.700 0.437 0.462 #> 3.143 4.634 3.355 3.800 0.411 0.484 #> 3.143 4.634 3.355 3.900 0.385 0.507 #> heinz41 hunts32 #> 0.051 0.023 #> 0.053 0.025 #> 0.055 0.028 #> 0.056 0.030 #> 0.057 0.032 #> 0.059 0.035 #> 0.060 0.038 #> 0.061 0.040 #> 0.062 0.043 #> 0.062 0.046
predict(result, pred_data = slice(ketchup, 1:20))
#> Multinomial logistic regression (MNL) #> Data : ketchup #> Response variable : choice #> Level(s) : heinz28, heinz32, heinz41, hunts32 in choice #> Explanatory variables: price.heinz28, price.heinz32, price.heinz41, price.hunts32 #> Prediction dataset : slice(ketchup, 1:20) #> Rows shown : 10 of 20 #> #> price.heinz28 price.heinz32 price.heinz41 price.hunts32 heinz28 heinz32 #> 5.200 3.700 4.600 3.400 0.272 0.423 #> 5.200 4.300 4.600 4.400 0.591 0.244 #> 4.600 2.500 4.600 4.800 0.067 0.918 #> 5.200 3.700 4.600 3.400 0.272 0.423 #> 4.600 3.000 4.600 4.800 0.182 0.784 #> 4.700 3.000 5.000 3.000 0.175 0.657 #> 4.600 3.100 5.100 4.100 0.258 0.706 #> 4.700 3.400 4.600 3.100 0.262 0.460 #> 4.700 3.400 5.000 3.100 0.294 0.444 #> 5.000 3.400 5.000 2.800 0.177 0.365 #> heinz41 hunts32 #> 0.098 0.206 #> 0.121 0.043 #> 0.015 0.000 #> 0.098 0.206 #> 0.033 0.001 #> 0.035 0.133 #> 0.027 0.010 #> 0.081 0.197 #> 0.049 0.213 #> 0.041 0.418