Statalist


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

Re: st: probability mass function for a binomial distribution -correction


From   Steven Samuels <[email protected]>
To   [email protected]
Subject   Re: st: probability mass function for a binomial distribution -correction
Date   Sun, 29 Jun 2008 13:08:20 -0400

I put an undefined variable in the -list- statement. Sorry.

-Steve

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.

/*---------------------------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 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
[email protected]

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/
*
*   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/



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