Most of regression methods assume that response variables follow some exponential distribution families, e.g. Guassian, Poisson, Gamma, etc. However, this assumption was frequently violated in real world by, for example, zeroinflated overdispersion problem. A number of methods were developed to deal with such problem, and among them, QuasiPoisson and Negative Binomial are the most popular methods perhaps due to that major statistical softwares contain such functions. Unlike Negative Binomial distribution, there is no function for generating QuasiPoisson distributed random variable in R. In this blog, I will show how to generate QuasiPoisson distributed variable using Negative Binomial distribution.
Let variable follows QuasiPoisson distribution, then the variance of should have a linear relationship with the mean of :
where, is called the disperision parameter, and for overdispersion variables , should greater than 1.
If variable follows Negative Binomial distribution, the variance of should have quadratic relationship with the mean of .
Random Negative Binomial variable can be generated in R using function rnbinom:
1 2 3 4 5 

If we can find the relationship between and , then we can use the Negative Binomial distribution to generate QuasiPoisson distributed random variable. The proof process is listed as the following:
So, we can define such a function in R:
1 2 3 

Take an example to diagnose the performance of the above function: and . According to the relationship , the generated variable should have variance arround 15.
1 2 3 4 5 6 

So, it works!
Rbloggers.com offers daily email updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...