-1

My R sessionInfo() of the failed runs:

R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] caper_0.5.2     mvtnorm_1.0-2   MASS_7.3-35    
[4] gsubfn_0.6-6    proto_0.3-10    picante_1.6-2  
[7] nlme_3.1-118    vegan_2.2-1     lattice_0.20-29
[10] permute_0.8-3   ape_3.2        

loaded via a namespace (and not attached):
[1] cluster_1.15.3 grid_3.1.2     Matrix_1.1-4  
[4] mgcv_1.8-3     parallel_3.1.2 tcltk_3.1.2   
[7] tools_3.1.2 

I'm working on isolating which variables cause the specif failure upon interaction. (Update: There is no specific predictor, it's just the number of predictors going above a thresh hold determine by the # of species)


I have an error which appears to be internal to the "caper" package within R. The exact error is:

Error in if (any(stRes > robust)) { : missing value where TRUE/FALSE needed

Where the error occurs on this line of code:
crunchMod <- crunch(f, data = contrasts)

Using dataSet1.txt below with 7 predictors, I find that the regression works perfectly with ), )^2 and )^3. Using dataSet2.txt below with 12 predictors, I find that only ")" works and both )^2 and )^3 produce the error above. Here is the minimal code needed to reproduce my error:

library(caper)
library(ape)

setwd("Your_Directory")
caperDS <- read.table("dataSet1.txt", header = TRUE) #Also include "dataSet2.txt"

myTrees = read.nexus("Tree1.tre") #Also include "Tree2.tre"

contrasts <- comparative.data(myTrees, caperDS, Species)
f <- as.formula(paste(paste(names(caperDS)[2],"~"), paste(paste("(",paste(names(caperDS)[3:ncol(caperDS)], collapse="+"))),")^3")) #Vary this between ")", ")^2" and ")^3"
crunchMod <- crunch(f, data = contrasts)
print(summary(crunchMod))

Due to the space it took, I've redacted the data I provided earlier. Since it is now apparent that this error is a general problem (see below), you can find data sets to examine cited within http://cran.r-project.org/web/packages/caper/vignettes/caper.pdf

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3834916
  • 143
  • 1
  • 11
  • I didn't downvote, but generally "is this code correct" type questions are not useful. We cannot run the code you posted because we don't have any input data to run it on. Plus, it helps if the code you post is the minimal amount to reproduce the error. I looks like you have a bunch of stuff that's not directly related to your problem. Review [how to make a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips to improve your question. – MrFlick Feb 04 '15 at 17:35
  • BTW: you said *this code is no where present within my program*. Perhaps you should look at the functions you are using. For instance, if you just type in `caper::crunch`, you'll see (near the end) the code in question. This doesn't answer you question, but it shows you the code with the error, a **great** step towards finding out why your specific instance is not working properly. Ditto to @MrFlick, without (simple) input data, (simpler) code, and clearly-defined expected output, there's not much we can do to help. – r2evans Feb 04 '15 at 17:38
  • Judging by the error, I would guess you have some missing values in some of your variables. Try running `na.omit()` on your data first. Also not your downvoter, but to make this a better question you should really try to isolate where the bug is... your `folders` variables and the way you construct your formula don't matter here. Find a single formula that produces an error, try to run `crunch` directly on your data with that formula, and run your code line by line until you find the line with the error. – Gregor Thomas Feb 04 '15 at 17:40
  • I hope I made this question more reproducible! Thanks for the feedback. – user3834916 Feb 04 '15 at 18:43

1 Answers1

0

Ok, so I did a lot of experimentation and the answer is almost surely that I was putting too many predictors into the crunch() function and it "broke". The number of predictors it can accept varies upon how many subjects are present within the data set.

I came to this conclusion because it did not matter what predictors I removed; it was good enough to just remove a few at random. However, I don't understand why the crunch() function yields an error from this situation instead of exiting peacefully (assuming the behavior is intended). If someone could elaborate further on this in a comment/subsequent answer, I would appreciate it.

user3834916
  • 143
  • 1
  • 11