Consider the following figures for a 2x1 vector in Matlab with a probability distribution that is a mixture of two Gaussian components.
P=10^3; %number draws v=1; %First component mu_a = [0,0.5]; sigma_a = [v,0;0,v]; %Second component mu_b = [0,8.2]; sigma_b = [v,0;0,v]; %Combine MU = [mu_a;mu_b]; SIGMA = cat(3,sigma_a,sigma_b); w = ones(1,2)/2; %equal weight 0.5 obj = gmdistribution(MU,SIGMA,w); %Draws RV_temp = random(obj,P);%Px2 % Transform each component of RV_temp into a uniform in [0,1] by estimating the cdf. RV1=ksdensity(RV_temp(:,1), RV_temp(:,1),'function', 'cdf'); RV2=ksdensity(RV_temp(:,2), RV_temp(:,2),'function', 'cdf');
Now, if we check whether RV1 and RV2 evenly distributed on [0,1] , doing
ecdf(RV1) ecdf(RV2)
we see that RV1 evenly distributed on [0,1] (the empirical cdf is close to the 45 degree line), but RV2 is not.
I do not understand why. It seems that the farther mu_a(2) and mu_b(2) , the worse the work with ksdensity with a reasonable number of draws. Why?