Newer
Older
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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) %>%
colMeans(na.rm = TRUE)
mean(inter_item_A)
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, check.keys=FALSE)
psych::alpha(scale_A, check.keys=TRUE)$total$std.alpha
scale_B1 <- responses_coded %>%
select(B02:B07)
scale_B2 <- responses_coded %>%
select(B09:B14)
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")
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
file1 = read.csv("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)
}