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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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