Programming the statistical procedures from SAS

Effectplot with Backtransformed Variable

Reply
Occasional Contributor
Posts: 15

Effectplot with Backtransformed Variable

Is there an easy way to use the Effectplot statement to plot predictor by explanatory variable but using the back-transformed explanatory variable?

 

For example, my x variable might be log(area) and I want to plot using area.

 

A typical statement I use: effectplot fit (x=logarea ) / clm ilink;

 

I know how to do this using estimate statements but it is a lot of work.

 

Thanks!

Super User
Posts: 23,724

Re: Effectplot with Backtransformed Variable

[ Edited ]

One other option is to capture the data for the effect plot, change it and use SGPLOT to graph it. But that’s probably as much work as your other options. 

 


Sascoder wrote:

Is there an easy way to use the Effectplot statement to plot predictor by explanatory variable but using the back-transformed explanatory variable?

 

For example, my x variable might be log(area) and I want to plot using area.

 

A typical statement I use: effectplot fit (x=logarea ) / clm ilink;

 

I know how to do this using estimate statements but it is a lot of work.

 

Thanks!


 

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

How do you capture the data for the effect plot?  If the dataset has the range of values of the explanatory value for the x-axis along with the predicted value (y) that would get me 90% there. 

 

Thanks!

 

Super User
Posts: 23,724

Re: Effectplot with Backtransformed Variable

https://blogs.sas.com/content/iml/2017/01/09/ods-output-any-statistic.html

 

This blog post explains how to get the data. 

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

Thanks much for helping here.

I have not been able to find the ods table name for the effectplot statement or syntax for how to get the data used in the effectplot.

 

I found this:

http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_plm_details0...

"Each of the EFFECTPLOT, ESTIMATE, LSMEANS, LSMESTIMATE, and SLICE statements also creates tables, which are not listed in Table 87.12. For information about these tables, see the corresponding sections of Chapter 19: Shared Concepts and Topics."

 

But in the link it directs to, I cannot find any mention of the tables.  It does mention the ods graphics names, but not for the background data.

 

Do you have any knowledge on this?

 

Thanks once again!  If I figure this out, it will be a huge time-saver in many ways!

 

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

For example, I tried:

 

effectplot fit (x=logarea ) / clm ilink ;

ods output effectplot=tst;

 

and

effectplot fit (x=logarea ) / clm ilink out=tst;

 

Neither of these worked.

 

Thanks!

SAS Super FREQ
Posts: 4,241

Re: Effectplot with Backtransformed Variable

The link that Reeza supplied has directions and an example. Modifying it to your syntax gives:

 

ods trace on;
proc genmod data=sashelp.class;
class sex;
model weight = height sex / dist=normal;
effectplot fit (x=height ) / clm ilink;
run;

Output Added:
-------------
Name: FitPlot
Label: Fit Plot 1
Template: Stat.Genmod.Graphics.FitPlot
Path: Genmod.EffectPlots.FitPlot

 

Therefore you should use

ods output FitPlot=tst;

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

Thanks very much!  This is great.

One more question just to make sure there isn't an easier way.

I run effectplots for multiple variables in a model.  Is there an easy way to get SAS to assign the variable name to each observation?  Looks like SAS concatenates the data for each variable but with no identifier for the specific variables.

 

I can use the macro below to accomplish what I need, but it would be more convenient to load all the data for a model into one dataset and then do the plots.  Based on my experience with other ods tables, I am guessing there is not a way, but I figure it doesn't hurt to ask.

 

And my apologies, I looked all over the web link from Reeza and learned lots of things I didn't know, but did not find much explanation about this.

 

Thanks again!!!

 

proc genmod data=sashelp.class;
  class sex;
  model weight = height age / dist=normal;
  store rslts;
run;

%macro effplt(vr);
 ods graphics / imagename="plt_&vr";
 *ods trace on;
 ods output FitPlot=tst&vr;
 proc plm restore=rslts;
   effectplot fit (x=&vr ) / clm ilink;
 run;

 proc sgplot data = tst&vr noautolegend ;
   series y=_predicted x=_xcont1 / ;
   series y=_lclm x=_xcont1 / ;
   series y=_uclm x=_xcont1 / ;
   yaxis label= "&vr";
 run;
%mend;

%effplt(height);
%effplt(age);

 

 

SAS Super FREQ
Posts: 4,241

Re: Effectplot with Backtransformed Variable

 I'm not sure what you are asking. Are you saying you want a new column called VAR that contains the name of the variable that was used to create the analysis?   If so, use the following.  I have also modified the SGPLOT statement to use the BAND statement to show the upper/lower CLs, in case that appeals to you:

 


%macro effplt(vr);
 ods graphics / imagename="plt_&vr";
 *ods trace on;
 ods output FitPlot=tst&vr;
 proc plm restore=rslts;
   effectplot fit (x=&vr ) / clm ilink;
 run;

 data tst&vr;  /* add name of variable */
    set tst&vr;
    Var = "&vr";
 run;

 proc sgplot data = tst&vr noautolegend ;
   band x=_xcont1 lower=_lclm upper=_uclm;
   series y=_predicted x=_xcont1;
   yaxis label= "&vr";
 run;
%mend;

This looks like you are preparing to create many one-variable regressions. If so, there is a more efficient way to run many regressions.

"An easy way to run thousands of regressions in SAS"

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

Apologies, I should have been clearer

What I have been doing is running all effectplots in one PLM run (or straight from genmod), but this doesn't allow me to backtransform logged variables or unstandardize or adjust variables for plotting.

 


proc genmod data=sashelp.class;
  class sex;
  model weight = height age / dist=normal;
  store rslts;
run;

proc plm restore=rslts;
   effectplot fit (x=height ) / clm ilink;

   effectplot fit (x=age ) / clm ilink;
run;

 

If I add the ods output =

Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

Looks like my reply didn't fully get thru so second try here...

 

What I have been doing is running all effectplots in one PLM run (or straight from genmod or glimmix with plm), but this doesn't allow me to backtransform logged variables or unstandardize or adjust variables for plotting.

 


proc genmod data=sashelp.class;
  class sex;
  model weight = logheight age / dist=normal;
  store rslts;
run;

proc plm restore=rslts;
   effectplot fit (x=logheight ) / clm ilink;

   effectplot fit (x=age ) / clm ilink;
run;

 

If I add the   ods output =st statement

I get one dataset with 400 rows with no information on which data is for height and which is for age.  I had added a datastep like yours to my macro where I do the variable transformation, but it requires separate calls for each variable (not a huge big deal but more code-tracking).

 

Your macro modification that concatenates data to tst and labels each row would definitely work but I was wondering if there was a statement added to the effectsplot or ods output statement that would do the same thing.

 

Just getting the plot data into a dataset is a huge help!

 

Thanks again for your help!

 

 

 

 

SAS Super FREQ
Posts: 4,241

Re: Effectplot with Backtransformed Variable

Each FitPlot contains 200 observations, so create an ID variable whose value represents var 1, var 2, etc.  If necessary, use PROC FORMAT to define a custom format that replaces 1,2,3,... with "var 1", "var 2", "var 3", etc.

 


/* create an ID variable using the fact that each data set has 200 obs */
%let NobsInPlot = 200;
data Want;
set FP;
ID = ceil(_N_ / &NobsInPlot);
run;
Occasional Contributor
Posts: 15

Re: Effectplot with Backtransformed Variable

Yeah, That would work, as long as SAS concatenates the data in a consistent predictable way.  I'll try it out.

Thanks very much for your help!

Ask a Question
Discussion stats
  • 12 replies
  • 237 views
  • 2 likes
  • 3 in conversation