Replace “Your Name” with your actual name.

Instructions

Please complete this exam on your own. Include your R code, interpretations, and answers within this document.

Part 1: Types of Data and Measurement Errors

Question 1: Data Types in Psychological Research

Read Chapter 2 (Types of Data Psychologists Collect) and answer the following:

  1. Describe the key differences between nominal, ordinal, interval, and ratio data. Provide one example of each from psychological research.

Write your answer(s) here Nominal, consists of categories that are mutually exclusive with no order. Example: gender Ordinal, ordered categories with unequal intervals. Example: scale ratings Interval: categories with equal intervals, no true zero. Example: temperature in celsius Ratio: order4ed categories with equal intervals and a true zero. Example: reaction time

  1. For each of the following variables, identify the appropriate level of measurement (nominal, ordinal, interval, or ratio) and explain your reasoning:
    • Scores on a depression inventory (0-63)
    • Response time in milliseconds
    • Likert scale ratings of agreement (1-7)
    • Diagnostic categories (e.g., ADHD, anxiety disorder, no diagnosis)
    • Age in years

Write your answer(s) here - Scores on a depression inventory (0-63) -> Interval: Measured on a scale with equal intervals between the values, meaning the difference between any two scores is consistent. There is also no true zero point. - Response time in milliseconds -> Ratio: Response time is a continuous variable with a true zero point. - Likert scale ratings of agreement (1-7) -> Ordinal: Likert scale ratings represent an ordered set of categories. Intervals between categories are not guaranteed to be equal, which means it is ordinal data. - Diagnostic categories (e.g., ADHD, anxiety disorder, no diagnosis) -> Nominal: Qualitative categories that have no inherent order or ranking. Categories represent different conditions or states, but there is no meaningful ordering between them. - Age in years -> Ratio: Age is continuous variable with a true zero point. Has equal intervals between values. ### Question 2: Measurement Error Referring to Chapter 3 (Measurement Errors in Psychological Research):

  1. Explain the difference between random and systematic error, providing an example of each in the context of a memory experiment.

Write your answer(s) here Random error is unpredictable and occurs due to chance, like a participant’s fluctuating attention in a memory experiment. Systematic error is consistent and due to flaws in the experiment, such as presenting words too quickly, affecting all participants similarly.

  1. How might measurement error affect the validity of a study examining the relationship between stress and academic performance? What steps could researchers take to minimize these errors?

Write your answer(s) here Measurement error can affect the study by giving incorrect data, which may lead to wrong conclusions about the link between stress and academic performance. To reduce these errors, researchers should use reliable tools, make instructions clear, have a larger sample size, and use objective measurements when possible.


Part 2: Descriptive Statistics and Basic Probability

Question 3: Descriptive Analysis

The code below creates a simulated dataset for a psychological experiment. Run the below code chunk without making any changes:

# Create a simulated dataset
set.seed(123)  # For reproducibility

# Number of participants
n <- 50

# Create the data frame
data <- data.frame(
  participant_id = 1:n,
  reaction_time = rnorm(n, mean = 300, sd = 50),
  accuracy = rnorm(n, mean = 85, sd = 10),
  gender = sample(c("Male", "Female"), n, replace = TRUE),
  condition = sample(c("Control", "Experimental"), n, replace = TRUE),
  anxiety_pre = rnorm(n, mean = 25, sd = 8),
  anxiety_post = NA  # We'll fill this in based on condition
)

# Make the experimental condition reduce anxiety more than control
data$anxiety_post <- ifelse(
  data$condition == "Experimental",
  data$anxiety_pre - rnorm(n, mean = 8, sd = 3),  # Larger reduction
  data$anxiety_pre - rnorm(n, mean = 3, sd = 2)   # Smaller reduction
)

# Ensure anxiety doesn't go below 0
data$anxiety_post <- pmax(data$anxiety_post, 0)

# Add some missing values for realism
data$reaction_time[sample(1:n, 3)] <- NA
data$accuracy[sample(1:n, 2)] <- NA

