beta0=1;beta1=2;sigma2=9;n=50
beta0
x=rand(n,1)*10
epsilon=normrnd (0, sqrt (sigma2),n,1)
y=beta0+beta1*x+epsilon
regstats(y,x,'linear')
scatter(x,y)
X=[x ones(50,1)]
betahat=(inv(X'*X))*(X'*y)
ttest(betahat-[beta0;beta1])
ttest(betahat-[beta0;beta1-2])
yhat
plot(yhat,x)
plot([0 1]*betahat+[1 0]*betahat*x,x,beta0+beta1*x,x)
yhat2=[0 1]*betahat+[1 0]*betahat*x
yhat-yhat2
r
e
e=y-yhat
s2=(e'*e)/48
(s2-sigma2)/sigma2
