简体   繁体   English

R中的2路随机分组方差分析

[英]2-Way Randomized Block ANOVA in R

've been trying to analyze my data set and I believe that I am on the right track, but need some conformation. 我一直在尝试分析我的数据集,我认为我的工作是正确的,但需要一定的条件。 I'm trying to analyze the catch rate of fishes along several reaches of the same river and evaluate the effectiveness of the type of gear used over 2 years of study. 我正在尝试分析同一条河多处鱼类的捕获率,并评估2年研究中使用的渔具类型的有效性。

My data consists of: 我的数据包括:

1) 21 Different Sites 2) Sampling Techniques categorized as "Active" or "Passive" 3) 2 years of data gathering separated by month. 1)21个不同的站点2)采样技术分为“主动”或“被动” 3)2年的数据收集按月分开。

The sites were not sampled uniformly over the course of the study. 在研究过程中未对站点进行统一采样。 They were not all sampled every month, not all for the same amount of time, nor with the same sampling techniques. 并非每个月都对它们进行采样,也不是在相同的时间量内,也不是使用相同的采样技术对它们进行采样。 I believe you could categorize it as a non-repeating measure since almost no two sampling periods are the same. 我相信您可以将其归类为非重复性措施,因为几乎没有两个采样周期相同。

I believe that the correct way to analyze this data would be to use a 2-way Randomized Block ANOVA. 我认为分析此数据的正确方法是使用2路随机分组方差分析。 The months would be what is being blocked in the analysis. 几个月将是分析中被阻止的时间。 I got some results, but was unsure if the code used was the correct one. 我得到了一些结果,但是不确定所使用的代码是否正确。

Would anyone be able to proof the code I used and confirm/deny that it is indeed the correct code for a 2-Way Randomized Block design in R? 谁能证明我使用的代码并确认/否认它确实是R中2向随机块设计的正确代码?

Fish<-read.csv(file.choose(),header=TRUE)
Fish
FishLM<-lm(Caught.Hr ~ Site + Method + Site:Method,Fish)
anova(FishLM)

Here is some sample data: 以下是一些示例数据:

Site     Month  Year    Device  Method  Hrs/Month   Caught  Caught/Hr  
Reach 01    5   2014    BS      Active  0.7            0    0  
Reach 01    6   2014    BS      Active  7.92           0    0  
Reach 01    7   2014    BS      Active  5.73           0    0  
Reach 01    8   2014    BS      Active  1.82           0    0  
Reach 01    9   2014    BS      Active  10.08          0    0  
Reach 01    10  2014    BS      Active  10.08          0    0  
Reach 01    11  2014    BS      Active  6.9            0    0  
Reach 02    3   2013    BS      Active  2.5            0    0  
Reach 02    4   2013    BS      Active  2.5            0    0  
Reach 02    5   2013    BS      Active  3.75           0    0  
Reach 02    6   2013    BS      Active  17.3           0    0  
Reach 02    7   2013    BS      Active  2.5            0    0  
Reach 02    8   2013    BS      Active  2.5            0    0  
Reach 02    9   2013    BS      Active  2.5            0    0  
Reach 02    10  2013    BS      Active  2.5            0    0  
Reach 02    11  2013    BS      Active  2.5            0    0  
Reach 03    3   2013    BS      Active  3              0    0  
Reach 03    4   2013    BS      Active  3              0    0  
Reach 03    5   2013    BS     Active   2.5            0    0  
Reach 03    6   2013    BS     Active   3.5            1    0.285714286  
Reach 03    7   2013    BS     Active   3              0    0  
Reach 03    8   2013    BS     Active   3              0    0  
Reach 03    9   2013    BS     Active   3              1    0.333333333  
Reach 03    10  2013    BS     Active   8.75           2    0.228571429  
Reach 03    11  2013    BS      Active  3              0    0  
Reach 04    3   2013    MT      Passive           
Reach 04    4   2013    MT      Passive           
Reach 04    5   2013    MT      Passive           
Reach 04    6   2013    MT      Passive 72             0    0  
Reach 04    7   2013    MT      Passive 120            2    0.016666667  
Reach 04    8   2013    MT      Passive 120            0    0  
Reach 04    9   2013    MT      Passive 72             0    0  
Reach 04    10  2013    MT      Passive           
Reach 04    11  2013    MT      Passive           
Reach 07    3   2014    MF      Passive           
Reach 07    4   2014    MF      Passive 96             7    0.072916667  
Reach 07    5   2014    MF      Passive 96             5    0.052083333  
Reach 07    6   2014    MF      Passive 96             8    0.083333333  
Reach 07    7   2014    MF      Passive 96             1    0.010416667  
Reach 07    8   2014    MF      Passive 96             1    0.010416667  
Reach 07    9   2014    MF      Passive 96             3    0.03125  
Reach 07    10  2014    MF      Passive 96            10    0.104166667  
Reach 07    11  2014    MF      Passive           

Thanks. 谢谢。

If I'm reading your question correctly (and I'm not sure that I am), you are trying to examine the variation in a continuous variable Caught.Hr which you believe to be normally distributed--hence ANOVA. 如果我正确地阅读了您的问题(并且不确定我是不是),则您正在尝试检查连续变量Caught.Hr的变化,您认为该变化是正态分布的,因此称为ANOVA。 In addition, you have two treatment effects: Site and Method and you have repeated measures on a monthly basis. 此外,您还具有两种治疗效果:“ Site和“ Method并且每月进行一次重复测量。

Your model is thus 因此,您的模型是

$$Y_{ijk} = \\mu + S_i + M_j + (SM) {ij} + \\epsilon {ijk}$$ $$ Y_ {ijk} = \\ mu + S_i + M_j +(SM) {ij} + \\ epsilon {ijk} $$

where 哪里
- Y_{ijk} is the catch rate at site i with method j in time period k. -Y_ {ijk}是在时间段k中使用方法j在站点i处的捕获率。
- mu represents the population average catch rate - 代表人口平均捕获率
- S_i indicates the effect of each site, -S_i表示每个站点的效果,
- M_j indicates the effect of each sampling method, -M_j表示每种采样方法的效果,
- (SM)_{ij} is the interaction effect, - (SM)_ {ij}是互动效果,
- e_{ijk} is random variation -e_ {ijk}是随机变化

I fail to see, from your description, what your blocking factor is. 从您的描述中,我看不到您的阻碍因素是什么。 It just sounds like you have an unbalanced design. 听起来您的设计不平衡。 It appears to me, from your description, that you do not have a randomized block design. 根据您的描述,在我看来,您没有随机分组设计。 You have a Factor design with two factors, which is also unbalanced. 您有一个包含两个因子的因子设计,这两个因子也不平衡。

But yes, this would work: 但是是的,这会起作用:

FishLM<-lm(Caught.Hr ~ Site + Method + Site:Method,Fish)
anova(FishLM)

Edit: 编辑:

I think that what I've said above is valid based on your data. 我认为以上所述基于您的数据是有效的。 Though I do have a concern that you're using ANOVA. 尽管我确实担心您使用的是ANOVA。 This appears to be count data ie- poisson not normal distribution. 这似乎是计数数据,而不是正态分布。 eg: 例如:

# This has problems based on hours / obs
Fishglm <- glm(Caught ~ Site + Method + Site:Method, data=Fish, 
  family= poisson(link = "log"))
# could use neg-binomial on the rate instead.
library(MASS)
Fishnb <- glm.nb(Caught.Hr ~ Site + Method + Site:Method, data=Fish)

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

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