1 Loading Libraries

library(psych) # for the describe() command
library(car) # for the leveneTest() command
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:psych':
## 
##     logit
library(effsize) # for the cohen.d() command
## 
## Attaching package: 'effsize'
## The following object is masked from 'package:psych':
## 
##     cohen.d

2 Importing Data

# import the dataset you cleaned previously
# this will be the dataset you'll use throughout the rest of the semester
d <- read.csv(file="Data/arc_data_final (3).csv", header=T)

3 State Your Hypothesis

There is a significant difference in General Anxiety Disorder-7 (GAD-7) scores between participants with a clinically diagnosed anxiety disorder and those without.

4 Check Your Variables

# you only need to check the variables you're using in the current analysis
# although you checked them previously, it's always a good idea to look them over again and be sure that everything is correct
str(d)
## 'data.frame':    2073 obs. of  41 variables:
##  $ X                   : int  1 20 30 31 32 33 48 49 57 58 ...
##  $ gender              : chr  "female" "male" "female" "female" ...
##  $ trans               : chr  "no" "no" "no" "no" ...
##  $ sexual_orientation  : chr  "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" "Heterosexual/Straight" ...
##  $ ethnicity           : chr  "White - British, Irish, other" "White - British, Irish, other" "White - British, Irish, other" "White - British, Irish, other" ...
##  $ relationship_status : chr  "In a relationship/married and cohabiting" "Prefer not to say" "Prefer not to say" "In a relationship/married and cohabiting" ...
##  $ age                 : chr  NA "1 under 18" "1 under 18" "4 between 36 and 45" ...
##  $ urban_rural         : chr  "city" "city" "city" "town" ...
##  $ income              : chr  "3 high" NA NA "2 middle" ...
##  $ education           : chr  "6 graduate degree or higher" "prefer not to say" "2 equivalent to high school completion" "5 undergraduate degree" ...
##  $ employment          : chr  "3 employed" "1 high school equivalent" "1 high school equivalent" "3 employed" ...
##  $ treatment           : chr  "no psychological disorders" "in treatment" "not in treatment" "no psychological disorders" ...
##  $ health              : chr  "something else or not applicable" "something else or not applicable" "something else or not applicable" "two conditions" ...
##  $ mhealth             : chr  "none or NA" "anxiety disorder" "none or NA" "none or NA" ...
##  $ sleep_hours         : chr  "3 7-8 hours" "2 5-6 hours" "3 7-8 hours" "2 5-6 hours" ...
##  $ exercise            : num  0 2 3 1.5 NA 1 NA 2 2 1.7 ...
##  $ pet                 : chr  "cat" "cat" "dog" "no pets" ...
##  $ covid_pos           : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ covid_neg           : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ big5_open           : num  5.33 5.33 5 6 NA ...
##  $ big5_con            : num  6 3.33 5.33 5.67 NA ...
##  $ big5_agr            : num  4.33 4.33 6.67 4.67 NA ...
##  $ big5_neu            : num  6 6.67 4 4 NA ...
##  $ big5_ext            : num  2 1.67 6 5 NA ...
##  $ pswq                : num  4.94 3.36 1.86 3.94 NA ...
##  $ iou                 : num  3.19 4 1.59 3.37 NA ...
##  $ mfq_26              : num  4.2 3.35 4.65 4.65 NA 4.5 NA 4.3 5.25 4.45 ...
##  $ mfq_state           : num  3.62 3 5.88 4 NA ...
##  $ rse                 : num  2.3 1.6 3.9 1.7 NA 3.9 NA 2.4 1.8 NA ...
##  $ school_covid_support: num  NA NA NA NA NA NA NA NA NA NA ...
##  $ school_att          : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ pas_covid           : num  3.22 4.56 3.33 4.22 NA ...
##  $ pss                 : num  3.25 3.75 1 3.25 NA 2 NA 2 4 1.25 ...
##  $ phq                 : num  1.33 3.33 1 2.33 NA ...
##  $ gad                 : num  1.86 3.86 1.14 2 NA ...
##  $ edeq12              : num  1.58 1.83 1 1.67 NA ...
##  $ brs                 : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ swemws              : num  2.86 2.29 4.29 3.29 NA ...
##  $ isolation_a         : num  2.25 NA NA 2.5 NA 1.75 NA 2 1.25 NA ...
##  $ isolation_c         : num  NA 3.5 1 NA NA NA NA NA NA 1 ...
##  $ support             : num  2.5 2.17 5 2.5 NA ...
d$mhealth <- as.factor(d$mhealth)

table(d$mhealth, useNA = "always")
## 
##              anxiety disorder                       bipolar 
##                           210                            11 
##                    depression              eating disorders 
##                            52                            51 
##                    none or NA obsessive compulsive disorder 
##                          1621                            38 
##                         other                          ptsd 
##                            53                            37 
##                          <NA> 
##                             0
# you can use the describe() command on an entire datafrom (d) or just on a single variable (d$pss)
describe(d$gad)
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 1327 2.04 0.91   1.71    1.95 0.85   1   4     3 0.68    -0.72 0.02
# also use a histogram to examine your continuous variable
hist(d$gad)

