sample.h: Generate random deviates from zero-inflated or hurdle models

Description Usage Arguments Details Value Reference Examples

View source: R/sample.h.r

Description

Generate random deviates from zero-inflated or hurdle Poisson, negative binomial, beta binomial and beta negative binomial models.

Usage

1
2
3
4
5
sample.h(N, phi, distri = "poisson", lambda = NA, r = NA, p = NA,
  alpha1 = NA, alpha2 = NA, n = NA)

sample.zi(N, phi, distri = "poisson", lambda = NA, r = NA, p = NA,
  alpha1 = NA, alpha2 = NA, n = NA)

Arguments

N

The sample size. Should be a positive number. If it is not an integer, N will be automatically rounded up to the smallest integer that no less than N.

phi

The structural parameter φ, should be a positive value within (0,1).

distri

The corresponding standard distribution. Can be one of {'poisson','nb','bb', 'bnb'}, which corresponds to Poisson, negative binomial, beta binomial and beta negative binomial distributions respectively.

lambda

A value for the parameter of Poisson distribution. Should be a positive number.

r

the number of success before which m failures are observed, where m is a random variable from negative binomial or beta negative binomial distribution. Must be a positive number. If it is not an integer, r will be automatically rounded up to the smallest integer that no less than r.

p

The probability of success, should be a positive value within (0,1).

alpha1

The first shape parameter of beta distribution. Should be a positive number.

alpha2

The second shape parameter of beta distribution. Should be a positive number.

n

The number of trials. Must be a positive number. If it is not an integer, n will be automatically rounded up to the smallest integer that no less than n.

Details

By setting distri=poisson, sample.h and sample.zi simulates N random deviates from hurdle and zero-inflated Poisson distribution, respectively, and so on forth. For arguments with length larger than 1, only the first element will be used.

Arguments r and p are for the use of zero-inflated and hurdle negative binomial distributions. alpha1, alpha2 and n are for zero-inflated and hurdle beta binomial distributions. r, alpha1 and alpha2 are used in zero-inflated and hurdle beta negative binomial distributions.

The procedure of generating random deviates follows the work of Aldirawi et al. (2019). The algorithm calls functions for standard distributions to simulate the non-zero samples. Random deviates from standard Poisson and negative binomial distributions can be generated by basic R function rpois and rnbinom. Functions rbbinom and rbnbinom are available for standard beta binomial and beta negative binomial distributions in R package extraDistr.

Value

A vector of length N containing non-negative integers from the zero-inflated or hurdle version of distribution determined by distri.

Reference

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
t1=sample.h(N=2000,phi=0.2,distri='Poisson',lambda=5)  ##hurdle poisson random values
t2=sample.h(N=2000,phi=0.2,distri='nb',r=10,p=0.6)   ##hurdle negative binomial
t3=sample.h(N=2000,phi=0.2,distri='bb',alpha1=8,alpha2=9,n=10)   ##hurdle beta binomial
##hurdle beta negative binomial.
t4=sample.h(N=2000,phi=0.2,distri='bnb',r=10,alpha1=8,alpha2=9)

t1=sample.zi(N=2000,phi=0.2,distri='Poisson',lambda=5)  ##zero-inflated poisson random values
t2=sample.zi(N=2000,phi=0.2,distri='nb',r=10,p=0.6)   ##zero-inflated negative binomial
t3=sample.zi(N=2000,phi=0.2,distri='bb',alpha1=8,alpha2=9,n=10)   ##zero-inflated beta binomial
##zero-inflated beta negative binomial
t4=sample.zi(N=2000,phi=0.2,distri='bnb',r=10,alpha1=8,alpha2=9)

iZID documentation built on Nov. 6, 2019, 5:08 p.m.