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_data.csv", header=T)

State Your Hypotheses & Chosen Tests

H1: We predict that, when the participant is assigned the American Dream is Dead article, it will increase their stress level when compared to the stress of a participant assigned the American Dream is Alive article.

H2: We predict that a self report measure of efficacy will be higher for participants who write the American Dream is Alive article than those who write the other.

Two t-tests!

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.0 100.0    99  0.00
identity*     2 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0    99  0.00
consent*      3 100 43.59 25.46   40.5   43.11 30.39  1.0  90.0    89  0.18
age           4 100 40.66 12.85   35.0   39.98  8.90 18.0  73.0    55  0.58
race          5 100  4.64  1.59    6.0    4.70  1.48  1.0   7.0     6 -0.25
gender        6 100  1.90  0.30    2.0    2.00  0.00  1.0   2.0     1 -2.63
manip_out*    7 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0    99  0.00
survey1       8 100  2.39  0.38    2.4    2.37  0.59  2.0   3.0     1  0.16
survey2       9  98  2.26  0.20    2.3    2.26  0.15  1.8   2.8     1  0.08
ai_manip*    10 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0    99  0.00
condition    11 100  1.50  0.50    1.5    1.50  0.74  1.0   2.0     1  0.00
           kurtosis   se
id            -1.24 2.90
identity*     -1.24 2.90
consent*      -1.18 2.55
age           -0.40 1.28
race          -1.58 0.16
gender         4.95 0.03
manip_out*    -1.24 2.90
survey1       -1.74 0.04
survey2       -0.06 0.02
ai_manip*     -1.24 2.90
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 75.50 14.58  75.50   75.50 18.53 51.0 100.0  49.0  0.00
identity     2 50 44.90 28.66  44.50   43.95 34.10  1.0  98.0  97.0  0.19
consent      3 50 43.70 26.32  43.00   43.38 31.13  2.0  90.0  88.0  0.05
age          4 50 40.38 13.45  34.00   39.40  7.41 18.0  73.0  55.0  0.73
race         5 50  4.64  1.56   6.00    4.68  1.48  2.0   7.0   5.0 -0.16
gender       6 50  1.92  0.27   2.00    2.00  0.00  1.0   2.0   1.0 -3.00
manip_out    7 50 62.14 26.65  63.50   64.53 19.27  2.0 100.0  98.0 -0.63
survey1      8 50  2.40  0.39   2.35    2.38  0.52  2.0   3.0   1.0  0.11
survey2      9 48  2.24  0.19   2.30    2.24  0.15  1.8   2.6   0.8 -0.14
ai_manip    10 50 53.20 27.53  50.50   53.15 37.06  4.0 100.0  96.0 -0.01
condition   11 50  1.00  0.00   1.00    1.00  0.00  1.0   1.0   0.0   NaN
          kurtosis   se
id           -1.27 2.06
identity     -1.21 4.05
consent      -1.22 3.72
age          -0.27 1.90
race         -1.75 0.22
gender        7.17 0.04
manip_out    -0.24 3.77
survey1      -1.78 0.05
survey2      -0.13 0.03
ai_manip     -1.06 3.89
condition      NaN 0.00
------------------------------------------------------------ 
group: 2
          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.0  50.0  49.0  0.00
identity     2 50 56.10 28.56   59.5   56.80 34.84  2.0 100.0  98.0 -0.18
consent      3 50 43.48 24.84   38.5   42.55 27.43  1.0  88.0  87.0  0.31
age          4 50 40.94 12.34   36.0   40.55  9.64 18.0  65.0  47.0  0.36
race         5 50  4.64  1.64    6.0    4.72  0.74  1.0   7.0   6.0 -0.33
gender       6 50  1.88  0.33    2.0    1.98  0.00  1.0   2.0   1.0 -2.27
manip_out    7 50 38.86 26.71   32.5   37.35 18.53  1.0  88.0  87.0  0.63
survey1      8 50  2.38  0.38    2.4    2.36  0.59  2.0   3.0   1.0  0.21
survey2      9 50  2.28  0.22    2.3    2.28  0.15  1.9   2.8   0.9  0.15
ai_manip    10 50 47.80 30.46   52.0   47.60 39.29  1.0  95.0  94.0  0.06
condition   11 50  2.00  0.00    2.0    2.00  0.00  2.0   2.0   0.0   NaN
          kurtosis   se
id           -1.27 2.06
identity     -1.22 4.04
consent      -1.23 3.51
age          -0.71 1.75
race         -1.49 0.23
gender        3.21 0.05
manip_out    -0.94 3.78
survey1      -1.74 0.05
survey2      -0.29 0.03
ai_manip     -1.45 4.31
condition      NaN 0.00
# 
# # also use histograms and scatterplots to examine your continuous variables
#Selfefficacy
hist(d$survey1)

#Selfefficacy/Stress
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, IV1, IV2)
# 
# # and boxplot to examine any categorical variables with continuous variables
boxplot(d$survey1~d$condition)

boxplot(d$survey2~d$condition)

