Wednesday, November 19, 2014

11/19 part2

data testnewnew;
input a$ c $ yes no total;
datalines;
no no 2 279 281
no yes 3 43 46
yes no 44 456 500
yes yes 911 538 1449
;
run;

proc genmod data=testnewnew;
class a c;
model yes/total = a c / dist=bin  link=logit ;
run;

11/19 part1

data afterlife;
input race belief count @@;
datalines;
1 1 1339 1 0 300
2 1 260 2 0 55
3 1 88 3 0 22
;

proc genmod data=afterlife descending;
class race belief;
model count =race belief /dist=poi link=log;
run;

data test;
* table 7.3;
input alcohol $ cigarette $ marijuana$ count;
datalines;
yes yes yes 911
yes yes no 538
yes no yes 44
yes no no 456
no yes yes 3
no yes no 43
yes no yes 2
yes no no 279
;
run;


proc genmod data=test descending;
class alcohol cigarette marijuana;
model count = alcohol cigarette marijuana alcohol*cigarette alcohol*marijuana cigarette*marijuana / dist=poi link=log ;
run;

proc genmod data=test descending;
class alcohol(ref="no") cigarette(ref="no") marijuana(ref="no")/param=ref;
model count = alcohol cigarette marijuana alcohol*cigarette alcohol*marijuana cigarette*marijuana / dist=poi link=log ;
run;

Wednesday, November 12, 2014

11/12 part3

data poli;

input gender $ party $ ideology$ count ;
datalines;
fe do vl 44
fe do sl 47
fe do mo 118
fe do sc 23
fe do vc 32
fe re vl 18
fe re sl 28
fe re mo 86
fe re sc 39
fe re vc 48
ma do vl 36
ma do sl 34
ma do mo 53
ma do sc 18
ma do vc 23
ma re vl 12
ma re sl 18
ma re mo 62
ma re sc 45
ma re vc 51
;
run;
proc print data=poli;
run;


proc logistic data=poli order=data;
class party gender/param=ref;
freq count;
model ideology =  party gender /link=clogit aggregate scale=none;
output out = porb predprobs=I;
run;


proc logistic data=poli order=data;
class party gender/param=ref;
freq count;
model ideology =  party  /link=clogit aggregate scale=none;
output out = prob predprobs=I;
run;


proc freq data=prob noprint;
WEIGHT count;
tables party*ip_vl*ip_sl*ip_mo*ip_sc*ip_sl*ip_vc/
list nocum nopercent out=test;
run;

11/12 part2

data life;

input race$ gender $ belief$ count ;
datalines;
white f yes 371
white f und 49
white f no 74
white m yes 250
white m und 45
white m no 71
black f yes 64
black f und 9
black f no 15
black m yes 25
black m und 5
black m no 13
;
run;
proc print data=life;
run;


proc logistic data=life order=data;
class race gender;
freq count;
model belief= race gender /link=glogit aggregate scale=none;
output out=prob predprobs=I;
run;


proc logistic data=life order=data;
class race (ref="black")
gender (ref="m")/ param=ref;
freq count;
model belief= race gender /link=glogit aggregate scale=none;
output out=prob predprobs=I;
run;

11/12 part1

data alli;

input length choice $ @@;
datalines;

1.24 I  1.30 I  1.30 I  1.32 F  1.32 F  1.40 F  1.42 I  1.42 F

1.45 I  1.45 O  1.47 I  1.47 F  1.50 I  1.52 I  1.55 I  1.60 I

1.63 I  1.65 O  1.65 I  1.65 F  1.65 F  1.68 F  1.70 I  1.73 O

1.78 I  1.78 I  1.78 O  1.80 I  1.80 F  1.85 F  1.88 I  1.93 I

1.98 I  2.03 F  2.03 F  2.16 F  2.26 F  2.31 F  2.31 F  2.36 F

2.36 F  2.39 F  2.41 F  2.44 F  2.46 F  2.56 O  2.67 F  2.72 I

2.79 F  2.84 F  3.25 O  3.28 O  3.33 F  3.56 F  3.58 F  3.66 F

3.68 O  3.71 F  3.89 F
;
run;

proc print data=alli;
run;

proc logistic;
model choice=length / link =glogit;
run;



proc logistic;
model choice=length / link =glogit aggregate scale=none;
run;

