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;
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
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
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.
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
I double checked the paper I followed and realised that I misunderstood its methodology.
Yes, my question doesn't make sense. Thank you anyways.
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.