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

State Your Hypotheses & Chosen Tests

H1: Participants who perceive their social media identity as different to their real one will report higher intolerance of uncertainty than participants who perceive their social media identity as similar to their real one.

H2: Self-esteem will predict intolerance of uncertainty, and the relationship will be negative.

The chosen tests will be a T-Test and Pearson’s Correlation.

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  0.00
identity*     2 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0  99.0  0.00
consent*      3 100 29.60 14.64   27.5   29.69 15.57  1.0  56.0  55.0  0.03
age           4 100 39.85 13.83   35.0   38.46  8.90 18.0  79.0  61.0  0.99
race          5 100  4.56  1.52    6.0    4.64  0.00  2.0   6.0   4.0 -0.20
gender        6 100  1.96  0.20    2.0    2.00  0.00  1.0   2.0   1.0 -4.62
manip_out*    7 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0  99.0  0.00
survey1       8 100  3.48  0.23    3.5    3.49  0.00  2.5   4.2   1.7 -0.76
survey2       9 100  2.48  0.13    2.5    2.49  0.00  2.1   2.8   0.7 -0.56
ai_manip*    10 100 50.50 29.01   50.5   50.50 37.06  1.0 100.0  99.0  0.00
condition    11 100  1.50  0.50    1.5    1.50  0.74  1.0   2.0   1.0  0.00
           kurtosis   se
id            -1.24 2.90
identity*     -1.24 2.90
consent*      -0.98 1.46
age            0.52 1.38
race          -1.79 0.15
gender        19.58 0.02
manip_out*    -1.24 2.90
survey1        4.64 0.02
survey2        2.29 0.01
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 = "condition")

 Descriptive statistics by group 
condition: 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.0  50.0  49.0  0.00
identity     2 50 52.68 27.89   50.5   52.73 35.58  1.0 100.0  99.0  0.00
consent      3 50 29.72 14.47   31.0   30.12 14.83  1.0  55.0  54.0 -0.18
age          4 50 40.10 12.99   35.0   38.62  7.41 21.0  79.0  58.0  1.24
race         5 50  4.60  1.46    5.0    4.65  1.48  2.0   6.0   4.0 -0.16
gender       6 50  1.94  0.24    2.0    2.00  0.00  1.0   2.0   1.0 -3.59
manip_out    7 50 51.72 29.13   52.0   51.60 35.58  2.0 100.0  98.0 -0.01
survey1      8 50  3.51  0.17    3.5    3.50  0.00  3.0   4.2   1.2  0.59
survey2      9 50  2.49  0.14    2.5    2.50  0.00  2.1   2.8   0.7 -0.30
ai_manip    10 50 52.46 31.05   48.5   52.75 45.96  1.0  98.0  97.0  0.01
condition   11 50  1.00  0.00    1.0    1.00  0.00  1.0   1.0   0.0   NaN
          kurtosis   se
id           -1.27 2.06
identity     -1.23 3.94
consent      -0.96 2.05
age           1.18 1.84
race         -1.84 0.21
gender       11.15 0.03
manip_out    -1.26 4.12
survey1       6.40 0.02
survey2       1.38 0.02
ai_manip     -1.47 4.39
condition      NaN 0.00
------------------------------------------------------------ 
condition: 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.0 100.0  49.0  0.00
identity     2 50 48.32 30.21   50.5   47.85 38.55  3.0  99.0  96.0  0.03
consent      3 50 29.48 14.96   25.0   29.27 17.05  2.0  56.0  54.0  0.22
age          4 50 39.60 14.75   34.5   38.15 10.38 18.0  75.0  57.0  0.80
race         5 50  4.52  1.59    6.0    4.62  0.00  2.0   6.0   4.0 -0.21
gender       6 50  1.98  0.14    2.0    2.00  0.00  1.0   2.0   1.0 -6.65
manip_out    7 50 49.28 29.13   49.0   49.25 34.84  1.0  95.0  94.0  0.01
survey1      8 50  3.45  0.27    3.5    3.46  0.00  2.5   4.1   1.6 -0.87
survey2      9 50  2.48  0.11    2.5    2.49  0.00  2.1   2.8   0.7 -1.17
ai_manip    10 50 48.54 26.99   55.5   48.52 30.39  2.0 100.0  98.0 -0.08
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.33 4.27
consent      -1.06 2.12
age          -0.09 2.09
race         -1.82 0.23
gender       43.12 0.02
manip_out    -1.29 4.12
survey1       2.56 0.04
survey2       3.19 0.02
ai_manip     -1.07 3.82
condition      NaN 0.00
# also use histograms and scatterplots to examine your continuous variables
hist(d$survey1)

