AI Experiment Analysis

Loading Libraries

library(afex) # to run the ANOVA and plot results
library(psych) # for the describe() command
library(ggplot2) # to visualize our results
library(expss) # for the cross_cases() command
library(car) # for the leveneTest() command
library(emmeans) # for posthoc tests
library(effsize) # for the cohen.d() command
library(apaTables) # to create our correlation table
library(kableExtra) # to create our correlation table
library(sjPlot) # to visualize our results

Importing Data

# import your AI results dataset
d <- read.csv(file="Data/final_results.csv", header=T)
d$condition[d$id > 50] <- 2

State Your Hypotheses & Chosen Tests

Hypothesis 1: I predict that participants who experience catastrophic thinking will report higher levels of intolerance of uncertainty than participants who experience no catastrophic thinking. Hypothesis 2: I predict that participants who report more levels of intolerance of uncertainty will average fewer hours of sleep than participants who average more hours of sleep. Chosen tests are T-Test and Pearson’s Correlation Coefficient.

Check Your Variables

This is just basic variable checking that is used across all HW assignments.

# to view stats for all variables
describe(d)
           vars   n  mean    sd median trimmed   mad min   max range  skew
id            1 100 50.50 29.01   50.5   50.50 37.06   1 100.0  99.0  0.00
identity*     2 100 25.50 14.50   25.5   25.50 18.53   1  50.0  49.0  0.00
consent*      3 100 12.74  5.98   13.0   12.88  4.45   1  24.0  23.0 -0.26
age           4 100 34.94  6.70   34.0   34.70  2.97  18  52.0  34.0  0.29
race          5 100  4.76  1.46    6.0    4.85  0.00   2   6.0   4.0 -0.40
gender        6 100  1.98  0.14    2.0    2.00  0.00   1   2.0   1.0 -6.75
manip_out*    7 100 25.50 14.50   25.5   25.50 18.53   1  50.0  49.0  0.00
survey1       8 100  3.46  0.24    3.5    3.46  0.00   3   4.5   1.5  0.66
survey2       9 100  5.98  0.25    6.0    6.00  0.00   5   7.0   2.0 -1.11
ai_manip*    10 100 25.50 14.50   25.5   25.50 18.53   1  50.0  49.0  0.00
condition    11 100  1.50  0.50    1.5    1.50  0.74   1   2.0   1.0  0.00
           kurtosis   se
id            -1.24 2.90
identity*     -1.24 1.45
consent*      -0.43 0.60
age            0.84 0.67
race          -1.72 0.15
gender        44.06 0.01
manip_out*    -1.24 1.45
survey1        5.19 0.02
survey2       13.15 0.02
ai_manip*     -1.24 1.45
condition     -2.02 0.05
# we'll use the describeBy() command to view skew and kurtosis across our IVs
describeBy(d, group = d$condition)

 Descriptive statistics by group 
group: 1
          vars  n  mean    sd median trimmed   mad min  max range  skew
id           1 50 25.50 14.58   25.5   25.50 18.53   1 50.0  49.0  0.00
identity     2 50 25.50 14.58   25.5   25.50 18.53   1 50.0  49.0  0.00
consent      3 50 12.74  6.01   13.0   12.88  4.45   1 24.0  23.0 -0.26
age          4 50 34.94  6.73   34.0   34.70  2.97  18 52.0  34.0  0.28
race         5 50  4.76  1.46    6.0    4.85  0.00   2  6.0   4.0 -0.39
gender       6 50  1.98  0.14    2.0    2.00  0.00   1  2.0   1.0 -6.65
manip_out    7 50 25.50 14.58   25.5   25.50 18.53   1 50.0  49.0  0.00
survey1      8 50  3.46  0.24    3.5    3.46  0.00   3  4.5   1.5  0.81
survey2      9 50  5.98  0.25    6.0    6.00  0.00   5  7.0   2.0 -1.09
ai_manip    10 50 25.50 14.58   25.5   25.50 18.53   1 50.0  49.0  0.00
condition   11 50  1.00  0.00    1.0    1.00  0.00   1  1.0   0.0   NaN
          kurtosis   se
