matlab中的一元回归

来源:百度知道 编辑:UC知道 时间:2024/05/04 04:17:53
我在matlab中输入如下程序
function[x,y]=DataRegress1
xx=[2.38 2.44 2.70 2.98 3.32 3.12 2.14 2.86 3.50 3.20 2.78 2.70 2.36 2.42 2.62 2.80 2.92 3.04 3.26 2.30];
yy=[51.11 50.63 51.82 52.97 54.47 53.33 49.90 51.99 55.81 52.93 52.87 52.36 51.38 50.87 51.02 51.29 52.73 52.81 53.59 49.77];
[x,index]=sort(xx);
y=yy(index);

[x,y]=DataRegress1;
[c,s]=polyfit(x,y,1);
[yhat,w]=polyconf(c,x,s,.05);
syy=sum(y.^2)-length(x)*mean(y)^2;
sse=syy-c(1)*(sum(x.*y)-length(x)*mean(x)*mean(y));
plot(x,yhat,'k-',x,yhat-w,'k--',x,yhat+w,'k- -',x,y,'ks',[x;x],[yhat;y],'k-')
legend('Regression line','95% confidence of y',4)
axis([2 3.6 57])
xlabel('x(input)')
ylabel('y(reponse)')
titel('simple linear regression')
text(2.1,56,['coefficient of determination R^2=' num2str(1-sse/syy,3)])
来进行一元回归,可执行的时候弹出如下对话
??? Maximum recursion limit of 5

改了4处,程序通了,见程序批注。
function[x,y]=DataRegress1
xx=[2.38 2.44 2.70 2.98 3.32 3.12 2.14 2.86 3.50 3.20 2.78 2.70 2.36 2.42 2.62 2.80 2.92 3.04 3.26 2.30];
yy=[51.11 50.63 51.82 52.97 54.47 53.33 49.90 51.99 55.81 52.93 52.87 52.36 51.38 50.87 51.02 51.29 52.73 52.81 53.59 49.77];
[x,index]=sort(xx)
y=yy(index)

%[x,y]=DataRegress1; %useless sentance
[c,s]=polyfit(x,y,1);
[yhat,w]=polyconf(c,x,s,.05);
syy=sum(y.^2)-length(x)*mean(y)^2;
sse=syy-c(1)*(sum(x.*y)-length(x)*mean(x)*mean(y));
plot(x,yhat,'k-',x,yhat-w,'k--',x,yhat+w,'k--',x,y,'ks',[x;x],[yhat;y],'k-') %yhat+w,'k--' NOT yhat+w,'k- -'
legend('Regression line','95% confidence of y',4)
axis([2 3.6 48 57]) %Ymin=48 absent
xlabel('x(input)')
ylabel('y(reponse)')
title('simple linear regression') %title NOT titel
text(2.1,56,['coefficien