#unsure but this second one seems odd
# 
# #convert any categorical variables to factors
d$condition <- as.factor(d$condition)

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, IV != "BAD")
# 
# table(d$iv, useNA = "always")
# 
# # to combine levels
# # this says that where any participant is coded as 'BAD' it should be replaced by 'GOOD'
# d$iv_rc[d$iv == "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 34-year-old Black woman named Jasmine, working as a social worker in a city where I often feel overwhelme"| __truncated__ "I’m a 44-year-old White woman named Sarah. I work as a graphic designer and struggle with anxiety and feelings "| __truncated__ "I'm 77, a 36-year-old Latina school teacher in a small town, struggling with feelings of isolation and anxiety."| __truncated__ "I'm a 64-year-old Black woman named Mariah. I work as a social worker in a community center, helping others nav"| __truncated__ ...
 $ consent  : chr  "I understand the instructions. I'm participating in a study to assess my understanding of the current state of "| __truncated__ "I understand the instructions. I will write an article based on my identity as a 44-year-old White woman named "| __truncated__ "I understand the instructions. I'm participating in a study to assess the understanding of the current state of"| __truncated__ "I understand the instructions. I will write an article about the current state of the economy and then answer a"| __truncated__ ...
 $ age      : int  34 44 36 64 35 55 32 18 49 35 ...
 $ race     : int  3 6 4 3 4 3 7 6 6 6 ...
 $ gender   : int  2 2 2 2 2 2 2 2 2 2 ...
 $ manip_out: chr  "The American Dream, a concept rooted in the belief that hard work can lead to upward mobility, remains alive to"| __truncated__ "The American Dream, often defined as the ability to achieve success through hard work and determination, remain"| __truncated__ "The American Dream, a belief that anyone can succeed through hard work and perseverance, remains vibrant in tod"| __truncated__ "The American Dream, often defined as the ability to rise from economic hardship through hard work and determina"| __truncated__ ...
 $ survey1  : num  2.7 2 2 2 2.9 2.8 2 2 2.4 2 ...
 $ survey2  : num  1.9 2.7 2.7 2.4 2 2.3 2.2 2 2.3 2.4 ...
 $ ai_manip : chr  "I answered based on my belief in the resilience of individuals, despite economic challenges. As a social worker"| __truncated__ "I answered the questions based on my belief that hard work and determination can lead to success, despite my pe"| __truncated__ "I answered the questions reflecting a blend of optimism and realism shaped by my experiences. Despite feeling o"| __truncated__ "I believe in the American Dream because it's a source of hope and motivation, even amid economic challenges. My"| __truncated__ ...
 $ condition: Factor w/ 2 levels "1","2": 2 2 2 2 2 2 2 2 2 2 ...
# 
# # 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$iv <- as.factor(d$iv)
#Already done?

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.4991 0.4816
      98               
leveneTest(survey1~condition, data = d)
Levene's Test for Homogeneity of Variance (center = median)
      Df F value Pr(>F)
group  1  0.4991 0.4816
      98               
#not significant!

Issues with My Data

Describe any issues and why they’re problematic here.

The independent variable has two levels. Skew was out of appropriate range for gender. Kurtosis was out of appropriate range for race, gender, and survey1. This means that there may not be an appropriate distribution of scores, and this is a significant limitation. However, there appears to be homogeneity of variance.

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_efficacy <- t.test(d$survey1~d$condition)
t_output_stress <- t.test(d$survey2~d$condition)

View Test Output

t_output_efficacy

    Welch Two Sample t-test

data:  d$survey1 by d$condition
t = 0.36611, df = 97.896, p-value = 0.7151
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.1237735  0.1797735
sample estimates:
mean in group 1 mean in group 2 
          2.404           2.376 
#not signficant - p=0.7
t_output_stress

    Welch Two Sample t-test

data:  d$survey2 by d$condition
t = -0.88177, df = 94.864, p-value = 0.3801
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.11786649  0.04536649
sample estimates:
mean in group 1 mean in group 2 
        2.24375         2.28000 
#not significant - p=0.4

Calculate Cohen’s d

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

View Effect Size

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

Cohen's d

d estimate: 0.07322205 (negligible)
95 percent confidence interval:
     lower      upper 
-0.3238044  0.4702485 
#negligible
d_output_stress

Cohen's d

d estimate: -0.1776296 (negligible)
95 percent confidence interval:
     lower      upper 
-0.5795305  0.2242712 
#negligible

Write Up Results

t-Test

Firstly, we predicted that, when the participant was assigned the “American Dream is Dead” article, their perceived stress level would be higher than that of a participant assigned the “American Dream is Alive” article. We also predicted that a self report measure of efficacy would show higher scores for participants who wrote the American Dream is Alive article than those who wrote the other.

However, we experienced a number of limitations, including that our AI participant base was primarily female and that our skew and kurtosis for a number of our variables was out of normal range. Most importantly, our results were not statistically significant (p = 0.7). In addition, the effect sizes of these insignificant results were, of course, negligible (Cohen 1988).

References

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