# remember, you might need to install packages
library(psych) # for the describe() command
library(expss) # for the cross_cases() command
Basic Statistics Lab
Load Libraries
Load Data
<- read.csv(file="Data/mydata.csv", header=T)
d # names(d)
Univariate Plots: Histograms & Tables
table(d$urban_rural)
city isolated dwelling town village
282 30 559 382
table(d$sexual_orientation)
Asexual Bi Gay/Lesbian
33 158 50
Heterosexual/Straight I use another term Prefer not to say
894 33 85
hist(d$gad)
hist(d$support)
hist(d$pss)
hist(d$isolation)
Univariate Normality
Check skew and kurtosis. Cutoffs are -2 and +2; if skew or kurtosis are higher or lower than those values, I need to mention it in my writeup
describe(d)
vars n mean sd median trimmed mad min max range skew
urban_rural* 1 1253 2.83 1.10 3.00 2.91 1.48 1 4.0 3.0 -0.69
sexual_orientation* 2 1253 3.79 1.02 4.00 3.82 0.00 1 6.0 5.0 -0.50
gad 3 1253 2.04 0.91 1.71 1.95 0.85 1 4.0 3.0 0.69
support 4 1253 3.57 0.95 3.67 3.63 0.99 1 5.0 4.0 -0.45
pss 5 1253 2.93 0.95 3.00 2.92 1.11 1 5.0 4.0 0.08
isolation 6 1253 2.15 0.84 2.00 2.12 1.11 1 3.5 2.5 0.17
kurtosis se
urban_rural* -0.85 0.03
sexual_orientation* 1.27 0.03
gad -0.71 0.03
support -0.53 0.03
pss -0.75 0.03
isolation -1.28 0.02
Bivariate Plots
Crosstabs
cross_cases(d, urban_rural, sexual_orientation)
sexual_orientation | ||||||
---|---|---|---|---|---|---|
Asexual | Bi | Gay/Lesbian | Heterosexual/Straight | I use another term | Prefer not to say | |
urban_rural | ||||||
city | 6 | 41 | 12 | 189 | 7 | 27 |
isolated dwelling | 1 | 5 | 24 | |||
town | 19 | 69 | 26 | 398 | 17 | 30 |
village | 7 | 43 | 12 | 283 | 9 | 28 |
#Total cases | 33 | 158 | 50 | 894 | 33 | 85 |
# I want to meet the lone ace living in the middle of nowhere, sounds like an interesting person
Scatterplots
plot(d$gad, d$support,
main="Scatterplot of Anxiety and Social Support",
xlab = "Anxiety",
ylab = "Social Support")
plot(d$gad, d$pss,
main="Scatterplot of Anxiety and Stress",
xlab = "Anxiety",
ylab = "Stress")
plot(d$gad, d$isolation,
main="Scatterplot of Anxiety and Isolation",
xlab = "Anxiety",
ylab = "Isolation")
plot(d$support, d$pss,
main="Scatterplot of Social Support and Stress",
xlab = "Social Support",
ylab = "Stress")
plot(d$support, d$isolation,
main="Scatterplot of Social Support and Isolation",
xlab = "Social Support",
ylab = "Isolation")
plot(d$pss, d$isolation,
main="Scatterplot of Stress and Isolation",
xlab = "Stress",
ylab = "Isolation")
Boxplots
boxplot(data=d, pss~urban_rural,
main="Boxplot of Stress and Living Location",
xlab = "Stress",
ylab = "Living Location")
boxplot(data=d, pss~sexual_orientation,
main="Boxplot of Stress and Sexual Orientation",
xlab = "Stress",
ylab = "Sexual Orientation")
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).