R-square: The coefficient of determination

버전 1.4.0.0 (2.11 KB) 작성자: Jered Wells
RSQUARE is a simple routine for computing R-square (coefficient of determination).
다운로드 수: 13.9K
업데이트 날짜: 2012/2/14

라이선스 보기

Compute coefficient of determination of data fit model and RMSE

[r2 rmse] = rsquare(y,f)
[r2 rmse] = rsquare(y,f,c)

RSQUARE computes the coefficient of determination (R-square) value from
actual data Y and model data F. The code uses a general version of
R-square, based on comparing the variability of the estimation errors
with the variability of the original values. RSQUARE also outputs the
root mean squared error (RMSE) for the user's convenience.

Note: RSQUARE ignores comparisons involving NaN values.

INPUTS
Y : Actual data
F : Model fit

OPTION
C : Constant term in model
R-square may be a questionable measure of fit when no
constant term is included in the model.
[DEFAULT] TRUE : Use traditional R-square computation
FALSE : Uses alternate R-square computation for model
without constant term [R2 = 1 - NORM(Y-F)/NORM(Y)]

OUTPUT
R2 : Coefficient of determination
RMSE : Root mean squared error

EXAMPLE
x = 0:0.1:10;
y = 2.*x + 1 + randn(size(x));
p = polyfit(x,y,1);
f = polyval(p,x);
[r2 rmse] = rsquare(y,f);
figure; plot(x,y,'b-');
hold on; plot(x,f,'r-');
title(strcat(['R2 = ' num2str(r2) '; RMSE = ' num2str(rmse)]))

Jered R Wells
11/17/11
jered [dot] wells [at] duke [dot] edu

v1.2 (02/14/2012)

Thanks to John D'Errico for useful comments and insight which has helped
to improve this code. His code POLYFITN was consulted in the inclusion of
the C-option (REF. File ID: #34765).

인용 양식

Jered Wells (2024). R-square: The coefficient of determination (https://www.mathworks.com/matlabcentral/fileexchange/34492-r-square-the-coefficient-of-determination), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2008b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.4.0.0

Added NaN protection
Included option, warning, and code for models without constant term
Added better error-checking
Added RMSE computation for convenience
Included H1 line

1.2.0.0

Edited help file and added example

1.1.0.0

Cleaned up description

1.0.0.0