Basic Statistics

Load Libraries

library(psych) # for the describe() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
## 
## To drop variable use NULL: let(mtcars, am = NULL) %>% head()
## 
## 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

# import data for the lab
# For HW import mydata.csv

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

Univariate Plots: Histograms & Tables

table(d2$trans) #shows level of variable and how many participants
## 
##                no Prefer not to say               yes 
##               941                37                31
table(d2$age)
## 
##          1 under 18 2 between 18 and 25 3 between 26 and 35 4 between 36 and 45 
##                 673                  54                   6                  87 
##           5 over 45 
##                 189
hist(d2$big5_agr) # variable 5 #creates histogram of variable

hist(d2$big5_ext)

hist(d2$rse)

hist(d2$pas_covid)

Univariate Normality

We analyzed the skew and kurtosis of our continuous variables and most were within the accepted range. However, one variable (trans) was outside of the accepted range. For the purpose of this class we will use it anyway.

describe(d2)
##           vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## trans*       1 1009 1.10 0.39   1.00    1.00 0.00   1   3     2  4.08    15.93
## age*         2 1009 2.07 1.64   1.00    1.84 0.00   1   5     4  1.01    -0.83
## big5_agr     3 1009 5.01 1.12   5.00    5.05 0.99   1   7     6 -0.39    -0.03
## big5_ext     4 1009 4.34 1.45   4.33    4.38 1.48   1   7     6 -0.23    -0.77
## rse          5 1009 2.65 0.71   2.70    2.67 0.74   1   4     3 -0.20    -0.74
## pas_covid    6 1009 3.24 0.68   3.22    3.26 0.66   1   5     4 -0.23     0.12
##             se
## trans*    0.01
## age*      0.05
## big5_agr  0.04
## big5_ext  0.05
## rse       0.02
## pas_covid 0.02

Bivariate Plots

Crosstabs

cross_cases(d2, trans, age) #Update with categorical variables for HW
 age 
 1 under 18   2 between 18 and 25   3 between 26 and 35   4 between 36 and 45   5 over 45 
 trans 
   Prefer not to say  31 1 5
   no  613 52 6 86 184
   yes  29 2
   #Total cases  673 54 6 87 189

Scatterplots

plot(d2$big5_agr, d2$rse,
     main="Scatterplot of big5_agr and rse",
     xlab = "big5_agr",
     ylab = "rse")

plot(d2$big5_ext, d2$pas_covid,
     main="Scatterplot of big5_ext and pas_covid",
     xlab = "big5_ext",
     ylab = "pas_covid")

Boxplots

#One categorical and one continuous
#Continuous variable first!!!
boxplot(data=d2, big5_ext~trans,
        main="Boxplot of trans and big5_ext",
        xlab = "trans",
        ylab = "big5_ext")

boxplot(data=d2, pas_covid~age,
        main="Boxplot of age and pas_covid",
        xlab = "age",
        ylab = "pas_covid")