Predictions

Description

Outcome predicted by a fitted model on a specified scale for a given combination of values of the predictor variables, such as their observed values, their means, or factor levels (a.k.a. "reference grid").

  • predictions(): unit-level (conditional) estimates.

  • avg_predictions(): average (marginal) estimates.

The newdata argument and the datagrid() function can be used to control where statistics are evaluated in the predictor space: "at observed values", "at the mean", "at representative values", etc.

See the predictions vignette and package website for worked examples and case studies:

Usage

predictions(
  model,
  newdata = NULL,
  variables = NULL,
  vcov = TRUE,
  conf_level = 0.95,
  type = NULL,
  by = FALSE,
  byfun = NULL,
  wts = NULL,
  transform = NULL,
  hypothesis = NULL,
  equivalence = NULL,
  p_adjust = NULL,
  df = Inf,
  numderiv = "fdforward",
  ...
)

avg_predictions(
  model,
  newdata = NULL,
  variables = NULL,
  vcov = TRUE,
  conf_level = 0.95,
  type = NULL,
  by = TRUE,
  byfun = NULL,
  wts = NULL,
  transform = NULL,
  hypothesis = NULL,
  equivalence = NULL,
  p_adjust = NULL,
  df = Inf,
  numderiv = "fdforward",
  ...
)

Arguments

model Model object
newdata

Grid of predictor values at which we evaluate predictions.

  • Warning: Please avoid modifying your dataset between fitting the model and calling a marginaleffects function. This can sometimes lead to unexpected results.

  • NULL (default): Unit-level predictions for each observed value in the dataset (empirical distribution). The dataset is retrieved using insight::get_data(), which tries to extract data from the environment. This may produce unexpected results if the original data frame has been altered since fitting the model.

  • string:

    • "mean": Predictions at the Mean. Predictions when each predictor is held at its mean or mode.

    • "median": Predictions at the Median. Predictions when each predictor is held at its median or mode.

    • "marginalmeans": Predictions at Marginal Means. See Details section below.

    • "tukey": Predictions at Tukey’s 5 numbers.

    • "grid": Predictions on a grid of representative numbers (Tukey’s 5 numbers and unique values of categorical predictors).

  • datagrid() call to specify a custom grid of regressors. For example:

    • newdata = datagrid(cyl = c(4, 6)): cyl variable equal to 4 and 6 and other regressors fixed at their means or modes.

    • See the Examples section and the datagrid() documentation.

variables

Counterfactual variables.

  • Output:

    • predictions(): The entire dataset is replicated once for each unique combination of variables, and predictions are made.

    • avg_predictions(): The entire dataset is replicated, predictions are made, and they are marginalized by variables categories.

    • Warning: This can be expensive in large datasets.

    • Warning: Users who need "conditional" predictions should use the newdata argument instead of variables.

  • Input:

    • NULL: computes one prediction per row of newdata

    • Character vector: the dataset is replicated once of every combination of unique values of the variables identified in variables.

    • Named list: names identify the subset of variables of interest and their values. For numeric variables, the variables argument supports functions and string shortcuts:

      • A function which returns a numeric value

      • Numeric vector: Contrast between the 2nd element and the 1st element of the x vector.

      • "iqr": Contrast across the interquartile range of the regressor.

      • "sd": Contrast across one standard deviation around the regressor mean.

      • "2sd": Contrast across two standard deviations around the regressor mean.

      • "minmax": Contrast between the maximum and the minimum values of the regressor.

      • "threenum": mean and 1 standard deviation on both sides

      • "fivenum": Tukey’s five numbers

vcov

Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values:

  • FALSE: Do not compute standard errors. This can speed up computation considerably.

  • TRUE: Unit-level standard errors using the default vcov(model) variance-covariance matrix.

  • String which indicates the kind of uncertainty estimates to return.

    • Heteroskedasticity-consistent: “HC”, “HC0”, “HC1”, “HC2”, “HC3”, “HC4”, “HC4m”, “HC5”. See ?sandwich::vcovHC

    • Heteroskedasticity and autocorrelation consistent: “HAC”

    • Mixed-Models degrees of freedom: "satterthwaite", "kenward-roger"

    • Other: “NeweyWest”, “KernHAC”, “OPG”. See the sandwich package documentation.

  • One-sided formula which indicates the name of cluster variables (e.g., ~unit_id). This formula is passed to the cluster argument of the sandwich::vcovCL function.

  • Square covariance matrix

  • Function which returns a covariance matrix (e.g., stats::vcov(model))