Wednesday, November 5, 2014

11/05/2014 part 2

data crab;
input color  spine  width  satell  weight;
weight=weight/1000;
color=color-1;

if color=4 then dark=1 ;
else dark=0;




if satell>0 then y=1;
if satell=0 then y=0;
n=1;

datalines;
3  3  28.3  8  3050
4  3  22.5  0  1550
2  1  26.0  9  2300
4  3  24.8  0  2100
4  3  26.0  4  2600
3  3  23.8  0  2100
2  1  26.5  0  2350
4  2  24.7  0  1900
3  1  23.7  0  1950
4  3  25.6  0  2150
4  3  24.3  0  2150
3  3  25.8  0  2650
3  3  28.2  11 3050
5  2  21.0  0  1850
3  1  26.0  14 2300
2  1  27.1  8  2950
3  3  25.2  1  2000
3  3  29.0  1  3000
5  3  24.7  0  2200
3  3  27.4  5  2700
3  2  23.2  4  1950
2  2  25.0  3  2300
3  1  22.5  1  1600
4  3  26.7  2  2600
5  3  25.8  3  2000
5  3  26.2  0  1300
3  3  28.7  3  3150
3  1  26.8  5  2700
5  3  27.5  0  2600
3  3  24.9  0  2100
2  1  29.3  4  3200
2  3  25.8  0  2600
3  2  25.7  0  2000
3  1  25.7  8  2000
3  1  26.7  5  2700
5  3  23.7  0  1850
3  3  26.8  0  2650
3  3  27.5  6  3150
5  3  23.4  0  1900
3  3  27.9  6  2800
4  3  27.5  3  3100
2  1  26.1  5  2800
2  1  27.7  6  2500
3  1  30.0  5  3300
4  1  28.5  9  3250
4  3  28.9  4  2800
3  3  28.2  6  2600
3  3  25.0  4  2100
3  3  28.5  3  3000
3  1  30.3  3  3600
5  3  24.7  5  2100
3  3  27.7  5  2900
2  1  27.4  6  2700
3  3  22.9  4  1600
3  1  25.7  5  2000
3  3  28.3  15 3000
3  3  27.2  3  2700
4  3  26.2  3  2300
3  1  27.8  0  2750
5  3  25.5  0  2250
4  3  27.1  0  2550
4  3  24.5  5  2050
4  1  27.0  3  2450
3  3  26.0  5  2150
3  3  28.0  1  2800
3  3  30.0  8  3050
3  3  29.0  10 3200
3  3  26.2  0  2400
3  1  26.5  0  1300
3  3  26.2  3  2400
4  3  25.6  7  2800
4  3  23.0  1  1650
4  3  23.0  0  1800
3  3  25.4  6  2250
4  3  24.2  0  1900
3  2  22.9  0  1600
4  2  26.0  3  2200
3  3  25.4  4  2250
4  3  25.7  0  1200
3  3  25.1  5  2100
4  2  24.5  0  2250
5  3  27.5  0  2900
4  3  23.1  0  1650
4  1  25.9  4  2550
3  3  25.8  0  2300
5  3  27.0  3  2250
3  3  28.5  0  3050
5  1  25.5  0  2750
5  3  23.5  0  1900
3  2  24.0  0  1700
3  1  29.7  5  3850
3  1  26.8  0  2550
5  3  26.7  0  2450
3  1  28.7  0  3200
4  3  23.1  0  1550
3  1  29.0  1  2800
4  3  25.5  0  2250
4  3  26.5  1  1967
4  3  24.5  1  2200
4  3  28.5  1  3000
3  3  28.2  1  2867
3  3  24.5  1  1600
3  3  27.5  1  2550
3  2  24.7  4  2550
3  1  25.2  1  2000
4  3  27.3  1  2900
3  3  26.3  1  2400
3  3  29.0  1  3100
3  3  25.3  2  1900
3  3  26.5  4  2300
3  3  27.8  3  3250
3  3  27.0  6  2500
4  3  25.7  0  2100
3  3  25.0  2  2100
3  3  31.9  2  3325
5  3  23.7  0  1800
5  3  29.3  12 3225
4  3  22.0  0  1400
3  3  25.0  5  2400
4  3  27.0  6  2500
4  3  23.8  6  1800
2  1  30.2  2  3275
4  3  26.2  0  2225
3  3  24.2  2  1650
3  3  27.4  3  2900
3  2  25.4  0  2300
4  3  28.4  3  3200
5  3  22.5  4  1475
3  3  26.2  2  2025
3  1  24.9  6  2300
2  2  24.5  6  1950
3  3  25.1  0  1800
3  1  28.0  4  2900
5  3  25.8  10 2250
3  3  27.9  7  3050
3  3  24.9  0  2200
3  1  28.4  5  3100
4  3  27.2  5  2400
3  2  25.0  6  2250
3  3  27.5  6  2625
3  1  33.5  7  5200
3  3  30.5  3  3325
4  3  29.0  3  2925
3  1  24.3  0  2000
3  3  25.8  0  2400
5  3  25.0  8  2100
3  1  31.7  4  3725
3  3  29.5  4  3025
4  3  24.0  10 1900
3  3  30.0  9  3000
3  3  27.6  4  2850
3  3  26.2  0  2300
3  1  23.1  0  2000
3  1  22.9  0  1600
5  3  24.5  0  1900
3  3  24.7  4  1950
3  3  28.3  0  3200
3  3  23.9  2  1850
4  3  23.8  0  1800
4  2  29.8  4  3500
3  3  26.5  4  2350
3  3  26.0  3  2275
3  3  28.2  8  3050
5  3  25.7  0  2150
3  3  26.5  7  2750
3  3  25.8  0  2200
4  3  24.1  0  1800
4  3  26.2  2  2175
4  3  26.1  3  2750
4  3  29.0  4  3275
2  1  28.0  0  2625
5  3  27.0  0  2625
3  2  24.5  0  2000
;

