Re: [R] Predicting classification error from rpart

From: Andy Bunn <abunn_at_whrc.org>
Date: Sat 15 Oct 2005 - 03:53:23 EST


Anthony. Look at ?predict.rpart, I think this might be the kind of table you are looking for.

     data(iris)
     sub <- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25))
     fit <- rpart(Species ~ ., data=iris, subset=sub)
     fit
     table(predict(fit, iris[-sub,], type="class"), iris[-sub, "Species"])

HTH, Andy

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch]On Behalf Of Anthony Staines
> Sent: Friday, October 14, 2005 1:44 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Predicting classification error from rpart
>
>
> Hi,
>
> I think I'm missing something very obvious, but I am missing it, so I
> would be very grateful for help. I'm using rpart to analyse data on
> skull base morphology, essentially predicting sex from one or several
> skull base measurements. The sex of the people whose skulls are being
> studied is known, and lives as a factor (M,F) in the data. I want to
> get back predictions of gender, and particularly misclassification
> rates.
>
> rpart produces output like this :-
>
> > printcp(rpart.LFM)
> Classification tree:
> rpart(formula = Sex ~ LFM, data = Brides2)
> Variables actually used in tree construction: LFM
> Root node error: 44/104 = 0.42308 n= 104
>
> CP nsplit rel error xerror xstd
> 1 0.227273 0 1.00000 1.00000 0.11451
> 2 0.113636 1 0.77273 0.95455 0.11372
> 3 0.022727 2 0.65909 0.95455 0.11372
> 4 0.010000 5 0.59091 0.95455 0.11372
> >
>
> Presumably 'root node error' and 'rel error' are something to do with
> error but what? 'Root node error ' seems to be some sort of deviance,
> and I have no idea what 'rel error' is. the tree library does produce
> a simple estimate of misclassification, but rpart doesn't seem to.
>
> Any ideas?
>
> Thanks,
> Anthony Staines
> --
> Dr. Anthony Staines, Senior Lecturer in Epidemiology.
> School of Public Health and Population Sciences, UCD, Earlsfort
> Terrace, Dublin 2, Ireland.
> Tel:- +353 1 716 7345. Fax:- +353 1 716 7407 Mobile:- +353 86 606 9713
> Web:- http://phm.ucd.ie
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 15 04:03:43 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:54:23 EST