Re: [R] cross validation function translated from stata

2010-01-21 Thread zhu yao
Thanks Frank and Steve. I rewrite the R code as follows. # m is the number of fold to split sample, n is the loop number of cross validation library(caret) calcvnb<-function(formula,dat,m,n) { cvnb<-rep(0,2) dim(cvnb)<-c(200,100) for (i in 1:n) { group<-rep(0,length=110) sg<-createFolds(d

Re: [R] cross validation function translated from stata

2010-01-21 Thread Frank E Harrell Jr
Take a look at the validate.lrm function in the rms package. Note that the use of threshold probabilities results in an improper scoring rule which will mislead you. Also note that you need to repeat 10-fold CV 50-100 times for precision, and that at each repeat you have to start from zero in

Re: [R] cross validation function translated from stata

2010-01-21 Thread Steve Lianoglou
Hi, On Thu, Jan 21, 2010 at 8:55 AM, zhu yao wrote: > Hi, everyone: > > I ask for help about translating a stata program into R. > > The program perform cross validation as it stated. > > #1. Randomly divide the data set into 10 sets of equal size, ensuring equal > numbers of events in each set >

[R] cross validation function translated from stata

2010-01-21 Thread zhu yao
Hi, everyone: I ask for help about translating a stata program into R. The program perform cross validation as it stated. #1. Randomly divide the data set into 10 sets of equal size, ensuring equal numbers of events in each set #2. Fit the model leaving out the 1st set #3. Apply the fitted model