# View the first few rows of the dataset
head(data)
##   participant_id reaction_time  accuracy gender    condition anxiety_pre
## 1              1      271.9762  87.53319 Female      Control    31.30191
## 2              2      288.4911  84.71453 Female Experimental    31.15234
## 3              3      377.9354  84.57130 Female Experimental    27.65762
## 4              4      303.5254  98.68602   Male      Control    16.93299
## 5              5      306.4644  82.74229 Female      Control    24.04438
## 6              6      385.7532 100.16471 Female      Control    22.75684
##   anxiety_post
## 1     29.05312
## 2     19.21510
## 3     20.45306
## 4     13.75199
## 5     17.84736
## 6     19.93397

Now, perform the following computations*:

  1. Calculate the mean, median, standard deviation, minimum, and maximum for reaction time and accuracy, grouped by condition (hint: use the psych package).
library(psych)
describe(data$accuracy)
##    vars  n mean   sd median trimmed  mad   min    max range  skew kurtosis   se
## X1    1 48 86.5 9.23  86.53   86.52 8.65 61.91 106.87 44.97 -0.05    -0.06 1.33
  1. Using dplyr and piping, create a new variable anxiety_change that represents the difference between pre and post anxiety scores (pre minus post). Then calculate the mean anxiety change for each condition.
library(dplyr)
head(data)
##   participant_id reaction_time  accuracy gender    condition anxiety_pre
## 1              1      271.9762  87.53319 Female      Control    31.30191
## 2              2      288.4911  84.71453 Female Experimental    31.15234
## 3              3      377.9354  84.57130 Female Experimental    27.65762
## 4              4      303.5254  98.68602   Male      Control    16.93299
## 5              5      306.4644  82.74229 Female      Control    24.04438
## 6              6      385.7532 100.16471 Female      Control    22.75684
##   anxiety_post
## 1     29.05312
## 2     19.21510
## 3     20.45306
## 4     13.75199
## 5     17.84736
## 6     19.93397
data %>%
  mutate(anxiety_change = anxiety_pre - anxiety_post)
