/* pain1.sas */ title 'Multivariate repeated measures analysis of the pain data'; /* Read data from an old .xls spreadsheet */ proc import datafile="/home/u1407221/441s24/data/Pain.xls" out=ouch0 dbms=xls replace; getnames=yes; proc print; /* Dose 1 Dose 2 Dose 3 ------ ----- ------ Drug 1 Drug1Dose1 Drug1Dose2 Drug1Dose3 Drug 2 Drug2Dose1 Drug2Dose2 Drug2Dose3 */ /* Computing sum and contrast variables in the data step */ data ouch1; set ouch0; /* Pairwise differences */ d12 = Drug1Dose1-Drug1Dose2; d13 = Drug1Dose1-Drug1Dose3; d14 = Drug1Dose1-Drug2Dose1; d15 = Drug1Dose1-Drug2Dose2; d16 = Drug1Dose1-Drug2Dose3; d23 = Drug1Dose2-Drug1Dose3; d24 = Drug1Dose2-Drug2Dose1; d25 = Drug1Dose2-Drug2Dose2; d26 = Drug1Dose2-Drug2Dose3; d34 = Drug1Dose3-Drug2Dose1; d35 = Drug1Dose3-Drug2Dose2; d36 = Drug1Dose3-Drug2Dose3; d45 = Drug2Dose1-Drug2Dose2; d46 = Drug2Dose1-Drug2Dose3; d56 = Drug2Dose2-Drug2Dose3; /* Marginal means and interactions */ Drug1 = mean(of Drug1Dose1-Drug1Dose3); Drug2 = mean(of Drug2Dose1-Drug2Dose3); Dose1 = (Drug1Dose1+Drug2Dose1)/2; Dose2 = (Drug1Dose2+Drug2Dose2)/2; Dose3 = (Drug1Dose3+Drug2Dose3)/2; Drugdiff = drug1-drug2; doseD12 = dose1-dose2; doseD13 = dose1-dose3; doseD23 = dose2-dose3; DrugEffect1 = Drug1Dose1-Drug2Dose1; DrugEffect2 = Drug1Dose2-Drug2Dose2; DrugEffect3 = Drug1Dose3-Drug2Dose3; label DrugEffect1 = 'Drug effect for dose 1' DrugEffect2 = 'Drug effect for dose 2' DrugEffect3 = 'Drug effect for dose 3'; int1 = DrugEffect1-DrugEffect2; int2 = DrugEffect1-DrugEffect3; int3 = DrugEffect2-DrugEffect3; proc means data=ouch1 n mean stddev maxdec=3; var Drug1Dose1 -- Drug2Dose3 Drug1 Drug2 Dose1-Dose3 DrugEffect1-DrugEffect3; run; /* Test for overall differences, main effects and interaction. Just look at the multivariate output. */ ods select MultStat (persist); proc reg data=ouch1; title2 'Overall test'; model d12-d16 = ; Overall: mtest intercept = 0; run; proc reg data=ouch1; title2 'Main Effect of Drug'; model drugdiff = ; Drug: mtest intercept = 0; /* Could have used test or just looked at the univariate t statistic. */ run; proc reg; title2 'Main Effect of Dose Level'; model dosed12 dosed13 = ; Dose: mtest intercept = 0; run; proc reg data=ouch1; title2 'Drug by Dose Interaction'; model int1 int2 = ; Drug_by_Dose: mtest intercept = 0; run; /* Follow up, including tests of pairwise difference even though the overall test was not significant. */ ods select all; /* Turning off the selection */ proc means data=ouch1 n mean t probt; title2 'Follow up with matched t-tests'; var d12 -- d56 dosed12--dosed23 int1-int3 ; /* Specify transformations of response variables within proc reg Dose 1 Dose 2 Dose 3 ------ ----- ------ Drug 1 Drug1Dose1 Drug1Dose2 Drug1Dose3 Drug 2 Drug2Dose1 Drug2Dose2 Drug2Dose3 */ /* Strangely, after the first time I use ods select in a job, it only seems to work when I precede it with quit. ods is a little flaky with SAS OnDemand; maybe that's the reason. */ quit; ods select MultStat; proc reg data=ouch0 plots=none; title2 'Specify new response variables within proc reg'; model Drug1Dose1 -- Drug2Dose3 = ; Overall: mtest intercept = 0, Drug1Dose1-Drug1Dose2, Drug1Dose1-Drug1Dose3, Drug1Dose1-Drug2Dose1, Drug1Dose1-Drug2Dose2, Drug1Dose1-Drug2Dose3; Drug: mtest intercept = 0, Drug1Dose1+Drug1Dose2+Drug1Dose3 - Drug2Dose1-Drug2Dose2-Drug2Dose3; Dose: mtest intercept = 0, Drug1Dose1+Drug2Dose1 - Drug1Dose2-Drug2Dose2, Drug1Dose2+Drug2Dose2 - Drug1Dose3-Drug2Dose3; Interaction: mtest intercept = 0, Drug1Dose1-Drug2Dose1 - Drug1Dose2+Drug2Dose2, Drug1Dose1-Drug2Dose1 - Drug1Dose3+Drug2Dose3; run; quit; ods select MultStat GLM.Repeated.WithinSubject.ModelANOVA; proc glm data=ouch0; title2 'Two-factor within cases the easy way'; model Drug1Dose1--Drug2Dose3 = ; repeated Drug 2, Dosage 3 / short summary; /* Factor on the right changes fastest (like numbers) */ run; quit; ods select MultStat GLM.Repeated.WithinSubject.ModelANOVA; proc glm data=ouch0; title2 'Overall test the easy way'; model Drug1Dose1--Drug2Dose3 = ; repeated treatment / short summary; run; quit;