Verifying Frequency Probability in Octave

86 Views Asked by At

I asked a question in stats pertaining to the frequency of $N$ events that have weighted outcomes.

I'm doing my own embedded implementation, and would like to check my work. How would I do this in octave? I want to check for the case where $N=15$ using the random events below:

\begin{align*} f_1(0.870292482885583,15)\\ f_2(0.296072459472033,9)\\ f_3(0.239476668131953,6)\\ f_4(0.210507137319701,18)\\ f_5(0.385627406961031,11)\\ f_6(0.340338025468699,10)\\ f_7(0.488128489957119,11)\\ f_8(0.983321258332711,18)\\ f_9(0.092710364886216,11)\\ f_{10}(0.993127281732787,9)\\ f_{11}(0.206742439976538,16)\\ f_{12}(0.0678548007254048,9)\\ f_{13}(0.74522192081138,8)\\ f_{14}(0.114650275403596,15)\\ f_{15}(0.804419665265864,5)\\ \end{align*}

The weights sum to 171. I've run my own implementation and learned that there is a roughly $30\%$ chance that the sum of the weights is greater than or equal to 86.

How do I reach that same conclusion in octave?

1

There are 1 best solutions below

0
On BEST ANSWER

If you want to do a Monte Carlo simulation of the problem:

%%first define N and the probability and weight vectors p,w
k = 1000; %number of simulations to run
sums = sum(double(rand(k,N)<p(:)') * w(:), 2); %sum for each simulation
p_success = mean(sums >= 86); %empirical frequency of the sum being (e.g.) at least 86