BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
comeon2012
Fluorite | Level 6

I want to obtain the coefficients, T value, R square, intercept, and residual for EACH OBS through regression and then output/outest the result into a new dataset.

For example, there are 10 obs in a sample and there are 2 independent variables (X1 and X2). I want to generate a dataset like below:


obs

1     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

2     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

3     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

4     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

5     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

6     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

7     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

8    coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

9     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual

10     coefficient of X1   coefficient of X2    intercept    T value   Adj R square    residual



Please be noted what I want is not the set of parameter estimates, t value, adjusted R square etc for the WHOLE sample.


What I know is to obtain the residual for each obs (through below code) and output into a new dataset, but how to write the code for obtaining the other iterms? Thank you.


proc reg data=dataset;

  model y = x1 x2;

  output out=dataset_reg

             r=residual;

run;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

No, Maybe it is just a question of vocabulary but in my mind, a statistical model is a way to summarize and sometimes understand a phenomenon underlying data with a smaller amount of information. I don't understand the purpose of getting one model per data point, as you seem to want.

PG

PG

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

I don't know about the concept of observation r-square, but for the rest, you could do:

proc reg data=sashelp.class outest=oe;

model weight = height age;

output out=op predicted=predicted residual=residual student=tValue;

run;

quit;

proc sql;

create table want as

select op.*,

  oe.height*op.height as heightCoef,

  oe.age*op.age as ageCoef,

  oe.intercept

from oe, op;

select * from want;

quit;

PG

PG
comeon2012
Fluorite | Level 6

Hi PG,

Thank you for your help. It goes well but the intercept keeps the same for all obs. Is it possible to get the intercept for EACH obs?

Thanks.

PGStats
Opal | Level 21

No, Maybe it is just a question of vocabulary but in my mind, a statistical model is a way to summarize and sometimes understand a phenomenon underlying data with a smaller amount of information. I don't understand the purpose of getting one model per data point, as you seem to want.

PG

PG
comeon2012
Fluorite | Level 6

I double checked the paper I followed and realised that I misunderstood its methodology.

Yes, my question doesn't make sense. Thank you anyways.

Reeza
Super User

Your question doesn't make sense.

That would mean a regression model for each observation, which isn't statistically valid.

Or are you looking for the values of X1, X2 instead of the coefficients?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 3648 views
  • 5 likes
  • 3 in conversation