A Priming study

In a provocative paper, Bargh, Chen and Burrows (1996) sought to test whether or not priming people with trait concepts would trigger trait-consistent behavior. In one study, they primed participants with either neutral words (e.g.; bat, cookie, pen), or with words related to an elderly stereotype (e.g.; wise, stubborn, old). They then, unbeknownst to the participants, used a stopwatch to record how long it took the participants to walk down a hallway at the conclusion of an experiment. They predicted that participants primed with words related to the elderly would walk slower than those primed with neutral words.

In this WPA, you will analyze fake data corresponding to this study.

Dataset description

Our fake study has 3 primary independent variables:

Variable Description Possible Values
prime What kind of primes was the participant given? neutral, elderly
prime.duration How long (in minutes) were primes displayed to participants? 1, 5, 10, or 30
grandparents Did the participant have a close relationship with their grandparents? yes means yes, no means no, none means they never met their grandparents.
id The order in which participants completed the study Integers from 1 to 500
age Participants’ age Integers larger than 18
sex Participant’s sex "m" = male, "f" = female
attention Did the participant pass an attention check? 1 = yes, 0 = no
walk How long (in seconds) did participants take to walk down the hallway? Positive numbers

Load the data

  1. The text file containing the data is called priming.txt. It is available at http://nathanieldphillips.com/wp-content/uploads/2016/10/priming.txt. Load the data into R by running the following:
priming <- read.table("http://nathanieldphillips.com/wp-content/uploads/2016/10/priming.txt")

Here is how the data should look:

a b c d e f g h
1 m 21 1 asdf 1 no 25.4
2 m 21 1 asdf 30 no 23.6
3 f 22 1 asdf 30 none 34.5
4 m 23 1 elderly 1 yes 40.4
5 m 23 1 asdf 10 none 25.0
6 m 22 1 asdf 10 yes 24.7

Understanding and cleaning the data

  1. Get to know the data using View(), summary(), head() and str().

  2. Look at the names of the dataframe with names(). Those aren’t very informative are they? Change the names to the correct values (make sure to use the naming scheme I describe in the dataset description).

names(priming) <- c("id", "sex", "age", "attention", "prime", "prime.duration", "grandparents", "walk")

Applying functions to columns

  1. What was the mean participant age?
mean(priming$age)
## [1] 21.996

4b. Create a new vector object called age.v that contains the age data. Calculate the mean age from this vector. Do you get the same result as you did in the previous question?

age.v <- priming$age
mean(age.v)
## [1] 21.996
  1. What was the median walking time?
median(priming$walk)
## [1] 34.7
  1. How many females were there? How many males?
sum(priming$sex == "m")
## [1] 248
  1. What percent of participants passed the attention check (Hint: To calculate a percentage from a 0, 1 variable, use mean())
mean(priming$attention)
## [1] 0.886
  1. Walking time is currently in seconds. Add a new column to the dataframe called walk.m That shows the walking time in minutes rather than seconds.
priming$walk.m <- priming$walk / 60

Indexing and subsettting dataframes

Try to split your answers to these problems into two steps

Step 1: Index or subset the original data and store as a new object with a new name.

Step 2: Calculate the appropriate summary statistic using the new, subsetted object you just created.

  1. What were the sexes of the first 10 participants?
priming$sex[1:10]
##  [1] m m f m m m f m f m
## Levels: f m
  1. What was the data for the 50th participant?
priming[50,]
##    id sex age attention   prime prime.duration grandparents walk    walk.m
## 50 50   m  21         1 elderly              1         none 34.3 0.5716667
  1. What was the mean walking time for the elderly prime condition?
mean(priming$walk[priming$prime == "elderly"])
## [1] 39.17612
  1. What was the mean walking time for the neutral prime condition?
mean(priming$walk[priming$prime == "neutral"])
## [1] 26.50167
  1. What was the mean walking time for participants less than 23 years old?
mean(priming$walk[priming$age < 23])
## [1] 28.8359
  1. What was the mean walking time for females with a close relationship with their grandparents?
