library(lavaan)
library(psych)
## FFM intercorrelations from Ones, Viswesvaran, & Reiss (1996) / Ones (1993)
## FFM-EMG correlations re-attenuated from Judge et al., (2002). 
## These correlations are calculated in the corresponding Excel file.
cor_FFM_emg_redis <- lav_matrix_lower2full(
  c(1,
    0.19,	1,
    0.16,	0.17,	1,
    0.25,	0.17,	0.11,	1,
    0.26,	0.00,	-0.06,	0.27,	1,
    0.20, 0.26, 0.19, 0.04, 0.26, 1))

colnames(cor_FFM_emg_redis) <-  c("ES", "E", "O", "A", "C", "Emg")
N_FFM_redis_emg <- c(148721,
                     440440, 294515,
                     254937, 252004, 47177,
                     415679, 135529, 144205, 79303,
                     490296, 683001, 356680, 162975, 288512,
                     7510*17/35, 9801*23/42, 8025*30/48, 7221*20/37, 11705*37/60)

emg_model <- 'Emg ~ E + A + C + ES + O'
emg_redis_fit <- sem(emg_model, sample.cov = cor_FFM_emg_redis, 
                     sample.nobs = harmonic.mean(N_FFM_redis_emg))  # 17524.01
summary(emg_redis_fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE)[[6]]
sqrt(0.17754662)



## FFM intercorrelations from Ones, Viswesvaran, & Reiss (1996) / Ones (1993)
## FFM-EFF correlations re-attenuated from Judge et al., (2002). 
## These correlations are calculated in the corresponding Excel file.
cor_FFM_redis <- lav_matrix_lower2full(
  c(1,
    0.19,	1,
    0.16,	0.17,	1,
    0.25,	0.17,	0.11,	1,
    0.26,	0.00,	-0.06,	0.27,	1,
    0.18, 0.20, 0.20, 0.17, 0.13, 1))

cor_FFM_Judge <- lav_matrix_lower2full(
  c(1,
    0.19,	1,
    0.16,	0.17,	1,
    0.25,	0.17,	0.11,	1,
    0.26,	0.00,	-0.06, 0.27,	1,
    0.22, 0.24, 0.24, 0.21, 0.16, 1))

colnames(cor_FFM_redis) <- c("ES", "E", "O", "A", "C", "Eff")
colnames(cor_FFM_Judge) <- c("ES", "E", "O", "A", "C", "Eff")

### N from Ones, Viswesvaran, & Reiss (1996) / Ones (1993)
### As well as weighted N in Judge et al., (2002) weighted by the number of studies (EFF vs EMG)
N_FFM_redis <- c(148721,
                 440440, 294515,
                 254937, 252004, 47177,
                 415679, 135529, 144205, 79303,
                 490296, 683001, 356680, 162975, 288512,
                 7510*18/35, 9801*19/42, 8025*18/48, 7221*17/37, 11705*23/60)

redis_model <- 'Eff ~ E + A + C + ES + O'
redis_fit <- sem(redis_model, sample.cov = cor_FFM_redis, 
                 sample.nobs = harmonic.mean(N_FFM_redis))  ## 14008.12
summary(redis_fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE)
summary(redis_fit, fit.measures = TRUE, standardized = TRUE, rsquare = TRUE)[[6]]
sqrt(0.10167797)


