Advertisement
Guest User

Untitled

a guest
Mar 19th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. function [RSq] = RSquared(ymodel, ydata)
  2. %Calculate the coefficient of determination (R^2) between a set of real and
  3. %modelled vaues
  4.  
  5. %Arguments:
  6. %IN:
  7. %ymodel - array of corresponding modelled values.
  8. %ydata - array of real data values of the dependant variable
  9.  
  10. %OUT:
  11. %RSq - calculated coefficient of determination
  12.  
  13.  
  14. %Load chain age data
  15.  
  16. ChainAges = load('-NAME OF FILE-') ;
  17. xdata = (ChainAges(: ,1)) ;
  18. ydata = (ChainAges(: ,2)) ;
  19.  
  20.  
  21. PC = polyfit(xdata, ydata, 1) ;
  22. Gradient = PC(1) ;
  23. Intercept = PC(2) ;
  24.  
  25. %
  26.  
  27. s = 0 ;
  28.  
  29. for a = 1:length(ydata)
  30. s = s + ydata(a);
  31. end
  32. ymean = s/length(ydata) ;
  33.  
  34. %
  35.  
  36. ymodel = (Gradient*xdata) + Intercept ;
  37.  
  38. for b = 1:length(ydata)
  39. SSerrArray(b) = ((ymodel(b) - ydata(b))^2) ;
  40. end
  41.  
  42. SSerrArray1 = SSerrArray(b) ;
  43. SSerr = 0 ;
  44.  
  45. for b = 1:length(ydata)
  46. SSerr = SSerr + SSerrArray1 ;
  47. end
  48.  
  49. %
  50.  
  51. for c = 1:length(ydata)
  52. SStotArray(c) = ((ydata(c) - ymean)^2) ;
  53. end
  54.  
  55. SStotArray1 = SStotArray(c) ;
  56. SStot = 0 ;
  57.  
  58. for d = 1:length(ydata)
  59. SStot = SStot + SStotArray1 ;
  60. end
  61.  
  62. %
  63.  
  64. RSq = 1 - (SSerr/SStot) ;
  65.  
  66. display(RSq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement