### Instructions #' Please read everything carefully. #' Anything following '#' is a comment that is meant for a person to read. #' Everything else is syntax that can be ran in R. #' Your task is to follow the steps below. #' Throughout this document you will be adding in your own code to answer the questions. #' You will then email this script to Garrett and relabel the script: LastName_FirstName_PSY392_HW1 #' I will run your code to see if it works. #' Some questions ask you to provide a written response, do so with comments using # #' This homework needs to be sent to Garrett by 5:00 pm on Friday, September 6 *** ### Step 0 - Download this file #' If you left-click on the Homework 1 link it will open a tab in your browser that displays text. #' You can copy and paste the content of that page into a new R script. #' Or you can right click on the Homework 1 link and click save as then select save as R script. ### Step 1 - Download the data #' For this homework you will be working with the class data from STATLAB - Speeded Reaction Time. #' You can download this data from the class website: http://www2.psych.purdue.edu/~gfrancis/Classes/PSY392/indexF19.html #' Once at the website, navigate to the row containing August 26. #' The data is located in the far right column of this row. #' Download the data by clicking on '(class data)'. #' If you are having trouble downloading the data you may need to right click on the class data link and select save link as. ### Step 2 - Set up working directories #' Now that the data is downloaded it is important to set up a working directory. #' You can do this however you like, but this is how I typically set up my folder structures for classes. i.e., a folder for PSY 392 #' Inside my PSY 392 folder I create a folder for homework - i.e., 'HW' #' Place this R script and the data file into this homework subfolder within your class folder. #' When you use this R script in RStudio you will need to tell it what the working directory is. #' To do this click on Session within the top menu bar. #' Then click on Set Working Directory => Choose Directory. #' Then navigate to your HW subfolder that you created, which is where this Rscript and the data should now be. #' The point of all of this is to tell R where necessary files are located on your computer so that R can work with them. ### Step 3 - Read in data #' Now you can check if your working directory has been set correctly. getwd() # what is my current working directory? #' Is the data file in your current working directory list.files() # what are the files in my current working directory? # read in the csv file that contains the class data - be sure to specify the correct file! HW1data <-read.csv("SimpleRT.csv") # we are going to store the data into a variable called HW1data ### Step 4 - Getting to know the data #' You should now see HW1data in the top right portion of RStudio in the Global Enivronment window #' It tells you that there are 600 observations in 2 columns names(HW1data) # what are the names of the column in my data? #' Uh oh! We do not have a subject number column. #' To fix this we can create a new column that creates an id number that repeats for the number of trials each participant completed #' We know that each participant completed 50 trials. Thus, our subject id variable will repeat 50 times for each participant before changing. #' We also know that we have 600 total observations. 600 total observations divided by 50 observations per person = 12 people. #' So, we will create 12 subject numbers that each repeat 50 times. #' We then create a new column in our data frame for subjectNumbers HW1data$subjectNumber <- rep(1:12, each = 50) view(HW1data) # look at data and see that subject numbers repeat 50 times and then increases ### Step 5 - Descriptive statistics #' If you are not sure how to do this in R then you should search for the information online. #' An important part of programming is learning how to learning program on your own. #' Of course, if you are struggling please contact us or come to office hours. #' Compute the following statistcs for ReactionTime_ms: #' Mean #' Median #' Mode #' Standard deviation #' Variance #' Minimum value #' Maximum value #' Range ### Step 6 - Data visualization #' Try your best to create a visualization of the data #' Here is a link to some simple plots in R - https://www.statmethods.net/graphs/index.html #' Provide reasoning for the type of plot you chose #' Describe your visualization ### Step 7 - Data tidying at the subject level #' So, far we have looked at the data for every trial for every person. #' However, we frequently care about how individual people or groups do. #' Thus, we need to average across every trial for each participant to get the average reaction time for each person. #' To do this I am going to use the tidyverse package install.packages("tidyverse") # install the package we need -- you only need to do this once library(tidyverse) # make sure the package is loaded. #' The tidyverse uses the pipe symbol '%>%' #' The shortcut for this is control + shift + m on pc or command + shift + m on mac subDataHW1 <- HW1data %>% # create a new data frame from the HW1data group_by(subjectNumber) %>% # that groups the data by subject number summarize(meanSubRT_ms = mean(ReactionTime_ms)) # then summarize the data by calculating the mean RT for each subject ### Step 8 #' Who was the fastest subject? #' Who was the slowest subject? #' Create a visualization of the distribution of meanRTs at the subject level #' Provide reasoning for the type of plot you chose #' Describe your visualization