# if you haven't used a given package before, you'll need to download it first
# delete the "#" before the install function and run it to download
# re-insert the "#" before the install function so that the file will Knit later
# then run the library function calling that package
#install.packages("psych")
#install.packages("expss")
library(psych) # for the describe() command
## Warning: package 'psych' was built under R version 4.3.3
#library(expss) # for the cross_cases() command
##Import Data
# Import the "fakedata.csv" file
d2 <- read.csv("Data/projectdata.csv")
# Note: for the HW, you will import "projectdata.csv" that you created and exported in the Data Prep Lab
Tables are used to visualize individual categorical variables. Histograms are used to visualize individual continuous variables.
# use tables to visualize categorical data
table(d2$gender)
##
## f m nb
## 2263 774 52
table(d2$marriage5)
##
## are currently divorced from one another
## 714
## are currently married to one another
## 2092
## never married each other and are not together
## 238
## never married each other but are currently together
## 45
# use histograms to visualize continuous data
hist(d2$moa_role)
hist(d2$idea)
hist(d2$mindful)
hist(d2$belong)
describe(d2)
## vars n mean sd median trimmed mad min max range
## ResponseID* 1 3089 1545.00 891.86 1545.00 1545.00 1144.57 1.00 3089 3088.00
## gender* 2 3089 1.28 0.49 1.00 1.21 0.00 1.00 3 2.00
## marriage5* 3 3089 1.88 0.59 2.00 1.84 0.00 1.00 4 3.00
## moa_role 4 3089 2.97 0.72 3.00 3.00 0.74 1.00 4 3.00
## idea 5 3089 3.58 0.38 3.62 3.62 0.37 1.00 4 3.00
## mindful 6 3089 3.71 0.84 3.73 3.71 0.79 1.13 6 4.87
## belong 7 3089 3.23 0.61 3.30 3.25 0.59 1.30 5 3.70
## skew kurtosis se
## ResponseID* 0.00 -1.20 16.05
## gender* 1.39 0.85 0.01
## marriage5* 0.46 1.51 0.01
## moa_role -0.33 -0.84 0.01
## idea -1.53 4.44 0.01
## mindful -0.07 -0.15 0.02
## belong -0.27 -0.12 0.01
## 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 continuous variables and all were within the accepted range (-2/+2).
## OPTION 2
# We analyzed the skew and kurtosis of our continuous variables and (#) were within the accepted range (-2/+2). However, (#) variables (list variable name(s) here) were outside of the accepted range. For this analysis, we will use them anyway, but outside of this class this is bad practice.
We analyzed the skew and kurtosis of our continuous variables and 3 were within the accepted range (-2/+2). However, 1 variable: idea (Perceptions of Emerging Adulthood) was outside of the accepted range. For this analysis, we will use them anyway, but outside of this class this is bad practice.
Crosstabs are used to visualize combinations of two categorical variables.
#cross_cases(d2, variable2, variable3)
xtabs(~ gender + marriage5, data=d2)
## marriage5
## gender are currently divorced from one another
## f 530
## m 171
## nb 13
## marriage5
## gender are currently married to one another
## f 1525
## m 534
## nb 33
## marriage5
## gender never married each other and are not together
## f 176
## m 56
## nb 6
## marriage5
## gender never married each other but are currently together
## f 32
## m 13
## nb 0
# Note: for HW, replace the two lab variables with your project ones)
#install.packages("maditr")
#library(maditr)
Scatterplots are used to visualize combinations of two continuous variables.
plot(d2$moa_role, d2$belong,
main="Scatterplot of Perceived Importance of Markers of Adulthood and Need to Belong",
xlab = "Perceived Importance of Markers of Adulthood",
ylab = "Need to Belong")
plot(d2$mindful, d2$idea,
main="Scatterplot of Mindful Attention Awareness and Perceptions of Emerging Adulthood",
xlab = "Mindful Attention Awareness",
ylab = "Perceptions of Emerging Adulthood")
# 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,moa_role~gender,
main="Boxplot of Gender Identity and Perceived Importance of Markers of Adulthood",
xlab = "Gender Identity",
ylab = "Perceived Importance of Markers of Adulthood")
boxplot(data=d2, moa_role~marriage5,
main="Boxplot of Parents' Marital Status and Perceived Importance of Markers of Adulthood",
xlab = "Parents' Marital Status",
ylab = "Perceived Importance of Markers of Adulthood")
# 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.
We did it!!