Skip to content
Prev 317956 / 398506 Next

generate variable y to produce excess zero in ZIP analysis

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