R:ezANOVA中的重复测量ANOVA错误一个或多个单元丢失数据

时间:2017-05-11 16:49:10

标签: r anova

最初我们在考虑单因素方差分析,但似乎我需要做一个双向因为我有两个自变量。对于每个宏观上的每个鳄鱼洞,会话(采取迷你陷阱采样的时间)和TRAP(每个陷阱平均每个孔4个)CPUE将是因变量,然后是ID列。

SESSION TRAP    CPUE    ID
One     M1E1    3   1
One     M1E2    0   2
One     M1E3    0   3
One     M1E4    2   4
One     M1W1    0   5
One     M1W2    0   6
One     M1W3    0   7
One     M1W4    0   8
One     M2E1    0   9
One     M2E2    0   10
One     M2E3    0   11
One     M2E4    0   12
One     M2W1    0   13
One     M2W2    1   14
One     M2W3    1   15
One M2W4    0   16
One M3E1    5   17
One M3E2    2   18
One M3E3    0   19
One M3E4    3   20
One M3W1    0   21
One M3W2    0   22
One M3W3    0   23
One M3W4    2   24
One M4E1    0   25
One M4E2    1   26
One M4E3    0   27
One M4E4    0   28
One M4W1    0   29
One M4W2    0   30
One M4W3    0   31
One M4W4    8   32
Two M4E1    23  33
Two M4E2    5   34
Two M4E3    0   35
Two     M4E4    10  36
Two     M4W1    23  37
Two     M4W2    7   38
Two     M4W3    1   39
Two     M4W4    7   40
Two     M3E1    6   41
Two     M3E2    3   42
Two     M3E3    5   43
Two     M3E4    10  44
Two     M3W1    8   45
Two     M3W2    0   46
Two     M3W3    1   47
Two     M3W4    5   48
Two     M2E1    12  49
Two     M2E2    15  50
Two     M2E3    3   51
Two     M2E4    10  52
Two     M2W1    5   53
Two     M2W2    11  54
Two     M2W3    6   55
Two     M2W4    4   56
Two     M1E1    13  57
Two     M1E2    19  58
Two     M1E3    3   59
Two     M1E4    30  60
Two     M1W1    16  61
Two     M1W2    2   62
Two     M1W3    4   63
Two     M1W4    27  64
Three   M4E1    0   65
Three   M4E2    26  66
Three   M4E3    3   67
Three   M4E4    13  68
Three   M4W1    9   69
Three   M4W2    0   70
Three   M4W3    4   71
Three   M4W4    2   72
Three   M3E1    29  73
Three   M3E2    0   74
Three   M3E3    0   75
Three   M3E4    11  76
Three   M3W1    27  77
Three   M3W2    5   78
Three   M3W3    8   79
Three   M3W4    3   80
Three   M2E1    5   81
Three   M2E2    11  82
Three   M2E3    62  83
Three   M2E4    31  84
Three   M2W1    11  85
Three   M2W2    1   86
Three   M2W3    0   87
Three   M2W4    9   88
Three   M1E1    48  89
Three   M1E2    78  90
Three   M1E3    14  91
Three   M1E4    7   92
Three   M1W1    3   93
Three   M1W2    63  94
Three   M1W3    43  95
Three   M1W4    31  96 

我正在使用此命令:

> output = ezANOVA(data = CSV.Repeated.Measures.ANOVA.Minnow._2cm.R.Data.Sheet, dv= CPUE, wid = ID, within = .(SESSION, TRAP), detailed = TRUE, type = 3)

我收到此错误消息:

  

ezANOVA_main出错(data = data,dv = dv,wid = wid,within =   在,:一个或多个单元格缺少数据。尝试使用ezDesign()   检查你的数据。

我不知道exDesign()试图告诉我的是什么。

1 个答案:

答案 0 :(得分:0)

我会尝试使用ezANOVA解决您的问题。当然,有必要了解实验的所有细节,以便对您的问题做出完整而正确的答案。

如果我没有错,你写道,min鱼陷阱是实验的样本单位,并且对这些单位进行重复测量(在不同的实验条件下)。因此,样本单位的ID不是存储在ID列中的ID;需要生成一个新的id变量 这是数据集:

df <- structure(list(SESSION = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("One", "Three", 
"Two"), class = "factor"), TRAP = structure(c(1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 
1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c("1", 
"2", "3", "4"), class = "factor"), CPUE = c(3L, 0L, 0L, 2L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 5L, 2L, 0L, 3L, 0L, 
0L, 0L, 2L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 8L, 23L, 5L, 0L, 10L, 
23L, 7L, 1L, 7L, 6L, 3L, 5L, 10L, 8L, 0L, 1L, 5L, 12L, 15L, 3L, 
10L, 5L, 11L, 6L, 4L, 13L, 19L, 3L, 30L, 16L, 2L, 4L, 27L, 0L, 
26L, 3L, 13L, 9L, 0L, 4L, 2L, 29L, 0L, 0L, 11L, 27L, 5L, 8L, 
3L, 5L, 11L, 62L, 31L, 11L, 1L, 0L, 9L, 48L, 78L, 14L, 7L, 3L, 
63L, 43L, 31L), ID = structure(1:96, .Label = c("1", "2", "3", 
"4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", 
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", 
"27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", 
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", 
"49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", 
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", 
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", 
"82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", 
"93", "94", "95", "96"), class = "factor"), MACROCOSM = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1", 
"2", "3", "4"), class = "factor"), HOLE = structure(c(1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("E", 
"W"), class = "factor")), .Names = c("SESSION", "TRAP", "CPUE", 
"ID", "MACROCOSM", "HOLE"), row.names = c(NA, -96L), class = "data.frame")

这是代码(希望)能够为您找到解决问题的方法:

df$MACROCOSM <- factor(substr(df$TRAP, 2, 2))
df$HOLE <- factor(substr(df$TRAP, 3, 3))
df$TRAP <- factor(substr(df$TRAP, 4, 4))

library(ez)
ezOut <- ezANOVA(data = df, 
    dv=CPUE, wid = .(TRAP), within = .(SESSION,HOLE,MACROCOSM), 
    detailed = TRUE, type = 1)
print(ezOut)

#############
$ANOVA
                  Effect DFn DFd       SSn        SSd          F           p p<.05        ges
1                SESSION   2   6 4372.5625  753.35417 17.4123780 0.003174556     * 0.30542230
2                   HOLE   1   3  276.7604   56.11458 14.7961760 0.031011624     * 0.02707856
3              MACROCOSM   3   9 2030.5313 1466.76042  4.1530939 0.041961697     * 0.16957246
4           SESSION:HOLE   2   6  216.2708   60.47917 10.7278677 0.010436491     * 0.02128617
5      SESSION:MACROCOSM   6  18 2327.6875 3995.39583  1.7477774 0.167180534       0.18968127
6         HOLE:MACROCOSM   3   9  198.6146 1070.34375  0.5566845 0.656642963       0.01958241
7 SESSION:HOLE:MACROCOSM   6  18  461.4792 2541.43750  0.5447458 0.767574519       0.04435012