<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: sas code for getting the R^2 transformation linear model in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/597121#M172016</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295444"&gt;@lei2004&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree that the formula for R&lt;FONT size="1 2 3 4 5 6 7"&gt;1&lt;/FONT&gt;² in the article is a bit confusing, but (without having access to the original source by Kvålseth) I think you just need to insert the y&lt;FONT size="1 2 3 4 5 6 7"&gt;i&lt;/FONT&gt;, their mean and &lt;EM&gt;the back-transformed predicted values&lt;/EM&gt; (EDIT: that is: exp("(log y&lt;FONT size="1 2 3 4 5 6 7"&gt;i&lt;/FONT&gt;) hat")).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking the first of the two numeric examples from section 3 of the article:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
log_y=log(y);
cards;
0 .5
1 4
2 6
3 7
16 12
20 22
;

proc summary data=have;
var y;
output out=stats css=css;
run;

proc reg data=have;
model log_y=x;
output out=pred p=log_y_hat;
quit;

data want(keep=sse css rsq);
if _n_=1 then set stats;
set pred end=last;
sse+(y-exp(log_y_hat))**2;
if last;
rsq=1-sse/css;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  css        sse        rsq

287.208    34.9594    0.87828&lt;/PRE&gt;
&lt;P&gt;(matching the authors' result 0.88)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second example I got rsq=-0.31642, again matching the (corrected) value in the article (up to a minor rounding issue).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Equivalently, you could obtain CSS from PROC REG (see ODS table ANOVA for &lt;FONT face="courier new,courier"&gt;model y=x&lt;/FONT&gt;, which could be included in the existing PROC REG step as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;model log_y y=x&lt;/FONT&gt;) instead of PROC SUMMARY.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Oct 2019 22:04:40 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2019-10-16T22:04:40Z</dc:date>
    <item>
      <title>sas code for getting the R^2 transformation linear model</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/596931#M171951</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a question about how to get the R^2 by transformed linear model? This R^2 should be under the base model and original scale. the model is log(y)=b0+bi*x+e. The R^2 needed is the model transformed back to the y=exp(b0+b1*x). I am confused how to get the R^2 by the model&amp;nbsp;y=exp(b0+b1*x+e)? Is there anyone can help to figure out the code? Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attachment about this topic.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 14:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/596931#M171951</guid>
      <dc:creator>lei2004</dc:creator>
      <dc:date>2019-10-16T14:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: sas code for getting the R^2 transformation linear model</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/597050#M172001</link>
      <description>&lt;P&gt;If you are using a linear regression to fit the transformed model log(y)=b0+bi*x, with bo and bi optimized to maximize R-square, then what do you actually mean by r-square for the "original" model Y=exp(b0+bi*x)? &amp;nbsp; In the estimated model, R-square is a proportional-reduction-in-error where model error is the sum of squared(actual-estimate)&amp;nbsp; = sum of squared(log(y)-estimate(log(y))) but I don't see how one could transform that to get a similarly-defined proportional-reduction-in-error in the original scale.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess you could get a correlation of the observed Y and the estimated exp(b0+bi*x), and I imagine there is a way to get an R2 from that.&amp;nbsp; I just don't know what it would mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 19:22:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/597050#M172001</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-16T19:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: sas code for getting the R^2 transformation linear model</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/597121#M172016</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295444"&gt;@lei2004&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree that the formula for R&lt;FONT size="1 2 3 4 5 6 7"&gt;1&lt;/FONT&gt;² in the article is a bit confusing, but (without having access to the original source by Kvålseth) I think you just need to insert the y&lt;FONT size="1 2 3 4 5 6 7"&gt;i&lt;/FONT&gt;, their mean and &lt;EM&gt;the back-transformed predicted values&lt;/EM&gt; (EDIT: that is: exp("(log y&lt;FONT size="1 2 3 4 5 6 7"&gt;i&lt;/FONT&gt;) hat")).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking the first of the two numeric examples from section 3 of the article:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y;
log_y=log(y);
cards;
0 .5
1 4
2 6
3 7
16 12
20 22
;

proc summary data=have;
var y;
output out=stats css=css;
run;

proc reg data=have;
model log_y=x;
output out=pred p=log_y_hat;
quit;

data want(keep=sse css rsq);
if _n_=1 then set stats;
set pred end=last;
sse+(y-exp(log_y_hat))**2;
if last;
rsq=1-sse/css;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;  css        sse        rsq

287.208    34.9594    0.87828&lt;/PRE&gt;
&lt;P&gt;(matching the authors' result 0.88)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the second example I got rsq=-0.31642, again matching the (corrected) value in the article (up to a minor rounding issue).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Equivalently, you could obtain CSS from PROC REG (see ODS table ANOVA for &lt;FONT face="courier new,courier"&gt;model y=x&lt;/FONT&gt;, which could be included in the existing PROC REG step as&amp;nbsp;&lt;FONT face="courier new,courier"&gt;model log_y y=x&lt;/FONT&gt;) instead of PROC SUMMARY.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 22:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sas-code-for-getting-the-R-2-transformation-linear-model/m-p/597121#M172016</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-16T22:04:40Z</dc:date>
    </item>
  </channel>
</rss>

