5

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.

tdy
  • 36,675
  • 19
  • 86
  • 83
vitalik
  • 51
  • 3

3 Answers3

2

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
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
1

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]
image_doctor
  • 501
  • 3
  • 6
1

You could use EmpiricalDistribution :

f = EmpiricalDistribution[data]

Mean[f]
(* 1/5 *)

Expectation[x^3, x \[Distributed] f]
(* 101/6655 *)

Moment[f, 2]
(* 31/605 *)
b.gatessucks
  • 1,242
  • 1
  • 15
  • 19