フィルターのクリア

How to build an empiric cdf/pdf of a compound poisson continuos distribution

49 ビュー (過去 30 日間)
simone
simone 2024 年 8 月 4 日 13:14
編集済み: Torsten 2024 年 8 月 4 日 17:20
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
Torsten 2024 年 8 月 4 日 14:12
x_con is undefined when you use the command
[cdf, X_ptf] = ecdf(x_con);
simone
simone 2024 年 8 月 4 日 14:14
my bad, fixed

サインインしてコメントする。

採用された回答

Torsten
Torsten 2024 年 8 月 4 日 14:25
編集済み: Torsten 2024 年 8 月 4 日 14:56
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 件のコメント
simone
simone 2024 年 8 月 4 日 15:18
Thanks for your reply first of all! Secondly this isn't quite what im trying to do. I get the graphs are pretty important, but still i need a more quantitative results. Right now i need to build two vectors: 1) X_ptf: contains the randomly generated values, where each value is only repeted once 2) p = for each value in X_ptf i get the montecarlo approximation of the theoretical probability.
Torsten
Torsten 2024 年 8 月 4 日 15:26
編集済み: Torsten 2024 年 8 月 4 日 17:20
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)
phat = 1x2
1.0e+06 * 2.5273 0.1077
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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!

Translated by