Wiener, Matthew
2003-Dec-03 16:26 UTC
[R] Error in randomForest.default(m, y, ...) : negative lengt h vectors are not allowed
Christian -- You don't provide enough information (like a call) to answer this. I suspect, though, that you may be subsetting in a way that passes randomForest no data. I'm not aware offhand of an easy way to get this error from randomForest. I tried creating some data superficially similar to yours to see whether something would break if there were only a single value in the variable to be explained, but everything worked fine (though it does give a reasonable warning).> test.dat <- data.frame(a = rep(0, 1000), b = runif(1000), c = sample(0:1,1000, replace = TRUE, p = c(.8, .2))> t8 <- randomForest(a ~ b + c, data = test.dat)Warning message: The response has five or fewer unique values. Are you sure you want to do regression? in: randomForest.default(m, y, ...)> test.dat[sample(1:1000, 100),"a"] <- runif(100, 1, 200) > t8 <- randomForest(a ~ b + c, data = test.dat)Some other generated data might come up with the error, but I'd bet on the subsetting problem. Hope this helps, -Matt Matthew Wiener RY84-202 Applied Computer Science & Mathematics Dept. Merck Research Labs 126 E. Lincoln Ave. Rahway, NJ 07065 732-594-5303 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Christian Schulz Sent: Wednesday, December 03, 2003 9:42 AM To: r-help at stat.math.ethz.ch Subject: [R] Error in randomForest.default(m, y, ...) : negative length vectors are not allowed Hi, what i'm doing wrong? I'm using a data.frame with ~ 90.000 instances and 7 attributes, 5 are binary recoded 1 independend variable are a real one and the target is a real one,too. The distributions are not very skewed in the dummy variables ,but in the real variables are ~ 60.000 zero values instances, but zero means no money is payed and is a important value! Many thanks for help & suggestions, regards,christian ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Christian Schulz
2003-Dec-03 17:22 UTC
AW: [R] Error in randomForest.default(m, y, ...) : negative length vectors are not allowed
Hmmm, thanks for your suggestions i'm in the same opinion with any subsetting problem, but curious is that my model i.e. with library(gbm) or simple lm works, because my task is to find out the weights/importance values for the attributes and i would like compare the results between the randomForest classifier and a linear approach. I check it with your suggestions and code snippets in detail and feedback you the problem, if i found the solution. regards,Christian -----Urspr?ngliche Nachricht----- Von: Wiener, Matthew [mailto:matthew_wiener at merck.com] Gesendet: Mittwoch, 3. Dezember 2003 17:26 An: 'Christian Schulz'; r-help at stat.math.ethz.ch Betreff: RE: [R] Error in randomForest.default(m, y, ...) : negative lengt h vectors are not allowed Christian -- You don't provide enough information (like a call) to answer this. I suspect, though, that you may be subsetting in a way that passes randomForest no data. I'm not aware offhand of an easy way to get this error from randomForest. I tried creating some data superficially similar to yours to see whether something would break if there were only a single value in the variable to be explained, but everything worked fine (though it does give a reasonable warning).> test.dat <- data.frame(a = rep(0, 1000), b = runif(1000), c = sample(0:1,1000, replace = TRUE, p = c(.8, .2))> t8 <- randomForest(a ~ b + c, data = test.dat)Warning message: The response has five or fewer unique values. Are you sure you want to do regression? in: randomForest.default(m, y, ...)> test.dat[sample(1:1000, 100),"a"] <- runif(100, 1, 200) > t8 <- randomForest(a ~ b + c, data = test.dat)Some other generated data might come up with the error, but I'd bet on the subsetting problem. Hope this helps, -Matt Matthew Wiener RY84-202 Applied Computer Science & Mathematics Dept. Merck Research Labs 126 E. Lincoln Ave. Rahway, NJ 07065 732-594-5303 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Christian Schulz Sent: Wednesday, December 03, 2003 9:42 AM To: r-help at stat.math.ethz.ch Subject: [R] Error in randomForest.default(m, y, ...) : negative length vectors are not allowed Hi, what i'm doing wrong? I'm using a data.frame with ~ 90.000 instances and 7 attributes, 5 are binary recoded 1 independend variable are a real one and the target is a real one,too. The distributions are not very skewed in the dummy variables ,but in the real variables are ~ 60.000 zero values instances, but zero means no money is payed and is a important value! Many thanks for help & suggestions, regards,christian ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help