Challenge · Build an index from the SM11 items
Self-paced bonus · write the code yourself, on data you procured
Optional challenge — after the lab, any time
Your M05 lab is complete once you’ve built and verified Table 1. This page is different from the lab and from most course activities: there is no code here to copy. You get the goal, the facts you can’t guess, and a set of checks your answer has to pass. The code is yours to write.
That is the point. Every other activity this semester hands you a scaffold; this one asks whether you can build something from a specification — which is what you’ll actually be doing on your group project, and after.
You’ll need: your PSY652_project open, pew_atp_w163.sav in data/, and the pew_selected data frame from Step 4 of the lab. Nothing here is graded, and nothing goes in your lab notebook.
Stuck, or want to check your work? The full worked solution is on its own page — but give it a real attempt first. The struggle is where the learning is.
The goal
Wave 163 asked social-media users a three-part question — how important is social media to you personally for…
- (a) finding other people who share your views ·
SM11_a_W163 - (b) getting involved with political or social issues you care about ·
SM11_b_W163 - (c) giving you a venue to express your opinions ·
SM11_c_W163
Your task: combine those three columns into a single score per respondent, then check that you built what you think you built.
Facts you can’t guess from the data
These come from the codebook and questionnaire you filed in Step 1. Read them carefully — two of the four will change your code.
- Each item is coded 1–4, where
1 = Very importantand4 = Not at all important. The numbers run backwards relative to the name “importance.” 99 = Refused, stored as a real number — the same sentinel you handled for the demographics in the lab.- The items were asked only of social-media users. Everyone else has no value, by design.
- The three are separate questions about different activities, not a published Pew scale. Whatever you build is an index you defined.
What your answer has to do
Four requirements. Each one is a decision, not just a line of code.
- Decide whether averaging is defensible at all — before you average. The items should be positively associated if they’re summarizing one idea; look before you leap.
- Fix the direction so that a higher score means more important. Right now it means less.
- Handle the refusals so
99never enters an average. - Set a minimum-items rule: form the score only for respondents who answered at least 2 of the 3, and return a missing value otherwise. Decide this before you look at results.
Success criteria · how you’ll know you got it
Your finished score should pass all four of these. Check them yourself — that’s part of the exercise.
| Check | What you should see |
|---|---|
| Range | The score runs from 1 to 4, and higher means more important |
| Association | The three items correlate positively, roughly 0.66 to 0.75 |
| Coverage | About 4,110 respondents get a score |
| Who | Essentially everyone with a score is a social-media user — if a non-user has one, something is wrong |
That last check is the one worth building the habit around: a derived variable should exist for exactly the people who were eligible for it, and no one else.
Where to look if you’re stuck
The moves are all ones you’ve met. In rough order of use:
- Getting the items out of labelled form first. These three arrive as
<dbl+lbl>, and almost everything below wants plain numbers with the refusal code already gone. The lab’s closing box — Labelled data, and the two ways out of it — has the two functions and, importantly, the order they go in. Do this once, into its own data frame, and build everything else on top of it; converting inline at each step is how the two copies drift apart. - The correlation check — the M05 Module checks the four severity items this same way before averaging them, and says what a matrix of correlations does and doesn’t license. For the picture you’ll need corrplot, which the lab skeleton does not load, so add a library() line for it.
- Row-wise averaging — the M05 Module’s composite section covers rowMeans() with pick(), and why a row-wise mean is different from a column mean.
- Counting answered items — the same Module section builds a counter with rowSums() and is.na().
- The minimum-items rule — case_when(), with both arms written out, and the
NAtyped to match the other arm’s type. - Reversing a 1–4 scale — no function needed; it’s arithmetic. If
1should become4and4should become1, what do you subtract from what?
One design decision worth making deliberately: you could grab the three columns with a select helper that matches their shared prefix. Think about whether you want to. An index is a claim about which items it contains — and a helper re-answers that question every time the file changes.
Before you look at the solution
If your code runs but a check fails, that’s the most useful moment on this page. Work backwards from which check failed:
- Range is 1–4 but reversed? Your direction fix didn’t fire, or fired twice.
- Score exists for non-users? Your missing-value handling is filling in values it shouldn’t. Think about what happens when you tell an averaging function to skip missing values — and then hand it a row where every value is missing. What does it have left to average, and what does it give back?
- Far fewer scores than expected? Your minimum-items rule may be stricter than you meant, or you’re averaging without telling the mean to skip missing values.
- Far more? Your rule may not be firing at all.