[R] Rotation Forest Error Message

Rasmus Liland jr@| @end|ng |rom po@teo@no
Fri Aug 21 10:18:11 CEST 2020


On 2020-08-21 16:22 +1200, Abby Spurdle wrote:
| On Fri, Aug 21, 2020 at 4:16 PM Abby Spurdle <spurdle.a using gmail.com> wrote:
| | On Fri, Aug 21, 2020 at 1:06 PM Sparks, John <jspark4 using uic.edu> wrote:
| | |
| | | Hi R Helpers,
| | |
| | | I wanted to try the rotationForest 
| | | package.
| | |
| | | I pointed it at my data set and 
| | | got the error message "Error in if 
| | | (K >= ncol(x)) stop("K should not 
| | | be greater than or equal to the 
| | | number of columns in x") :
| | |   argument is of length zero'.
| | |
| | | My dataset has 3688 obs. of  111 variables.
| | |
| | | Would a quick adjustment to the 
| | | default value of K resolve this?
| | |
| | | If anybody with more experience 
| | | with the package than me has a 
| | | general suggestion I would 
| | | appreciate it.
| |
| | Note that I'm not familiar with this 
| | package or the method.  Also note 
| | that you haven't told anyone what 
| | function you're using, or what your 
| | call was.
| |
| | I'm assuming that you're using the 
| | rotationForest() function.  
| | According to its help page, the 
| | default is:
| |
| |     K = round(ncol(x)/3, 0)
| |
| | There's no reason why the default K 
| | value should be higher than the 
| | number of columns, unless:
| | (1) There's a bug with the package; or
| | (2) There's a problem with your input.
| |
| | I note that the package is only 
| | version 0.1.3, so a bug is not out 
| | of the question.  Also, I'm a little 
| | surprised the author didn't use 
| | integer division:
| |
| |     K = ncol(x) %/% 3
| |
| | You could just set K to the above 
| | value, and see what happens...
| 
| Just re-read your question and 
| realized I misread the error message.  
| The argument is of zero length.
| 
| But the conclusion is the same, either 
| a bug in the package, or a problem 
| with your input.

Dear John,

check to see if your columns only has 
numbers in them like the *de jure* iris 
dataset used in the example in 
?rotationForest::rotationForest.

	idx <- 1:100
	idx.new <- which(!(1:nrow(iris) %in% idx))
	y <- as.factor(ifelse(iris$Species[idx]=="setosa", 0, 1))
	x <- iris[idx, -5]
	newdata <- iris[idx.new, -5]
	K <- ncol(x) %/% 3
	L <- 100
	rF <-
	  rotationForest::rotationForest(
	    x=x,
	    y=y,
	    K=K,
	    L=L)
	predict(object=rF, newdata=newdata)

Best,
Rasmus



More information about the R-help mailing list