rpart (version 1.0-6)

rpart: Recursive Partitioning and Regression Trees

Description

Fit a rpart model

Usage

rpart(formula, data, weights, subset, na.action=na.rpart, method,
	     model=F, x=F, y=T, parms, control=rpart.control(...), ...)

Arguments

formula
a formula, as in the lm function.
data
an optional data frame in which to interpret the variables named in the formula
weights
optional weights (currently ignored).
subset
optional expression saying that only a subset of the rows of the data should be used in the fit.
na.action
The default action deletes all observations for which y is missing, but keeps those in which one or more predictors are missing.
method
one of "anova", "poisson", "class" or "exp". If method is missing then the routine tries to make an intellegent guess. If y is a survival object, then method="exp"
model
keep a copy of the model frame in the result. If the input value for model is a model frame (likely from an earlier call to the rpart function), then this frame is used rather than constructing new data.
x
keep a copy of the x matrix in the result.
y
keep a copy of the dependent variable in the result.
parms
optional parameters for the splitting function. Anova splitting has no parameters. Poisson splitting has a single parameter, the coefficient of variation of the prior distribution on the rates. The default value is 1. Exponential splitting has the same p
control
options that control details of the rpart algorithm.
...
arguments to rpart.control may also be specified in the call to rpart.

Value

  • an object of class rpart, a superset of class tree.

Details

This differs from the tree function mainly in its handling of surrogate variables.

References

Breiman, Friedman, Olshen, and Stone. (1984) Classification and Regression Trees. Wadsworth.

See Also

rpart.control, rpart.object, tree, summary.rpart, print.rpart

Examples

Run this code
data(kyphosis)
fit <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis)
fit2 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis,
              parms=list(prior=c(.65,.35), split='information'))
fit3 <- rpart(Kyphosis ~ Age + Number + Start, data=kyphosis,
              control=rpart.control(cp=.05))
par(mfrow=c(1,2))
plot(fit)
text(fit,use.n=T)
plot(fit2)
text(fit2,use.n=T)

Run the code above in your browser using DataLab