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

State Your Hypotheses & Chosen Tests

H1: I predict that individuals who believe that others perceive their racial group negatively will report higher levels of General Anxiety Disorder symptoms. The chosen test for this will be t tests since we are measuring the differences between two groups. General Anxiety Disorder (DV), perception of negative racial bias (IV) condition survey1

H2: I predict that individuals who have more General Anxiety Disorder will report greater levels of isolation. The chosen test will be a correlation since we will be looking at the relationship between the dependent and independent variable. GAD (IV) reported isolation (DV)survey 2

Check Your Variables

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

# # to view stats for all variables
describe(d)
Warning in FUN(newX[, i], ...): no non-missing arguments to min; returning Inf
Warning in FUN(newX[, i], ...): no non-missing arguments to max; returning -Inf
           vars   n  mean    sd median trimmed   mad min    max range  skew
id            1 100 50.50 29.01  50.50   50.50 37.06   1 100.00 99.00  0.00
identity*     2 100 50.50 29.01  50.50   50.50 37.06   1 100.00 99.00  0.00
consent*      3 100  1.29  0.46   1.00    1.24  0.00   1   2.00  1.00  0.91
age           4 100 40.96 12.64  35.00   39.04  4.45  24  80.00 56.00  1.31
race*         5 100  4.21  2.19   3.00    4.10  1.48   1   8.00  7.00  0.73
gender        6 100  2.15  0.89   2.00    2.00  0.00   1   7.00  6.00  4.10
manip_out*    7 100 43.41 21.32  50.50   44.62 22.98   1  76.00 75.00 -0.43
survey1       8 100  4.04  1.06   4.00    3.93  1.27   2   8.00  6.00  1.02
survey2       9 100  2.97  0.49   3.12    3.02  0.37   2   3.75  1.75 -0.78
ai_manip*    10 100 50.50 29.01  50.50   50.50 37.06   1 100.00 99.00  0.00
condition    11 100  1.50  0.50   1.50    1.50  0.74   1   2.00  1.00  0.00
X            12   0   NaN    NA     NA     NaN    NA Inf   -Inf  -Inf    NA
           kurtosis   se
id            -1.24 2.90
identity*     -1.24 2.90
consent*      -1.18 0.05
age            0.92 1.26
race*         -0.72 0.22
gender        17.73 0.09
manip_out*    -1.08 2.13
survey1        1.30 0.11
survey2       -0.62 0.05
ai_manip*     -1.24 2.90
condition     -2.02 0.05
X                NA   NA
# 
# # we'll use the describeBy() command to view skew and kurtosis across our IVs
describeBy(d, group = 'condition')
Warning in FUN(newX[, i], ...): no non-missing arguments to min; returning Inf
Warning in FUN(newX[, i], ...): no non-missing arguments to max; returning -Inf
Warning in FUN(newX[, i], ...): no non-missing arguments to min; returning Inf
Warning in FUN(newX[, i], ...): no non-missing arguments to max; returning -Inf

 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.50   25.50 18.53   1  50.00 49.00  0.00
identity     2 50 53.00 28.80  53.00   53.25 36.32   1 100.00 99.00 -0.06
consent      3 50  1.24  0.43   1.00    1.18  0.00   1   2.00  1.00  1.18
age          4 50 40.42 12.28  35.00   38.88  4.45  24  74.00 50.00  1.13
race         5 50  4.24  2.30   3.00    4.15  1.48   1   8.00  7.00  0.67
gender       6 50  2.24  1.08   2.00    2.00  0.00   1   7.00  6.00  3.72
manip_out    7 50 29.14 21.34  25.50   26.80 18.53   1  76.00 75.00  0.90
survey1      8 50  4.07  1.02   4.00    3.97  0.74   2   7.00  5.00  0.90
survey2      9 50  2.92  0.51   3.12    2.96  0.56   2   3.75  1.75 -0.54
ai_manip    10 50 57.64 30.31  56.50   59.23 38.55   1 100.00 99.00 -0.30
condition   11 50  1.00  0.00   1.00    1.00  0.00   1   1.00  0.00   NaN
X           12  0   NaN    NA     NA     NaN    NA Inf   -Inf  -Inf    NA
          kurtosis   se
id           -1.27 2.06
identity     -1.23 4.07
consent      -0.62 0.06
age           0.38 1.74
race         -0.97 0.33
gender       13.00 0.15
manip_out    -0.09 3.02
survey1       1.06 0.14
survey2      -1.00 0.07
ai_manip     -1.11 4.29
condition      NaN 0.00
X               NA   NA
------------------------------------------------------------ 
condition: 2
          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.00 100.0 49.00  0.00
identity     2 50 48.00 29.30  46.00   47.77 37.06  2.00  99.0 97.00  0.07
consent      3 50  1.34  0.48   1.00    1.30  0.00  1.00   2.0  1.00  0.66
age          4 50 41.50 13.10  35.50   39.30  5.19 27.00  80.0 53.00  1.40
race         5 50  4.18  2.10   4.00    4.05  1.48  1.00   8.0  7.00  0.77
gender       6 50  2.06  0.65   2.00    2.00  0.00  1.00   5.0  4.00  3.41
manip_out    7 50 57.68  6.92  57.50   57.88  8.15 44.00  69.0 25.00 -0.07
survey1      8 50  4.02  1.12   4.00    3.90  1.48  2.57   8.0  5.43  1.09
survey2      9 50  3.01  0.47   3.25    3.08  0.37  2.00   3.5  1.50 -1.04
ai_manip    10 50 43.36 26.04  35.50   42.75 35.58  3.00  90.0 87.00  0.19
condition   11 50  2.00  0.00   2.00    2.00  0.00  2.00   2.0  0.00   NaN
X           12  0   NaN    NA     NA     NaN    NA   Inf  -Inf  -Inf    NA
          kurtosis   se