conf_level numeric value between 0 and 1. Confidence level to use to build a confidence interval.
type string indicates the type (scale) of the predictions used to compute contrasts or slopes. This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero". When an unsupported string is entered, the model-specific list of acceptable values is returned in an error message. When type is NULL, the first entry in the error message is used by default.
by

Aggregate unit-level estimates (aka, marginalize, average over). Valid inputs:

  • FALSE: return the original unit-level estimates.

  • TRUE: aggregate estimates for each term.

  • Character vector of column names in newdata or in the data frame produced by calling the function without the by argument.

  • Data frame with a by column of group labels, and merging columns shared by newdata or the data frame produced by calling the same function without the by argument.

  • See examples below.

  • For more complex aggregations, you can use the FUN argument of the hypotheses() function. See that function’s documentation and the Hypothesis Test vignettes on the marginaleffects website.

byfun A function such as mean() or sum() used to aggregate estimates within the subgroups defined by the by argument. NULL uses the mean() function. Must accept a numeric vector and return a single numeric value. This is sometimes used to take the sum or mean of predicted probabilities across outcome or predictor levels. See examples section.
wts

string or numeric: weights to use when computing average contrasts or slopes. These weights only affect the averaging in avg_*() or with the by argument, and not the unit-level estimates themselves. Internally, estimates and weights are passed to the weighted.mean() function.

  • string: column name of the weights variable in newdata. When supplying a column name to wts, it is recommended to supply the original data (including the weights variable) explicitly to newdata.

  • numeric: vector of length equal to the number of rows in the original data or in newdata (if supplied).

transform A function applied to unit-level adjusted predictions and confidence intervals just before the function returns results. For bayesian models, this function is applied to individual draws from the posterior distribution, before computing summaries.
hypothesis

specify a hypothesis test or custom contrast using a numeric value, vector, or matrix, a string, or a string formula.

  • Numeric:

    • Single value: the null hypothesis used in the computation of Z and p (before applying transform).

    • Vector: Weights to compute a linear combination of (custom contrast between) estimates. Length equal to the number of rows generated by the same function call, but without the hypothesis argument.

    • Matrix: Each column is a vector of weights, as describe above, used to compute a distinct linear combination of (contrast between) estimates. The column names of the matrix are used as labels in the output.

  • String formula to specify linear or non-linear hypothesis tests. If the term column uniquely identifies rows, terms can be used in the formula. Otherwise, use b1, b2, etc. to identify the position of each parameter. The b* wildcard can be used to test hypotheses on all estimates. If a named vector is used, the names are used as labels in the output. Examples:

    • hp = drat

    • hp + drat = 12

    • b1 + b2 + b3 = 0

    • b* / b1 = 1

  • String:

    • "pairwise": pairwise differences between estimates in each row.

    • "reference": differences between the estimates in each row and the estimate in the first row.

    • "sequential": difference between an estimate and the estimate in the next row.

    • "revpairwise", "revreference", "revsequential": inverse of the corresponding hypotheses, as described above.

  • See the Examples section below and the vignette: https://marginaleffects.com/vignettes/hypothesis.html

equivalence Numeric vector of length 2: bounds used for the two-one-sided test (TOST) of equivalence, and for the non-inferiority and non-superiority tests. See Details section below.
p_adjust Adjust p-values for multiple comparisons: "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", or "fdr". See stats::p.adjust
df Degrees of freedom used to compute p values and confidence intervals. A single numeric value between 1 and Inf. When df is Inf, the normal distribution is used. When df is finite, the t distribution is used. See insight::get_df for a convenient function to extract degrees of freedom. Ex: slopes(model, df = insight::get_df(model))
numderiv

