Estimate pdf from a random variable

5 ビュー (過去 30 日間)
dustin
dustin 2014 年 9 月 3 日
回答済み: Raghava S N 2024 年 11 月 21 日 5:47
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)

回答 (1 件)

Raghava S N
Raghava S N 2024 年 11 月 21 日 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!

Community Treasure Hunt

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

Start Hunting!

Translated by