Search code examples
rvegan

How to run vegan::varpart without having this "NA/NaN/Inf in foreign function call (arg 1)" message error?


I am currently trying to run the varpart function on some of my data but I get the following error every time: "Error in qr.default(X, tol = 1e-06) : NA/NaN/Inf in foreign function call (arg 1)"

Shortly put, my whole dataset contains informations about fishing gears, levels of pressure and different sessions in time. I have no issue running the varpart function on all of my data but if I create a new object with only the data regarding a specific gear and/or a specific pressure it doesnt work anymore....

I checked for missing values but couldnt find one...

Here is an example of my problem:

library(vegan)
#> Le chargement a nécessité le package : permute
#> Le chargement a nécessité le package : lattice
#> This is vegan 2.5-5
A<-runif(45,min=0,max=0.75)
B<-runif(45,min=0,max=0.75)
C<-runif(45,min=0,max=0.75)
SP<-data.frame(cbind(A,B,C))
Session<-as.factor(rep(c("S1","S2","S3","S4","S5"),each=9))
LONG<-rep(c(48.32287917),each=45)
data<-data.frame(cbind(Session,LONG))
data$Session<-as.factor(data$Session)
varpart<-varpart(SP,~ Session,~ LONG, data=data)
#> Error in qr.default(X, tol = 1e-06) : 
  NA/NaN/Inf in foreign function call (arg 1)

Has any of you already encountered this kind of problem before or knows how to fix it ? Thank you!


Solution

  • varpart performs variation partition, and for that it needs at least two variables for which to partition the variation. You had only one (Session) – the second one you supplied (LONG) was constant, and hence will explain no variation and was not counted as a variable. We do not check against non-varying "variables", and you get a confusing error message. However, if you are hand-crafting your model with meaningless (constant) "variables", you should expect weird error messages. We could add a test against constants, but somehow it feels strange.