string or list of strings indicating the method to use to for the numeric differentiation used in to compute delta method standard errors.

  • "fdforward": finite difference method with forward differences

  • "fdcenter": finite difference method with central differences (default)

  • "richardson": Richardson extrapolation method

  • Extra arguments can be specified by passing a list to the numDeriv argument, with the name of the method first and named arguments following, ex: numderiv=list(“fdcenter”, eps = 1e-5). When an unknown argument is used, marginaleffects prints the list of valid arguments for each method.

Additional arguments are passed to the predict() method supplied by the modeling package.These arguments are particularly useful for mixed-effects or bayesian models (see the online vignettes on the marginaleffects website). Available arguments can vary from model to model, depending on the range of supported arguments by each modeling package. See the "Model-Specific Arguments" section of the ?slopes documentation for a non-exhaustive list of available arguments.

Value

A data.frame with one row per observation and several columns:

  • rowid: row number of the newdata data frame

  • type: prediction type, as defined by the type argument

  • group: (optional) value of the grouped outcome (e.g., categorical outcome models)

  • estimate: predicted outcome

  • std.error: standard errors computed using the delta method.

  • p.value: p value associated to the estimate column. The null is determined by the hypothesis argument (0 by default), and p values are computed before applying the transform argument. For models of class feglm, Gam, glm and negbin, p values are computed on the link scale by default unless the type argument is specified explicitly.

  • s.value: Shannon information transforms of p values. How many consecutive "heads" tosses would provide the same amount of evidence (or "surprise") against the null hypothesis that the coin is fair? The purpose of S is to calibrate the analyst’s intuition about the strength of evidence encoded in p against a well-known physical phenomenon. See Greenland (2019) and Cole et al. (2020).

  • conf.low: lower bound of the confidence interval (or equal-tailed interval for bayesian models)

  • conf.high: upper bound of the confidence interval (or equal-tailed interval for bayesian models)

See ?print.marginaleffects for printing options.

Functions

  • avg_predictions(): Average predictions

Standard errors using the delta method

Standard errors for all quantities estimated by marginaleffects can be obtained via the delta method. This requires differentiating a function with respect to the coefficients in the model using a finite difference approach. In some models, the delta method standard errors can be sensitive to various aspects of the numeric differentiation strategy, including the step size. By default, the step size is set to 1e-8, or to 1e-4 times the smallest absolute model coefficient, whichever is largest.

marginaleffects can delegate numeric differentiation to the numDeriv package, which allows more flexibility. To do this, users can pass arguments to the numDeriv::jacobian function through a global option. For example:

  • options(marginaleffects_numDeriv = list(method = “simple”, method.args = list(eps = 1e-6)))

  • options(marginaleffects_numDeriv = list(method = “Richardson”, method.args = list(eps = 1e-5)))

  • options(marginaleffects_numDeriv = NULL)

See the "Standard Errors and Confidence Intervals" vignette on the marginaleffects website for more details on the computation of standard errors:

https://marginaleffects.com/vignettes/uncertainty.html

Note that the inferences() function can be used to compute uncertainty estimates using a bootstrap or simulation-based inference. See the vignette:

https://marginaleffects.com/vignettes/bootstrap.html

Model-Specific Arguments

Some model types allow model-specific arguments to modify the nature of marginal effects, predictions, marginal means, and contrasts. Please report other package-specific predict() arguments on Github so we can add them to the table below.

https://github.com/vincentarelbundock/marginaleffects/issues

Package Class Argument Documentation
brms brmsfit ndraws brms::posterior_predict
re_formula brms::posterior_predict
lme4 merMod re.form lme4::predict.merMod
allow.new.levels lme4::predict.merMod
glmmTMB glmmTMB re.form glmmTMB::predict.glmmTMB
allow.new.levels glmmTMB::predict.glmmTMB
zitype glmmTMB::predict.glmmTMB
mgcv bam exclude mgcv::predict.bam
robustlmm rlmerMod re.form robustlmm::predict.rlmerMod
allow.new.levels robustlmm::predict.rlmerMod
MCMCglmm MCMCglmm ndraws

