Estimate pdf from a random variable
5 views (last 30 days)
Show older comments
I set up X to be the difference of two uniform random variables U1 and U2. I have constructed the histogram plot, but how would I estimate the PDF of X?
rng;
X = unifrnd(-5, 5, 1000, 1) - unifrnd(-5, 5, 1000, 1);
bincenters = (-5:0.5:5);
bins = length(bincenters);
h = zeros(bins, 1); % pre-allocating h
for i = 1:length(X)
for k = 1:bins
if X(i) > bincenters(k) - 0.5/2 && X(i) <= bincenters(k) + 0.5/2
h(k, 1) = h(k, 1) + 1;
end
end
end
pxest = h/(1000*0.5);
bar(bincenters, pxest)
0 Comments
Answers (1)
Raghava S N
on 21 Nov 2024 at 5:47
To estimate the probability density function of a random variable, the kernel density estimation algorithm can be used. To do this, you can use the “ksdensity” function in MATLAB - https://www.mathworks.com/help/stats/ksdensity.html#:~:text=ksdensity(x)%20returns%20a%20probability%20density%20estimate%2C%20f%2C%20for%20the%20sample%20data%20in%20the%20vector%20or%20two%2Dcolumn%20matrix%20x.
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!