使用纯素包:Pielou相似性无法记录输出

时间:2015-03-05 06:44:19

标签: r vegan

我正在vegan创建一个不同丰富度的数据框。我与Pielou遇到了麻烦,因为我需要记录以前创建的“pumice.richness”数据以实现此结果并得到以下错误:

analysis <- function(havreanosim, havre_ANOSIM3.csv)
outfile <- sprintf("%s-analysis.txt", description)
pumice.data<-read.csv("c:\\pumice\\phd\\data_analysis\\havre\\havre_ANOSIM3.csv",header=T)
pumice.locationcode <- pumice.data[, 1:ncol(pumice.data)]
pumice.trop_temp_subtrop <- pumice.data[, 2:ncol(pumice.data)]
pumice.shannon <- specnumber~locationcode(pumice.locationcode, "shannon")
pumice.simpson <- specnumber~locationcode(pumice.locationcode, "simpson")
pumice.richness <- specnumber~locationcode(pumice.locationcode)
pumice.pielou <- pumice.shannon / log(pumice.richness)
Error in log(pumice.richness) : 
  non-numeric argument to mathematical function

我试图将其转换为矢量,因为我认为可能R使用以下方法读取此数据:

as.numeric(levels(f))[f]

但是我无法在这里得到结果,也许这不是问题。

1 个答案:

答案 0 :(得分:1)

你对如何在R中调用函数有一些严重的误解。你在哪里看到涉及specnumber()的调用格式为:

specnumber ~ locationcode(pumice.locationcode, "shannon")

...

您正在将公式用螺栓连接到函数调用上,该函数调用某个未知函数locationcode

我真的有没有想法你想要做什么,因为你显示的代码混乱,但问题的根源显然是你在pumice.shannon和{pumice.richness和{{{}}形成公式对象{1}}然后尝试对这些公式对象进行数学运算。

您似乎也在尝试specnumber()diversity()就是您需要的地方。

这似乎会复制您要实现的目标(使用可重现的示例)

data(BCI)
rich <- specnumber(BCI)
shan <- diversity(BCI, "shannon")
shan / log(rich)

给出:

> shan / log(rich)
        1         2         3         4         5         6         7         8 
0.8865579 0.8685692 0.8476046 0.8752597 0.8602030 0.8500724 0.8706729 0.8729254 
        9        10        11        12        13        14        15        16 
0.8358867 0.8561634 0.8642843 0.8347024 0.8786069 0.8762317 0.8729284 0.8641446 
       17        18        19        20        21        22        23        24 
0.8244489 0.8788828 0.8554245 0.8853802 0.8639438 0.8325271 0.8841064 0.8738548 
       25        26        27        28        29        30        31        32 
0.8755378 0.8751655 0.8661975 0.8314621 0.8281171 0.8419326 0.8575355 0.8453403 
       33        34        35        36        37        38        39        40 
0.8397172 0.8451677 0.5978626 0.8505725 0.8468656 0.7978912 0.7968043 0.7382083 
       41        42        43        44        45        46        47        48 
0.8762204 0.8881987 0.8387881 0.8431126 0.8213811 0.8554539 0.8477709 0.8676229 
       49        50 
0.8377231 0.8618931