A wrapper is used because the model interface requires the response variable
to be numeric rather than ordered or factor; the wrapper edits the input
data accordingly.
Value
An object of S3 class rpart as returned by
rpartScore::rpartScore().
Examples
house_data <-
MASS::housing[rep(seq(nrow(MASS::housing)), MASS::housing$Freq), -5]
# subsample to reduce runtime
house_data <- house_data[sample(nrow(house_data), nrow(house_data) / 5), ]
# fit wrapper
( fit_orig <- rpartScore::rpartScore(
formula = Sat ~ Infl + Type + Cont,
data = transform(house_data, Sat = as.integer(Sat))
) )
#> n= 336
#>
#> node), split, n, deviance, yval
#> * denotes terminal node
#>
#> 1) root 336 254 2
#> 2) Infl=Low,Medium 255 182 2 *
#> 3) Infl=High 81 55 3 *
( fit_wrap <- rpartScore_wrapper(
formula = Sat ~ Infl + Type + Cont,
data = house_data
) )
#> n= 336
#>
#> node), split, n, deviance, yval
#> * denotes terminal node
#>
#> 1) root 336 254 2
#> 2) Infl=Low,Medium 255 182 2 *
#> 3) Infl=High 81 55 3 *