# 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)
##
## f m nb
## 575 162 36
table(d2$disability)
##
## chronic health learning other physical psychiatric
## 137 108 76 44 346
## sensory
## 62
# use histograms to visualize 4 continuous variables
hist(d2$pipwd)
hist(d2$moa_independence)
hist(d2$belong)
hist(d2$support)
# quick & dirty normality test: check skew & kurtosis values
describe(d2)
## vars n mean sd median trimmed mad min max range
## ResponseID* 1 773 387.00 223.29 387.00 387.00 286.14 1.00 773.0 772.00
## gender* 2 773 1.30 0.55 1.00 1.20 0.00 1.00 3.0 2.00
## disability* 3 773 3.70 1.71 5.00 3.77 1.48 1.00 6.0 5.00
## pipwd 4 773 2.91 0.70 2.93 2.92 0.69 1.13 5.0 3.87
## moa_independence 5 773 3.48 0.46 3.50 3.53 0.49 1.50 4.0 2.50
## belong 6 773 3.29 0.61 3.30 3.31 0.59 1.40 4.8 3.40
## support 7 773 5.31 1.23 5.58 5.44 1.11 0.00 7.0 7.00
## skew kurtosis se
## ResponseID* 0.00 -1.20 8.03
## gender* 1.65 1.77 0.02
## disability* -0.44 -1.36 0.06
## pipwd 0.01 -0.06 0.03
## moa_independence -1.19 1.78 0.02
## belong -0.26 -0.19 0.02
## support -0.95 0.75 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$pipwd)
##
## Shapiro-Wilk normality test
##
## data: d2$pipwd
## W = 0.99537, p-value = 0.02003
shapiro.test(d2$moa_independence)
##
## Shapiro-Wilk normality test
##
## data: d2$moa_independence
## W = 0.89396, p-value < 0.00000000000000022
shapiro.test(d2$belong)
##
## Shapiro-Wilk normality test
##
## data: d2$belong
## W = 0.99145, p-value = 0.0001888
shapiro.test(d2$support)
##
## Shapiro-Wilk normality test
##
## data: d2$support
## W = 0.93587, p-value < 0.00000000000000022
We analyzed the skew and kurtosis of our four continuous variables and all were within the acceptable range (-2/+2).
Scatterplots are used to visualize combinations of two continuous variables.
plot(d2$pipwd, d2$moa_independence,
main="Scatterplot of Positive Identity of a Person with a Disability and Independence",
xlab = "Positive Identity of a Person with a Disability",
ylab = "Independence")
plot(d2$belong, d2$support,
main="Scatterplot of Need to Belong and Perceived Social Support",
xlab = "Need to Belong",
ylab = "Perceived Social Support")
# 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, pipwd~disability,
main="Boxplot of Positive Identity by Disability",
xlab = "Disability",
ylab = "Positive Identity")
boxplot(data=d2, support~gender,
main="Boxplot of Perceived Social Support by Gender",
xlab = "Gender",
ylab = "Perceived Social Support")
# 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.
Those are the basics!!