Randomly selecting values from a zero inflated distribution in R

佐手、 提交于 2020-01-16 03:52:07

问题


Hello and thanks in advance for the help!

A while back I asked a question about randomly selecting values according to a probability distribution. This is related, but I think it deserves its own post.

The vector I created in the last question was binary, now I would like to generate a weighted vector (ie with bounded integers). I am sampling from a zero-inflated or quasi-poisson distribution with a long tail, so there is a much higher probability of selecting a zero than another value, but there is a finite probability of selecting a large value (eg 63).

I can use rpois to select values from a poisson distribution and create a vector of a given length. This is similar to what I would like to do, so I will use it as an example.

e=seq(0:63)
vec<-c(0,0,0,1,1,1)
ones <- which(vec == 1L)
temp=rpois((sum(vec)),e)
vec[ones]<-temp

This works well for assigning a specific number of values selected from a poisson distribution to a vector. Is there anyway to make it quasi-poisson or zero inflated?


回答1:


There's a big list of the different distributions here: http://cran.r-project.org/web/views/Distributions.html

For zero inflated poisson...

install.packages("gamlss.dist")
library(gamlss.dist)

rZIP(n, mu, sigma)

For quasi-poisson, it looks like there are some capabilities within the VGAM package with quasipoissonff, but that seems to be for fitting rather than generating. It looks like Arthur Charpentier was on to something here - but you really need to know what you're looking for to get the distribution right: http://freakonometrics.blog.free.fr/index.php?post/2010/10/21/How-to-genrerate-variables-from-a-quasi-Poisson-distribution



来源:https://stackoverflow.com/questions/7034648/randomly-selecting-values-from-a-zero-inflated-distribution-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!