I have 5 distinct events A,B,C,D,E which have relative probability of occurring of 0.1, 0.2, 0.5, 0.5, 0.4 respectively. I would like to plot the probability distribution of 5C2(2 choose 5) or all 10 possible outcomes that can result when choosing 2 possible events out of 5. The y axis should represent the probability of that choice and the x-axis should be the events (ex. AB, AC, DE etc). Events may not be repeatedly chosen (i.e no AA or BB) and once a pair is chosen the order doesn't matter (ex. DE or ED but not both events - only one combination can exist).
So for example:
probability of AB = 0.1*0.2 = 0.02
probability of CE = 0.5 * 0.4 = 0.2
etc.. until we have 10 values plotted
I don't know how to begin with this so would appreciate some help.
I'm not quite sure what you mean. You want a category plot of these pairs? It's just ten, so write them out. One text wave of the pairs and a numeric wave with the values. If you're asking about other ways to plot it: another possibility is to show them on a grid with colour coding for the probabilities.
Where text_wave and prob_wave are the event names and probabilities, created and entered manually before running the program. To display it as described, type
function Probability()wave/T text_wave
wave prob_wave
variable index=0variable choose_n = 3variablei, j, k // number of index variables must equal value of choose_nvariable point_counter = binomial(numpnts(prob_wave),choose_n)make/o/n=(point_counter) combined_prob_wave
make/t/o/n=(point_counter) combined_text_wave
for(i=0;i<numpnts(prob_wave);i+=1)for(j=(i+1);j<numpnts(prob_wave);j+=1)for(k=(j+1);k<numpnts(prob_wave);k+=1)
combined_text_wave[index] = text_wave[i]+text_wave[j]+text_wave[k]
combined_prob_wave[index] = prob_wave[i]*prob_wave[j]*prob_wave[k]
index += 1endforendforendforend
I noticed that in my previous version, the first for loop (for point_counter) was actually just calculating the binomial coefficient, so I replaced this with Igor's built in binomial() function. I've also added a choose_n variable, which is where you enter the choose number (i.e. x in nCx). Beware though, because changing this value is not enough to correctly transition between choose numbers. You'll need to add or remove levels of the nested for loops (adding index variables as needed), but this is pretty straight forward since it should always follow the pattern demonstrated here. This could perhaps be done more elegantly using a do/while structure to eliminate the need to change the code, but I couldn't come up with a way to do this.
March 19, 2015 at 03:24 pm - Permalink
Where text_wave and prob_wave are the event names and probabilities, created and entered manually before running the program. To display it as described, type
display combined_prob_wave vs combined_text_wave
March 19, 2015 at 03:31 pm - Permalink
March 19, 2015 at 08:08 pm - Permalink
I noticed that in my previous version, the first for loop (for point_counter) was actually just calculating the binomial coefficient, so I replaced this with Igor's built in binomial() function. I've also added a choose_n variable, which is where you enter the choose number (i.e. x in nCx). Beware though, because changing this value is not enough to correctly transition between choose numbers. You'll need to add or remove levels of the nested for loops (adding index variables as needed), but this is pretty straight forward since it should always follow the pattern demonstrated here. This could perhaps be done more elegantly using a do/while structure to eliminate the need to change the code, but I couldn't come up with a way to do this.
March 20, 2015 at 08:02 am - Permalink