##    participant_id reaction_time  accuracy gender    condition anxiety_pre
## 1               1      271.9762  87.53319 Female      Control    31.30191
## 2               2      288.4911  84.71453 Female Experimental    31.15234
## 3               3      377.9354  84.57130 Female Experimental    27.65762
## 4               4      303.5254  98.68602   Male      Control    16.93299
## 5               5      306.4644  82.74229 Female      Control    24.04438
## 6               6      385.7532 100.16471 Female      Control    22.75684
## 7               7      323.0458  69.51247 Female      Control    29.50392
## 8               8      236.7469  90.84614   Male      Control    22.02049
## 9               9            NA  86.23854 Female Experimental    32.81579
## 10             10      277.7169  87.15942 Female      Control    22.00335
## 11             11            NA  88.79639 Female Experimental    33.42169
## 12             12      317.9907  79.97677   Male Experimental    16.60658
## 13             13      320.0386  81.66793   Male Experimental    14.91876
## 14             14      305.5341  74.81425 Female      Control    50.92832
## 15             15      272.2079  74.28209 Female Experimental    21.66514
## 16             16            NA  88.03529 Female      Control    27.38582
## 17             17      324.8925  89.48210 Female Experimental    30.09256
## 18             18      201.6691  85.53004   Male      Control    21.12975
## 19             19      335.0678  94.22267 Female      Control    29.13490
## 20             20      276.3604 105.50085   Male      Control    27.95172
## 21             21      246.6088  80.08969 Female      Control    23.27696
## 22             22      289.1013  61.90831   Male      Control    25.52234
## 23             23      248.6998  95.05739   Male      Control    24.72746
## 24             24      263.5554  77.90799   Male Experimental    42.02762
## 25             25      268.7480  78.11991 Female      Control    19.06931
## 26             26      215.6653  95.25571 Female Experimental    16.23203
## 27             27      341.8894  82.15227   Male      Control    25.30231
## 28             28      307.6687  72.79282   Male      Control    27.48385
## 29             29      243.0932  86.81303 Female      Control    28.49219
## 30             30      362.6907        NA   Male      Control    21.33308
## 31             31      321.3232  85.05764   Male Experimental    16.49339
## 32             32      285.2464  88.85280 Female Experimental    35.10548
## 33             33      344.7563  81.29340 Female      Control    22.20280
## 34             34      343.9067  91.44377   Male      Control    18.07590
## 35             35      341.0791  82.79513 Female      Control    23.10976
## 36             36      334.4320  88.31782 Female Experimental    23.42259
## 37             37      327.6959  95.96839 Female Experimental    33.87936
## 38             38      296.9044  89.35181 Female Experimental    25.67790
## 39             39      284.7019  81.74068 Female      Control    31.03243
## 40             40      280.9764  96.48808   Male Experimental    21.00566
## 41             41      265.2647  94.93504   Male      Control    26.71556
## 42             42      289.6041  90.48397 Female      Control    22.40251
## 43             43      236.7302        NA   Male      Control    25.75667
## 44             44      408.4478  78.72094 Female      Control    17.83709
## 45             45      360.3981  98.60652   Male      Control    14.51359
## 46             46      243.8446  78.99740   Male Experimental    40.97771
## 47             47      279.8558 106.87333   Male Experimental    29.80567
## 48             48      276.6672 100.32611 Female Experimental    14.98983
## 49             49      338.9983  82.64300 Female      Control    20.11067
## 50             50      295.8315  74.73579 Female      Control    15.51616
##    anxiety_post anxiety_change
## 1     29.053117     2.24879426
## 2     19.215099    11.93723893
## 3     20.453056     7.20456483
## 4     13.751994     3.18099329
## 5     17.847362     6.19701754
## 6     19.933968     2.82286978
## 7     24.342317     5.16159899
## 8     17.758982     4.26150823
## 9     19.863065    12.95272240
## 10    22.069157    -0.06580401
## 11    25.063956     8.35773571
## 12     7.875522     8.73106229
## 13     3.221330    11.69742764
## 14    45.327922     5.60039736
## 15    16.642661     5.02247855
## 16    21.290659     6.09516212
## 17    23.416047     6.67651035
## 18    21.642810    -0.51305479
## 19    26.912456     2.22244027
## 20    24.773302     3.17841445
## 21    18.586930     4.69002601
## 22    20.597288     4.92505594
## 23    20.358843     4.36861886
## 24    31.904850    10.12276506
## 25    14.370025     4.69928609
## 26     8.052780     8.17924981
## 27    21.952702     3.34960540
## 28    24.334744     3.14910235
## 29    24.635854     3.85633353
## 30    18.283727     3.04934997
## 31     2.627509    13.86588190
## 32    27.376440     7.72904122
## 33    18.430744     3.77205314
## 34    15.607200     2.46869675
## 35    19.873474     3.23628902
## 36    19.373641     4.04895160
## 37    26.428138     7.45122383
## 38    16.420951     9.25694721
## 39    28.470531     2.56189924
## 40    15.350273     5.65539054
## 41    21.378795     5.33676775
## 42    17.294151     5.10836205
## 43    20.466142     5.29052622
## 44    15.992029     1.84506400
## 45     7.508622     7.00496546
## 46    27.270622    13.70708547
## 47    22.108595     7.69707534
## 48    11.069351     3.92047789
## 49    17.068705     3.04196717
## 50    10.016330     5.49982914

Write your answer(s) here The mean between pre anxiety and post anxiety scores is 5.64 when you subtract pre anxiety and post anxiety.

Question 4: Probability Calculations

Using the concepts from Chapter 4 (Descriptive Statistics and Basic Probability in Psychological Research):

  1. If reaction times in a cognitive task are normally distributed with a mean of 350ms and a standard deviation of 75ms:
    1. What is the probability that a randomly selected participant will have a reaction time greater than 450ms?
    2. What is the probability that a participant will have a reaction time between 300ms and 400ms?
1 - pnorm(450, mean = 350, sd = 75)
## [1] 0.09121122
pnorm(400, mean = 350, sd = 75) - pnorm(300, mean=350, sd = 75)
## [1] 0.4950149

Write your answer(s) here The probability that a randomly selected participant will have a reaction time greater than 450 ms is 9.12% and the probability that a randomly selected participant will have a reaction time between 300ms and 400ms is 49.50%


Part 3: Data Cleaning and Manipulation

Question 5: Data Cleaning with dplyr

Using the dataset created in Part 2, perform the following data cleaning and manipulation tasks:

  1. Remove all rows with missing values and create a new dataset called clean_data.
clean_data <- data %>%
  na.omit()
