{"id":4397,"date":"2014-12-02T03:43:54","date_gmt":"2014-12-02T08:43:54","guid":{"rendered":"http:\/\/www.thejuliagroup.com\/blog\/?p=4397"},"modified":"2014-12-02T03:43:54","modified_gmt":"2014-12-02T08:43:54","slug":"making-your-proc-mixed-into-repeated-measures-anova","status":"publish","type":"post","link":"https:\/\/www.thejuliagroup.com\/blog\/making-your-proc-mixed-into-repeated-measures-anova\/","title":{"rendered":"Making your PROC MIXED into REPEATED measures ANOVA"},"content":{"rendered":"<p>What if you wanted to turn your PROC MIXED into a repeated measures ANOVA using PROC GLM. Why would you want to do this? Well, I don&#8217;t know why you would want to do it but I wanted to do it because I wanted to demonstrate for my class that both give you the same fixed effects F value and significance.<\/p>\n<p>I started out with the Statin dataset from the <a href=\"http:\/\/www.prenhall.com\/cody\/\">Cody and Smith textbook<\/a>. In this data set, each subject has three records,one each for drugs A, B and C. To do a mixed model with subject as a random effect and drug as a fixed effect, you would code it as so. Remember to include both the subject variable and your fixed effect in the CLASS statement.<\/p>\n<p>Proc mixed data = statin ;<br \/>\nclass subj drug ;<br \/>\nmodel ldl = drug ;<br \/>\nrandom subj ;<\/p>\n<p>To do a repeated measures ANOVA with PROC GLM you need three variables for each subject, not three records.<\/p>\n<p><strong>First, create three data sets<\/strong> for Drug A, Drug B and Drug C.<\/p>\n<p>Data one two three ;<br \/>\nset statin ;<br \/>\nif drug = &#8216;A&#8217; then output one ;<br \/>\nelse if drug = &#8216;B&#8217; then output two ;<br \/>\nelse if drug = &#8216;C&#8217; then output three ;<\/p>\n<p><strong>Second, sort these datasets and as you read in each one, rename LDL<\/strong> to a new name so that when you merge the datasets you have three different names. Yes, I really only needed to rename two of them, but I figured it was just neater this way.<\/p>\n<p>proc sort data = one (rename= (ldl =ldla)) ;<br \/>\nby subj ;<\/p>\n<p>proc sort data= two (rename = (ldl = ldlb)) ;<br \/>\nby subj ;<br \/>\nproc sort data=three (rename =(ldl = ldlc)) ;<br \/>\nby subj ;<\/p>\n<p><strong>Third, merge the three datasets by subject.<\/strong><\/p>\n<p>data mrg ;<br \/>\nmerge one two three ;<br \/>\nby subj ;<\/p>\n<p>Fourth, run your repeated measures ANOVA .<\/p>\n<p>Your three times measuring LDL are the dependent . It seems weird to not have an independent on the other side of the equation, but that&#8217;s the way it is. In your REPEATED statement you give a name for the repeated variable and the number of levels. I used &#8220;drug&#8221; here to be consistent but actually, this could be any name at all. I could have used &#8220;frog&#8221; or &#8220;rutabaga&#8221; instead and it would have worked just as well.<\/p>\n<p>proc glm data = mrg ;<br \/>\nmodel ldla ldlb ldlc = \/nouni ;<br \/>\nrepeated drug 3 (1 2 3) ;<br \/>\nrun ;<\/p>\n<p><a href=\"http:\/\/www.thejuliagroup.com\/documents\/mixed_repeated.html\">Compare the results and you will see that both give you the numerator and denominator degrees of freedom, F-statistic and p-value for the fixed effect of drug.<\/a><\/p>\n<p>Now you can be happy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What if you wanted to turn your PROC MIXED into a repeated measures ANOVA using PROC GLM. Why would you want to do this? Well, I don&#8217;t know why you would want to do it but I wanted to do it because I wanted to demonstrate for my class that both give you the same&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9,11],"tags":[],"class_list":["post-4397","post","type-post","status-publish","format-standard","hentry","category-software","category-statistics"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/4397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/comments?post=4397"}],"version-history":[{"count":2,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/4397\/revisions"}],"predecessor-version":[{"id":4399,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/posts\/4397\/revisions\/4399"}],"wp:attachment":[{"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/media?parent=4397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/categories?post=4397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thejuliagroup.com\/blog\/wp-json\/wp\/v2\/tags?post=4397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}