Basic Statistics HW

Load Libraries

# remember, you might need to install packages

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

Load Data

 d <- read.csv(file="Data/mydata.csv", header=T)
 names(d)
[1] "age"       "gender"    "mindful"   "efficacy"  "stress"    "socmeduse"

Univariate Plots: Histograms & Tables

table(d$age) # UPDATE FOR HW!!!

1 between 18 and 25 2 between 26 and 35 3 between 36 and 45           4 over 45 
               1982                 115                  38                  18 
table(d$gender)

   f    m   nb 
1579  543   31 
hist(d$mindful)

hist(d$efficacy)

hist(d$stress)

hist(d$socmeduse)

Univariate Normality

Check skew and kurtosis. cutoffs are -2 or +2; if skew or kurtosis are higher or lower than these values, I need to mention it in my writeup!!!

describe(d)
          vars    n  mean   sd median trimmed  mad   min  max range  skew
age*         1 2153  1.11 0.43   1.00    1.00 0.00  1.00  4.0  3.00  4.41
gender*      2 2153  1.28 0.48   1.00    1.21 0.00  1.00  3.0  2.00  1.36
mindful      3 2153  3.72 0.84   3.73    3.72 0.79  1.13  6.0  4.87 -0.04
efficacy     4 2153  3.11 0.44   3.10    3.12 0.44  1.20  4.0  2.80 -0.19
stress       5 2153  3.06 0.60   3.10    3.06 0.59  1.30  4.6  3.30 -0.01
socmeduse    6 2153 34.25 8.59  35.00   34.52 7.41 11.00 55.0 44.00 -0.31
          kurtosis   se
age*         21.08 0.01
gender*       0.71 0.01
mindful      -0.15 0.02
efficacy      0.36 0.01
stress       -0.15 0.01
socmeduse     0.20 0.19

Bivariate Plots

Crosstabs

cross_cases(d, age, gender)
 gender 
 f   m   nb 
 age 
   1 between 18 and 25  1470 482 30
   2 between 26 and 35  69 46
   3 between 36 and 45  28 9 1
   4 over 45  12 6
   #Total cases  1579 543 31

Scatterplots

plot(d$mindful, d$efficacy,
     main="Scatterplot of Mindfulness and Efficacy",
     xlab = "Mindful",
     ylab = "Efficacy")

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

plot(d$mindful, d$socmeduse,
     main="Scatterplot of Mindfulness and Social Media Use",
     xlab = "Mindful",
     ylab = "Socmeduse")

plot(d$efficacy, d$stress,
     main="Scatterplot of Efficacy and Stress",
     xlab = "Efficacy",
     ylab = "Stress")

plot(d$efficacy, d$socmeduse,
     main="Scatterplot of Efficacy and Social Media Use",
     xlab = "Efficacy",
     ylab = "Socmeduse")

plot(d$socmeduse, d$stress,
     main="Scatterplot of Social Media Use and Stress",
     xlab = "Socmeduse",
     ylab = "Stress")

Boxplots

boxplot(data=d, mindful~age,
        main="Boxplot of Mindfulness and Age",
        xlab = "Age",
        ylab = "Mindful")

boxplot(data=d, mindful~gender,
        main="Boxplot of Mindfulness and Gender",
        xlab = "Gender",
        ylab = "Mindful")

Write-Up

We reviewed plots and descriptive statistics for our six chosen variables. Two variables had issues with skew and/or kurtosis: age scores were positively skewed (4.41) and age scores were also kurtotic (21.08). The other 5 variables had skew and kurtosis within the accepted range (-2/+2).