[R] generate variable y to produce excess zero in ZIP analysis
S Ellison
S.Ellison at LGCGroup.com
Wed Feb 20 15:03:25 CET 2013
> Subject: [R] 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
>
>
>
> Dear Mr/Mrs
>
> I am Lili Puspita Rahayu, student from magister third level
> of Statistics in Bogor Agriculture University.
> Mr/
> Mrs, now I'm analyzing the Zero inflated Poisson (ZIP), which
> is a solution of the Poisson regression where the response
> variable (Y) has zero excess. ZIP now I was doing did not use
> real data, but using simulated data in R. Simulations by
> generating data on variables x1, x2, x3 with each size n =
> 100, after which generate data on response variable (Y).
> However, when I generate the variable y, after generating
> variables x1, x2, x3, then the simulation result in the
> variable y that does not have a zero excess. Sometimes just a
> coincidence there are 23%, 25% the proportion of zero on the
> variable Y. This is because I generate variables x1, x2, x3
> with a distribution that has a small parameter values. I've
> been consulting with my lecturer, and suggested to generate
> variable Y that can control the proportion of zero on ZIP
> analysis. I've been trying to make the syntax, but has not
> succeeded.I would like to ask for assistance to R to make the
> syntax to generate simulated Y variables that can control the
> proportion of zeros after generating variables x1, x2, x3 on
> ZIP analysis.Thus, I can examine more deeply to determine how
> much the proportion of zeros on response variable (Y) that
> can be used in the Poisson regression analysis, parametric
> ZIP and ZIP semiparametric.
>
> syntax that I made previously by generating variable y
> without being controlled to produce zero excess in R :
>
> > b0=1.5
> > b1=-log(2)
> > b2=log(3)
> > b3=log(4)
> > n=100
> > x1<-rnorm(n, mean=5, sd=2)
> > x2<-runif(n, min=1, max=2)
> > x3<-rnorm(n, mean=10, sd=15)
> >
> > y<-seq(1,n)
> > for(i in 1:n)
> + {
> + m<-exp(b0+b1*x1[i]+b2*x2[i]+b3*x3[i])
> + yp<-rpois(1,m)
> + y[i]<-yp
> + }
>
>
> I am very
> grateful for the assistance of R.
> I am looking forward to hearing from you. Thank you very much.
>
> Sincerely yours
> Lili Puspita Rahayu
> [[alternative HTML version deleted]]
>
>
*******************************************************************
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
More information about the R-help
mailing list