rsquared

バージョン 1.0.0.0 (2.05 KB) 作成者: R P
calculate standard and adjusted R-squared (coefficient of determination)
ダウンロード: 819
更新 2016/12/5

ライセンスの表示

rsquared calculates the coefficient of determination (r2) from the original
data (ydata) and fited data (yestimation). It also calculates the adjusted
coefficient (r2adj) considering the number of parameters of the model
(nparam).

Syntax:
r2 = rsquared(ydata,yestimation)
[r2,r2adj]=rsquared(ydata,yestimation,nparam)

Example:
xdata = [1 5 14 23 25 48 49 59 73 77 99 ];
ydata = [-100 70 100 450 550 2200 2300 3400 5300 5906 9600];
plot(xdata,ydata,'ok'), hold on
param_1 = polyfit(xdata,ydata,1);
yestimation_1 = polyval(param_1,xdata);
[r2_1,r2adj_1]=rsquared(ydata,yestimation_1,length(param_1))
plot(xdata,yestimation_1,'-r')
param_2 = polyfit(xdata,ydata,2);
yestimation_2 = polyval(param_2,xdata);
plot(xdata,yestimation_2,'-b')
[r2_2,r2adj_2]=rsquared(ydata,yestimation_2,length(param_2))
legend({'data',['r2=' num2str(r2_1) ', r2adj=' ...
num2str(r2adj_1)],['r2=' num2str(r2_2) ', r2adj=' num2str(r2adj_2)]}, ...
'Location','best')

Equations
SSres=sum( (ydata-yestimation).^2 ); % residual sum of squares
SStot=sum( (ydata-mean(ydata)).^2 ); % total sum of squares
r2=1-SSres/SStot; % standard rsquared
r2adj = 1 - SSres/SStot * (length(ydata)-1)/(length(ydata)-nparam); % adjust for the number of parameters

Check https://en.wikipedia.org/wiki/Coefficient_of_determination

引用

R P (2024). rsquared (https://www.mathworks.com/matlabcentral/fileexchange/60577-rsquared), MATLAB Central File Exchange. に取得済み.

MATLAB リリースの互換性
作成: R2016a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersFile Operations についてさらに検索
タグ タグを追加

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
バージョン 公開済み リリース ノート
1.0.0.0

help update