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] "gender"   "age"      "moa_role" "belong"   "swb"      "mindful" 

Univariate Plots: Histograms & Tables

table(d$gender) #update for hw

   f    m   nb 
1542  533   31 
table(d$age)

1 between 18 and 25 2 between 26 and 35 3 between 36 and 45           4 over 45 
               1941                 111                  37                  17 
# 
hist(d$moa_role)

hist(d$belong)

hist(d$swb)

hist(d$mindful)

Univariate Normality

Check skew and kurtosis. Cutoffs are -2 to +2. If either are higher or lower, mention it in write up

describe(d)
         vars    n mean   sd median trimmed  mad  min max range  skew kurtosis
gender*     1 2106 1.28 0.48   1.00    1.21 0.00 1.00   3  2.00  1.35     0.70
age*        2 2106 1.11 0.43   1.00    1.00 0.00 1.00   4  3.00  4.44    21.37
moa_role    3 2106 2.97 0.72   3.00    3.01 0.74 1.00   4  3.00 -0.33    -0.81
belong      4 2106 3.21 0.61   3.20    3.23 0.59 1.30   5  3.70 -0.28    -0.10
swb         5 2106 4.43 1.33   4.50    4.49 1.48 1.00   7  6.00 -0.36    -0.49
mindful     6 2106 3.71 0.84   3.73    3.72 0.79 1.13   6  4.87 -0.04    -0.15
           se
gender*  0.01
age*     0.01
moa_role 0.02
belong   0.01
swb      0.03
mindful  0.02

Bivariate Plots

Crosstabs

cross_cases(d, d$gender, d$age)
 d$age 
 1 between 18 and 25   2 between 26 and 35   3 between 36 and 45   4 over 45 
 d$gender 
   f  1436 67 27 12
   m  475 44 9 5
   nb  30 1
   #Total cases  1941 111 37 17

Scatterplots

plot(d$moa_role, d$belong,
      main="Scatterplot of Importance of Role Transitions and Need for Belonging",
      xlab = "Importance of Role Transitions",
      ylab = "Need for Belonging")

plot(d$moa_role, d$swb,
      main="Scatterplot of Importance of Role Transitions and Satisfaction with Life",
      xlab = "Importance of Role Transitions",
      ylab = "Satistfaction with Life")

plot(d$moa_role, d$mindful,
      main="Scatterplot of Importance of Role Transitions and Mindfulness",
      xlab = "Importance of Role Transitions",
      ylab = "Mindfulness")

plot(d$belong, d$swb,
      main="Need for Belonging and Satisfaction with Life",
      xlab = "Need for Belonging",
      ylab = "Satisfaction with Life")

plot(d$belong, d$mindful,
      main="Need for Belonging and Mindfulness",
      xlab = "Need for Belonging",
      ylab = "Mindfulness")

plot(d$swb, d$mindful,
      main="Scatterplot of Satisfaction with Life and Mindfulness",
      xlab = "Satisfaction with Life",
      ylab = "Mindfulness")

Boxplots

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

boxplot(data=d, belong~age,
        main="Boxplot of Need for Belonging and Age",
        xlab = "Age",
        ylab = "Need for Belonging")

Write-Up

We reviewed plots and descriptive statistics for our six chosen variables. All four of our continuous variables had skew and kurtosis within the accepted range (-2/+2). Crosstabulations of age and gender, scatterplots between all possible combinations of satisfaction with life, mindfulness, need for belonging, and importance of role transitions, and two boxplots describing need for belonging and age and gender and mindfulness were created.