怎样用matlab做出一元线性回归图形
x值分别为1656,2122,2864,4033,6099。y值为2112,2170,2291,2456,2759最好写出编程语言给出编完后的图形,感激不尽了...
x值分别为1656,2122,2864,4033,6099。y值为2112,2170,2291,2456,2759最好写出编程语言给出编完后的图形,感激不尽了
展开
展开全部
>> clear
>> x=[1656,2122,2864,4033,6099];
>> y=[2112,2170,2291,2456,2759];
>> [P,S]=polyfit(x,y,1)
%P为拟合回归系数即y=P(1)*x+p(2)
P =
1.0e+003 *
0.0001 1.8666
S =
R: [2x2 double]
df: 3
normr: 9.4223
>> [Y,delta]=polyconf(P,x,S)
%给出回归Y的95%的置信区间为[Y-delta,Y+delta]
Y =
1.0e+003 *
2.1090 2.1772 2.2858 2.4569 2.7592
delta =
20.6907 19.8923 19.1147 19.2502 23.2005
>> x1=1600:100:6100;
>> f=polyval(P,x1);
>> plot(x,y,'ro',x1,f,'-')%绘图查看拟合效果
>> hold on
>> plot(x,Y+delta,'*g')
>> plot(x,Y-delta,'*g')%给出拟合的置信区间
希望我的回答能帮助你!
>> x=[1656,2122,2864,4033,6099];
>> y=[2112,2170,2291,2456,2759];
>> [P,S]=polyfit(x,y,1)
%P为拟合回归系数即y=P(1)*x+p(2)
P =
1.0e+003 *
0.0001 1.8666
S =
R: [2x2 double]
df: 3
normr: 9.4223
>> [Y,delta]=polyconf(P,x,S)
%给出回归Y的95%的置信区间为[Y-delta,Y+delta]
Y =
1.0e+003 *
2.1090 2.1772 2.2858 2.4569 2.7592
delta =
20.6907 19.8923 19.1147 19.2502 23.2005
>> x1=1600:100:6100;
>> f=polyval(P,x1);
>> plot(x,y,'ro',x1,f,'-')%绘图查看拟合效果
>> hold on
>> plot(x,Y+delta,'*g')
>> plot(x,Y-delta,'*g')%给出拟合的置信区间
希望我的回答能帮助你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询