Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [RSq] = RSquared(ymodel, ydata)
- %Calculate the coefficient of determination (R^2) between a set of real and
- %modelled vaues
- %Arguments:
- %IN:
- %ymodel - array of corresponding modelled values.
- %ydata - array of real data values of the dependant variable
- %OUT:
- %RSq - calculated coefficient of determination
- %Load chain age data
- ChainAges = load('-NAME OF FILE-') ;
- xdata = (ChainAges(: ,1)) ;
- ydata = (ChainAges(: ,2)) ;
- PC = polyfit(xdata, ydata, 1) ;
- Gradient = PC(1) ;
- Intercept = PC(2) ;
- %
- s = 0 ;
- for a = 1:length(ydata)
- s = s + ydata(a);
- end
- ymean = s/length(ydata) ;
- %
- ymodel = (Gradient*xdata) + Intercept ;
- for b = 1:length(ydata)
- SSerrArray(b) = ((ymodel(b) - ydata(b))^2) ;
- end
- SSerrArray1 = SSerrArray(b) ;
- SSerr = 0 ;
- for b = 1:length(ydata)
- SSerr = SSerr + SSerrArray1 ;
- end
- %
- for c = 1:length(ydata)
- SStotArray(c) = ((ydata(c) - ymean)^2) ;
- end
- SStotArray1 = SStotArray(c) ;
- SStot = 0 ;
- for d = 1:length(ydata)
- SStot = SStot + SStotArray1 ;
- end
- %
- RSq = 1 - (SSerr/SStot) ;
- display(RSq)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement