How do I calculate the R^2?

4 ビュー (過去 30 日間)
Chris Herdelin
Chris Herdelin 2021 年 9 月 8 日
回答済み: Jeff Miller 2021 年 9 月 8 日
n=100;
alpha=1;
beta=1.5;
e = randn(n,1);
x=rand(n,1);
y=alpha + x*beta + e;
x=[ones(n,1), x];
bhat = inv(x'*x)*x'*y;
disp 'The OLS estimate of beta is';
disp(bhat);
resids = y - x*bhat;
s2 = resids'*resids/(n-2);
disp 'The OLS estimator of the error variance is';
disp(s2);

回答 (1 件)

Jeff Miller
Jeff Miller 2021 年 9 月 8 日
Either of these:
Rsqr = corr(x(:,2),y)^2;
RsqrAlso = 1-(std(resids)/std(y))^2;

カテゴリ

Help Center および File ExchangeMining Geology についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by