Testing a Rival Explanation SOCL 3633 Research Methods · Lab 6 · Midwestern State University
Older people in the GSS report more hours of TV a day. Does getting older cause people to watch more TV, or does something else explain the pattern? Today you find the pattern, then test two rival explanations in the data. Keep this page open next to RStudio and work through the tabs in order. Before you leave, you submit two things in the Lab 6 submission on D2L: your response sheet and the picture file of your own chart.
Get set up
Two new tools today
breaks sets where each group ends, and labels names the groups.if_else(rincome == "Not applicable", "No income from work", "Income from work") sorts everyone into two groups.The pattern: Steps 2 and 3
Step 2: keep people with both values
Select all the lines from tv_age <- through the labels line and run them. Then run nrow(tv_age).
Step 3: average TV hours by age group
- Put
age_groupin the blank, select the four lines fromby_age <-, and run them. Then runby_ageto see the table. - Select the chart lines and run them, then
print(age_chart).
If something goes wrong
| What you see | What to do |
|---|---|
| "object 'age_group' not found" | Step 2 did not run all the way. Select every line of Step 2 and run them together. |
| Only one row in a table, or NA averages | A blank is still empty or misspelled. Variable names are lower case. |
| In Step 5, everyone is in "Income from work" | The Step 4 blank is empty or misspelled. Type Not applicable exactly, with a capital N, inside the quotation marks, and run Step 4 again. |
A + sign in the Console | A parenthesis is missing. Press Escape in the Console, fix it, and run all the lines of the step again. |
Rival explanation: work. Steps 4 and 5
Most people 65 and older are retired. People who are not working may have more time for TV at any age. If so, working for pay could be a third factor behind the age pattern.
Step 4: who has income from work?
- Put
Not applicablein the blank, inside the quotation marks, and run the three lines. - Run the next block to see the share of each age group with no income from work.
Step 5: compare age groups within each work group
- Put
workin the blank, select the lines fromby_age_work <-, and run them. Then runby_age_work. - Run the chart lines and
print(work_chart).
On your own: Step 6, marriage
Another rival explanation: married people may watch less TV, and the age groups differ in how many people are married. Test it the same way you tested work.
- In the first blank, put
Married, exactly as it appears in the data, inside the quotation marks. Run those three lines. - In the second blank, put
married, the name of your new variable. Run the lines, thenby_age_married. - Run the chart lines. Look at the chart, then replace "Write your title here" with a complete sentence of about ten words that says what it shows. Run the chart lines again.
- Write one ggsave() line that saves
my_chartwith your last name, for examplesmith_lab6.png, and run it. Useheight = 6so both panels fit.
Lab 6 response sheet
Answer in complete sentences. Then assemble your answers and paste them into the Lab 6 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
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.
All averages on this page come from the gss_cat extract and were checked by running the lab script. They are unweighted, and they include only people who were asked about TV hours.