cd("~/your path");

hw8 = readtable("hw8.txt");
y = hw8.y; x1 = hw8.x1;x2 = hw8.x2;
n = length(y); 
X = [1 + zeros(n,1),x1,x2]; % The design matrix
p = length(X(1,:)); % Useful later

betahat = inv(transpose(X)*X)*transpose(X)*y;

sigma2hat = sum((y - X*betahat).^2)/(n - p);

sebetahat = sqrt(diag(sigma2hat*inv(transpose(X)*X)));

tvals = betahat./sebetahat;

pvals = 2.*(1 - normcdf(abs(tvals)));
out= round([betahat,sebetahat,tvals,pvals],3);
out = array2table(out);


out.Properties.VariableNames = {'betahat' 'se' 'z' 'p-value'};
out

% Here is the linear regression function that
% is already in Matlab. Compare the output to that 
% you get with the codew above.
X2 = [x1,x2];
fitlm(X2,y)




