Skip to content

generate variable y to produce excess zero in ZIP analysis

3 messages · lili puspita rahayu, S Ellison, Jagat.K.Sheth at wellsfargo.com

#
Maybe something like

rzip <-  function(n, lambda, zip=0.0) {
	#zip is the desired proportion of _excess_ zeros
               if(zip>1.0 || zip <0) stop("zip must be in (0,1)")
               n.zip <- ceiling(zip*n)
               n.pois <- n-n.zip
              sample( c( rpois(n.pois, lambda), rep(0,n.zip) ) )
}

#Example
rzip(50, 3.5, zip=0.5)

Having said that, I'd bet there's a package out there that already does it better...

 S Ellison
*******************************************************************
This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
1 day later
#
Also something like 

## generate zero-inflated Poisson data
n <- 100
x1 <- rnorm(n)
x2 <- rnorm(n)
ind <- rbinom(n,1,1/(1+exp(-1-0.1*x1)))
y <- ifelse(ind,rpois(n,lambda=exp(1+0.2*x2)),0)

There is at least zeroinfl in the CRAN package pscl and fmr in Lindsey's non-CRAN package gnlm for fitting zero-inflated regression models via maximum likelihood.