fit_model: Fit a parsnip model and manipulate it as a base R model like...

fit_modelR Documentation

Fit a parsnip model and manipulate it as a base R model like lm

Description

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 class 'model_fit'
summary(object, ...)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

## S3 method for class '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)

# You can use summary(), AIC(), anova(), tidy(), glance(), etc. directly
summary(trees_fit)
anova(trees_fit)
AIC(trees_fit)
coef(trees_fit)
library(chart)
chart(trees_fit)
# etc.

SciViews/modelit documentation built on Nov. 24, 2024, 10:23 a.m.