How to build an empiric cdf/pdf of a compound poisson continuos distribution
4 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone.
as I said in the title i'm trying to obtain the empiric cdf (or pdf) of a compound poisson continuos distribution. Let
be a compound poisson distribution with
as parameters, while λ being the parameter of the random variable N (poisson) and F being the distribution of the i-th Y (assuming all
are iid and extracted from the same lognormal distribution of given parameters). I managed to build a vector called "x_ptf" which contains random values extracted from
, however im struggling into obtaining the empirical cdf/pdf.




clear all; close all; clc
rng(200724)
%mean and standard deviation of a given sample (sample of Yi)
mu_c = 4432.62; var_c= 533130.21;
%lognormal parameters
var_log = log(var_c/mu_c^2+1); sig_log = sqrt(var_log);
mu_log = -var_log/2 +log(mu_c);
%Compound-Poisson distribution
lam = 570; %poisson distribution parameter
nsims = 10^5; %number of simulations
num = poissrnd(lam,1,nsims); %random numbers extracted from the N poisson variable
x_ptf = zeros(nsims,1); %iniziatiling the storage where the random generated numbers will be allocated
for i = 1:length(num)
x_ptf(i) = sum(lognrnd(mu_log,sig_log,1,num(i))); %building randomly generated numbers
end
[cdf, X_ptf] = ecdf(x_ptf);
X_ptf = X_ptf(2:end); cdf = cdf(2:end); %doing this because i get zero two times as the first two components of X_con vector
p = [cdf(1) diff(cdf)']'; %building the pdf from the cdf
E = sum(X_ptf.*p); %empirical mean
plot(X_ptf,p,'*'); %this plot doesn't make sense
The empirical mean is correct, but the pdf distribution is wrong as shown by the plot. I think it means there's some problem with the "ecfd" function im using, is there any way to fix? Or maybe some other functions i could try? Ive already used "ksdensity" but it's not working. Can somebody help?
2 件のコメント
採用された回答
Torsten
2024 年 8 月 4 日
編集済み: Torsten
2024 年 8 月 4 日
clear all; close all; clc
rng(200724)
%mean and standard deviation of a given sample (sample of Yi)
mu_c = 4432.62; var_c= 533130.21;
%lognormal parameters
var_log = log(var_c/mu_c^2+1); sig_log = sqrt(var_log);
mu_log = -var_log/2 +log(mu_c);
%Compound-Poisson distribution
lam = 570; %poisson distribution parameter
nsims = 10^5; %number of simulations
num = poissrnd(lam,1,nsims); %random numbers extracted from the N poisson variable
x_ptf = zeros(nsims,1); %iniziatiling the storage where the random generated numbers will be allocated
for i = 1:length(num)
x_ptf(i) = sum(lognrnd(mu_log,sig_log,1,num(i))); %building randomly generated numbers
end
[cdf, X_ptf] = ecdf(x_ptf);
figure(1)
plot(X_ptf,gradient(cdf)./gradient(X_ptf))
ylim([0 6e-4])
figure(2)
plot(X_ptf,cdf)
figure(3)
histogram(x_ptf,'Normalization','pdf')
figure(4)
histogram(x_ptf,'Normalization','cdf')
2 件のコメント
Torsten
2024 年 8 月 4 日
編集済み: Torsten
2024 年 8 月 4 日
1) X_ptf: contains the randomly generated values, where each value is only repeted once
X_ptf = unique(x_ptf)
But I doubt that values will exactly repeat.
2) p = for each value in X_ptf i get the montecarlo approximation of the theoretical probability.
Since the distribution is continuous, p = 0 for each value in X_ptf.
A method that is often used to approximate the empirical pdf is to assume a distribution type (e.g. a normal distribution in the below case) and to fit its parameters best-possible to approximate the given data:
clear all; close all; clc
rng(200724)
%mean and standard deviation of a given sample (sample of Yi)
mu_c = 4432.62; var_c= 533130.21;
%lognormal parameters
var_log = log(var_c/mu_c^2+1); sig_log = sqrt(var_log);
mu_log = -var_log/2 +log(mu_c);
%Compound-Poisson distribution
lam = 570; %poisson distribution parameter
nsims = 10^5; %number of simulations
num = poissrnd(lam,1,nsims); %random numbers extracted from the N poisson variable
x_ptf = zeros(nsims,1); %iniziatiling the storage where the random generated numbers will be allocated
for i = 1:length(num)
x_ptf(i) = sum(lognrnd(mu_log,sig_log,1,num(i))); %building randomly generated numbers
end
phat = mle(x_ptf)
x = linspace(min(x_ptf),max(x_ptf),1000);
hold on
plot(x,normpdf(x,phat(1),phat(2)))
histogram(x_ptf,'Normalization','pdf')
hold off
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!