Basic Statistics

Load Libraries

library(psych) # for the describe() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
## 
## To aggregate several columns with one summary: take(mtcars, mpg, hp, fun = mean, by = am)
## 
## Attaching package: 'maditr'
## The following object is masked from 'package:base':
## 
##     sort_by
## 
## Use 'expss_output_rnotebook()' to display tables inside R Notebooks.
##  To return to the console output, use 'expss_output_default()'.

Import Data

d2 <- read.csv(file="Data/mydata.csv", header = T)

Univariate Plots: Histograms & Tables

table(d2$race_rc) #the table command shows us what the levels of this variable are, and how many participants are in each level
## 
##       asian       black    hispanic multiracial  nativeamer       other 
##         201         234         277         285          10          91 
##       white 
##        1984
table(d2$usdream)
## 
##               american dream is important and achievable for me 
##                                                            1423 
##     american dream is important but maybe not achievable for me 
##                                                             335 
## american dream is not important and maybe not achievable for me 
##                                                             572 
##        american dream is not important but is achievable for me 
##                                                             177 
##                            not sure if american dream important 
##                                                             575
hist(d2$moa_independence) #the hist command creates a histogram of the variable

hist(d2$idea)

hist(d2$support)

hist(d2$socmeduse)

Univariate Normality

We analyzed the skew and kurtosis of our continuous variables and half were within the accepted range (-2/+2). However, two variables (moa_independence, idea) were outside of the accepted range. For this analysis, we will use them anyway, but outside of this class this is bad practice.

describe(d2) #we use this to check univariate normality ... skew and kurtosis, (-2/+2)
##                  vars    n  mean   sd median trimmed  mad min max range  skew
## race_rc*            1 3082  5.56 2.12   7.00    5.90 0.00   1   7     6 -1.00
## usdream*            2 3082  2.40 1.55   2.00    2.25 1.48   1   5     4  0.62
## moa_independence    3 3082  3.54 0.46   3.67    3.61 0.49   1   4     3 -1.44
## idea                4 3082  3.58 0.38   3.62    3.62 0.37   1   4     3 -1.50
## support             5 3082  5.53 1.13   5.75    5.66 0.99   0   7     7 -1.10
## socmeduse           6 3082 34.45 8.60  35.00   34.72 7.41  11  55    44 -0.31
##                  kurtosis   se
## race_rc*            -0.63 0.04
## usdream*            -1.14 0.03
## moa_independence     2.55 0.01
## idea                 4.31 0.01
## support              1.43 0.02
## socmeduse            0.26 0.15

Bivariate Plots

Crosstabs

cross_cases(d2, race_rc, usdream) 
 usdream 
 american dream is important and achievable for me   american dream is important but maybe not achievable for me   american dream is not important and maybe not achievable for me   american dream is not important but is achievable for me   not sure if american dream important 
 race_rc 
   asian  74 37 33 9 48
   black  108 20 55 12 39
   hispanic  159 33 27 13 45
   multiracial  124 33 58 15 55
   nativeamer  5 1 1 3
   other  31 6 29 6 19
   white  922 205 369 122 366
   #Total cases  1423 335 572 177 575

Scatterplots

plot(d2$moa_independence, d2$support,
     main="Scatterplot of moa_independence and support",
     xlab = "moa_independence",
     ylab = "support")

plot(d2$idea, d2$socmeduse,
     main="Scatterplot of idea and socmeduse",
     xlab = "idea",
     ylab = "socmeduse")

Boxplots

boxplot(data=d2, moa_independence~race_rc,
        main="Boxplot of race_rc and moa_independence",
        xlab = "race_rc",
        ylab = "moa_independence")

boxplot(data=d2, idea~usdream,
        main="Boxplot of usdream and idea",
        xlab = "usdream",
        ylab = "idea")