How can obtain the probability density function for a random discreate set of data and fit a custom distribution function ??
8 次查看(过去 30 天)
显示 更早的评论
I have random data. I want to calculate the probability density function. I also fit a custom distribution function which is the
where gamma is the gamma function of n and n is the distribution parameter and x is the variable.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1563519/image.png)
I attached the data. Can you provide the solution for this ??
回答(2 个)
Torsten
2023-12-8
编辑:Torsten
2023-12-8
Use "histogram" to plot the empirical probability density function for your data and use "mle" to estimate n.
Why are there so many data repeated multiple times ? Did you create them artificially ?
8 个评论
Torsten
2023-12-13
x = xlsread('temp_data.xlsx');
pdf = @(x,n)n^n/gamma(n) * x.^(n-1) .* exp(-n*x);
[phat,pci] = mle(x,'pdf',pdf,'Start',1)
hold on
h = histogram(x);
h.Normalization = 'pdf';
y = linspace(0,max(x),100);
plot(y,pdf(y,phat))
hold off
John D'Errico
2023-12-12
编辑:John D'Errico
2023-12-12
Can you write custom code to fit a PDF to data? Yes. It is not that truly difficult, if you know what you are doing. HOWEVER, SHOULD you write custom code to fit a PDF using maximum likelihood estimation? NO. It already exists in MATLAB, Use those codes. Writing your own code to do something already provided to you is a bad idea. If you don't have a clue what you are doing and don't have the skills in such things, then your result will be poor. Use code provided to you by professionals. Even there, you can have problems if you use the code incorrectly or provide it bad data that does not fit the distribution, but at least you give yourself a chance of success.
Now, does your data have a problem? YES. It is not at all random looking. In fact, what you have is not even a set of samples from a distribution, but apparently a cumulative histogram of sorts.
x = xlsread('temp_data.xlsx');
plot(x)
In there I see what appears to be stairsteps in your "data". So these are not samples from a continuous distribution. For example, the first 54 points in that vector are identical. It is not clear how you generated this data, which you claim to have measured.
So first, you need to explain what you have in that data set. How you created it.
2 个评论
Paul
2023-12-13
I think writing one's own code to solve a problem is great way to learn. The "professional" code can be used for comparison.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!