Commit 5f757fea authored by Maike Kleemeyer's avatar Maike Kleemeyer
Browse files

Delete analyse_data.R

parent ec6ad8b0
library(corrr)
# Binary questions
# Do you work in a group?
table(responses$A01, useNA = "ifany")
# Did you have a personal conversation with your supervisor?
table(responses$B14, useNA = "ifany")
# Have you been subjected to bullying during the past 12 months?
table(responses$D12, useNA = "ifany")
# Have you been subjected to gender discrimination during the past 12 months?
table(responses$E05, useNA = "ifany")
# Have you been subjected to sexual harassment during the past 12 months?
table(responses$F11, useNA = "ifany")
# Do children under the age of 18 live in your household?
table(responses$H07, useNA = "ifany")
# Do people with care needs live in your household?
df <- as.data.frame(table(responses$H30, useNA = "ifany"))
# Have you taken parental leave?
table(responses$H14, useNA = "ifany")
# Gender?
table(responses$I02, useNA = "ifany")
# Position?
table(responses$I03, useNA = "ifany")
# COMPUTE sum scores and means for A2, A3, B1, B2, C1, D1, D2, E1, E2, G1, G5, G7
analyses <- responses_coded %>%
mutate(sum_A = rowSums(select(.,A03:A05), na.rm = TRUE),
sum_B1 = rowSums(select(.,B02:B07), na.rm = TRUE),
sum_B2 = rowSums(select(.,B09:B14), na.rm = TRUE),
sum_C = rowSums(select(.,C02:C04), na.rm = TRUE),
sum_D = rowSums(select(.,D02:D06), na.rm = TRUE),
sum_E = rowSums(select(.,E03:E05), na.rm = TRUE),
sum_F = rowSums(select(.,F02:F08), na.rm = TRUE),
sum_H_worklife = rowSums(select(.,H02:H06), na.rm = TRUE),
sum_H_workfamily = rowSums(select(.,H09:H13), na.rm = TRUE),
sum_H_parentalleave_yes = rowSums(select(.,H17:H21), na.rm = TRUE),
sum_H_parentalleave_no = rowSums(select(.,H23:H25), na.rm = TRUE)
)
# Zeroes should be removed here, which appear if all items are not answered (=NA)
analyses <- analyses %>%
mutate(mean_A = rowMeans(select(.,A03:A05), na.rm = TRUE),
mean_B1 = rowMeans(select(.,B02:B07), na.rm = TRUE),
mean_B2 = rowMeans(select(.,B09:B14), na.rm = TRUE),
mean_C = rowMeans(select(.,C02:C04), na.rm = TRUE),
mean_D = rowMeans(select(.,D02:D06), na.rm = TRUE),
mean_E = rowMeans(select(.,E03:E05), na.rm = TRUE),
mean_F = rowMeans(select(.,F02:F08), na.rm = TRUE),
mean_H_worklife = rowMeans(select(.,H02:H06), na.rm = TRUE),
mean_H_workfamily = rowMeans(select(.,H09:H13), na.rm = TRUE),
mean_H_parentalleave_yes = rowMeans(select(.,H17:H21), na.rm = TRUE),
mean_H_parentalleave_no = rowMeans(select(.,H23:H25), na.rm = TRUE)
)
scale_A <- responses_coded %>%
select(A03:A05)
inter_item_A <- scale_A %>%
correlate() %>%
select(-term)
corr_table_A <- bind_rows(inter_item_A, colMeans(inter_item_A, na.rm = TRUE))
rownames(corr_table_A) <- c(items, "mean")
scale_A <- scale_A %>%
mutate(mean_A = rowMeans(., na.rm = TRUE))
item_total_A <- scale_A %>%
correlate() %>%
focus(mean_A)
item_total_A
mean(item_total_A$mean_A)
scale_A$mean_A <- NULL # delete the score column we made earlier
rely_A <- psych::alpha(scale_A, use = "complete.obs", check.keys=TRUE)
output_A <- bind_cols(rely_A$item.stats$n, rely_A$item.stats$mean, rely_A$item.stats$sd, rely_A$item.stats$r.drop, rely_A$alpha.drop$raw_alpha)
colnames(output_A) <- c("total", "mean", "SD", "Corrected Item total r", "Alpha if item deleted")
psych::alpha(scale_A, check.keys=TRUE)$total$std.alpha
scale_B1 <- responses_coded %>%
select(B02:B07)
scale_B2 <- responses_coded %>%
select(B09:B13)
scale_C <- responses_coded %>%
select(C02:C04)
scale_D <- responses_coded %>%
select(D02:D06)
scale_E <- responses_coded %>%
select(E03:E05)
scale_F <- responses_coded %>%
select(F02:F08)
scale_H_worklife <- responses_coded %>%
select(H02:H06)
scale_H_workfamily <- responses_coded %>%
select(H09:H13)
scale_H_parentalleave_yes <- responses_coded %>%
select(H17:H21)
scale_H_parentalleave_no <- responses_coded %>%
select(H23:H25)
# Run Factor analysis on all likert scale items
## OLD R CODE
setwd("~/Seafile/FragebogenMpg/Reanalysen_Feb2020")
file1 = read.csv("~/Seafile/FragebogenMpg/Reanalysen_Feb2020/20200106_MPG Work Culture_Basic Data_likert.csv",header=TRUE,sep=";")
library(psych)
library(umx)
library(ggplot2)
library(Hmisc)
file1$H1_gender <- as.factor(file1$H1_gender)
scale_a <- subset(file1, select = A2_groupatmo1_1:A3_groupatmo4_3)
umxEFA(file1, factors = 19, scores= "ML")
print(class(file1[[i]]))
for (i in colnames(file1)){
p <- ggplot(file1, aes(x=c("all"),
y=file1[[i]]))
+ geom_violin(trim=FALSE)
data_summary <- function(x) {
m <- mean(x)
ymin <- m-sd(x)
ymax <- max(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
p + stat_summary(fun.data=data_summary)
p <- ggplot(file1, aes(x=file1$H1_gender,
y=file1[[i]], fill=file1$H1_gender))
+ geom_violin(trim=FALSE)
data_summary <- function(x) {
m <- mean(x)
ymin <- m-sd(x)
ymax <- max(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
p + stat_summary(fun.data=data_summary)
p <- ggplot(file1, aes(x=file1$H1_gender,
y=file1[[i]], fill=file1$startlanguage))
+ geom_violin(trim=FALSE)
data_summary <- function(x) {
m <- mean(x)
ymin <- m-sd(x)
ymax <- max(x)
return(c(y=m,ymin=ymin,ymax=ymax))
}
p + stat_summary(fun.data=data_summary)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment