Hi Folks,
Can anybody provide me a simple SAS datastep algorithm for the below question and a statistical explanation for my understanding please
If I have a decision to make how do I calculate the probability of a selection how does one calculate the probability?
For example: What is the probability of me selecting Tea – with sugar – with milk.
What is the formula? 0.5 x 0.5 x 0.5
This is a better question for CrossValidated than here.
P(Tea, sugar, milk)= p(tea)*p(sugar)*p(milk)=0.5*0.5*0.5=1/8
Each odd is 0.5 because there are two options
i.e. choices are tea or coffee so p(tea)=1/2=0.5
and the same logic applies for remaining ingredients.
Another way to calculate this is to list all the possible combinations and see how many times you get your output:
1 out of 8 possible combinations:
Tea|Sugar|Milk
Tea|Sugar|No Milk
Tea|No Sugar|Milk
Tea|No Sugar|No Milk
Coffee|Sugar|Milk
Coffee|Sugar|No Milk
Coffee|No Sugar|Milk
Coffee|No Sugar|No Milk
Sorry. I couldn't see that picture. Maybe it is being block by China.
Hi,
First off, I apologise for that coz it aint opening. Well the picture depicts as follows:
Wish I could get the pic to work, but that's exactly the information.
Hope you are well.
Thanks so much,
Charlotte
I can't see the picture either. I get the message
Description: Could not process your request for the document because it would cause an HTTP proxy cycle. Please check the URL and your browser's proxy settings.
Hi,
Probability selecting Tea – with sugar – with milk is
0.5 x 0.5 x 0.5
Which is aleardy mentioned above in your question.
Well, i noticed that. I'm not understanding the logic though or may be I'm having a blonde moment. lol. I thought it would be 0.5*0.25*0.25*0.25*0.25. I still would like you to explain me the formula if you don't mind.
Sure, tea – with sugar – with milk are 3 independent events each having two possible outcomes. In the given scenario with sugar has prob=0.5, with sugar prob=0.5 and with milk prob=0.5. In the next step we just need to multiply them.
This is a better question for CrossValidated than here.
P(Tea, sugar, milk)= p(tea)*p(sugar)*p(milk)=0.5*0.5*0.5=1/8
Each odd is 0.5 because there are two options
i.e. choices are tea or coffee so p(tea)=1/2=0.5
and the same logic applies for remaining ingredients.
Another way to calculate this is to list all the possible combinations and see how many times you get your output:
1 out of 8 possible combinations:
Tea|Sugar|Milk
Tea|Sugar|No Milk
Tea|No Sugar|Milk
Tea|No Sugar|No Milk
Coffee|Sugar|Milk
Coffee|Sugar|No Milk
Coffee|No Sugar|Milk
Coffee|No Sugar|No Milk
Pedantic note: Assumes the probabilities of the choices are independent.
True
SAS has a function for it:
data _null_;
p=0.5; /*is a numeric probability of success parameter, the success rate of each test*/
n=3; /*is an integer number of independent Bernoulli trials parameter: the total number of the tests*/
m=3;
/*is an integer number of successes random variable: the number of successful test, in your case,
the m is the Maximum: n, as the probability of one success in one trial is the same as all success in all trials*/
prob=PROBBNML(p,n,m)- PROBBNML(p,n,m-1);
put prob=;
run;
Haikuo
Or use the CDF function. The following statements are equivalent:
prob=PROBBNML(p,n,m) - PROBBNML(p,n,m-1);
prob2 = cdf("Binomial",m,p,n) - cdf("Binomial",m-1,p,n);
Thanks for sharing, Rick! CDF function is obviously much more powerful.
Hi Haikuo and Rick,Thank you so much for the Genius help. I can't appreciate enough. Anyways, did you memorise SAS functions or you developed a knack to quickly search for the right now? I am asking this coz your inputs will only help me learn faster.
Cheers,
Charlotte
SAS is big. I don't pretend to know it all, but I've taken the time to learn about the functions that I use over and over. CDF is one of those functions. If you do a lot with univariate distributions in SAS, read this article: Four essential functions for statistical programmers - The DO Loop
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.