简体   繁体   English

为什么在运行adonis函数(permanova)时我总是得到df 1?

[英]Why do I always get 1 for df when running adonis function (permanova)?

I run adonis on community data and environmental matrix (that contains a factor of two levels and 6 continuous variables) using Bray-Curtis and I always take 1 df but this is not the case. 我使用Bray-Curtis在社区数据和环境矩阵(包含两个级别的因子和6个连续变量)上运行adonis,我总是采用1 df,但事实并非如此。 Probably there is a bug here. 可能这里有一个错误。

See also the example in adonis 另请参见adonis中的示例

data(dune) 
data(dune.env)  
str(dune.env)  
adonis(dune ~ Management*A1, data=dune.env, permutations=99)

Although A1 is a numeric variable the result provides 1 df. 尽管A1是数字变量,但结果提供1 df。

In the model: 在模型中:

> adonis(dune ~ Management*A1, data=dune.env, permutations=99)

Call:
adonis(formula = dune ~ Management * A1, data = dune.env, permutations = 99) 

Permutation: free
Number of permutations: 99

Terms added sequentially (first to last)

              Df SumsOfSqs MeanSqs F.Model      R2 Pr(>F)   
Management     3    1.4686 0.48953  3.2629 0.34161   0.01 **
A1             1    0.4409 0.44089  2.9387 0.10256   0.02 * 
Management:A1  3    0.5892 0.19639  1.3090 0.13705   0.21   
Residuals     12    1.8004 0.15003         0.41878          
Total         19    4.2990                 1.00000          
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

The main effect of A1 uses a single degree of freedom because it is a continuous variable. A1主要作用是使用单个自由度,因为它是一个连续变量。 The interaction between Management and A1 uses 3 additional degree's of freedom as there is one additional "effect" of A1 per level of Management . ManagementA1之间的交互使用了3个额外的自由度,因为每个Management级别都有一个额外的A1 “效果”。

This is all expected and there is certainly no bug illustrated in adonis() from this model. 这都是预期的,并且此模型的adonis()肯定没有显示任何错误。

Importantly, you must insure that factor variables are coded as factors otherwise, for example if the categories are coded as integers, then R will still interpret those variables as continuous/numeric. 重要的是,必须确保将因子变量编码为因子,否则,例如,如果类别编码为整数,则R仍会将那些变量解释为连续/数字。 It will only interpret them as factors if coerced to the "factor" class. 如果将其强制为"factor"类,它将仅将它们解释为因素。 Check the output of str(df) , where df is your data frame containing the predictor variables (covariates; the things on the right-hand side of ~ ), and insure that each factor variable is of the appropriate class. 检查str(df)的输出,其中df是包含预测变量(协变量; ~右边的东西str(df) 数据框,并确保每个因子变量都属于适当的类。 For example, the dune.env data are: 例如, dune.env数据是:

> str(dune.env)  
'data.frame':   20 obs. of  5 variables:
 $ A1        : num  2.8 3.5 4.3 4.2 6.3 4.3 2.8 4.2 3.7 3.3 ...
 $ Moisture  : Ord.factor w/ 4 levels "1"<"2"<"4"<"5": 1 1 2 2 1 1 1 4 3 2 ...
 $ Management: Factor w/ 4 levels "BF","HF","NM",..: 4 1 4 4 2 2 2 2 2 1 ...
 $ Use       : Ord.factor w/ 3 levels "Hayfield"<"Haypastu"<..: 2 2 2 2 1 2 3 3 1 1 ...
 $ Manure    : Ord.factor w/ 5 levels "0"<"1"<"2"<"3"<..: 5 3 5 5 3 3 4 4 2 2 ...

which indicates that Management is a factor, A1 is numeric (it is the thickness of the A1 soil horizon), and the remaining variables are ordered factors (but still factors; they work correctly in R's omdel formula infrastructure). 表示Management是一个因素, A1是数字(它是A1土壤层的厚度),其余变量是有序因素(但仍然是因素;它们在R的omdel公式基础结构中正常运行)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM