BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Reeza
Super User

And my original answer today was Smiley Happy

@umarkhan  You didn't add the r=stw_residual to the PROC NLIN program in the output statement.

The PROC summary should point to this data set instead of the smallp dataset in Paige Miller code.

afgdurrani0
Pyrite | Level 9

Full code:

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

;

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 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);

run;

afgdurrani0
Pyrite | Level 9

Did you read my full code? There no result about R^2 still.

Reeza
Super User

UmarKhan wrote:

Did you read my full code? There no result about R^2 still.

Yes. My original answer was wrong, but you didn't implement it anyways.

Did you open the final dataset?

proc print data=final;run;

afgdurrani0
Pyrite | Level 9

It finally works Smiley Happy Many thanks to Paige Miller and Reeza. the generated R^2 is Coefficient of determination or adjusted R^2?

Reeza
Super User

should get the correct answer not me, if you're able to change that.

afgdurrani0
Pyrite | Level 9

Dear Reeza

The R^2 that is produced with this proc modification is adjusted R^2 or coefficient of determination?  Please answer.

afgdurrani0
Pyrite | Level 9

Dear Paige Miller

The R^2 that is produced with this proc is adjusted R^2 or coefficient of determination?  Please answer

Rick_SAS
SAS Super FREQ

Paige Miller sent you a link to a Wikipedia article. If you read the article, you can learn about the R-squared statistic and see that the formula is 1-(SSres/SStot).  That same article contains a section about the adjusted R-squared statistic, in the event that you want to compute that statistic as well.

afgdurrani0
Pyrite | Level 9

Dear Rick

I try but couldn't fit that formula in it.

Can you please modify it more with this for adjusted r^2. I need to write adjusted r^2 in my research paper.

I took the formula for adjusted R2  and can  be calculated as 1-[(1-R2)(n-1)(n-k-1)-1]

where n is the number of data points and k is the number of regressors (parameters in your cases)

- and you already now are able to calculate R2.

But I don't have any good knowledge of these programming, that's I need yous help in modifying the program further to produce adjusted r2.


Many thanks for the response. 

Rick_SAS
SAS Super FREQ

I feel confident that you can complete this step on your own if you give it a try. Time for you to try to learn some SAS programming! This is an easy computation, so it is a good opportunity for you to practice.

In the DATA step, right after you compute the rsquared variable, define a new variable like this:

adjrsquared = /* put formula here */;

In your formula, use the rsquared variable from the previous line, and substitute values for n and k from your problem. For example, if you have n=100 nonmissing abservations and k=2 parameters in your model, you would use 100 and 2 in the formula.

You should also know that multiplication is performed using the '*' symbol and division by using the '/' symbol. I suggest you use division instead of raising the last quantity to the -1 power.  And be sure to end each SAS statement with a semicolon.  Good luck!

afgdurrani0
Pyrite | Level 9

Si, no result Smiley Sad just errors !

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);

run;

proc print data=expp;

run;

data expp;

adjrsquared = (1-((1-rsquared)(16-2-1)/1));

run;

Reeza
Super User

Multiplication is denoted by *.

afgdurrani0
Pyrite | Level 9

No error but no result

data expp;

adjrsquared = (1-(1-rsquared*16-1**16-2-1)/1);

run;

proc print data=expp;

run;

Reeza
Super User

You didn't follow the instructions from Rick.

In the DATA step, right after you compute the rsquared variable, define a new variable like this:

adjrsquared = /* put formula here */;

Add your line In the DATA FINAL step from the working code, not a new data step.

Also, I think your formula is incorrect.

EDIT: I would calculate it by hand and then tweak the program until I generated the correct results.

Additionally, if you go to the SAS Analytics U portion of this site there are FREE training courses on programming in SAS as well as YouTube videos.

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
  • 3838 views
  • 20 likes
  • 4 in conversation