Calculate Negative loglikelihood of custom probability distribution
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have a 1D vector, whose data are chi distributed. The Matlab built-in function negloglik expects a probability distribution object pd, which for standard distributions can be created by fitdist. Unfortunately, my chi distribution is no standard distribution and is thus not supported by fitdist.
How can I calculated the Negative loglikelihood in my special case?
댓글 수: 0
채택된 답변
Torsten
2022년 8월 20일
편집: Torsten
2022년 8월 20일
% Generate random numbers from chi distribution with k = 6
k = 6;
y = rand(150,1);
x = gammaincinv(y,k/2);
x = sqrt(2*x);
% Recover k by maximum likelihood estimate
syms k
f = prod(x.^(k-1).*exp(-x.^2/2)/(2^(k/2-1)*gamma(k/2)));
logf = log(f)
dlogfdk = simplify(diff(logf,k))
knum = vpasolve(dlogfdk==0,k,[0 10])
negative_log_likelihood = subs(-logf,k,knum)
k = 0:0.1:10;
Logf = matlabFunction(logf);
plot(k,-Logf(k))
댓글 수: 6
추가 답변 (1개)
Torsten
2022년 8월 20일
편집: Torsten
2022년 8월 20일
Why don't you deduce the equation you have to solve for k by hand ?
The paragraph
Continuous distribution, continuous parameter space
under
explains in detail what to do.
I get (for comparison):
sum_{i=1}^{i=n} log(xi) - n/2*log(2) - n/2*digamma(k/2) = 0
where xi (i=1,...,n) are your measurement data.
Solve for k (e.g. using fsolve) to get the maximum likelihood estimate for the parameter.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!