LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (November 2004, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 24 Nov 2004 00:38:04 -0500
Reply-To:     "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Chang Y. Chung" <chang_y_chung@HOTMAIL.COM>
Subject:      Re: Calculation of weighted std error of mean
Comments: To: Tim Churches <tchur@OPTUSHOME.COM.AU>

On Wed, 24 Nov 2004 04:32:52 +1100, Tim Churches <tchur@OPTUSHOME.COM.AU> wrote:

>I am having some difficulties reproducing the results calculated by PROC >MEANS for a weighted std error of the mean. I am using the formula >provided in the SAS documentation (see >http://jeff-lab.queensu.ca/stat/sas/sasman/sashtml/proc/zormulas.htm ) >but it is not clear (to me at least) how teh std deviation is being >calculated in the weighted case. > >Can someone cast light on this?

Hi, Tim,

It seems to work for me. First time I did this, I mis-calculated the mean. But the online doc seems to be correct. If you have missing values, then you may want to double check the definition of even the very simple stats like n.

Cheers, Chang

data one; do x = 1 to 5; w = 1 + (x <= 2); output; end; run; proc print data=one; run; /* on lst Obs x w 1 1 2 2 2 2 3 3 1 4 4 1 5 5 1 */ proc means data=one print stdErr; var x; weight w; run; /* on lst The MEANS Procedure

Analysis Variable : x

Std Error ------------ 0.6998542 ------------ */

/* replication */ data _null_;

array x[1:5] x1-x5 (1,2,3,4,5); array w[1:5] w1-w5 (2,2,1,1,1);

d = 5-1; /* variance divisor */

sum_w = 0; sum_wx = 0; do i = 1 to 5; sum_wx + (w[i] * x[i]); sum_w + (w[i]); end; x_bar = sum_wx / sum_w; /* mean */

dev_sq = 0; do i = 1 to 5; dev_sq + (w[i] * (x[i] - x_bar)**2); end; s_sq = (1/d) * dev_sq; /* variance */ s = sqrt(s_sq); /* standard deviation */

stdErr = s / sqrt(sum(of w1-w5)); /* std error */

put stdErr=;

run; /* on log stdErr=0.6998542122 */


Back to: Top of message | Previous page | Main SAS-L page