rstatisticsanalysisanovarobust

WRS2 package - robust 2-way ANOVA


I am an R beginner and I'm trying to run a robust RM ANOVA using WRS2.

I've started with formatting the data with the IVs (Condition and GVS) as factors with 3 and 2 levels respectively (see below) but I'm not sure I'm formatting the ID column correctly (it's multiple rows per subject). The PD column in my data frame is the DV (numeric).

Participant<-factor(TerryRHWB$Participant, levels = c(1:36)) #is this the right way to classify subjects?
GVS<-factor(TerryRHWB$GVS, levels=c(1, 2, 3), labels=c("Sham", "LGVS", "RGVS")) #factorial variable with n levels
Condition<-factor(TerryRHWB$Condition, levels=c(1, 2), labels=c("RH", "WB"))
PD<-c(TerryRHWB$PD)
as.data.frame(TerryRHWB)`

After formatting the data (hopefully not too wrongly so), I load the library and type the fuction:

library(WRS2)
#2-way anova with interactions + post-hocs
t2way(formula=PD ~ Condition * GVS, data=TerryRHWB, tr = 0.2)
mcp2atm(formula=PD ~ Condition * GVS, data=TerryRHWB, tr = 0.2)` 

What I get is this error:

t2way(formula=PD ~ Condition * GVS, data=TerryRHWB, tr = 0.2)
Error in x[[grp[i]]] : attempt to select less than one element in get1index
mcp2atm(formula=PD ~ Condition * GVS, data=TerryRHWB, tr = 0.2)
Error in x[[j]] : attempt to select less than one element in integerOneIndex

It's probably something I've overlooked while formatting the data frame but I couldn't find a solution by surfing the web - any input on what the error means would be incredibly appreciated.

Here, the data I'm using:

   Participant Condition GVS   PD
