0
$\begingroup$

I'm trying to create a piecewise function with y values {.1, .2, .342, .353,...,.9} and x-values {1, 2, 3, 4,...,n}. My end goal is to do this: Define a simple discrete probability distribution and then calculate x-values given y-values. For example, given 0.11, I should get back 2. Given 0.05, I should get back 1. Etc.

So far, I've tried

 Piecewise[{distrib[[x]], 0 < x < Length[distrib]}] 

This didn't work (I don't know why)

and

 Distrib = ProbabilityDistribution[distrib[[x]], {x, 1, Length[distrib]}]

This wouldn't let me create an InverseCDF.

Any suggestions?

$\endgroup$
1
$\begingroup$

Here's an example:

x = Range[1, 5];
p = {0.1, 0.1, 0.142, 0.3, 0.358};
data = Transpose[{x, p}];
prob[x_] := Piecewise[{#[[2]], x == #[[1]]} & /@ data, 0]
discrete = ProbabilityDistribution[prob[i], {i, 1, Length[x], 1}] 

Discrete probability distribution

InverseCDF[discrete, 0.11]
(* 2 *)
InverseCDF[discrete, 0.05]
(* 1 *)
$\endgroup$
0
$\begingroup$

I'm not certain of your goals. Are you looking for the following?

f =(1 + Count[yvals, x_ /; x <= #]) &
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.