# remember, you might need to install packages
library(psych) # for the describe() command
library(expss) # for the cross_cases() commandBasic Statistics Lab
Load Libraries
Load Data
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)[1] "education" "sleep_hours" "brs" "iou" "mfq_state"
[6] "phq"
Univariate Plots: Histograms & Tables
table(d$sleep_hours)
1 < 5 hours 2 5-6 hours 3 7-8 hours 4 8-10 hours 5 > 10 hours
44 130 143 64 21
table(d$education)
1 equivalent to not completing high school
96
2 equivalent to high school completion
182
3 equivalent to vocational/technical program completion
3
4 equivalent to AP/IB completion
70
5 undergraduate degree
15
6 graduate degree or higher
8
prefer not to say
28
hist(d$brs)hist(d$iou)hist(d$phq)hist(d$mfq_state)Univariate Normality
Check skew and kurtosis. Cutoffs are -2 to 2, if skew or kurtosis are higher or lower than these values, I need to mention in it my write up.
describe(d) vars n mean sd median trimmed mad min max range skew
education* 1 402 2.66 1.71 2.00 2.37 1.48 1.00 7 6.00 1.23
sleep_hours* 2 402 2.72 1.03 3.00 2.71 1.48 1.00 5 4.00 0.26
brs 3 402 2.70 0.88 2.67 2.69 0.99 1.00 5 4.00 0.10
iou 4 402 2.94 0.94 2.96 2.94 1.15 1.04 5 3.96 0.01
mfq_state 5 402 3.73 1.01 3.75 3.76 1.11 1.00 6 5.00 -0.26
phq 6 402 2.54 0.87 2.56 2.54 0.99 1.00 4 3.00 -0.01
kurtosis se
education* 0.63 0.09
sleep_hours* -0.41 0.05
brs -0.69 0.04
iou -0.96 0.05
mfq_state -0.28 0.05
phq -1.08 0.04
Bivariate Plots
Crosstabs
cross_cases(d, education, sleep_hours)| sleep_hours | |||||
|---|---|---|---|---|---|
| 1 < 5 hours | 2 5-6 hours | 3 7-8 hours | 4 8-10 hours | 5 > 10 hours | |
| education | |||||
| 1 equivalent to not completing high school | 13 | 27 | 34 | 16 | 6 |
| 2 equivalent to high school completion | 19 | 62 | 62 | 30 | 9 |
| 3 equivalent to vocational/technical program completion | 1 | 2 | |||
| 4 equivalent to AP/IB completion | 8 | 24 | 23 | 11 | 4 |
| 5 undergraduate degree | 6 | 8 | 1 | ||
| 6 graduate degree or higher | 7 | 1 | |||
| prefer not to say | 3 | 11 | 7 | 5 | 2 |
| #Total cases | 44 | 130 | 143 | 64 | 21 |
Scatterplots
plot(d$iou, d$brs,
main="Scatterplot of Intolerance of Uncertainty and Resilience",
xlab = "Intolerance of Uncertainty",
ylab = "Resilience") plot(d$iou, d$phq,
main="Scatterplot of Intolerance of Uncertainty and Depression",
xlab = "Intolerance of Uncertainty",
ylab = "Depression")plot(d$iou, d$mfq_state,
main="Scatterplot of Intolerance of Uncertainty and Mental Flexibility",
xlab = "Intolerance of Uncertainty",
ylab = "Mental Flexibility")plot(d$brs, d$phq,
main="Scatterplot of Resilience and Depression",
xlab = "Resilience",
ylab = "Depression")plot(d$brs, d$mfq_state,
main="Scatterplot of Resilience and Mental Flexibility",
xlab = "Resilience",
ylab = "Mental Flexibility")plot(d$phq, d$mfq_state,
main="Scatterplot of Depression and Mental Flexibility",
xlab = "Depression",
ylab = "Mental Flexibility")Boxplots
boxplot(data=d, iou~education,
main="Boxplot of Intolerance of Uncertainty and Education",
xlab = "Education",
ylab = "Intolerance of Uncertainty")boxplot(data=d, iou~sleep_hours,
main="Boxplot of Intolerance of Uncertainty and Hours of Sleep",
xlab = "Hours of Sleep",
ylab = "Intolerance of Uncertainty")Write-Up
We reviewed plots and descriptive statistics for our six chosen variables: Educations, Hours of Sleep,iou, brs, phq, mfq_state. All four of our continuous variables, iou, brs, phq, and mfq_state, had skew and kurtosis within the accepted range (-2/+2).