View source: R/mid_conditional.R
mid.conditional | R Documentation |
mid.conditional()
calculates the data required to draw Individual Conditional Expectation (ICE) curves from a fitted MID model.
ICE curves visualize how a single observation's prediction changes as a specified variable's value varies, while all other variable are held constant.
mid.conditional(
object,
variable,
data = NULL,
n.samples = 100L,
max.nrow = 100000L,
type = c("response", "link"),
keep.effects = TRUE
)
object |
a "mid" object. |
variable |
a character string or expression specifying the single predictor variable for which to calculate ICE curves. |
data |
a data frame containing the observations to be used for the ICE calculations. If not provided, data is automatically extracted based on the function call. |
n.samples |
the number of sample points for the |
max.nrow |
the maximum number of rows for the output data frames. If the number of evaluation points exceeds this limit, the original data is randomly subsampled. |
type |
the type of prediction to return. "response" (default) for the original scale or "link" for the scale of the linear predictor. |
keep.effects |
logical. If |
The function generates a set of hypothetical observations by creating copies of the original data and varying the specified variable
across a range of sample points.
It then obtains a prediction for each of these hypothetical observations from the MID model. The returned object can be plotted to visualize the ICE curves.
mid.conditional()
returns an object of class "mid.conditional". This is a list with the following components:
terms |
a character vector of relevant terms for the |
observed |
a data frame of the original observations used, along with their predictions. |
conditional |
a data frame of the hypothetical observations and their corresponding predictions. |
values |
a vector of the sample points for the |
interpret
, plot.mid.conditional
, ggmid.mid.conditional
data(airquality, package = "datasets")
mid <- interpret(Ozone ~ .^2, data = airquality, lambda = 1)
# Calculate the ICE values for a fitted MID model
ice <- mid.conditional(mid, variable = "Wind", data = airquality)
print(ice)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.