BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

Using this code snippet:

 

PROC GLMSELECT DATA = WORK.Training TESTDATA = WORK.Test;
MODEL
.... / selection=none stb showpvalues;
ods output
"Fit Statistics" = WORK.Model_Fit
"Parameter Estimates" = WORK.ParameterEstimates
Nobs = WORK.Nobs;
RUN;

 

The dataset WORK.Model_Fit contains:

 

Root MSE
Dependent Mean
R-Square
Adj R-Sq
AIC
AICC
SBC
ASE (Train)
ASE (Test)

 

Is the R-Square measured on the training dataset? Is it possible to obatin the R-Square fro the training and test dataset?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Here is an example:

 

/* Split a dataset into training and test subsets */
data splitClass;
set sashelp.class;
if mod(_n_, 3) > 0 then role = "training";
else role = "test";
run;

proc glmselect data=splitclass;
class sex;
model weight = sex height / selection=none;
partition rolevar=role(test="test" train="training");
output out=outClass residual=resWeight;
run;


proc sql noprint;
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_training trimmed
from outClass where role="training";
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_test trimmed
from outClass where role="test";
quit;

%put &=r2_training &=r2_test;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

One option is to calculate R square yourself from the residuals as 1 - USS(resid)/CSS(dependent) for each data subset.

PG
Ksharp
Super User
You can use SCORE or CODE statement to score new dataset and calculated R-square.
OR
proc glmselect;
model.........
run;

proc reg.......
model y=&_GLSIND ;
........

to get that R-square.

csetzkorn
Lapis Lazuli | Level 10
Thanks, sorry this does not make much sense. I am able to use proc plm. I could use this to potentially calculate the r-square against the test dataset myself. The final aim is to put it into a macro variable.
PGStats
Opal | Level 21

Here is an example:

 

/* Split a dataset into training and test subsets */
data splitClass;
set sashelp.class;
if mod(_n_, 3) > 0 then role = "training";
else role = "test";
run;

proc glmselect data=splitclass;
class sex;
model weight = sex height / selection=none;
partition rolevar=role(test="test" train="training");
output out=outClass residual=resWeight;
run;


proc sql noprint;
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_training trimmed
from outClass where role="training";
select 1 - uss(resWeight)/css(weight) as rsquare format=7.4
into :r2_test trimmed
from outClass where role="test";
quit;

%put &=r2_training &=r2_test;
PG

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
  • 4 replies
  • 2680 views
  • 1 like
  • 3 in conversation