How to calculate real probability of data
6 views (last 30 days)
Show older comments
Hello, I have a slight question which maybe really simple but am getting stack somehow. Suppose we have a measured data say A=5*rand(1000,1). Suppose am to find the probability distribution of the data, I assume I would easily do this via histogram plot as the one inserted below. Which woul give probabilty distribution of the data in an histogram plot. My question is, is there a way I can get the probability values in a matrix of the same dimenions as A. I mean the vallues that were used to plot the histogram, is there a way I can extract this information?
histogram(A,'Normalization','probability')
0 Comments
Accepted Answer
Paul
on 13 Jun 2023
"is there a way I can get the probability values in a matrix of the same dimenions as A."
The number of bins in the histogram will always, or very nearly always, be less than number of elements in A. So I don't think this will be possible.
"I mean the vallues that were used to plot the histogram, is there a way I can extract this information?"
histogram returns an object from which the properties of the the histogram can be obtained via dot indexing:
rng(100);
A = 5*rand(1000,1);
h = histogram(A,'Normalization','probability');
h.Values % values of the bin heights
If the elements of A are supposed to be samples from a continuous distribution, then it may be better to use the pdf normalization of histogram. I guess it depends on how the histogram is going to be used.
0 Comments
More Answers (1)
Torsten
on 13 Jun 2023
Edited: Torsten
on 13 Jun 2023
Usually, one assumes that the underlying distribution for the realizations in A is continuous. This implies that each element in A has probability 0. You could extract probabilities for an element to be in a certain interval, e.g. In the following example, if you take as interval [x(i),x(i+1)], then the probability that the random variable gets a value within this interval is approximately f(i+1)-f(i).
A = 5*rand(1000,1);
[f,x] = ecdf(A);
plot(x,f)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!