Bayesian posterior summaries

By default, credible intervals in bayesian models are built as equal-tailed intervals. This can be changed to a highest density interval by setting a global option:

options(“marginaleffects_posterior_interval” = “eti”)

options(“marginaleffects_posterior_interval” = “hdi”)

By default, the center of the posterior distribution in bayesian models is identified by the median. Users can use a different summary function by setting a global option:

options(“marginaleffects_posterior_center” = “mean”)

options(“marginaleffects_posterior_center” = “median”)

When estimates are averaged using the by argument, the tidy() function, or the summary() function, the posterior distribution is marginalized twice over. First, we take the average across units but within each iteration of the MCMC chain, according to what the user requested in by argument or tidy()/summary() functions. Then, we identify the center of the resulting posterior using the function supplied to the “marginaleffects_posterior_center” option (the median by default).

Equivalence, Inferiority, Superiority

\(\theta\) is an estimate, \(\sigma_\theta\) its estimated standard error, and \([a, b]\) are the bounds of the interval supplied to the equivalence argument.

Non-inferiority:

  • \(H_0\): \(\theta \leq a\)

  • \(H_1\): \(\theta > a\)

  • \(t=(\theta - a)/\sigma_\theta\)

  • p: Upper-tail probability

Non-superiority:

  • \(H_0\): \(\theta \geq b\)

  • \(H_1\): \(\theta < b\)

  • \(t=(\theta - b)/\sigma_\theta\)

  • p: Lower-tail probability

Equivalence: Two One-Sided Tests (TOST)

  • p: Maximum of the non-inferiority and non-superiority p values.

Thanks to Russell V. Lenth for the excellent emmeans package and documentation which inspired this feature.

Prediction types

The type argument determines the scale of the predictions used to compute quantities of interest with functions from the marginaleffects package. Admissible values for type depend on the model object. When users specify an incorrect value for type, marginaleffects will raise an informative error with a list of valid type values for the specific model object. The first entry in the list in that error message is the default type.

The invlink(link) is a special type defined by marginaleffects. It is available for some (but not all) models and functions. With this link type, we first compute predictions on the link scale, then we use the inverse link function to backtransform the predictions to the response scale. This is useful for models with non-linear link functions as it can ensure that confidence intervals stay within desirable bounds, ex: 0 to 1 for a logit model. Note that an average of estimates with type=“invlink(link)” will not always be equivalent to the average of estimates with type=“response”.

Some of the most common type values are:

response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, detection, disp, ev, expected, expvalue, fitted, invlink(link), latent, latent_N, linear.predictor, linpred, location, lp, mean, numeric, p, ppd, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob

References

  • Greenland S. 2019. "Valid P-Values Behave Exactly as They Should: Some Misleading Criticisms of P-Values and Their Resolution With S-Values." The American Statistician. 73(S1): 106–114.

  • Cole, Stephen R, Jessie K Edwards, and Sander Greenland. 2020. "Surprise!" American Journal of Epidemiology 190 (2): 191–93. https://doi.org/10.1093/aje/kwaa136

Examples

library(marginaleffects)



# Adjusted Prediction for every row of the original dataset
mod <- lm(mpg ~ hp + factor(cyl), data = mtcars)
pred <- predictions(mod)
head(pred)

 Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
     20.0      1.204 16.6   <0.001 204.1  17.7   22.4
     20.0      1.204 16.6   <0.001 204.1  17.7   22.4
     26.4      0.962 27.5   <0.001 549.0  24.5   28.3
     20.0      1.204 16.6   <0.001 204.1  17.7   22.4
     15.9      0.992 16.0   <0.001 190.0  14.0   17.9
     20.2      1.219 16.5   <0.001 201.8  17.8   22.5

Columns: rowid, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, mpg, hp, cyl 
Type:  response 
# Adjusted Predictions at User-Specified Values of the Regressors
predictions(mod, newdata = datagrid(hp = c(100, 120), cyl = 4))

  hp cyl Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
 100   4     26.2      0.986 26.6   <0.001 516.6  24.3   28.2
 120   4     25.8      1.110 23.2   <0.001 393.8  23.6   27.9

