MATLAB Answers

How to generate mixture of exponential and beta distribution

15 views (last 30 days)
Hello
I have to generate random variable from exponential and beta distribution where a=4 b=7 for beta and lamda=0.5 while p=0.8 How can i generate mixture of both?

  0 Comments

Sign in to comment.

Accepted Answer

Jeff Miller
Jeff Miller on 3 May 2020
Check whether I have interpreted your parameters correctly, but it should look something like this:
lambda = 0.5;
a = 4;
b = 7;
pr_exponen = 0.8;
n = 1000;
e = exprnd(1/lambda,n,1);
b = betarnd(a,b,n,1);
u = rand(n,1);
mix = zeros(n,1);
use_e = u < pr_exponen;
mix(use_e) = e(use_e);
mix(~use_e) = b(~use_e);
figure; histogram(mix);

  4 Comments

Show 1 older comment
Jeff Miller
Jeff Miller on 3 May 2020
You could use e<=0.8 but that would be a different distribution, and one that is not a mixture in the usual meaning of that term. A standard mixture would sometimes include e>0.8, which would not happen if you used e<=0.8
Lakshit Chugh
Lakshit Chugh on 4 May 2020
Ok can you help me i am using the dataset but i am getting mse not valid in the same dataset i am looking to find mse of histogram estimation ?
h = 3.5*s*(length(x)).^(-1/3);
% compute the skew factor (for histograms):
sf = ((2^(1/3))*s) / ( exp(5*s^2/4) * ((s^2 + 2)^(1/3)) * (exp(s^2) - 1)^(1/2) );
h = h*sf;
% get the limits, bins, bin centers etc:
x_lim_left = min(x)-1;
x_lim_rght = max(x)+1;
t0 = x_lim_left;
tm = x_lim_rght;
rng = tm-t0;
nbin = ceil(rng/h);
bins = t0:h:(nbin*h+t0); % <- the bin edges ...
bc = bins(1:end-1)+0.5*h; % <- the bin centers ...
x(find(x<x_lim_left))=x_lim_left;
x(find(x>x_lim_rght))=x_lim_rght;
vk=histc(x,bins); vk(end)=[];
% normalize:
fhat = vk/(n*h);
N_MC = 10;
xinterp = linspace( t0, tm, 15 );
all_mse = zeros(3,length(xinterp),N_MC);
amse = zeros(3,1);
for mci=1:N_MC
%x = exprnd(mu,1,n); % get new data
%x = lognrnd(1,1/2,1,n);
% = std(x);
% the histogram estimate:
[bc,fhat,bins] = norm_ref_rule_w_skew_hist(x);
pdf_approx = interp1(bc,fhat,xinterp,'nearest');
%pdf_approx(pdf_approx>1) = 0.0;
sefx = (pdf_approx - exppdf(xinterp,mu)).^2;
all_mse(1,:,mci) = sefx;
amse(1) = amse(1) + (1/N_MC)*trapz(xinterp,sefx);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!