run;

proc print data=crab;
run;

proc genmod descending data=crab;
model y=width/dist=bin link=logit;
run;


proc genmod descending data=crab;
class color;
model y=width color/dist=bin link=logit obstats;
contrast'a-d' color 1 0 0 -1;
run;

proc logistic descending ;
class color spine/param=ref;
model y=width weight color spine/
selection =backword lackfit outroc=classif1;
proc plot data=classif1;
plot _sensit_*_1mspec_;

11/5/2014

data death;
input vict $ def $ yes no;
tol=yes+no;
datalines;
w w 53 414
w b 11 37
b w 0 16
b b 4 139
;
run;

proc print data=death;
run;

proc genmod data=death;
class vict def;
model yes/tol=vict def/ dist=bin link=logit;
run;

proc logistic data=death;
class vict def;
model yes/tol=vict def/lackfit;
run;

proc logistic data=death;
class vict def/param=ref;
model yes/tol=vict def/lackfit;
run;


data aids;
input race $ azt $ y n;
total=y+n;
datalines;
white yes 14 93
white no 32 81
black yes 11 52
black no 12 43
;
*Asian yes 6 29
*Asian no 7 33;
run;

proc print data=aids;
run;

proc genmod data=aids;
class race azt;
model y/total=race azt/ dist=bin link=logit;
run;

proc genmod data=aids;
class race azt;
model y/total=race azt race*azt/ dist=bin link=logit;
run;


data one;
set aids;
outcome="yes"; count=y; output;
outcome="no"; count=n; output;
drop y n total;
run;

proc print data=one;
run;

proc freq data=one;
weight count;
tables race*azt*outcome /chm1;
run;

proc logistic data=aids;
class race (ref="white") azt(ref="no") / param=ref;
model y/total =azt race;
run;


proc logistic data=aids;
class race (ref="black") azt(ref="no") / param=ref;
model y/total =azt race;


run;

Wednesday, October 29, 2014

carb sas code

data crab;
input color  spine  width  satell  weight;
if satell>0 then y=1;
if satell=0 then y=0;
n=1;

