<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello:<div><br></div><div>I just wanted to correct something that's in the record.</div><div><br></div><div>I may have copied something incorrectly, but when I used the equations for calculating r sent previously in this e-mail chain, I did not get the right answer.  Perhaps that is the reason or there is something else that's changed that I am unaware of. </div><div><br></div><div>I found instead what I've copied below from</div><div><br></div><div><a href="https://www.mathsisfun.com/data/correlation.html">https://www.mathsisfun.com/data/correlation.html</a><br></div><div><br></div><div>However, you can find in the ncl library a function to calculate r as well (and I think it may be part of the new regline).</div><div><br></div><div><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/escorc.shtml">https://www.ncl.ucar.edu/Document/Functions/Built-in/escorc.shtml</a><br></div><div><br></div><div>Here's the calculation of r following the page above, translating into ncl language.</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>ave_x= avg(x)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>ave_y= avg(y)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>a =<span class="gmail-Apple-converted-space">  </span>x-ave_x</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>b =<span class="gmail-Apple-converted-space">  </span>y-ave_y</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>ab = a*b</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>a2 = a*a</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>b2 = b*b</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>sum_ab = sum(ab)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>sum_a2 = sum(a2)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>sum_b2 = sum(b2)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>r= sum_ab/(sqrt(sum_a2*sum_b2))</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:21px;line-height:normal;font-family:"Courier New";color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>print("r = " + r)</span></p></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 3, 2017 at 5:10 PM Barry Lynn <<a href="mailto:barry.h.lynn@gmail.com">barry.h.lynn@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi:<div><br></div><div>I didn't see that this function has been updated to calculate the coefficient of determination (r).</div><div><br></div><div>I did see this e-mail and one after (e.g.: <a href="https://www.ncl.ucar.edu/Support/talk_archives/2009/2202.html" target="_blank">https://www.ncl.ucar.edu/Support/talk_archives/2009/2202.html</a></div><div><br></div><div>but this (below) may be more useful for users wanting the simplest approach to calculating statistics for a line.</div><div><br></div><div>







<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">begin</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">x = (/1,2,3,4,5,6,7,8,9,10/)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">y = (/0.6,1.6,1.2,2.2,2.3,3.1,2.8,4.1,4.7,3.3/)</span></p>
<p class="m_3203725027505853930gmail-p2"><span class="m_3203725027505853930gmail-s1"></span><br></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">rc = regline(x,y)  ; function as is.</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">print("rc = " + rc)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">printVarSummary(rc)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>sum_xy = sum(x*y)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>sum_x = sum(x)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>sum_x2 = sum(x^2)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>sum_y = sum(y)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>sum_y2 = sum(y^2)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>n = dimsi</span><span class="m_3203725027505853930gmail-s2">z</span><span class="m_3203725027505853930gmail-s1">es(x)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>r_n = n*sum_xy - sum_x*sum_y</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>r_d =(n*sum_x2<span class="m_3203725027505853930gmail-Apple-converted-space">  </span>- (sum_x)^2)*(n*sum_y2<span class="m_3203725027505853930gmail-Apple-converted-space">  </span>- (sum_y)^2)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>r = r_n/sqrt(r_d)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>print(r)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>r2 = r^2</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><span class="m_3203725027505853930gmail-Apple-converted-space">    </span>print(r2)</span></p>
<p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">end</span></p><p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1">Answer r = 0.9075 and r2 = 0.82364.</span></p><p class="m_3203725027505853930gmail-p1"><span class="m_3203725027505853930gmail-s1"><br></span></p><div><br></div>-- <br><div class="m_3203725027505853930gmail_signature"><div dir="ltr">Barry H. Lynn, Ph.D<div><div>Senior Lecturer,</div><div><div><span style="color:rgb(136,136,136)">The Institute of the Earth Science, </span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">The Hebrew University of Jerusalem, </span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">Givat Ram, Jerusalem 91904, Israel </span><br style="color:rgb(136,136,136)"></div><span style="color:rgb(136,136,136)">Tel: 972 547 231 170</span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">Fax: (972)-25662581</span></div></div><div><span style="color:rgb(136,136,136)"><br></span></div><div>C.E.O, Weather It Is, LTD<br>Weather and Climate Focus<br><a href="http://weather-it-is.com" target="_blank">http://weather-it-is.com</a><br>Jerusalem, Israel<br>Local: 02 930 9525<br>Cell: 054 7 231 170<br>Int-IS: x972 2 930 9525<br>US 914 432 3108<br></div></div></div>
</div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr">Barry H. Lynn, Ph.D<div><div>Senior Associate Scientist, Lecturer,</div><div><div><span style="color:rgb(136,136,136)">The Institute of the Earth Science, </span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">The Hebrew University of Jerusalem, </span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">Givat Ram, Jerusalem 91904, Israel </span><br style="color:rgb(136,136,136)"></div><span style="color:rgb(136,136,136)">Tel: 972 547 231 170</span><br style="color:rgb(136,136,136)"><span style="color:rgb(136,136,136)">Fax: (972)-25662581</span></div></div><div><span style="color:rgb(136,136,136)"><br></span></div><div>C.E.O, Weather It Is, LTD<br>Weather and Climate Focus<br><a href="http://weather-it-is.com" target="_blank">http://weather-it-is.com</a><br>Jerusalem, Israel<br>Local: 02 930 9525<br>Cell: 054 7 231 170<br>Int-IS: x972 2 930 9525<br><br></div></div></div></div></div></div>