Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的相关矩阵与鱼类丰度_R_Matrix_Correlation - Fatal编程技术网

R中的相关矩阵与鱼类丰度

R中的相关矩阵与鱼类丰度,r,matrix,correlation,R,Matrix,Correlation,我有一个数据集,包括每周取样的鱼类丰度。我希望创建一个矩阵,显示在特定时间段内,一个物种的丰度与另一个物种的丰度之间的相关性。最好的方法是什么?对于这种性质的数据,我可以使用皮尔逊相关性吗 我的数据包括12个物种和20周。每周都有记录在案的丰度 例如: Week species 1 species 2 species 3 1 150 1000 0 2 250 1

我有一个数据集,包括每周取样的鱼类丰度。我希望创建一个矩阵,显示在特定时间段内,一个物种的丰度与另一个物种的丰度之间的相关性。最好的方法是什么?对于这种性质的数据,我可以使用皮尔逊相关性吗

我的数据包括12个物种和20周。每周都有记录在案的丰度

例如:

Week     species 1      species 2     species 3
1              150          1000            0
2              250          1500            0
3              700          1400            0
4              80           2000         1800
5              0            500         600

寻找一个物种和另一个物种的发生率或丰度之间的相关性。

以下基本分析可能会有所帮助:

ddf = structure(list(Week = 1:5, species1 = c(150L, 250L, 700L, 80L, 
0L), species2 = c(1000L, 1500L, 1400L, 2000L, 500L), species3 = c(0L, 
0L, 0L, 1800L, 600L)), .Names = c("Week", "species1", "species2", 
"species3"), class = "data.frame", row.names = c(NA, -5L))

> ddf
  Week species1 species2 species3
1    1      150     1000        0
2    2      250     1500        0
3    3      700     1400        0
4    4       80     2000     1800
5    5        0      500      600
随时间排列的不同物种之间的相关矩阵(显示物种2和物种3之间的某些直接相关,以及物种1和物种3之间的反向相关):

图形表示法:

ddfm = melt(ddf, id="Week")
ddfm
   Week variable value
1     1 species1   150
2     2 species1   250
3     3 species1   700
4     4 species1    80
5     5 species1     0
6     1 species2  1000
7     2 species2  1500
8     3 species2  1400
9     4 species2  2000
10    5 species2   500
11    1 species3     0
12    2 species3     0
13    3 species3     0
14    4 species3  1800
15    5 species3   600

library(ggplot2)
ggplot(ddfm, aes(x=Week, y=value, group=variable, color=variable)) + geom_line()

如果您能在此处提供数据样本,论坛会更有帮助。我试图添加一个示例,说明我的数据是什么样的,标题为week、species 1、species 2、species 3,数值为数字。请参见下面的答案。因此,这非常有帮助!非常感谢。
ddfm = melt(ddf, id="Week")
ddfm
   Week variable value
1     1 species1   150
2     2 species1   250
3     3 species1   700
4     4 species1    80
5     5 species1     0
6     1 species2  1000
7     2 species2  1500
8     3 species2  1400
9     4 species2  2000
10    5 species2   500
11    1 species3     0
12    2 species3     0
13    3 species3     0
14    4 species3  1800
15    5 species3   600

library(ggplot2)
ggplot(ddfm, aes(x=Week, y=value, group=variable, color=variable)) + geom_line()