Sampling Variation SOCL 3633 Research Methods · Lab 5 · Midwestern State University
Today you treat the 21,483 people in our GSS data as a whole population, draw random samples from it, and watch what happens to the answer. Every student will get different numbers from the random samples. That is what the lab is about, not a mistake. Keep this page open next to RStudio and work through the tabs in order. Before you leave, you submit two things in the Lab 5 submission on D2L: your response sheet and the picture file of your own chart.
Get set up
Two new tools today
slice_sample(gss, n = 50) gives a random sample of 50 people. Each time you run it, you get a different 50.replicate(500, ...) draws 500 samples in a few seconds.One sample at a time: Steps 2 to 4
Step 2: the answer in the full data
Run mean(gss$relig == "None"). The $ sign picks one column out of the data, so gss$relig is the religion column. As in Lab 1, the mean of TRUE and FALSE answers is the share for whom it is TRUE.
[1] 0.1639901: 16.4 percent of the 21,483 people report no religion. Write it down. Today it is the true value you compare every sample to.Step 3: one random sample of 50
- Put
50in the first blank and run the line. Nothing prints. R stored 50 randomly chosen people asmy_sample. - Put
my_samplein the next blank and run it. Write down the share.
Step 4: two more samples
Run the two Step 3 lines again, twice. Each time R draws a new random sample of 50 and gives a new share. Write down all three. Compare them with the person next to you. Your numbers will not match, and neither of you made an error.
If something goes wrong
| What you see | What to do |
|---|---|
| "object 'my_sample' not found" | The slice_sample() line did not run. Run it first, then the mean() line. |
| The share is 0 or 1 exactly | Check the spelling and capital letter in "None". A misspelled category matches no one. |
A + sign in the Console | A parenthesis is missing. Press Escape in the Console, fix the line, and run it again. |
| A chart block takes a long time | Drawing 500 samples takes a few seconds. Wait for the > prompt to come back before running anything else. |
500 samples: Steps 5 and 6
Step 5: 500 samples of 50
Step 5 has no blanks. Select every line from shares_50 <- down to print(chart_50) and run them together. Each bar shows how many of the 500 samples gave a share in that range. The dashed line is the true value, 16.4 percent.
Step 6: 500 samples of 1,000
- Put
1000in the blank (no comma), then select every line fromshares_1000 <-down toprint(chart_1000)and run them. - Compare the two charts. Both use the same horizontal axis, so you can see the difference directly.
A list that leaves people out: Step 7
Suppose the only list you could sample from included people aged 40 and older, the way the Literary Digest's lists in 1936 left out many people. You draw 500 samples of 2,000 people from that list, twice the size of Step 6.
- Put
40in the blank and run theframe_40line. The>=sign means "greater than or equal to." - Select every line from
shares_frame <-down toprint(chart_frame)and run them.
On your own: Step 8
- Run the
count()line to see the religion groups. - In the three places that say
"Catholic", put a different group, typed exactly as it appears in the list, inside quotation marks. Pick a group with at least 500 people, or try a very small group and see what happens. - Run the lines from
my_group_true <-down toprint(my_chart). - Replace "Write your title here" with a complete sentence of about ten words that says what the chart shows. Run the chart lines again.
- Write one ggsave() line that saves
my_chartwith your last name, for examplesmith_lab5.png, and run it.
Lab 5 response sheet
Answer in complete sentences. Then assemble your answers and paste them into the Lab 5 submission in D2L. In the same submission, upload the picture file of your own chart. Your answers stay on this page and are not sent anywhere until you paste them.
Sources
Lusinchi, Dominic. 2012. "President Landon and the 1936 Literary Digest Poll: Were Automobile and Telephone Owners to Blame?" Social Science History 36(1):23-50.
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. dplyr: A Grammar of Data Manipulation. R package. https://dplyr.tidyverse.org
Wickham, Hadley. 2016. ggplot2: Elegant Graphics for Data Analysis. New York: Springer.
The charts on this page come from one run of the lab script. Because samples are random, your charts will differ a little. The full-data shares are unweighted shares of the gss_cat extract.