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

Hello Si,

Here I did with hand:

adj. R^2 = 1-[(1-0.97)(16-1)(16-2-1)^-1]=0.965 0.96.


But for me it is not possible to do each time with hand. I must find the programming that can estimate the adjusted r2 along with others parameters. Surely, I will learn the SAS programming and will join your suggested group but right now I need the solution of my this problem. Please edit my program as I must find the adjusted r2 value as soon as possible (I have to submit my work by morning.)

Reeza
Super User

Not a sir. I only suggested the by hand calculation to ensure that your program works. Did you modify the program as I suggested? If so post that code that still doesn't work. Even so, that code is hard coded to the N and P in the model assumed which isn't what you may want.

afgdurrani0
Pyrite | Level 9

I did like this and I think it works correctly now.

output out=expp p=pstw r=stw_residual;

run;

proc summary data=expp;

     var stw_residual stw;

     output out=stats css(stw)=sstot uss(stw_residual)=ssres;

run;

data expp;

     set stats;

     rsquared=1-(ssres/sstot);

     adjrsquared = 1-(1-rsquared)*(90-1)*(90-4-1)**-1;

run;

proc print data=expp;

run;

But a big problem that I have is that every time it is not possible for me to enter the observations number and parameters number, how it is possible to automatically adjust this too. And also check the formula that I did correctly or not, but it generated adjusted r2 along with simple r2.

Reeza
Super User

Did that number match the hand calculated adjusted R-Squared?

Easiest solution is to create macro variables that hold N and the number of parameters, P.

afgdurrani0
Pyrite | Level 9

Dear  Reeza,

I don't have that much good knowledge of these programming. Please you make all these changes, later on I will learn from the source you identify me but right now I need a modify programming that can estimate adjusted r2 quickly. You please make all the desired changes in this programming. 

Rick_SAS
SAS Super FREQ

The Support Communities will be offline for a week for upgrade/maintanence, so here's your answer. It looks like there are p=2 parameters in this model. If you have other models with a different number of parameters, you'll have to change the last statement in the following DATA step:

proc summary data=largep;

     var stw_residual stw;

     output out=stats css(stw)=sstot uss(stw_residual)=ssres N=N;

run;

data expp;

     set stats;

     rsquared=1-(ssres/sstot);

     adjrsquared = 1-(1-rsquared)*(N-1) / (N- 2  -1);       /* ... / (N-p-1) */

run;

proc print data=expp;

run;

Good luck with your analysis.  When you put as much effort into learning to program as you put into trying to get others to write the program, you will become an awesome programmer. I look forward to seeing your SAS skills advance.

afgdurrani0
Pyrite | Level 9

Thanks it works nice. But sir the only problem is that I cant write p number each time manually as I have some programming where I have parameters number different like in some the parameters are 2 while in another the p number is 4.

It will make me confused to write p number each time.  So the last modification I want is automatically fitting p vale just like N value.

SAS is really awesome and in our all research papers we write that the analysis of data were done by SAS. I will learn more about programming. 

Need the answer of my this question before the system starts unavailable,  please.

Reeza
Super User

I take paypal :smileycool:

This is semi-dynamic but you would have to change the dataset name in the SQL code as required.

Good luck with your SAS programming.

 

 

data large;

input sow stw time;

datalines;

4 3.366 3

4 3.052 6

4 2.666 9

4 2.755 12

4 2.203 15

4 1.886 18

3.982 1.525 21

3.882 1.547 24

3.393 0.81 27

3.586 0.76 30

2.295 0.27 33

3.475 0.67 36

;

ods table parameterestimates=pe;

proc nlin data=large method=marquardt;

parms B=0.5 R=0.1;

delta=0.000001;

 

 

s=sow**(1-B)-R*(1-B)*time;

if s>0 then stx=s**(1/(1-B));

else stx=0;

 

 

model stw=stx;

 

 

sb=(sow**(1-B+delta)-R*(1-B+delta)*time);

if sb>0 then sdb=(stx-sb**(1/(1-B+delta)))/delta;

else sdb=0;

der.B=sdb;

 

 

sr=(sow**(1-B)-(R-delta)*(1-B)*time);

if sr>0 then sdr=(stx-sr**(1/(1-B)))/delta;

else sdr=0;

der.R=sdr;

 

output out=largep p=pstw r=stw_residual;

run;

 

 

proc sql noprint;

select count(*) into :np from pe;

select count(*) into :n from large;

quit;

 

 

%put Number of Parameters: &np;

%put Number of Observations: &n;

 

proc summary data=largep;

     var stw_residual stw;

     output out=stats css(stw)=sstot uss(stw_residual)=ssres;

run;

data final;

     set stats;

     rsquared=1-(ssres/sstot);

     adjrsquared = 1-(1-rsquared)*(&n-1) / (&n- &np -1);

run;

afgdurrani0
Pyrite | Level 9

Many thanks to sir Rick and dearest Reeza for helping me in modifying my model. It works perfectly and I just need to write the parameter number nothing else. Dearest Reeza special thanks to you Smiley Happy

Reeza
Super User

The last post had the parameters incorrectly specified in the last formula.

 

This was because the forum automatically converting code to emoticons and my sloppy attempt to correct from it. I've edited the code above to be the correct version now. 

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
  • 39 replies
  • 3852 views
  • 20 likes
  • 4 in conversation