MATLAB: PDF of a function of a random variable – wrong scale

density functionpdfprobability theoryrandom variableStatistics and Machine Learning Toolbox

I have a random variable x, which is log-normally distributed with PDF lognpdf(x, 0,psi*sqrt(rho)).
I also have a function of x, Fx which PDF I want to find; I am using the following theorem and code:
x = 0.5:0.01:2; rho = 0.1; psi = 0.1834;
%Function of a random variable
Fx = logncdf(0.7./x,0,psi*sqrt(1 - rho));
%PDF of a function of a random variable
PDF_Fx = lognpdf(x, 0,psi*sqrt(rho)).*abs(gradient(x,Fx));
%PDF reaches 30
plot(Fx,PDF_Fx); set(gca,'XLim',[0 0.095]);
%Integral over pdf gives -1
trapz(Fx,PDF_Fx)
The problem is the scale of the resulting PDF which reaches very high levels of around 30. How can a probability of certain value of a rnd variable be 30? However, when I integrate over the PDF with trapz I get -1 which also doesn't make much sense. Is there something in the transformations that messes up with the scale of the PDF that I am not taking into account?

Best Answer

The integral of the PDF has to be 1, but the PDF of an interval is multiplied by the width of the interval when doing the integral.
For example, if you took an interval of width 1/30 and you limited the PDF to one, then the integral could not exceed 1 * (1/30) . So the PDF has to be 30 so that the integral would be 30 * (1/30) = 1
So, do not worry about the PDF exceeding 1.
As for the value coming out -1: your Fx values decrease instead of increasing.
trapz(fliplr(Fx),fliplr(PDF_Fx))