datalines;
3  3  28.3  8  3050
4  3  22.5  0  1550
2  1  26.0  9  2300
4  3  24.8  0  2100
4  3  26.0  4  2600
3  3  23.8  0  2100
2  1  26.5  0  2350
4  2  24.7  0  1900
3  1  23.7  0  1950
4  3  25.6  0  2150
4  3  24.3  0  2150
3  3  25.8  0  2650
3  3  28.2  11 3050
5  2  21.0  0  1850
3  1  26.0  14 2300
2  1  27.1  8  2950
3  3  25.2  1  2000
3  3  29.0  1  3000
5  3  24.7  0  2200
3  3  27.4  5  2700
3  2  23.2  4  1950
2  2  25.0  3  2300
3  1  22.5  1  1600
4  3  26.7  2  2600
5  3  25.8  3  2000
5  3  26.2  0  1300
3  3  28.7  3  3150
3  1  26.8  5  2700
5  3  27.5  0  2600
3  3  24.9  0  2100
2  1  29.3  4  3200
2  3  25.8  0  2600
3  2  25.7  0  2000
3  1  25.7  8  2000
3  1  26.7  5  2700
5  3  23.7  0  1850
3  3  26.8  0  2650
3  3  27.5  6  3150
5  3  23.4  0  1900
3  3  27.9  6  2800
4  3  27.5  3  3100
2  1  26.1  5  2800
2  1  27.7  6  2500
3  1  30.0  5  3300
4  1  28.5  9  3250
4  3  28.9  4  2800
3  3  28.2  6  2600
3  3  25.0  4  2100
3  3  28.5  3  3000
3  1  30.3  3  3600
5  3  24.7  5  2100
3  3  27.7  5  2900
2  1  27.4  6  2700
3  3  22.9  4  1600
3  1  25.7  5  2000
3  3  28.3  15 3000
3  3  27.2  3  2700
4  3  26.2  3  2300
3  1  27.8  0  2750
5  3  25.5  0  2250
4  3  27.1  0  2550
4  3  24.5  5  2050
4  1  27.0  3  2450
3  3  26.0  5  2150
3  3  28.0  1  2800
3  3  30.0  8  3050
3  3  29.0  10 3200
3  3  26.2  0  2400
3  1  26.5  0  1300
3  3  26.2  3  2400
4  3  25.6  7  2800
4  3  23.0  1  1650
4  3  23.0  0  1800
3  3  25.4  6  2250
4  3  24.2  0  1900
3  2  22.9  0  1600
4  2  26.0  3  2200
3  3  25.4  4  2250
4  3  25.7  0  1200
3  3  25.1  5  2100
4  2  24.5  0  2250
5  3  27.5  0  2900
4  3  23.1  0  1650
4  1  25.9  4  2550
3  3  25.8  0  2300
5  3  27.0  3  2250
3  3  28.5  0  3050
5  1  25.5  0  2750
5  3  23.5  0  1900
3  2  24.0  0  1700
3  1  29.7  5  3850
3  1  26.8  0  2550
5  3  26.7  0  2450
3  1  28.7  0  3200
4  3  23.1  0  1550
3  1  29.0  1  2800
4  3  25.5  0  2250
4  3  26.5  1  1967
4  3  24.5  1  2200
4  3  28.5  1  3000
3  3  28.2  1  2867
3  3  24.5  1  1600
3  3  27.5  1  2550
3  2  24.7  4  2550
3  1  25.2  1  2000
4  3  27.3  1  2900
3  3  26.3  1  2400
3  3  29.0  1  3100
3  3  25.3  2  1900
3  3  26.5  4  2300
3  3  27.8  3  3250
3  3  27.0  6  2500
4  3  25.7  0  2100
3  3  25.0  2  2100
3  3  31.9  2  3325
5  3  23.7  0  1800
5  3  29.3  12 3225
4  3  22.0  0  1400
3  3  25.0  5  2400
4  3  27.0  6  2500
4  3  23.8  6  1800
2  1  30.2  2  3275
4  3  26.2  0  2225
3  3  24.2  2  1650
3  3  27.4  3  2900
3  2  25.4  0  2300
4  3  28.4  3  3200
5  3  22.5  4  1475
3  3  26.2  2  2025
3  1  24.9  6  2300
2  2  24.5  6  1950
3  3  25.1  0  1800
3  1  28.0  4  2900
5  3  25.8  10 2250
3  3  27.9  7  3050
3  3  24.9  0  2200
3  1  28.4  5  3100
4  3  27.2  5  2400
3  2  25.0  6  2250
3  3  27.5  6  2625
3  1  33.5  7  5200
3  3  30.5  3  3325
4  3  29.0  3  2925
3  1  24.3  0  2000
3  3  25.8  0  2400
5  3  25.0  8  2100
3  1  31.7  4  3725
3  3  29.5  4  3025
4  3  24.0  10 1900
3  3  30.0  9  3000
3  3  27.6  4  2850
3  3  26.2  0  2300
3  1  23.1  0  2000
3  1  22.9  0  1600
5  3  24.5  0  1900
3  3  24.7  4  1950
3  3  28.3  0  3200
3  3  23.9  2  1850
4  3  23.8  0  1800
4  2  29.8  4  3500
3  3  26.5  4  2350
3  3  26.0  3  2275
3  3  28.2  8  3050
5  3  25.7  0  2150
3  3  26.5  7  2750
3  3  25.8  0  2200
4  3  24.1  0  1800
4  3  26.2  2  2175
4  3  26.1  3  2750
4  3  29.0  4  3275
2  1  28.0  0  2625
5  3  27.0  0  2625
3  2  24.5  0  2000
;

