Basic Statistics Lab

Load Libraries

# remember, you might need to install packages

library(psych) # for the describe() command
library(expss) # for the cross_cases() command

Load Data

# WILL.NEED TO UPDATE THIS FOR THE HW!! USE MY DATA!
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)
[1] "edu"     "gender"  "support" "stress"  "swb"     "mindful"

Univariate Plots: Histograms & Tables

table(d$edu)

     1 High school diploma or less, and NO COLLEGE 
                                                58 
                            2 Currently in college 
                                              2553 
3 Completed some college, but no longer in college 
                                                35 
                  4 Complete 2 year College degree 
                                               181 
                      5 Completed Bachelors Degree 
                                               140 
                 6 Currently in graduate education 
                                               137 
                  7 Completed some graduate degree 
                                                60 
table(d$gender)

   f    m   nb 
2320  790   54 
# 
 hist(d$support)

 hist(d$stress)

 hist(d$swb)

 hist(d$mindful)

Univariate Normality

Check skew and kurtosis.

describe(d)
        vars    n mean   sd median trimmed  mad  min max range  skew kurtosis
edu*       1 3164 2.51 1.25   2.00    2.18 0.00 1.00 7.0  6.00  2.18     3.65
gender*    2 3164 1.28 0.49   1.00    1.21 0.00 1.00 3.0  2.00  1.39     0.87
support    3 3164 5.53 1.14   5.75    5.65 0.99 0.00 7.0  7.00 -1.12     1.51
stress     4 3164 3.05 0.60   3.00    3.05 0.59 1.30 4.7  3.40  0.04    -0.17
swb        5 3164 4.47 1.32   4.67    4.53 1.48 1.00 7.0  6.00 -0.36    -0.45
mindful    6 3164 3.71 0.84   3.73    3.71 0.79 1.13 6.0  4.87 -0.06    -0.14
          se
edu*    0.02
gender* 0.01
support 0.02
stress  0.01
swb     0.02
mindful 0.01

Bivariate Plots

Crosstabs

cross_cases(d, edu, gender)
 gender 
 f   m   nb 
 edu 
   1 High school diploma or less, and NO COLLEGE  31 22 5
   2 Currently in college  1890 624 39
   3 Completed some college, but no longer in college  26 8 1
   4 Complete 2 year College degree  130 48 3
   5 Completed Bachelors Degree  100 37 3
   6 Currently in graduate education  105 30 2
   7 Completed some graduate degree  38 21 1
   #Total cases  2320 790 54

Scatterplots

plot(d$support, d$stress,
     main="Scatterplot of Social Support and Stress",
     xlab = "Social Support",
     ylab = "Stress")

plot(d$support, d$swb,
     main="Scatterplot of Social Support and Subjective Well-being",
     xlab = "Social Support",
     ylab = "Subjective Well-being")

plot(d$support, d$mindful,
     main="Scatterplot of Social Support and Mindfulness",
     xlab = "Social Support",
     ylab = "Mindfulness")

plot(d$stress, d$swb,
     main="Scatterplot of Stress and Subjective Well-being",
     xlab = "Stress",
     ylab = "Subjective Well-being")

plot(d$stress, d$mindful,
     main="Scatterplot of Stress and Mindfullness",
     xlab = "Stress",
     ylab = "Minfullness")

plot(d$swb, d$mindful,
     main="Scatterplot of Subjective Well-being and Mindfullness",
     xlab = "Subjective Well-being",
     ylab = "Mindfulness")

Boxplots

# remember that continuous variable comes first, CONTINUOUS~CATEGORICAL
boxplot(data=d, stress~edu,
        main="Boxplot of Stress and Education",
        xlab = "Education",
        ylab = "Stress")

boxplot(data=d, stress~gender,
        main="Boxplot of Stress and Gender",
        xlab = "Gender",
        ylab = "Stress")

Write-Up

We reviewed plots and descriptive statistics for our six chosen variables. The education variable had issues with skew and kurtosis: education scores were positivley skewed (2.18) and education scores were kurtotic (3.65). The other variables of gender, stress, support,swb, and mindfulhad skew and kurtosis within the accepted range (-2/+2).