#Installing “Here” Package
#install.packages("here")
library("here")
## here() starts at /Users/sammyromero/Documents/LaboratoryinPsychology/P421homework/P421Labs
library(psych) # for the describe() command
library(expss) # for the cross_cases() command
## Loading required package: maditr
##
## To aggregate all non-grouping columns: take_all(mtcars, mean, by = am)
##
## Attaching package: 'maditr'
## The following object is masked from 'package:base':
##
## sort_by
d2 <- read.csv(file = "Data/mydata.csv", header = T)
#the table command shows us what the levels of the variable are, and how many participants are in each variable
# categorical variables:
table(d2$disability)
##
## chronic health learning other physical psychiatric
## 147 124 87 49 378
## sensory
## 70
table(d2$income)
##
## 1 low 2 middle 3 high rather not say
## 257 218 141 239
#this command creates a histogram of the variable
# continuous variables:
hist(d2$swb)
hist(d2$idea)
hist(d2$mindful)
hist(d2$belong)
I analyzed the skew and kurtosis of the continuous variables and all were within the accepted range (-2/+2).
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
## disability* 1 855 3.70 1.71 5.00 3.77 1.48 1.00 6.00 5.00 -0.43
## income* 2 855 2.42 1.19 2.00 2.40 1.48 1.00 4.00 3.00 0.14
## swb 3 855 4.06 1.39 4.17 4.10 1.48 1.00 7.00 6.00 -0.19
## idea 4 855 3.59 0.34 3.62 3.63 0.37 2.12 4.00 1.88 -1.11
## mindful 5 855 3.48 0.84 3.47 3.48 0.79 1.13 5.67 4.53 -0.04
## belong 6 855 3.30 0.60 3.30 3.32 0.59 1.40 5.00 3.60 -0.23
## kurtosis se
## disability* -1.36 0.06
## income* -1.49 0.04
## swb -0.76 0.05
## idea 1.41 0.01
## mindful -0.19 0.03
## belong -0.21 0.02
cross_cases(d2, disability, income) #update variable 2 and variable 3 with your categorical variable names
| income | ||||
|---|---|---|---|---|
| 1 low | 2 middle | 3 high | rather not say | |
| disability | ||||
| chronic health | 45 | 35 | 22 | 45 |
| learning | 39 | 28 | 25 | 32 |
| other | 29 | 19 | 12 | 27 |
| physical | 17 | 17 | 6 | 9 |
| psychiatric | 112 | 100 | 63 | 103 |
| sensory | 15 | 19 | 13 | 23 |
| #Total cases | 257 | 218 | 141 | 239 |
plot(d2$belong , d2$idea,
main="Scatterplot of belong and idea",
xlab = "belong",
ylab = "idea")
plot(d2$mindful , d2$belong,
main="Scatterplot of Mindful and Belong",
xlab = "Mindful",
ylab = "Belong")
# boxplots use one ONE CATEGORICAL and ONE CONTINUOUS variable!!!
# make sure to enter them in the right order
# categorical variable goes BEFORE the tilde ~
# continuous variable goes AFTER the tilde ~
boxplot(data=d2, swb~income,
main="Boxplot of swb and income",
xlab = "swb",
ylab = "income")
boxplot(data=d2, idea~disability,
main="Boxplot of idea and disability",
xlab = "idea",
ylab = "disability")