- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear,
I am currently using multiple imputation for my dataset. Normally I report everything with mean and standard error.
But is there a way to calculate or analyse medians instead of means for the imputed dataset?
Thank you!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to use a Procedure that gives a standard error for the median so that you will be able to calculate the between and within imputation variance. I think both Proc LIFETEST and SURVEYMEANS are the only procedures that do this. I include an example below which uses the latter.
/*Sample Data Set that assumes Proc MI has already been run*/
data test;
do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211);
output;
end;
end;
run;
proc surveymeans data=test median;
by _imputation_;
var y;
ods output quantiles=stats;
run;
proc mianalyze data=stats;
modeleffects estimate;
stderr stderr;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
try using proc univariate.
proc univariate data=sashelp.class;
var age;
output out=result MEDIAN=median;
run;
For other statistics, please refer to the following
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_syntax21.htm
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I am currenlty using the following statement for calculating means of the imputed data.
proc univariate data= test_imputed noprint;
var DAM ;
output out = test_imputed2 mean = DAM_new stderr= std_DAM ;
by intervention _Imputation_;
run;
proc mianalyze data=test_imputed edf=20;
modeleffects DAM_new;
stderr std_DAM;
by intervention;
run;
How should I adapt the proc mianalyze statement if I use median in the proc univariate?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC MEANS and PROC SUMMARY also calculate medians and standard deviations/standard errors.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi ,
Thank you, could you please give an example of a code? I am using this code to calcute means for the imputed dataset.
Does proc means and proc summary also work with proc mianalyze?
proc univariate data= test_imputed noprint;
var DAM ;
output out = test_imputed2 mean = DAM_new stderr= std_DAM ;
by intervention _Imputation_;
run;
proc mianalyze data=test_imputed edf=20;
modeleffects DAM_new;
stderr std_DAM;
by intervention;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Now I am confused. I did not interpret your original problem statement to be what your code is trying to do. I interpreted your original statement to mean that you did some form of multiple imputation, and after that you report means (or medians) and standard errors. But now it seems your code is doing things in the opposite order, computing medians and following that some form of missing value imputation.
So which is it?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I imputed one variable with the PROC MI statement. Afterwards, I do the analyses 'by _Imputation' (which can be proc univariate, proc glm, etc - based on the analysis I need) , followed by a PROC MIANALYZE statement to gather the final results.
Now I want to have medians (instead of means) of my imputed variable. But ofcourse taking into account the multiple imputation, I have to work with proc univariate followed by a PROC MIANALYZE. But I don't know how to adapt the code for medians (if this is even possible with proc mianalyze).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to use a Procedure that gives a standard error for the median so that you will be able to calculate the between and within imputation variance. I think both Proc LIFETEST and SURVEYMEANS are the only procedures that do this. I include an example below which uses the latter.
/*Sample Data Set that assumes Proc MI has already been run*/
data test;
do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211);
output;
end;
end;
run;
proc surveymeans data=test median;
by _imputation_;
var y;
ods output quantiles=stats;
run;
proc mianalyze data=stats;
modeleffects estimate;
stderr stderr;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I like Rob's solution. However, there is another procedure that can estimate medians and provide standard errors. You can use PROC QUANTREG to estimate the median and std err and confidence intervals.
Here is an example that uses PROC QUANTREG:
ods exclude all;
proc quantreg data=test ci=sparsity;
by _imputation_;
model y=;
ods output ParameterEstimates=PE;
run;
ods exclude none;
proc mianalyze data=stats;
modeleffects estimate;
stderr stderr;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
proc univariate also could get CI of median.
proc univariate data=sashelp.heart CIQUANTDF CIQUANTNORMAL;
var weight;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes. I originally mentioned that, but Rob reminded me that PROC MIANALYZE needs an estimate of a standard error, not a CI. UNIVARIATE only provides the CI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for this solution!
could you explain me the following part of the script? :
do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211)
is it based on the amount of imputations (in my case 20)? Do I need to adapt this if I use 20 imputations?
Where does y=100+10*rannor(34211) come from?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
You can essentially ignore the first step in the sample program as I used it to generate a data set similar to what you would have gotten from Proc MI on your own data. You would just pick up at the Proc SURVEYMEANS step that you would run on your own data.