function myreg(x,y)
nvar=size(x,2)+1;
n=size(x,1);
x=[ones(n,1),x];
beta=x'*x\x'*y;
rss=sum((y-x*beta).^2)
tss=sum((y-mean(y)).^2)
rsq=1-rss/tss;%r squred
fval=(tss-rss)/(nvar-1)/(tss/(n-1));%f value
pval=fcdf(fval,(nvar-1),(n-1);
sigma=rss/(n-nvar);
unt=eye(nvar);
variance=diag((x'*x)\unt)*sigma;
std=sqrt(variance);
tvalue=beta./std;%t value;
tpval=2*(1-tcdf(abs(tval),(n-nvar));
fprint('---------------result of regression-------------------\n')
fprint('coefficients');fprint(' ');
fprint('mse');fprint(' ');
fprint('tvalue');fprint(' ');
fprint('pvalue');fprint(' ');
fprintf('\n');
for i=1:nvar
fprint('%4.4f',beta(i,1));fprint(' ');
fprint('%4.4f',std(i,1));fprint(' ');
fprint('%4.4f',tvalue(i,1));fprint(' ');
fprint('%4.4f',tpval(i,1));fprint(' ');
fprint('\n')
end
fprint('----------------------------------------------------\n')
end
nvar=size(x,2)+1;
n=size(x,1);
x=[ones(n,1),x];
beta=x'*x\x'*y;
rss=sum((y-x*beta).^2)
tss=sum((y-mean(y)).^2)
rsq=1-rss/tss;%r squred
fval=(tss-rss)/(nvar-1)/(tss/(n-1));%f value
pval=fcdf(fval,(nvar-1),(n-1);
sigma=rss/(n-nvar);
unt=eye(nvar);
variance=diag((x'*x)\unt)*sigma;
std=sqrt(variance);
tvalue=beta./std;%t value;
tpval=2*(1-tcdf(abs(tval),(n-nvar));
fprint('---------------result of regression-------------------\n')
fprint('coefficients');fprint(' ');
fprint('mse');fprint(' ');
fprint('tvalue');fprint(' ');
fprint('pvalue');fprint(' ');
fprintf('\n');
for i=1:nvar
fprint('%4.4f',beta(i,1));fprint(' ');
fprint('%4.4f',std(i,1));fprint(' ');
fprint('%4.4f',tvalue(i,1));fprint(' ');
fprint('%4.4f',tpval(i,1));fprint(' ');
fprint('\n')
end
fprint('----------------------------------------------------\n')
end