0

I am getting the following error when I try to plot a model I created with vegdist in the vegan package of R.

#Error in x$vectors[take, axes][ch, ] : incorrect number of dimensions

I am trying to see if the species assemblage of animals differs between days of the week at a single site. My code is listed below, complete with annotations as to what I am trying to do at each step.

#reshape my data (df1) into a new multivariate dataframe
dfnew<-dcast(df1, DayOfWeek + SessionID ~ SpeciesName, fill = NULL)
#find out how many species there are
x <- length(dfnew)
#remove the rows (if any) that do not contain any values at all (excluding the first 2 columns which are actually factors we will use in the next step)
dfnew <- dfnew[rowSums(is.na(dfnew)) != ncol(dfnew[,3:x]),] 
#finally, convert all na's to zeros
dfnew[is.na(dfnew)] <- 0

#make two separate data frames to hold the data (dfspecies), and the factors (dfDoW)
dfDoW <- data.frame(dfnew$DayOfWeek)
dfspecies <- data.frame(dfnew[,-1:-2])

library("vegan", lib.loc="~/R/win-library/3.2")
#create a resemblance matrix based off bray-curtis distances (best for comparing species assemblages)
dis <- vegdist(dfspecies, method = "bray")
#create the factor we need to test
groups <- factor(dfDoW$dfnew.DayOfWeek)
#create a model of how the species assemblage varies between days of the week
mod <- betadisper(dis, groups)
#plot the model into a PCoA plot
plot(mod)
#test if species varies according to day of week
permutest(mod, pairwise = T)

Now, the part where the error occurs is the second last line "plot(mod)"

#Error in x$vectors[take, axes][ch, ] : incorrect number of dimensions  

I have looked at the str() of the data.frame to make sure they match (they do).

The crazy part is that this exact code works perfectly for another factor that I am testing on the same data (time of day).

I think the model is actually running because the permute line of code provides output.

I provide a screenshot of a small demo dataset below that I can extrapolate back to my code.

If anyone can please help that would be great, thanks!

Small demo dataset

patL
  • 2,259
  • 1
  • 17
  • 38
  • Please provide a reproducible example of your data. not an image. You can do `dput(df1)`. – patL May 10 '18 at 07:11
  • I can generate the same error message if `groups` has a factor level with only one case. For instance: `data(dune); d <- vegdist(dune); gr <- rep("A", nrow(dune)); gr[3] <- "B"; mod <- betadisper(d, gr); plot(mod)`. Is this the case with your data? – Jari Oksanen May 10 '18 at 14:17

1 Answers1

0

There is no reproducible example, but I managed to trigger the very same error message when I had a group with only one member. This problem is now fixed in https://github.com/vegandevs/vegan, and this fix will be in the next vegan release. If only possible, check the github fix and report about its success (both success and failure are equally interesting).

Jari Oksanen
  • 3,287
  • 1
  • 11
  • 15
  • Thank you Jari! Yes, one of my levels of the factor has only 1 replicate (Friday). I will update on the next vegan release as you suggest. In the meantime, I will just exclude that level of the factor, it's not really necessary right now anyway. – T.Martin May 10 '18 at 22:36
  • This is now fixed in **vegan** release 2.5-2 in CRAN. – Jari Oksanen May 21 '18 at 16:47