Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here and there, I mentioned two codes to generated quasiPoisson random variables. And in both of them, the negative binomial approximation seems to be wrong. Recall that the negative binomial distribution is where and in R, a negative binomial distribution can be parametrized using two parameters, out of the following ones
• the size • the probability • the mean Recall also that the variance for a negative binomial distribution should be Here, we consider a distribution such that and . In the previous posts, I used i.e.
```rqpois = function(n, lambda, phi) {
mu = lambda
k = mu/(phi * mu - 1)
r1 = rnbinom(n, mu = mu, size = k)
r2 = rnbinom(n, size=phi*mu/(phi-1),prob=1/phi)
k = mu/phi/(1-1/phi)
r3 = rnbinom(n, mu = mu, size = k)
r4 = rnbinom(n, size=mu/phi/(1-1/phi),prob=1/phi)
r = cbind(r1,r2,r3,r4)
return(r)
}```
but as we can see below, none of those two functions work,
```> N=rqpois(1000000,2,4)
> mean(N[,1])
 2.001992
> mean(N[,2])
 8.000033
> var(N[,1])/ mean(N[,1])
 7.97444
> var(N[,2])/ mean(N[,2])
 4.002022```
with the first one, the expected value is correct, while it is the overdispersion parameter for the second. Now, if we do the maths correctly, it comes which should now work,
```> mean(N[,3])
 2.001667
> mean(N[,4])
 2.002776
> var(N[,3])/ mean(N[,3])
 3.999318
> var(N[,4])/ mean(N[,4])
 4.009647```
So, finally it is better when we do the maths well.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7495576,"math_prob":0.99793816,"size":1909,"snap":"2022-05-2022-21","text_gpt3_token_len":594,"char_repetition_ratio":0.11811024,"word_repetition_ratio":0.1687898,"special_character_ratio":0.3404924,"punctuation_ratio":0.16203703,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9998621,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"im_url_duplicate_count":[null,5,null,3,null,3,null,3,null,3,null,3,null,5,null,3,null,3,null,3,null,5,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-17T02:16:08Z\",\"WARC-Record-ID\":\"<urn:uuid:610903c5-e93a-4d81-a978-f37a68005073>\",\"Content-Length\":\"97270\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:811edad2-b71f-4d6a-8c27-7c6932d6fda5>\",\"WARC-Concurrent-To\":\"<urn:uuid:1f14674d-b2ea-4921-92ad-5789b3e708a0>\",\"WARC-IP-Address\":\"172.64.104.18\",\"WARC-Target-URI\":\"https://www.r-bloggers.com/2010/11/generating-a-quasi-poisson-distribution-version-2/\",\"WARC-Payload-Digest\":\"sha1:EEZVXYBD7WXWLRU3AWV3U64LOHYZEML3\",\"WARC-Block-Digest\":\"sha1:DI5SV2EWUIHMY3Q77RS5YHMCJND5X7CN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662515466.5_warc_CC-MAIN-20220516235937-20220517025937-00332.warc.gz\"}"}