Columns: rowid, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, mpg, hp, cyl 
Type:  response 
m <- lm(mpg ~ hp + drat + factor(cyl) + factor(am), data = mtcars)
predictions(m, newdata = datagrid(FUN_factor = unique, FUN_numeric = median))

 Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %  hp drat cyl am
     22.0       1.29 17.0   <0.001 214.0  19.4   24.5 123  3.7   6  1
     18.2       1.27 14.3   <0.001 151.9  15.7   20.7 123  3.7   6  0
     25.5       1.32 19.3   <0.001 274.0  23.0   28.1 123  3.7   4  1
     21.8       1.54 14.1   <0.001 148.3  18.8   24.8 123  3.7   4  0
     22.6       2.14 10.6   <0.001  84.2  18.4   26.8 123  3.7   8  1
     18.9       1.73 10.9   <0.001  89.0  15.5   22.3 123  3.7   8  0

Columns: rowid, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, mpg, hp, drat, cyl, am 
Type:  response 
# Average Adjusted Predictions (AAP)
library(dplyr)
mod <- lm(mpg ~ hp * am * vs, mtcars)

avg_predictions(mod)

 Estimate Std. Error    z Pr(>|z|)   S 2.5 % 97.5 %
     20.1      0.484 41.5   <0.001 Inf  19.1     21

Columns: estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
predictions(mod, by = "am")

 am Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
  0     17.1      0.629 27.3   <0.001 541.7  15.9   18.4
  1     24.4      0.760 32.1   <0.001 748.3  22.9   25.9

Columns: am, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
# Conditional Adjusted Predictions
plot_predictions(mod, condition = "hp")

# Counterfactual predictions with the `variables` argument
# the `mtcars` dataset has 32 rows

mod <- lm(mpg ~ hp + am, data = mtcars)
p <- predictions(mod)
head(p)

 Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
     25.4      0.818 31.0   <0.001 700.5  23.8   27.0
     25.4      0.818 31.0   <0.001 700.5  23.8   27.0
     26.4      0.850 31.1   <0.001 701.1  24.7   28.1
     20.1      0.775 25.9   <0.001 490.0  18.6   21.6
     16.3      0.677 24.0   <0.001 421.6  15.0   17.6
     20.4      0.796 25.6   <0.001 478.6  18.8   22.0

Columns: rowid, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, mpg, hp, am 
Type:  response 
nrow(p)
[1] 32
# average counterfactual predictions
avg_predictions(mod, variables = "am")

 am Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
  0     17.9      0.676 26.6   <0.001 513.7  16.6   19.3
  1     23.2      0.822 28.3   <0.001 581.2  21.6   24.8

Columns: am, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
# counterfactual predictions obtained by replicating the entire for different
# values of the predictors
p <- predictions(mod, variables = list(hp = c(90, 110)))
nrow(p)
[1] 64
# hypothesis test: is the prediction in the 1st row equal to the prediction in the 2nd row
mod <- lm(mpg ~ wt + drat, data = mtcars)

predictions(
    mod,
    newdata = datagrid(wt = 2:3),
    hypothesis = "b1 = b2")

  Term Estimate Std. Error z Pr(>|z|)    S 2.5 % 97.5 %
 b1=b2     4.78      0.797 6   <0.001 28.9  3.22   6.35

Columns: term, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
# same hypothesis test using row indices
predictions(
    mod,
    newdata = datagrid(wt = 2:3),
    hypothesis = "b1 - b2 = 0")

    Term Estimate Std. Error z Pr(>|z|)    S 2.5 % 97.5 %
 b1-b2=0     4.78      0.797 6   <0.001 28.9  3.22   6.35

Columns: term, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
# same hypothesis test using numeric vector of weights
predictions(
    mod,
    newdata = datagrid(wt = 2:3),
    hypothesis = c(1, -1))

   Term Estimate Std. Error z Pr(>|z|)    S 2.5 % 97.5 %
 custom     4.78      0.797 6   <0.001 28.9  3.22   6.35

