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 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!