Matlab 用极大似然函数估计自定义分布的参数
我试图使用MATLAB中的Matlab 用极大似然函数估计自定义分布的参数,matlab,debugging,distribution,mle,Matlab,Debugging,Distribution,Mle,我试图使用MATLAB中的mle()函数来估计6参数自定义分布的参数 自定义发行版的PDF为 而CDF是 其中,Γ(x,y)和Γ(x)分别是上不完全伽马函数和伽马函数。α、 θ、β、a、b和c是自定义分布的参数K由以下公式给出 给定一个数据向量“data”,我想估计参数α、θ、β、a、b和c 到目前为止,我已经提出了以下代码: data = rand(20000,1); % Since I cannot upload the acutal data, we may use
mle()
函数来估计6参数自定义分布的参数
自定义发行版的PDF为
而CDF是
其中,Γ(x,y)和Γ(x)分别是上不完全伽马函数和伽马函数。α、 θ、β、a、b和c是自定义分布的参数K由以下公式给出
给定一个数据向量“data
”,我想估计参数α、θ、β、a、b和c
到目前为止,我已经提出了以下代码:
data = rand(20000,1); % Since I cannot upload the acutal data, we may use this
t = 0:0.0001:0.5;
fun = @(w,a,b,c) w^(a-1)*(1-w)^(b-1)*exp^(-c*w);
% to estimate the parameters
custpdf = @(data,myalpha,mybeta,mytheta,a,b,c)...
((integral(@(t)fun(t,a,b,c),0,1)^-1)*...
mybeta*...
igamma(myalpha,((mytheta/t)^mybeta)^(a-1))*...
(mytheta/t)^(myalpha*mybeta+1)*...
exp(-(mytheta/t)^mybeta-(c*(igamma(myalpha,(mytheta/t)^mybeta)/gamma(myalpha)))))...
/...
(mytheta*...
gamma(myalpha)^(a+b-1)*...
(gamma(myalpha)-igamma(myalpha,(mytheta/t)^mybeta))^(1-b));
custcdf = @(data,myalpha,mybeta,mytheta,a,b,c)...
(integral(@(t)fun(t,a,b,c),0,1)^-1)*...
integral(@(t)fun(t,a,b,c),0,igamma(myalpha,(mytheta/t)^mybeta)^mybeta/gamma(myalpha));
phat = mle(data,'pdf',custpdf,'cdf',custcdf,'start',0.0);
但我得到了以下错误:
Error using mlecustom (line 166)
Error evaluating the user-supplied pdf function
'@(data,myalpha,mybeta,mytheta,a,b,c)((integral(@(t)fun(t,a,b,c),0,1)^-1)*mybeta*igamma(myalpha,((mytheta/t)^mybeta)^(a-1))*(mytheta/t)^(myalpha*mybeta+1)*exp(-(mytheta/t)^mybeta-(c*(igamma(myalpha,(mytheta/t)^mybeta)/gamma(myalpha)))))/(mytheta*gamma(myalpha)^(a+b-1)*(gamma(myalpha)-igamma(myalpha,(mytheta/t)^mybeta))^(1-b))'.
Error in mle (line 245)
phat = mlecustom(data,varargin{:});
Caused by:
Not enough input arguments.
我试图查看错误行,但我无法找出错误的实际位置
哪个函数缺少较少的输入?它指的是乐趣吗?当试图估计参数时,mle
为什么缺少较少的输入
有人能帮我调试错误吗
提前感谢。exp()
- 起点涉及6个参数,而不仅仅是一个参数
0.1*一(1,6)
- 在custcdf
中,要求积分的上界为a scalar,我做了一些尝试和错误,范围是[mle
。对于 试用某些值会导致cdf为负值或小于1,丢弃它们2~9]
- 然后使用右边的一个来计算上限,看看它是否是 与您预定义的相同
Censored = ones(5,1);% All data could be trusted
data = rand(5,1); % Since I cannot upload the acutal data, we may use this
f = @(w,a,b,c) (w.^(a-1)).*((1-w).^(b-1)).*exp(-c.*w);
% to estimate the parameters
custpdf = @(t,alpha,theta,beta, a,b,c)...
(((integral(@(w)f(w,a,b,c), 0,1)).^-1).*...
beta.*...
((igamma(alpha, (theta./t).^beta)).^(a-1)).*...
((theta./t).^(alpha.*beta + 1 )).*...
exp(-(((theta./t).^beta)+...
c.*igamma(alpha, (theta./t).^beta)./gamma(alpha))))./...
(theta.*...
((gamma(alpha)).^(a+b-1)).*...
((gamma(alpha)-...
igamma(alpha, (theta./t).^beta)).^(1-b)));
custcdf = @(t,alpha,theta,beta, a,b,c)...
((integral(@(w)f(w,a,b,c), 0,1)).^-1).*...
(integral(@(w)f(w,a,b,c), 0,2));
phat = mle(data,'pdf',custpdf,'cdf',custcdf,'start', 0.1.*ones(1,6),'Censoring',Censored);
结果
phat = 0.1017 0.1223 0.1153 0.1493 -0.0377 0.0902
请将错误粘贴为代码(而不是图像),以便可以搜索。另外,标题中不需要添加任何内容。@Dev iL我按照要求进行了更改。我很确定问题在于将您的
custpdf
用作mle
的pdf
,因为mle
仅提供2个输入(请参阅)——“此自定义函数接受向量数据
和一个或多个单个分布参数作为输入参数,并返回累积概率值的向量。。如果要向函数传递2个以上的变量,应执行以下操作。同样的情况也适用于custcdf
@Dev-iL您的意思是mle(数据,'pdf',custpdf,'cdf',custcdf,'start',0.0)代码>应该是mle(数据,'pdf',@datacustpdf(数据,myalpha,mybeta,myseta,a,b,c),'cdf',@datacustcdf(数据,myalpha,mybeta,myseta,b,c),'start',0.0)代码>大致上是(但有2个输入和正确的语法)。无论如何-至少在调试阶段,我建议对命名函数使用更少的匿名函数和更多的函数句柄(例如function out=custpdf(…)
)。调试多行匿名函数并不十分方便。非常感谢。你的代码运行得很好。请问有没有办法继续使用上界的igama(myalpha,(mybeta/t)^mybeta)^mybeta/gamma(myalpha)
。使用for循环
会有帮助吗?虽然传递数据向量似乎有问题。还有一件事,我们可以使用phat
值来生成定制发行版的pdf吗?这可能需要我们验证phat
是否正确获得。(我可以将此作为一个单独的问题发布)custpdf(数据、pheta(1)、pheta(2)、pheta(3)、pheta(4)、pheta(5)、pheta(6))
可用于生成pdf。上限必须是标量,正如您所说,您可以绘制pdf,看看它是否正确。使用upper bound=2,3…..9
并绘制pdf,对于实际数据,可能会有所不同。只要尝试不同的上限,如果你得到的错误像cdf是负的,那么这是错误的猜测。或者错误可能是cdf必须大于或等于1。我尝试使用custpdf(数据,pheta(1),pheta(2),pheta(3),pheta(4),pheta(5),pheta(6))
,但我得到了非常不同的PDF,这不应该是事实。尝试了积分的不同上界,但没有成功。
phat = 0.1017 0.1223 0.1153 0.1493 -0.0377 0.0902