# 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 get total summary skip 'by' argument: take_all(mtcars, mean)
##Import Data
# Import the "fakedata.csv" file
d2 <- read.csv("/Users/laracobasmartinez/Library/CloudStorage/OneDrive-IndianaUniversity/SOCIAL PSYCH LAB/RESEARCH/FINAL PAPER and homeworks/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$race_rc)
##
## asian black hispanic multiracial nativeamer other
## 99 145 133 156 6 43
## white
## 1034
table(d2$party_rc)
##
## apolitical democrat independent republican
## 219 823 184 390
# use histograms to visualize continuous data
hist(d2$pipwd)
hist(d2$swb)
hist(d2$support)
hist(d2$stress)
describe(d2)
## vars n mean sd median trimmed mad min max range
## ResponseID* 1 1616 808.50 466.64 808.50 808.50 598.97 1.00 1616.0 1615.00
## race_rc* 2 1616 5.53 2.13 7.00 5.86 0.00 1.00 7.0 6.00
## party_rc* 3 1616 2.46 1.00 2.00 2.45 0.00 1.00 4.0 3.00
## pipwd 4 1616 2.94 0.56 3.00 2.93 0.40 1.13 5.0 3.87
## swb 5 1616 4.33 1.35 4.50 4.38 1.48 1.00 7.0 6.00
## support 6 1616 5.43 1.16 5.67 5.54 1.11 0.00 7.0 7.00
## stress 7 1616 3.13 0.61 3.10 3.12 0.59 1.40 4.7 3.30
## skew kurtosis se
## ResponseID* 0.00 -1.20 11.61
## race_rc* -0.97 -0.72 0.05
## party_rc* 0.42 -1.01 0.02
## pipwd 0.12 1.36 0.01
## swb -0.30 -0.50 0.03
## support -1.00 1.08 0.03
## stress 0.02 -0.19 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.
cross_cases(d2, race_rc, party_rc)
party_rc | ||||
---|---|---|---|---|
apolitical | democrat | independent | republican | |
race_rc | ||||
asian | 18 | 47 | 17 | 17 |
black | 28 | 107 | 6 | 4 |
hispanic | 23 | 85 | 12 | 13 |
multiracial | 16 | 78 | 23 | 39 |
nativeamer | 4 | 1 | 1 | |
other | 15 | 15 | 6 | 7 |
white | 119 | 487 | 119 | 309 |
#Total cases | 219 | 823 | 184 | 390 |
# Note: for HW, replace the two lab variables with your project ones)
Scatterplots are used to visualize combinations of two continuous variables.
plot(d2$support, d2$stress,
main="Scatterplot of Perceived Social Support and Percieved Stress",
xlab = "Perceived Social Support",
ylab = "Percieved Stress")
plot(d2$pipwd, d2$swb,
main="Scatterplot of Positive Identity as a Person With a Disability and Satisfaction with Life",
xlab = "Positive Identity as a Person With a Disability",
ylab = "Satisfaction with Life")
# 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, support~race_rc,
main="Boxplot of Perceived Social Support and Race/Ethnicity",
xlab = "Perceived Social Support",
ylab = "Race/Ethnicity")
boxplot(data=d2, pipwd~party_rc,
main="Boxplot of Positive Identity as a Person With a Disability and Political Party Affiliation",
xlab = "Positive Identity as a Person With a Disability",
ylab = "Political Party")
# 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.
normalizePath("Data/projectdata.csv")
## Warning in normalizePath("Data/projectdata.csv"):
## path[1]="Data/projectdata.csv": No such file or directory
## [1] "Data/projectdata.csv"
I’m starting to wonder if I shouldve done disability status instead of race because I realized I dont know how I can make sure I’m looking only at the scores and data of the EAMMI2 participants who are disabled.