# remember, you might need to install packages
library(psych) # for the describe() command
library(expss) # for the cross_cases() command
Basic Statistics HW
Load Libraries
Load Data
<- read.csv(file="Data/mydata.csv", header=T)
d names(d)
[1] "race_rc" "age" "moa_safety" "swb" "support"
[6] "stress"
Univariate Plots: Histograms & Tables
table(d$race_rc) # UPDATE FOR HW!!!
asian black hispanic multiracial nativeamer other
140 185 226 204 8 80
white
1278
table(d$age)
1 between 18 and 25 2 between 26 and 35 3 between 36 and 45 4 over 45
1952 115 37 17
hist(d$moa_safety)
hist(d$swb)
hist(d$support)
hist(d$stress)
Univariate Normality
Check skew and kurtosis. Cuttoffs are -2 to +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 kurtosis
race_rc* 1 2121 5.41 2.16 7.00 5.72 0.00 1.0 7.0 6.0 -0.84 -0.94
age* 2 2121 1.11 0.43 1.00 1.00 0.00 1.0 4.0 3.0 4.41 21.12
moa_safety 3 2121 3.21 0.65 3.25 3.28 0.74 1.0 4.0 3.0 -0.71 -0.06
swb 4 2121 4.44 1.33 4.50 4.50 1.48 1.0 7.0 6.0 -0.36 -0.48
support 5 2121 5.53 1.14 5.75 5.66 0.99 0.0 7.0 7.0 -1.10 1.36
stress 6 2121 3.06 0.60 3.10 3.06 0.59 1.3 4.6 3.3 -0.02 -0.14
se
race_rc* 0.05
age* 0.01
moa_safety 0.01
swb 0.03
support 0.02
stress 0.01
Bivariate Plots
Crosstabs
cross_cases(d, race_rc, age)
age | ||||
---|---|---|---|---|
1 between 18 and 25 | 2 between 26 and 35 | 3 between 36 and 45 | 4 over 45 | |
race_rc | ||||
asian | 135 | 4 | 1 | |
black | 149 | 29 | 3 | 4 |
hispanic | 202 | 18 | 6 | |
multiracial | 188 | 12 | 4 | |
nativeamer | 8 | |||
other | 72 | 5 | 3 | |
white | 1198 | 47 | 20 | 13 |
#Total cases | 1952 | 115 | 37 | 17 |
Scatterplots
plot(d$moa_safety, d$swb,
main="Scatterplot of Safety and Satisfaction with Life Scale",
xlab = "Safety",
ylab = "Satisfaction with Life Scale")
plot(d$moa_safety, d$support,
main="Scatterplot of Safety and Multidimensional Scale of Perceived Social Support",
xlab = "Safety",
ylab = "Multidimensional Scale of Perceived Social Support")
plot(d$moa_safety, d$stress,
main="Scatterplot of Safety and Perceived Stress Questionnaire",
xlab = "Safety",
ylab = "Perceived Stress Questionnaire")
plot(d$swb, d$support,
main="Scatterplot of Satisfaction with Life Scale and Percieved Social Support",
xlab = "Satisfaction with Life Scale",
ylab = "Percieved Social Support")
plot(d$swb, d$stress,
main="Scatterplot of Satisfaction with Life Scale and Percieved Stress Questionnaire",
xlab = "Satisfaction with Life Scale",
ylab = "Percieved Stress Questionnaire")
plot(d$support, d$stress,
main="Scatterplot of Percieved Social Support and Percieved Stress Questionnaire",
xlab = "Percieved Social Support",
ylab = "Percieved Stress Questionnaire")
Boxplots
boxplot(data=d, swb~race_rc,
main="Boxplot of Satisfaction with Life Scale and Race/Ethnicity",
xlab = "Satisfaction with Life Scale",
ylab = "Race/Ethnicity")
boxplot(data=d, swb~age,
main="Boxplot of Satisfaction with Life Scale and Age",
xlab = "Satisfaction with Life Scale",
ylab = "Age")
Write-Up
We reviewed plots and descriptive statistics for our six chosen variables. Age variables had issues with skew and kurtosis: Age scores were skewed (4.41) and kurtotic (21.12). The other Race/Ethnicity, Safety, Satisfaction with Life scale, Perceived Social Support, and Percieved Stress variables had skew and kurtosis within the accepted range (-2/+2).