This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/likelihood/exercises/mlepropest.m

27 lines
653 B
Matlab

m = 2.0; % slope
sigmas = [0.1, 1.0]; % standard deviations
ns = [100, 1000]; % number of data pairs
trials = 1000; % number of data sets
for i = 1:length(sigmas)
sigma = sigmas(i);
for j = 1:length(ns)
n = ns(j);
slopes = zeros(trials, 1);
for k=1:trials
% data pairs:
x = 5.0*rand(n, 1);
y = m*x + sigma*randn(n, 1);
% fit:
slopes(k) = mleslope(x, y);
end
subplot(2, 2, 2*(i-1)+j);
bins = [1.9:0.005:2.1];
hist(slopes, bins);
xlabel('estimated slope');
title(sprintf('sigma=%g, n=%d', sigma, n));
end
end
savefigpdf(gcf, 'mlepropest.pdf', 15, 10);