Programming the statistical procedures from SAS

Adjusted R^2 (adjusted R square)

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

Adjusted R^2 (adjusted R square)

R^2 is unfortunately not a part of the output from the nonlinear regression (e.g. below) in the newer versions of SAS. But I need the adjusted r2 value or simple r2 (coefficient of determination) for my research manuscript. Please kindly modify my below proc programming that could also estimate the R2.

Many thanks

proc nlin data=small 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;

  1. 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;

  1. der.R=sdr;

output out=smallp p=pstw;

run;


Accepted Solutions
Solution
‎08-27-2015 02:39 PM
Trusted Advisor
Posts: 1,418

Re: Adjusted R^2 (adjusted R square)

change the line

output out=smallp p=pstw;


to

output out=smallp p=pstw r=stw_residual;


Then, this ought to work (untested code)

proc summary data=smallp;

     var stw_residual stw;

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

run;

data final;

     set stats;

     rsquared=1-(ssres/sstot);

run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,418

Re: Adjusted R^2 (adjusted R square)

Using the residual values that your can output into your dataset smallp, the calculation of R-squared is pretty simple. Why, I believe even Wikipedia has the proper formulas to use.

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

Dearest Miller, I don't have very strong knowledge of these programming that's why I need someone expert like you to insert/modify my present programming that could also estimate the R^2.

Solution
‎08-27-2015 02:39 PM
Trusted Advisor
Posts: 1,418

Re: Adjusted R^2 (adjusted R square)

change the line

output out=smallp p=pstw;


to

output out=smallp p=pstw r=stw_residual;


Then, this ought to work (untested code)

proc summary data=smallp;

     var stw_residual stw;

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

run;

data final;

     set stats;

     rsquared=1-(ssres/sstot);

run;

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

No result for R^2 Smiley Sad . It shows nothing about R^2

Here is the complete data, please use it if you want

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;

run;

Trusted Advisor
Posts: 1,418

Re: Adjusted R^2 (adjusted R square)

Is there an error in the SAS LOG?

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

No , nothing like that. But before it use to produce R^2 along with my desired parameters but now the newer version doesn't generate the R^2. that's why I want to modify my persent programming to make it capable to produce R^2 (or AIC at least)

Trusted Advisor
Posts: 1,418

Re: Adjusted R^2 (adjusted R square)

Reading your messages, I don't see where you stated that you actually tried to run the code I provided. Did you do that? What happened?

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

Yes sir of course I did but no result. I try your both suggested but no result. You can also copy past my data in sas program and can see the result.

Many thanks

Grand Advisor
Posts: 16,874

Re: Adjusted R^2 (adjusted R square)

@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 code.

With these changes it runs fine for me with your sample data.

I'll assume you can make the changes on your system.

PS, Thank you for the sample data/code but It's helpful to include the full code you ran.

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

I added r=stw_residual in the output statement but no result about R^2. The one I give is the original form of my programming without any addition. But I modified the output statement and inserted r=stw_residual in the output as I was suggested, but result was similar as without this modification.

Grand Advisor
Posts: 16,874

Re: Adjusted R^2 (adjusted R square)

Post your full code. The code above doesn't include the portion Paige suggested.

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

Here is the 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;

Grand Advisor
Posts: 16,874

Re: Adjusted R^2 (adjusted R square)

Go back and read Paiges answer. Where's the proc summary? Proc NLIN does not calculate the R-squared directly.

change the line

output out=smallp p=pstw;


to

output out=smallp p=pstw r=stw_residual;


Then, this ought to work (untested code)

proc summary data=smallp;

     var stw_residual stw;

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

run;

data final;

     set stats;

     rsquared=1-(ssres/sstot);

run;

Contributor
Posts: 58

Re: Adjusted R^2 (adjusted R square)

I also run like that too: but same result nothing about R^2.

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 39 replies
  • 868 views
  • 20 likes
  • 4 in conversation