Я получаю следующую ошибку при попытке построить модель, созданную с помощью vegdist
в пакете vegan
из R.
#Error in x$vectors[take, axes][ch, ] : incorrect number of dimensions
Я пытаюсь понять, различается ли видовая совокупность животных в разные дни недели на одном участке.
Мой код указан ниже и содержит аннотации к тому, что я пытаюсь сделать на каждом этапе.
#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)
Теперь часть, где возникает ошибка, - вторая последняя строка "plot (mod)"
#Error in x$vectors[take, axes][ch, ] : incorrect number of dimensions
Я посмотрел на str()
из data.frame
, чтобы убедиться, что они совпадают (они соответствуют).
Сумасшедшая часть в том, что этот точный код отлично работает для другого фактора, который я тестирую на тех же данных (время суток).
Я думаю, что модель на самом деле работает, потому что строка кода permute
обеспечивает вывод.
Ниже приведен скриншот небольшого демонстрационного набора данных, который я могу экстраполировать обратно на свой код.
Если кто-нибудь может помочь, это было бы здорово, спасибо!
![Small demo dataset](https://i.stack.imgur.com/xl3bW.png)