source("../Utilities/Utilities-Main.R")
library(psych)
library(dplyr)


############# This file produces the number of studies for EMG/EFF

# Leadership Emergence
data_FFM_emg <- data_FFM %>% filter(DV == 1 & INCLUDE_IN_ANALYSIS == 1)

studies_emg <- data_FFM_emg %>% arrange(`Full Citation`, IV) %>% select(`Full Citation`,`Publication code`, N, rxx, ryy, IV, Country,
                                                                        rxy, Collectivism, `What is computed (not directy reported)?`)
# write.csv(studies_emg, "EMG_STUDIES.csv", fileEncoding = "UTF-8")

# data_FFM_emg2 <- data_FFM2 %>% filter(DV == 1)

data_FFM_emg %>% group_by(`Coding ID`)
length(table(data_FFM_emg %>% group_by(`Coding ID`) %>% select(`Coding ID`)))  # 108 samples
sum(data_FFM_emg %>% group_by(`Coding ID`) %>% summarize(NN = max(N)) %>% select(NN))  # Harmonic N = 30305.64


# Leadership Effectiveness
data_FFM_eff <- data_FFM %>% filter(INCLUDE_AS_JUDGE_OP == 1)

### Edit the columns here if you need other cultural dimensions
studies_eff <- data_FFM_eff %>% arrange(`Full Citation`, IV) %>% select(`Full Citation`,`Publication code`, N, rxx, ryy, IV, Country,
                                                                        rxy, Collectivism, `ES_TYPE`)
write.csv(studies_eff, "EFF_STUDIES2.csv", fileEncoding = "UTF-8")
length(table(data_FFM_eff %>% group_by(`Coding ID`) %>% select(`Coding ID`)))  # 108 samples
sum(data_FFM_eff %>% group_by(`Coding ID`) %>% summarize(NN = max(N)) %>% select(NN))  # Harmonic N = 41166.77

names(table(data_FFM_eff %>% group_by(`Coding ID`) %>% select(`Coding ID`)))
names(table(data_FFM_emg %>% group_by(`Coding ID`) %>% select(`Coding ID`)))
intersect(names(table(data_FFM_eff %>% group_by(`Coding ID`) %>% select(`Coding ID`))),
          names(table(data_FFM_emg %>% group_by(`Coding ID`) %>% select(`Coding ID`))))
108 + 108 - 12   # 204



### HEXACO ####

# Leadership Emergence
data_HEXACO_emg <- data_HEXACO %>% filter(DV == 1 & INCLUDE_TYPE == 1)
length(table(data_HEXACO_emg %>% group_by(`Coding ID`) %>% select(`Coding ID`)))  # 12 samples
sum(data_HEXACO_emg %>% group_by(`Coding ID`) %>% summarize(NN = max(N)) %>% select(NN))  # Harmonic N = 2266
studies_emg_HEX <- data_HEXACO_emg %>% arrange(`Full Citation`, IV) %>% select(`Full Citation`,`Publication code`, N, rxx, ryy, IV, Country,
                                                                                   rxy, Collectivism, ES_TYPE)
# write.csv(studies_emg_HEX, "EMG_HEX_STUDIES.csv", fileEncoding = "UTF-8")


# Leadership Effectiveness
data_HEXACO_eff <- data_HEXACO %>% filter(INCLUDE_AS_JUDGE_OP == 1)
length(table(data_HEXACO_eff %>% group_by(`Coding ID`) %>% select(`Coding ID`)))  # 8 samples
sum(data_HEXACO_eff %>% group_by(`Coding ID`) %>% summarize(NN = max(N)) %>% select(NN))  # Harmonic N = 1045
studies_eff_HEX <- data_HEXACO_eff %>% arrange(`Full Citation`, IV) %>% select(`Full Citation`,`Publication code`, N, rxx, ryy, IV, Country,
                                                                               rxy, Collectivism, ES_TYPE)
# write.csv(studies_eff_HEX, "EFF_HEX_STUDIES.csv", fileEncoding = "UTF-8")
intersect(data_HEXACO_emg$`Article ID`, data_HEXACO_eff$`Article ID`)

