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)

Import Data

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

Univariate Plots: Histograms & Tables

table(d2$gender) #table command shows what the levels of variable are and how many participants in each level
## 
##    f    m   nb 
## 2258  774   52
table(d2$income)
## 
##          1 low       2 middle         3 high rather not say 
##            864            861            523            836
hist(d2$moa_role) #the hist command creates histogram of variable

hist(d2$idea)

hist(d2$efficacy)

hist(d2$stress)

Univariate Normality

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

describe(d2) #use this to check uni. normality...skew and kurtosis, (-2/+2)
##          vars    n mean   sd median trimmed  mad min max range  skew kurtosis
## gender*     1 3084 1.28 0.49   1.00    1.21 0.00 1.0 3.0   2.0  1.38     0.84
## income*     2 3084 2.43 1.16   2.00    2.41 1.48 1.0 4.0   3.0  0.15    -1.44
## moa_role    3 3084 2.97 0.72   3.00    3.00 0.74 1.0 4.0   3.0 -0.33    -0.84
## idea        4 3084 3.58 0.38   3.62    3.62 0.37 1.0 4.0   3.0 -1.54     4.47
## efficacy    5 3084 3.13 0.45   3.10    3.13 0.44 1.1 4.0   2.9 -0.25     0.46
## stress      6 3084 3.05 0.60   3.00    3.05 0.59 1.3 4.7   3.4  0.04    -0.17
##            se
## gender*  0.01
## income*  0.02
## moa_role 0.01
## idea     0.01
## efficacy 0.01
## stress   0.01

Bivariate Plots

Crosstabs

cross_cases(d2, gender, income)
 income 
 1 low   2 middle   3 high   rather not say 
 gender 
   f  635 648 364 611
   m  212 202 155 205
   nb  17 11 4 20
   #Total cases  864 861 523 836

Scatterplots

plot(d2$efficacy, d2$stress,
     main="Scatterplot of efficacy and stress",
     xlab = "efficacy",
     ylab = "stress")

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

Boxplots

boxplot(data=d2, stress~income,
        main="Boxplot of income and stress",
        xlab = "income", 
        ylab = "stress")

boxplot(data=d2, stress~gender,
        main="Boxplot of gender and stress",
        xlab = "gender",
        ylab = "stress")