[R] rpart.predict error--subscript out of bounds

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Apr 7 10:09:18 CEST 2006


Leon wrote:

> Hi,
> I am using rpart to do leave one out cross validation, but met some problem,
> Data is a data frame, the first column is the subject id, the second column is the group id, and the rest columns are numerical variables,
> 
> 
>>Data[1:5,1:10]
> 
>   sub.id group.id X3262.345 X3277.402 X3369.036 X3439.895 X3886.935 X3939.054 X3953.777 X3970.352
> 1  32613  HAM_TSP  417.7082  430.4895  619.4776  720.8246 1048.1290  374.4598  770.4653  646.8712
> 2  32616  HAM_TSP 2553.5913 1113.4997  225.5340  274.5644 1105.7908  363.4623 2380.1872  784.9196
> 3  32617  HAM_TSP  291.6596  314.7322  238.3287  315.8305  982.6276  299.5855 1059.1140  540.8592
> 4  32628  HAM_TSP  456.9504  508.2278  552.3632  719.9989 1306.6299  446.6184 1352.9955  867.4219
> 5  32629  HAM_TSP  898.8879  640.2680  342.5477  386.5816  811.6709  518.0244  715.9886  441.1622
> 
> Example, I use the first sample as test set, the rest as training set
> 
> 
>>fit <- rpart(as.factor(Data[-1,2]) ~., Data[-1, -c(1:2 ) ], minbucket=2  )
> 
> 
>>predict(fit, Data[1,],type='prob')
> 
> Error in predict.rpart(fit, Data[1, ]) : subscript out of bounds


rpart has only seen one class so far, hence the tree consists of the 
root only.

Uwe Ligges



> but when I changes the parameter of type into 'class'
> it works well
> 
> 
>>predict(fit, Data[1,-c(1:2)],type='class')
> 
> [1] HTLV_Carrier
> Levels: HAM_TSP HTLV_Carrier Leukemia Normal
> 
> Could anyone tell me what is the problem with it?
> 
> Thanks very much in advance!
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list