Re: [R] repeating an analysis

2010-10-18 Thread Andrew Halford
Hi All, For those still interested the code submitted by Phil (see below) worked a treat and produced a vector with the optimal 'nsplit' collated from 50 runs of the rpart model. I then produced a histogram for the vector called answer and chose my modal number for nsplits from which I had my

Re: [R] repeating an analysis

2010-10-13 Thread Andrew Halford
thanks Phil, I have your solution and another which I will attempt in the next day or so and will post results to the list then. cheers andy On Wed, Oct 13, 2010 at 10:30 AM, Phil Spector spec...@stat.berkeley.eduwrote: Andrew - I think answer = replicate(50,{fit1 -

[R] repeating an analysis

2010-10-12 Thread Andrew Halford
Hi All, I have to say upfront that I am a complete neophyte when it comes to programming. Nevertheless I enjoy the challenge of using R because of its incredible statistical resources. My problem is this .I am running a regression tree analysis using rpart and I need to run the

Re: [R] repeating an analysis

2010-10-12 Thread Phil Spector
Andrew - I think answer = replicate(50,{fit1 - rpart(CHAB~.,data=chabun, method=anova, control=rpart.control(minsplit=10, cp=0.01, xval=10)); x = printcp(fit1);

Re: [R] repeating an analysis

2010-10-12 Thread Peter Langfelder
I think you want something like this: optimal.nSplit = rep(NA, 50) # This will hold the result for (run in 1:50) { fit1 = rpart(...) cpTable = fit1$cptable bestRow = which.min(cpTable[, xerror]); optimal.nSplit[run] = cpTable[bestRow, nsplit] } In any case, look at ?rpart ?printcp