SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JUMMY
Obsidian | Level 7

How do I run weighted least squares on the data below using PROC REG where the weights are chosen to account for unequal variances?

 

data one;
  input X @;
  do i= 1 to 4;
   input Y @;
   output;
  end;
  drop i;
datalines;
2.5  7.5 9.5 8.0 8.5
5.0  11.0 12.0 9.0 10.0
7.5  11.0 16.0 12.5 14.0
10.0  16.5 14.5 21.5 19.0
;
run;


proc reg data=one plots=all;
  model Y=X / p r clm cli influence;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

It's fairly simple to do when you have replicates, as in your example data:

 

/* Compute variance estimates of dependent variable Y for each value of X */
proc sql;
create table three as
select *,
    1/var(y) as invVar
from one
group by x;
quit;

/* Weighted regression */
proc reg data=three plots=all;
  model Y=X / p r clm cli influence;
  weight invVar;
run;
quit;
PG

View solution in original post

4 REPLIES 4
JUMMY
Obsidian | Level 7
@PaigeMiller, what would my weight be with regard to this question? What variable do I use?
PaigeMiller
Diamond | Level 26

I think this is all explained in the documentation.

A WEIGHT statement names a variable in the input data set with values that are relative weights for a weighted least squares fit. If the weight value is proportional to the reciprocal of the variance for each observation, then the weighted estimates are the best linear unbiased estimates (BLUE).

 

Of course, for the VERY SIMPLE data set you provide, there is no such variable. You could compute the variance for each observation, and then make a new variable to use in the WEIGHT statement which is the reciprocal of the variance.

--
Paige Miller
PGStats
Opal | Level 21

It's fairly simple to do when you have replicates, as in your example data:

 

/* Compute variance estimates of dependent variable Y for each value of X */
proc sql;
create table three as
select *,
    1/var(y) as invVar
from one
group by x;
quit;

/* Weighted regression */
proc reg data=three plots=all;
  model Y=X / p r clm cli influence;
  weight invVar;
run;
quit;
PG

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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