Just hours ago, I posted my first set of functions for R to determine the sample size for a known population. Then, I had to update that post to reflect my newfound knowledge, and now, I thought I would update again, so that the best functions I came up with would all be in one place.
There are two functions, sample.size.table() and sample.size() which you can easily load in R by typing source("http://news.mrdwab.com/samplesize") at the command prompt.
> sample.size.table(c.lev=c(90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 99.9,
+99.99, 99.999, 99.9999), population =100)
Suggested sample sizes at different confidence levels
Population =100
Margin of error =5%
Response distribution =50%
Confidence Level Sample Size
190%73291%74392%76493%77594%78695%80796%81897%83998%851099%871199.9%921299.99%941399.999%951499.9999%96
Unlike the original function I had written, this one allows you to enter any values your heart desires (logical values would be from 1 to 99.99-something) and even lets you enter an array of numbers like we did in the example above. Pretty spiffy, right?
sample.size()
If you don’t care for a whole array of results, you might be more interested in simply using the sample.size() function, which looks like this:
> sample.size(c.lev=97, population =300)
Recommended sample size for a population of 300 at a 97% confidence level
Population =300
Confidence level =97
Margin of error =0.05
Response distribution =0.5
Recommended sample size =183
Now, I guess we need to see if this post was made prematurely too!
There, you’ll find any updates or any functions I’ve added–like a new function to determine the confidence interval if you know the sample size, the population, and the confidence level.
There, you’ll find any updates or any functions I’ve added–like a new function to determine the confidence interval if you know the sample size, the population, and the confidence level.
Enjoy!
Shanti Gupta
Ananda, This is really useful in learning how to calculate sample size with confidence interval.
http://news.mrdwab.com mrdwab
Shanti,
The calculation part is useful, but what I like most is being able to see multiple scenarios in a single place. For instance, what would our samples be at different confidence levels? What about different margins of error? Using this function–or slightly modified versions of this function, it is easy to see how changing these values would affect your sample size.
Prashanth NS
Thanks! Very useful.
http://ananda.mahto.info Ananda
You’re welcome.
Just out of curiosity, do you use R at the Institute of Public Health, Bangalore?
http://news.mrdwab.com mrdwab
You’re welcome.
Just out of curiosity, do you use R at your work? I’m curious about R’s uptake in India’s professional sector.
—- On Wed, 22 Jun 2011 11:45:49 +0530 Disqus <> wrote —-
The new sample size calculator for R (already)
aka “Maybe I shouldn’t post so quickly”
Just hours ago, I posted my first set of functions for R to determine the sample size for a known population. Then, I had to update that post to reflect my newfound knowledge, and now, I thought I would update again, so that the best functions I came up with would all be in one place.
There are two functions,
sample.size.table()andsample.size()which you can easily load in R by typing source("http://news.mrdwab.com/samplesize") at the command prompt.Here’s some more information about each.
sample.size.table()
The new code looks like this:
What’s good about it or when do you use it? Now, you can specify the confidence levels you want to experiment with. See the following example:
Unlike the original function I had written, this one allows you to enter any values your heart desires (logical values would be from 1 to 99.99-something) and even lets you enter an array of numbers like we did in the example above. Pretty spiffy, right?
sample.size()
If you don’t care for a whole array of results, you might be more interested in simply using the
sample.size()function, which looks like this:It’s pretty easy to use. Here’s an example:
Now, I guess we need to see if this post was made prematurely too!
Related posts (possibly):