# 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
library(expss) # for the cross_cases() command
## Loading required package: maditr
##
## To select columns from data: columns(mtcars, mpg, vs:carb)
##
## Use 'expss_output_viewer()' to display tables in the RStudio Viewer.
## To return to the console output, use 'expss_output_default()'.
##Import Data
# Import the projectdata.csv file created in the Data Prep Lab
d2 <- read.csv("~/Downloads/Psy P421( Social Capstone)/Research/Final Paper/Data/projectdata.csv")
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
## 2320 788 54
# use histograms to visualize continuous data
hist(d2$stress)
hist(d2$swb)
hist(d2$belong)
hist(d2$support)
describe(d2)
## vars n mean sd median trimmed mad min max range
## ResponseID* 1 3162 1581.50 912.94 1581.50 1581.50 1172.00 1.0 3162.0 3161.0
## gender* 2 3162 1.28 0.49 1.00 1.21 0.00 1.0 3.0 2.0
## socmeduse 3 3162 34.44 8.57 35.00 34.72 7.41 11.0 55.0 44.0
## stress 4 3162 3.05 0.60 3.00 3.05 0.59 1.3 4.7 3.4
## swb 5 3162 4.48 1.32 4.67 4.53 1.48 1.0 7.0 6.0
## belong 6 3162 3.23 0.61 3.30 3.25 0.59 1.3 5.0 3.7
## support 7 3162 5.53 1.13 5.75 5.66 0.99 0.0 7.0 7.0
## skew kurtosis se
## ResponseID* 0.00 -1.20 16.24
## gender* 1.40 0.88 0.01
## socmeduse -0.31 0.26 0.15
## stress 0.03 -0.17 0.01
## swb -0.36 -0.45 0.02
## belong -0.26 -0.12 0.01
## support -1.10 1.43 0.02
## 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 all were within the accepted range (-2/+2).
Crosstabs are used to visualize combinations of two categorical variables.
# Note: our dataset has only one categorical variable (gender), so a crosstab is not applicable here.
table(d2$gender)
##
## f m nb
## 2320 788 54
Scatterplots are used to visualize combinations of two continuous variables.
plot(d2$socmeduse, d2$stress,
main = "Scatterplot of Social Media Use and Stress",
xlab = "socmeduse",
ylab = "stress")
plot(d2$socmeduse, d2$swb,
main = "Scatterplot of Social Media Use and Subjective Well-Being",
xlab = "socmeduse",
ylab = "swb")
Boxplots are used to visualize combinations of one categorical and one continuous variable.
boxplot(d2$stress ~ d2$gender,
main = "Boxplot of Stress by Gender",
xlab = "gender",
ylab = "stress")
boxplot(d2$swb ~ d2$gender,
main = "Boxplot of Subjective Well-Being by Gender",
xlab = "gender",
ylab = "swb")
We did it!!