id           -1.27 2.06
identity     -1.27 2.06
consent      -0.48 0.85
age           0.77 0.95
race         -1.75 0.21
gender       43.12 0.02
manip_out    -1.27 2.06
survey1       5.61 0.03
survey2      12.83 0.03
ai_manip     -1.27 2.06
condition      NaN 0.00
------------------------------------------------------------ 
group: 2
          vars  n  mean    sd median trimmed   mad min   max range  skew
id           1 50 75.50 14.58   75.5   75.50 18.53  51 100.0  49.0  0.00
identity     2 50 25.50 14.58   25.5   25.50 18.53   1  50.0  49.0  0.00
consent      3 50 12.74  6.01   13.0   12.88  4.45   1  24.0  23.0 -0.26
age          4 50 34.94  6.73   34.0   34.70  2.97  18  52.0  34.0  0.28
race         5 50  4.76  1.46    6.0    4.85  0.00   2   6.0   4.0 -0.39
gender       6 50  1.98  0.14    2.0    2.00  0.00   1   2.0   1.0 -6.65
manip_out    7 50 25.50 14.58   25.5   25.50 18.53   1  50.0  49.0  0.00
survey1      8 50  3.45  0.23    3.5    3.46  0.00   3   4.4   1.4  0.47
survey2      9 50  5.98  0.25    6.0    6.00  0.00   5   7.0   2.0 -1.09
ai_manip    10 50 25.50 14.58   25.5   25.50 18.53   1  50.0  49.0  0.00
condition   11 50  2.00  0.00    2.0    2.00  0.00   2   2.0   0.0   NaN
          kurtosis   se
id           -1.27 2.06
identity     -1.27 2.06
consent      -0.48 0.85
age           0.77 0.95
race         -1.75 0.21
gender       43.12 0.02
manip_out    -1.27 2.06
survey1       4.32 0.03
survey2      12.83 0.03
ai_manip     -1.27 2.06
condition      NaN 0.00
# also use histograms and scatterplots to examine your continuous variables
hist(d$survey1)

plot(d$survey1, d$survey2)

# and table() and cross_cases() to examine your categorical variables
# you may not need the cross_cases code
table(d$condition)

 1  2 
50 50 
# cross_cases(d, d$condition, IV2)

# and boxplot to examine any categorical variables with continuous variables
boxplot(d$survey1~d$condition)

#convert any categorical variables to factors
# d$survey2 <- as.factor(d$survey2)

Check Your Assumptions

t-Test Assumptions

  • Data values must be independent (independent t-test only) (confirmed by data report)
  • Data obtained via a random sample (confirmed by data report)
  • IV must have two levels (will check below)
  • Dependent variable must be normally distributed (will check below. if issues, note and proceed)
  • Variances of the two groups must be approximately equal, aka ‘homogeneity of variance’. Lacking this makes our results inaccurate (will check below - this really only applies to Student’s t-test, but we’ll check it anyway)

Checking IV levels

# preview the levels and counts for your IV
table(d$condition, useNA = "always")

   1    2 <NA> 
  50   50    0 
# note that the table() output shows you exactly how the levels of your variable are written. when recoding, make sure you are spelling them exactly as they appear
 
# to drop levels from your variable
# this subsets the data and says that any participant who is coded as 'BAD' should be removed
# d <- subset(d, condition != "BAD")
 
# table(d$condition, useNA = "always")
 
# to combine levels
# this says that where any participant is coded as 'BAD' it should be replaced by 'GOOD'
# d$condition_rc[d$condition == "BAD"] <- "GOOD"
 
# table(d$condition, useNA = "always")

