fit.nested_model {nestedmodels} | R Documentation |
Fit a nested model to a dataset
Description
fit.model_spec()
takes a nested model specification and fits the inner
model specification to each nested data frame in the given dataset.
Usage
## S3 method for class 'nested_model'
fit(
object,
formula,
data,
case_weights = NULL,
control = parsnip::control_parsnip(),
...
)
Arguments
object |
An |
formula |
An object of class |
data |
A data frame. If used with a 'nested_model' object, the data frame must already be nested. |
case_weights |
An optional vector of case weights. Passed into
|
control |
A |
... |
Passed into |
Value
A nested_model_fit
object with several elements:
-
spec
: The model specification object (the inner model of the nested model object) -
fit
: A tibble containing the model fits and the nests that they correspond to. -
inner_names
: A character vector of names, used to help with nesting the data during predictions.
See Also
parsnip::fit.model_spec()
parsnip::model_fit
Examples
library(parsnip)
library(tidyr)
model <- linear_reg() %>%
set_engine("lm") %>%
nested()
nested_data <- nest(example_nested_data, data = -id)
fit(model, z ~ x + y + a + b, nested_data)