Basic Statistics

Load Libraries

# if you haven't run this code before, you'll need to download the below packages first
# instructions on how to do this are included in the video
# but as a reminder, you use the packages tab to the right

library(psych) # for the describe() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
## 
## To get total summary skip 'by' argument: take_all(mtcars, mean)
## 
## Attaching package: 'maditr'
## The following object is masked from 'package:base':
## 
##     sort_by
## 
## Use 'expss_output_viewer()' to display tables in the RStudio Viewer.
##  To return to the console output, use 'expss_output_default()'.

##Import Data

d2 <- read.csv(file="mydata.csv" , header = T)

Univariate Plots: Histograms & Tables

table(d2$gender)
## 
##    f    m   nb 
## 2195  748   52
table(d2$edu)
## 
##      1 High school diploma or less, and NO COLLEGE 
##                                                 52 
##                             2 Currently in college 
##                                               2415 
## 3 Completed some college, but no longer in college 
##                                                 34 
##                   4 Complete 2 year College degree 
##                                                174 
##                       5 Completed Bachelors Degree 
##                                                133 
##                  6 Currently in graduate education 
##                                                133 
##                   7 Completed some graduate degree 
##                                                 54
hist(d2$moa_independence)

hist(d2$mindful)

hist(d2$belong)

hist(d2$socmeduse)

Univariate Normality

We analyzed the skew and kurtosis of our continuous variables and most (mindful, belong, socmeduse) were within the accepted range (-2/+2). However, some variables (moa_independence) were outside of the accepted range. For this analysis, we will use them anyway, but outside of this class this is bad practice.

describe(d2)
##                  vars    n  mean   sd median trimmed  mad   min max range  skew
## gender*             1 2995  1.28 0.49   1.00    1.21 0.00  1.00   3  2.00  1.39
## edu*                2 2995  2.51 1.25   2.00    2.19 0.00  1.00   7  6.00  2.17
## moa_independence    3 2995  3.54 0.46   3.67    3.61 0.49  1.00   4  3.00 -1.43
## moa_role            4 2995  2.96 0.72   3.00    3.00 0.74  1.00   4  3.00 -0.32
## moa_safety          5 2995  3.20 0.64   3.25    3.26 0.74  1.00   4  3.00 -0.71
## moa_maturity        6 2995  3.59 0.43   3.67    3.65 0.49  1.00   4  3.00 -1.20
## mindful             7 2995  3.71 0.84   3.73    3.72 0.79  1.13   6  4.87 -0.06
## belong              8 2995  3.23 0.61   3.30    3.25 0.59  1.30   5  3.70 -0.26
## socmeduse           9 2995 34.45 8.58  35.00   34.73 7.41 11.00  55 44.00 -0.32
##                  kurtosis   se
## gender*              0.88 0.01
## edu*                 3.58 0.02
## moa_independence     2.49 0.01
## moa_role            -0.85 0.01
## moa_safety           0.03 0.01
## moa_maturity         1.90 0.01
## mindful             -0.13 0.02
## belong              -0.13 0.01
## socmeduse            0.27 0.16

Bivariate Plots

Crosstabs

cross_cases(d2, gender, edu)
 edu 
 1 High school diploma or less, and NO COLLEGE   2 Currently in college   3 Completed some college, but no longer in college   4 Complete 2 year College degree   5 Completed Bachelors Degree   6 Currently in graduate education   7 Completed some graduate degree 
 gender 
   f  27 1786 26 126 94 102 34
   m  20 592 7 45 36 29 19
   nb  5 37 1 3 3 2 1
   #Total cases  52 2415 34 174 133 133 54

Scatterplots

plot(d2$moa_independence, d2$socmeduse,
     main="Scatterplot of moa_independence and socmeduse",
     xlab = "moa_independence",
     ylab = "socmeduse")

plot(d2$belong, d2$socmeduse,
     main="Scatterplot of belong and socmeduse",
     xlab = "belong",
     ylab = "socmeduse")

Boxplots

boxplot(data=d2, moa_independence~gender,
        main="Boxplot of gender and moa_independence",
        xlab = "gender",
        ylab = "moa_independence")

boxplot(data=d2, socmeduse~gender,
        main="Boxplot of gender and socmeduse",
        xlab = "gender",
        ylab = "socmeduse")