Matlab_Gui在线性回归中的应用
第21卷文山师范高等专科学校学报
on ), ];
2008年 第3期
[20,360,100,15], HorizontalAlignment , l , string , 请输入回归自变量 );
h2_t=uicontrol(gc,f style , text , position ,[20,300,100,15], HorizontalAlignment , l , string , 请输入回归因变量 );
h3_t=uicontrol(gc,f style , text , position ,[50,200,100,20], HorizontalAlignment , l , string , 请输入临界值 );
h4_t=uicontrol(gc,f style , text , position ,[50,160,100,20], HorizontalAlignment , l , string , 请输入预测值x0 );
h5_t=uicontrol(gc,f style , text , position ,[50,80,100,20], HorizontalAlignment , l , string , 检验值(F) );
h6_t=uicontrol(gc,f style , text , position ,[50,40,100,20], HorizontalAlignment , l , string , 回归方程 );
h7_t=uicontrol(gc,f style , text , position ,[50,5,100,20], HorizontalAlignment , l , string , 线性相关系数 );
h8_t=uicontrol(gc,f style , text , string , 预测置信区间(95%) , HorizontalAlignment , l , position ,[50,120,100,20]);
%d定义文本标签
hh=[ ff1=str2num(f1);, , ff2=str2num(f2);, , p=polyfit(ff1,ff2,1);, , y1=polyval(p,ff1);, , [,fe,iR,lxx,xb,s,n]=ff(ff1,ff2,y1,p(1));, ];
hhh=[ F=num2str(f);, , set(h6_e, string ,F), , R=num2str(R);, , set(h8_e, string ,R), , p1=num2str(p(1));, , p2=num2str(p(2));, , set(h7_e, string ,[p1, x , + , ( ,p2, ) ]), , set(h2_b, ena-ble , on ), ];
hh1=[ h2=figure( toolbar , none , number-title , off , name , 残差直方图 ), , hist(e,iceil(sqrt(n))), , gridon, ];
%残差画直方图时分为sqrt(n)取整
hh2=[ h1=figure( toolbar , none , number-title , off , name , 散点与回归直线图 ), ,hh,hhh, plot(ff1,ff2, * ,ff1,y1, - ), , legend( 散点图 , 回归直线 ), , gridon, ,hh1, set(h3_e, enable , on ), , set(h4_e, enable ,
hh3=[hh, X=str2num(x0);, , T=str2num(lm);, , y0=polyval(p,X);, , yj=T*s*sqrt(1+1/n+(X-xb)^2/lxx);, , yx=y0-y;j, , ys=y0+y;j, , YX=num2str(yx);, , YS=num2str(ys);, , set(h5_e, string ,[ [ YX , YS ] ]), ];
%定义调用变量
h1_b=uicontrol(gc,f style , pushbutton , po-sition ,[60,240,80,20], string , 回归分析 ,
HorizontalAlignment , c , callback ,hh2);h2_b=uicontrol(gc,f-style.,-pushbutton.,-string.,-预测.,-HorizontalAlignment.,-l.,-pos-ition.,[210,240,80,20],-enable.,-off.,-callback.,hh3);
%定义按钮Matlab子程序
function[,fe,iR,lxx,xb,s,n]=ff(x,y,y1,b)n=length(x);xb=mean(x);yb=mean(y);lxy=0;lyy=0;lxx=0;ei=zeros(size(y));%d定义残差
fori=1:n
lxy=lxy+(x(i)-xb)*(y(i)-yb);lyy=lyy+(y(i)-yb)^2;
lxx=lxx+(x(i)-xb)^2;ei(i)=y(i)-y1(i);end
U=b*lxy;Q=lyy-U;R=lxy/sqrt(lxx*lyy);%线性回归系数
s=sqrt(Q/(n-2));f=U/s^2;sj=sqrt(Q/(n-2))1
112 Matlab_Gui实例应用分析
例:炼钢基本上是个氧化脱碳的过程,钢液原来的含碳量的多少直接影响到冶炼时间的长短1表1是某平炉34炉的熔毕碳(即全部炉料熔化完毕时钢液的含碳量)与精炼时间(从熔毕至出钢,冶炼所需的时间)的生产记录1
求解以下问题:归方程;
(1)冶炼时间关于碳含量的回
(2)对回归方程作F检验,相关系数检
验,残差分析;(3)若某炉熔毕碳为145(即1145%),估计该炉的置信度为95%的冶炼置信区间1
95


