Source:
Psi Chi R Contest
#Load packages and import data
library(dplyr)
library(readr)
library(ggplot2)
september=read.csv('Sept_R_Data.csv')
Data processing (level 1)
Write a script that will filter out participants who are missing
values for the ‘Age’ variable
Write a script that will filter out participants who are missing
values for the ‘Stateborn’ variable
sept_clean=september %>%
dplyr::filter(!is.na(Age) & !is.na(Stateborn)) %>%
dplyr::filter(str_detect(Age,'^[0-9]+$') & str_detect(Stateborn,'^[0-9]+$'))
Descriptive Statistics (level 2)
Create a variable called ‘CFPSCompas’ by summing together the
following variables: FPS7, FPS8, FPS9, FPS10 CFPSCompas is a variable
that measures Compassionate Reverence
Create a variable called ‘FACEsatis’ by summing together the
following variables: FACES53, FACES54, FACES55, FACES56, FACES57,
FACES58, FACES59, FACES60, FACES61, FACES62 FACEsatis is a variable that
measures Family Satisfaction
sept_clean=sept_clean %>%
mutate(FACEsatis=FACES53+FACES54+FACES55+FACES56+ FACES57+FACES58+FACES59+FACES60+ FACES61+FACES62,CFPSCompas=FPS7+FPS8+FPS9+FPS10) %>%
filter(!is.na(FACEsatis) & !is.na(CFPSCompas))
Data visualization (level 3)
Create a graph that shows the mean levels of Family Satisfaction by
gender
#Create mean for FACC and keep `Gender` as 123 rather than mutate into M/F
sept_clean2=sept_clean %>%
filter(!is.na(Gender)) %>%
select(Gender,FACEsatis,CFPSCompas,dplyr::everything())
sept_gender_face=sept_clean2 %>%
group_by(Gender) %>%
summarise(FACE_mean=mean(FACEsatis))
#Create column graph
sept_gender_face %>%
ggplot(aes(x=Gender,y=FACE_mean))+
geom_col(fill='darkgreen')+
theme_bw()+
expand_limits(y=40)+
labs(title='Mean Levels of Family Satisfaction by Gender',x='Gender',y='Family Satisifaction')+
theme(plot.title =element_text(hjust=.5))

Inferential statistics (level 4)
Test if there is an association between Compassionate Reverence and
Family Satisfaction. Note any key statistics.
test_cor=cor(sept_clean2$CFPSCompas,sept_clean2$FACEsatis)
print(test_cor) #0.44
## [1] 0.4413071
Scatter Plot
#Optional scatter plot, for fun
sept_clean2 %>%
ggplot(aes(y=FACEsatis,x=CFPSCompas))+
geom_point()+
geom_smooth(method='lm',se=F)+
theme_bw()+
labs(title='Family Satisfaction by Compassionate Reverance',x='Compassionate Reverance',y='Family Satisfaction')+
theme(plot.title = element_text(hjust=.5))

Test if there are any gender differences in mean levels of Family
Satisfaction. Note any key statistics.
#Run ANOVA
anovatest=anova(lm(sept_clean2$FACEsatis~sept_clean2$Gender))
print(anovatest) #p-value = 0.7905
## Analysis of Variance Table
##
## Response: sept_clean2$FACEsatis
## Df Sum Sq Mean Sq F value Pr(>F)
## sept_clean2$Gender 1 5 5.327 0.0706 0.7905
## Residuals 439 33106 75.411
LS0tDQp0aXRsZTogIlBzaSBDaGkgUiBDb250ZXN0IC0gU2VwdGVtYmVyIDIwMjMiDQpvdXRwdXQ6DQogIGh0bWxfZG9jdW1lbnQ6DQogICAgYWx3YXlzX2FsbG93X2h0bWw6IHllcw0KICAgIGRmX3ByaW50OiBwYWdlZA0KICAgIHRvYzogeWVzDQogICAgdG9jX2Zsb2F0OiB5ZXMNCiAgICBudW1iZXJfc2VjdGlvbnM6IG5vDQogICAgYW5jaG9yX3NlY3Rpb25zOiBUUlVFDQogICAgY29kZV9mb2xkaW5nOiBoaWRlDQogICAgY29kZV9kb3dubG9hZDogVFJVRQ0KLS0tDQpbKipTb3VyY2UqKjogUHNpIENoaSBSIENvbnRlc3RdKGh0dHBzOi8vb3NmLmlvL3g1cWNuL3dpa2kvaG9tZS8pDQoNCmBgYHtyIHNldHVwLGluY2x1ZGU9Rn0NCiMqKkNvZGUgd2lsbCBiZSByZXZlYWxlZCBhZnRlciB0aGUgc3VibWlzc2lvbiBkZWFkbGluZS4qKg0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KG1lc3NhZ2U9Rix3YXJuaW5nPUYsZWNobyA9IFQpDQpgYGANCg0KYGBge3J9DQojTG9hZCBwYWNrYWdlcyBhbmQgaW1wb3J0IGRhdGENCg0KbGlicmFyeShkcGx5cikNCmxpYn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