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

##NEED TO UPDATE FOR HOMEWORK! USE MYDATA
d <- read.csv(file="Data/mydata.csv", header=T)
names(d)
[1] "age"      "party_rc" "mindful"  "efficacy" "npi"      "stress"  

Univariate Plots: Histograms & Tables

table(d$age)

1 between 18 and 25 2 between 26 and 35 3 between 36 and 45           4 over 45 
               1969                 111                  38                  18 
table(d$party_rc)

 apolitical    democrat independent  republican 
        325        1089         218         504 
hist(d$mindful)

hist(d$efficacy)

hist(d$npi)

hist(d$stress)

Univariate Normality

Check skew and kurtosis. within +- 2 is okay, outside is bad

describe(d)
          vars    n mean   sd median trimmed  mad  min max range  skew kurtosis
age*         1 2136 1.11 0.43   1.00    1.00 0.00 1.00 4.0  3.00  4.44    21.30
party_rc*    2 2136 2.42 1.01   2.00    2.40 0.00 1.00 4.0  3.00  0.46    -0.97
mindful      3 2136 3.71 0.84   3.73    3.72 0.79 1.13 6.0  4.87 -0.04    -0.15
efficacy     4 2136 3.11 0.44   3.10    3.12 0.44 1.20 4.0  2.80 -0.19     0.36
npi          5 2136 0.27 0.30   0.15    0.23 0.23 0.00 1.0  1.00  0.99    -0.56
stress       6 2136 3.06 0.60   3.10    3.06 0.59 1.30 4.6  3.30 -0.02    -0.15
            se
age*      0.01
party_rc* 0.02
mindful   0.02
efficacy  0.01
npi       0.01
stress    0.01

Bivariate Plots

Crosstabs

cross_cases(d, party_rc, age)
 age 
 1 between 18 and 25   2 between 26 and 35   3 between 36 and 45   4 over 45 
 party_rc 
   apolitical  299 22 4
   democrat  1005 55 19 10
   independent  199 14 5
   republican  466 20 10 8
   #Total cases  1969 111 38 18

Scatterplots

plot(d$mindful, d$efficacy,
main="Scatterplot of Mindfulness and Efficacy",
xlab = "Mindfulness",
ylab = "Efficacy")

plot(d$mindful, d$npi,
main="Scatterplot of Mindfulness and Narcissism",
xlab = "Mindfulness",
ylab = "Narcissism")

plot(d$mindful, d$stress,
main="Scatterplot of Mindfulness and Stress",
xlab = "Mindfulness",
ylab = "Stress")

plot(d$efficacy, d$npi,
main="Scatterplot of Efficacy and Narcissism",
xlab = "Efficacy",
ylab = "Narcissism")

plot(d$efficacy, d$stress,
main="Scatterplot of Efficacy and Stress",
xlab = "Efficacy",
ylab = "Stress")

plot(d$npi, d$stress,
main="Scatterplot of Narcissism and Stress",
xlab = "Narcissism",
ylab = "Stress")

Boxplots

#remember continuous variable comes first, then categorical CONTINUOUS~CATEGORICAL
boxplot(data=d, npi~party_rc,
  main="Boxplot of Narcissism and Political Party",
  xlab = "Political Party",
  ylab = "Narcissism")

boxplot(data=d, mindful~age,
  main="Boxplot of Mindfuless and Age",
  xlab = "Age",
  ylab = "Mindfulness")

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).