[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: probability mass function for a binomial distribution |

Date |
Sun, 29 Jun 2008 18:37:44 +0100 |

Readers following along should note the renaming of various functions in this territory from Stata 9 to Stata 10. Stata 10 users can see -help whatsnew9to10-. That is, Carlo, as he signalled, is using Stata 9. Stata 9's -Binomial()- is Stata 10's -binomialtail()-. -Binomial()- continues to work. Thus I think this appearance of being undocumented is in fact a side-effect of name change. Nick n.j.cox@durham.ac.uk Steven Samuels I agree with Nick's advice to construct the functions on first principles whenever possible. Interestingly, Carlo has discovered the apparently undocumented "survival' function Binomial(k,n,p) equal to P(X>=k), whereas the documented function binomial(k,n,p) is P(X<=k). Here is a version of Carlo's program with a correction for k= 20. -Steve /*---------------------------begin example-------------------------*/ drop _all clear set obs 21 g id=_n-1 g n=20 g k=_n-1 g p=.2 g double Binomial=Binomial( n, k, p) g double PMF_Binomial=Binomial[_n]- Binomial[_n+1] in 1/20 replace PMF_Binomial=Binomial[_n] in 21 //Correction g double PMF2 = 0.2^k * 0.8^(20 - k) * comb(20, k) list id n k p Binomial binomial PMF* /*--------------------------end example----------------------------*/ On Jun 29, 2008, at 11:26 AM, Nick Cox wrote: > What is available as a defined function shows up a trade-off > problem. It > wouldn't be difficult to define a thousand functions, but then some > people might complain about the complexity of the list and the > difficulty of finding a solution. > > Otherwise put, I guess the answer to Carlo's question is that Stata > users -- unlike spreadsheet users, it seems --- are paid the > compliment > of knowing enough statistics to work this out from first principles: > > gen double bmp = p^k * (1 - p)^(20 - k) * comb(20, k) > > Note in passing two other details: > > I prefer to use -double-s here. > > Putting constants into variables isn't necessary: > > gen double bmp = 0.2^k * 0.8^(20 - k) * comb(20, k) > > In cases like this the advantage of a canned function over a one-line > solution using another canned function would be pretty small. > > Nick > n.j.cox@durham.ac.uk > > Carlo Lazzaro > > I have probably found out the answer to my last Friday thread. > I do hope this may be useful for someone else on the list. > However, a little concern remains about the lack among Stata 9.2/SE > commands > of an in-built for calculating the (probably too trivial) probability > mass > function for a binomial distribution, which is instead available > within > the > most widespread spreadsheets. > One more time, my grateful thought go out to Steve and Nick (in > order of > appearance in my incoming e-mail folder) for pointing me out the > importance > of a step-by-step research in dealing with Stata troubles. > > ---------------------------begin example------------------------- > set obs 21 > g id=_n-1 > g n=20 > g k=_n-1 > g p=.2 > g Binomial=Binomial( n, k, p) > g PMF_Binomial=1- Binomial if id==20 > replace PMF_Binomial=Binomial[_n]- Binomial[_n+1] in 1/20 > --------------------------end example---------------------------- > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**R: st: probability mass function for a binomial distribution***From:*"Carlo Lazzaro" <carlo.lazzaro@tin.it>

**RE: st: probability mass function for a binomial distribution***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: probability mass function for a binomial distribution***From:*Steven Samuels <sjhsamuels@earthlink.net>

- Prev by Date:
**Re: AW: st: 3 Level - LMM - Number of clusters?** - Next by Date:
**Re: st: post oaxaca decomposition** - Previous by thread:
**Re: st: probability mass function for a binomial distribution** - Next by thread:
**RE: st: probability mass function for a binomial distribution** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |