Re: [R] sample size estimation for count (poisson?) data?

From: Shawn Morrison <>
Date: Thu, 13 Nov 2008 14:43:39 -0700

Thanks. I did the search before I posted and found those threads. However, it does not seem to do what I want. All I want to do is estimate the sample size for a point estimate, not do a GLM. I just want the mean within a margin of error, and to a given CI.

I've tried writing some code to do a simulation (below). Will this do the job?

#Generate data from Poission distribution, with lambda = 5 data = rpois(200, lambda = 5)
mean(data); var(data)

#Parameter Estimates
moe = 0.03 # margin of error = +/- 3%
sample.size = 168 # number of hunters to sample

#Draw sample size from population, calc mean. Run 10,000 iterations d = numeric(10000)
for (i in 1:10000) {
samp = (sample(data, sample.size, replace = FALSE)) d[i] = mean(samp)

#What are the bounds on the values that correspond to the margin of error?

#values from 'd' based on 90% confidence intervals q25=quantile(d, 0.05)

#top row = bounds on the mean from the margin of error, second row = bounds based on simulated data and sample size, third row = 1 = true, 0 = false in terms of the sample size being adequate to meet requirements of the margin of error.
output=rbind(cbind(lower,upper), cbind(q25,q95), cbind(q25>lower, q95<upper))
row.names(output) = c("known", "estimated","True/False") output

On 12-Nov-08, at 4:41 PM, David Winsemius wrote:

> The first hit for search on "sample size" and "poisson" on Baron's
> search engine web interface appears on target:
> Getting the same result from your console window requires a couple
> of extra back-slashes:
> > RSiteSearch(""sample size" poisson")
> Error: syntax error
> > RSiteSearch("\"sample size\" poisson")
> A search query has been submitted to
> The results page should open in your browser shortly.
> --
> David Winsemius
> Heritage Labs
> On Nov 12, 2008, at 2:46 PM, Shawn Morrison wrote:
>> Is there a function in R that will allow me to estimate the sample
>> size required from count data (poisson data?), given the known
>> variance and desired margin of error and confidence interval?
>> My specific data set will be based on a survey of hikers that will be
>> asked about the number of animals of species 'x' they observed during
>> a given period. I need to know the number of hikers to interview. ie,
>> I would like to calculate the mean number of species 'x' +/- margin
>> of
>> error with 95% confidence.
>> This is a simple exercise for normally distributed continuous data,
>> but I'm running into roadblocks for count data.
>> Sincerely,
>> Shawn Morrison
>> [[alternative HTML version deleted]]
>> ______________________________________________
>> mailing list
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 14 Nov 2008 - 07:07:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 14 Nov 2008 - 07:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive