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

d <- read.csv(file="Data/mydata.csv", header=T)
names(d)
[1] "gender"    "party_rc"  "socmeduse" "belong"    "swb"       "stress"   

Univariate Plots: Histograms & Tables

table(d$gender) # UPDATE FOR HW

   f    m   nb 
2307  786   53 
table(d$party_rc)

 apolitical    democrat independent  republican 
        439        1597         327         783 
hist(d$socmeduse)

hist(d$belong)

hist(d$swb)

hist(d$stress)

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 it in my writeup!!!!

describe(d)
          vars    n  mean   sd median trimmed  mad  min  max range  skew
gender*      1 3146  1.28 0.49   1.00    1.21 0.00  1.0  3.0   2.0  1.39
party_rc*    2 3146  2.46 1.01   2.00    2.45 0.00  1.0  4.0   3.0  0.42
socmeduse    3 3146 34.45 8.58  35.00   34.73 7.41 11.0 55.0  44.0 -0.31
belong       4 3146  3.23 0.60   3.30    3.25 0.59  1.3  5.0   3.7 -0.26
swb          5 3146  4.48 1.32   4.67    4.53 1.48  1.0  7.0   6.0 -0.36
stress       6 3146  3.05 0.60   3.00    3.05 0.59  1.3  4.7   3.4  0.03
          kurtosis   se
gender*       0.86 0.01
party_rc*    -1.04 0.02
socmeduse     0.26 0.15
belong       -0.12 0.01
swb          -0.46 0.02
stress       -0.17 0.01

Bivariate Plots

Crosstabs

cross_cases(d, gender, party_rc)
 party_rc 
 apolitical   democrat   independent   republican 
 gender 
   f  325 1219 215 548
   m  109 341 102 234
   nb  5 37 10 1
   #Total cases  439 1597 327 783

Scatterplots

plot(d$socmeduse, d$belong,
     main="Scatterplot of Social Media Use and Need to Belong",
     xlab = "Social Media Use",
     ylab = "Need to Belong")

plot(d$socmeduse, d$swb,
     main="Scatterplot of Social Media Use and Satisfaction With Life",
     xlab = "Social Media Use",
     ylab = "Satisfaction With Life")

plot(d$socmeduse, d$stress,
     main="Scatterplot of Social Media Use and Stress",
     xlab = "Social Media Use",
     ylab = "Stress")

plot(d$belong, d$swb,
     main="Scatterplot of Need to Belong and Satisfaction With Life",
     xlab = "Need to Belong",
     ylab = "Satisfaction With Life")

plot(d$belong, d$stress,
     main="Scatterplot of Need to Belong and Stress",
     xlab = "Need to Belong",
     ylab = "Stress")

plot(d$swb, d$stress,
     main="Scatterplot of Satisfaction With Life and Stress",
     xlab = "Satisfaction With Life",
     ylab = "Stress")

Boxplots

boxplot(data=d, swb~gender,
        main="Boxplot of Satisfaction With Life and Gender",
        xlab = "Gender",
        ylab = "Satisfaction With Life")

boxplot(data=d, swb~party_rc,
        main="Boxplot of Satisfaction With Life and Political Party",
        xlab = "Political Party",
        ylab = "Satisfaction With Life")

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