1             1         1   1 -0.3
2             1         2   1  0.9
3             1         1   2  8.5
4             1         2   2 -1.7
5             1         1   3  0.4
6             1         2   3 -1.2
7             2         1   1  2.1
8             2         2   1 -1.1
9             2         1   2  0.8
10            2         2   2 -0.2
11            2         1   3  1.6
12            2         2   3  1.7
13            3         1   1 -0.3
14            3         2   1  0.9
15            3         1   2 -0.9
16            3         2   2  1.6
17            3         1   3 -2.6
18            3         2   3  0.2
19            4         1   1 -3.1
20            4         2   1  4.7
21            4         1   2 -1.7
22            4         2   2  1.8
23            4         1   3 -0.7
24            4         2   3 -0.5
25            5         1   1  2.2
26            5         2   1  3.4
27            5         1   2  3.0
28            5         2   2 -3.6
29            5         1   3  1.8
30            5         2   3 -5.9
31            6         1   1  0.0
32            6         2   1  2.8
33            6         1   2  4.0
34            6         2   2 -0.3
35            6         1   3 -0.1
36            6         2   3 -0.1
37            7         1   1 -0.9
38            7         2   1  0.1
39            7         1   2  0.0
40            7         2   2  0.4  
41            7         1   3 -0.9
42            7         2   3  0.1
43            8         1   1  1.1
44            8         2   1 -0.6
45            8         1   2 -0.2
46            8         2   2 -1.7  
47            8         1   3  1.7
48            8         2   3 -3.4
49            9         1   1  0.7
50            9         2   1  3.3
51            9         1   2 -3.6
52            9         2   2  3.0
53            9         1   3 -2.3
54            9         2   3 -0.3
55           10         1   1  3.0
56           10         2   1  0.2
57           10         1   2 -2.6
58           10         2   2  0.8
59           10         1   3 -1.0
60           10         2   3 -1.7
61           11         1   1  0.6
62           11         2   1  1.1 
63           11         1   2 -0.6
64           11         2   2  0.0
65           11         1   3  1.9
66           11         2   3 -0.8
67           12         1   1  1.3
68           12         2   1 -0.5
69           12         1   2 -0.4
70           12         2   2  0.9
71           12         1   3  1.3
72           12         2   3 -2.7
73           13         1   1  0.2
74           13         2   1  2.0
75           13         1   2 -2.1
76           13         2   2  1.8
77           13         1   3 -1.2
78           13         2   3  0.7
79           14         1   1 -0.4
80           14         2   1 -0.8
81           14         1   2 -0.3
82           14         2   2 -2.5
83           14         1   3  2.1
84           14         2   3  4.3
85           15         1   1 -1.1
86           15         2   1 -0.8
87           15         1   2 -1.1
88           15         2   2 -0.8
89           15         1   3  0.0
90           15         2   3 -2.2
91           16         1   1  1.7
92           16         2   1  1.1
93           16         1   2  1.4
94           16         2   2  0.0
95           16         1   3  1.2
96           16         2   3 -0.7
97           17         1   1  1.1
98           17         2   1  1.3
99           17         1   2 -0.1
100          17         2   2 -3.0
101          17         1   3  2.9
102          17         2   3  2.2
103          18         1   1 -1.0
104          18         2   1  0.4
105          18         1   2  1.0
106          18         2   2  0.6
107          18         1   3 -1.9
108          18         2   3  1.2
109          19         1   1  0.0
110          19         2   1 -0.8
111          19         1   2 -0.5
112          19         2   2  3.3 
113          19         1   3  0.7
114          19         2   3 -0.7
115          20         1   1 -0.5
116          20         2   1 -1.0
117          20         1   2  0.8
118          20         2   2 -0.3
119          20         1   3 -1.1
120          20         2   3  0.8
121          21         1   1 -0.2
122          21         2   1  0.0
123          21         1   2  1.5
124          21         2   2  9.4
125          21         1   3  2.1   
126          21         2   3  1.0
127          22         1   1  1.3
128          22         2   1 -0.1
129          22         1   2  1.3
130          22         2   2 -0.3
131          22         1   3 -1.4
132          22         2   3 -0.5
133          23         1   1 -0.8
134          23         2   1 -3.4
135          23         1   2 -1.0
136          23         2   2 -1.9
137          23         1   3  0.5
138          23         2   3  0.3
139          24         1   1  1.0
140          24         2   1  0.6
141          24         1   2  0.5
142          24         2   2  0.5
143          24         1   3 -0.9
144          24         2   3 -1.2
145          25         1   1 -2.6
146          25         2   1 -0.9
147          25         1   2 -3.1
148          25         2   2  3.3
149          25         1   3 -0.8
150          25         2   3  0.7
151          26         1   1 10.4
152          26         2   1  2.9
153          26         1   2  6.2
154          26         2   2  5.0
155          26         1   3  4.9
156          26         2   3  1.7
157          27         1   1  0.1
158          27         2   1 -0.2
159          27         1   2 -1.9
160          27         2   2  0.2
161          27         1   3  1.8
162          27         2   3  1.3
163          28         1   1 -0.5
164          28         2   1  0.3
165          28         1   2 -0.3
166          28         2   2 -2.4
167          28         1   3 -4.1
168          28         2   3 -0.6
169          29         1   1 -0.2
170          29         2   1  0.2
171          29         1   2 -0.1
172          29         2   2 -0.7
173          29         1   3  1.4
174          29         2   3  0.0
175          30         1   1 -2.1
176          30         2   1  0.2 
177          30         1   2  0.1
178          30         2   2  0.9
179          30         1   3  0.2
180          30         2   3  3.6
181          31         1   1 -2.3
182          31         2   1 -0.2
183          31         1   2 -1.0
184          31         2   2 -2.3
185          31         1   3  1.6
186          31         2   3  0.2
187          32         1   1  1.3 
188          32         2   1  2.9
189          32         1   2  0.2
190          32         2   2  2.0
191          32         1   3  0.1
192          32         2   3  0.4
193          33         1   1  2.3
194          33         2   1  3.3
195          33         1   2  1.1
196          33         2   2 -0.8
197          33         1   3  0.0
198          33         2   3  3.0
199          34         1   1 -0.2
200          34         2   1  0.0
201          34         1   2  1.0
202          34         2   2  2.4
203          34         1   3 -0.6
204          34         2   3  0.0
205          35         1   1 -0.8
206          35         2   1 -1.5
207          35         1   2 -0.9
208          35         2   2 -0.1
209          35         1   3  0.5
210          35         2   3 -0.7
211          36         1   1 -1.3
212          36         2   1  2.7
213          36         1   2 -0.3
214          36         2   2 -1.8
215          36         1   3 -1.7
216          36         2   3 -0.3

Thanks to anyone willing to take the time to help a newbie out!


Solution

  • I am also a newbie but I have just had the same problem as you. I found that by grouping the data and then making sure the IVs are factors, t2way works.

    Try:

    TerryRHWB <- TerryRHWB %>% group_by(Condition, GVS) # Group the data 
    TerryRHWB$Condition <- factor(TerryRHWB$Condition) # convert to factor
    TerryRHWB$GVS <- factor(TerryRHWB$GVS) # convert to factor
    

    Good luck!