How can i calculate PDF and CDF of non-parametric distribution?

I want to do probabilistic forecast from point forecast. I do have error distribution (non parametric) from point forecast. How can i calculate PDF and CDF of non-parametric distribution?

 Accepted Answer

I am not certain what your data are. If ,they are appropriate for the function, I would begin with the ecdf function, since it is intended to do exactly what it appears that you want to do. It is usually easier to get the CDE first, then diferentiate it to get the PDF. See the See Also section of that documentation for similar functions.

11 Comments

I have a large time series data: example
Observed: [7445.2, 7479.02, 7581.5, 7673.74, 7735.22, 7780.17, 7828.16, 7869.96, 8028.72, 8180.64, 8223.12, 8415.97, 8515.09]
Predicted: [7438.35, 7502.96, 7548.12, 7683.68, 7797.14, 7846.95, 7887.55, 7922.21, 7950.36, 8160.52, 8318.25, 8261.64, 8474.051073]
Error: [6.8496, -23.9437, 33.3789, -9.9402, -61.9291, -66.7859, -59.3943, -52.2508, 78.3525, 20.1152, -95.1370, 154.3224, 41.0389]
Perhaps —
Observed = [7445.2, 7479.02, 7581.5, 7673.74, 7735.22, 7780.17, 7828.16, 7869.96, 8028.72, 8180.64, 8223.12, 8415.97, 8515.09];
Predicted = [7438.35, 7502.96, 7548.12, 7683.68, 7797.14, 7846.95, 7887.55, 7922.21, 7950.36, 8160.52, 8318.25, 8261.64, 8474.051073];
[fo,xo,folo,foup] = ecdf(Observed, 'Function','cdf');
[fp,xp,fplo,fpup] = ecdf(Predicted, 'Function','cdf');
figure
ecdf(Observed, 'Bounds','on')
hold on
ecdf(Predicted, 'Bounds','on')
% plot(xo(6),fo(6), 'p')
hold off
Ax = gca;
% Ax.Children
ecdfp = Ax.Children(3); % Line Handle For 'legend'
ecdfo = Ax.Children(6); % Line Handle For 'legend'
% ecdfp = Ax.Children(4); % Line Handle For 'legend'
% ecdfo = Ax.Children(7); % Line Handle For 'legend'
% get(Ax)
grid
legend([ecdfo,ecdfp], 'Observed', 'Predicted', 'Location','best')
I am not certain what result you want.
(The commented-out lines allowed me to determine the approopriate legend arguments and DisplayNames for the appropriate stairs plots. I am retaining them here for my reference.)
.
Dear Star Strider, thank you very much for your kind support, much appreciated. Since i am learning probabilistic forecast, and i would like to come up with some results like the attached figure, prediction interval, to show my understanding that there are curtain (%, say 10-95%) for some specific amount demand.
Thank you again.
As always, my pleasure!
I am not certain how to use empiric CDF (or PDF) with respect to predicitions such as those you are modeling, since least-squares regression techniques assume that the errors (residuals) are normally-distributed. The units of the ‘x’ variable in the ecdf estimates and plot also do not seem to have anything in common with the y-axis values in the plot image, so I have no idea how to interpret them. I am not certain what the assump[tions are in the regression or other procedure you are using, or that I would be able to understand them well enough to suggest an approach.
Otherwise, to apply that distribution to a linear or nonlinear regression result to estimate the prediction confidence intervals or parameter confidence intervals would require getting the parameter covariance matrix (this is straightforward with nlinfit) and then using it and the residuals to calculate the prediction confidence interval using the ecdf result. (I have done something similar, however not in many years, and then with the t-distribution.) It would likely be possible to code that process to use the ecdf result instead, simply using interpolation to return the correct inverse probability result.
This was not part of the original post, so I am simply doing my best to provide a reasonable explanation. It might be worthwhile to post another Question specifically addressing the prediction interval problem, along with a reasonably detailed description of the procedure you are using to predict the energy usage and how you want to apply the ecdf result here to it.
Thanks a lot, i understand your point. Since i am new to probabilistic forecast, let me study a bit and understand what you have provided so far. Will post another question as per your suggessions.
As always, my pleasure!
If you have an open-source reference to what you are doing, please post it. I would like to understand more about this. (I may know it by a different name.)
.
I have attached the paper for your refference. i am studying and trying to follow.
That is interesting. I did not previously understand what you were doing to do the predictions.
The MATLAB Deep Learning Toolbox has a number of possible architectures that will llikely do what you want. Among them are: lstm, perceptron, patternnet, feedforwardnet, and narnet. There may also be others that would apply to what you are doing.
At one point, I used neural networks extensively (even programming my own in FORTRAN), however have not used them in more than a decade, so I likely would not be of much help to you with them, especially since the MATLAB functions have likely changed significantly since I last used them.
.
I honestly have no idea.
I have never heard ot that, and so I have no experience with it.
.
my problem here is with inisializing the vector, which is not working for me properly since i have my own obs and fcst, not a vactor with random number. My obs vector should be (13 x 13) and fcst is (13 x 1)
obs: [7445.2, 7479.02, 7581.5, 7673.74, 7735.22, 7780.17, 7828.16, 7869.96, 8028.72, 8180.64, 8223.12, 8415.97, 8515.09];
fcst: [7438.35, 7502.96, 7548.12, 7683.68, 7797.14, 7846.95, 7887.55, 7922.21, 7950.36, 8160.52, 8318.25, 8261.64, 8474.051073];
INPUT
obs: Vector of observations
fcst: Matrix of Ensemble forecast of size N x M. NB: N must equal length(obs), M equals the number of ensemble members
plot_pos: plotting positions that determine cumulative distribution function
OUTPUT
mean_CRPS: Mean of non missing CRPS values
crps_values: A vector (length n) of CRPS values
num: number of non missing CRPS values used to compute mean_CRPS
EXAMPLES:
fcst = rand(1000,1000);
obs = rand(1000,1);
[meanCRPS] = crps(fcst,obs);

Sign in to comment.

More Answers (1)

You get some start towards estimates of the PDF/CDF from histogram and ksdensity. See the help and documentation to those functions. The next step (possibly) for you would then be to convert those estimates into a form (interpolating+extrapolating function?) that suits your forecast implementation - this might be trivial or "challenging" depending on circumstances - but those functions should give you first estimates.
HTH

Community Treasure Hunt

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

Start Hunting!