Code
library('ggplot2')
library('dplyr')
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Trust in science and scientists
August 30, 2024
This page documents the data processing steps involved with Survey-01 in PSYCH 490.012 Fall 2024.
The survey questions were adapted from those discussed in (Krumrei-Mancuso & Rouse, 2016; Nadelson et al., 2014; Plohl & Musil, 2023).
Direct link: https://forms.gle/kpwGFo2qpsKmNLya9
First, we load the external packages (groups of R commands) that we will be using.
Next, we download the data from the Google Sheet where it is collected. Dr. Gilmore has stored his Google account credentials in a special environment file that can be accessed by the R command Sys.getenv("GMAIL_SURVEY")
.
It’s vital to be very careful when creating and sharing code like this that involves sensitive information like login credentials.
Gilmore likes to put credentials in an .Renviron
file that lives in his home directory. This is a recommended practice. On Mac OS and Linux, that’s ~/.Renviron
. You can use the usethis::edit_r_profile()
command at the R console (not the Terminal) to open your own .Renviron
file. In Gilmore’s case, he has added the following line to that file:
GMAIL_SURVEY="<my-google-account>"
Here, he has substituted his Google account with credentials/access to the required files for <my-google-account>
. Then, when the R code below calls Sys.getenv("GMAIL_SURVEY")
, the value of those credentials is returned as a text string.
Make sure to close and save the .Renviron
file and restart your R session before testing this yourself.
if (!dir.exists('csv')) {
message("Creating missing `csv/`.")
dir.create("csv")
}
if (params$update_data) {
options(gargle_oauth_email = Sys.getenv("GMAIL_SURVEY"))
googledrive::drive_auth()
googledrive::drive_download(
"PSYCH 490.012: Survey 01: Openness and Trust in Science (Responses)",
path = file.path("csv", params$fn),
type = "csv",
overwrite = TRUE
)
message("Data updated.")
} else {
message("Using stored data.")
}
The data file has been saved as a comma-separated value (CSV) format data file in a special directory called csv/
.
Because these data might contain sensitive or identifiable information, we only keep a local copy and do not share it publicly via GitHub. This is achieved by adding the name of the data directory to a special .gitignore
file.
Next we load the saved data file and then proceed to clean it.
There are 17 responses. That’s great for a small class!
These are the column/variable names.
[1] "Timestamp"
[2] "I have at times changed opinions that were important to me, when someone showed me I was wrong."
[3] "I am willing to change my position on an important issue in the face of good reasons."
[4] "I am open to revising my important beliefs in the face of new information."
[5] "I am willing to change my opinions on the basis of compelling reason."
[6] "I’m willing to change my mind once it’s made up about an important topic."
[7] "When scientists change their mind about a scientific idea it diminishes my trust in their work."
[8] "Scientists ignore evidence that contradicts their work."
[9] "Scientific theories are weak explanations."
[10] "Scientists intentionally keep their work secret."
[11] "We can trust scientists to share their discoveries even if they don't like their findings."
[12] "Scientists don't value the ideas of others."
[13] "I trust that the work of scientists is to make life better for people."
[14] "Scientists don't care if laypersons understand their work."
[15] "We should trust the work of scientists."
[16] "We should trust that scientists are being honest in their work."
[17] "We should trust that scientists are being ethical in their work."
[18] "Scientific theories are trustworthy."
[19] "When scientists form a hypothesis they are just guessing."
[20] "People who understand science more have more trust in science."
[21] "We can trust science to find the answers that explain the natural world."
[22] "I trust scientists can find solutions to our major technological problems."
[23] "We cannot trust scientists because they are biased in their perspectives."
[24] "Scientists will protect each other even when they are wrong."
[25] "We cannot trust scientists to consider ideas that contradict their own."
[26] "Today's scientists will sacrifice the well being of others to advance their research."
[27] "We cannot trust science because it moves too slowly."
[28] "If you wish to comment about the questions in this survey, you may do so here. You are not required to comment. Your comments might be seen by others."
For plotting and analyses, it’s usually easier to shorten the questions by creating a short name that reflects the underlying idea or construct. We’ll use the rename()
function from the dplyr
package for this.
We first rename the variables from the “Openness to Revising One’s Viewpoint” subscale from the Comprehensive Intellectual Humility Scale (Krumrei-Mancuso & Rouse, 2016).
survey_01_clean <- survey_01 |>
dplyr::rename(
timestamp = "Timestamp",
when_shown_wrong = "I have at times changed opinions that were important to me, when someone showed me I was wrong.",
good_reason = "I am willing to change my position on an important issue in the face of good reasons." ,
new_info = "I am open to revising my important beliefs in the face of new information.",
compelling_reason = "I am willing to change my opinions on the basis of compelling reason.",
mind_made_up = "I’m willing to change my mind once it’s made up about an important topic.",
comments = "If you wish to comment about the questions in this survey, you may do so here. You are not required to comment. Your comments might be seen by others."
)
Notice how the rename()
function puts the ‘new’ name on the left and the ‘old’ name on the right.
Keep in mind that the shorter names involve non-arbitrary choices. It’s good to keep the original questions close at-hand if you really want to understand what question people were asked.
Now, we rename the variables from the (Nadelson et al., 2014) trust in science and scientists survey.
survey_01_clean <- survey_01_clean |>
dplyr::rename(
ignore_contradictory_evidence = "Scientists ignore evidence that contradicts their work.",
theories_are_weak = "Scientific theories are weak explanations.",
keep_work_secret = "Scientists intentionally keep their work secret.",
dont_value_others_ideas = "Scientists don't value the ideas of others.",
dont_care_laypeople_understand = "Scientists don't care if laypersons understand their work.",
should_trust_work = "We should trust the work of scientists.",
should_trust_honesty = "We should trust that scientists are being honest in their work.",
should_trust_ethical = "We should trust that scientists are being ethical in their work.",
more_understanding_more_trust = "People who understand science more have more trust in science.",
trust_explain_natural_world = "We can trust science to find the answers that explain the natural world.",
cant_trust_biased = "We cannot trust scientists because they are biased in their perspectives.",
protect_each_other_when_wrong = "Scientists will protect each other even when they are wrong.",
wont_consider_contradictory_ideas = "We cannot trust scientists to consider ideas that contradict their own.",
sacrifice_others_to_advance = "Today's scientists will sacrifice the well being of others to advance their research.",
cant_trust_moves_slowly = "We cannot trust science because it moves too slowly.",
change_minds_undermines_trust = "When scientists change their mind about a scientific idea it diminishes my trust in their work.",
share_findings_dont_like = "We can trust scientists to share their discoveries even if they don't like their findings.",
make_life_better = "I trust that the work of scientists is to make life better for people.",
theories_trustworthy = "Scientific theories are trustworthy.",
hypotheses_just_guesses = "When scientists form a hypothesis they are just guessing.",
trust_find_tech_solutions = "I trust scientists can find solutions to our major technological problems."
)
Now, let’s look at the names to confirm they all got changed.
[1] "timestamp" "when_shown_wrong"
[3] "good_reason" "new_info"
[5] "compelling_reason" "mind_made_up"
[7] "change_minds_undermines_trust" "ignore_contradictory_evidence"
[9] "theories_are_weak" "keep_work_secret"
[11] "share_findings_dont_like" "dont_value_others_ideas"
[13] "make_life_better" "dont_care_laypeople_understand"
[15] "should_trust_work" "should_trust_honesty"
[17] "should_trust_ethical" "theories_trustworthy"
[19] "hypotheses_just_guesses" "more_understanding_more_trust"
[21] "trust_explain_natural_world" "trust_find_tech_solutions"
[23] "cant_trust_biased" "protect_each_other_when_wrong"
[25] "wont_consider_contradictory_ideas" "sacrifice_others_to_advance"
[27] "cant_trust_moves_slowly" "comments"
We’ll pause here to start building a data dictionary, a file that explains the origin, format, and usage of our dataset.
We’ll add other items to the data dictionary later.
We should omit the first response in the dataset. That was the one Dr. Gilmore used to generate a Google Sheet, and isn’t real data. He put “test” in the comments
field to make it easy to detect.
Remember, this is the relationship between the numbers and the verbal ratings:
Here are the questions:
question | short_name |
---|---|
I have at times changed opinions that were important to me, when someone showed me I was wrong. | when_shown_wrong |
I am willing to change my position on an important issue in the face of good reasons. | good_reason |
I am open to revising my important beliefs in the face of new information. | new_info |
I am willing to change my opinions on the basis of compelling reason. | compelling_reason |
I’m willing to change my mind once it’s made up about an important topic. | mind_made_up |
Here is a dotplot of the data:
survey_01_openness <- survey_01_clean[, 1:6] |>
tidyr::pivot_longer(cols=2:6, names_to = "question", values_to = "rating")
survey_01_openness |>
ggplot() +
aes(x = rating) +
geom_dotplot(dotsize = .2) +
xlim(1,5) +
xlab("strongly disagree <-----> strongly agree ") +
theme(axis.title.y = element_blank()) +
theme(axis.text.y = element_blank()) +
theme(axis.ticks = element_blank()) +
facet_wrap(facets = vars(question), ncol = 1)
See the Fall 2023 results here: Figure 6.
It would be even better to create a function that generates the plot and shows the long and short question names. Any time I repeat myself, I should remember this acronym:
Don’t Repeat Yourself
Write It Down
There are a number of these, so we break them into smaller groups for visualization.
Remember, we use the same response options as for the ‘openness’ questions, see Figure 1.
Here are the questions:
question | short_name |
---|---|
When scientists change their mind about a scientific idea it diminishes my trust in their work. | change_minds_undermines_trust |
Scientists ignore evidence that contradicts their work. | ignore_contradictory_evidence |
Scientific theories are weak explanations. | theories_are_weak |
Scientists intentionally keep their work secret. | keep_work_secret |
We can trust scientists to share their discoveries even if they don’t like their findings. | share_findings_dont_like |
Scientists don’t value the ideas of others. | dont_value_others_ideas |
I trust that the work of scientists is to make life better for people. | make_life_better |
Scientists don’t care if laypersons understand their work. | dont_care_laypeople_understand |
We should trust the work of scientists. | should_trust_work |
We should trust that scientists are being honest in their work. | should_trust_honesty |
We should trust that scientists are being ethical in their work. | should_trust_ethical |
Scientific theories are trustworthy. | theories_trustworthy |
When scientists form a hypothesis they are just guessing. | hypotheses_just_guesses |
People who understand science more have more trust in science. | more_understanding_more_trust |
We can trust science to find the answers that explain the natural world. | trust_explain_natural_world |
I trust scientists can find solutions to our major technological problems. | trust_find_tech_solutions |
We cannot trust scientists because they are biased in their perspectives. | cant_trust_biased |
Scientists will protect each other even when they are wrong. | protect_each_other_when_wrong |
We cannot trust scientists to consider ideas that contradict their own. | wont_consider_contradictory_ideas |
Today’s scientists will sacrifice the well being of others to advance their research. | sacrifice_others_to_advance |
We cannot trust science because it moves too slowly. | cant_trust_moves_slowly |
Trust in science questions from (Nadelson et al., 2014)
Here is are plots of your ratings:
survey_01_trust <- survey_01_clean |>
tidyr::pivot_longer(cols=7:27, names_to = "question", values_to = "rating")
survey_01_trust |>
ggplot() +
aes(rating) +
geom_dotplot(dotsize = .4) +
xlim(1, 5) +
theme(axis.title.y = element_blank()) +
theme(axis.text.y = element_blank()) +
theme(axis.ticks = element_blank()) +
facet_wrap(facets = vars(question), ncol = 3)
See the Fall 2023 results here: Figure 7.
Here are summary statistics about the ratings sorted in descending order:
question | mean_rating | sd_rating |
---|---|---|
more_understanding_more_trust | 4.000000 | 0.6123724 |
trust_explain_natural_world | 3.764706 | 0.6642112 |
make_life_better | 3.705882 | 0.9195587 |
trust_find_tech_solutions | 3.529412 | 0.7998162 |
theories_trustworthy | 3.411765 | 1.0036697 |
should_trust_work | 3.352941 | 0.9963167 |
should_trust_ethical | 3.176471 | 0.9510057 |
should_trust_honesty | 3.176471 | 0.9510057 |
share_findings_dont_like | 3.058823 | 0.8993462 |
dont_care_laypeople_understand | 3.000000 | 0.7905694 |
ignore_contradictory_evidence | 2.764706 | 0.9034249 |
protect_each_other_when_wrong | 2.764706 | 1.0914103 |
change_minds_undermines_trust | 2.470588 | 0.8744746 |
keep_work_secret | 2.411765 | 1.0641207 |
cant_trust_biased | 2.235294 | 0.9034249 |
hypotheses_just_guesses | 2.235294 | 0.8313702 |
sacrifice_others_to_advance | 2.235294 | 1.0914103 |
wont_consider_contradictory_ideas | 2.117647 | 0.6002450 |
dont_value_others_ideas | 1.823529 | 0.8089572 |
theories_are_weak | 1.823529 | 0.8089572 |
cant_trust_moves_slowly | 1.705882 | 0.9851844 |
Next, we calculate aggregate “openness” and “trust” scores to look at the relationship between these variables.
Some of the “trust” variables are reverse-coded, so we have to address that. We’ll start by adding a variable to our data dictionary that indicates the “sign” of the weight we should apply to that variable.
If the sign is reversed, then we must assign 1 to 5, 2 to 4, 3 to 3, 4 to 2, and 5 to 1.
Here is a table of the weights to apply to the questions:
question | short_name | sign_wt |
---|---|---|
Timestamp | timestamp | 0 |
I have at times changed opinions that were important to me, when someone showed me I was wrong. | when_shown_wrong | 1 |
I am willing to change my position on an important issue in the face of good reasons. | good_reason | 1 |
I am open to revising my important beliefs in the face of new information. | new_info | 1 |
I am willing to change my opinions on the basis of compelling reason. | compelling_reason | 1 |
I’m willing to change my mind once it’s made up about an important topic. | mind_made_up | 1 |
When scientists change their mind about a scientific idea it diminishes my trust in their work. | change_minds_undermines_trust | -1 |
Scientists ignore evidence that contradicts their work. | ignore_contradictory_evidence | -1 |
Scientific theories are weak explanations. | theories_are_weak | -1 |
Scientists intentionally keep their work secret. | keep_work_secret | -1 |
We can trust scientists to share their discoveries even if they don't like their findings. | share_findings_dont_like | 1 |
Scientists don't value the ideas of others. | dont_value_others_ideas | -1 |
I trust that the work of scientists is to make life better for people. | make_life_better | 1 |
Scientists don't care if laypersons understand their work. | dont_care_laypeople_understand | -1 |
We should trust the work of scientists. | should_trust_work | 1 |
We should trust that scientists are being honest in their work. | should_trust_honesty | 1 |
We should trust that scientists are being ethical in their work. | should_trust_ethical | 1 |
Scientific theories are trustworthy. | theories_trustworthy | 1 |
When scientists form a hypothesis they are just guessing. | hypotheses_just_guesses | -1 |
People who understand science more have more trust in science. | more_understanding_more_trust | 1 |
We can trust science to find the answers that explain the natural world. | trust_explain_natural_world | 1 |
I trust scientists can find solutions to our major technological problems. | trust_find_tech_solutions | 1 |
We cannot trust scientists because they are biased in their perspectives. | cant_trust_biased | -1 |
Scientists will protect each other even when they are wrong. | protect_each_other_when_wrong | -1 |
We cannot trust scientists to consider ideas that contradict their own. | wont_consider_contradictory_ideas | -1 |
Today's scientists will sacrifice the well being of others to advance their research. | sacrifice_others_to_advance | -1 |
We cannot trust science because it moves too slowly. | cant_trust_moves_slowly | -1 |
If you wish to comment about the questions in this survey, you may do so here. You are not required to comment. Your comments might be seen by others. | comments | 0 |
I found some mistakes in the code I used last year to reverse-code variables when I revisited it this year. Only when I went through each question one-by-one did I find the errors. I’m very glad I’d shown the variables in a table.
This next section of code reflects my attempt to make a function that categorizes the weights that should be applied to the variables. I think this is more reliable and more transparent. In other words, I think it’s easier to see what’s actually going on.
What do you think?
# Note: this function seems to be equivalent to the manual coding above.
# So, I did not change the rest of the code to make use of it.
assign_trust_wt <- function(var_name) {
wt <- if_else(var_name %in% c('when_shown_wrong',
'good_reason',
'new_info',
'mind_made_up',
'compelling_reason',
'should_trust_work',
'should_trust_honesty',
'should_trust_ethical',
'more_understanding_more_trust',
'trust_explain_natural_world',
'share_findings_dont_like',
'make_life_better',
'theories_trustworthy',
'trust_find_tech_solutions'), 1,
if_else(var_name %in% c('ignore_contradictory_evidence',
'theories_are_weak',
'keep_work_secret',
'dont_value_others_ideas',
'dont_care_laypeople_understand',
'cant_trust_biased',
'protect_each_other_when_wrong',
'wont_consider_contradictory_ideas',
'sacrifice_others_to_advance',
'cant_trust_moves_slowly',
'change_minds_undermines_trust',
'hypotheses_just_guesses'
), -1, 0))
wt
}
survey_01_data_dictionary <- survey_01_data_dictionary |>
dplyr::mutate(sign_wt_new = assign_trust_wt(short_name))
survey_01_data_dictionary[,c(1,2,4,5)] |>
knitr::kable(format = "html") |>
kableExtra::kable_classic()
question | short_name | sign_wt | sign_wt_new |
---|---|---|---|
Timestamp | timestamp | 0 | 0 |
I have at times changed opinions that were important to me, when someone showed me I was wrong. | when_shown_wrong | 1 | 1 |
I am willing to change my position on an important issue in the face of good reasons. | good_reason | 1 | 1 |
I am open to revising my important beliefs in the face of new information. | new_info | 1 | 1 |
I am willing to change my opinions on the basis of compelling reason. | compelling_reason | 1 | 1 |
I’m willing to change my mind once it’s made up about an important topic. | mind_made_up | 1 | 1 |
When scientists change their mind about a scientific idea it diminishes my trust in their work. | change_minds_undermines_trust | -1 | -1 |
Scientists ignore evidence that contradicts their work. | ignore_contradictory_evidence | -1 | -1 |
Scientific theories are weak explanations. | theories_are_weak | -1 | -1 |
Scientists intentionally keep their work secret. | keep_work_secret | -1 | -1 |
We can trust scientists to share their discoveries even if they don't like their findings. | share_findings_dont_like | 1 | 1 |
Scientists don't value the ideas of others. | dont_value_others_ideas | -1 | -1 |
I trust that the work of scientists is to make life better for people. | make_life_better | 1 | 1 |
Scientists don't care if laypersons understand their work. | dont_care_laypeople_understand | -1 | -1 |
We should trust the work of scientists. | should_trust_work | 1 | 1 |
We should trust that scientists are being honest in their work. | should_trust_honesty | 1 | 1 |
We should trust that scientists are being ethical in their work. | should_trust_ethical | 1 | 1 |
Scientific theories are trustworthy. | theories_trustworthy | 1 | 1 |
When scientists form a hypothesis they are just guessing. | hypotheses_just_guesses | -1 | -1 |
People who understand science more have more trust in science. | more_understanding_more_trust | 1 | 1 |
We can trust science to find the answers that explain the natural world. | trust_explain_natural_world | 1 | 1 |
I trust scientists can find solutions to our major technological problems. | trust_find_tech_solutions | 1 | 1 |
We cannot trust scientists because they are biased in their perspectives. | cant_trust_biased | -1 | -1 |
Scientists will protect each other even when they are wrong. | protect_each_other_when_wrong | -1 | -1 |
We cannot trust scientists to consider ideas that contradict their own. | wont_consider_contradictory_ideas | -1 | -1 |
Today's scientists will sacrifice the well being of others to advance their research. | sacrifice_others_to_advance | -1 | -1 |
We cannot trust science because it moves too slowly. | cant_trust_moves_slowly | -1 | -1 |
If you wish to comment about the questions in this survey, you may do so here. You are not required to comment. Your comments might be seen by others. | comments | 0 | 0 |
I’m on the fence about whether “People who understand science more have more trust in science.” should be in the composite. What do you think? What did (Plohl & Musil, 2023) do?
# Recode variables with "reverse" indicator (sign_x == -1)
recode_reverse_vars <- function(x, sign_x) {
if (sign_x == -1) {
switch(x,
5,
4,
3,
2,
1)
} else {
x
}
}
# Recode a specific variable based on its column index
recode_var <- function(var_i, df_vars = survey_01_clean, df_dict = survey_01_data_dictionary) {
vals <- unname(unlist(df_vars[, var_i]))
wts <- unname(unlist(rep(df_dict[var_i, 4], length(vals))))
purrr::map2(vals, wts, recode_reverse_vars) |>
unlist()
}
# Recode the entire dataset and create a new data frame/tibble
recode_survey_01 <- function() {
x <- purrr::map(1:28, recode_var)
var_names <- survey_01_data_dictionary[,2] |>
unlist() |>
unname()
names(x) <- var_names
as_tibble(x)
}
# Run the recode_survey_01() function
survey_01_recoded <- recode_survey_01()
# Calculate the composite scores as mean values across rows (within participants)
survey_01_recoded <- survey_01_recoded |>
dplyr::mutate(openness_comp = rowMeans(survey_01_recoded[, 2:6]),
trust_comp = rowMeans(survey_01_recoded[, 7:27]))
Here’s a plot to ensure our recoded data about trust in science make sense.
survey_01_recoded |>
tidyr::pivot_longer(cols=7:27, names_to = "question", values_to = "rating") |>
ggplot()+
aes(rating) +
geom_dotplot(dotsize = .4) +
xlim(1, 5) +
theme(axis.title.y = element_blank()) +
theme(axis.text.y = element_blank()) +
theme(axis.ticks = element_blank()) +
facet_wrap(facets = vars(question), ncol = 3)
Bin width defaults to 1/30 of the range of the data. Pick better value with
`binwidth`.
Here we evaluate the relationship between a person’s openness and their trust in science.
Pearson's product-moment correlation
data: openness_comp and trust_comp
t = 2.6603, df = 15, p-value = 0.01782
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.1175296 0.8228953
sample estimates:
cor
0.5661903
Here are the Fall 2023 results: Figure 8.
Comments
Code
No one seemed to have had any comments.