- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am working on Inverse Probability weighting. However, the codes I have are deleting the treatment group. When I remove the part of the code that does that, I have the same number of observations at the end. I am a little confused because, I was hoping it would work like matching were unmatched observations are excluded. Please, how do I achieve balance after weighting? The following are my codes.
Thank you for your help!
proc logistic data=data2;
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2 bmi2
mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
pmh_dialysis infection_ed_source2 infection_ed_source2 Lactate1_cat
citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out = ps pred = ps;
run;
/***inverse probability of treatment weight (IPTW)*****/
/*****the inverse of the propensity score****/
/***this code excludes the treatment grp***/
data ps_weight;
set ps;
ps_weight=1/ps;
if telemed_use=_level_;
run;
/**this code keeps full sample***/
data ps_weight;
set ps;
ps_weight=1/ps;
run;
proc freq data=ps_weight;
table telemed_use;run;
/*****A SQL procedure creates a weight that reflects the sample size for each of the treatment groups***/
proc sql;
create table ps_weight_adj as
select *, (count(*)/1191)*ps_weight as ps_weight_adj
from ps_weight
group by telemed_use;
quit;
/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=ps_weight_adj;
class telemed_use(ref='0') / param=reference ;
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight ps_weight_adj / normalize;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The following SAS code helped.
The is is the link to the source of the SAS code Calculating IPW and SMR in SAS - BAILEY DEBARMORE
Thank you
/***CREATING PROPENSITY SCORES********/
proc logistic data=data2 DESC;
class sex Age2 bmi2 triage_pulse2 mode_arrival pmh_copd pmh_cirrhosis
pmh_transplant pmh_cancer pmh_diabetes pmh_dialysis infection_ed_source2 Lactate1_cat
ICU_yn2 RUCA ed_dispo;
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2
mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
pmh_dialysis infection_ed_source2 Lactate1_cat
citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out=denom p=d;
run;
/****Generate numerator for stabilized weights- output a dataset with results of
regression called num, with the resulting probabilities stored in variable n -
note that there is nothing on the right side of the equation because
the numerator will simply be P(A=a), where a = observed exposure status; *****/
proc logistic data=data2 desc;
model telemed_use=;
output out=num p=n;
run;
/*****Generate stabilized and unstabilized weights***/
proc sort data=data2;
by record_id;run;
proc sort data=denom;
by record_id;run;
proc sort data=num;
by record_id;run;
data newdata;
mergedata2 denom num;
by record_id;
if telemed_use=1 then uw=1/d; else if telemed_use=0 then uw=1/(1-d);
if telemed_use=1 then sw=n/d; else if telemed_use=0 then sw=(1-n)/(1-d);
run;
/*Remember we can use 1 - P(exposed) for the unexposed weight components;*/
*Check the distribution of your IPTW - the mean should be 1.**/
proc means data=newdata mean sum min max;
var uw sw;
run;
/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=newdata ;
class telemed_use(ref='0') / param=reference ;
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight sw ;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Which variable(s) define "treatment group"? You have around 30 variables that we have no idea which you may consider a treatment group.
Which is the first step where you notice the "treatment group" is missing?
With that many variables just how many records do you have in the Data2 data set? How many records do you have for each "treatment group"?
You may want to consider carefully reading your Model statement. It appears that you have some variables on the model statement twice: Infection_ed_source2, Bmi2. It won't hurt to only use them once and may help.
I strongly recommend that when you a magic number such as 1191 in the following that you document exactly where it came from and why it is used. Otherwise at a later time you may try to modify the code and either miss using the new value or not remember exactly how to derive it.
proc sql;
create table ps_weight_adj as
select *, (count(*)/1191)*ps_weight as ps_weight_adj
from ps_weight
group by telemed_use;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The following SAS code helped.
The is is the link to the source of the SAS code Calculating IPW and SMR in SAS - BAILEY DEBARMORE
Thank you
/***CREATING PROPENSITY SCORES********/
proc logistic data=data2 DESC;
class sex Age2 bmi2 triage_pulse2 mode_arrival pmh_copd pmh_cirrhosis
pmh_transplant pmh_cancer pmh_diabetes pmh_dialysis infection_ed_source2 Lactate1_cat
ICU_yn2 RUCA ed_dispo;
model telemed_use = sex Age2 bmi2 triage_pulse2 triage_systolic total_sofa1_ed2
mode_arrival pmh_copd pmh_cirrhosis pmh_transplant pmh_cancer pmh_diabetes
pmh_dialysis infection_ed_source2 Lactate1_cat
citypop_2019 EDVolume_2019 totalbeds ICU_yn2 RUCA transferdist ed_dispo
/link=logit rsquare ;
output out=denom p=d;
run;
/****Generate numerator for stabilized weights- output a dataset with results of
regression called num, with the resulting probabilities stored in variable n -
note that there is nothing on the right side of the equation because
the numerator will simply be P(A=a), where a = observed exposure status; *****/
proc logistic data=data2 desc;
model telemed_use=;
output out=num p=n;
run;
/*****Generate stabilized and unstabilized weights***/
proc sort data=data2;
by record_id;run;
proc sort data=denom;
by record_id;run;
proc sort data=num;
by record_id;run;
data newdata;
mergedata2 denom num;
by record_id;
if telemed_use=1 then uw=1/d; else if telemed_use=0 then uw=1/(1-d);
if telemed_use=1 then sw=n/d; else if telemed_use=0 then sw=(1-n)/(1-d);
run;
/*Remember we can use 1 - P(exposed) for the unexposed weight components;*/
*Check the distribution of your IPTW - the mean should be 1.**/
proc means data=newdata mean sum min max;
var uw sw;
run;
/***PROPENSITY SCORE WEIGHTED OUTCOME MODEL****/
proc logistic data=newdata ;
class telemed_use(ref='0') / param=reference ;
model complete_adherence (event='1') = telemed_use / rsquare clodds=wald lackfit ;
weight sw ;
run;