print(clean_data)
##    participant_id reaction_time  accuracy gender    condition anxiety_pre
## 1               1      271.9762  87.53319 Female      Control    31.30191
## 2               2      288.4911  84.71453 Female Experimental    31.15234
## 3               3      377.9354  84.57130 Female Experimental    27.65762
## 4               4      303.5254  98.68602   Male      Control    16.93299
## 5               5      306.4644  82.74229 Female      Control    24.04438
## 6               6      385.7532 100.16471 Female      Control    22.75684
## 7               7      323.0458  69.51247 Female      Control    29.50392
## 8               8      236.7469  90.84614   Male      Control    22.02049
## 10             10      277.7169  87.15942 Female      Control    22.00335
## 12             12      317.9907  79.97677   Male Experimental    16.60658
## 13             13      320.0386  81.66793   Male Experimental    14.91876
## 14             14      305.5341  74.81425 Female      Control    50.92832
## 15             15      272.2079  74.28209 Female Experimental    21.66514
## 17             17      324.8925  89.48210 Female Experimental    30.09256
## 18             18      201.6691  85.53004   Male      Control    21.12975
## 19             19      335.0678  94.22267 Female      Control    29.13490
## 20             20      276.3604 105.50085   Male      Control    27.95172
## 21             21      246.6088  80.08969 Female      Control    23.27696
## 22             22      289.1013  61.90831   Male      Control    25.52234
## 23             23      248.6998  95.05739   Male      Control    24.72746
## 24             24      263.5554  77.90799   Male Experimental    42.02762
## 25             25      268.7480  78.11991 Female      Control    19.06931
## 26             26      215.6653  95.25571 Female Experimental    16.23203
## 27             27      341.8894  82.15227   Male      Control    25.30231
## 28             28      307.6687  72.79282   Male      Control    27.48385
## 29             29      243.0932  86.81303 Female      Control    28.49219
## 31             31      321.3232  85.05764   Male Experimental    16.49339
## 32             32      285.2464  88.85280 Female Experimental    35.10548
## 33             33      344.7563  81.29340 Female      Control    22.20280
## 34             34      343.9067  91.44377   Male      Control    18.07590
## 35             35      341.0791  82.79513 Female      Control    23.10976
## 36             36      334.4320  88.31782 Female Experimental    23.42259
## 37             37      327.6959  95.96839 Female Experimental    33.87936
## 38             38      296.9044  89.35181 Female Experimental    25.67790
## 39             39      284.7019  81.74068 Female      Control    31.03243
## 40             40      280.9764  96.48808   Male Experimental    21.00566
## 41             41      265.2647  94.93504   Male      Control    26.71556
## 42             42      289.6041  90.48397 Female      Control    22.40251
## 44             44      408.4478  78.72094 Female      Control    17.83709
## 45             45      360.3981  98.60652   Male      Control    14.51359
## 46             46      243.8446  78.99740   Male Experimental    40.97771
## 47             47      279.8558 106.87333   Male Experimental    29.80567
## 48             48      276.6672 100.32611 Female Experimental    14.98983
## 49             49      338.9983  82.64300 Female      Control    20.11067
## 50             50      295.8315  74.73579 Female      Control    15.51616
##    anxiety_post
## 1     29.053117
## 2     19.215099
## 3     20.453056
## 4     13.751994
## 5     17.847362
## 6     19.933968
## 7     24.342317
## 8     17.758982
## 10    22.069157
## 12     7.875522
## 13     3.221330
## 14    45.327922
## 15    16.642661
## 17    23.416047
## 18    21.642810
## 19    26.912456
## 20    24.773302
## 21    18.586930
## 22    20.597288
## 23    20.358843
## 24    31.904850
## 25    14.370025
## 26     8.052780
## 27    21.952702
## 28    24.334744
## 29    24.635854
## 31     2.627509
## 32    27.376440
## 33    18.430744
## 34    15.607200
## 35    19.873474
## 36    19.373641
## 37    26.428138
## 38    16.420951
## 39    28.470531
## 40    15.350273
## 41    21.378795
## 42    17.294151
## 44    15.992029
## 45     7.508622
## 46    27.270622
## 47    22.108595
## 48    11.069351
## 49    17.068705
## 50    10.016330
  1. Create a new variable performance_category that categorizes participants based on their accuracy:
    • “High” if accuracy is greater than or equal to 90
    • “Medium” if accuracy is between 70 and 90
    • “Low” if accuracy is less than 70
