How do I generate a pdf from some known percentile values

조회 수: 40 (최근 30일)
Christopher Stokes
Christopher Stokes 2021년 10월 12일
댓글: Star Strider 2021년 10월 13일
Hi Matlab community,
I have percentile values that describe a distribution of possible sea level rise magnitudes. I would like to be able to generate a probability density function that closely approximates the actual distribution from which the percentile values were generated. Can anyone suggest how to achieve this please?
Example data:
prctiles = [5 10 30 33 50 67 70 90 95];
SLR = [3.2760 3.5265 4.1286 4.2013 4.5566 4.9151 4.9836 5.6045 5.9105];

채택된 답변

Star Strider
Star Strider 2021년 10월 12일
A slightly different approach —
prctiles = [5 10 30 33 50 67 70 90 95];
SLR = [3.2760 3.5265 4.1286 4.2013 4.5566 4.9151 4.9836 5.6045 5.9105];
B = fminsearch(@(b) norm(prctiles/100 - cdf('Normal',SLR,b(1),b(2))), [SLR(prctiles==50);rand])
B = 2×1
4.5589 0.8095
SLRv = linspace(min(SLR), max(SLR));
yfit = cdf('Normal', SLRv, B(1), B(2));
figure
plot(SLR, prctiles/100, 'p')
hold on
plot(SLRv, yfit, '-r')
hold off
grid
title(sprintf('$p = N(%.2f, %.3f)$',B), 'Interpreter','latex')
legend('SLR','Fitted Noprmal Distribution', 'Location','NW')
Experiment to get different results.
.
  댓글 수: 6
Christopher Stokes
Christopher Stokes 2021년 10월 13일
That's a great solution, thank you! Really appreciate your help and great to see how these optimisation functions can be applied.
Star Strider
Star Strider 2021년 10월 13일
As always, my pleasure!
It was an education for me as well!
.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2021년 10월 12일
Have you seen fitdist() in the Stats toolbox?
Of course you'd be better off with much more data.
  댓글 수: 1
Image Analyst
Image Analyst 2021년 10월 12일
편집: Image Analyst 2021년 10월 12일
Here's an example:
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 17;
SLR = [3.2760 3.5265 4.1286 4.2013 4.5566 4.9151 4.9836 5.6045 5.9105];
% Plot data.
subplot(2, 1, 1);
bar(SLR)
grid on;
title('Original SLR Data', 'FontSize', fontSize);
xlabel('Index', 'FontSize', fontSize);
ylabel('SLR Value', 'FontSize', fontSize);
% Get distribution.
d = fitdist(SLR(:), 'Normal')
% Make curve, plot distribution.
% https://en.wikipedia.org/wiki/Normal_distribution
x = linspace(min(SLR), max(SLR), 1000);
amp = 1 / (d.sigma * sqrt(2*pi));
y = amp * exp(-(1/2) * ((x - d.mu) / d.sigma) .^ 2)
subplot(2, 1, 2);
plot(x, y, 'b-', 'LineWidth', 2);
grid on;
title('Estimated Distribution of SLR', 'FontSize', fontSize);
xlabel('SLR', 'FontSize', fontSize);
ylabel('PDF', 'FontSize', fontSize);
Pick the distribution that fits the theory of what the distribution should actually be. Hopefully you know this in advance. Actually you need to if you're going to model it. Otherwise just normalize your histogram and that is the actual PDF.

댓글을 달려면 로그인하십시오.


Christopher Stokes
Christopher Stokes 2021년 10월 12일
Hi, I have been using that function quite a bit recently and the excellent wrapper function allfitdist() from the file exchange. My problem is that they rely on relatively large data samples from which to build a PDF when what I have is a small number of summary statistics that describe the distribution (i.e. not data samples). I imagine there is a way to use fitdist to do what I need to do, but I can't envisage how this would work.

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by