- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
In this paper http://www.lexjansen.com/pharmasug/2003/Posters/P048.pdf
the author said that to get the 95% CI of the mean, it is the best to get N , Mean and Stdeer and use TINV function to calculate. This will get a narrower 95% CI for the mean compared to proc means or proc summary.
How did Proc Means or proc summary calculate the 95% CI for the mean?
In reality, which method is more often used?
*** three methods to get 95% CI for mean;
DATA test ;
INPUT subjno trt age ;
CARDS ;
1 1 25
2 2 30
3 1 15
4 1 45
5 2 22
6 2 54
;
RUN ;
PROC SORT DATA = test;
BY trt ;
RUN ;
*** method one: use proc means;
PROC MEANS DATA=test NOPRINT ;
BY trt ;
VAR age ;
OUTPUT OUT=xxtmp N=n MEAN=mean
STDERR=stderr LCLM=lclm Uclm=uclm ;
RUN ;
*** method two: use proc summary;
PROC SUMMARY DATA=test NOPRINT;
BY trt;
VAR age;
OUTPUT OUT=xxtmps N=n MEAN=mean
STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;
*** method three: use proc summary - this is the correct one;
PROC MEANS DATA=test NOPRINT;
BY trt ;
VAR age ;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean
STDERR=stderr LCLM=lclm UCLM=uclm ;
RUN ;
DATA xxtmp_2 ;
SET xxtmp_1;
lo = mean - ( TINV ( 0.95 , n-1 ) * stderr ) ;
hi = mean + ( TINV ( 0.95 , n-1 ) * stderr ) ;
RUN ;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I fixed it, but may have overridden yours.
Anyways, the paper is wrong - it's doing alpha=0.1 not alpha=0.05. The calculation happening is for a 90% confidence interval, not 95%.
Look at the 95% in the TINV function, for a two sided test it should 1-alpha/2 = 0.975 NOT 0.95. Once everything is the same the numbers from proc means match.
title 'method one: use proc means, alpha = 0.05, two sided test';
PROC MEANS DATA=sashelp.class n mean stderr lclm uclm alpha=0.05 vardef=df;
class sex;
VAR height;
OUTPUT OUT=xxtmp N=n MEAN=mean STDERR=stderr LCLM=lclm Uclm=uclm;
RUN;
*** method three: use proc summary - this is the correct one;
PROC MEANS DATA=sashelp.class noprint;
class sex;
VAR height;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;
DATA xxtmp_2;
SET xxtmp_1;
lo=mean - (TINV (0.975 , n-1) * stderr);
hi=mean + (TINV (0.975 , n-1) * stderr);
RUN;
title 'method two: use proc summary - this is the correct one';
proc print data=xxtmp_2;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I get a "not found" error for your link.
I wonder if this alternative is for a specific purpose but can't check as the link doesn't seem to work, at least for me.
Look in the online help for "Keywords and Formulas" in the SAS Elementary Statistic Procedures.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
you can copy and paste the URL and it works.
I just fixed the link
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I fixed it, but may have overridden yours.
Anyways, the paper is wrong - it's doing alpha=0.1 not alpha=0.05. The calculation happening is for a 90% confidence interval, not 95%.
Look at the 95% in the TINV function, for a two sided test it should 1-alpha/2 = 0.975 NOT 0.95. Once everything is the same the numbers from proc means match.
title 'method one: use proc means, alpha = 0.05, two sided test';
PROC MEANS DATA=sashelp.class n mean stderr lclm uclm alpha=0.05 vardef=df;
class sex;
VAR height;
OUTPUT OUT=xxtmp N=n MEAN=mean STDERR=stderr LCLM=lclm Uclm=uclm;
RUN;
*** method three: use proc summary - this is the correct one;
PROC MEANS DATA=sashelp.class noprint;
class sex;
VAR height;
OUTPUT OUT=xxtmp_1 N=n MEAN=mean STDERR=stderr LCLM=lclm UCLM=uclm;
RUN;
DATA xxtmp_2;
SET xxtmp_1;
lo=mean - (TINV (0.975 , n-1) * stderr);
hi=mean + (TINV (0.975 , n-1) * stderr);
RUN;
title 'method two: use proc summary - this is the correct one';
proc print data=xxtmp_2;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for pointing out the mistake in the paper. Now I don't feel confused any more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The reply is strictly speaking still incorrect in the code , as you state your going to use proc summary, but in fact you've repeated proc means twice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Suki99 wrote:
The reply is strictly speaking still incorrect in the code , as you state your going to use proc summary, but in fact you've repeated proc means twice.
PROC MEANS and SUMMARY are interchangeable in this context.