clean_data <- data %>%
  mutate(performance_category = case_when(accuracy >= 90 ~ "High", accuracy >= 70 & accuracy < 90 ~ "Medium", accuracy < 70 ~ "Low"))
print(clean_data)
##    participant_id reaction_time  accuracy gender    condition anxiety_pre
## 1               1      271.9762  87.53319 Female      Control    31.30191
## 2               2      288.4911  84.71453 Female Experimental    31.15234
## 3               3      377.9354  84.57130 Female Experimental    27.65762
## 4               4      303.5254  98.68602   Male      Control    16.93299
## 5               5      306.4644  82.74229 Female      Control    24.04438
## 6               6      385.7532 100.16471 Female      Control    22.75684
## 7               7      323.0458  69.51247 Female      Control    29.50392
## 8               8      236.7469  90.84614   Male      Control    22.02049
## 9               9            NA  86.23854 Female Experimental    32.81579
## 10             10      277.7169  87.15942 Female      Control    22.00335
## 11             11            NA  88.79639 Female Experimental    33.42169
## 12             12      317.9907  79.97677   Male Experimental    16.60658
## 13             13      320.0386  81.66793   Male Experimental    14.91876
## 14             14      305.5341  74.81425 Female      Control    50.92832
## 15             15      272.2079  74.28209 Female Experimental    21.66514
## 16             16            NA  88.03529 Female      Control    27.38582
## 17             17      324.8925  89.48210 Female Experimental    30.09256
## 18             18      201.6691  85.53004   Male      Control    21.12975
## 19             19      335.0678  94.22267 Female      Control    29.13490
## 20             20      276.3604 105.50085   Male      Control    27.95172
## 21             21      246.6088  80.08969 Female      Control    23.27696
## 22             22      289.1013  61.90831   Male      Control    25.52234
## 23             23      248.6998  95.05739   Male      Control    24.72746
## 24             24      263.5554  77.90799   Male Experimental    42.02762
## 25             25      268.7480  78.11991 Female      Control    19.06931
## 26             26      215.6653  95.25571 Female Experimental    16.23203
## 27             27      341.8894  82.15227   Male      Control    25.30231
## 28             28      307.6687  72.79282   Male      Control    27.48385
## 29             29      243.0932  86.81303 Female      Control    28.49219
## 30             30      362.6907        NA   Male      Control    21.33308
## 31             31      321.3232  85.05764   Male Experimental    16.49339
## 32             32      285.2464  88.85280 Female Experimental    35.10548
## 33             33      344.7563  81.29340 Female      Control    22.20280
## 34             34      343.9067  91.44377   Male      Control    18.07590
## 35             35      341.0791  82.79513 Female      Control    23.10976
## 36             36      334.4320  88.31782 Female Experimental    23.42259
## 37             37      327.6959  95.96839 Female Experimental    33.87936
## 38             38      296.9044  89.35181 Female Experimental    25.67790
## 39             39      284.7019  81.74068 Female      Control    31.03243
## 40             40      280.9764  96.48808   Male Experimental    21.00566
## 41             41      265.2647  94.93504   Male      Control    26.71556
## 42             42      289.6041  90.48397 Female      Control    22.40251
## 43             43      236.7302        NA   Male      Control    25.75667
## 44             44      408.4478  78.72094 Female      Control    17.83709
## 45             45      360.3981  98.60652   Male      Control    14.51359
## 46             46      243.8446  78.99740   Male Experimental    40.97771
## 47             47      279.8558 106.87333   Male Experimental    29.80567
## 48             48      276.6672 100.32611 Female Experimental    14.98983
## 49             49      338.9983  82.64300 Female      Control    20.11067
## 50             50      295.8315  74.73579 Female      Control    15.51616
##    anxiety_post performance_category
## 1     29.053117               Medium
## 2     19.215099               Medium
## 3     20.453056               Medium
## 4     13.751994                 High
## 5     17.847362               Medium
## 6     19.933968                 High
## 7     24.342317                  Low
## 8     17.758982                 High
## 9     19.863065               Medium
## 10    22.069157               Medium
## 11    25.063956               Medium
## 12     7.875522               Medium
## 13     3.221330               Medium
## 14    45.327922               Medium
## 15    16.642661               Medium
## 16    21.290659               Medium
## 17    23.416047               Medium
## 18    21.642810               Medium
## 19    26.912456                 High
## 20    24.773302                 High
## 21    18.586930               Medium
## 22    20.597288                  Low
## 23    20.358843                 High
## 24    31.904850               Medium
## 25    14.370025               Medium
## 26     8.052780                 High
## 27    21.952702               Medium
## 28    24.334744               Medium
## 29    24.635854               Medium
## 30    18.283727                 <NA>
## 31     2.627509               Medium
## 32    27.376440               Medium
## 33    18.430744               Medium
## 34    15.607200                 High
## 35    19.873474               Medium
## 36    19.373641               Medium
## 37    26.428138                 High
## 38    16.420951               Medium
## 39    28.470531               Medium
## 40    15.350273                 High
## 41    21.378795                 High
## 42    17.294151                 High
## 43    20.466142                 <NA>
## 44    15.992029               Medium
## 45     7.508622                 High
## 46    27.270622               Medium
## 47    22.108595                 High
## 48    11.069351                 High
## 49    17.068705               Medium
## 50    10.016330               Medium
  1. Filter the dataset to include only participants in the Experimental condition with reaction times faster than the overall mean reaction time.
