From 713a3707ae6c3749b669c28599d94d27cbc331a8 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Mon, 11 Sep 2023 10:17:47 -0400 Subject: [PATCH] docs --- R/marginal_means.R | 5 +---- R/predictions.R | 6 +----- R/slopes.R | 3 +-- book/articles/predictions.qmd | 4 ++-- man-roxygen/type.R | 4 +++- man/comparisons.Rd | 9 +++++---- man/get_group_names.Rd | 3 +-- man/get_predict.Rd | 3 +-- man/marginal_means.Rd | 11 +++++------ man/marginalmeans.Rd | 11 +++++------ man/plot_cap.Rd | 3 +-- man/plot_cco.Rd | 3 +-- man/plot_cme.Rd | 3 +-- man/plot_comparisons.Rd | 3 +-- man/plot_predictions.Rd | 3 +-- man/plot_slopes.Rd | 3 +-- man/predictions.Rd | 12 +++++------- man/slopes.Rd | 9 +++++---- 18 files changed, 41 insertions(+), 57 deletions(-) diff --git a/R/marginal_means.R b/R/marginal_means.R index c16c677c3..28a440423 100644 --- a/R/marginal_means.R +++ b/R/marginal_means.R @@ -21,10 +21,7 @@ #' 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 -#' default value is used. This default is the first model-related row in -#' the `marginaleffects:::type_dictionary` dataframe. If `type` is `NULL` and -#' the default value is "response", the function tries to compute marginal means -#' on the link scale before backtransforming them using the inverse link function. +#' first entry in the error message is used by default. #' @param wts character value. Weights to use in the averaging. #' + "equal": each combination of variables in `newdata` gets equal weight. #' + "cells": each combination of values for the variables in the `newdata` gets a weight proportional to its frequency in the original data. diff --git a/R/predictions.R b/R/predictions.R index 8dd9471fd..931574503 100644 --- a/R/predictions.R +++ b/R/predictions.R @@ -14,9 +14,6 @@ #' * #' #' @rdname predictions -#' @details -#' For `glm()`, `MASS::glm.nb`, `gam::gam()`, and `feols::feglm` models with `type`, `transform` and `hypothesis` all equal to `NULL` (the default), `predictions()` first predicts on the link scale, and then backtransforms the estimates and confidence intervals. This implies that the `estimate` produced by `avg_predictions()` will not be exactly equal to the average of the `estimate` column produced by `predictions()`. Users can circumvent this behavior and average predictions directly on the response scale by setting `type="response"` explicitly. With `type="response"`, the intervals are symmetric and may have undesirable properties (e.g., stretching beyond the `[0,1]` bounds for a binary outcome regression). -#' #' @param model Model object #' @param variables Counterfactual variables. #' * Output: @@ -59,8 +56,7 @@ #' 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 -#' default value is used. This default is the first model-related row in -#' the `marginaleffects:::type_dictionary` dataframe. See the details section for a note on backtransformation. +#' first entry in the error message is used by default. #' @param 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. #' #' @template deltamethod diff --git a/R/slopes.R b/R/slopes.R index 7b5b4efbf..ac09a4c37 100644 --- a/R/slopes.R +++ b/R/slopes.R @@ -53,8 +53,7 @@ #' 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 -#' default value is used. This default is the first model-related row in -#' the `marginaleffects:::type_dictionary` dataframe. +#' first entry in the error message is used by default. #' @param slope string indicates the type of slope or (semi-)elasticity to compute: #' - "dydx": dY/dX #' - "eyex": dY/dX * Y / X diff --git a/book/articles/predictions.qmd b/book/articles/predictions.qmd index 58438181f..cc97bbdc3 100644 --- a/book/articles/predictions.qmd +++ b/book/articles/predictions.qmd @@ -178,7 +178,7 @@ pred <- predictions(modlin) mean(pred$estimate) ``` -Note that in GLM models with a non-linear link function, the predictions are first made on the link scale, averaged, and then back transformed. Thus, the average prediction may not be exactly identical to the average of predictions: +Note that in GLM models with a non-linear link function, the default `type` is `linkinv(link)`. This means that predictions are first made on the link scale, averaged, and then back transformed. Thus, the average prediction may not be exactly identical to the average of predictions: ```{r} mod <- glm(vs ~ hp + am, data = mtcars, family = binomial) @@ -224,7 +224,7 @@ predictions( summarize(AAP = mean(estimate)) ``` -Note that the two results are exactly identical when we specify `type="response"` explicitly. However, they will differ slightly when we leave `type` unspecified, because `marginaleffects` will then automatically make predictions and average on the link scale, before backtransforming: +Note that the two results are exactly identical when we specify `type="response"` explicitly. However, they will differ slightly when we leave `type` unspecified, because `marginaleffects` will then automatically make predictions and average on the link scale, before backtransforming (`"linkinv(link)"`): ```{r} predictions( diff --git a/man-roxygen/type.R b/man-roxygen/type.R index e2622b7ff..63d29cd48 100644 --- a/man-roxygen/type.R +++ b/man-roxygen/type.R @@ -1,6 +1,8 @@ #' @section 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 `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 `linkinv(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,1] for a logit model. Note that an average of estimates with `type="linkinv(link)"` will not always be equivalent to the average of estimates with `type="response"`. #' #' Some of the most common `type` values are: #' diff --git a/man/comparisons.Rd b/man/comparisons.Rd index 868b9ed6a..93c1fb917 100644 --- a/man/comparisons.Rd +++ b/man/comparisons.Rd @@ -130,8 +130,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ @@ -408,11 +407,13 @@ Thanks to Russell V. Lenth for the excellent \code{emmeans} package and document \section{Prediction types}{ -The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. +The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. The first entry in the list in that error message is the default type. + +The \code{linkinv(link)} is a special type defined by \code{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: \link{0,1} for a logit model. Note that an average of estimates with \code{type="linkinv(link)"} will not always be equivalent to the average of estimates with \code{type="response"}. Some of the most common \code{type} values are: -response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob +response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linkinv(link), linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob } \examples{ diff --git a/man/get_group_names.Rd b/man/get_group_names.Rd index df652c99c..8be3d3634 100644 --- a/man/get_group_names.Rd +++ b/man/get_group_names.Rd @@ -55,8 +55,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} } \value{ A character vector diff --git a/man/get_predict.Rd b/man/get_predict.Rd index 6f0e0babc..1b0578ad6 100644 --- a/man/get_predict.Rd +++ b/man/get_predict.Rd @@ -150,8 +150,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{...}{Additional arguments are passed to the \code{predict()} method supplied by the modeling package.These arguments are particularly useful diff --git a/man/marginal_means.Rd b/man/marginal_means.Rd index 8ed819a1e..c47f3e98c 100644 --- a/man/marginal_means.Rd +++ b/man/marginal_means.Rd @@ -63,10 +63,7 @@ compute marginal effects or contrasts. 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe. If \code{type} is \code{NULL} and -the default value is "response", the function tries to compute marginal means -on the link scale before backtransforming them using the inverse link function.} +first entry in the error message is used by default.} \item{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.} @@ -270,11 +267,13 @@ Thanks to Russell V. Lenth for the excellent \code{emmeans} package and document \section{Prediction types}{ -The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. +The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. The first entry in the list in that error message is the default type. + +The \code{linkinv(link)} is a special type defined by \code{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: \link{0,1} for a logit model. Note that an average of estimates with \code{type="linkinv(link)"} will not always be equivalent to the average of estimates with \code{type="response"}. Some of the most common \code{type} values are: -response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob +response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linkinv(link), linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob } \examples{ diff --git a/man/marginalmeans.Rd b/man/marginalmeans.Rd index 5802c0aa9..0045f18e2 100644 --- a/man/marginalmeans.Rd +++ b/man/marginalmeans.Rd @@ -63,10 +63,7 @@ compute marginal effects or contrasts. 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe. If \code{type} is \code{NULL} and -the default value is "response", the function tries to compute marginal means -on the link scale before backtransforming them using the inverse link function.} +first entry in the error message is used by default.} \item{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.} @@ -264,11 +261,13 @@ Thanks to Russell V. Lenth for the excellent \code{emmeans} package and document \section{Prediction types}{ -The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. +The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. The first entry in the list in that error message is the default type. + +The \code{linkinv(link)} is a special type defined by \code{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: \link{0,1} for a logit model. Note that an average of estimates with \code{type="linkinv(link)"} will not always be equivalent to the average of estimates with \code{type="response"}. Some of the most common \code{type} values are: -response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob +response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linkinv(link), linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob } \examples{ diff --git a/man/plot_cap.Rd b/man/plot_cap.Rd index 8c3a24fe1..987476531 100644 --- a/man/plot_cap.Rd +++ b/man/plot_cap.Rd @@ -50,8 +50,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/plot_cco.Rd b/man/plot_cco.Rd index c324f36fd..55710b483 100644 --- a/man/plot_cco.Rd +++ b/man/plot_cco.Rd @@ -51,8 +51,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/plot_cme.Rd b/man/plot_cme.Rd index 709241e00..31946a15a 100644 --- a/man/plot_cme.Rd +++ b/man/plot_cme.Rd @@ -50,8 +50,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/plot_comparisons.Rd b/man/plot_comparisons.Rd index e6b200e93..3f4f7bd28 100644 --- a/man/plot_comparisons.Rd +++ b/man/plot_comparisons.Rd @@ -56,8 +56,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/plot_predictions.Rd b/man/plot_predictions.Rd index 6fb81a987..63d041986 100644 --- a/man/plot_predictions.Rd +++ b/man/plot_predictions.Rd @@ -50,8 +50,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/plot_slopes.Rd b/man/plot_slopes.Rd index 18ff52459..424dd629e 100644 --- a/man/plot_slopes.Rd +++ b/man/plot_slopes.Rd @@ -55,8 +55,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{vcov}{Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values: \itemize{ diff --git a/man/predictions.Rd b/man/predictions.Rd index 941056d2b..d59287841 100644 --- a/man/predictions.Rd +++ b/man/predictions.Rd @@ -115,8 +115,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe. See the details section for a note on backtransformation.} +first entry in the error message is used by default.} \item{by}{Aggregate unit-level estimates (aka, marginalize, average over). Valid inputs: \itemize{ @@ -221,9 +220,6 @@ See the predictions vignette and package website for worked examples and case st \item \url{https://marginaleffects.com/} } } -\details{ -For \code{glm()}, \code{MASS::glm.nb}, \code{gam::gam()}, and \code{feols::feglm} models with \code{type}, \code{transform} and \code{hypothesis} all equal to \code{NULL} (the default), \code{predictions()} first predicts on the link scale, and then backtransforms the estimates and confidence intervals. This implies that the \code{estimate} produced by \code{avg_predictions()} will not be exactly equal to the average of the \code{estimate} column produced by \code{predictions()}. Users can circumvent this behavior and average predictions directly on the response scale by setting \code{type="response"} explicitly. With \code{type="response"}, the intervals are symmetric and may have undesirable properties (e.g., stretching beyond the \verb{[0,1]} bounds for a binary outcome regression). -} \section{Functions}{ \itemize{ \item \code{avg_predictions()}: Average predictions @@ -334,11 +330,13 @@ Thanks to Russell V. Lenth for the excellent \code{emmeans} package and document \section{Prediction types}{ -The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. +The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. The first entry in the list in that error message is the default type. + +The \code{linkinv(link)} is a special type defined by \code{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: \link{0,1} for a logit model. Note that an average of estimates with \code{type="linkinv(link)"} will not always be equivalent to the average of estimates with \code{type="response"}. Some of the most common \code{type} values are: -response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob +response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linkinv(link), linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob } \examples{ diff --git a/man/slopes.Rd b/man/slopes.Rd index 77723b8be..cdc2c0347 100644 --- a/man/slopes.Rd +++ b/man/slopes.Rd @@ -76,8 +76,7 @@ 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 \code{type} is \code{NULL}, the -default value is used. This default is the first model-related row in -the \code{marginaleffects:::type_dictionary} dataframe.} +first entry in the error message is used by default.} \item{by}{Aggregate unit-level estimates (aka, marginalize, average over). Valid inputs: \itemize{ @@ -330,11 +329,13 @@ Thanks to Russell V. Lenth for the excellent \code{emmeans} package and document \section{Prediction types}{ -The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. +The \code{type} argument determines the scale of the predictions used to compute quantities of interest with functions from the \code{marginaleffects} package. Admissible values for \code{type} depend on the model object. When users specify an incorrect value for \code{type}, \code{marginaleffects} will raise an informative error with a list of valid \code{type} values for the specific model object. The first entry in the list in that error message is the default type. + +The \code{linkinv(link)} is a special type defined by \code{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: \link{0,1} for a logit model. Note that an average of estimates with \code{type="linkinv(link)"} will not always be equivalent to the average of estimates with \code{type="response"}. Some of the most common \code{type} values are: -response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob +response, link, E, Ep, average, class, conditional, count, cum.prob, cumprob, density, disp, expected, expvalue, fitted, latent, linear.predictor, linkinv(link), linpred, location, lp, mean, p, pr, precision, prediction, prob, probability, probs, quantile, risk, scale, survival, unconditional, utility, variance, xb, zero, zlink, zprob } \examples{