Poisson Recursive Partitioning and Regression Trees with Exposures
Source:R/rpart.R
rpart_exposure.Rd
This function is a wrapper around rpart::rpart()
for Poisson regression
trees using weighted exposures (observation times).
Usage
rpart_exposure(
formula,
data,
exposure_col = "exposure",
weights = NULL,
control,
cost,
shrink = 1,
...
)
Arguments
- formula
A model formula that contains a single response variable on the left-hand side.
- data
Optional. A data frame containing variables used in the model.
- exposure_col
Character string. The name of a column in
data
containing exposures.- weights
Optional weights to use in the fitting process.
- control
A list of hyperparameters. See
rpart::rpart.control()
.- cost
A vector of non-negative costs for each variable in the model.
- shrink
Optional parameter for the splitting function. Coefficient of variation of the prior distribution.
- ...
Alternative input for arguments passed to
rpart::rpart.control()
.
Details
Outside of the tidymodels
ecosystem, rpart_exposure()
has no
advantages over rpart::rpart()
since that function allows for exposures to
be specified in the formula interface by passing cbind(exposure, y)
as a
response variable.
Within tidymodels
, rpart_exposure()
provides an advantage because
it will ensure that exposures are included in the data whenever resamples are
created.
The formula
, data
, weights
, control
, and cost
arguments have the
same meanings as rpart::rpart()
. shrink
is passed to rpart::rpart()
's
parms
argument via a named list. See that function's documentation for full
details.
Examples
rpart_exposure(deaths ~ age_group + gender, us_deaths,
exposure_col = "population")
#> n= 140
#>
#> node), split, n, deviance, yval
#> * denotes terminal node
#>
#> 1) root 140 51701770.0 0.012433090
#> 2) age_group=25-34,35-44,45-54,55-64,65-74 100 10090330.0 0.005996979
#> 4) age_group=25-34,35-44,45-54 60 1037681.0 0.002401215
#> 8) age_group=25-34,35-44 40 219942.2 0.001550297 *
#> 9) age_group=45-54 20 102550.3 0.004096230 *
#> 5) age_group=55-64,65-74 40 1598645.0 0.012700650
#> 10) age_group=55-64 20 246107.6 0.008899093 *
#> 11) age_group=65-74 20 237356.1 0.018263680 *
#> 3) age_group=75-84,85+ 40 4697172.0 0.073516860
#> 6) age_group=75-84 20 170261.7 0.045847100 *
#> 7) age_group=85+ 20 45488.2 0.137105000 *