IMPORTANT: This is here mostly to remind me of how I solved my problem. You should read The new sample size calculator for R (already) if you really want to use this function.
In the research class at the Tata-Dhan Academy, students are currently getting into sampling, so I thought I would introduce them to R. However, try as I might, I couldn’t find how to do a simple sample size calculation in R if I knew, for instance, the size of the population I wanted to sample from, the confidence level desired, and the confidence interval desired.
Now, I know that there are literally hundreds of such calculators online, but I thought it would be a good excuse for me to learn how to write a function. Here are my first three four functions which demonstrate some of the features available for writing functions in R. These are relatively basic, and there might be better ways to do this (if there are, please share!) but it was still a fun experiment for me.
One of the features I find useful in Excel is the ability to create “pivot” tables. Essentially pivot tables let you summarize big tables of data in different ways, using different variables to “pivot” your data around (hence the name, I guess). Pivot tables are most easily understood through an example, so here’s one done using Excel 2007, and the sort-of-equivalent “Data-Pilot” in OpenOffice.org Calc (OO.o Calc).




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.
Read More »