[R] help with plot.rpart
Sarah Goslee
sarah.goslee at gmail.com
Fri Jul 29 17:24:31 CEST 2011
Ah, now we're getting somewhere. Think how easy this would be if
you'd provided this information initially.
On Fri, Jul 29, 2011 at 11:11 AM, <mark at statcourse.com> wrote:
> Ø data=read.table("http://statcourse.com/research/boston.csv", , sep=",",
> header = TRUE)
> Ø library(rpart)
> Ø fit=rpart (MV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+ PT+B+LSTAT)
> Please: Show me the tree.
> Mark
Well, your rpart() statement won't run, so obviously you can't see the tree.
There's no data argument, and the variable names don't match the
column headers in the data you provided.
Here's a revised version, that prints and plots the tree, and predicts
some test data.
# corrected rpart(), guessing at what you meant
markdata <- read.table("http://statcourse.com/research/boston.csv", ,
sep=",", header = TRUE)
fit <- rpart (MEDV~ CRIM+ZN+INDUS+CHAS+NOX+RM+AGE+DIS+RAD+TAX+
PTRATIO+B+LSTAT, data=markdata)
# two ways of looking at the complete tree
fit
plot(fit)
text(fit)
# predicting a few values
mark.subsample <- markdata[1:5,]
predict(fit, mark.subsample, type="vector")
If this is your actual code, your problem was far more basic than plotting
and predicting. Sharing your error messages would have been a good start.
Sarah
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list