How to build an empiric cdf/pdf of a compound poisson continuos distribution
49 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1746561/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1746566/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1746571/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1746576/image.png)
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,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 个评论
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)
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!