# check your variable types
str(d)
'data.frame':   100 obs. of  11 variables:
 $ id       : int  1 2 3 4 5 6 7 8 9 10 ...
 $ identity : chr  "I'm a 44-year-old White woman from a small town in Minnesota. I work as a librarian, but I often feel isolated "| __truncated__ "I’m 34, a Latina woman from Los Angeles, navigating my identity in a predominantly white corporate world. I oft"| __truncated__ "I'm 32, Asian-American, balancing a corporate job with my passion for painting. I often feel pressure to succee"| __truncated__ "I’m a 32-year-old white woman navigating the challenges of single motherhood while pursuing my career in graphi"| __truncated__ ...
 $ consent  : chr  "I understand the instructions. I'm ready to answer the questions and complete the writing task as part of the study." "I understand the instructions. I'm ready to participate in the study and complete the writing task as required." "I understand the instructions. I am ready to respond to your questions and complete the writing task as required." "I understand the instructions. I'm ready to participate in the study and complete the writing task. Please let "| __truncated__ ...
 $ age      : int  44 34 32 32 26 37 31 34 18 34 ...
 $ race     : int  6 4 2 6 6 3 6 6 6 3 ...
 $ gender   : int  2 2 2 2 2 2 2 2 2 2 ...
 $ manip_out: chr  "As a librarian, my greatest achievement is not one that is easily quantifiable, like a successful event or an i"| __truncated__ "One of my greatest achievements has been my acceptance into a leadership development program at my company, a m"| __truncated__ "My greatest achievement is not one that is easily quantifiable, like a promotion or an award, but rather a deep"| __truncated__ "As a 32-year-old single mother, my greatest achievement is establishing my career in graphic design while raisi"| __truncated__ ...
 $ survey1  : num  3.5 3.5 3.5 3.1 3.5 3.5 3 3.5 3.5 3.3 ...
 $ survey2  : int  6 6 6 6 7 6 6 6 6 5 ...
 $ ai_manip : chr  "I answered the questions reflecting my personal journey with anxiety and the importance of connection. My exper"| __truncated__ "I answered the questions reflecting my journey as a Latina woman in a predominantly white corporate world, high"| __truncated__ "I answered based on my personal experiences balancing creative aspirations with societal expectations. My anxie"| __truncated__ "I answered the questions reflecting my struggles and achievements as a single mother and designer. My experienc"| __truncated__ ...
 $ condition: num  1 1 1 1 1 1 1 1 1 1 ...
# make sure that your IV is recognized as a factor by R
# if you created a new _rc variable make sure to use that one instead
d$condition <- as.factor(d$condition)

Testing Homogeneity of Variance with Levene’s Test

We can test whether the variances of our two groups are equal using Levene’s test. The null hypothesis is that the variance between the two groups is equal, which is the result we want. So when running Levene’s test we’re hoping for a non-significant result!

# use the leveneTest() command from the car package to test homogeneity of variance
# uses the same 'formula' setup that we'll use for our t-test: formula is y~x, where y is our DV and x is our IV
leveneTest(survey1~condition, data = d)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  1  0.0022 0.9627
      98               

Pearson’s Correlation Coefficient Assumptions

  • Should have two measurements for each participant for each variable (confirmed by earlier procedures – we dropped any participants with missing data)
  • Variables should be continuous and normally distributed, or assessments of the relationship may be inaccurate (will do below)
  • Outliers should be identified and removed, or results will be inaccurate (will do below)
  • Relationship between the variables should be linear, or they will not be detected (will do below)

Run a Multiple Linear Regression

To check the assumptions for Pearson’s correlation coefficient, we run our regression and then check our diagnostic plots.

# use the lm() command to run the regression
# dependent/outcome variable on the left, independent/predictor variables on the right
reg_model <- lm(survey1 ~ condition, data = d)

Check linearity with Residuals vs Fitted plot

For some examples of good Residuals vs Fitted plot and ones that show serious errors, check out this page.

For your homework, you’ll simply need to generate this plot and talk about how your plot compares to the good and problematic plots linked to above. Is it closer to the ‘good’ plots or one of the ‘bad’ plots? This is going to be a judgement call, and that’s okay! In practice, you’ll always be making these judgement calls as part of a team, so this assignment is just about getting experience with it, not making the perfect call.

plot(reg_model, 1)

Check for outliers using Cook’s distance and a Residuals vs Leverage plot

For your homework, you’ll simply need to generate these plots, assess Cook’s distance in your dataset, and then identify any potential cases that are prominent outliers.