# can use the describeBy() command to view the means and standard deviations by group
# it's very similar to the describe() command but splits the dataframe according to the 'group' variable
describeBy(d$gad, group=d$mhealth)
## 
##  Descriptive statistics by group 
## group: anxiety disorder
##    vars   n mean   sd median trimmed  mad  min max range  skew kurtosis   se
## X1    1 134 2.74 0.87   2.71    2.76 1.06 1.14   4  2.86 -0.13    -1.14 0.07
## ------------------------------------------------------------ 
## group: bipolar
##    vars n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 7 2.45 1.23      3    2.45 1.48   1   4     3 -0.12    -1.98 0.47
## ------------------------------------------------------------ 
## group: depression
##    vars  n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 35 1.98 0.71      2    1.91 0.64   1   4     3 0.97     0.48 0.12
## ------------------------------------------------------------ 
## group: eating disorders
##    vars  n mean   sd median trimmed  mad  min max range  skew kurtosis   se
## X1    1 32 2.88 0.69      3     2.9 0.64 1.57   4  2.43 -0.31    -1.02 0.12
## ------------------------------------------------------------ 
## group: none or NA
##    vars    n mean   sd median trimmed  mad min max range skew kurtosis   se
## X1    1 1025 1.87 0.84   1.57    1.75 0.64   1   4     3 0.97    -0.06 0.03
## ------------------------------------------------------------ 
## group: obsessive compulsive disorder
##    vars  n mean   sd median trimmed  mad min  max range  skew kurtosis   se
## X1    1 28 2.61 0.73   2.64    2.64 0.74   1 3.71  2.71 -0.36    -0.75 0.14
## ------------------------------------------------------------ 
## group: other
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 38  2.7 0.96   2.86    2.72 1.16   1   4     3 -0.13    -1.46 0.16
## ------------------------------------------------------------ 
## group: ptsd
##    vars  n mean   sd median trimmed  mad min max range  skew kurtosis   se
## X1    1 28 2.73 1.02   2.71    2.77 1.48   1   4     3 -0.23    -1.26 0.19
# last, use a boxplot to examine your continuous and categorical variables together
boxplot(d$gad~d$mhealth)

5 Check Your Assumptions

5.1 T-test Assumptions

  • IV must have two levels
  • Data values must be independent (independent t-test only)
  • Data obtained via a random sample
  • Dependent variable must be normally distributed
  • Variances of the two groups are approximately equal

5.2 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(gad~mhealth, data = d)
## Levene's Test for Homogeneity of Variance (center = median)
##         Df F value  Pr(>F)  
## group    7  2.0385 0.04741 *
##       1319                  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

As you can see, our data is very close to significant. When running a t-test, we can account for heterogeneity in our variance by using Welch’s t-test, which does not have the same assumptions as Student’s t-test (the default type of t-test) about variance. R defaults to using Welch’s t-test so this doesn’t require any changes on our part! Even if your data has no issues with homogeneity of variance, you’ll still use Welch’s t-test – it handles the potential issues around variance well and there are no real downsides. We’re just using Levene’s test here to get into the habit of changing the homogeneity of our variance, even if we already have a solution for any potential problems.

5.3 Issues with My Data

My independent variable has more than two levels. To proceed with this analysis, I will drop the non-binary participants from my sample. I will make a note to discuss this issue in my Method write-up and in my Discussion as a limitation of my study.

My data also has some potential issues regarding homogeneity of variance. Although Levene’s test was not significant, it was close to the significance threshold. To accommodate any potential heterogeneity of variance, I will use Welch’s t-test instead of Student’s t-test.

# once again, subetting to drop the nb group
d <- subset(d, mhealth != "bipolar")
d <- subset(d, mhealth != "depression")
d <- subset(d, mhealth != "eating disorders")
d <- subset(d, mhealth != "obsessive compulsive disorder")
d <- subset(d, mhealth != "other")
d <- subset(d, mhealth != "ptsd")
table(d$mhealth)
## 
##              anxiety disorder                       bipolar 
##                           210                             0 
##                    depression              eating disorders 
##                             0                             0 
##                    none or NA obsessive compulsive disorder 
##                          1621                             0 
##                         other                          ptsd 
##                             0                             0
d$mhealth <- droplevels(d$mhealth) # using droplevels() to drop the empty factor

6 Run a T-test

# Run a T-test
t_output <- t.test(d$gad~d$mhealth)

7 View Test Output

t_output
## 
##  Welch Two Sample t-test
## 
## data:  d$gad by d$mhealth
## t = 10.966, df = 167.12, p-value < 2.2e-16
## alternative hypothesis: true difference in means between group anxiety disorder and group none or NA is not equal to 0
## 95 percent confidence interval:
##  0.7135673 1.0269018
## sample estimates:
## mean in group anxiety disorder       mean in group none or NA 
##                       2.738806                       1.868571

8 Calculate Cohen’s d

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

9 View Effect Size

d_output
## 
## Cohen's d
## 
## d estimate: 1.034367 (large)
## 95 percent confidence interval:
##     lower     upper 
## 0.8492721 1.2194618

10 Write Up Results

To test our hypothesis that there is a significant difference in General Anxiety Disorder-7 (GAD-7) scores between participants with a clinically diagnosed anxiety disorder and those without, we used an two-sample or independent t-test. This required us to drop our bi-polar, eating disorders, depression, ptsd, OCD, and other participants from our sample, as we are limited to a two-group comparison when using this test. We tested the homogeneity of variance with Levene’s test and found some signs of heterogeneity (p = .067). This suggests that there is an increased chance of Type I error. To correct for this possible issue, we use Welch’s t-test, which does not assume homogeneity of variance. Our data met all other assumptions of a t-test.

As predicted, we found that people with Anxiety Disorder (M = 2.74, SD = .95) reported significantly higher scores than those without (M = 1.87, SD = .89); t(288.7) = 10.966, p < .001 (see Figure 1). The effect size was calculated using Cohen’s d, with a value of 1.03 (large effect; Cohen, 1988).

References

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