id           -1.27 2.06
identity     -1.30 4.14
consent      -1.60 0.07
age           1.10 1.85
race         -0.54 0.30
gender       13.97 0.09
manip_out    -1.18 0.98
survey1       1.31 0.16
survey2      -0.14 0.07
ai_manip     -1.35 3.68
condition      NaN 0.00
X               NA   NA
# 
# # also use histograms and scatterplots to examine your continuous variables
hist(d$survey1)

plot(d$survey1, d$survey2)

hist(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)

# 
# #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$iv, useNA = "always")
# 
# # check your variable types
str(d)
'data.frame':   100 obs. of  12 variables:
 $ id       : int  1 2 3 4 5 6 7 8 9 10 ...
 $ identity : chr  "I’m a 42-year-old Asian woman living in Seattle. I work as a software engineer but often feel isolated due to m"| __truncated__ "I’m a 35-year-old multiracial woman, navigating the complexities of my identity. I often feel isolated, struggl"| __truncated__ "I'm a 74-year-old Asian woman named Mei, living in San Francisco. I often feel isolated due to my anxiety, stru"| __truncated__ "I’m 47, a Native Hawaiian woman juggling my roles as a mother and a nurse. I love my culture, but anxiety often"| __truncated__ ...
 $ consent  : chr  "I understand these instructions." "I understand the instructions." "I understand the instructions." "I understand the instructions." ...
 $ age      : int  42 35 74 47 37 34 29 34 32 34 ...
 $ race     : chr  "2" "7" "2" "5" ...
 $ gender   : int  2 2 2 2 2 5 7 1 2 7 ...
 $ manip_out: chr  "As I read the excerpt, I feel a mixture of pride and longing. I’m proud to see the acknowledgment of hard work,"| __truncated__ "As I read the excerpt, I feel a mix of pride and frustration. It’s uplifting to see positive recognition of har"| __truncated__ "As I read the excerpt, I feel a mix of pride and sadness. The recognition of hard work and resilience resonates"| __truncated__ "As I read the excerpt, I feel a mix of pride and longing. It's uplifting to see hard work and resilience acknow"| __truncated__ ...
 $ survey1  : num  3.29 3.71 3 3 4.29 ...
 $ survey2  : num  2 3.38 3.12 3.5 2 ...
 $ ai_manip : chr  "I answered the questions reflecting my experiences of pride and isolation as an Asian woman in tech. My anxiety"| __truncated__ "I answered based on my experiences of pride and frustration in navigating my multiracial identity. The recognit"| __truncated__ "I answered the questions reflecting my feelings of pride in my heritage while also acknowledging the loneliness"| __truncated__ "I answered the questions with a mix of pride in my heritage and recognition of my struggles with anxiety and is"| __truncated__ ...
 $ condition: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
 $ X        : logi  NA NA NA NA NA NA ...
# 
# # 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)

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  1.8103 0.1816
      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(survey2 ~ survey1, 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.

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$survey2~d$condition)

View Test Output

t_output

    Welch Two Sample t-test

data:  d$survey2 by d$condition
t = -0.9451, df = 97.486, p-value = 0.3469
alternative hypothesis: true difference in means between group 1 and group 2 is not equal to 0
95 percent confidence interval:
 -0.2867394  0.1017394
sample estimates:
mean in group 1 mean in group 2 
         2.9200          3.0125 

Calculate Cohen’s d

# # once again, we use our formula to calculate cohen's d
d_output <- 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

Cohen's d

d estimate: -0.1890196 (negligible)
95 percent confidence interval:
     lower      upper 
-0.5867984  0.2087592 

Run a Correlation Test !

Create a Correlation Matrix

d2 <- subset(d, select=c(survey1,survey2))
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.02
survey2   -0.02    1.00
Sample Size 
[1] 100
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
        survey1 survey2
survey1    0.00    0.88
survey2    0.88    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 racial and ethnic minority individuals in the United States experience higher rates of generalized anxiety disorder compared to white individuals using an independent samples t-test. While our data met all the assumptions for a t-test, the results showed no statistically significance between the two groups 2.92 and 3.01,t(97.49) = -0.95, p = 0.35, d = 0.01, 95% CI [-0.29, 0.10] (see Figure 1). According to Cohen (1988), the effect size was a weak effect.

Correlation Test

We predict that generalized anxiety disorder (GAD), eating disorder symptoms, and isolation will be positively correlated, while social support levels will be negatively correlated. A Pearson correlation was conducted to examine the relationship between Survey1 and Survey2 scores. The analysis revealed a very weak, negative, and non-significant correlation between the two variables, r(98) = -0.02, p = .88. This suggests that there is no meaningful linear relationship between Survey1 and Survey2 scores in this sample of 100 participants.

[1] "Table 1: Means, standard deviations, and correlations with confidence intervals\n"
Variable M SD 1
Percived Stress Scale (PSS) 4.04 1.06
General Anxiety Disorder Scale (GAD) 2.97 0.49 -.02
[-.21, .18]
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.