mean(priming$walk[priming$sex == "f" & priming$grandparents == "yes"])
## [1] 34.22515
  1. What was the mean walking time for males over 21 years old without a close relationship with their grandparents?
mean(priming$walk[priming$sex == "m" & priming$age > 21 & priming$grandparents == "none"])
## [1] 25.76126

Checkpoint! If you got this far you are doing great!

Creating new dataframe objects

  1. Create a new dataframe called priming.simple that only contains the columns id, prime, and walk
priming.simple <- priming[c("id", "prime", "walk")]
  1. Some of the data don’t make any sense. For example, some walking times are negative, some prime values aren’t correct, and some prime.duration values weren’t part of the original study plan. Create a new dataframe called priming.c (aka., priming clean) that only includes rows with valid values for each column – do this by looking for an few strange values in each column, and by looking at the original dataset description. Additionally, only include participants who passed the attention check. Here’s a skeleton of how your code should look
# Create priming.c, a subset of the original priming data
#  (replace __ with the appropriate values)
priming.c <- subset(priming,
                    subset = sex %in% c(_____) & 
                             age > ____ &
                             attention == ___ &
                             prime %in% c(___) &
                             prime.duration %in% c(___) &
                             grandparents %in% c(___) &
                             walk > ___ )
# Create priming.c, a subset of the original priming data
#  (replace __ with the appropriate values)
priming.c <- subset(priming,
                    subset = sex %in% c("m", "f") & 
                             age > 18 &
                             attention == 1 &
                             prime %in% c("elderly", "neutral") &
                             prime.duration %in% c(1, 5, 10, 30) &
                             grandparents %in% c("no", "none", "yes") &
                             walk > 0)
  1. How many participants gave valid data and passed the attention check? (Hint: Use the result from your previous answer!)
nrow(priming.c)
## [1] 291
  1. Of those participants who gave valid data and passed the attention check, what was the mean walking time of those given the elderly and neutral prime (calculate these separately).
with(subset(priming.c, prime == "elderly"), mean(walk))
## [1] 41.93209
with(subset(priming.c, prime == "neutral"), mean(walk))
## [1] 30.25669

Challenges

The following questions apply to your cleaned dataframe (priming.c)

  1. Did the effect of priming condition on walking times differ between the first 50 and the last 50 participants. That is, what was the difference in the mean walking time between the two priming conditions for the first 50 participants? What about the last 50 participants? (Hint: Make sure to index the data using id!)?
mean(priming.c$walk[priming.c$id <= 50 & priming.c$prime == "elderly"]) - mean(priming.c$walk[priming.c$id <= 50 & priming.c$prime == "neutral"])
## [1] 11.04059
mean(priming.c$walk[priming.c$id >= 450 & priming.c$prime == "elderly"]) - mean(priming.c$walk[priming.c$id >= 450 & priming.c$prime == "neutral"])
## [1] 10.21579
  1. Do you find evidence that a participant’s relationship with their grandparents affects how they responded to the primes?
# Strong relationship only
mean(priming.c$walk[priming.c$grandparents == "yes" & priming.c$prime == "elderly"]) - mean(priming.c$walk[priming.c$grandparents == "yes" & priming.c$prime == "neutral"])
## [1] 13.57851
# No relationship only
mean(priming.c$walk[priming.c$grandparents == "none" & priming.c$prime == "elderly"]) - mean(priming.c$walk[priming.c$grandparents == "none" & priming.c$prime == "neutral"])
## [1] 9.667544
  1. Due to a computer error, the data from every participant with an even id number is invalid. Remove these data from your priming.c dataframe.
priming.c <- priming.c[priming.c$id %in% seq(1, 501, by = 2),]

Submit!

Save and email your wpa_X_LastFirst.R file to me at nathaniel.phillips@unibas.ch. Then, go to https://goo.gl/forms/8pKm39PMS29JoLjI2 to complete the WPA submission form.