Skip to contents
loading...

fit_model() takes a model_spec object from {parsnip} and it fits is. Then, usual methods like summary(), or coef() can be applied directly on it, while it can still be used as the {tidymodels} recommends it.

Usage

fit_model(data, formula, ..., type = NULL, env = parent.frame())

# S3 method for model_fit
summary(object, ...)

# S3 method for model_fit
anova(object, ...)

# S3 method for model_fit
plot(x, y, ...)

# S3 method for model_fit
chart(data, ..., type = "model", env = parent.frame())

# S3 method for model_fit
as.function(x, ...)

# S3 method for model_fit
coef(object, ...)

# S3 method for model_fit
vcov(object, ...)

# S3 method for model_fit
confint(object, parm, level = 0.95, ...)

# S3 method for model_fit
fitted(object, ...)

# S3 method for model_fit
residuals(object, ...)

# S3 method for model_fit
rstandard(model, ...)

# S3 method for model_fit
cooks.distance(model, ...)

# S3 method for model_fit
hatvalues(model, ...)

# S3 method for model_fit
deviance(object, ...)

# S3 method for model_fit
AIC(object, ..., k = 2)

# S3 method for model_fit
BIC(object, ...)

# S3 method for model_fit
family(object, ...)

# S3 method for model_fit
nobs(object, ...)

# S3 method for model_fit
formula(x, ...)

# S3 method for model_fit
variable.names(object, ...)

# S3 method for model_fit
labels(object, ...)

Arguments

data

A data frame (or a model_fit object for chart())

formula

A formula specifying a model

...

Further arguments passed to the method

type

The type of model fitting, specified by a model_spec object or the name of such an object in a string

env

The environment where to evaluate type. It is parent.frame() by default and you probably have no reasons to change it, unless you really know what you are doing!

object

A model_fit object

x

Idem

y

Not used here

parm

Specification of parameters for the confidence intervals (vector of numbers or of names). If missing, all parameters are considered.

level

Confidence level required.

model

Idem

k

The penalty per parameter to be used in the AIC (by default, k = 2).

Value

A model_fit object.

Examples

library(parsnip)
data(trees, package = "datasets")

# Take the habit to prefix your regression model specs by `reg_`
reg_lm <- linear_reg(mod = "regression", engine = "lm")
trees_fit <- fit_model$reg_lm(data = trees, Volume ~ Girth)
#> Error in x(type = name, ...): The type= argument must provide a model_spec object or its name in a character string.

# You can use summary(), AIC(), anova(), tidy(), glance(), etc. directly
summary(trees_fit)
#> Error in eval(expr, envir, enclos): object 'trees_fit' not found
anova(trees_fit)
#> Error in eval(expr, envir, enclos): object 'trees_fit' not found
AIC(trees_fit)
#> Error in eval(expr, envir, enclos): object 'trees_fit' not found
coef(trees_fit)
#> Error in eval(expr, envir, enclos): object 'trees_fit' not found
library(chart)
chart(trees_fit)
#> Error in eval(expr, envir, enclos): object 'trees_fit' not found
# etc.