1

I am running MaxEnt in R which is a species distribution model -- I am trying to run a 10 fold x validation on the data but keep getting two error messages:

Error in data.frame(..., check.names = FALSE) : 
   arguments imply differing number of rows: 1, 2, 0

And the warning message:

In mean.default(sapply(e, function(x) { :
   argument is not numeric or logical: returning NA

I'm somewhat new to R and don't know where I'm going wrong here -- the columns all have the same number of rows and there are no non-numeric values in the data frame... Thanks for any help/thoughts

DavidH
  • 415
  • 4
  • 21
Chris R.
  • 11
  • 1
  • Can you post a [MCVE](https://stackoverflow.com/help/mcve) so that we can reproduce the error? Without code for context, it's difficult to help. – Dan Jan 18 '18 at 18:52
  • Here is the section of code throwing these error messages: – Chris R. Jan 18 '18 at 18:58
  • xVal<- subset(KCwoT.Tng, select = c(ag, cent, jor, kliv, traw, silt)) k <- 10 group <- kfold(xVal, k) e <- list() for (i in 1:k) { train <- xVal[group != i,] test <- xVal[group == i,] trainx<- train[,2:length(xVal)] trainp<- train[,1] me <- maxent(trainx,trainp) testxp<-test[test[,1] == 1,2:length(xVal)] testxa<-test[test[,1] == 0,2:length(xVal)] testp <- predict(me, testxp) testa <- predict(me, testxa) e[[i]] <- evaluate(p=testp, a=testa) } – Chris R. Jan 18 '18 at 18:59
  • mean(sapply( e, function(x){slot(x, 'auc')} )) median(sapply( e, function(x){slot(x, 'auc')} )) mean(sapply( e, function(x){slot(x, 'cor')} )) median(sapply( e, function(x){slot(x, 'cor')} )) KCwoT.ME.eval@TPR[match(threshold(KCwoT.ME.eval)[2],KCwoT.ME.eval@t)] KCwoT.ME.eval@TNR[match(threshold(KCwoT.ME.eval)[2],KCwoT.ME.eval@t)] KCwoT.ME.eval@CCR[match(threshold(KCwoT.ME.eval)[2],KCwoT.ME.eval@t)] – Chris R. Jan 18 '18 at 18:59
  • xVal<- subset(KCwoT.Tng, select = c(ag, cent, jor, kliv, traw, silt)) k <- 10 group <- kfold(xVal, k) e <- list() for (i in 1:k) { train <- xVal[group != i,] test <- xVal[group == i,] trainx<- train[,2:length(xVal)] trainp<- train[,1] me <- maxent(trainx,trainp) testxp<-test[test[,1] == 1,2:length(xVal)] testxa<-test[test[,1] == 0,2:length(xVal)] testp <- predict(me, testxp) testa <- predict(me, testxa) e[[i]] <- evaluate(p=testp, a=testa) } – Chris R. Jan 18 '18 at 19:05
  • You can edit your question to add the code using code tags. Also, you'll need to include the data used. – Dan Jan 18 '18 at 19:15
  • Thanks so much- I'm new to this site and using tags but think I can figure it out. Looks like I just upload the R script and .csv files and add a tag – Chris R. Jan 18 '18 at 19:29
  • I'm sorry can anyone help direct me how to upload files or post an MCVE? I created an example R script and input file (.csv) and made sure it reproduces the same problem I'm having. However I can't figure out how to make that available for folks to see it?.... – Chris R. Jan 18 '18 at 19:56
  • The link I provided in my first comment explains how to post a MCVE. You can edit your original post to add your code and add your example data using `dput` to avoid people having to download a file. – Dan Jan 22 '18 at 12:04

0 Answers0