# 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
# WILL NEED TO UPDATE THIS FOR HW!! USE MYDATA
<- read.csv(file="Data/mydata.csv", header=T)
d names(d)
[1] "edu" "party_rc" "npi" "mindful" "swb" "support"
Univariate Plots: Histograms & Tables
table(d$edu)
1 High school diploma or less, and NO COLLEGE
57
2 Currently in college
2539
3 Completed some college, but no longer in college
35
4 Complete 2 year College degree
179
5 Completed Bachelors Degree
137
6 Currently in graduate education
135
7 Completed some graduate degree
59
table(d$party_rc)
apolitical democrat independent republican
437 1596 326 782
hist(d$npi)
hist(d$mindful)
hist(d$swb)
hist(d$support)
Univariate Normality
Check skew and kurtosis.
describe(d)
vars n mean sd median trimmed mad min max range skew kurtosis
edu* 1 3141 2.50 1.25 2.00 2.18 0.00 1.00 7 6.00 2.19 3.72
party_rc* 2 3141 2.46 1.01 2.00 2.45 0.00 1.00 4 3.00 0.42 -1.04
npi 3 3141 0.28 0.31 0.15 0.24 0.23 0.00 1 1.00 0.94 -0.69
mindful 4 3141 3.71 0.84 3.73 3.71 0.79 1.13 6 4.87 -0.06 -0.14
swb 5 3141 4.48 1.32 4.67 4.53 1.48 1.00 7 6.00 -0.36 -0.46
support 6 3141 5.53 1.13 5.75 5.66 0.99 0.00 7 7.00 -1.12 1.50
se
edu* 0.02
party_rc* 0.02
npi 0.01
mindful 0.02
swb 0.02
support 0.02
Bivariate Plots
Crosstabs
cross_cases(d, edu, party_rc)
party_rc | ||||
---|---|---|---|---|
apolitical | democrat | independent | republican | |
edu | ||||
1 High school diploma or less, and NO COLLEGE | 13 | 28 | 4 | 12 |
2 Currently in college | 338 | 1270 | 260 | 671 |
3 Completed some college, but no longer in college | 6 | 17 | 6 | 6 |
4 Complete 2 year College degree | 28 | 86 | 27 | 38 |
5 Completed Bachelors Degree | 19 | 78 | 11 | 29 |
6 Currently in graduate education | 26 | 77 | 13 | 19 |
7 Completed some graduate degree | 7 | 40 | 5 | 7 |
#Total cases | 437 | 1596 | 326 | 782 |
Scatterplots
plot(d$npi, d$mindful,
main="Scatterplot of Narcissistic Personality Inventory and Mindful Attention Awareness",
xlab = "Narcissistic Personality Inventory",
ylab = "Mindful Attention Awareness")
plot(d$npi, d$swb,
main="Scatterplot of Narcissistic Personality Inventory and Satisfaction with Life",
xlab = "Narcissistic Personality Inventory",
ylab = "Satisfaction with Life")
plot(d$npi, d$support,
main="Scatterplot of Narcissistic Personality Inventory and Perceived Social Support",
xlab = "Narcissistic Personality Inventory",
ylab = "Perceived Social Support")
plot(d$mindful, d$swb,
main="Scatterplot of Mindful Attention Awareness and Satisfaction with Life",
xlab = "Mindful Attention Awareness",
ylab = "Satisfaction with Life")
plot(d$mindful, d$support,
main="Scatterplot of Mindful Attention Awareness and Perceived Social Support",
xlab = "Mindful Attention Awareness",
ylab = "Perceived Social Support")
plot(d$swb, d$support,
main="Scatterplot of Satisfaction with Life and Perceived Social Support",
xlab = "Satisfaction with Life",
ylab = "Perceived Social Support")
Boxplots
# remember that continuous variable comes first, CONTINUOUS~CATEGORICAL
boxplot(data=d, npi~edu,
main="Boxplot of Narcissistic Personality Inventory and Education Level",
xlab = "Education Level",
ylab = "Narcissistic Personality Inventory")
boxplot(data=d, npi~party_rc,
main="Boxplot of Narcissistic Personality Inventory and Political Party",
xlab = "Political Party",
ylab = "Narcissistic Personality Inventory")
Write-Up
We reviewed plots and descriptive statistics for our six chosen variables. The Education Level variable had issues with skew and/or kurtosis: worry scores were postively skewed (2.21) and self-esteem scores were kurtotic (3.80). The other five variables had skew and kurtosis within the accepted range (-2/+2).