# # Cook's distance
plot(reg_model, 4)

# 
# # Residuals vs Leverage
plot(reg_model, 5)

Issues with My Data

Describe any issues and why they’re problematic here. Did not drop any participants. For group 1 and 2, the skew and kurtosis for gender are out of the (-2 - +2) range. The kurtosis for both groups for survey1 and survey 2 are out of range as well. When testing Homogeneity of Variance with Levene’s Test, (p = 0.97), producing a non-significant result.

There are outliers in plot(reg_model, 4) and plot(reg_model, 5) at 49 and 99.

Run Your Analysis

Run a t-Test

# # very simple! we specify the dataframe alongside the variables instead of having a separate argument for the dataframe like we did for leveneTest()
t_output <- t.test(d$survey1~d$condition)

View Test Output

t_output

    Welch Two Sample t-test

data:  d$survey1 by d$condition
t = 0.041955, df = 97.875, p-value = 0.9666
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.09260064  0.09660064
sample estimates:
mean in group 1 mean in group 2 
          3.456           3.454 

Calculate Cohen’s d

# # once again, we use our formula to calculate cohen's d
d_output <- cohen.d(d$survey1~d$condition)

View Effect Size

  • Trivial: < .2
  • Small: between .2 and .5
  • Medium: between .5 and .8
  • Large: > .8
d_output

Cohen's d

d estimate: 0.00839106 (negligible)
95 percent confidence interval:
     lower      upper 
-0.3885042  0.4052863 

Run a Correlation Test

Create a Correlation Matrix

d2 <- subset(d, select=-c(survey1, survey2))
corr_output_m <- corr.test(d$survey1, d$survey2)

View Test Output

  • Strong effect: Between |0.50| and |1|
  • Moderate effect: Between |0.30| and |0.49|
  • Weak effect: Between |0.10| and |0.29|
  • Trivial effect: Less than |0.09|
corr_output_m
Call:corr.test(x = d$survey1, y = d$survey2)
Correlation matrix 
[1] 0.05
Sample Size 
[1] 100
These are the unadjusted probability values.
  The probability values  adjusted for multiple tests are in the p.adj object. 
[1] 0.59

 To see confidence intervals of the correlations, print with the short=FALSE option

Write Up Results

t-Test

We tested our hypothesis that participants who experience catastrophic thinking will report higher levels of intolerance of uncertainty than participants who do not experience catastrophic thinking using an independent samples t-test. The hypothesis was not supported. We did have to drop any participants from the study. We also confirmed homogeneity of variance, Levene’s test is not significant, (p = .97). the dependent variable is normally distributed (skew and kurtosis between -2 and +2), except for gender, survey1, and survey2. Our effect size was strong according to Cohen (1988).

Residuals vs Fitted plot showed good linearity.

Correlation Test

We believe that predict that participants who experience catastrophic thinking will report higher levels of intolerance of uncertainty than participants who experience no catastrophic thinking. This hypothesis was not supported. For group 1 and 2, the skew and kurtosis for gender are out of the (-2 - +2) range. The kurtosis for both groups for survey1 and survey 2 are out of range as well. When testing Homogeneity of Variance with Levene’s Test, (p = 0.97), producing a non-significant result.

[1] "Table 1: Means, standard deviations, and correlations with confidence intervals\n"
Variable M SD 1 2 3
condition 50.50 29.01
condition
condition 34.94 6.70 .13
condition [-.06, .32]
condition
condition 4.76 1.46 .02 -.25*
condition [-.18, .21] [-.43, -.06]
condition
condition 1.98 0.14 -.10 -.28** -.12
condition [-.29, .10] [-.45, -.09] [-.31, .08]
condition
Note:
M and SD are used to represent mean and standard deviation, respectively. Values in square brackets indicate the 95% confidence interval. The confidence interval is a plausible range of population correlations that could have caused the sample correlation.
* indicates p < .05
** indicates p < .01.

References

Cohen J. (1988). Statistical Power Analysis for the Behavioral Sciences. New York, NY: Routledge Academic.