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

From |
"Carlo Lazzaro" <carlo.lazzaro@tin.it> |

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

Subject |
st: R: How to sample from a Multinomial distribution |

Date |
Thu, 28 Feb 2008 09:09:31 +0100 |

Dear Tiago, Provided that I have understood your question well, I suppose you have to draw random samples from a so called Dirichlet distribution (please, see Briggs A, Schulper M, Claxton K. Decision Modelling for Health Economic Evaluation. Oxford: Oxford University Press, 2006: 116-118). Assuming you start with counts instead of probabilities, I would suggest you to fit three independent gamma distributions (where parameter alfa is the mean^2/SE^2 and parameter beta is SE^2/mean of your original dataset)and use the inverse gamma for random sampling and eventually obtain the probabilities you are seeking. Translating into Stata, it would be like this (please, see the example below). ------------------------------begin example-------------------------- cap program drop simgamma program simgamma, rclass args a1 b1 a2 b2 a3 b3 tempname beta1 beta2 beta3 scalar `beta1' = `b1'*invgammap(`a1',uniform()) scalar `beta2' = `b2'*invgammap(`a2',uniform()) scalar `beta3' = `b3'*invgammap(`a3',uniform()) return scalar beta1 = `beta1' return scalar beta2 = `beta2' return scalar beta3 = `beta3' end clear set obs 10000 g a1=1 g b1=1251 g a2=1 g b2=350 g a3=1 g b3=116 simulate beta1=r(beta1) beta2=r(beta2) beta3=r(beta3), reps(10000) nodots: simgamma a1 b1 a2 b2 a3 b3 egen first_tot= rowtotal ( beta1 beta2 beta3) g pG1= beta1/ first_tot g pG2= beta2/ first_tot g pG3= beta3/ first_tot ----------------end example------------------------------------------------- Please consider that values for a(lfa) and b(eta) in my example should be changed according to your original data. HTH and Kind Regards, Carlo -----Messaggio originale----- Da: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di tiago.pereira@incor.usp.br Inviato: mercoledì 27 febbraio 2008 19.42 A: statalist@hsphsun2.harvard.edu Oggetto: st: How to sample from a Multinomial distribution Dear Statalisters, I have to generate data for a sample, which has three groups (G1, G2 and G3). In this respect, the probability distribution for the G1, G2 and G3 follows a multinomial distribution with parameter vector P = (pG1 ,pG2 ,pG3 ). I have used -genbinomial- to generate the first two groups, and then the last one is calculate by subtraction. Since this is not an elegant way to do that, is the any routine that does in Stata the task above mentioned ? I have not found anything yet. Thanks in advance! Tiago * * 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/

- Prev by Date:
**Re: st: Critical values for stock and yogo test when the clusteroption is used** - Next by Date:
**RE: st: storing tables and values in tables** - Previous by thread:
**st: cannibalizing game platforms for Stata?** - Next by thread:
**st: totals by dpto, sex et al.** - Index(es):

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