Hi,

I was trying to do cross-validation using the crossval function (bootstrap 
package), with the following code:

---------------------------------------------------------------------------------------------------------

 theta.fit <- function(x,y){     
      model <- svm(x,y,kernel = "linear") 
 }
 
 theta.predict <- function(fit,x){
      prediction <- predict(fit,x)            
      return(prediction)
 }
 
 x <- matrix(rnorm(5100),102,50)
 rownames(x) <- paste('a',1:102,sep='')
 colnames(x) <- paste('b',1:50,sep='')
 y <- factor(sample(1:2,102,replace=T))
 
 results <- crossval(x,y,theta.fit,theta.predict)   # LOOCV 

-----------------------------------------------------------------------------------------------------------

I get the following error:

Error in scale(newdata[, object$scaled, drop = FALSE], center = 
object$x.scale$"scaled:center",  : 
  (subscript) logical subscript too long

It seems to work alright if I use 10 fold cross validation (e.g. results <- 
crossval(x,y,theta.fit,theta.predict,ngroup = 10), but gives the error for 
LOOCV.

What am I doing wrong?

thanks!

My session info is:
> sessionInfo()
R version 2.7.1 (2008-06-23) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rpart_3.1-41     lattice_0.17-8   ROCR_1.0-2       gplots_2.6.0    
[5] gdata_2.4.2      gtools_2.5.0     e1071_1.5-18     class_7.2-42    
[9] bootstrap_1.0-21

loaded via a namespace (and not attached):
[1] grid_2.7.1  tools_2.7.1


---------------------------------------------------------------------------------------------------------



      
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to