# if you haven't used a given package before, you'll need to download it first
# insert the "#" before the install function so that the file will Knit later
# then run the library function calling that package
#install.packages("")
library(psych) # for the describe() command
# Import the "fakedata.csv" file for this Lab
d2 <- read.csv("data/projectdata.csv")
# Note: for your Project version, you will import "projectdata.csv" that you created and exported at the end of the Project Data Prep assignment.
Tables are used to visualize individual categorical variables. Histograms are used to visualize individual continuous variables.
# use tables to visualize 2 categorical variables
table(d2$gender)
##
## female I use another term male Prefer not to say
## 535 19 115 10
table(d2$age)
##
## 1 under 18 2 between 18 and 25
## 626 53
# use histograms to visualize 4 continuous variables
hist(d2$big5_neu)
hist(d2$iou)
hist(d2$pas_covid)
hist(d2$gad)
# quick & dirty normality test: check skew & kurtosis values
describe(d2)
## vars n mean sd median trimmed mad min max range
## X 1 679 5177.50 2599.62 5808.00 5325.60 3036.36 20 8858.00 8838.00
## gender* 2 679 1.41 0.82 1.00 1.25 0.00 1 4.00 3.00
## age* 3 679 1.08 0.27 1.00 1.00 0.00 1 2.00 1.00
## big5_neu 4 679 4.65 1.45 5.00 4.74 1.48 1 7.00 6.00
## iou 5 679 2.69 0.93 2.56 2.65 1.04 1 4.89 3.89
## pas_covid 6 679 3.24 0.68 3.33 3.26 0.66 1 5.00 4.00
## gad 7 679 2.19 0.92 2.00 2.13 1.06 1 4.00 3.00
## skew kurtosis se
## X -0.42 -1.13 99.76
## gender* 1.62 0.94 0.03
## age* 3.14 7.86 0.01
## big5_neu -0.53 -0.40 0.06
## iou 0.32 -0.83 0.04
## pas_covid -0.33 0.22 0.03
## gad 0.44 -1.02 0.04
## For the required write-up below, choose one of these options to paste and edit below based on your output.
## OPTION 1
# We analyzed the skew and kurtosis of our four continuous variables and all were within the acceptable range (-2/+2).
## OPTION 2
# We analyzed the skew and kurtosis of our four continuous variables and (#) were within the acceptable range (-2/+2). However, (#) variables (list variable name(s) here) were outside of the acceptable range. For our analysis we will use them anyway, but outside of class this is bad practice.
# Objective normality test: Shapiro-Wilks test
# We want the test to be NON-SIG (aka > .05) to indicate normality
options(scipen = 999)
# the above code turns off scientific notation
shapiro.test(d2$big5_neu)
##
## Shapiro-Wilk normality test
##
## data: d2$big5_neu
## W = 0.95858, p-value = 0.0000000000006596
shapiro.test(d2$iou)
##
## Shapiro-Wilk normality test
##
## data: d2$iou
## W = 0.96962, p-value = 0.0000000001171
shapiro.test(d2$pas_covid)
##
## Shapiro-Wilk normality test
##
## data: d2$pas_covid
## W = 0.98904, p-value = 0.00005845
shapiro.test(d2$gad)
##
## Shapiro-Wilk normality test
##
## data: d2$gad
## W = 0.92422, p-value < 0.00000000000000022
I analyzed the skew and kurtosis of the four continuous variables and all were within the acceptable range (-2/+2).
Scatterplots are used to visualize combinations of two continuous variables.
plot(d2$big5_neu, d2$iou,
main="Scatterplot of Neuroticism and Intolerance of Uncertainty",
xlab = "Neuroticism",
ylab = "Intolerance of Uncertainty")
plot(d2$pas_covid, d2$gad,
main="Scatterplot of Pandemic Anxiety and General Anxiety",
xlab = "Pandemic Anxiety",
ylab = "General Anxiety")
# Note: for HW, you will choose to plot 2 combos of your 4 continuous variables, based on your hypotheses. You may repeat 1 variable to see its association with 2 others. You will need replace the variable names on the first line of the function as well as the 'main' (aka plot title), 'xlab' and 'ylab' lines to correctly label the graphs -- remember to use the actual variable names, not their scales, so someone reading your plots can understand them.
Boxplots are used to visualize combinations of one categorical and one continuous variable.
# ORDER MATTERS HERE: 'continuous variable' ~ 'categorical variable'
boxplot(data=d2, iou~age,
main="Boxplot of Intolerance of Uncertainty by Age",
xlab = "Age",
ylab = "Intolerance of Uncertainty")
boxplot(data=d2, pas_covid~gender,
main="Boxplot of Pandemic Anxiety by Gender",
xlab = "Gender",
ylab = "Pandemic Anxiety")
# Note: for HW, you will choose to plot 2 combos of any of your 4 continuous variables with either of your 2 categorical variables, based on your hypotheses. You may repeat 1 variable to see its association with others. Again, you will need replace the variable names on the first line of the function as well as the 'main' (aka plot title), 'xlab' and 'ylab' lines to correctly label the graphs -- remember to use the actual variable names, not their scales, so someone reading your plots can understand them.