Saturday, July 25, 2009

Independent t-test with PROC MIXED


proc ttest data=anorexia (where=(treat in ("Cont","CBT")));
class treat;
var prewt;
run;

/* equal variance */
proc mixed data=anorexia (where=(treat in ("Cont","CBT")));
class treat;
model prewt = treat;
run;

/* unequal variance */
proc mixed data=anorexia (where=(treat in ("Cont","CBT")));
class treat;
model prewt = treat / DDFM=Satterthwaite;
repeated / group=treat;
run;

Friday, July 24, 2009

Paired t-test with PROC MIXED


proc import datafile="C:\projects\Endocrine\CGMS\data\ex\anorexia.csv" out=anorexia
dbms=csv replace; getnames=yes;
run;

proc sql;
create table cbt_long as
select var1 as patient, 0 as time, prewt as y
from anorexia (where=(treat="CBT"))
union
select var1 as patient, 1 as time, postwt as y
from anorexia (where=(treat="CBT"))
;quit;

proc mixed data= cbt_long;
class patient;
model y = time / s;
random patient;
* repeated / subject=patient type=cs rcorr;
run;

/* Paired t-test with SQL */
proc sql;
select t(postwt-prewt) as t, prt(postwt-prewt) as p_value
from anorexia (where=(treat="CBT"))
;quit;

PROC SQL: functions

COUNT, FREQ, N: number of nonmissing values

NMISS: number of missing values

MIN: smallest value

MAX: largest value

RANGE: range of values

SUM: sum of values

SUMWGT: sum of the WEIGHT variable values(footnote 1)

AVG, MEAN: means or average of values

T: Student's t value for testing the hypothesis that the population mean is zero

PRT: probability of a greater absolute value of Student's t

USS: uncorrected sum of squares

CSS: corrected sum of squares

VAR: variance

STD: standard deviation

STDERR: standard error of the mean

CV: coefficient of variation (percent)

Thursday, July 16, 2009

array & output


%let ntime=288;
data series (drop=j);
array c(30) ;
array s(30);
do time=1 to &ntime;
do j=1 to 30;
c[j]=cos(2*3.141593*j* time/&ntime); s[j]=sin(2*3.141593*j* time/&ntime);
end;
output;
end;
run;

Sunday, May 17, 2009

SEM


data illfl (type=corr);
input _type_ $1-4 _name_ $6-13
exercise 15-20 hardy 22-27
fitness 29-34 stress 36-41
illness 43-48;
cards;
n 373 373 373 373 373
mean 40.90 0.00 67.10 4.80 716.7
std 66.50 3.80 18.40 6.70 624.8
corr exercise 1.00
corr hardy -0.03 1.00
corr fitness 0.39 0.07 1.00
corr stress -0.05 -0.23 -0.13 1.00
corr illness -0.08 -0.16 -0.29 0.34 1.00
;;;;


/* Confirmatory Factor Analysis */

proc calis data=illfl corr;
lineqs
hardy = p1 F1 + e1,
stress = p2 F1 + e2,
illness = p3 F1 + e3,
fitness = p4 F2 + e4,
exercise= p5 F2 + e5;
std
e1-e5 = vare1-vare5,
F1 = 1,
F2 = 1;
cov
F1 F2 = covf1f2;
VAR exercise fitness hardy stress illness;
run;


/* Exploratory Factor Analysis */

proc factor data=illfl method=ml scree priors=smc;
var hardy stress illness fitness exercise;
run;

proc factor data=illfl method=ml rotate=v n=2 reorder plot priors=smc;
var hardy stress illness fitness exercise;
run;

Thursday, April 23, 2009

Poisson vs. Logistic regression


data melanoma;
input age $ region $ cases total;
ltotal=log(total);
datalines;
35-44 south 75 220407
45-54 south 68 198119
55-64 south 63 134084
65-74 south 45 70708
75+ south 27 34233
<35 south 64 1074246
35-44 north 76 564535
45-54 north 98 592983
55-64 north 104 450740
65-74 north 63 270908
75+ north 80 161850
<35 north 61 2880262
;
proc genmod data=melanoma order=data;
class age region;
model cases = age region / dist=poisson link=log offset=ltotal;
run;

proc sql;
create table melanoma2 as
select age, region, 1 as resp, cases as count from melanoma union
select age, region, 0 as resp, total-cases as count from melanoma
;quit;

proc genmod data=melanoma2;
weight count;
class age region;
model resp=age region / dist=binomial link=logit;
run;

proc mixed


data bond;
input ingot metal $ pres @@;
datalines;
1 n 67.0 1 i 71.9 1 c 72.2
2 n 67.5 2 i 68.8 2 c 66.4
3 n 76.0 3 i 82.6 3 c 74.5
4 n 72.7 4 i 78.1 4 c 67.3
5 n 73.1 5 i 74.2 5 c 73.2
6 n 65.8 6 i 70.8 6 c 68.7
7 n 75.6 7 i 84.9 7 c 69.0
;

proc mixed data=bond method=reml;
class ingot metal;
model pres=metal;
random ingot;
lsmeans metal / diff=control('n') adjust=dunnett;
run;

/* by simulation */
lsmeans metal / diff=control("n") cl
adjust=simulate(report seed=4943838 cvadjust);