/* Howard Seltman'sxSAS PROC MIXED for BiorhythmsiPage
This file is usable in both SAS and HTML!  SAS users ignore everything
surrounded by < and > (visible after downloading).
*/
 
/* Simulated data: 10 controls, 10 treated
   Step 1: Use large fixed model, and test for necessity of AR(1)
*/

/* True biorhythm of simulated "attrib"
     Fundamental frequency=1/24 hours, harmonic=1/8 hours
     All subjects: Harmonic amplitude=7, harmonic phase shift= -1 hour,
       fundamental amplitude=5 +/- 1(sd), mean rises by 3 for each decade
       beyond age 40 (-3 per decade below 40)
     Controls: mean=45 +/- 2(sd), fundamental phase shift= 4 +/- 2(sd)
     Treated: mean=50 +/- 5(sd), fundamental phase shift= -2 +/- 2(sd)
*/

options linesize=80;

/*
Help on SAS data step
*/
data Sim1;
infile 'Sim.dat';
input id age sex rx time attrib;
  cos24=cos(2*3.14159/24*time);
  cos12=cos(2*3.14159/12*time);
  cos8=cos(2*3.14159/8*time);
  cos6=cos(2*3.14159/6*time);
  cos4p8=cos(2*3.14159/4.8*time);
  sin24=sin(2*3.14159/24*time);
  sin12=sin(2*3.14159/12*time);
  sin8=sin(2*3.14159/8*time);
  sin6=sin(2*3.14159/6*time);
  sin4p8=sin(2*3.14159/4.8*time);
  artime=int(time*100);  /* remove decimals to get correct sort order */
run;



/*****************************
  Large fixed model; test AR
*****************************/

title 'Sim Step 1: Fund + 4 Harm + Tx + Rand Int +/-AR(1)';

title2 'Without AR(1)';
/*
Help on SAS proc mixed statement
*/
proc mixed data=Sim1 info;
/*
Help on SAS class statement
*/
  class rx sex;
/*
Help on SAS model statement
*/
  model attrib = rx age sex cos24 sin24 cos12 sin12 cos8 sin8 cos6 sin6
    cos4p8 sin4p8
    rx*cos24 rx*sin24 rx*cos12 rx*sin12 rx*cos8 rx*sin8 
    rx*cos6 rx*sin6 rx*cos4p8 rx*sin4p8;
/*
Help on SAS random statement
*/
  random int /type=UN sub=id;
run;

title2 'With AR(1)';
proc mixed data=Sim1 info;
  class rx sex artime;
  model attrib = rx age sex cos24 sin24 cos12 sin12 cos8 sin8 cos6 sin6
    cos4p8 sin4p8
    rx*cos24 rx*sin24 rx*cos12 rx*sin12 rx*cos8 rx*sin8 
    rx*cos6 rx*sin6 rx*cos4p8 rx*sin4p8;
  random int /type=UN sub=id;
/*
Help on SAS repeated statement
*/
  repeated artime / type=ar(1) sub=id;
run;

/*
*/