[R] prediction in a loop with only one sample

PIKAL Petr petr.pikal at precheza.cz
Mon May 13 09:23:27 CEST 2013


Hi

Without reproducible example you probably do not persuade us to go through your almost unreadable code.

>From what you say I think you need split your file to two - training and testing

The approach I would use is sampling a row index.

ind<- sample(1:nrow(some.data), 300)

testing <- some.data[ind,]
training <- some.data[-ind,]

Regards
Petr

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of asdf1234
> Sent: Saturday, May 11, 2013 9:59 AM
> To: r-help at r-project.org
> Subject: [R] prediction in a loop with only one sample
> 
> Dear all,
> 
> I have a sample with 920 observations. I want to create a loop which
> takes 300 of these observations for the prediction and the rest to
> estimate the model.
> 
> My idea was to create something like this:
> 
> cs.training.dat       <- read.table...
> cs.training.dat_sub1 <- subset(cs.training.dat, Income>10)
> cs.training.dat_sub2 <- subset(cs.training.dat_sub1, Dept.Ratio<=1)
> cs.training.dat_sub3 <- subset(cs.training.dat_sub2,
> Credit.Limit.Ratio<=1)
> 
> for (i in 1:500){
> y.2 <- cs.training.dat_sub3$y[1+[i]:300+[i]]
> y.1 <- cs.training.dat_sub3$y[-(1+[i]:300+[i])]
> NTimes.60DaysLate.2 <-
> (cs.training.dat_sub3$NTimes.60DaysLate[1+[i]:300+[i]])
> NTimes.60DaysLate.1 <-
> (cs.training.dat_sub3$NTimes.60DaysLate[-(1+[i]:300+[i])])
> Credit.Limit.Ratio.2 <-
> (cs.training.dat_sub3$Credit.Limit.Ratio[1+[i]:300+[i]])
> Credit.Limit.Ratio.1 <-
> (cs.training.dat_sub3$Credit.Limit.Ratio[-(1+[i]:300+[i])])
> Dept.Ratio.2 <- (cs.training.dat_sub3$Dept.Ratio[1+[i]:300+[i]])
> Dept.Ratio.1 <- (cs.training.dat_sub3$Dept.Ratio[-(1+[i]:300+[i])])
> Numb.Dependents.2 <-
> (cs.training.dat_sub3$Numb.Dependents[1+[i]:300+[i]])
> Numb.Dependents.1 <- (cs.training.dat_sub3$Numb.Dependents[-
> (1+[i]:300+[i]])
> X.1[i] <- cbind(NTimes.60DaysLate.1, Credit.Limit.Ratio.1,
> Dept.Ratio.1,
> Numb.Dependents.1)
> X.2[i] <- cbind(NTimes.60DaysLate.2, Credit.Limit.Ratio.2,
> Dept.Ratio.2,
> Numb.Dependents.2)
> }
> 
> However, I get error massages because R cannot read 1+[i] ...
> Do you have any idea how I can create 500 different pairs from my one
> sample where one variabe contains 300 observation and the other the
> rest?
> 
> Thank you very much in advance.
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/prediction-
> in-a-loop-with-only-one-sample-tp4666819.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list