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.
Our fake study has 3 primary independent variables:
prime: What kind of primes was the participant given? neutral means neutral primes, elderly means elderly primes.prime.duration: How long (in minutes) were primes displayed to participants? There were 4 conditions: 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.There was one primary dependent variable
walk: How long (in seconds) did participants take to walk down the hallway?There were 4 additional variables:
id: The order in which participants completed the studyage: Participants’ agesex: Participants’ sexattention: Did the participant pass an attention check? 0 means they failed the attention check, 1 means they passed.This is actually covered in Chapter 9, not Chapter 8. So I’ll run through how to do this as a class.
Briefly, whenever you want to load or save data in R you need to tell R where the data is to be saved or where the data is being loaded from. Last week, for instance, we loaded data directly from a url. This week we’ll load data that is saved on our machine. To do this we need to set a working directory. This is the default folder R will look in to save or load data. If we wish to load (or save) data from a different folder, we can either changed the working directory, or specify the filepath from the current working directory to the desired folder.
There are two methods we can use for setting our working directory. The instructions below describe how to load your data using both methods. You only need to do one. IF you want to try both, make sure you use different folder names.
Outside R, create a new folder called Rcourse (or any name you choose). Create two separate subfolders within Rcourse called R and data.
Open a new R script called wpa_3_LASTFIRST.R (where LASTFIRST is your last and first name), and save it in the R folder.
Use the setwd function to change the working directory to the Rcourse folder. You need to give the filepath to this folder. You can also check the current directory by using getwd,
setwd("/Users/aluckman/Documents/R_Spring2017/Rcourse")
# This should be the filepath to the Rcourse folder on your machine.
getwd()
## [1] "/Users/aluckman/Documents/R_Spring2017/Rcourse"
# This matches the path you just entered.
You can also control your working directory by creating an R-project in RStudio (see Chapter 9 for more details on R-projects). Basically working in an R-project automatically sets your working directory to the location of the R-project file (.RProj).
Start a new R-project called RCourse (or something similar) using the menus. Then (either within RStudio or outside of R), navigate to the location of your RCourse project, and add the folders R and data.
Open a new R script called wpa_3_LASTFIRST.R (where LASTFIRST is your last and first name), and save it in the R folder.
The text file containing the data is called priming.txt. It is available at http://nathanieldphillips.com/wp-content/uploads/2016/10/priming.txt. Open the link, righ-click on the page, and save the file in the data folder.
Using read.table() load the data into a new R object called priming. Note that the text file is tab–delimited and contains a header row, so be sure to include the sep = "\t" and header = TRUE arguments! As priming.txt is in a subfolder of your working directory, you need to include the subfolder in the filename.
priming <- read.table(file = "data/priming.txt",
sep = "\t",
header = TRUE)
Get to know the data using View(), summary(), head() and str().
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).
What was the mean participant age?
How many participants were there from each sex?
What was the median walking time?
What percent of participants passed the attention check (Hint: To calculate a percentage from a 0, 1 variable, use mean())
Walking time is currently in seconds. Add a new column to the dataframe called walking.m That shows the walking time in minutes rather than seconds.
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.
What were the sexes of the first 10 participants?
What was the data for the 50th participant?
What was the mean walking time for the elderly prime condition?
What was the mean walking time for the neutral prime condition?
What was the mean walking time for participants less than 23 years old?
What was the mean walking time for females with a close relationship with their grandparents?
What was the mean walking time for males over 24 years old without a close relationship with their grandparents?
Checkpoint! If you got this far you are doing great!
Create a new dataframe called priming.att that only includes rows where participants passed the attention check. (Hint: use indexing or subset())
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 > ___ )
How many participants gave valid data and passed the attention check? (Hint: Use the result from your previous answer!)
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).
Save your two dataframe objects priming and priming.c in an .RData file called priming.RData in the data folder of your project
Save your priming.c object as a tab–delimited text file called priming_clean.txt in the data folder of your project.
Clean your workspace by running rm(list = ls())
Re-load your two dataframe objects using load().
A colleague of yours wants access to the data from the females given the neutral prime in your experiment. Create a dataframe called priming.f that only includes these data. Additionally, do not include the id column as this could be used to identify the participants.
Save your priming.f object as a tab–delimited text file called priming_females.txt in the data folder of your project.
Save your entire workspace using save.image to an .RData file called priming_ws.RData in the data folder of your project.
The following questions apply to your cleaned dataframe (priming.c)
Did the effect of priming condition on walking times differ between the first 100 and the last 100 participants (Hint: Make sure to index the data using id!)?
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.
Do you find evidence that a participant’s relationship with their grandparents affects how they responded to the primes?
Save and email your ‘.R’ file wpa_3_LastFirst.R to me at ashleyjames.luckman@unibas.ch. Put the subject as WPA3-23496-02.