24小时热门版块排行榜    

查看: 3303  |  回复: 15

monitor2885

至尊木虫 (职业作家)

队长

[求助] 求广义线性模型GLM的函数表达式 已有1人参与

y=b0+b1*x1+b2*x2+b3*sin(x3)

y=[7.1;4.1;5.2;6.3];
x1=[1;2;3;4];
x2=[100;205;306;150];
x3=[8;10;12;5];

link 函数是 normal,求 glmfit 的表达式,求 b0, b1, b2, b3,谢谢。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

Retirement
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

512095518

专家顾问 (正式写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
monitor2885: 金币+10, ★★★很有帮助 2015-10-29 09:55:21
b0 = 3.3941
b1 = 1.5278
b2 = -0.0044
b3 = 2.6494
没有极限,只有超越!
2楼2015-10-29 09:52:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (职业作家)

队长

引用回帖:
2楼: Originally posted by 512095518 at 2015-10-29 09:52:11
b0 = 3.3941
b1 = 1.5278
b2 = -0.0044
b3 = 2.6494

b = glmfit([x1 x2 x3],y,'normal','link','normal')
这个语句,为何不对呀?第一个Normal代表distr,第二个normal是link函数,不对吗?
Retirement
3楼2015-10-29 09:55:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

512095518

专家顾问 (正式写手)

【答案】应助回帖

我不太明白就是link函数是normal是什么意思,我用matlab非线性拟合帮你求出参数

y=[7.1;4.1;5.2;6.3];
x1=[1;2;3;4];
x2=[100;205;306;150];
x3=[8;10;12;5];
x=[x1 x2 x3];
f=@(b,x)b(4)+b(1)*x(:,1)+b(2)*x(:,2)+b(3)*sin(x(:,3))
b0=[0 0 0 0]';
opt=optimset('TolFun',1e-3,'TolX',1e-3);
[b R]=nlinfit(x,y,f,b0,opt)

最后求得b的数组
没有极限,只有超越!
4楼2015-10-29 09:55:11
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (职业作家)

队长

引用回帖:
4楼: Originally posted by 512095518 at 2015-10-29 09:55:11
我不太明白就是link函数是normal是什么意思,我用matlab非线性拟合帮你求出参数

y=;
x1=;
x2=;
x3=;
x=;
f=@(b,x)b(4)+b(1)*x(:,1)+b(2)*x(:,2)+b(3)*sin(x(:,3))
b0=';
opt=optimset('TolFun',1e-3,'Tol ...

如果写成 b = glmfit([x1 x2 sin(x3)],y,'normal') 就对了。为什么不写Link呢?奇怪。你看matlab help里面那个汽车的例子,写link了呀
Use the glmfit function to carry out the associated regression:

b = glmfit(w,[poor total],'binomial','link','logit')
b =
  -13.3801
    0.0042
Retirement
5楼2015-10-29 09:57:40
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

512095518

专家顾问 (正式写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
monitor2885: 金币+10, ★★★很有帮助 2015-10-29 10:42:13
引用回帖:
5楼: Originally posted by monitor2885 at 2015-10-29 09:57:40
如果写成 b = glmfit(,y,'normal') 就对了。为什么不写Link呢?奇怪。你看matlab help里面那个汽车的例子,写link了呀
Use the glmfit function to carry out the associated regression:

b = glmfit(w,,'bino ...

实际上b = glmfit([x1 x2 sin(x3)],y)也就可以出结果了,我猜想广义线性模型中的Y=b0+b1*x1+b2*x2+b3*x3,其中用sin(x3)来代替x3这才适用模型,所以你最开始b = glmfit([x1 x2 x3],y,'normal','link','normal')这样直接用x3就有问题,不符合模型假设

b = glmfit([x1 x2 sin(x3)],y,'normal','link','identity')这个格式也是可以的

函数格式为b = glmfit(X,y,distr,param1,val1,param2,val2,...),distr can be any of the following strings: 'binomial', 'gamma', 'inverse gaussian', 'normal' (the default), and 'poisson'.

b = glmfit(X,y,distr,param1,val1,param2,val2,...) additionally allows you to specify optional parameter name/value pairs to control the model fit. Acceptable parameters are as follows.

从matlab函数解释中看出,param参数是来优化distr分布的,你要注意写全了,要么就都缺省让函数内在保持一致,用b = glmfit([x1 x2 sin(x3)],y),要么就都写全了,用b = glmfit([x1 x2 sin(x3)],y,'normal','link','identity')
没有极限,只有超越!
6楼2015-10-29 10:27:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

512095518

专家顾问 (正式写手)

【答案】应助回帖

★ ★ ★ ★ ★
monitor2885: 金币+5, 有帮助 2015-10-29 10:45:30
引用回帖:
3楼: Originally posted by monitor2885 at 2015-10-29 09:55:10
b = glmfit(,y,'normal','link','normal')
这个语句,为何不对呀?第一个Normal代表distr,第二个normal是link函数,不对吗?...

link这个参数里面没有normal这一值作为选项,你用identity来代替你第二个normal就可以了
没有极限,只有超越!
7楼2015-10-29 10:30:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (职业作家)

队长

引用回帖:
6楼: Originally posted by 512095518 at 2015-10-29 10:27:09
实际上b = glmfit(,y)也就可以出结果了,我猜想广义线性模型中的Y=b0+b1*x1+b2*x2+b3*x3,其中用sin(x3)来代替x3这才适用模型,所以你最开始b = glmfit(,y,'normal','link','normal')这样直接用x3就有问题,不符合 ...

你看stats,哪个是significance?
stats is a structure with the following fields:
beta — Coefficient estimates b
dfe — Degrees of freedom for error
s — Theoretical or estimated dispersion parameter
sfit — Estimated dispersion parameter
se — Vector of standard errors of the coefficient estimates b
coeffcorr — Correlation matrix for b
covb — Estimated covariance matrix for B
t — t statistics for b
p — p-values for b
resid — Vector of residuals
residp — Vector of Pearson residuals
residd — Vector of deviance residuals
resida — Vector of Anscombe residuals
Retirement
8楼2015-10-29 10:44:36
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

512095518

专家顾问 (正式写手)

【答案】应助回帖

引用回帖:
8楼: Originally posted by monitor2885 at 2015-10-29 10:44:36
你看stats,哪个是significance?
stats is a structure with the following fields:
beta — Coefficient estimates b
dfe — Degrees of freedom for error
s — Theoretical or estimated dispersion parame ...

你是要求R2么,我感觉那里面都不是,matlab里面没有直接求R2的命令,需要自己写。不过方法也很简单。
R2就是决定系数(coefficient of determination),有的教材上翻译为判定系数,也称为拟合优度。

你原始数为b,拟合方程求得数为a,则
R2 =sum((a - mean(b)).^2)/sum((b - mean(b)).^2)
没有极限,只有超越!
9楼2015-10-29 10:57:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

monitor2885

至尊木虫 (职业作家)

队长

引用回帖:
9楼: Originally posted by 512095518 at 2015-10-29 10:57:14
你是要求R2么,我感觉那里面都不是,matlab里面没有直接求R2的命令,需要自己写。不过方法也很简单。
R2就是决定系数(coefficient of determination),有的教材上翻译为判定系数,也称为拟合优度。

你原始数 ...

显著性检验,signif=0.1,0.05,0.001...
Retirement
10楼2015-10-29 11:01:46
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 monitor2885 的主题更新
信息提示
请填处理意见