Columns: term, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
# two custom contrasts using a matrix of weights
lc <- matrix(c(
    1, -1,
    2, 3),
    ncol = 2)
predictions(
    mod,
    newdata = datagrid(wt = 2:3),
    hypothesis = lc)

   Term wt Estimate Std. Error    z Pr(>|z|)     S  2.5 % 97.5 % drat
 custom  2     4.78      0.797  6.0   <0.001  28.9   3.22   6.35  3.6
 custom  3   115.21      3.647 31.6   <0.001 725.0 108.07 122.36  3.6

Columns: rowid, term, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, mpg, drat, wt 
Type:  response 
# `by` argument
mod <- lm(mpg ~ hp * am * vs, data = mtcars)
predictions(mod, by = c("am", "vs"))

 am vs Estimate Std. Error    z Pr(>|z|)     S 2.5 % 97.5 %
  0  0     15.0      0.791 19.0   <0.001 265.7  13.5   16.6
  0  1     20.7      1.036 20.0   <0.001 294.0  18.7   22.8
  1  0     19.7      1.119 17.7   <0.001 229.3  17.6   21.9
  1  1     28.4      1.036 27.4   <0.001 546.3  26.3   30.4

Columns: am, vs, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  response 
library(nnet)
nom <- multinom(factor(gear) ~ mpg + am * vs, data = mtcars, trace = FALSE)

# first 5 raw predictions
predictions(nom, type = "probs") |> head()

 Group Estimate Std. Error        z Pr(>|z|)   S     2.5 %   97.5 %
     3 3.62e-05   2.00e-03   0.0181   0.9856 0.0 -3.89e-03 3.96e-03
     3 3.62e-05   2.00e-03   0.0181   0.9856 0.0 -3.89e-03 3.96e-03
     3 9.35e-08   6.91e-06   0.0135   0.9892 0.0 -1.35e-05 1.36e-05
     3 4.04e-01   1.97e-01   2.0567   0.0397 4.7  1.90e-02 7.90e-01
     3 1.00e+00   1.25e-03 802.4784   <0.001 Inf  9.98e-01 1.00e+00
     3 5.18e-01   2.90e-01   1.7884   0.0737 3.8 -4.97e-02 1.09e+00

Columns: rowid, group, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, gear, mpg, am, vs 
Type:  probs 
# average predictions
avg_predictions(nom, type = "probs", by = "group")

 Group Estimate Std. Error     z Pr(>|z|)     S  2.5 % 97.5 %
     3    0.469     0.0404 11.60   <0.001 100.9 0.3895  0.548
     4    0.375     0.0614  6.11   <0.001  29.9 0.2546  0.495
     5    0.156     0.0462  3.38   <0.001  10.4 0.0656  0.247

Columns: group, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high 
Type:  probs 
by <- data.frame(
    group = c("3", "4", "5"),
    by = c("3,4", "3,4", "5"))

predictions(nom, type = "probs", by = by)

  By Estimate Std. Error     z Pr(>|z|)     S  2.5 % 97.5 %
 3,4    0.422     0.0231 18.25   <0.001 244.7 0.3766  0.467
 5      0.156     0.0462  3.38   <0.001  10.4 0.0656  0.247

Columns: estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, by 
Type:  probs 
# sum of predicted probabilities for combined response levels
mod <- multinom(factor(cyl) ~ mpg + am, data = mtcars, trace = FALSE)
by <- data.frame(
    by = c("4,6", "4,6", "8"),
    group = as.character(c(4, 6, 8)))
predictions(mod, newdata = "mean", byfun = sum, by = by)

  By Estimate Std. Error     z Pr(>|z|)    S  2.5 % 97.5 %
 4,6    0.876      0.147 5.955   <0.001 28.5  0.588  1.165
 8      0.124      0.147 0.842      0.4  1.3 -0.165  0.412

Columns: estimate, std.error, statistic, p.value, s.value, conf.low, conf.high, by 
Type:  probs