Corrcoef and R^2 definition give different R^2 values

5 ビュー (過去 30 日間)
Rui
Rui 2012 年 10 月 26 日
Hi everyone,
I am trying to calculate R^2 value for my data and simulation. I used two different ways.
First one,
C = corrcoef(ydata,simulation);
rsq1 = C(1,2).^2;
Second one,
rsq2 = 1 - norm(ydata-simulation)^2 / norm(ydata-mean(ydata))^2;
They should be the same, but actually, the second one is smaller than the first one. Could anyone tell me what is a possible reason for that? Thanks a lot!
Rui

回答 (2 件)

Chris A
Chris A 2012 年 10 月 26 日
編集済み: Chris A 2012 年 10 月 26 日
Try the following code:
a=rand(100,1);
c=10*a;
corrcoef(a,c); % This should be the matrix [1 1; 1 1]
% Why should this number be equal to 1.
rsq2 = 1 - norm(a-c)^2 / norm(a-mean(c))^2; % rsq2 is not 1

Tom Lane
Tom Lane 2012 年 10 月 27 日
I would expect your formula to work if simulation is a set of predicted values from fitting ydata using least squares as a function of a set of predictors, including a constant term. Otherwise maybe not.

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by