# if you haven't run this code before, you'll need to download the below packages first
# instructions on how to do this are included in the video
# but as a reminder, you use the packages tab to the right
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
# import our data for the lab
d2 <- read.csv(file ="Data/mydata.csv" , header = T)
table(d2$gender) #the table command shows us what the levels of this variable are and how many participants are in each level. replace these two variablenumber texts with categorical variables
##
## f m nb
## 2252 770 53
table(d2$marriage5)
##
## are currently divorced from one another
## 712
## are currently married to one another
## 2084
## never married each other and are not together
## 235
## never married each other but are currently together
## 44
hist(d2$moa_role) # hist command creates the histogram for the variables, continuous variables
hist(d2$moa_maturity)
hist(d2$swb)
hist(d2$belong)
We analyzed the skew and kurtosis of our continuous variables and all were within the accepted range (-2/+2).
We analyzed the skew and kurtosis of our … and most were within the accepted range (-2/+2). However, some variables (list them in parentheses) 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) #used to check univariate normality, skew and kurtosis range is (-2/+2)
## vars n mean sd median trimmed mad min max range skew
## gender* 1 3075 1.28 0.49 1.00 1.21 0.00 1.0 3 2.0 1.39
## marriage5* 2 3075 1.87 0.59 2.00 1.84 0.00 1.0 4 3.0 0.45
## moa_role 3 3075 2.97 0.72 3.00 3.00 0.74 1.0 4 3.0 -0.33
## moa_maturity 4 3075 3.59 0.43 3.67 3.65 0.49 1.0 4 3.0 -1.20
## swb 5 3075 4.47 1.32 4.67 4.53 1.48 1.0 7 6.0 -0.37
## belong 6 3075 3.23 0.61 3.30 3.25 0.59 1.3 5 3.7 -0.27
## kurtosis se
## gender* 0.87 0.01
## marriage5* 1.51 0.01
## moa_role -0.85 0.01
## moa_maturity 1.89 0.01
## swb -0.45 0.02
## belong -0.13 0.01
cross_cases(d2, gender, marriage5) #update variables with categorical variables and next the continuous Vs
 marriage5 | ||||
---|---|---|---|---|
 are currently divorced from one another |  are currently married to one another |  never married each other and are not together |  never married each other but are currently together | |
 gender | ||||
   f | 529 | 1518 | 173 | 32 |
   m | 170 | 532 | 56 | 12 |
   nb | 13 | 34 | 6 | |
   #Total cases | 712 | 2084 | 235 | 44 |
plot(d2$moa_role, d2$moa_maturity,
main="Scatterplot of moa_role and moa_maturity",
xlab = "moa_role",
ylab = "moa_maturity")
plot(d2$swb, d2$belong,
main="Scatterplot of swb and belong",
xlab = "swb",
ylab = "belong")
plot(d2$swb, d2$moa_maturity,
main="Scatterplot of swb and moa_maturity",
xlab = "swb",
ylab = "moa_maturity")
plot(d2$moa_role, d2$swb,
main="Scatterplot of moa_role and swb",
xlab = "moa_role",
ylab = "swb")
plot(d2$moa_role, d2$belong,
main="Scatterplot of moa_role and belong",
xlab = "moa_role",
ylab = "belong")
plot(d2$moa_maturity, d2$belong,
main="Scatterplot of moa_maturity and belong",
xlab = "moa_maturity",
ylab = "belong")
# boxplots use 1 categorical and 1 continuous variable
# use them in the right order! continuous~categorical
boxplot(data=d2, moa_role~gender,
main="Boxplot of gender and moa_role",
xlab = "gender",
ylab = "moa_role")
boxplot(data=d2, moa_maturity~marriage5,
main="Boxplot of marriage5 and moa_maturity",
xlab = "marriage5",
ylab = "moa_maturity")
boxplot(data=d2, moa_maturity~gender,
main="Boxplot of gender and moa_maturity",
xlab = "gender",
ylab = "moa_maturity")
boxplot(data=d2, belong~gender,
main="Boxplot of gender and belong",
xlab = "gender",
ylab = "belong")
boxplot(data=d2, belong~marriage5,
main="Boxplot of marriage5 and belong",
xlab = "marriage5",
ylab = "belong")
boxplot(data=d2, swb~marriage5,
main="Boxplot of marriage5 and swb",
xlab = "marriage5",
ylab = "swb")
boxplot(data=d2, swb~gender,
main="Boxplot of gender and swb",
xlab = "gender",
ylab = "swb")