楼主: omid
4745 9

[问答] 用nlp做最大似然估计报错 [推广有奖]

  • 0关注
  • 0粉丝

博士生

81%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
25390 点
帖子
361
精华
0
在线时间
370 小时
注册时间
2010-9-29
最后登录
2017-9-1

楼主
omid 发表于 2011-3-23 01:15:58 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
大家好,本人刚接触sas没有多久,现在遇到一个问题,想要实现一个最大似然估计,代码如下:
data A;
input pvment$ thickness ESAL rain @@;
datalines;
DGAC        48.96170255        544810        144.53
DGAC        52.62549946        236000        261.07
DGAC        54.35712505        310000        212.7
DGAC        54.41309566        284780        492.96
DGAC        36.66229293        3481320        157.99
DGAC        55.07167785        136250        531.11
DGAC        54.14445697        122000        513.33
OGAC        41.52548462        236000        261.07
OGAC        44.31461605        236000        261.07
OGAC        42.19031228        236000        261.07
OGAC        45.38567824        236000        261.07
OGAC        27.66625307        1662940        415.4
OGAC        33.64522296        210865        535.49
OGAC        26.56858947        89000        1187.11
OGAC        30.89045698        89000        1187.11
other 52.42478719        236000        261.07
other         50.30363374        236000        261.07
other         49.21335293        236000        261.07
other 50.01384679        236000        261.07
other         48.2134075        81070        21.3
other         44.08889863        81070        21.3
other         47.08160511        89000        2105.24
other         52.72141224        310000        212.7
other 57.51522172        310000        212.7
RAC         30.5341555        908520        833.66
RAC         23.26654254        243445        1425.6
RAC         31.62391067        91000        1183.35
RAC         27.16423427        286885        1679.37
RAC         22.78564813        243445        1425.6
RAC         33.05433851        91000        1183.35
RAC         24.05508273        286885        1679.37
;
(仅列出部分数据)
proc nlp data=A;
max f;
parms a1=.1, b1=.1, c1=.1, d1=.1,a2=.1, b2=.1, c2=.1, d2=.1,a3=.1, b3=.1, c3=.1, d3=.1,a4=.1, b4=.1, c4=.1, d4=.1;
if pvment eq 'dgac' then f1=a1+b1*thickness+c1*ESAL+d1*rain;
if pvment eq 'ogac' then f2=a2+b2*thickness+c2*ESAL+d2*rain;
if pvment eq 'other' then f3=a3+b3*thickness+c3*ESAL+d3*rain;
if pvment eq 'dgac' then f4=a4+b4*thickness+c4*ESAL+d4*rain;
f=exp(f1)/(exp(f1)+exp(f2)+exp(f3)+exp(f4));
run;


运行的时候总是提示说:ERROR: There are references to missing variables when the program code is executed for _OBS_= 1
在网上查了好久,也不知道怎么修改。希望能有人帮助,欢迎任何建议。本人无以为报,现在国外,可能查找资料比较方便,也只能提供这点感谢了~~。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:最大似然估计 最大似然 似然估计 NLP References NLP

回帖推荐

bobguy 发表于4楼  查看完整内容

There are a couple of problems here. You already find one. Other one is the values for variable pvment which are coded in mixed cases. you need to convert them when do a comparison. See in the program below. Other tip when you have a problem like this you can plug in the program in a data step to see what's going on. HTH data A; a1=.1; b1=.1; c1=.1; d1=.1;a2=.1; b2=.1; c2=.1; ...

本帖被以下文库推荐

沙发
omid 发表于 2011-3-23 04:09:03
我的问题解决了,发现时exp(fi)i=RAC OGDC other  OGAC, 数值过大,导致错误,可以对数据进行预处理,如将ESAL缩小100000,相应的所得到的系数也缩小100000倍,不知道这样子处理是否合适?

藤椅
register_me 发表于 2011-3-23 20:15:47
对的,不过你也可以吧初值设的小一点,或者从负值开始
不过看你的code像是要做多元的logistic 回归
你可以直接yong
proc logistic 做,不用这么复杂

板凳
bobguy 发表于 2011-3-24 08:54:13
omid 发表于 2011-3-23 04:09
我的问题解决了,发现时exp(fi)i=RAC OGDC other  OGAC, 数值过大,导致错误,可以对数据进行预处理,如将ESAL缩小100000,相应的所得到的系数也缩小100000倍,不知道这样子处理是否合适?
There are a couple of problems here. You already find one.

Other one is the values for variable pvment which are coded in mixed cases. you need to convert them when do a comparison. See in the program below.

Other tip when you have a problem like this you can plug in the program in a data step to see what's going on.

HTH



