s-news
[Top] [All Lists]

Re: cv.tree in a function

To: Patrick Burns <pburns@pburns.seanet.com>
Subject: Re: cv.tree in a function
From: Odile <mullodi@yahoo.fr>
Date: Wed, 7 Sep 2005 23:16:42 +0200 (CEST)
Cc: s-news@lists.biostat.wustl.edu
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=XA26+eETq+jY4SZ2/MgKB9TOFcA37VUrAm/0tI5glsGpZPgAknQBPPVzoLvKarGNkhSWQQagbnYjadktz60pF9XAR4Zmap+mYJPVvM8igiLn7o97RhJfp8T/sHCzjXhdl1uPaf69CPlfFh9myPcz6v//tWvQU8cYQKCaxTCSBTM= ;
In-reply-to: <431ED4D0.4080704@pburns.seanet.com>
Thanks for your help, I'll try this. S poetry seems to
be a very interesting guide.

Of course, there is a comma here :
cv.tree(arbre, FUN = prune.tree)

Just a mistake in the copy-paste procedure...


--- Patrick Burns <pburns@pburns.seanet.com> a écrit :

> It should work if you assign 'learning' to frame 1.
> S Poetry explains this -- I think mostly in the
> chapter
> on Formulas.
> 
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S
> User")
> 
> Odile wrote:
> 
> > Hello,
> > My s-plus programm does not work and I do not know
> why! The problem 
> > may come from the function cv.tree.
> >  
> > Here is my function :
> >  
> >
> > "bagging"<-
> >
> > function(learning,test)
> >
> > {
> >
> > n <- nrow(learning)
> >
> > m <- nrow(test)
> >
> > K <- 25
> >
> > predi <- matrix(nrow = m, ncol = K)
> >
> > arbre <- tree(learning)
> >
> > cval <- cv.tree(arbre FUN = prune.tree)  # It
> stops here!
> >
> > print("here") # That is not printed...
> >
> > for (i in 1:K){
> >
> > XXX <- learning[sample(n,n,T),]
> >
> > arb <-
>
tree(XXX,control=tree.control(nrow(learning),mindev=0.005))
> >
> > cval <- cv.tree(arb, FUN = prune.tree)
> >
> > mi <- min(cval$dev)
> >
> > p <- min(cval$size[cval$dev==mi]) # (number of
> nodes when the deviance 
> > is min)
> >
> > elag <- prune.tree(arb, best=p)
> >
> > predi[,i] <- predict.tree(elag,newdata=test)
> >
> > }
> >
> > pred <- rowMeans(predi)
> >
> > errors(pred,test[,1])
> >
> > }
> >
> > bagging(app1,test1)
> >
> > S-plus reply is :
> >
> > "Error: Object "learning" not found"
> >
> > or if I just run what is inside for {}, I get
> "missing values are not 
> > allowed"
> >
> > app1 and test1 are dataframes I get with the
> funtion read.table and 
> > they do not contain any missing values. Actually,
> if I type :
> >
> > arbre <- tree(app1)
> >
> > cval <- cv.tree(arbre, FUN = prune.tree) 
> >
> > in the command window, it works (cval is
> calculated).
> >
> > Thanks for your help,
> >
> > odile.
> >
> >
> 


        

        
                
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com

<Prev in Thread] Current Thread [Next in Thread>