Updated maximum likelihood chapter.
Common latex header file.
This commit is contained in:
12
likelihood/code/mlegammafit.m
Normal file
12
likelihood/code/mlegammafit.m
Normal file
@@ -0,0 +1,12 @@
|
||||
% generate gamma distributed random numbers:
|
||||
n = 50;
|
||||
shape = 2.0;
|
||||
scale = 1.0;
|
||||
x = gamrnd(shape, scale, n, 1);
|
||||
|
||||
% maximum likelihood estimate:
|
||||
p = mle(x, 'distribution', 'gamma');
|
||||
|
||||
% report results:
|
||||
fprintf('shape=%.2f\n', p(1));
|
||||
fprintf('scale=%.2f\n', p(2));
|
||||
@@ -3,8 +3,8 @@ n = 100;
|
||||
mu = 3.0;
|
||||
sigma =2.0;
|
||||
x = randn(n,1)*sigma+mu;
|
||||
fprintf(' mean of the data is %.2f\n', mean(x))
|
||||
fprintf('standard deviation of the data is %.2f\n', std(x))
|
||||
fprintf(' mean of the data is %.2f\n', mean(x))
|
||||
|
||||
% mean as parameter:
|
||||
pmus = 2.0:0.01:4.0;
|
||||
@@ -18,12 +18,19 @@ end
|
||||
lm = prod(lms, 1); % likelihood
|
||||
loglm = sum(log(lms), 1); % log likelihood
|
||||
|
||||
% position of maxima:
|
||||
maxlm = max(lm); % height of the maximum
|
||||
pmumaxlm = pmus(lm==maxlm); % pmu where lm is at maximum
|
||||
pmumaxloglm = pmus(loglm==max(loglm)); % same for loglm in one line
|
||||
fprintf(' maximum of likelihood is at %.2f\n', pmumaxlm)
|
||||
fprintf(' maximum of log-likelihood is at %.2f\n', pmumaxloglm)
|
||||
|
||||
% plot likelihood of mean:
|
||||
subplot(1, 2, 1);
|
||||
plot(pmus, lm );
|
||||
plot(pmus, lm);
|
||||
xlabel('mean')
|
||||
ylabel('likelihood')
|
||||
subplot(1, 2, 2);
|
||||
plot(pmus, loglm );
|
||||
plot(pmus, loglm);
|
||||
xlabel('mean')
|
||||
ylabel('log likelihood')
|
||||
|
||||
Reference in New Issue
Block a user