ranova with two within factors
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello everyone,
I have a question about how to do a repeated measures anova in Matlab. I have data from 20 people who were tested in 4 conditions each: treatment A pre test, treatment A post test, treatment B pre test, treatment B post test. I want to use time and treatment as factors. However I only managed an anova with one factor. Here's what I got so far:
datatable = cell2table(struct2cell([pre.A, pre.B, post.A, post.B]'));
datatable.Properties.VariableNames = {'pre_A','pre_B','post_A','post_B'};
rm = fitrm(datatable, 'pre_A,pre_B,post_A,post_B~1','WithinDesign',[1:4]);
ranovatable = ranova(rm)
How do I introduce the treatment as a second within factor? I read the documentation but did not find anything I could make use of. Thank you so much in advance!
채택된 답변
Jeff Miller
2019년 6월 16일
편집: Jeff Miller
2020년 11월 24일
datatable.Properties.VariableNames = {'pre_A','pre_B','post_A','post_B'};
% When you have more than one repeated-measures factor, you must set up a table
% to indicate the levels on each factor for each of your different variables.
% Here is the command you need for this case:
WithinStructure = table([1 1 2 2]',[1 2 1 2]','VariableNames',{'PrePost','TreatAB'});
% The 4 different rows of the WithinStructure table correspond to the 4 different
% columns, 'pre_A','pre_B','post_A','post_B', respectively, in your data table.
% Each 'pre_A','pre_B','post_A','post_B' column is coded as 1/2 on the PrePost factor
% and as 1/2 on the TreatAB factor.
% (Added based on later comments:)
% Indicate that the 1's and 2's of WithinStructure are category labels
% rather than regression-type numerical covariates:
WithinStructure.PrePost = categorical(WithinStructure.PrePost);
WithinStructure.TreatAB = categorical(WithinStructure.TreatAB);
% Now pass the WithinStructure table to fitrm so that it knows how the different
% columns correspond to the different levels of the repeated-measures factors.
rm = fitrm(datatable, 'pre_A,pre_B,post_A,post_B~1','WithinDesign',WithinStructure);
% Finally, you need to specify the repeated-measures factors again when you call ranova, like this:
ranovatable = ranova(rm,'WithinModel','PrePost*TreatAB');
댓글 수: 10
RP
2019년 6월 17일
Thank you so much, this works perfectly!
RP
2019년 6월 18일
I don't know if you can answer this but I just had a look at my results and something seems odd, so I ran the code exactly as you wrote it and it does work but I get F values of 800 and extremely small p values. Maybe someone has an idea what could have gone wrong?
Jeff Miller
2019년 6월 19일
Those F and p values are possible if there are large effects in the data. What makes you think something is wrong?
Sorry that's not much of an answer, but it is hard to say much without seeing the data.
I'm assuming that you have 20 rows in the data table, corresponding to the 20 people, and that you have four columns per row/person with the four measures {'pre_A','pre_B','post_A','post_B'. Are those assumptions correct?
RP
2019년 6월 19일
I also ran the same analysis in R and SPSS and got a different result (it was the same result for both so I think that is the correct one). I totally understand that you cannot really say more based on the limited information, don't worry! I just thought maybe something was wrong in the code, like in the order of the 1 and 2 in the table.
The assumptions are correct, yes. Could you maybe tell me what this part of the code means: 'pre_A,pre_B,post_A,post_B~1'? I have seen some examples where instead of the 1, there was something that seemed like the name of a factor. Also in some examples not all names of conditions were used but instead something like 'pre_A - post_B'. Can you help me make sense of that? Specifically, what does the 1 stand for?
Jeff Miller
2019년 6월 19일
Hmmm...I also tried a numerical example and got different results. Although MATLAB produces an ANOVA table with the same structure and df's as other packages, the SS's, MS's, and F's are different, so I am really not sure what underlying model MATLAB is using. Well, maybe I've just got the specifications wrong.
As far as the ~1 notation, this is used to indicate that there are no between-subjects factors. For example, if you did have between-subjects factors like gender and treatment (with columns having those names in the original datatable), you would use a specification like 'pre_A,pre_B,post_A,post_B~Gender*Treatment'
RP
2019년 6월 20일
Ok thanks a lot, now it makes sense! I also believe Matlab uses some other model or calculation because several people here tried it now and it does not seem to produce the correct results. Thanks for your help!
Florian Binder
2019년 7월 8일
The differences to SPSS and R may be because the variable type in the WithinStructure is not categorical.
You have to make the variables in the WithinStructure categorical if they are not metric.
Prabhjot Dhami
2020년 11월 24일
편집: Prabhjot Dhami
2020년 11월 24일
I ran into the same issue of extremely small p-values, and what Florian Binder suggested seems to be correct. Make sure the appropriate variables in the WithinStructure are categorical. After doing so with my own data, I compared the Matlab output with SPSS, and they were identical.
@Jeff Miller Thank you for the explanation!
However, when I run your code I always get multiple error messages at the code when I try to fith the Within Struct Table
I have basically the same structure with the difference that my treatment has 3 levels (a,b,c) and my condition also has 3 levels.
Do you have any idea why that can be?
These are the messages:
Error using classreg.regr.FormulaProcessor (line 385)
The model formula contains names not recognized as predictor or response names.
Error in fitrm (line 77)
s = RepeatedMeasuresModel.fit(ds,model,varargin{:});
Error in RM_Anova (line 10)
rm = fitrm(dT,
'A1,A2,A3,B1,B2,B3,C1,C2,C3~1','WithinDesign',dWithinStructure);
Jeff Miller
2021년 4월 23일
No, sorry, I can't tell from this info. I suggest you start a new question and provide more explanation about the design, as well as all the relevant code.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Repeated Measures and MANOVA에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