filtered_data <-data %>%
  filter(reaction_time > 311.75 & condition == "Experimental")
print(filtered_data)
##   participant_id reaction_time accuracy gender    condition anxiety_pre
## 1              3      377.9354 84.57130 Female Experimental    27.65762
## 2             12      317.9907 79.97677   Male Experimental    16.60658
## 3             13      320.0386 81.66793   Male Experimental    14.91876
## 4             17      324.8925 89.48210 Female Experimental    30.09256
## 5             31      321.3232 85.05764   Male Experimental    16.49339
## 6             36      334.4320 88.31782 Female Experimental    23.42259
## 7             37      327.6959 95.96839 Female Experimental    33.87936
##   anxiety_post
## 1    20.453056
## 2     7.875522
## 3     3.221330
## 4    23.416047
## 5     2.627509
## 6    19.373641
## 7    26.428138

Write your answer(s) here describing your data cleaning process. Able to pipe and filter to the experimental data drom the condition column and then print data lined up with reaction times that were greater than the mean of 311.75.


Part 4: Visualization and Correlation Analysis

Question 6: Correlation Analysis with the psych Package

Using the psych package, create a correlation plot for the simulated dataset created in Part 2. Include the following steps:

  1. Select the numeric variables from the dataset (reaction_time, accuracy, anxiety_pre, anxiety_post, and anxiety_change if you created it).
  2. Use the psych package’s corPlot() function to create a correlation plot.
  3. Interpret the resulting plot by addressing:
    • Which variables appear to be strongly correlated?
    • Are there any surprising relationships?
    • How might these correlations inform further research in psychology?
library(psych)
corPlot(cor(reaction_time))

**Write your answer(s) here**

---

## Part 5: Reflection and Application 

### Question 7: Reflection
Reflect on how the statistical concepts and R techniques covered in this course apply to psychological research:

1. Describe a specific research question in psychology that interests you. What type of data would you collect, what statistical analyses would be appropriate, and what potential measurement errors might you need to address?

2. How has learning R for data analysis changed your understanding of psychological statistics? What do you see as the biggest advantages and challenges of using R compared to other statistical software?

**Write your answer(s) here**
A research question I'm interested in is: How does sleep deprivation affect reaction time and accuracy in attention tasks? I would collect data on sleep duration, reaction times, and accuracy. Descriptive statistics and paired-samples t-tests would help compare performance before and after sleep deprivation. Measurement errors might include self-report bias in sleep duration and other factors like mood or motivation affecting performance.

Learning R has improved my understanding of statistics by showing how to manipulate data and automate analyses. R offers flexibility and power for complex analyses, but its steep learning curve and need for coding skills can be challenging compared to easier-to-use software like SPSS.


---

#### Submission Instructions:

Ensure to knit your document to HTML format, checking that all content is correctly displayed before submission. Publish your assignment to RPubs and submit the URL to canvas.
## Error in parse(text = input): <text>:4:1: unexpected '^'
## 3: 
## 4: **
##    ^