Skip to content

Commit dbbd486

Browse files
committed
Add section working with survey response metadata
1 parent 79c272e commit dbbd486

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

materials/sections/survey-workflow.qmd

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,22 @@ To get a list of all the surveys in your Qualtrics instance, use the `all_survey
9191

9292
```{r, eval = FALSE}
9393
surveys <- all_surveys()
94-
kable(surveys) %>%
95-
kable_styling()
94+
glimpse(surveys)
9695
```
9796

9897
This function returns a list of surveys, in this case only one, and information about each, including an identifier and it's name. We'll need that identifier later, so let's go ahead and extract it using base R from the data frame.
9998

10099
```{r, eval = FALSE}
101-
i <- which(surveys$name == "Survey for Data Science Training")
102-
id <- surveys$id[i]
100+
id <- surveys %>%
101+
filter(name == "Survey for Data Science Training") %>%
102+
pull(id)
103103
```
104104

105105
You can retrieve a list of the questions the survey asked using the `survey_questions` function and the survey `id`.
106106

107107
```{r, eval = FALSE}
108108
questions <- survey_questions(id)
109-
kable(questions) %>%
110-
kable_styling()
109+
questions
111110
```
112111

113112
This returns a `data.frame` with one row per question with columns for question id, question name, question text, and whether the question was required. This is helpful to have as a reference for when you are looking at the full survey results.
@@ -116,18 +115,45 @@ To get the full survey results, run `fetch_survey` with the survey id.
116115

117116
```{r, eval = FALSE}
118117
survey_results <- fetch_survey(id)
119-
glimpse(survey_results)
118+
survey_results %>% head(1) %>% glimpse
120119
```
121120

122121
The survey results table has tons of information in it, not all of which will be relevant depending on your survey. The table has identifying information for the respondents (eg: `ResponseID`, `IPaddress`, `RecipientEmail`, `RecipientFirstName`, etc), much of which will be empty for this survey since it is anonymous. It also has information about the process of taking the survey, such as the `StartDate`, `EndDate`, `Progress`, and `Duration`. Finally, there are the answers to the questions asked, with columns labeled according to the `qname` column in the questions table (eg: Q1, Q2, Q3). Depending on the type of question, some questions might have multiple columns associated with them. We'll have a look at this more closely in a later example.
123122

123+
#### Response metadata
124+
125+
As mentioned above, Qualtrics helpfully provides some metadata with each response. Let's use some of this information now. First, you'll noticed a column named `Finished`, containing `TRUE` or `FALSE` values. This indicates whether the respondent fully completed and submitted the survey. In many cases, you will want to filter out unfinished survey responses to avoid analyzing incomplete answers. Let's go ahead and remove those now.
126+
127+
```{r, eval = FALSE}
128+
# Report the frequency of finished vs unfinished responses
129+
survey_results %>% count(Finished)
130+
131+
# Remove unfinished responses
132+
survey_results <- survey_results %>% filter(Finished)
133+
```
134+
135+
Second, you'll noticed columns named `LocationLongitude` and `LocationLatitude`. These give an approximate best-guess location of the respondent based on IP address. This is usually accurate to a city level in the United States, but perhaps only to a country for many international respondents, and can be completely wrong in some cases (e.g., if the respondent is using a VPN). Nevertheless, it can be useful to give at least a rough sense of where your respondents are located. Let's use `leaflet` to draw a quick map of our survey respondents.
136+
137+
```{r, eval = FALSE}
138+
library(leaflet)
139+
survey_results %>%
140+
leaflet %>%
141+
addTiles() %>%
142+
addMarkers(
143+
lng = ~ LocationLongitude,
144+
lat = ~ LocationLatitude,
145+
popup = ~ Q2
146+
)
147+
```
148+
149+
124150
#### Question 2
125151

126152
Let's look at the responses to the second question in the survey, "How long have you been programming?" Remember, the first question was the consent question.
127153

128154
We'll use the `dplyr` and `tidyr` tools we learned earlier to extract the information. Here are the steps:
129155

130-
- `select` the column we want (`Q1`)
156+
- `select` the column we want (`Q2`)
131157
- `group_by` and `summarize` the values
132158

133159
```{r, eval = FALSE}

0 commit comments

Comments
 (0)