data A;
a1=.1; b1=.1; c1=.1; d1=.1;a2=.1; b2=.1; c2=.1;
d2=.1;a3=.1; b3=.1; c3=.1; d3=.1;a4=.1; b4=.1; c4=.1; d4=.1;

input pvment$ thickness ESAL rain @@;
if lowcase(pvment) eq 'dgac' then f1=a1+b1*thickness+c1*ESAL+d1*rain;
else if lowcase(pvment) eq 'ogac' then f2=a2+b2*thickness+c2*ESAL+d2*rain;
else if lowcase(pvment) eq 'other' then f3=a3+b3*thickness+c3*ESAL+d3*rain;
else if lowcase(pvment) eq 'dgac' then f4=a4+b4*thickness+c4*ESAL+d4*rain;
f=exp(f1)/(exp(f1)+exp(f2)+exp(f3)+exp(f4));
datalines;
DGAC        48.96170255        544810        144.53
DGAC        52.62549946        236000        261.07
DGAC        54.35712505        310000        212.7
DGAC        54.41309566        284780        492.96
DGAC        36.66229293        3481320        157.99
DGAC        55.07167785        136250        531.11
DGAC        54.14445697        122000        513.33
OGAC        41.52548462        236000        261.07
OGAC        44.31461605        236000        261.07
OGAC        42.19031228        236000        261.07
OGAC        45.38567824        236000        261.07
OGAC        27.66625307        1662940        415.4
OGAC        33.64522296        210865        535.49
OGAC        26.56858947        89000        1187.11
OGAC        30.89045698        89000        1187.11
other 52.42478719        236000        261.07
other         50.30363374        236000        261.07
other         49.21335293        236000        261.07
other 50.01384679        236000        261.07
other         48.2134075        81070        21.3
other         44.08889863        81070        21.3
other         47.08160511        89000        2105.24
other         52.72141224        310000        212.7
other 57.51522172        310000        212.7
RAC         30.5341555        908520        833.66
RAC         23.26654254        243445        1425.6
RAC         31.62391067        91000        1183.35
RAC         27.16423427        286885        1679.37
RAC         22.78564813        243445        1425.6
RAC         33.05433851        91000        1183.35
RAC         24.05508273        286885        1679.37
;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

报纸
omid 发表于 2011-3-26 03:05:16
thx very much for your instruction. It helps a lot

地板
omid 发表于 2011-3-26 03:09:01
i appreciate ur help. if there is anything i can do for u,  please just send me message.

7
omid 发表于 2011-3-26 03:42:33
And if there is anything i can do for u,  please just do not hesitate to send me message. thx again.

8
shenruiyang211 发表于 2011-6-19 19:09:53
我要做一个非线性的参数估计,输入的程序如下:
DATA PIN;
SET WORK.AA;
proc nlp data=PIN;
max logf;
    parms alpha delta eb es mu;
bounds alpha>0;
     logf = log((1-alpha) * pdf('POISSON',buy, eb) * pdf('POISSON',sell, es) + alpha * delta * pdf('POISSON',buy, eb) * pdf('POISSON',sell, es+mu) + alpha * (1-delta) * pdf('POISSON',buy, eb+mu) * pdf('POISSON',sell, es));
   run;
为什么得到这样的结果呢?

NOTE: Your code contains 1 program statements.
NOTE: Gradient is computed using analytic formulas.
NOTE: Hessian is computed using analytic formulas.
NOTE: A finite difference approximation is used for the derivative of the PDF function at 行 7 列 32.
NOTE: Initial value of parameter alpha is set randomly to 0.2773802985.
NOTE: Initial value of parameter delta is set randomly to 0.1538283379.
NOTE: Initial value of parameter eb is set randomly to 0.5712921012.
NOTE: Initial value of parameter es is set randomly to 0.4688570571.
NOTE: Initial value of parameter mu is set randomly to 0.5988910089.
ERROR: Execution Errors for _OBS_= 1 :
ERROR: There are references to missing variables when the program code is executed for _OBS_= 1
WARNING: Your program statements cannot be executed completely.
WARNING: In a total of 1 calls an error occurred during execution of the program statements. NLP attempted to recover by using a
         shorter step size.
我不知道错在了哪里,请指教?THANKYOU!


4# bobguy

9
shenruiyang211 发表于 2011-6-20 12:26:31
您好!为什么我拿你的代码运行后,输出的结果就是PALMS赋予参数的初始值呢?你运行的时候会这样吗?rl=https://bbs.pinggu.org/redirect.php?goto=findpost&pid=8728886&ptid=1059711]2#[/url] omid

10
shiyishibasui 发表于 2013-11-17 23:18:49
新手运行楼主的代码之后也得到这一串提示

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-24 13:07