[ncl-talk] Regarding RegLine (coefficient of determination)
Barry Lynn
barry.h.lynn at gmail.com
Tue Oct 3 08:10:53 MDT 2017
Hi:
I didn't see that this function has been updated to calculate the
coefficient of determination (r).
I did see this e-mail and one after (e.g.:
https://www.ncl.ucar.edu/Support/talk_archives/2009/2202.html
but this (below) may be more useful for users wanting the simplest approach
to calculating statistics for a line.
begin
x = (/1,2,3,4,5,6,7,8,9,10/)
y = (/0.6,1.6,1.2,2.2,2.3,3.1,2.8,4.1,4.7,3.3/)
rc = regline(x,y) ; function as is.
print("rc = " + rc)
printVarSummary(rc)
sum_xy = sum(x*y)
sum_x = sum(x)
sum_x2 = sum(x^2)
sum_y = sum(y)
sum_y2 = sum(y^2)
n = dimsizes(x)
r_n = n*sum_xy - sum_x*sum_y
r_d =(n*sum_x2 - (sum_x)^2)*(n*sum_y2 - (sum_y)^2)
r = r_n/sqrt(r_d)
print(r)
r2 = r^2
print(r2)
end
Answer r = 0.9075 and r2 = 0.82364.
--
Barry H. Lynn, Ph.D
Senior Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581
C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171003/f52a440b/attachment.html>
More information about the ncl-talk
mailing list