BookmarkSubscribeRSS Feed
iank131
Quartz | Level 8

Hi,

In SAS 9.2 Help, there is an example entitled "Weighted Statistics Example" that uses the Proc Means Weight option. I am trying to understand how the variances in the example are calculated by doing it manually in EXCEL, but I cannot work out how SAS calculates it. Referring to the code below, I am able to calculate the variance that is in Example 1, but can someone please explain to me Example 2 and 3.

My exact questions are:

1. In example 2, how do you calculate Est_SigmaSq (i.e. var)?

2. If you were to transform the variable ObjectSize in Example 2, what would it be in order to get the variance Est_SigmaSq?

3. The same two questions apply for Example 3.

Below is the code as given in SAS Help and I also attach the Excel I am using to do my manual calculations if you need it.

Thanks and Regards

Ian.

data size;

   input Distance ObjectSize @@;

   Precision=1/distance;

   datalines;

1.5 30 1.5 20 1.5 30 1.5 25

3   43 3   33 3   25 3   30

4.5 25 4.5 36 4.5 48 4.5 33

6   43 6   36 6   23 6   48

7.5 30 7.5 25 7.5 50 7.5 38

;

*EXAMPLE1;

proc means data=size maxdec=3 n mean var stddev;

   var objectsize;

   title1 'Unweighted Analysis of the SIZE Data Set';

run;

**EXAMPLE2;

proc means data=size maxdec=3 n mean var stddev;

   weight precision;

   var objectsize;

   output out=wtstats var=Est_SigmaSq std=Est_Sigma;

   title1 'Weighted Analysis Using Default VARDEF=DF';

run;

**EXAMPLE3;

proc means data=size maxdec=3 n mean var std vardef=weight;

   weight precision;

   var objectsize;

   title1 'Weighted Analysis Using VARDEF=WEIGHT';

run;

4 REPLIES 4
1zmm
Quartz | Level 8

The documentation for the WEIGHT statement in PROC MEANS.describes how the sample variance is calculated from the individual variable values and their weights, the weighted mean, and the divisor[the default value of n-1 or of the sum of the weights when VARDEF=WEIGHT].

iank131
Quartz | Level 8

1zmm, thanks for answering, but I have read the documentation that you refer to (a number of times) and it does not answer my question. That is why I am asking if someone can help me here.

Ian.

Reeza
Super User

If you want to mimic the calculation in Excel, take the weight and multiply it by the observation, precision*object_size

Then calculate STD and Variance as you would normally in excel using the weighted observations.

iank131
Quartz | Level 8

Ok. Thanks. I have been able to reproduce the results.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 6051 views
  • 0 likes
  • 3 in conversation