Normalization of probability distribution function
Show older comments
I'm trying to obtain a probability distribution curve with an area equal to 1. I have a dataset of about 3 million values ranging from 0 to 3.5 but this range changes depending on other input parameters irrelevant to my question. I'm basically trying to assign probabilities from 0 to 1 based on experimental data to later apply a Monte Carlo but for some reason I can't figure out why the area under my distribution curve is much larger than 1 and I can't seem to find a way to normalize it. Here is my code pertaining the issue and a snippet of the figure I obtain. Thank you so much in advance to anyone that helps.
EDIT: The value for the variable "area" is actually 1, I just can't seem to visualize how the probabilities amount to 1 in the y-axis.
% Compute the kernel density estimation for electron energy distribution
% from main ion
[f,xi] = ksdensity(Electron_info(:,2));
% Compute the area under the curve
area = trapz(xi,f);
% Normalize the kernel density estimate by the area
f_norm = f/area;
% plot the KDE curve
figure(1)
plot(xi, f_norm,'r')
hold on
% Set plot properties
legend('Ion excitation')
xlabel('Electron Energy (eV)')
ylabel('Probability Density')
title('Electron Energy Distribution')
xlim([0 3.5])
set(gcf, 'Color','w')

Accepted Answer
More Answers (1)
I think the kernel density is already normalized ...
From the documentation:
[f,xi] = ksdensity(x) returns a probability density estimate, f, for the sample data in the vector or two-column matrix x. The estimate is based on a normal kernel function, and is evaluated at equally-spaced points, xi, that cover the range of the data in x. ksdensity estimates the density at 100 points for univariate data, or 900 points for bivariate data.
If you want to see the cumulated area under the curve, use
[f,xi] = ksdensity(Electron_info(:,2),'Function','cdf');
2 Comments
Jorge Fernandez
on 25 Apr 2023
Torsten
on 25 Apr 2023
The probability density function gives information about the probability for an interval of x-values. The probability to get a single x-value for a continuous distribution is always 0.
Categories
Find more on Exploration and Visualization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!