2

I am using the gls function from the nlme package in R to fit a linear model to data on skull shape across certain snake species (dependent variable) and habitat and diet (explanatory variables). I was able to successfully get results from this, but then wanted to have some measure of the robustness of the results, so I randomly permuted some subset of the data n times, while running gls on each of the permuted subsets, and recorded p-values in order to have some sense for the meaningfulness of my results against a randomly permuted subset of my data. When doing this, I encountered various errors like this:

 Error in glsEstimate(glsSt, control = glsEstControl) : 
  computed "gls" fit is singular, rank 7

Which have been identical except for the rank being different during different run attempts.

This is perplexing to me as when using the entire dataset, the function seems to work normally. It is only with certain subsets/permutations of the data that it outputs this error and I can't seem to find the correlate that is causing the issue.

Here is an example of what I have been doing (but not my actual data), that exhibits the issue:

#Creating fake data
Habitat<-sample(rep(c("Arboreal", "Terrestrial", "Fossorial", "Cryptozoic"), 37))
Diet<-sample(rep(c("Annelids", "Mollusks", "Reptiles", "Amphibians"), 37))
TestEco<-cbind(Habitat, Diet)
Shape<-as.matrix(rep(1, 148))

#Running robustness test
n<-100
reps=100

for (i in 1:reps) {

    #Random smaller species subset and corresponding eco data
    species<-sample(1:148, size=n)
    subshape<-Shape[species,]
    subeco<-TestEco[species,]

    #Running a gls analysis with this data subset
    subdata<-data.frame(coords=subshape, Habitat_Use=subeco[,1], Diet=subeco[,2])
    subPGLS<-gls(coords ~ Habitat_Use+Diet, data=subdata, method="ML")

}

I would really appreciate any guidance in the right direction. I would also be happy to provide more information.

Thanks, Greg

GregP
  • 21
  • 1

0 Answers0