Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolating Function as PDF in Mathematica

I want to use interpolation of a function as a PDF and be able to use tools like Mean, Probability, CDF and so on. I did the following:

 f = Interpolation[data];
 dist = ProbabilityDistribution[f[x], {x,0,1000}];

And for example when I try:

Mean[dist] //N

it just returns input. The same thing with other other functions.

like image 468
vitalik Avatar asked Oct 08 '22 02:10

vitalik


2 Answers

You could use a discrete distribution:

data = {1, 2, 1, 3, 4};
data = data/Total@data;
f = Interpolation[data];
dist = ProbabilityDistribution[f[x], {x, 1, 5, 1}];
Mean[dist] // N
like image 101
Dr. belisarius Avatar answered Oct 13 '22 10:10

Dr. belisarius


You could also experiment with a SmoothKernelDistrubution.

d = SmoothKernelDistribution[data];

cdf=CDF[d]

Plot[cdf[x], {x, -1, 1}]

Quantile[d, 0.95]

Moment[d, 2]
like image 44
image_doctor Avatar answered Oct 13 '22 10:10

image_doctor