hist(d$survey2)

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)

#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, 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$iv_rc[d$condition == "BAD"] <- "GOOD"

#table(d$iv, 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 34 and identify as Latino. I work in graphic design, often lost in my creativity, but I struggle with lonel"| __truncated__ "I'm 59, Black, and work as a school counselor in a bustling city. I’m passionate about helping students but str"| __truncated__ "I’m a 35-year-old white woman named Lisa. I work as a graphic designer, but I often feel unappreciated at my jo"| __truncated__ "I’m a 29-year-old White woman named Sarah, working as a graphic designer in a small marketing agency. I often f"| __truncated__ ...
 $ consent  : chr  "I understand the instructions. I'm ready to participate in the study and complete the writing task. Please let "| __truncated__ "I understand the instructions. I'm ready to participate in the study of writing ability and to respond to the q"| __truncated__ "I understand the instructions. I'm ready to participate in the study 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  34 59 35 29 35 34 43 47 59 41 ...
 $ race     : int  4 3 6 6 3 3 6 6 3 6 ...
 $ gender   : int  1 2 2 2 2 2 2 2 2 2 ...
 $ manip_out: chr  "In today’s digital age, the distinction between our social media identities and our real-life selves has become"| __truncated__ "In today’s digital age, the distinction between social media identity and real-life identity has become increas"| __truncated__ "In today’s digital age, the disparity between our social media identities and our real-life selves is more pron"| __truncated__ "In today’s digital age, the disparity between one’s social media identity and real-life persona is more pronoun"| __truncated__ ...
 $ survey1  : num  3.9 3 3.5 3.5 3.5 3.5 3.5 3.5 3.3 3.5 ...
 $ survey2  : num  2.5 2.8 2.5 2.2 2.2 2.5 2.6 2.5 2.2 2.5 ...
 $ ai_manip : chr  "I answered reflecting the contrast between my curated social media presence and my true self. My responses high"| __truncated__ "I answered the questions reflecting my struggle between my vibrant social media presence advocating for mental "| __truncated__ "I answered the questions reflecting my experiences with social media and its impact on my mental health. I ofte"| __truncated__ "I answered our questions reflecting the contrast between my curated social media identity and my real-life stru"| __truncated__ ...
 $ condition: Factor w/ 2 levels "1","2": 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  2.5159 0.1159
      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 ~ survey2, 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-cutoff is .5
plot(reg_model, 4)

# Residuals vs Leverage
plot(reg_model, 5)

Issues with My Data

In the residuals vs Leverage plot, we came across a spike which may mean an outlier is skewing the outcome of the data. However, we also used the diagnostic plots to check for linearity and other potential outliers and ran into no other potential issues.

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 = 1.27, df = 82.966, p-value = 0.2076
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.03249257  0.14729257
sample estimates:
mean in group 1 mean in group 2 
         3.5078          3.4504 

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.2540076 (small)
95 percent confidence interval:
     lower      upper 
-0.1444831  0.6524984 

Run a Correlation Test

Create a Correlation Matrix

d2 <- subset(d, select=-c(id,identity,consent,age, race, gender,manip_out, ai_manip,condition))
corr_output_m <- corr.test(d2)

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 = d2)
Correlation matrix 
        survey1 survey2
survey1    1.00    0.07
survey2    0.07    1.00
Sample Size 
[1] 100
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
        survey1 survey2
survey1    0.00    0.46
survey2    0.46    0.00

 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 perceive their social media identity as different to their real one will report higher intolerance of uncertainty than participants who perceive their social media identity as similar to their real one. Our data met all of the assumptions of a t-test and we did not find a significant difference p >.05.

Correlation Test

We tested our hypothesis that self-esteem will predict intolerance of uncertainty, and the relationship will be negative.

There were a few issues with the data. In the residuals vs Leverage plot, we came across a spike which means an outlier may be skewing the outcome of the data. However, we also used the other diagnostic plots to check for linearity and other outliers and ran into no other potential issues.

Using Pearson’s Correlation Test, we found a trivial positive correlation between variables self- esteem and intolerance of uncertainty; r(100)=0.07, p > .05 (refer to Table 1).

Variable M SD 1
Self -Esteem 3.48 0.23
Intolerance of Uncertainty 2.48 0.13 .07
[-.12, .27]
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.