Basic Statistics

Load Libraries

#install.packages("psych")
#install.packages("expss")

library(psych)
library(expss)
## Loading required package: maditr
## 
## To select rows from data: rows(mtcars, am==0)

Import Data

d2 <- read.csv("Data/projectdata.csv")

Univariate Plots: Histograms & Tables

# Categorical variables — use tables
table(d2$gender)
## 
##             female I use another term               male  Prefer not to say 
##                233                 17                 41                  6
table(d2$mhealth)
## 
##              anxiety disorder                       bipolar 
##                            43                             3 
##                    depression              eating disorders 
##                             5                            14 
##                    none or NA obsessive compulsive disorder 
##                           200                            11 
##                         other                          ptsd 
##                            12                             9
# Continuous variables — use histograms
hist(d2$phq,
     main = "Distribution of Depression Symptoms",
     xlab = "Depression Symptoms")

hist(d2$pss,
     main = "Distribution of Perceived Stress",
     xlab = "Perceived Stress")

hist(d2$gad,
     main = "Distribution of Anxiety Symptoms",
     xlab = "Anxiety Symptoms")

hist(d2$brs,
     main = "Distribution of Resilience",
     xlab = "Resilience")

Univariate Normality for Continuous Variables

describe(d2)
##          vars   n    mean     sd  median trimmed    mad  min  max range  skew
## X           1 297 7557.14 740.05 7531.00 7553.08 925.14 6291 8860  2569  0.05
## gender*     2 297    1.39   0.80    1.00    1.22   0.00    1    4     3  1.75
## mhealth*    3 297    4.52   1.66    5.00    4.64   0.00    1    8     7 -0.96
## phq         4 297    2.63   0.85    2.67    2.64   0.99    1    4     3 -0.04
## gad         5 297    2.61   0.91    2.71    2.62   1.06    1    4     3 -0.12
## brs         6 297    2.64   0.86    2.50    2.64   0.74    1    5     4  0.15
## pss         7 297    3.51   0.87    3.75    3.56   0.74    1    5     4 -0.43
##          kurtosis    se
## X           -1.19 42.94
## gender*      1.61  0.05
## mhealth*     0.76  0.10
## phq         -1.00  0.05
## gad         -1.14  0.05
## brs         -0.58  0.05
## pss         -0.51  0.05
## OPTION 1
# We analyzed the skew and kurtosis of our continuous variables and all were within
# the accepted range (-2/+2).

## OPTION 2
# We analyzed the skew and kurtosis of our continuous variables and (#) were within the accepted range (-2/+2). However, (#) variables (list variable name(s) here) were outside of the accepted range. For this analysis, we will use them anyway, but outside of this class this is bad practice.

We analyzed the skew and kurtosis of our continuous variables and all were within the accepted range (-2/+2).

Bivariate Plots

Crosstabs

# Two categorical variables
cross_cases(d2, gender, mhealth)
 mhealth 
 anxiety disorder   bipolar   depression   eating disorders   none or NA   obsessive compulsive disorder   other   ptsd 
 gender 
   I use another term  4 1 8 3 1
   Prefer not to say  1 1 3 1
   female  31 1 3 13 159 11 8 7
   male  7 1 2 30 1
   #Total cases  43 3 5 14 200 11 12 9

Scatterplots

# Perceived stress and depression symptoms (relevant to H1)
plot(d2$pss, d2$phq,
     main = "Scatterplot of Perceived Stress and Depression Symptoms",
     xlab = "Perceived Stress",
     ylab = "Depression Symptoms")

# Anxiety symptoms and depression symptoms (relevant to H2)
plot(d2$gad, d2$phq,
     main = "Scatterplot of Anxiety Symptoms and Depression Symptoms",
     xlab = "Anxiety Symptoms",
     ylab = "Depression Symptoms")

Boxplots

# Depression symptoms by gender
boxplot(data = d2, phq ~ gender,
        main = "Depression Symptoms by Gender",
        xlab = "Gender",
        ylab = "Depression Symptoms")

# Perceived stress by gender
boxplot(data = d2, pss ~ gender,
        main = "Perceived Stress by Gender",
        xlab = "Gender",
        ylab = "Perceived Stress")

We did it!!