Augment your model object

# S3 method for rpart
augment(x, data = NULL, newdata = NULL, ...)

Arguments

x

rpart model

data

data.frame from the model

newdata

new data to use for predictions, residuals, etc.

...

extra arguments to pass

Value

augment.rpart returns the original data with additional columns:

  • .fitted: The fitted value or class.

  • .resid: only given when the same data as was used for the model is provided.

Examples

library(rpart) rpart_fit <- rpart(Sepal.Width ~ ., iris) augment(rpart_fit)
#> # A tibble: 150 x 7 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species .fitted .resid #> <dbl> <dbl> <dbl> <dbl> <fct> <dbl> <dbl> #> 1 5.1 3.5 1.4 0.2 setosa 3.71 0.214 #> 2 4.9 3 1.4 0.2 setosa 3.20 0.204 #> 3 4.7 3.2 1.3 0.2 setosa 3.20 0.00357 #> 4 4.6 3.1 1.5 0.2 setosa 3.20 0.104 #> 5 5 3.6 1.4 0.2 setosa 3.20 -0.396 #> 6 5.4 3.9 1.7 0.4 setosa 3.71 -0.186 #> 7 4.6 3.4 1.4 0.3 setosa 3.20 -0.196 #> 8 5 3.4 1.5 0.2 setosa 3.20 -0.196 #> 9 4.4 2.9 1.4 0.2 setosa 3.20 0.304 #> 10 4.9 3.1 1.5 0.1 setosa 3.20 0.104 #> # … with 140 more rows