Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Csgof does not count var categories with zero observations |
Date | Thu, 7 Jun 2012 09:57:09 +0100 |
Examples . chitesti 315 108 101 32 \ 556*9/16 556*3/16 556*3/16 556*1/16 observed frequencies from keyboard; expected frequencies from keyboard Pearson chi2(3) = 0.4700 Pr = 0.925 likelihood-ratio chi2(3) = 0.4754 Pr = 0.924 +-------------------------------------------+ | observed expected obs - exp Pearson | |-------------------------------------------| | 315 312.750 2.250 0.127 | | 108 104.250 3.750 0.367 | | 101 104.250 -3.250 -0.318 | | 32 34.750 -2.750 -0.467 | +-------------------------------------------+ Mata : obs = (315,108,101,32) : exp = (556/16) * (9,3,3,1) : sum(((obs - exp):^2) :/ exp) .4700239808 : chi2tail(3, sum((obs - exp):^2 :/ exp)) .9254258951 chitesti 60 62 67 68 64 56 62 44 58 67 observed frequencies from keyboard; expected frequencies equal Pearson chi2(9) = 7.4934 Pr = 0.586 likelihood-ratio chi2(9) = 7.9287 Pr = 0.541 +-------------------------------------------+ | observed expected obs - exp Pearson | |-------------------------------------------| | 60 60.800 -0.800 -0.103 | | 62 60.800 1.200 0.154 | | 67 60.800 6.200 0.795 | | 68 60.800 7.200 0.923 | | 64 60.800 3.200 0.410 | |-------------------------------------------| | 56 60.800 -4.800 -0.616 | | 62 60.800 1.200 0.154 | | 44 60.800 -16.800 -2.155 | | 58 60.800 -2.800 -0.359 | | 67 60.800 6.200 0.795 | +-------------------------------------------+ Mata : o = (60, 62, 67, 68, 64, 56, 62, 44, 58, 67) : e = sum(o) / 10 : sum((o :- e):^2 :/ e) 7.493421053 : chi2tail(9, sum((o :- e):^2 :/ e)) .5858880273 With both -chitesti- and Mata, you just type in 0 when appropriate just like any other observed frequency. As said, the help for -chitest- and -chitesti- gives other examples too. On Thu, Jun 7, 2012 at 12:29 AM, Nick Cox <njcoxstata@gmail.com> wrote: > -csgof- is a user-written program from > http://www.ats.ucla.edu/stat/stata/ado/analysis/ > > The Statalist FAQ advises at > http://www.stata.com/support/faqs/res/statalist.html#stata > > "Say what command(s) you are using. If they are not part of official > Stata, say where they come from: the STB/SJ, SSC, or other archives." > > See -chitest- and -chitesti- from -tab_chi- (SSC) for alternatives. > The examples in the help files are pertinent. > > Another alternative is to use Mata. Many chi-square problems reduce to > a few lines of Mata. > > Nick > > On Wed, Jun 6, 2012 at 10:56 PM, Tara Johnson <tjohnsonrogers@gmail.com> wrote: > >> I want to conduct a chi-square goodness of fit test. The problem is I >> have a variable with multiple categories with no observations. When I >> run csgof, Stata does not include the categories with no observations. >> How do I get Stata to count the categories which could be there in >> principle but which in practice don't exist? >> * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/