Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

Question 1

This document contains code to generate simulated Poisson-distributed data for different lambda values, calculate the maximum likelihood estimate of lambda, and compare it to the theoretical fisher information. It then generates simulated linear regression data according to the model Y = aX + b + epsilon, calculates the likelihood functions for the parameters a and b over a grid of values, and determines their maximum likelihood estimates.

Uploaded by

Lakshmi Sampath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Question 1

This document contains code to generate simulated Poisson-distributed data for different lambda values, calculate the maximum likelihood estimate of lambda, and compare it to the theoretical fisher information. It then generates simulated linear regression data according to the model Y = aX + b + epsilon, calculates the likelihood functions for the parameters a and b over a grid of values, and determines their maximum likelihood estimates.

Uploaded by

Lakshmi Sampath
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

% Define the lambda values

lambda_values = [0.1, 1, 10];

% Define the number of observations


N = 1000; % You can adjust this as needed

% Initialize arrays to store results


variance_theta_ML = zeros(1, length(lambda_values));
fisher_information = zeros(1, length(lambda_values));

% Generate random samples from Poisson distribution for each lambda


for i = 1:length(lambda_values)
lambda = lambda_values(i);
samples = poissrnd(lambda, N, 1); % Generate Poisson-distributed samples

% Maximum Likelihood Estimation for lambda (theta)


theta_ML = sum(samples) / N;

% Calculate the Fisher Information


fisher_information(i) = N / lambda;

% Calculate the variance of the ML estimator


variance_theta_ML(i) = var(samples) / N;
end

% Display the results


for i = 1:length(lambda_values)
fprintf('Lambda = %.1f:\n', lambda_values(i));
fprintf(' Variance of ML estimator: %.4f\n', variance_theta_ML(i));
fprintf(' Fisher Information: %.4f\n\n', fisher_information(i));
end

Lambda = 0.1:
Variance of ML estimator: 0.0001
Fisher Information: 10000.0000
Lambda = 1.0:
Variance of ML estimator: 0.0010
Fisher Information: 1000.0000
Lambda = 10.0:
Variance of ML estimator: 0.0092
Fisher Information: 100.0000

% Define parameters
N = 300;
sigma_e2 = 1.5;
a = 4;
b = 5;

% Generate data with known parameters


X = randn(N, 1); % Random X values
epsilon = sqrt(sigma_e2) * randn(N, 1); % Random noise

1
Y = a * X + b + epsilon; % Observed Y values

% Likelihood functions for a and b


likelihood_a = @(a) -sum((Y - a*X - b).^2) / (2*sigma_e2);
likelihood_b = @(b) -sum((Y - a*X - b).^2) / (2*sigma_e2);

% Grid of values for a and b


a_values = linspace(0, 8, 100);
b_values = linspace(0, 10, 100);

% Calculate likelihood values for a and b


likelihood_values_a = arrayfun(likelihood_a, a_values);
likelihood_values_b = arrayfun(likelihood_b, b_values);

% Plot likelihood functions for a


subplot(2, 1, 1);
plot(a_values, likelihood_values_a);
xlabel('Parameter a');
ylabel('Log Likelihood');
title('Likelihood Function for Parameter a');

% Plot likelihood functions for b


subplot(2, 1, 2);
plot(b_values, likelihood_values_b);
xlabel('Parameter b');
ylabel('Log Likelihood');
title('Likelihood Function for Parameter b');

2
% Find ML estimates for a and b
[~, idx_a] = max(likelihood_values_a);
[~, idx_b] = max(likelihood_values_b);

% ML estimates
a_ML = a_values(idx_a);
b_ML = b_values(idx_b);

% Display results
fprintf('ML Estimate for a: %.4f\n', a_ML);

ML Estimate for a: 4.0404

fprintf('ML Estimate for b: %.4f\n', b_ML);

ML Estimate for b: 5.0505

You might also like