Negative multinomial distribution
A demo of random number generation, density evaluation, and distribution fitting for the negative mutlinomial distribution
Contents
Generate negative multinomial random vectors
clear; % reset random seed s = RandStream('mt19937ar','Seed',1); RandStream.setGlobalStream(s); % sample size n = 100; % # bins d = 5; % prob parameter prob = repmat(1/(d+1),1,d+1); % overdispersion b = 2; % generate random vectors X = negmnrnd(prob,b,n);
Evaluate negative multinomial pdf at true parameter value
logL = negmnpdfln(X,prob,b); display(sum(logL));
-859.4829
Fit negative multinomial distribution
tic; [p_hat, b_hat, stats] = negmnfit(X); toc; display([p_hat, b_hat]); display(stats.se'); display(stats); figure; plot(stats.logL_iter); xlabel('iteration'); ylabel('log-likelihood');
Elapsed time is 0.024200 seconds. 0.1787 0.1647 0.1522 0.1506 0.1531 0.2007 2.4261 0.0127 0.0122 0.0117 0.0116 0.0117 0.4274 stats = struct with fields: BIC: 1.7410e+03 AIC: 1.7293e+03 iterations: 4 gradient: [6×1 double] logL: -856.6715 logL_iter: [-856.7447 -856.6721 -856.6715 -856.6715] se: [6×1 double] dof: 6