24小时热门版块排行榜    

查看: 6211  |  回复: 9
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

古道西风11

新虫 (初入文坛)

[求助] 求助 用matlab拟合三元线性回归方程及分析

用matlab拟合三元线性回归方程,我自己弄了一个如下
x1=[23.00 23.00 23.00 23.00 23.00 28.00 28.00 28.00 28.00 28.00]';
x2=[0.30 0.30 0.30 0.30 0.30 0.10 0.10 0.10 0.10 0.10]';
x3=[0.00 0.69 1.09 1.38 1.61 0.00 0.69 1.09 1.38 1.61]';
y=[-0.91 -0.35 -0.05 0.15 0.29 -0.58 -0.04 0.23 0.41 0.54];
x=[ones(10,1) x1 x2 x3];
>> [b,bint,r,rint,stats]=regress(y,x);
??? Error using ==> or
Matrix dimensions must agree.

Error in ==> regress at 70
wasnan = (isnan(y) | any(isnan(X),2));

>> b,bint,stats,rcoplot(r,rint)

b =

         0
   -0.0115
   -1.7878
    0.6751


bint =

         0         0
   -0.0168   -0.0062
   -2.2782   -1.2973
    0.5701    0.7800


stats =

    0.9747  134.6812    0.0000    0.0059
问题:
1.我编写的程序对吗?
2.输入程序中,总是会出现warning的那段文字,不知道怎么修改?
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

08小贝

金虫 (正式写手)

本人菜鸟一枚,请问楼主 你这个的回归刚才怎么写呀?我在做一个题目,跟你的有点类似。。但是不知道怎么写回归方程。。请楼主赐教~~
8楼2012-09-28 20:31:01
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 10 个回答

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖


感谢参与,应助指数 +1
臭水沟: 金币+1, 谢谢交流~~ 2012-07-11 12:11:55
x,y的行数应该一样,所以y应该是列向量
showmethemoney
2楼2012-07-11 09:50:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

古道西风11

新虫 (初入文坛)

请问y写成列向量后又出现问题了,这是怎么回事啊??
>> x1=[23.00 23.00 23.00 23.00 23.00 28.00 28.00 28.00 28.00 28.00]';
x2=[0.30 0.30 0.30 0.30 0.30 0.10 0.10 0.10 0.10 0.10]';
x3=[0.00 0.69 1.09 1.38 1.61 0.00 0.69 1.09 1.38 1.61]';
>> y=[-0.91
      -0.35
      -0.05
      0.15
      0.29
      -0.58
      -0.04
      0.23
      0.41
      0.54];
>> x=[ones(10,1) x1 x2 x3];
>> [b,bint,r,rint,stats]=regress(y,x);
Warning: X is rank deficient to within machine precision.
> In regress at 82
>> b,bint,stats,rcoplot(r,rint)
3楼2012-07-11 10:17:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

★ ★
臭水沟: 金币+2, 谢谢交流~~ 2012-07-11 12:12:08
引用回帖:
3楼: Originally posted by 古道西风11 at 2012-07-11 10:17:45
请问y写成列向量后又出现问题了,这是怎么回事啊??
>> x1=';
x2=';
x3=';
>> y=;
>> x=;
>> =regress(y,x);
Warning: X is rank deficient to within machine precision.
> I ...

Most likely you have too many predictor variables, and too few observations. As an alaogy, imagine trying to fit a cubic polynomial regression with only two observations. REGRESS will make a choise about which coefficients to set to zero, but it can't possibly know what you really want.

变量太多,你可以试一下,分别使用x(:,1:2), x(:,1:3), x(:,2:3)算一下,使用3列时总会出现一个b=0。
showmethemoney
4楼2012-07-11 10:38:00
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见