An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20050912/8d8f9e91/attachment.pl
poisson mean hypothesis
5 messages · Jan Wijffels, Dimitris Rizopoulos, Thomas Lumley +1 more
you could use something like the following (in case of two-group
comparisons make the proper adjustements):
pois.test <- function(x, alternative = c("two.sided", "less",
"greater"), mu){
alternative <- match.arg(alternative)
if (missing(mu) || (length(mu) != 1 || is.na(mu)))
stop("'mu' must be a single number")
nx <- length(x)
mu.x <- mean(x)
stat <- (mu.x - mu) / sqrt(mu.x/nx)
p.value <- switch(alternative,
"two.sided" = 2 * pnorm(-abs(stat)),
"less" = pnorm(stat),
"greater" = pnorm(stat, lower = FALSE))
list("sample mean" = mu.x, "null mean" = mu, "alternative" =
alternative,
statistic = stat, p.value = p.value)
}
################
y <- rpois(50, 5)
pois.test(y, alt = "g", mu = 4)
y <- rpois(30, 15)
pois.test(y, alt = "l", mu = 16)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Jan Wijffels" <Jan.Wijffels at ucs.kuleuven.be>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, September 12, 2005 10:01 AM
Subject: [R] poisson mean hypothesis
Dear R-users, Is there a way to get p-values for a one-sided hypothesis test about a poisson mean? Thanks, Jan Wijffels University Center for Statistics W. de Croylaan 54 3001 Heverlee Belgium tel: +32 (0)16 322784 fax: +32 (0)16 322831 <http://www.kuleuven.be/ucs> http://www.kuleuven.be/ucs Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Dimitris,
Thanks for the test. But you are using a normal approximation to the
poisson distribution. This is not applicable in my case. I was more
looking for an exact test. Probably based on Garwood's (1936) confidence
interval. If there is already an R implementation available, than this
would be helpful for me.
Jan
-----Original Message-----
From: Dimitris Rizopoulos [mailto:dimitris.rizopoulos at med.kuleuven.be]
Sent: maandag 12 september 2005 11:33
To: Jan Wijffels
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] poisson mean hypothesis
you could use something like the following (in case of two-group
comparisons make the proper adjustements):
pois.test <- function(x, alternative = c("two.sided", "less",
"greater"), mu){
alternative <- match.arg(alternative)
if (missing(mu) || (length(mu) != 1 || is.na(mu)))
stop("'mu' must be a single number")
nx <- length(x)
mu.x <- mean(x)
stat <- (mu.x - mu) / sqrt(mu.x/nx)
p.value <- switch(alternative,
"two.sided" = 2 * pnorm(-abs(stat)),
"less" = pnorm(stat),
"greater" = pnorm(stat, lower = FALSE))
list("sample mean" = mu.x, "null mean" = mu, "alternative" =
alternative,
statistic = stat, p.value = p.value)
}
################
y <- rpois(50, 5)
pois.test(y, alt = "g", mu = 4)
y <- rpois(30, 15)
pois.test(y, alt = "l", mu = 16)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Jan Wijffels" <Jan.Wijffels at ucs.kuleuven.be>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, September 12, 2005 10:01 AM
Subject: [R] poisson mean hypothesis
Dear R-users, Is there a way to get p-values for a one-sided hypothesis test about a poisson mean? Thanks, Jan Wijffels University Center for Statistics W. de Croylaan 54 3001 Heverlee Belgium tel: +32 (0)16 322784 fax: +32 (0)16 322831 <http://www.kuleuven.be/ucs> http://www.kuleuven.be/ucs Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Use ppois(x,lambda), which gives P(X<=x) for mean=lambda. Eg: lower one-sided test for observing no events with mean of 3.4
ppois(0,3.4)
[1] 0.03337327 upper one-sided test for observing 8 events with a mean of 3.4 (need the -1 to include 8 in the rejection region)
ppois(8-1,3.4,lower.tail=FALSE)
[1] 0.02307394 If you want an exact confidence interval there is a formula involving the quantiles of the gamma distribution (ie the qgamma() function) that I can't remember off hand. It might even be Garwood's formula. -thomas
On Mon, 12 Sep 2005, Jan Wijffels wrote:
Dimitris,
Thanks for the test. But you are using a normal approximation to the
poisson distribution. This is not applicable in my case. I was more
looking for an exact test. Probably based on Garwood's (1936) confidence
interval. If there is already an R implementation available, than this
would be helpful for me.
Jan
-----Original Message-----
From: Dimitris Rizopoulos [mailto:dimitris.rizopoulos at med.kuleuven.be]
Sent: maandag 12 september 2005 11:33
To: Jan Wijffels
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] poisson mean hypothesis
you could use something like the following (in case of two-group
comparisons make the proper adjustements):
pois.test <- function(x, alternative = c("two.sided", "less",
"greater"), mu){
alternative <- match.arg(alternative)
if (missing(mu) || (length(mu) != 1 || is.na(mu)))
stop("'mu' must be a single number")
nx <- length(x)
mu.x <- mean(x)
stat <- (mu.x - mu) / sqrt(mu.x/nx)
p.value <- switch(alternative,
"two.sided" = 2 * pnorm(-abs(stat)),
"less" = pnorm(stat),
"greater" = pnorm(stat, lower = FALSE))
list("sample mean" = mu.x, "null mean" = mu, "alternative" =
alternative,
statistic = stat, p.value = p.value)
}
################
y <- rpois(50, 5)
pois.test(y, alt = "g", mu = 4)
y <- rpois(30, 15)
pois.test(y, alt = "l", mu = 16)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Jan Wijffels" <Jan.Wijffels at ucs.kuleuven.be>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, September 12, 2005 10:01 AM
Subject: [R] poisson mean hypothesis
Dear R-users, Is there a way to get p-values for a one-sided hypothesis test about a poisson mean? Thanks, Jan Wijffels University Center for Statistics W. de Croylaan 54 3001 Heverlee Belgium tel: +32 (0)16 322784 fax: +32 (0)16 322831 <http://www.kuleuven.be/ucs> http://www.kuleuven.be/ucs Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm [[alternative HTML version deleted]]
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Thomas Lumley <tlumley at u.washington.edu> writes:
Use ppois(x,lambda), which gives P(X<=x) for mean=lambda. Eg: lower one-sided test for observing no events with mean of 3.4
ppois(0,3.4)
[1] 0.03337327 upper one-sided test for observing 8 events with a mean of 3.4 (need the -1 to include 8 in the rejection region)
ppois(8-1,3.4,lower.tail=FALSE)
[1] 0.02307394 If you want an exact confidence interval there is a formula involving the quantiles of the gamma distribution (ie the qgamma() function) that I can't remember off hand. It might even be Garwood's formula.
Or you can clone the procedure in binom.test. In fact, using binom.test with a sufficiently large n is a rather decent "cheat":
binom.test(5,1e6)$conf * 1e6
[1] 1.623488 11.668293 attr(,"conf.level") [1] 0.95
ppois(4,1.623488)
[1] 0.975
ppois(5,11.668293)
[1] 0.02500060 The qgamma-based interval would seem to be from
qgamma(.025, 5)
[1] 1.623486 to
qgamma(1 - .025, 5 + 1)
[1] 11.66833 Notice that this is obtained as the intersection of the two one-sided intervals, each at half the nominal alpha level. There are other possible definitions (e.g. invert the two sided test), but this one has the advantage of being computable.
O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907