CCA分析:权重的错误。平均值。默认值(newX[, i],…):'x'和'w'必须具有相同的长度。

时间:2021-10-15 16:10:22

I'm very new to R and this might be a very silly question to ask but I'm quite stuck right now.

我对R很陌生,这可能是一个很愚蠢的问题,但我现在很为难。

I'm currently trying to do a Canonical Correspondence Analysis on my data to see which environmental factors have more weight on community distribution. I'm using the vegan package. My data consists of a table for the environmental factors (dataset EFamoA) and another for an abundance matrix (dataset AmoA). I have 41 soils, with 39 environmental factors and 334 species. After cleaning my data of any variables which are not numerical, I try to perform the cca analysis using the formula notation:

我目前正试图对我的数据进行规范的通信分析,以了解哪些环境因素对社区分布的影响更大。我正在使用素食包装。我的数据包括环境因素表(dataset EFamoA)和另一个用于丰富矩阵(dataset AmoA)的表。我有41个土壤,有39个环境因子和334个物种。在清除了所有非数值变量的数据之后,我尝试使用公式符号来执行cca分析:

CCA.amoA <- cca (AmoA ~ EFamoA$PH + EFamoA$LOI, data = EFamoA, 
scale = TRUE, na.action = na.omit)

But then I get this error:

但是我得到了这个错误:

Error in weighted.mean.default(newX[, i], ...) : 
'x' and 'w' must have the same length

I don't really know where to go from here and haven't found much regarding this problem anywhere (which leads me to think that it must be some sort of very basic mistake I'm doing). My environmental factor data is not standardized as I red in the cca help file that the algorithm does it but maybe I should standardize it before? (I've also red that scale = TRUE is only for species). Should I convert the data into matrices?

我真的不知道从这里到哪里去,也没有在任何地方发现这个问题(这让我认为这一定是我所犯的一个非常基本的错误)。我的环境因子数据在cca帮助文件中是不标准化的,这是算法做的但也许我应该标准化它?(我也有红色的刻度= TRUE只适用于物种)。我应该把数据转换成矩阵吗?

I hope I made my point clear enough as I've been struggling with this for a while now.

我希望我已经把我的观点说清楚了,因为我已经在这个问题上挣扎了一段时间了。

Edit: My environmental data has NA values

编辑:我的环境数据有NA值。

1 个解决方案

#1


0  

Alright so I was able to figure it out all by myself and it was indeed a silly thing, turns out my abundance data had soils as columns and species as rows, while environmental factor (EF) data had soils as rows and EF as columns.

好吧,我能自己弄清楚,这确实是一件很愚蠢的事情,我的丰度数据把土壤作为列和物种作为行,而环境因子(EF)数据有土壤为行,EF为列。

using t() on my data, I transposed my data.frame (and collaterally converted it into a matrix) and cca() worked (as "length" was the same, I assume). Transposing the data separately and loading it already transposed works too. Although maybe the t() approach saves the need of creating a whole new file (in case your data was organized using different rows as in my case), it converts the data into a matrix and this might not be desired in some cases, either way, this turned out to be a very simple and obvious thing to solve (took me a while though).

在我的数据上使用t(),我将我的data.frame(并将它转换为一个矩阵)和cca()工作(我假设为“长度”是相同的)。将数据分别转置和加载已经转置的工作。尽管也许t()方法保存的需要创建一个全新的文件(如果您的数据是使用不同的组织行我的情况),它将数据转换为一个矩阵,这可能不是预期在某些情况下,无论如何,这是一个非常简单明了的解决(我花了一段时间)。

#1


0  

Alright so I was able to figure it out all by myself and it was indeed a silly thing, turns out my abundance data had soils as columns and species as rows, while environmental factor (EF) data had soils as rows and EF as columns.

好吧,我能自己弄清楚,这确实是一件很愚蠢的事情,我的丰度数据把土壤作为列和物种作为行,而环境因子(EF)数据有土壤为行,EF为列。

using t() on my data, I transposed my data.frame (and collaterally converted it into a matrix) and cca() worked (as "length" was the same, I assume). Transposing the data separately and loading it already transposed works too. Although maybe the t() approach saves the need of creating a whole new file (in case your data was organized using different rows as in my case), it converts the data into a matrix and this might not be desired in some cases, either way, this turned out to be a very simple and obvious thing to solve (took me a while though).

在我的数据上使用t(),我将我的data.frame(并将它转换为一个矩阵)和cca()工作(我假设为“长度”是相同的)。将数据分别转置和加载已经转置的工作。尽管也许t()方法保存的需要创建一个全新的文件(如果您的数据是使用不同的组织行我的情况),它将数据转换为一个矩阵,这可能不是预期在某些情况下,无论如何,这是一个非常简单明了的解决(我花了一段时间)。