How do I run the program below in Matlab? b) How do I extend this program to calculate the R2 of this regression? How do I calculate the covariance matrix of the OLS estimator
1 次查看(过去 30 天)
显示 更早的评论
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);
a) Run the above program in Matlab and describe what each line of this program does.
b) Extend this program to calculate the R2 of this regression and print out the result.
c) Extend this program to calculate the covariance matrix of the OLS estimators
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!