run;

proc print data=crab;
run;

data crab1;
set crab;
wcat=0;
if width<=23.25 then wcat=1;
if 23.25 < width <=24.25 then wcat=2;
if 24.25 < width <=25.25 then wcat=3;
if 25.25 < width <=26.25 then wcat=4;
if 26.25 < width <=27.25 then wcat=5;
if 27.25 < width <=28.25 then wcat=6;
if 28.25  <width <=29.25 then wcat=7;
if width > 29.25 then wcat=8;
run;

proc sql;
create table midpt as
select*, mean(satell) as smean, mean(width)
as wmean, std(satell)*std(satell) as varsatell,
count(wcat) as total, sum(y) as yes
from crab1
group by wcat;
quit;

proc sort data=midpt;
by wcat;
run;

data midpt2;
set midpt;
by wcat;
if first.wcat;
run;



data midpt2;
set midpt2;
proportion=yes/total;
run;

proc print data=midpt2;
run;


proc genmod data=midpt2;
model yes/ total=wcat/dist=bin link=logit;
output out=temp1 p=pred1;
run;

/* this model is used for ungrouped data*/
/* default is the wald CI*/
proc genmod descending data=crab1;
model y=width/dist=bin link=logit;
run;

proc genmod descending data=crab1;
model y=wcat/dist=bin link=logit;
run;

proc genmod  data=crab1;
model y=wcat/dist=bin link=logit lrci;/* likelihood ratio CI*/
run;
proc genmod  descending data=crab1;
model y=width/dist=bin link=logit lrci/* likelihood ratio CI*/
covb; /* covariance of alpha and beta  */
output out=temp p=pred upper=ucl
lower=lcl;
run;


data aids;
input  yes no azt$ race$ ;
total=yes+no;
datalines;
14 93 yes white
32 81 no  white
11 52 yes black
12 43 no  black
;

run;

proc print data=aids;
run;

proc genmod data=aids; class race azt;
model yes/total=azt race/dist=bin link=logit;
run;

crab data

