从R中的零膨胀分布中随机选择值 [英] Randomly selecting values from a zero inflated distribution in R

查看:137
本文介绍了从R中的零膨胀分布中随机选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,谢谢您的帮助!



前一段时间,我问了

我在上一个问题中创建的向量是二进制的,现在我想生成一个加权向量(即与有界整数)。我从具有长尾巴的零膨胀或拟泊松分布中进行采样,因此选择零的可能性比另一个值高得多,但是选择大值(例如63)的可能性有限。 / p>

我可以使用rpois从泊松分布中选择值并创建给定长度的向量。这与我想做的类似,因此我将以它为例。

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

将从泊松分布中选择的特定数量的值分配给矢量。无论如何,它使拟泊松或零膨胀?

此处有很多不同的发行版: http://cran.r-project.org/web/views/Distributions.html



表示零泊松...

  install.packages( gamlss.dist)
库(gamlss.dist)

rZIP(n,mu,sigma)

对于准泊松,似乎VGAM软件包中具有准泊松功能,但这似乎是为了拟合而不是生成。看起来Arthur Charpentier确实在这里做某件事-但您确实需要知道要寻找正确的发行版的内容: http://freakonometrics.blog.free.fr/index.php?post/ 2010/10/21 /如何从准Poisson分布中生成变量


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?

解决方案

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

这篇关于从R中的零膨胀分布中随机选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