color  spine  width  satellite  weight
3  3  28.3  8  3050
4  3  22.5  0  1550
2  1  26.0  9  2300
4  3  24.8  0  2100
4  3  26.0  4  2600
3  3  23.8  0  2100
2  1  26.5  0  2350
4  2  24.7  0  1900
3  1  23.7  0  1950
4  3  25.6  0  2150
4  3  24.3  0  2150
3  3  25.8  0  2650
3  3  28.2  11 3050
5  2  21.0  0  1850
3  1  26.0  14 2300
2  1  27.1  8  2950
3  3  25.2  1  2000
3  3  29.0  1  3000
5  3  24.7  0  2200
3  3  27.4  5  2700
3  2  23.2  4  1950
2  2  25.0  3  2300
3  1  22.5  1  1600
4  3  26.7  2  2600
5  3  25.8  3  2000
5  3  26.2  0  1300
3  3  28.7  3  3150
3  1  26.8  5  2700
5  3  27.5  0  2600
3  3  24.9  0  2100
2  1  29.3  4  3200
2  3  25.8  0  2600
3  2  25.7  0  2000
3  1  25.7  8  2000
3  1  26.7  5  2700
5  3  23.7  0  1850
3  3  26.8  0  2650
3  3  27.5  6  3150
5  3  23.4  0  1900
3  3  27.9  6  2800
4  3  27.5  3  3100
2  1  26.1  5  2800
2  1  27.7  6  2500
3  1  30.0  5  3300
4  1  28.5  9  3250
4  3  28.9  4  2800
3  3  28.2  6  2600
3  3  25.0  4  2100
3  3  28.5  3  3000
3  1  30.3  3  3600
5  3  24.7  5  2100
3  3  27.7  5  2900
2  1  27.4  6  2700
3  3  22.9  4  1600
3  1  25.7  5  2000
3  3  28.3  15 3000
3  3  27.2  3  2700
4  3  26.2  3  2300
3  1  27.8  0  2750
5  3  25.5  0  2250
4  3  27.1  0  2550
4  3  24.5  5  2050
4  1  27.0  3  2450
3  3  26.0  5  2150
3  3  28.0  1  2800
3  3  30.0  8  3050
3  3  29.0  10 3200
3  3  26.2  0  2400
3  1  26.5  0  1300
3  3  26.2  3  2400
4  3  25.6  7  2800
4  3  23.0  1  1650
4  3  23.0  0  1800
3  3  25.4  6  2250
4  3  24.2  0  1900
3  2  22.9  0  1600
4  2  26.0  3  2200
3  3  25.4  4  2250
4  3  25.7  0  1200
3  3  25.1  5  2100
4  2  24.5  0  2250
5  3  27.5  0  2900
4  3  23.1  0  1650
4  1  25.9  4  2550
3  3  25.8  0  2300
5  3  27.0  3  2250
3  3  28.5  0  3050
5  1  25.5  0  2750
5  3  23.5  0  1900
3  2  24.0  0  1700
3  1  29.7  5  3850
3  1  26.8  0  2550
5  3  26.7  0  2450
3  1  28.7  0  3200
4  3  23.1  0  1550
3  1  29.0  1  2800
4  3  25.5  0  2250
4  3  26.5  1  1967
4  3  24.5  1  2200
4  3  28.5  1  3000
3  3  28.2  1  2867
3  3  24.5  1  1600
3  3  27.5  1  2550
3  2  24.7  4  2550
3  1  25.2  1  2000
4  3  27.3  1  2900
3  3  26.3  1  2400
3  3  29.0  1  3100
3  3  25.3  2  1900
3  3  26.5  4  2300
3  3  27.8  3  3250
3  3  27.0  6  2500
4  3  25.7  0  2100
3  3  25.0  2  2100
3  3  31.9  2  3325
5  3  23.7  0  1800
5  3  29.3  12 3225
4  3  22.0  0  1400
3  3  25.0  5  2400
4  3  27.0  6  2500
4  3  23.8  6  1800
2  1  30.2  2  3275
4  3  26.2  0  2225
3  3  24.2  2  1650
3  3  27.4  3  2900
3  2  25.4  0  2300
4  3  28.4  3  3200
5  3  22.5  4  1475
3  3  26.2  2  2025
3  1  24.9  6  2300
2  2  24.5  6  1950
3  3  25.1  0  1800
3  1  28.0  4  2900
5  3  25.8  10 2250
3  3  27.9  7  3050
3  3  24.9  0  2200
3  1  28.4  5  3100
4  3  27.2  5  2400
3  2  25.0  6  2250
3  3  27.5  6  2625
3  1  33.5  7  5200
3  3  30.5  3  3325
4  3  29.0  3  2925
3  1  24.3  0  2000
3  3  25.8  0  2400
5  3  25.0  8  2100
3  1  31.7  4  3725
3  3  29.5  4  3025
4  3  24.0  10 1900
3  3  30.0  9  3000
3  3  27.6  4  2850
3  3  26.2  0  2300
3  1  23.1  0  2000
3  1  22.9  0  1600
5  3  24.5  0  1900
3  3  24.7  4  1950
3  3  28.3  0  3200
3  3  23.9  2  1850
4  3  23.8  0  1800
4  2  29.8  4  3500
3  3  26.5  4  2350
3  3  26.0  3  2275
3  3  28.2  8  3050
5  3  25.7  0  2150
3  3  26.5  7  2750
3  3  25.8  0  2200
4  3  24.1  0  1800
4  3  26.2  2  2175
4  3  26.1  3  2750
4  3  29.0  4  3275
2  1  28.0  0  2625
5  3  27.0  0  2625
3  2  24.5  0  2000