knitr::opts_chunk$set(echo = TRUE, warning = TRUE, message = FALSE)

Preparation

load packages

options(scipen = 99999)

library(psych)
library(knitr)
library(dplyr)
library(tidyverse)
#library(QuantPsyc)
library(datarobot)
library(xtable)
library(reshape2)
library(naniar)
library(pander)
library(lavaan)
library(data.table)
library(corrplot)
library(GPArotation)
library(writexl)
library(car)
library(semTable)
library(ggplot2)
library(kableExtra)

Load correlation matrix

load("scale_cor.rda")

Load 14 factor loadings from EFA with equamax rotation based on latent correlation matrix

# Model with components defined by all constructs that load >.3


# # load varnames from ackward object
# for (i in 1:14){
#   temp =data.frame(scales = rownames(loadings_final_strong)[loadings_final_strong[,paste0("N",i)] >.31],loadings = loadings_final_strong[,paste0("N",i)][loadings_final_strong[,paste0("N",i)] >=.31])
# temp =temp[!is.na(temp$scales),]
# temp = temp[order(temp$loadings, decreasing = T),]
# temp$loadings = round(temp$loadings, digits = 2)
# temp$loadings = as.character(sub("0.", ".", temp$loadings))
# rownames(temp) = 1:nrow(temp)
# print(kable(temp))
#
# cat(paste0("N",i))
# cat("\n")
#
# cat("\n")
# cat("\n")
# }

load("BAcomploadings.rda")

options(knitr.kable.NA = '')
kable(round(BassAck14Loadings,2))
n1 n2 n3 n4 n5 n6 n7 n8 n9 n10 n11 n12 n13 n14
SAD_soc_inter 0.74
SAD_avoidance 0.73
SAD_performing 0.70 0.33
SAD_devaluation 0.67
SAD_being_observ 0.67
SAD_eating 0.58 0.31
SAD_attractive_pers 0.58
PF_forming_relshps 0.55 0.37 0.31
Spec_phob_avoid 0.47 0.44
Agoraphobia 0.44
DEP_hopelessn 0.65
DEP_depr_mood 0.63 0.32
DEP_dimin_selfconf 0.56 0.44
DEP_worthlessn 0.56 0.31
DEP_suicid_intent 0.53
DEP_dimin_interest 0.53 0.46 0.35
DEP_guilt 0.51
DEP_crying 0.47
DEP_decision_probl 0.42 0.36 0.40
PF_self_reflection 0.37 0.33 0.36
Panic_doctor_visits 0.84
Panic_attacks 0.83
Panic_phys_symp 0.80
Panic_dysf_thought 0.76
Panic_fear_recurr 0.72
Panic_avoid_behv 0.59
Somatic_symptoms 0.42 0.32
Hypochondriasis 0.33
GAD_free_float_anx 0.74
GAD_nervousness 0.73
GAD_irritability 0.69
GAD_excess_worry 0.69
DEP_rumination 0.43 0.47 0.33
DEP_psycmot_agit 0.35 0.46
PF_affect_diff 0.35 0.43 0.31
OCD_sympt 0.36 0.34
DI_perfectionism 0.34
EATA_restricted 0.88
EATA_omit_meal 0.87
EATA_time_frames 0.84
EATA_count_calories 0.83
EATA_purging_behv 0.65
EATA_exces_exercise 0.62 0.35
EATB_loss_ctrl 0.91
EATB_cope_negaff 0.89
EATB_overeating 0.89
EATB_intrus_thoughts 0.72
DEP_incr_appetite 0.62
EATB_soc_disguised 0.44 0.53 0.47
PS_unusual_beliefs 0.62
PS_percept_dysreg 0.60
Psychotic_symptoms 0.59
Dissociation 0.57
PS_eccentricity 0.49 0.37
PF_identity 0.39 0.33 0.40 0.31
Manic_sympt 0.36 0.36
PF_anticipation 0.59
PF_affect_comm 0.53
PF_intern_relshp_mod 0.52 0.42
NA_sep_insecur 0.48
DT_suspiciousness 0.44 0.38
PF_holistic_percptn 0.40 0.37
PF_self_est_reg 0.32 0.31 0.40
NA_perseveration 0.38 0.35
PF_affect_tolrnce 0.32 0.34 0.36
DEP_psycmot_inhib 0.57
DEP_reduc_energy 0.49 0.52
DEP_hypersomnia 0.51
DEP_circad_mood_fluct 0.49
DEP_concentration 0.38 0.33 0.45
DEP_loss_appetite 0.43
DEP_loss_libido 0.42
DT_intimcy_avoid 0.64
DT_restr_affectivity 0.34 0.64
DT_withdrawal 0.38 0.54
DEP_emot_numbn 0.31 0.54
DEP_crying_inab 0.33 0.48
DT_anhedonia 0.42 0.36 0.46
AN_callousness 0.70
AN_hostility 0.62
AN_deceitfulness 0.62
AN_manipulativns 0.31 0.59
AN_entitlement 0.59
AN_grandiosity 0.53
PF_impulse_reg 0.42 0.51
DI_impulsivity 0.31 0.39 0.37
Spec_phob_fear 0.72
Spec_phob_animals 0.70
Spec_phob_blood 0.69
EATA_body_selfest 0.34 0.34 0.69
EATB_worries 0.36 0.38 0.67
EATA_fear_weightg 0.40 0.41 0.63
EATA_fear_weightl 0.62
Subst_use_drug 0.70
DI_normviolation 0.68
Subst_use_alc 0.65
DI_risk_taking 0.44
DI_irresponsibility 0.31 0.33 0.36

Estimate bifactor models for every higher order factor in bass ackwards hierarchy including GP

Function to extract G and S loadings

# do it for every higher order factor
# G1 SomDepDet

# create list object with loadings from bifactormodels
bifloads = list()

# function to extract factorloadings on G factor and average factorloadings on S factors
extractGS = function(bifactload, G){
  gsloads = data.frame(scale = rownames(bifactload),G=bifactload[,G], S=NA)
  for (k in 1: nrow(bifactload)){
    gsloads$S[k] =mean(abs(bifactload[k,1:ncol(bifactload)-1][bifactload[k,1:ncol(bifactload)-1] !=0]), na.rm = T)
  }
  gsloads$G_minus_S = gsloads$G - gsloads$S
  gsloads = gsloads[order(gsloads$G_minus_S, decreasing = T),]
  rownames(gsloads) = 1:nrow(gsloads)
  return(data.frame(gsloads))
}

# function to extract factorloadings on G factor and highest S factor loading (including name)
extractGSmax = function(bifactload, G){
  gsloads = data.frame(scale = rownames(bifactload),G=bifactload[,G], S=NA)
  for (k in 1: nrow(bifactload)){
    gsloads$S[k] =max(abs(bifactload[k,!(names(bifactload) == G)]), na.rm = T)
     gsloads$St[k] =paste0("[",sub("0.", ".",round(gsloads$S[k], digits = 2)), ";",sub("\\_.*", "",names(bifactload)[which(abs(bifactload[k,!(names(bifactload) == G)]) == max(abs(bifactload[k,!(names(bifactload) == G)]), na.rm = T))]),"]")
  }
  gsloads$G_minus_S = gsloads$G - gsloads$S
  gsloads = gsloads[order(gsloads$G_minus_S, decreasing = T),]
  gsloads$S = gsloads$St
  gsloads$St = NULL
  rownames(gsloads) = 1:nrow(gsloads)
  return(data.frame(gsloads))
}

M8: Antagonism and PF Problems

M8base = "

#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + PF_impulse_reg + DI_impulsivity + DI_irresponsibility + PF_holistic_percptn
"

M8bifact ="
M8 =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity + AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + DI_irresponsibility

#orthogonal
N8_PF_Problems  ~~ 0*N11_EXT_Ant

M8  ~~ 0*N8_PF_Problems
M8  ~~ 0*N11_EXT_Ant
"


#G1basemodel <- cfa(model = paste0(G1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
M8bifactmodel = cfa(model = paste0(M8base, M8bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(M8bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]
kable(uSRMR)
fitindex value
usrmr usrmr 0.0441083
usrmr.se usrmr.se 0.0003855
usrmr.ci.lower usrmr.ci.lower 0.0434743
usrmr.ci.upper usrmr.ci.upper 0.0447424
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.1941745
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(M8bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0496076
summary(M8bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 34 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        72
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              35692.535
##   Degrees of freedom                                204
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems =~
##     PF_anticipatin    -0.049    0.010   -4.779    0.000   -0.049   -0.039
##     PF_affect_comm    -0.105    0.010  -10.241    0.000   -0.105   -0.087
##     PF_ntrn_rlshp_     0.046    0.009    4.850    0.000    0.046    0.039
##     NA_sep_insecur     0.264    0.009   28.285    0.000    0.264    0.216
##     DT_suspicisnss    -0.036    0.011   -3.279    0.001   -0.036   -0.026
##     PF_hlstc_prcpt     0.007    0.008    0.957    0.339    0.007    0.007
##     PF_self_est_rg     0.188    0.008   22.489    0.000    0.188    0.176
##     NA_perseveratn     0.137    0.008   16.465    0.000    0.137    0.129
##     PF_affct_tlrnc     0.597    0.009   64.630    0.000    0.597    0.484
##     PF_impulse_reg     0.083    0.007   11.847    0.000    0.083    0.076
##     DI_impulsivity     0.146    0.007   20.030    0.000    0.146    0.130
##     PF_frmng_rlshp    -0.101    0.010   -9.895    0.000   -0.101   -0.077
##     DEP_rumination     0.480    0.010   47.723    0.000    0.480    0.359
##     PF_affect_diff     0.680    0.010   70.751    0.000    0.680    0.528
##     PS_eccentricty     0.089    0.010    9.167    0.000    0.089    0.074
##     PF_identity        0.495    0.008   60.423    0.000    0.495    0.460
##   N11_EXT_Ant =~
##     AN_callousness     0.328    0.004   81.725    0.000    0.328    0.517
##     AN_hostility       0.379    0.006   67.724    0.000    0.379    0.396
##     AN_deceitflnss     0.487    0.005   90.452    0.000    0.487    0.534
##     AN_manipultvns     0.465    0.005   85.785    0.000    0.465    0.545
##     AN_entitlement     0.337    0.005   67.078    0.000    0.337    0.452
##     AN_grandiosity     0.399    0.007   59.162    0.000    0.399    0.369
##     PF_impulse_reg     0.370    0.006   62.193    0.000    0.370    0.338
##     DI_impulsivity     0.355    0.006   58.216    0.000    0.355    0.316
##     DI_irrspnsblty     0.184    0.005   37.143    0.000    0.184    0.243
##     PF_hlstc_prcpt     0.229    0.006   37.163    0.000    0.229    0.210
##   M8 =~
##     PF_anticipatin     0.934    0.007  138.074    0.000    0.934    0.740
##     PF_affect_comm     1.030    0.006  168.148    0.000    1.030    0.851
##     PF_ntrn_rlshp_     0.877    0.006  139.295    0.000    0.877    0.744
##     NA_sep_insecur     0.707    0.007   96.639    0.000    0.707    0.580
##     DT_suspicisnss     0.924    0.008  121.603    0.000    0.924    0.673
##     PF_hlstc_prcpt     0.696    0.006  113.992    0.000    0.696    0.640
##     PF_self_est_rg     0.720    0.006  117.811    0.000    0.720    0.672
##     NA_perseveratn     0.680    0.006  112.277    0.000    0.680    0.640
##     PF_affct_tlrnc     0.877    0.008  105.752    0.000    0.877    0.710
##     PF_impulse_reg     0.694    0.006  112.599    0.000    0.694    0.635
##     DI_impulsivity     0.708    0.006  110.512    0.000    0.708    0.630
##     PF_frmng_rlshp     0.732    0.008   95.299    0.000    0.732    0.556
##     DEP_rumination     0.832    0.008   97.931    0.000    0.832    0.623
##     PF_affect_diff     0.933    0.009  105.099    0.000    0.933    0.725
##     PS_eccentricty     0.904    0.006  139.630    0.000    0.904    0.747
##     PF_identity        0.822    0.007  118.207    0.000    0.822    0.764
##     AN_callousness     0.225    0.004   58.075    0.000    0.225    0.355
##     AN_hostility       0.522    0.006   93.864    0.000    0.522    0.546
##     AN_deceitflnss     0.434    0.005   80.123    0.000    0.434    0.476
##     AN_manipultvns     0.284    0.005   54.167    0.000    0.284    0.333
##     AN_entitlement     0.164    0.005   35.284    0.000    0.164    0.220
##     AN_grandiosity     0.495    0.006   76.752    0.000    0.495    0.458
##     DI_irrspnsblty     0.315    0.005   69.080    0.000    0.315    0.416
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems ~~
##     N11_EXT_Ant        0.000                               0.000    0.000
##     M8                 0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     M8                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .PF_anticipatin    0.717    0.007  100.966    0.000    0.717    0.451
##    .PF_affect_comm    0.392    0.005   76.352    0.000    0.392    0.268
##    .PF_ntrn_rlshp_    0.619    0.006  105.049    0.000    0.619    0.445
##    .NA_sep_insecur    0.916    0.008  113.200    0.000    0.916    0.616
##    .DT_suspicisnss    1.029    0.010  106.430    0.000    1.029    0.546
##    .PF_hlstc_prcpt    0.644    0.006  109.616    0.000    0.644    0.546
##    .PF_self_est_rg    0.593    0.005  111.399    0.000    0.593    0.517
##    .NA_perseveratn    0.647    0.006  112.021    0.000    0.647    0.574
##    .PF_affct_tlrnc    0.400    0.005   88.167    0.000    0.400    0.262
##    .PF_impulse_reg    0.570    0.005  105.895    0.000    0.570    0.477
##    .DI_impulsivity    0.614    0.006  107.149    0.000    0.614    0.486
##    .PF_frmng_rlshp    1.185    0.011  109.127    0.000    1.185    0.685
##    .DEP_rumination    0.860    0.008  108.297    0.000    0.860    0.483
##    .PF_affect_diff    0.323    0.005   70.790    0.000    0.323    0.195
##    .PS_eccentricty    0.638    0.006  106.197    0.000    0.638    0.436
##    .PF_identity       0.236    0.003   83.121    0.000    0.236    0.204
##    .AN_callousness    0.244    0.002   98.042    0.000    0.244    0.606
##    .AN_hostility      0.498    0.005  104.504    0.000    0.498    0.545
##    .AN_deceitflnss    0.405    0.004   92.615    0.000    0.405    0.488
##    .AN_manipultvns    0.431    0.005   95.262    0.000    0.431    0.593
##    .AN_entitlement    0.415    0.004  104.674    0.000    0.415    0.747
##    .AN_grandiosity    0.763    0.007  108.014    0.000    0.763    0.654
##    .DI_irrspnsblty    0.440    0.004  113.097    0.000    0.440    0.767
##     N8_PF_Problems    1.000                               1.000    1.000
##     N11_EXT_Ant       1.000                               1.000    1.000
##     M8                1.000                               1.000    1.000
#summary(G1basemodel, std=T, fit=T)

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$M8 = data.frame(lavInspect(M8bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(G1basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_M8 = data.frame(bifloads$M8$M8 - abs(bifloads$M8[,1]) - abs(bifloads$M8[,2]))
#
# rownames(loadingschange_M8) = rownames(bifloads$M8)
# names(loadingschange_M8) = "std_G_loading_minus_S_loading"
# loadingschange_M8 = loadingschange_M8 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_M8)[1] = "scale"

kable(extractGSmax(bifloads$M8, "M8"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_affect_comm 0.8513455 [.09;N8] 0.7647456
PF_intern_relshp_mod 0.7439208 [.04;N8] 0.7048687
PF_anticipation 0.7401914 [.04;N8] 0.7015088
PS_eccentricity 0.7472764 [.07;N8] 0.6736454
DT_suspiciousness 0.6731707 [.03;N8] 0.6470654
NA_perseveration 0.6401187 [.13;N8] 0.5115172
PF_self_est_reg 0.6721492 [.18;N8] 0.4962909
PF_forming_relshps 0.5562834 [.08;N8] 0.4792231
PF_holistic_percptn 0.6403920 [.21;N11] 0.4300657
NA_sep_insecur 0.5803610 [.22;N8] 0.3640795
DI_impulsivity 0.6300210 [.32;N11] 0.3138885
PF_identity 0.7643618 [.46;N8] 0.3041701
PF_impulse_reg 0.6348379 [.34;N11] 0.2967154
DEP_rumination 0.6231164 [.36;N8] 0.2637140
PF_affect_tolrnce 0.7097848 [.48;N8] 0.2261440
PF_affect_diff 0.7251626 [.53;N8] 0.1970215
DI_irresponsibility 0.4164949 [.24;N11] 0.1733317
AN_hostility 0.5459763 [.4;N11] 0.1495474
AN_grandiosity 0.4581256 [.37;N11] 0.0886395
AN_deceitfulness 0.4762756 [.53;N11] -0.0576062
AN_callousness 0.3551402 [.52;N11] -0.1623059
AN_manipulativns 0.3326953 [.54;N11] -0.2120327
AN_entitlement 0.2202529 [.45;N11] -0.2316934

G1: Somatic Depression and Detachment

G1base = "

#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + PF_self_reflection + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + PF_identity + PF_self_est_reg + DEP_reduc_energy + DEP_concentration + DT_anhedonia

#N9
N9_Somatic_Dep =~ DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms + NA_perseveration

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness
"

G1bifact ="
G1 =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + PF_self_reflection + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + PF_identity + PF_self_est_reg + DEP_reduc_energy + DEP_concentration + DT_anhedonia + DEP_psycmot_inhib + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_loss_appetite + DEP_loss_libido + Somatic_symptoms + NA_perseveration + DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + PF_intern_relshp_mod + DT_suspiciousness

N2_Depression  ~~ 0*N9_Somatic_Dep
N2_Depression  ~~ 0*N10_Detachment
N9_Somatic_Dep  ~~ 0*N10_Detachment

G1  ~~ 0*N9_Somatic_Dep
G1  ~~ 0*N10_Detachment
G1  ~~ 0*N2_Depression
"

#G1basemodel <- cfa(model = paste0(G1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
G1bifactmodel = cfa(model = paste0(G1base, G1bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(G1bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0396794
usrmr.se usrmr.se 0.0002781
usrmr.ci.lower usrmr.ci.lower 0.0392220
usrmr.ci.upper usrmr.ci.upper 0.0401369
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.2489926
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(G1bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0535622
summary(G1bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 39 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       105
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              65112.981
##   Degrees of freedom                                423
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression =~
##     DEP_hopelessn      0.570    0.007   83.760    0.000    0.570    0.457
##     DEP_depr_mood      0.387    0.005   73.211    0.000    0.387    0.352
##     DEP_dmn_slfcnf     0.510    0.006   91.509    0.000    0.510    0.431
##     DEP_worthlessn     0.572    0.007   79.057    0.000    0.572    0.420
##     DEP_suicd_ntnt     0.239    0.007   33.875    0.000    0.239    0.207
##     DEP_dimn_ntrst     0.357    0.006   64.779    0.000    0.357    0.296
##     DEP_guilt          0.483    0.007   67.228    0.000    0.483    0.359
##     DEP_crying         0.208    0.008   27.093    0.000    0.208    0.176
##     DEP_decsn_prbl     0.290    0.007   42.288    0.000    0.290    0.220
##     PF_self_rflctn    -0.114    0.007  -17.487    0.000   -0.114   -0.088
##     DEP_rumination     0.250    0.007   34.205    0.000    0.250    0.187
##     DEP_psycmot_gt     0.090    0.007   12.673    0.000    0.090    0.071
##     PF_affect_diff    -0.136    0.006  -21.210    0.000   -0.136   -0.106
##     PF_identity       -0.072    0.005  -14.043    0.000   -0.072   -0.067
##     PF_self_est_rg     0.279    0.006   46.265    0.000    0.279    0.260
##     DEP_reduc_nrgy     0.322    0.005   66.192    0.000    0.322    0.303
##     DEP_concentrtn     0.235    0.006   36.233    0.000    0.235    0.189
##     DT_anhedonia       0.258    0.006   40.199    0.000    0.258    0.211
##   N9_Somatic_Dep =~
##     DEP_psycmt_nhb     0.332    0.006   56.734    0.000    0.332    0.339
##     DEP_reduc_nrgy     0.512    0.005  113.466    0.000    0.512    0.482
##     DEP_hypersomni     0.297    0.007   43.769    0.000    0.297    0.293
##     DEP_crcd_md_fl     0.299    0.008   38.555    0.000    0.299    0.256
##     DEP_concentrtn     0.398    0.006   64.905    0.000    0.398    0.319
##     DEP_loss_apptt     0.155    0.006   28.015    0.000    0.155    0.182
##     DEP_loss_libid     0.315    0.008   38.680    0.000    0.315    0.271
##     DT_anhedonia       0.331    0.006   51.585    0.000    0.331    0.271
##     DEP_depr_mood      0.208    0.005   44.054    0.000    0.208    0.189
##     DEP_dmn_slfcnf     0.328    0.005   65.015    0.000    0.328    0.277
##     DEP_dimn_ntrst     0.477    0.005   92.077    0.000    0.477    0.395
##     DEP_decsn_prbl     0.245    0.006   38.753    0.000    0.245    0.186
##     Somatc_symptms     0.187    0.005   34.901    0.000    0.187    0.201
##     NA_perseveratn     0.114    0.006   18.385    0.000    0.114    0.107
##   N10_Detachment =~
##     DT_intimcy_avd     0.570    0.006   92.180    0.000    0.570    0.557
##     DT_rstr_ffctvt     0.674    0.006  104.860    0.000    0.674    0.565
##     DT_withdrawal      0.572    0.007   82.225    0.000    0.572    0.492
##     DEP_emot_numbn     0.386    0.007   56.583    0.000    0.386    0.311
##     DEP_crying_inb     0.255    0.007   34.388    0.000    0.255    0.202
##     DT_anhedonia       0.370    0.006   59.496    0.000    0.370    0.303
##     DEP_dimn_ntrst     0.148    0.005   32.386    0.000    0.148    0.123
##     PF_ntrn_rlshp_     0.340    0.006   53.859    0.000    0.340    0.289
##     DT_suspicisnss     0.396    0.008   49.006    0.000    0.396    0.289
##   G1 =~
##     DEP_hopelessn      0.840    0.007  118.833    0.000    0.840    0.673
##     DEP_depr_mood      0.837    0.006  142.742    0.000    0.837    0.761
##     DEP_dmn_slfcnf     0.852    0.007  130.248    0.000    0.852    0.719
##     DEP_worthlessn     0.975    0.008  129.715    0.000    0.975    0.716
##     DEP_suicd_ntnt     0.685    0.007  105.097    0.000    0.685    0.595
##     DEP_dimn_ntrst     0.868    0.007  133.249    0.000    0.868    0.720
##     DEP_guilt          0.978    0.007  134.153    0.000    0.978    0.729
##     DEP_crying         0.569    0.007   82.558    0.000    0.569    0.483
##     DEP_decsn_prbl     0.972    0.007  138.643    0.000    0.972    0.737
##     PF_self_rflctn     1.105    0.006  174.785    0.000    1.105    0.857
##     DEP_rumination     1.002    0.007  142.641    0.000    1.002    0.751
##     DEP_psycmot_gt     0.944    0.007  141.515    0.000    0.944    0.743
##     PF_affect_diff     1.120    0.006  178.960    0.000    1.120    0.870
##     PF_identity        0.975    0.005  192.142    0.000    0.975    0.907
##     PF_self_est_rg     0.750    0.006  128.881    0.000    0.750    0.701
##     DEP_reduc_nrgy     0.755    0.006  130.891    0.000    0.755    0.711
##     DEP_concentrtn     0.875    0.007  129.997    0.000    0.875    0.702
##     DT_anhedonia       0.739    0.007  107.282    0.000    0.739    0.605
##     DEP_psycmt_nhb     0.539    0.006   96.690    0.000    0.539    0.551
##     DEP_hypersomni     0.378    0.006   62.433    0.000    0.378    0.373
##     DEP_crcd_md_fl     0.470    0.007   67.729    0.000    0.470    0.403
##     DEP_loss_apptt     0.397    0.005   79.847    0.000    0.397    0.467
##     DEP_loss_libid     0.303    0.007   42.767    0.000    0.303    0.261
##     Somatc_symptms     0.576    0.005  111.682    0.000    0.576    0.620
##     NA_perseveratn     0.661    0.006  112.250    0.000    0.661    0.623
##     DT_intimcy_avd     0.438    0.006   72.474    0.000    0.438    0.428
##     DT_rstr_ffctvt     0.692    0.007  102.810    0.000    0.692    0.580
##     DT_withdrawal      0.542    0.007   79.703    0.000    0.542    0.466
##     DEP_emot_numbn     0.774    0.007  112.533    0.000    0.774    0.624
##     DEP_crying_inb     0.732    0.007  102.678    0.000    0.732    0.579
##     PF_ntrn_rlshp_     0.770    0.006  119.208    0.000    0.770    0.653
##     DT_suspicisnss     0.760    0.008   97.238    0.000    0.760    0.554
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression ~~
##     N9_Somatic_Dep     0.000                               0.000    0.000
##     N10_Detachment     0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N10_Detachment     0.000                               0.000    0.000
##     G1                 0.000                               0.000    0.000
##   N10_Detachment ~~
##     G1                 0.000                               0.000    0.000
##   N2_Depression ~~
##     G1                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .DEP_hopelessn     0.528    0.006   93.444    0.000    0.528    0.339
##    .DEP_depr_mood     0.315    0.003  103.940    0.000    0.315    0.261
##    .DEP_dmn_slfcnf    0.311    0.003   94.388    0.000    0.311    0.221
##    .DEP_worthlessn    0.577    0.006   95.045    0.000    0.577    0.311
##    .DEP_suicd_ntnt    0.801    0.007  113.079    0.000    0.801    0.603
##    .DEP_dimn_ntrst    0.324    0.004   91.629    0.000    0.324    0.223
##    .DEP_guilt         0.613    0.006  101.587    0.000    0.613    0.340
##    .DEP_crying        1.019    0.009  114.585    0.000    1.019    0.735
##    .DEP_decsn_prbl    0.650    0.006  111.457    0.000    0.650    0.374
##    .PF_self_rflctn    0.428    0.005   93.358    0.000    0.428    0.258
##    .DEP_rumination    0.716    0.007  109.968    0.000    0.716    0.401
##    .DEP_psycmot_gt    0.715    0.006  110.767    0.000    0.715    0.443
##    .PF_affect_diff    0.383    0.004   88.132    0.000    0.383    0.231
##    .PF_identity       0.201    0.002   81.415    0.000    0.201    0.173
##    .PF_self_est_rg    0.506    0.005  109.459    0.000    0.506    0.441
##    .DEP_reduc_nrgy    0.191    0.003   70.929    0.000    0.191    0.170
##    .DEP_concentrtn    0.577    0.005  107.218    0.000    0.577    0.371
##    .DT_anhedonia      0.634    0.006  102.726    0.000    0.634    0.425
##    .DEP_psycmt_nhb    0.557    0.005  106.829    0.000    0.557    0.581
##    .DEP_hypersomni    0.795    0.007  111.293    0.000    0.795    0.775
##    .DEP_crcd_md_fl    1.051    0.009  112.479    0.000    1.051    0.772
##    .DEP_loss_apptt    0.542    0.005  114.024    0.000    0.542    0.749
##    .DEP_loss_libid    1.161    0.010  112.505    0.000    1.161    0.859
##    .Somatc_symptms    0.495    0.004  111.780    0.000    0.495    0.575
##    .NA_perseveratn    0.677    0.006  113.338    0.000    0.677    0.600
##    .DT_intimcy_avd    0.531    0.006   89.575    0.000    0.531    0.507
##    .DT_rstr_ffctvt    0.488    0.006   76.492    0.000    0.488    0.344
##    .DT_withdrawal     0.731    0.008   97.286    0.000    0.731    0.541
##    .DEP_emot_numbn    0.790    0.007  107.809    0.000    0.790    0.514
##    .DEP_crying_inb    0.996    0.009  112.723    0.000    0.996    0.624
##    .PF_ntrn_rlshp_    0.682    0.006  108.181    0.000    0.682    0.490
##    .DT_suspicisnss    1.150    0.010  110.346    0.000    1.150    0.610
##     N2_Depression     1.000                               1.000    1.000
##     N9_Somatic_Dep    1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     G1                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$G1 = data.frame(lavInspect(G1bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(G1basemodel, what="std")$lambda)
#
# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_G1 = data.frame(bifloads$G1$G1 - abs(bifloads$G1[,1]) - abs(bifloads$G1[,2]) - abs(bifloads$G1[,3]))
#
# rownames(loadingschange_G1) = rownames(bifloads$G1)
# names(loadingschange_G1) = "std_G_loading_minus_S_loading"
# loadingschange_G1 = loadingschange_G1 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_G1)[1] = "scale"


kable( extractGSmax(bifloads$G1, "G1"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_identity 0.9067871 [.07;N2] 0.8400819
PF_self_reflection 0.8570573 [.09;N2] 0.7687518
PF_affect_diff 0.8702925 [.11;N2] 0.7645688
DEP_psycmot_agit 0.7431777 [.07;N2] 0.6721894
DEP_rumination 0.7507085 [.19;N2] 0.5636323
DEP_decision_probl 0.7370962 [.22;N2] 0.5169557
NA_perseveration 0.6229608 [.11;N9] 0.5158808
PF_self_est_reg 0.7006344 [.26;N2] 0.4402996
Somatic_symptoms 0.6204184 [.2;N9] 0.4191603
DEP_depr_mood 0.7613502 [.35;N2] 0.4092785
DEP_suicid_intent 0.5946612 [.21;N2] 0.3872423
DEP_concentration 0.7016146 [.32;N9] 0.3829578
DEP_crying_inab 0.5793843 [.2;N10] 0.3777706
DEP_guilt 0.7285974 [.36;N2] 0.3691972
PF_intern_relshp_mod 0.6531473 [.29;N10] 0.3645529
DEP_dimin_interest 0.7199269 [.4;N9] 0.3247037
DEP_emot_numbn 0.6241467 [.31;N10] 0.3130970
DEP_crying 0.4833988 [.18;N2] 0.3071444
DT_anhedonia 0.6045930 [.3;N10] 0.3016499
DEP_worthlessn 0.7157791 [.42;N2] 0.2958481
DEP_dimin_selfconf 0.7188089 [.43;N2] 0.2882988
DEP_loss_appetite 0.4669694 [.18;N9] 0.2853016
DT_suspiciousness 0.5536862 [.29;N10] 0.2650109
DEP_reduc_energy 0.7110648 [.48;N9] 0.2286935
DEP_hopelessn 0.6727786 [.46;N2] 0.2159965
DEP_psycmot_inhib 0.5511730 [.34;N9] 0.2121275
DEP_circad_mood_fluct 0.4025708 [.26;N9] 0.1463753
DEP_hypersomnia 0.3734897 [.29;N9] 0.0802859
DT_restr_affectivity 0.5801768 [.57;N10] 0.0148545
DEP_loss_libido 0.2609100 [.27;N9] -0.0096052
DT_withdrawal 0.4662936 [.49;N10] -0.0253380
DT_intimcy_avoid 0.4282746 [.56;N10] -0.1283743

G3: GAD + PF

G3base = "

#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N4
N4_GAD_OCD =~ GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + OCD_sympt + DI_perfectionism + PF_identity + PF_affect_tolrnce + DEP_concentration + DEP_decision_probl + PF_self_reflection
"

G3bifact ="
G3 =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity + GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + OCD_sympt + DI_perfectionism + PF_identity + DEP_concentration + DEP_decision_probl + PF_self_reflection

#orthogonal
N8_PF_Problems  ~~ 0*N4_GAD_OCD

G3  ~~ 0*N8_PF_Problems
G3  ~~ 0*N4_GAD_OCD
"


#G1basemodel <- cfa(model = paste0(G1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
G3bifactmodel = cfa(model = paste0(G3base, G3bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(G3bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0390410
usrmr.se usrmr.se 0.0002981
usrmr.ci.lower usrmr.ci.lower 0.0385507
usrmr.ci.upper usrmr.ci.upper 0.0395313
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.1977298
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(G3bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0569297
summary(G3bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 40 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        82
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              49475.758
##   Degrees of freedom                                269
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems =~
##     PF_anticipatin     0.543    0.007   78.201    0.000    0.543    0.431
##     PF_affect_comm     0.637    0.006  106.094    0.000    0.637    0.527
##     PF_ntrn_rlshp_     0.452    0.006   71.225    0.000    0.452    0.383
##     NA_sep_insecur     0.183    0.007   25.704    0.000    0.183    0.150
##     DT_suspicisnss     0.559    0.008   70.315    0.000    0.559    0.407
##     PF_hlstc_prcpt     0.470    0.006   74.128    0.000    0.470    0.433
##     PF_self_est_rg     0.145    0.006   25.293    0.000    0.145    0.136
##     NA_perseveratn     0.206    0.006   34.352    0.000    0.206    0.194
##     PF_affct_tlrnc     0.138    0.006   23.836    0.000    0.138    0.111
##     PF_impulse_reg     0.476    0.006   75.129    0.000    0.476    0.436
##     DI_impulsivity     0.415    0.006   64.264    0.000    0.415    0.369
##     PF_frmng_rlshp     0.344    0.008   41.264    0.000    0.344    0.261
##     DEP_rumination    -0.055    0.007   -8.466    0.000   -0.055   -0.041
##     PF_affect_diff     0.010    0.005    1.927    0.054    0.010    0.008
##     PS_eccentricty     0.472    0.006   73.933    0.000    0.472    0.390
##     PF_identity        0.051    0.004   11.706    0.000    0.051    0.048
##   N4_GAD_OCD =~
##     GAD_fre_flt_nx     0.807    0.007  119.792    0.000    0.807    0.563
##     GAD_nervousnss     0.796    0.007  110.952    0.000    0.796    0.529
##     GAD_irritablty     0.732    0.008   87.477    0.000    0.732    0.456
##     GAD_excss_wrry     0.613    0.006   98.576    0.000    0.613    0.470
##     DEP_rumination     0.090    0.007   12.283    0.000    0.090    0.067
##     DEP_psycmot_gt     0.065    0.007    9.397    0.000    0.065    0.051
##     PF_affect_diff    -0.052    0.006   -8.336    0.000   -0.052   -0.041
##     OCD_sympt          0.052    0.006    8.665    0.000    0.052    0.051
##     DI_perfectinsm     0.111    0.007   15.249    0.000    0.111    0.095
##     PF_identity       -0.133    0.005  -26.872    0.000   -0.133   -0.124
##     PF_affct_tlrnc    -0.077    0.006  -12.979    0.000   -0.077   -0.062
##     DEP_concentrtn     0.025    0.007    3.519    0.000    0.025    0.020
##     DEP_decsn_prbl     0.012    0.007    1.602    0.109    0.012    0.009
##     PF_self_rflctn    -0.203    0.007  -30.945    0.000   -0.203   -0.158
##   G3 =~
##     PF_anticipatin     0.743    0.007  103.920    0.000    0.743    0.589
##     PF_affect_comm     0.791    0.007  117.757    0.000    0.791    0.654
##     PF_ntrn_rlshp_     0.746    0.007  113.619    0.000    0.746    0.632
##     NA_sep_insecur     0.733    0.007  107.491    0.000    0.733    0.601
##     DT_suspicisnss     0.739    0.008   93.410    0.000    0.739    0.538
##     PF_hlstc_prcpt     0.560    0.006   88.681    0.000    0.560    0.515
##     PF_self_est_rg     0.747    0.006  130.029    0.000    0.747    0.698
##     NA_perseveratn     0.670    0.006  114.116    0.000    0.670    0.631
##     PF_affct_tlrnc     1.000    0.006  160.324    0.000    1.000    0.810
##     PF_impulse_reg     0.571    0.006   90.110    0.000    0.571    0.523
##     DI_impulsivity     0.632    0.006   98.535    0.000    0.632    0.563
##     PF_frmng_rlshp     0.590    0.008   76.117    0.000    0.590    0.448
##     DEP_rumination     1.028    0.007  148.776    0.000    1.028    0.770
##     PF_affect_diff     1.134    0.006  183.300    0.000    1.134    0.881
##     PS_eccentricty     0.784    0.007  117.146    0.000    0.784    0.648
##     PF_identity        0.962    0.005  186.812    0.000    0.962    0.894
##     GAD_fre_flt_nx     1.074    0.008  132.006    0.000    1.074    0.749
##     GAD_nervousnss     1.128    0.008  133.455    0.000    1.128    0.750
##     GAD_irritablty     1.082    0.009  118.071    0.000    1.082    0.674
##     GAD_excss_wrry     1.019    0.007  143.269    0.000    1.019    0.781
##     DEP_psycmot_gt     0.951    0.007  143.302    0.000    0.951    0.749
##     OCD_sympt          0.616    0.006  108.997    0.000    0.616    0.608
##     DI_perfectinsm     0.524    0.007   76.650    0.000    0.524    0.450
##     DEP_concentrtn     0.880    0.007  132.210    0.000    0.880    0.706
##     DEP_decsn_prbl     0.985    0.007  143.010    0.000    0.985    0.747
##     PF_self_rflctn     1.093    0.006  171.245    0.000    1.093    0.848
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##     G3                 0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     G3                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .PF_anticipatin    0.743    0.007  103.284    0.000    0.743    0.467
##    .PF_affect_comm    0.431    0.005   84.638    0.000    0.431    0.295
##    .PF_ntrn_rlshp_    0.631    0.006  105.863    0.000    0.631    0.454
##    .NA_sep_insecur    0.915    0.008  114.269    0.000    0.915    0.616
##    .DT_suspicisnss    1.027    0.010  106.389    0.000    1.027    0.545
##    .PF_hlstc_prcpt    0.646    0.006  104.938    0.000    0.646    0.547
##    .PF_self_est_rg    0.567    0.005  112.918    0.000    0.567    0.495
##    .NA_perseveratn    0.635    0.006  113.423    0.000    0.635    0.563
##    .PF_affct_tlrnc    0.499    0.005  106.704    0.000    0.499    0.327
##    .PF_impulse_reg    0.642    0.006  104.550    0.000    0.642    0.537
##    .DI_impulsivity    0.691    0.006  108.331    0.000    0.691    0.547
##    .PF_frmng_rlshp    1.265    0.011  113.481    0.000    1.265    0.731
##    .DEP_rumination    0.715    0.007  108.514    0.000    0.715    0.401
##    .PF_affect_diff    0.369    0.004   95.486    0.000    0.369    0.223
##    .PS_eccentricty    0.626    0.006  104.780    0.000    0.626    0.428
##    .PF_identity       0.211    0.002   86.022    0.000    0.211    0.182
##    .GAD_fre_flt_nx    0.252    0.004   67.065    0.000    0.252    0.123
##    .GAD_nervousnss    0.358    0.004   81.707    0.000    0.358    0.158
##    .GAD_irritablty    0.869    0.008  105.020    0.000    0.869    0.337
##    .GAD_excss_wrry    0.288    0.003   90.473    0.000    0.288    0.169
##    .DEP_psycmot_gt    0.706    0.006  111.057    0.000    0.706    0.437
##    .OCD_sympt         0.645    0.006  114.132    0.000    0.645    0.628
##    .DI_perfectinsm    1.068    0.009  115.657    0.000    1.068    0.788
##    .DEP_concentrtn    0.781    0.007  111.908    0.000    0.781    0.502
##    .DEP_decsn_prbl    0.768    0.007  110.383    0.000    0.768    0.442
##    .PF_self_rflctn    0.426    0.005   92.499    0.000    0.426    0.256
##     N8_PF_Problems    1.000                               1.000    1.000
##     N4_GAD_OCD        1.000                               1.000    1.000
##     G3                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$G3 = data.frame(lavInspect(G3bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(G1basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_G3 = data.frame(bifloads$G3$G3 - abs(bifloads$G3[,1]) - abs(bifloads$G3[,2]))
#
# rownames(loadingschange_G3) = rownames(bifloads$G3)
# names(loadingschange_G3) = "std_G_loading_minus_S_loading"
# loadingschange_G3 = loadingschange_G3 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_G3)[1] = "scale"


kable(extractGS(bifloads$G3, "G3"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_affect_diff 0.8807546 0.0242455 0.8565091
PF_identity 0.8943570 0.0858823 0.8084747
DEP_decision_probl 0.7471475 0.0087695 0.7383779
PF_affect_tolrnce 0.8103100 0.0869368 0.7233732
DEP_rumination 0.7697086 0.0543498 0.7153588
DEP_psycmot_agit 0.7486145 0.0512719 0.6973426
PF_self_reflection 0.8477976 0.1575152 0.6902824
DEP_concentration 0.7057133 0.0197629 0.6859504
PF_self_est_reg 0.6978667 0.1356036 0.5622631
OCD_sympt 0.6076625 0.0511681 0.5564944
NA_sep_insecur 0.6014307 0.1503796 0.4510511
NA_perseveration 0.6314749 0.1944911 0.4369838
DI_perfectionism 0.4501422 0.0953860 0.3547562
GAD_excess_worry 0.7808644 0.4699242 0.3109402
PS_eccentricity 0.6479157 0.3901721 0.2577437
PF_intern_relshp_mod 0.6322847 0.3829633 0.2493215
GAD_nervousness 0.7497902 0.5288660 0.2209242
GAD_irritability 0.6740572 0.4562503 0.2178069
DI_impulsivity 0.5625135 0.3692044 0.1933091
PF_forming_relshps 0.4481018 0.2614901 0.1866118
GAD_free_float_anx 0.7487362 0.5627111 0.1860251
PF_anticipation 0.5892103 0.4307441 0.1584662
DT_suspiciousness 0.5383685 0.4068538 0.1315148
PF_affect_comm 0.6541132 0.5267731 0.1273401
PF_impulse_reg 0.5225937 0.4358086 0.0867851
PF_holistic_percptn 0.5153726 0.4326441 0.0827285

D1: Distress

D1base = "

#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + PF_self_reflection + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + PF_identity + PF_self_est_reg + DEP_reduc_energy + DEP_concentration + DT_anhedonia

#N9
N9_Somatic_Dep =~ DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms + NA_perseveration

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness


#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N4
N4_GAD_OCD =~ GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + OCD_sympt + DI_perfectionism + PF_identity + PF_affect_tolrnce + DEP_concentration + DEP_decision_probl + PF_self_reflection

"

D1bifact ="
D1 =~   PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + PF_holistic_percptn + PF_self_est_reg  + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity  + PS_eccentricity + DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + PF_affect_diff + DEP_reduc_energy + DEP_psycmot_inhib + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_loss_appetite + DEP_loss_libido + NA_perseveration + DT_intimcy_avoid + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DT_suspiciousness  + GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + OCD_sympt + DI_perfectionism + PF_identity + DEP_concentration + DEP_decision_probl + PF_self_reflection


# Orthogonal


N2_Depression  ~~ 0*N4_GAD_OCD
N2_Depression  ~~ 0*N8_PF_Problems
N2_Depression  ~~ 0*N9_Somatic_Dep
N2_Depression  ~~ 0*N10_Detachment

N4_GAD_OCD  ~~ 0*N8_PF_Problems
N4_GAD_OCD  ~~ 0*N9_Somatic_Dep
N4_GAD_OCD  ~~ 0*N10_Detachment

N8_PF_Problems  ~~ 0*N9_Somatic_Dep
N8_PF_Problems  ~~ 0*N10_Detachment

N9_Somatic_Dep  ~~ 0*N10_Detachment


D1  ~~ 0*N2_Depression
D1  ~~ 0*N4_GAD_OCD
D1  ~~ 0*N8_PF_Problems
D1  ~~ 0*N9_Somatic_Dep
D1  ~~ 0*N10_Detachment

"

#D1basemodel <- cfa(model = paste0(D1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
D1bifactmodel = cfa(model = paste0(D1base, D1bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(D1bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.1720333
usrmr.se usrmr.se 0.0017019
usrmr.ci.lower usrmr.ci.lower 0.1692339
usrmr.ci.upper usrmr.ci.upper 0.1748327
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.5686167
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(D1bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.051364
summary(D1bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 50 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       161
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              138005.381
##   Degrees of freedom                                 967
##   P-value (Chi-square)                             0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression =~
##     DEP_hopelessn      0.694    0.006  109.713    0.000    0.694    0.555
##     DEP_depr_mood      0.468    0.005   95.837    0.000    0.468    0.443
##     DEP_dmn_slfcnf     0.594    0.005  113.438    0.000    0.594    0.530
##     DEP_worthlessn     0.699    0.007  105.034    0.000    0.699    0.513
##     DEP_suicd_ntnt     0.313    0.007   47.367    0.000    0.313    0.272
##     DEP_dimn_ntrst     0.411    0.005   78.968    0.000    0.411    0.386
##     DEP_guilt          0.597    0.007   90.870    0.000    0.597    0.445
##     DEP_crying         0.246    0.007   33.949    0.000    0.246    0.209
##     DEP_decsn_prbl     0.387    0.006   61.476    0.000    0.387    0.305
##     PF_self_rflctn     0.084    0.006   14.462    0.000    0.084    0.065
##     DEP_rumination     0.342    0.006   54.094    0.000    0.342    0.257
##     DEP_psycmot_gt     0.200    0.006   31.790    0.000    0.200    0.157
##     PF_affect_diff    -0.001    0.005   -0.176    0.860   -0.001   -0.001
##     PF_identity        0.076    0.004   17.962    0.000    0.076    0.071
##     PF_self_est_rg     0.372    0.005   70.400    0.000    0.372    0.355
##     DEP_reduc_nrgy     0.380    0.005   82.727    0.000    0.380    0.389
##     DEP_concentrtn     0.311    0.006   51.294    0.000    0.311    0.264
##     DT_anhedonia       0.296    0.006   48.383    0.000    0.296    0.274
##   N9_Somatic_Dep =~
##     DEP_psycmt_nhb     0.383    0.006   67.951    0.000    0.383    0.408
##     DEP_reduc_nrgy     0.540    0.004  124.762    0.000    0.540    0.553
##     DEP_hypersomni     0.333    0.007   51.217    0.000    0.333    0.336
##     DEP_crcd_md_fl     0.330    0.007   44.560    0.000    0.330    0.289
##     DEP_concentrtn     0.432    0.006   73.684    0.000    0.432    0.367
##     DEP_loss_apptt     0.194    0.005   36.463    0.000    0.194    0.232
##     DEP_loss_libid     0.334    0.008   42.814    0.000    0.334    0.291
##     DT_anhedonia       0.326    0.006   53.639    0.000    0.326    0.302
##     DEP_depr_mood      0.225    0.004   50.288    0.000    0.225    0.213
##     DEP_dmn_slfcnf     0.355    0.005   74.322    0.000    0.355    0.317
##     DEP_dimn_ntrst     0.485    0.005   98.273    0.000    0.485    0.456
##     DEP_decsn_prbl     0.273    0.006   45.256    0.000    0.273    0.215
##     Somatc_symptms     0.347    0.006   54.760    0.000    0.347    0.374
##     NA_perseveratn     0.158    0.006   27.646    0.000    0.158    0.155
##   N10_Detachment =~
##     DT_intimcy_avd     0.639    0.006  108.696    0.000    0.639    0.645
##     DT_rstr_ffctvt     0.957    0.007  141.874    0.000    0.957    0.803
##     DT_withdrawal      0.781    0.007  113.443    0.000    0.781    0.672
##     DEP_emot_numbn     0.557    0.006   85.906    0.000    0.557    0.489
##     DEP_crying_inb     0.392    0.007   56.179    0.000    0.392    0.330
##     DT_anhedonia       0.452    0.006   77.711    0.000    0.452    0.418
##     DEP_dimn_ntrst     0.182    0.004   42.741    0.000    0.182    0.171
##     PF_ntrn_rlshp_     0.285    0.006   51.769    0.000    0.285    0.269
##     DT_suspicisnss     0.298    0.007   42.371    0.000    0.298    0.237
##   N8_PF_Problems =~
##     PF_anticipatin     0.584    0.007   85.157    0.000    0.584    0.481
##     PF_affect_comm     0.659    0.006  111.051    0.000    0.659    0.573
##     PF_ntrn_rlshp_     0.364    0.006   60.887    0.000    0.364    0.343
##     NA_sep_insecur     0.200    0.007   28.229    0.000    0.200    0.166
##     DT_suspicisnss     0.448    0.008   58.910    0.000    0.448    0.355
##     PF_hlstc_prcpt     0.449    0.006   71.563    0.000    0.449    0.426
##     PF_self_est_rg     0.204    0.005   39.490    0.000    0.204    0.195
##     NA_perseveratn     0.246    0.006   41.805    0.000    0.246    0.242
##     PF_affct_tlrnc     0.089    0.006   16.224    0.000    0.089    0.073
##     PF_impulse_reg     0.441    0.006   70.568    0.000    0.441    0.416
##     DI_impulsivity     0.379    0.006   59.702    0.000    0.379    0.347
##     PF_frmng_rlshp     0.503    0.009   55.900    0.000    0.503    0.383
##     DEP_rumination    -0.006    0.006   -1.039    0.299   -0.006   -0.005
##     PF_affect_diff    -0.011    0.005   -2.198    0.028   -0.011   -0.009
##     PS_eccentricty     0.445    0.006   71.200    0.000    0.445    0.381
##     PF_identity        0.022    0.004    5.304    0.000    0.022    0.020
##   N4_GAD_OCD =~
##     GAD_fre_flt_nx     0.864    0.006  141.057    0.000    0.864    0.602
##     GAD_nervousnss     0.863    0.007  131.516    0.000    0.863    0.573
##     GAD_irritablty     0.778    0.008   99.153    0.000    0.778    0.485
##     GAD_excss_wrry     0.670    0.006  119.192    0.000    0.670    0.514
##     DEP_rumination     0.169    0.006   28.176    0.000    0.169    0.127
##     DEP_psycmot_gt     0.126    0.006   20.601    0.000    0.126    0.099
##     PF_affect_diff     0.006    0.006    1.134    0.257    0.006    0.005
##     OCD_sympt          0.078    0.006   13.644    0.000    0.078    0.077
##     DI_perfectinsm     0.141    0.007   19.830    0.000    0.141    0.121
##     PF_identity       -0.102    0.004  -24.446    0.000   -0.102   -0.095
##     PF_affct_tlrnc    -0.063    0.005  -11.588    0.000   -0.063   -0.052
##     DEP_concentrtn     0.064    0.005   12.127    0.000    0.064    0.054
##     DEP_decsn_prbl     0.075    0.006   13.405    0.000    0.075    0.059
##     PF_self_rflctn    -0.140    0.006  -24.946    0.000   -0.140   -0.109
##   D1 =~
##     PF_anticipatin     0.644    0.007   93.420    0.000    0.644    0.531
##     PF_affect_comm     0.688    0.006  108.413    0.000    0.688    0.598
##     PF_ntrn_rlshp_     0.557    0.006   94.800    0.000    0.557    0.525
##     NA_sep_insecur     0.697    0.007  103.001    0.000    0.697    0.581
##     PF_hlstc_prcpt     0.504    0.006   82.636    0.000    0.504    0.478
##     PF_self_est_rg     0.667    0.006  114.456    0.000    0.667    0.637
##     PF_affct_tlrnc     1.020    0.006  167.458    0.000    1.020    0.834
##     PF_impulse_reg     0.526    0.006   86.202    0.000    0.526    0.496
##     DI_impulsivity     0.596    0.006   96.103    0.000    0.596    0.546
##     PS_eccentricty     0.737    0.006  115.050    0.000    0.737    0.632
##     DEP_hopelessn      0.745    0.007  104.053    0.000    0.745    0.597
##     DEP_depr_mood      0.730    0.006  126.667    0.000    0.730    0.690
##     DEP_dmn_slfcnf     0.688    0.006  108.750    0.000    0.688    0.613
##     DEP_worthlessn     0.886    0.008  116.191    0.000    0.886    0.651
##     DEP_suicd_ntnt     0.654    0.007   99.571    0.000    0.654    0.568
##     DEP_dimn_ntrst     0.607    0.006  102.617    0.000    0.607    0.570
##     DEP_guilt          0.911    0.007  123.221    0.000    0.911    0.678
##     DEP_crying         0.561    0.007   81.414    0.000    0.561    0.477
##     PF_affect_diff     1.143    0.006  185.096    0.000    1.143    0.887
##     DEP_reduc_nrgy     0.570    0.005  105.282    0.000    0.570    0.584
##     DEP_psycmt_nhb     0.431    0.005   79.323    0.000    0.431    0.459
##     DEP_hypersomni     0.289    0.006   48.361    0.000    0.289    0.291
##     DEP_crcd_md_fl     0.392    0.007   57.488    0.000    0.392    0.344
##     DEP_loss_apptt     0.339    0.005   68.870    0.000    0.339    0.407
##     DEP_loss_libid     0.212    0.007   30.191    0.000    0.212    0.185
##     NA_perseveratn     0.573    0.006   99.551    0.000    0.573    0.563
##     DT_intimcy_avd     0.110    0.005   21.563    0.000    0.110    0.111
##     DEP_emot_numbn     0.465    0.006   76.350    0.000    0.465    0.408
##     DEP_crying_inb     0.513    0.007   76.705    0.000    0.513    0.432
##     DT_anhedonia       0.383    0.006   63.527    0.000    0.383    0.354
##     DT_suspicisnss     0.540    0.007   74.583    0.000    0.540    0.428
##     GAD_fre_flt_nx     1.029    0.008  128.373    0.000    1.029    0.718
##     GAD_nervousnss     1.077    0.008  128.467    0.000    1.077    0.716
##     GAD_irritablty     1.051    0.009  115.832    0.000    1.051    0.655
##     GAD_excss_wrry     0.982    0.007  138.848    0.000    0.982    0.753
##     DEP_rumination     0.974    0.007  137.483    0.000    0.974    0.731
##     DEP_psycmot_gt     0.922    0.007  136.740    0.000    0.922    0.726
##     OCD_sympt          0.621    0.006  109.824    0.000    0.621    0.613
##     DI_perfectinsm     0.516    0.007   75.256    0.000    0.516    0.444
##     PF_identity        0.973    0.005  191.461    0.000    0.973    0.907
##     DEP_concentrtn     0.724    0.007  111.111    0.000    0.724    0.615
##     DEP_decsn_prbl     0.855    0.007  123.812    0.000    0.855    0.674
##     PF_self_rflctn     1.096    0.006  171.981    0.000    1.096    0.850
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##     N8_PF_Problems     0.000                               0.000    0.000
##     N9_Somatic_Dep     0.000                               0.000    0.000
##     N10_Detachment     0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N10_Detachment ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N8_PF_Problems     0.000                               0.000    0.000
##   N10_Detachment ~~
##     N8_PF_Problems     0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N10_Detachment     0.000                               0.000    0.000
##   N2_Depression ~~
##     D1                 0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     D1                 0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     D1                 0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     D1                 0.000                               0.000    0.000
##   N10_Detachment ~~
##     D1                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .DEP_hopelessn     0.523    0.006   92.748    0.000    0.523    0.335
##    .DEP_depr_mood     0.316    0.003  104.377    0.000    0.316    0.282
##    .DEP_dmn_slfcnf    0.306    0.003   94.446    0.000    0.306    0.243
##    .DEP_worthlessn    0.581    0.006   95.327    0.000    0.581    0.313
##    .DEP_suicd_ntnt    0.801    0.007  113.235    0.000    0.801    0.604
##    .DEP_dimn_ntrst    0.329    0.003   94.943    0.000    0.329    0.290
##    .DEP_guilt         0.617    0.006  102.127    0.000    0.617    0.342
##    .DEP_crying        1.011    0.009  114.839    0.000    1.011    0.729
##    .DEP_decsn_prbl    0.646    0.006  111.656    0.000    0.646    0.402
##    .PF_self_rflctn    0.436    0.005   95.782    0.000    0.436    0.262
##    .DEP_rumination    0.679    0.006  110.836    0.000    0.679    0.383
##    .DEP_psycmot_gt    0.705    0.006  112.728    0.000    0.705    0.438
##    .PF_affect_diff    0.353    0.004   90.699    0.000    0.353    0.212
##    .PF_identity       0.188    0.002   81.334    0.000    0.188    0.163
##    .PF_self_est_rg    0.473    0.004  106.415    0.000    0.473    0.431
##    .DEP_reduc_nrgy    0.192    0.003   73.807    0.000    0.192    0.202
##    .DEP_concentrtn    0.573    0.005  107.271    0.000    0.573    0.414
##    .DT_anhedonia      0.626    0.006  104.308    0.000    0.626    0.534
##    .DEP_psycmt_nhb    0.550    0.005  104.909    0.000    0.550    0.623
##    .DEP_hypersomni    0.788    0.007  110.716    0.000    0.788    0.802
##    .DEP_crcd_md_fl    1.040    0.009  112.003    0.000    1.040    0.798
##    .DEP_loss_apptt    0.542    0.005  113.121    0.000    0.542    0.780
##    .DEP_loss_libid    1.164    0.010  112.674    0.000    1.164    0.881
##    .Somatc_symptms    0.742    0.007  109.833    0.000    0.742    0.860
##    .NA_perseveratn    0.623    0.006  111.315    0.000    0.623    0.601
##    .DT_intimcy_avd    0.561    0.006   96.819    0.000    0.561    0.571
##    .DT_rstr_ffctvt    0.505    0.007   67.832    0.000    0.505    0.356
##    .DT_withdrawal     0.741    0.008   93.960    0.000    0.741    0.548
##    .DEP_emot_numbn    0.772    0.007  104.912    0.000    0.772    0.595
##    .DEP_crying_inb    0.993    0.009  111.413    0.000    0.993    0.705
##    .PF_ntrn_rlshp_    0.601    0.006  106.326    0.000    0.601    0.534
##    .DT_suspicisnss    1.009    0.009  108.097    0.000    1.009    0.634
##    .PF_anticipatin    0.718    0.007  100.282    0.000    0.718    0.487
##    .PF_affect_comm    0.415    0.005   80.625    0.000    0.415    0.314
##    .NA_sep_insecur    0.917    0.008  113.869    0.000    0.917    0.635
##    .PF_hlstc_prcpt    0.655    0.006  106.090    0.000    0.655    0.590
##    .PF_affct_tlrnc    0.445    0.004  101.988    0.000    0.445    0.297
##    .PF_impulse_reg    0.652    0.006  106.419    0.000    0.652    0.580
##    .DI_impulsivity    0.693    0.006  109.454    0.000    0.693    0.581
##    .PF_frmng_rlshp    1.478    0.014  109.207    0.000    1.478    0.854
##    .PS_eccentricty    0.620    0.006  105.475    0.000    0.620    0.455
##    .GAD_fre_flt_nx    0.251    0.004   67.308    0.000    0.251    0.122
##    .GAD_nervousnss    0.361    0.004   81.675    0.000    0.361    0.159
##    .GAD_irritablty    0.867    0.008  105.335    0.000    0.867    0.336
##    .GAD_excss_wrry    0.288    0.003   90.071    0.000    0.288    0.169
##    .OCD_sympt         0.635    0.006  113.870    0.000    0.635    0.619
##    .DI_perfectinsm    1.068    0.009  115.617    0.000    1.068    0.788
##     N2_Depression     1.000                               1.000    1.000
##     N9_Somatic_Dep    1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     N8_PF_Problems    1.000                               1.000    1.000
##     N4_GAD_OCD        1.000                               1.000    1.000
##     D1                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$D1 = data.frame(lavInspect(D1bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(D1basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_D1 = data.frame(bifloads$D1$D1 - abs(bifloads$D1[,1]) - abs(bifloads$D1[,2]) - abs(bifloads$D1[,3]))
#
# rownames(loadingschange_D1) = rownames(bifloads$D1)
# names(loadingschange_D1) = "std_G_loading_minus_S_loading"
# loadingschange_D1 = loadingschange_D1 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_D1)[1] = "scale"

kable(extractGSmax(bifloads$D1, "D1"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_affect_diff 0.8874233 [.01;N8] 0.8786027
PF_identity 0.9068643 [.09;N4] 0.8121281
PF_affect_tolrnce 0.8335191 [.07;N8] 0.7604548
PF_self_reflection 0.8496024 [.11;N4] 0.7408188
DEP_psycmot_agit 0.7264274 [.16;N2] 0.5691310
OCD_sympt 0.6127779 [.08;N4] 0.5361186
DEP_rumination 0.7314739 [.26;N2] 0.4745322
NA_sep_insecur 0.5805320 [.17;N8] 0.4143866
DEP_decision_probl 0.6743829 [.31;N2] 0.3690730
DI_perfectionism 0.4438137 [.12;N4] 0.3227677
NA_perseveration 0.5627017 [.24;N8] 0.3209918
DEP_suicid_intent 0.5677118 [.27;N2] 0.2957646
PF_self_est_reg 0.6365641 [.36;N2] 0.2812399
DEP_crying 0.4766765 [.21;N2] 0.2680909
PS_eccentricity 0.6318392 [.38;N8] 0.2506453
DEP_depr_mood 0.6902603 [.44;N2] 0.2474824
DEP_concentration 0.6149031 [.37;N9] 0.2474330
GAD_excess_worry 0.7528746 [.51;N4] 0.2390099
DEP_guilt 0.6783302 [.44;N2] 0.2336539
DI_impulsivity 0.5459059 [.35;N8] 0.1987554
PF_intern_relshp_mod 0.5252044 [.34;N8] 0.1822174
DEP_loss_appetite 0.4069759 [.23;N9] 0.1745862
GAD_irritability 0.6546139 [.48;N4] 0.1698334
GAD_nervousness 0.7156105 [.57;N4] 0.1423402
DEP_worthlessn 0.6505873 [.51;N2] 0.1373287
GAD_free_float_anx 0.7176500 [.6;N4] 0.1152464
DEP_dimin_interest 0.5696783 [.46;N9] 0.1141520
DEP_crying_inab 0.4321730 [.33;N10] 0.1024399
DEP_dimin_selfconf 0.6131877 [.53;N2] 0.0836351
PF_impulse_reg 0.4963185 [.42;N8] 0.0799876
DT_suspiciousness 0.4283396 [.36;N8] 0.0730338
DEP_circad_mood_fluct 0.3435467 [.29;N9] 0.0541464
PF_holistic_percptn 0.4781662 [.43;N8] 0.0523222
DEP_psycmot_inhib 0.4586156 [.41;N9] 0.0507993
PF_anticipation 0.5306983 [.48;N8] 0.0499364
DEP_hopelessn 0.5969180 [.56;N2] 0.0416008
DEP_reduc_energy 0.5840774 [.55;N9] 0.0308802
PF_affect_comm 0.5982722 [.57;N8] 0.0253223
DEP_hypersomnia 0.2910589 [.34;N9] -0.0451555
DT_anhedonia 0.3540820 [.42;N10] -0.0635635
DEP_emot_numbn 0.4077193 [.49;N10] -0.0811731
DEP_loss_libido 0.1845978 [.29;N9] -0.1062397
Somatic_symptoms 0.0000000 [.37;N9] -0.3736257
PF_forming_relshps 0.0000000 [.38;N8] -0.3826380
DT_intimcy_avoid 0.1113072 [.65;N10] -0.5338054
DT_withdrawal 0.0000000 [.67;N10] -0.6720368
DT_restr_affectivity 0.0000000 [.8;N10] -0.8026439

D2: Fear

D2base = "


#N1
N1_Soc_Phob =~ SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + PF_forming_relshps + Spec_phob_avoid + Agoraphobia + DT_restr_affectivity + DT_withdrawal

#N3
N3_Panic =~ Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis

#N12
N12_Spec_Phob =~ Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid

"

D2bifact ="
D2 =~  SAD_soc_inter + SAD_avoidance + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + PF_forming_relshps + Agoraphobia + DT_restr_affectivity + DT_withdrawal  + Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis + Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid

N1_Soc_Phob  ~~ 0*N3_Panic
N1_Soc_Phob  ~~ 0*N12_Spec_Phob
N3_Panic  ~~ 0*N12_Spec_Phob

D2  ~~ 0*N1_Soc_Phob
D2  ~~ 0*N3_Panic
D2  ~~ 0*N12_Spec_Phob
"

#D2basemodel <- cfa(model = paste0(D2base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
D2bifactmodel = cfa(model = paste0(D2base, D2bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(D2bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0420660
usrmr.se usrmr.se 0.0004284
usrmr.ci.lower usrmr.ci.lower 0.0413614
usrmr.ci.upper usrmr.ci.upper 0.0427707
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.2006489
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(D2bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0598877
summary(D2bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 48 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        71
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              60220.537
##   Degrees of freedom                                205
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N1_Soc_Phob =~
##     SAD_soc_inter     0.915    0.008  119.783    0.000    0.915    0.618
##     SAD_avoidance     0.862    0.008  113.623    0.000    0.862    0.576
##     SAD_performing    0.634    0.007   93.976    0.000    0.634    0.523
##     SAD_devaluatin    0.870    0.008  105.313    0.000    0.870    0.541
##     SAD_being_bsrv    0.569    0.008   73.201    0.000    0.569    0.416
##     SAD_eating        0.502    0.007   68.536    0.000    0.502    0.396
##     SAD_ttrctv_prs    0.766    0.009   82.824    0.000    0.766    0.514
##     PF_frmng_rlshp    0.793    0.008   97.161    0.000    0.793    0.603
##     Spec_phob_avod    0.358    0.009   40.374    0.000    0.358    0.234
##     Agoraphobia       0.233    0.007   31.691    0.000    0.233    0.202
##     DT_rstr_ffctvt    0.571    0.008   74.419    0.000    0.571    0.479
##     DT_withdrawal     0.529    0.008   70.055    0.000    0.529    0.455
##   N3_Panic =~
##     Panc_dctr_vsts    0.503    0.004  122.226    0.000    0.503    0.677
##     Panic_attacks     0.900    0.006  144.145    0.000    0.900    0.718
##     Panc_phys_symp    1.023    0.008  128.502    0.000    1.023    0.645
##     Pnc_dysf_thght    0.744    0.006  122.269    0.000    0.744    0.603
##     Panic_fer_rcrr    0.777    0.007  103.877    0.000    0.777    0.530
##     Panic_avod_bhv    0.540    0.008   68.951    0.000    0.540    0.388
##     Somatc_symptms    0.226    0.005   41.596    0.000    0.226    0.244
##     Hypochondriass    0.223    0.008   28.504    0.000    0.223    0.180
##   N12_Spec_Phob =~
##     Spec_phob_fear    0.868    0.011   78.403    0.000    0.868    0.676
##     Spec_phob_nmls    0.499    0.009   53.248    0.000    0.499    0.389
##     Spec_phob_blod    0.369    0.007   49.956    0.000    0.369    0.371
##     SAD_performing    0.014    0.005    2.766    0.006    0.014    0.012
##     Spec_phob_avod    0.271    0.009   31.849    0.000    0.271    0.178
##   D2 =~
##     SAD_soc_inter     0.969    0.009  105.368    0.000    0.969    0.654
##     SAD_avoidance     1.072    0.009  119.628    0.000    1.072    0.716
##     SAD_devaluatin    1.183    0.009  124.556    0.000    1.183    0.735
##     SAD_being_bsrv    0.977    0.008  121.314    0.000    0.977    0.714
##     SAD_eating        0.893    0.007  119.359    0.000    0.893    0.705
##     SAD_ttrctv_prs    0.657    0.010   66.843    0.000    0.657    0.441
##     PF_frmng_rlshp    0.452    0.009   50.433    0.000    0.452    0.344
##     Agoraphobia       0.792    0.007  116.243    0.000    0.792    0.687
##     DT_rstr_ffctvt    0.453    0.008   56.989    0.000    0.453    0.380
##     DT_withdrawal     0.441    0.008   56.946    0.000    0.441    0.379
##     Panc_dctr_vsts    0.275    0.005   56.325    0.000    0.275    0.370
##     Panic_attacks     0.634    0.008   79.736    0.000    0.634    0.507
##     Panc_phys_symp    0.901    0.010   91.543    0.000    0.901    0.568
##     Pnc_dysf_thght    0.772    0.007  103.449    0.000    0.772    0.626
##     Panic_fer_rcrr    0.945    0.009  107.652    0.000    0.945    0.644
##     Panic_avod_bhv    0.847    0.008  100.632    0.000    0.847    0.608
##     Somatc_symptms    0.579    0.006  104.037    0.000    0.579    0.624
##     Hypochondriass    0.609    0.008   78.420    0.000    0.609    0.492
##     Spec_phob_fear    0.848    0.008  112.310    0.000    0.848    0.661
##     Spec_phob_nmls    0.682    0.008   85.956    0.000    0.682    0.532
##     Spec_phob_blod    0.457    0.006   72.451    0.000    0.457    0.459
##     SAD_performing    0.811    0.007  108.628    0.000    0.811    0.669
##     Spec_phob_avod    1.070    0.009  118.607    0.000    1.070    0.701
##
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N1_Soc_Phob ~~
##     N3_Panic          0.000                               0.000    0.000
##     N12_Spec_Phob     0.000                               0.000    0.000
##   N3_Panic ~~
##     N12_Spec_Phob     0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     D2                0.000                               0.000    0.000
##   N3_Panic ~~
##     D2                0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     D2                0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .SAD_soc_inter     0.419    0.005   91.280    0.000    0.419    0.191
##    .SAD_avoidance     0.347    0.004   90.974    0.000    0.347    0.155
##    .SAD_performing    0.411    0.004  104.923    0.000    0.411    0.280
##    .SAD_devaluatin    0.434    0.005   94.686    0.000    0.434    0.167
##    .SAD_being_bsrv    0.594    0.006  106.057    0.000    0.594    0.317
##    .SAD_eating        0.557    0.005  106.954    0.000    0.557    0.347
##    .SAD_ttrctv_prs    1.204    0.011  108.980    0.000    1.204    0.542
##    .PF_frmng_rlshp    0.898    0.009   99.569    0.000    0.898    0.519
##    .Spec_phob_avod    0.985    0.009  107.608    0.000    0.985    0.423
##    .Agoraphobia       0.648    0.006  103.552    0.000    0.648    0.487
##    .DT_rstr_ffctvt    0.889    0.008  110.326    0.000    0.889    0.626
##    .DT_withdrawal     0.878    0.008  111.437    0.000    0.878    0.649
##    .Panc_dctr_vsts    0.223    0.002   95.295    0.000    0.223    0.404
##    .Panic_attacks     0.356    0.004   79.321    0.000    0.356    0.227
##    .Panc_phys_symp    0.659    0.007   92.215    0.000    0.659    0.262
##    .Pnc_dysf_thght    0.373    0.004   93.376    0.000    0.373    0.245
##    .Panic_fer_rcrr    0.656    0.007  100.513    0.000    0.656    0.305
##    .Panic_avod_bhv    0.930    0.009  108.395    0.000    0.930    0.480
##    .Somatc_symptms    0.475    0.004  107.231    0.000    0.475    0.551
##    .Hypochondriass    1.115    0.010  112.068    0.000    1.115    0.726
##    .Spec_phob_fear    0.175    0.017   10.455    0.000    0.175    0.106
##    .Spec_phob_nmls    0.929    0.010   95.663    0.000    0.929    0.566
##    .Spec_phob_blod    0.645    0.006  101.981    0.000    0.645    0.652
##     N1_Soc_Phob       1.000                               1.000    1.000
##     N3_Panic          1.000                               1.000    1.000
##     N12_Spec_Phob     1.000                               1.000    1.000
##     D2                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$D2 = data.frame(lavInspect(D2bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(D2basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_D2 = data.frame(bifloads$D2$D2 - abs(bifloads$D2[,1]) - abs(bifloads$D2[,2]) - abs(bifloads$D2[,3]))
#
# rownames(loadingschange_D2) = rownames(bifloads$D2)
# names(loadingschange_D2) = "std_G_loading_minus_S_loading"
# loadingschange_D2 = loadingschange_D2 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_D2)[1] = "scale"
#
kable(extractGS(bifloads$D2, "D2"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
Spec_phob_avoid 0.7006408 0.2059921 0.4946487
Agoraphobia 0.6871137 0.2017613 0.4853523
SAD_performing 0.6685560 0.2672092 0.4013468
Somatic_symptoms 0.6240408 0.2438683 0.3801725
Hypochondriasis 0.4915516 0.1797305 0.3118211
SAD_eating 0.7046697 0.3957275 0.3089421
SAD_being_observ 0.7140208 0.4156196 0.2984012
Panic_avoid_behv 0.6082160 0.3876159 0.2206001
SAD_devaluation 0.7349786 0.5407100 0.1942686
Spec_phob_animals 0.5320986 0.3889330 0.1431656
SAD_avoidance 0.7163238 0.5760367 0.1402871
Panic_fear_recurr 0.6441685 0.5296456 0.1145229
Spec_phob_blood 0.4589547 0.3709518 0.0880029
SAD_soc_inter 0.6538793 0.6176565 0.0362228
Panic_dysf_thought 0.6258818 0.6029451 0.0229367
Spec_phob_fear 0.6607432 0.6762447 -0.0155015
SAD_attractive_pers 0.4408559 0.5138116 -0.0729557
DT_withdrawal 0.3789786 0.4549954 -0.0760169
Panic_phys_symp 0.5677169 0.6449786 -0.0772616
DT_restr_affectivity 0.3800984 0.4789672 -0.0988688
Panic_attacks 0.5066598 0.7183329 -0.2116731
PF_forming_relshps 0.3437260 0.6027538 -0.2590278
Panic_doctor_visits 0.3699130 0.6773854 -0.3074725

C1: Distress + Fear

C1base = "

#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + PF_self_reflection + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + PF_identity + PF_self_est_reg + DEP_reduc_energy + DEP_concentration + DT_anhedonia

#N9
N9_Somatic_Dep =~ DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms + NA_perseveration

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness


#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N4
N4_GAD_OCD =~ GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + OCD_sympt + DI_perfectionism + PF_identity + PF_affect_tolrnce + DEP_concentration + DEP_decision_probl + PF_self_reflection


#N1
N1_Soc_Phob =~ SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + PF_forming_relshps + Spec_phob_avoid + Agoraphobia + DT_restr_affectivity + DT_withdrawal

#N3
N3_Panic =~ Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis

#N12
N12_Spec_Phob =~ Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid

"

C1bifact ="
C1 =~  PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + PF_holistic_percptn + PF_self_est_reg  + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity  + PS_eccentricity + DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + PF_affect_diff + DEP_reduc_energy + DEP_psycmot_inhib + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_loss_appetite + DEP_loss_libido + NA_perseveration + DT_intimcy_avoid + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DT_suspiciousness  + GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + OCD_sympt + DI_perfectionism + PF_identity + DEP_concentration + DEP_decision_probl + PF_self_reflection + SAD_soc_inter + SAD_avoidance + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + PF_forming_relshps + Agoraphobia + DT_restr_affectivity + DT_withdrawal    + Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis + Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid


# Orthogonal


N1_Soc_Phob  ~~ 0*N2_Depression
N1_Soc_Phob  ~~ 0*N3_Panic
N1_Soc_Phob  ~~ 0*N4_GAD_OCD
N1_Soc_Phob  ~~ 0*N8_PF_Problems
N1_Soc_Phob  ~~ 0*N9_Somatic_Dep
N1_Soc_Phob  ~~ 0*N10_Detachment
N1_Soc_Phob  ~~ 0*N12_Spec_Phob

N2_Depression  ~~ 0*N3_Panic
N2_Depression  ~~ 0*N4_GAD_OCD
N2_Depression  ~~ 0*N8_PF_Problems
N2_Depression  ~~ 0*N9_Somatic_Dep
N2_Depression  ~~ 0*N10_Detachment
N2_Depression  ~~ 0*N12_Spec_Phob

N3_Panic  ~~ 0*N4_GAD_OCD
N3_Panic  ~~ 0*N8_PF_Problems
N3_Panic  ~~ 0*N9_Somatic_Dep
N3_Panic  ~~ 0*N10_Detachment
N3_Panic  ~~ 0*N12_Spec_Phob

N4_GAD_OCD  ~~ 0*N8_PF_Problems
N4_GAD_OCD  ~~ 0*N9_Somatic_Dep
N4_GAD_OCD  ~~ 0*N10_Detachment
N4_GAD_OCD  ~~ 0*N12_Spec_Phob

N8_PF_Problems  ~~ 0*N9_Somatic_Dep
N8_PF_Problems  ~~ 0*N10_Detachment
N8_PF_Problems  ~~ 0*N12_Spec_Phob

N9_Somatic_Dep  ~~ 0*N10_Detachment
N9_Somatic_Dep  ~~ 0*N12_Spec_Phob

N10_Detachment~~ 0*N12_Spec_Phob


C1  ~~ 0*N1_Soc_Phob
C1  ~~ 0*N3_Panic
C1  ~~ 0*N2_Depression
C1  ~~ 0*N12_Spec_Phob
C1  ~~ 0*N4_GAD_OCD
C1  ~~ 0*N8_PF_Problems
C1  ~~ 0*N9_Somatic_Dep
C1  ~~ 0*N10_Detachment

"

#C1basemodel <- cfa(model = paste0(C1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
C1bifactmodel = cfa(model = paste0(C1base, C1bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(C1bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0491758
usrmr.se usrmr.se 0.0003192
usrmr.ci.lower usrmr.ci.lower 0.0486508
usrmr.ci.upper usrmr.ci.upper 0.0497009
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.2412582
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(C1bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0575052
summary(C1bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 51 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       228
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              217036.463
##   Degrees of freedom                                1983
##   P-value (Chi-square)                             0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression =~
##     DEP_hopelessn      0.692    0.006  112.177    0.000    0.692    0.554
##     DEP_depr_mood      0.480    0.005  100.759    0.000    0.480    0.439
##     DEP_dmn_slfcnf     0.587    0.005  113.890    0.000    0.587    0.500
##     DEP_worthlessn     0.684    0.006  106.300    0.000    0.684    0.502
##     DEP_suicd_ntnt     0.305    0.006   47.278    0.000    0.305    0.265
##     DEP_dimn_ntrst     0.421    0.005   81.969    0.000    0.421    0.356
##     DEP_guilt          0.596    0.006   93.725    0.000    0.596    0.444
##     DEP_crying         0.256    0.007   35.876    0.000    0.256    0.217
##     DEP_decsn_prbl     0.389    0.006   63.010    0.000    0.389    0.297
##     PF_self_rflctn     0.107    0.005   19.710    0.000    0.107    0.083
##     DEP_rumination     0.365    0.006   58.881    0.000    0.365    0.274
##     DEP_psycmot_gt     0.221    0.006   35.929    0.000    0.221    0.174
##     PF_affect_diff     0.022    0.005    4.387    0.000    0.022    0.017
##     PF_identity        0.088    0.004   22.345    0.000    0.088    0.082
##     PF_self_est_rg     0.354    0.005   67.994    0.000    0.354    0.330
##     DEP_reduc_nrgy     0.372    0.005   81.738    0.000    0.372    0.355
##     DEP_concentrtn     0.306    0.006   51.094    0.000    0.306    0.247
##     DT_anhedonia       0.310    0.006   51.144    0.000    0.310    0.259
##   N9_Somatic_Dep =~
##     DEP_psycmt_nhb     0.360    0.006   63.075    0.000    0.360    0.368
##     DEP_reduc_nrgy     0.526    0.004  120.293    0.000    0.526    0.501
##     DEP_hypersomni     0.317    0.007   47.895    0.000    0.317    0.312
##     DEP_crcd_md_fl     0.312    0.008   41.415    0.000    0.312    0.267
##     DEP_concentrtn     0.418    0.006   70.314    0.000    0.418    0.337
##     DEP_loss_apptt     0.175    0.005   32.449    0.000    0.175    0.205
##     DEP_loss_libid     0.320    0.008   40.291    0.000    0.320    0.275
##     DT_anhedonia       0.309    0.006   50.314    0.000    0.309    0.258
##     DEP_depr_mood      0.217    0.005   47.513    0.000    0.217    0.198
##     DEP_dmn_slfcnf     0.348    0.005   71.695    0.000    0.348    0.297
##     DEP_dimn_ntrst     0.465    0.005   93.912    0.000    0.465    0.394
##     DEP_decsn_prbl     0.264    0.006   43.151    0.000    0.264    0.201
##     Somatc_symptms     0.193    0.005   40.500    0.000    0.193    0.208
##     NA_perseveratn     0.149    0.006   25.691    0.000    0.149    0.141
##   N10_Detachment =~
##     DT_intimcy_avd     0.517    0.006   82.505    0.000    0.517    0.505
##     DT_rstr_ffctvt     0.633    0.006  100.872    0.000    0.633    0.537
##     DT_withdrawal      0.471    0.007   71.654    0.000    0.471    0.410
##     DEP_emot_numbn     0.533    0.007   77.785    0.000    0.533    0.430
##     DEP_crying_inb     0.371    0.007   50.081    0.000    0.371    0.294
##     DT_anhedonia       0.437    0.006   71.111    0.000    0.437    0.365
##     DEP_dimn_ntrst     0.202    0.005   44.692    0.000    0.202    0.171
##     PF_ntrn_rlshp_     0.226    0.006   38.497    0.000    0.226    0.193
##     DT_suspicisnss     0.231    0.008   30.708    0.000    0.231    0.169
##   N8_PF_Problems =~
##     PF_anticipatin     0.542    0.007   77.521    0.000    0.542    0.430
##     PF_affect_comm     0.590    0.006   97.970    0.000    0.590    0.488
##     PF_ntrn_rlshp_     0.337    0.006   55.158    0.000    0.337    0.288
##     NA_sep_insecur     0.156    0.007   21.629    0.000    0.156    0.128
##     DT_suspicisnss     0.412    0.008   52.843    0.000    0.412    0.302
##     PF_hlstc_prcpt     0.408    0.006   63.954    0.000    0.408    0.376
##     PF_self_est_rg     0.160    0.005   30.261    0.000    0.160    0.150
##     NA_perseveratn     0.212    0.006   35.332    0.000    0.212    0.200
##     PF_affct_tlrnc     0.023    0.006    4.171    0.000    0.023    0.019
##     PF_impulse_reg     0.416    0.006   65.198    0.000    0.416    0.380
##     DI_impulsivity     0.353    0.006   54.667    0.000    0.353    0.315
##     PF_frmng_rlshp     0.232    0.007   31.106    0.000    0.232    0.179
##     DEP_rumination    -0.003    0.006   -0.402    0.687   -0.003   -0.002
##     PF_affect_diff    -0.072    0.005  -13.854    0.000   -0.072   -0.056
##     PS_eccentricty     0.387    0.006   61.339    0.000    0.387    0.320
##     PF_identity       -0.041    0.004  -10.112    0.000   -0.041   -0.038
##   N4_GAD_OCD =~
##     GAD_fre_flt_nx     0.823    0.006  147.458    0.000    0.823    0.574
##     GAD_nervousnss     0.819    0.006  136.504    0.000    0.819    0.544
##     GAD_irritablty     0.724    0.007   97.950    0.000    0.724    0.451
##     GAD_excss_wrry     0.626    0.005  123.583    0.000    0.626    0.480
##     DEP_rumination     0.158    0.006   27.080    0.000    0.158    0.119
##     DEP_psycmot_gt     0.109    0.006   18.509    0.000    0.109    0.086
##     PF_affect_diff    -0.038    0.005   -7.749    0.000   -0.038   -0.030
##     OCD_sympt          0.039    0.005    7.237    0.000    0.039    0.039
##     DI_perfectinsm     0.102    0.007   14.680    0.000    0.102    0.088
##     PF_identity       -0.141    0.004  -37.553    0.000   -0.141   -0.131
##     PF_affct_tlrnc    -0.104    0.005  -20.285    0.000   -0.104   -0.084
##     DEP_concentrtn     0.048    0.005    9.236    0.000    0.048    0.039
##     DEP_decsn_prbl     0.059    0.006   10.761    0.000    0.059    0.045
##     PF_self_rflctn    -0.169    0.005  -32.626    0.000   -0.169   -0.131
##   N1_Soc_Phob =~
##     SAD_soc_inter      1.047    0.006  170.236    0.000    1.047    0.707
##     SAD_avoidance      1.009    0.006  171.536    0.000    1.009    0.674
##     SAD_performing     0.741    0.005  141.053    0.000    0.741    0.616
##     SAD_devaluatin     0.950    0.006  158.530    0.000    0.950    0.590
##     SAD_being_bsrv     0.762    0.006  125.182    0.000    0.762    0.557
##     SAD_eating         0.663    0.006  115.576    0.000    0.663    0.523
##     SAD_ttrctv_prs     0.711    0.008   90.400    0.000    0.711    0.477
##     PF_frmng_rlshp     0.555    0.007   80.672    0.000    0.555    0.427
##     Spec_phob_avod     0.484    0.007   70.224    0.000    0.484    0.325
##     Agoraphobia        0.437    0.006   74.887    0.000    0.437    0.379
##     DT_rstr_ffctvt     0.245    0.005   46.278    0.000    0.245    0.208
##     DT_withdrawal      0.354    0.006   60.102    0.000    0.354    0.309
##   N3_Panic =~
##     Panc_dctr_vsts     0.540    0.004  141.030    0.000    0.540    0.726
##     Panic_attacks      0.880    0.006  155.472    0.000    0.880    0.703
##     Panc_phys_symp     1.119    0.007  154.748    0.000    1.119    0.705
##     Pnc_dysf_thght     0.792    0.005  149.056    0.000    0.792    0.642
##     Panic_fer_rcrr     0.869    0.007  130.658    0.000    0.869    0.592
##     Panic_avod_bhv     0.569    0.007   83.840    0.000    0.569    0.409
##     Somatc_symptms     0.235    0.004   53.963    0.000    0.235    0.253
##     Hypochondriass     0.261    0.007   37.507    0.000    0.261    0.210
##   N12_Spec_Phob =~
##     Spec_phob_fear     0.993    0.008  130.593    0.000    0.993    0.773
##     Spec_phob_nmls     0.720    0.008   92.254    0.000    0.720    0.561
##     Spec_phob_blod     0.509    0.006   82.973    0.000    0.509    0.512
##     SAD_performing     0.061    0.004   13.651    0.000    0.061    0.051
##     Spec_phob_avod     0.434    0.007   60.155    0.000    0.434    0.291
##   C1 =~
##     PF_anticipatin     0.760    0.007  107.426    0.000    0.760    0.603
##     PF_affect_comm     0.829    0.007  126.147    0.000    0.829    0.685
##     PF_ntrn_rlshp_     0.779    0.006  122.155    0.000    0.779    0.665
##     NA_sep_insecur     0.738    0.007  108.635    0.000    0.738    0.605
##     PF_hlstc_prcpt     0.600    0.006   96.870    0.000    0.600    0.552
##     PF_self_est_rg     0.721    0.006  123.722    0.000    0.721    0.673
##     PF_affct_tlrnc     1.029    0.006  167.968    0.000    1.029    0.833
##     PF_impulse_reg     0.612    0.006   98.480    0.000    0.612    0.560
##     DI_impulsivity     0.670    0.006  106.312    0.000    0.670    0.596
##     PS_eccentricty     0.833    0.007  127.603    0.000    0.833    0.688
##     DEP_hopelessn      0.747    0.007  106.008    0.000    0.747    0.598
##     DEP_depr_mood      0.776    0.006  132.645    0.000    0.776    0.710
##     DEP_dmn_slfcnf     0.775    0.006  120.573    0.000    0.775    0.661
##     DEP_worthlessn     0.894    0.007  119.437    0.000    0.894    0.657
##     DEP_suicd_ntnt     0.661    0.007  101.671    0.000    0.661    0.574
##     DEP_dimn_ntrst     0.804    0.006  125.643    0.000    0.804    0.680
##     DEP_guilt          0.910    0.007  124.735    0.000    0.910    0.678
##     DEP_crying         0.557    0.007   81.208    0.000    0.557    0.473
##     PF_affect_diff     1.129    0.006  182.327    0.000    1.129    0.877
##     DEP_reduc_nrgy     0.703    0.006  123.268    0.000    0.703    0.670
##     DEP_psycmt_nhb     0.527    0.006   94.612    0.000    0.527    0.539
##     DEP_hypersomni     0.371    0.006   61.381    0.000    0.371    0.366
##     DEP_crcd_md_fl     0.471    0.007   68.307    0.000    0.471    0.404
##     DEP_loss_apptt     0.391    0.005   78.687    0.000    0.391    0.459
##     DEP_loss_libid     0.287    0.007   40.544    0.000    0.287    0.246
##     NA_perseveratn     0.661    0.006  112.403    0.000    0.661    0.622
##     DT_intimcy_avd     0.432    0.006   71.617    0.000    0.432    0.422
##     DEP_emot_numbn     0.725    0.007  104.330    0.000    0.725    0.585
##     DEP_crying_inb     0.697    0.007   97.313    0.000    0.697    0.552
##     DT_anhedonia       0.675    0.007   99.559    0.000    0.675    0.564
##     DT_suspicisnss     0.794    0.008  103.299    0.000    0.794    0.582
##     GAD_fre_flt_nx     1.062    0.008  138.669    0.000    1.062    0.740
##     GAD_nervousnss     1.111    0.008  138.403    0.000    1.111    0.738
##     GAD_irritablty     1.089    0.009  124.285    0.000    1.089    0.679
##     GAD_excss_wrry     1.012    0.007  148.947    0.000    1.012    0.776
##     DEP_rumination     0.964    0.007  136.533    0.000    0.964    0.724
##     DEP_psycmot_gt     0.913    0.007  135.683    0.000    0.913    0.719
##     OCD_sympt          0.633    0.006  113.085    0.000    0.633    0.625
##     DI_perfectinsm     0.535    0.007   78.832    0.000    0.535    0.460
##     PF_identity        0.968    0.005  189.680    0.000    0.968    0.899
##     DEP_concentrtn     0.832    0.007  123.848    0.000    0.832    0.672
##     DEP_decsn_prbl     0.922    0.007  131.294    0.000    0.922    0.703
##     PF_self_rflctn     1.076    0.006  168.128    0.000    1.076    0.834
##     SAD_soc_inter      0.843    0.008  100.909    0.000    0.843    0.569
##     SAD_avoidance      0.938    0.008  113.663    0.000    0.938    0.627
##     SAD_devaluatin     1.130    0.009  131.486    0.000    1.130    0.702
##     SAD_being_bsrv     0.823    0.008  108.047    0.000    0.823    0.602
##     SAD_eating         0.766    0.007  108.610    0.000    0.766    0.604
##     SAD_ttrctv_prs     0.677    0.009   77.769    0.000    0.677    0.454
##     PF_frmng_rlshp     0.581    0.008   76.336    0.000    0.581    0.447
##     Agoraphobia        0.640    0.007   97.918    0.000    0.640    0.555
##     DT_rstr_ffctvt     0.658    0.007   98.665    0.000    0.658    0.558
##     DT_withdrawal      0.523    0.007   78.022    0.000    0.523    0.456
##     Panc_dctr_vsts     0.222    0.004   49.530    0.000    0.222    0.299
##     Panic_attacks      0.636    0.007   88.288    0.000    0.636    0.508
##     Panc_phys_symp     0.790    0.009   86.308    0.000    0.790    0.498
##     Pnc_dysf_thght     0.729    0.007  105.673    0.000    0.729    0.591
##     Panic_fer_rcrr     0.846    0.008  102.503    0.000    0.846    0.576
##     Panic_avod_bhv     0.828    0.008  106.468    0.000    0.828    0.595
##     Somatc_symptms     0.602    0.005  118.612    0.000    0.602    0.648
##     Hypochondriass     0.601    0.007   83.673    0.000    0.601    0.485
##     Spec_phob_fear     0.643    0.007   86.980    0.000    0.643    0.501
##     Spec_phob_nmls     0.463    0.008   60.584    0.000    0.463    0.361
##     Spec_phob_blod     0.312    0.006   52.160    0.000    0.312    0.314
##     SAD_performing     0.701    0.007  103.767    0.000    0.701    0.582
##     Spec_phob_avod     0.894    0.008  107.463    0.000    0.894    0.599
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N2_Depression ~~
##     N1_Soc_Phob        0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     N3_Panic           0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N1_Soc_Phob        0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N1_Soc_Phob        0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N1_Soc_Phob        0.000                               0.000    0.000
##   N10_Detachment ~~
##     N1_Soc_Phob        0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N2_Depression ~~
##     N3_Panic           0.000                               0.000    0.000
##     N4_GAD_OCD         0.000                               0.000    0.000
##     N8_PF_Problems     0.000                               0.000    0.000
##     N9_Somatic_Dep     0.000                               0.000    0.000
##     N10_Detachment     0.000                               0.000    0.000
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N3_Panic           0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N3_Panic           0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N3_Panic           0.000                               0.000    0.000
##   N10_Detachment ~~
##     N3_Panic           0.000                               0.000    0.000
##   N3_Panic ~~
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N10_Detachment ~~
##     N4_GAD_OCD         0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N8_PF_Problems     0.000                               0.000    0.000
##   N10_Detachment ~~
##     N8_PF_Problems     0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N10_Detachment     0.000                               0.000    0.000
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N10_Detachment ~~
##     N12_Spec_Phob      0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     C1                 0.000                               0.000    0.000
##   N3_Panic ~~
##     C1                 0.000                               0.000    0.000
##   N2_Depression ~~
##     C1                 0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     C1                 0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     C1                 0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     C1                 0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     C1                 0.000                               0.000    0.000
##   N10_Detachment ~~
##     C1                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .DEP_hopelessn     0.524    0.006   92.665    0.000    0.524    0.336
##    .DEP_depr_mood     0.315    0.003  103.666    0.000    0.315    0.264
##    .DEP_dmn_slfcnf    0.308    0.003   94.988    0.000    0.308    0.224
##    .DEP_worthlessn    0.587    0.006   96.248    0.000    0.587    0.316
##    .DEP_suicd_ntnt    0.797    0.007  113.428    0.000    0.797    0.600
##    .DEP_dimn_ntrst    0.315    0.003   92.278    0.000    0.315    0.226
##    .DEP_guilt         0.620    0.006  102.170    0.000    0.620    0.344
##    .DEP_crying        1.011    0.009  114.824    0.000    1.011    0.729
##    .DEP_decsn_prbl    0.646    0.006  111.700    0.000    0.646    0.376
##    .PF_self_rflctn    0.466    0.005  101.806    0.000    0.466    0.280
##    .DEP_rumination    0.687    0.006  110.748    0.000    0.687    0.387
##    .DEP_psycmot_gt    0.717    0.006  113.253    0.000    0.717    0.445
##    .PF_affect_diff    0.374    0.004   94.399    0.000    0.374    0.226
##    .PF_identity       0.193    0.002   83.132    0.000    0.193    0.166
##    .PF_self_est_rg    0.478    0.004  107.851    0.000    0.478    0.416
##    .DEP_reduc_nrgy    0.190    0.003   71.733    0.000    0.190    0.173
##    .DEP_concentrtn    0.571    0.005  107.098    0.000    0.571    0.372
##    .DT_anhedonia      0.596    0.006   99.110    0.000    0.596    0.416
##    .DEP_psycmt_nhb    0.550    0.005  105.337    0.000    0.550    0.574
##    .DEP_hypersomni    0.789    0.007  110.782    0.000    0.789    0.769
##    .DEP_crcd_md_fl    1.042    0.009  112.161    0.000    1.042    0.765
##    .DEP_loss_apptt    0.541    0.005  113.516    0.000    0.541    0.747
##    .DEP_loss_libid    1.168    0.010  112.648    0.000    1.168    0.863
##    .Somatc_symptms    0.407    0.004  110.000    0.000    0.407    0.472
##    .NA_perseveratn    0.624    0.006  111.475    0.000    0.624    0.553
##    .DT_intimcy_avd    0.595    0.006   95.978    0.000    0.595    0.568
##    .DT_rstr_ffctvt    0.494    0.006   79.402    0.000    0.494    0.356
##    .DT_withdrawal     0.696    0.007  101.017    0.000    0.696    0.529
##    .DEP_emot_numbn    0.728    0.007   98.256    0.000    0.728    0.473
##    .DEP_crying_inb    0.972    0.009  109.492    0.000    0.972    0.609
##    .PF_ntrn_rlshp_    0.600    0.006  105.373    0.000    0.600    0.437
##    .DT_suspicisnss    1.008    0.009  107.627    0.000    1.008    0.542
##    .PF_anticipatin    0.719    0.007   98.847    0.000    0.719    0.452
##    .PF_affect_comm    0.428    0.005   81.377    0.000    0.428    0.292
##    .NA_sep_insecur    0.918    0.008  114.172    0.000    0.918    0.618
##    .PF_hlstc_prcpt    0.653    0.006  105.587    0.000    0.653    0.553
##    .PF_affct_tlrnc    0.455    0.004  102.842    0.000    0.455    0.298
##    .PF_impulse_reg    0.647    0.006  105.066    0.000    0.647    0.541
##    .DI_impulsivity    0.689    0.006  108.651    0.000    0.689    0.546
##    .PF_frmng_rlshp    0.989    0.009  110.992    0.000    0.989    0.586
##    .PS_eccentricty    0.620    0.006  105.690    0.000    0.620    0.424
##    .GAD_fre_flt_nx    0.252    0.004   67.165    0.000    0.252    0.122
##    .GAD_nervousnss    0.360    0.004   81.563    0.000    0.360    0.159
##    .GAD_irritablty    0.866    0.008  105.664    0.000    0.866    0.336
##    .GAD_excss_wrry    0.286    0.003   90.422    0.000    0.286    0.168
##    .OCD_sympt         0.625    0.005  114.081    0.000    0.625    0.608
##    .DI_perfectinsm    1.057    0.009  115.678    0.000    1.057    0.781
##    .SAD_soc_inter     0.389    0.004   89.202    0.000    0.389    0.177
##    .SAD_avoidance     0.341    0.004   87.947    0.000    0.341    0.152
##    .SAD_performing    0.404    0.004  103.533    0.000    0.404    0.279
##    .SAD_devaluatin    0.414    0.004   95.373    0.000    0.414    0.160
##    .SAD_being_bsrv    0.612    0.006  107.569    0.000    0.612    0.327
##    .SAD_eating        0.580    0.005  109.312    0.000    0.580    0.361
##    .SAD_ttrctv_prs    1.259    0.011  112.788    0.000    1.259    0.566
##    .Spec_phob_avod    1.004    0.009  109.159    0.000    1.004    0.451
##    .Agoraphobia       0.729    0.006  113.832    0.000    0.729    0.548
##    .Panc_dctr_vsts    0.212    0.002   96.811    0.000    0.212    0.383
##    .Panic_attacks     0.389    0.004   89.071    0.000    0.389    0.248
##    .Panc_phys_symp    0.641    0.007   89.595    0.000    0.641    0.255
##    .Pnc_dysf_thght    0.364    0.004   92.787    0.000    0.364    0.239
##    .Panic_fer_rcrr    0.682    0.007  101.352    0.000    0.682    0.317
##    .Panic_avod_bhv    0.929    0.008  111.221    0.000    0.929    0.479
##    .Hypochondriass    1.107    0.010  115.143    0.000    1.107    0.721
##    .Spec_phob_fear    0.249    0.011   22.569    0.000    0.249    0.151
##    .Spec_phob_nmls    0.911    0.010   92.937    0.000    0.911    0.554
##    .Spec_phob_blod    0.633    0.006  101.500    0.000    0.633    0.640
##     N2_Depression     1.000                               1.000    1.000
##     N9_Somatic_Dep    1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     N8_PF_Problems    1.000                               1.000    1.000
##     N4_GAD_OCD        1.000                               1.000    1.000
##     N1_Soc_Phob       1.000                               1.000    1.000
##     N3_Panic          1.000                               1.000    1.000
##     N12_Spec_Phob     1.000                               1.000    1.000
##     C1                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$C1 = data.frame(lavInspect(C1bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(C1basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_C1 = data.frame(bifloads$C1$C1 - abs(bifloads$C1[,1]) - abs(bifloads$C1[,2]) - abs(bifloads$C1[,3]) - abs(bifloads$C1[,4]) - abs(bifloads$C1[,5]) - abs(bifloads$C1[,6]) - abs(bifloads$C1[,7]) - abs(bifloads$C1[,8]) )
#
# rownames(loadingschange_C1) = rownames(bifloads$C1)
# names(loadingschange_C1) = "std_G_loading_minus_S_loading"
# loadingschange_C1 = loadingschange_C1 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_C1)[1] = "scale"

kable(extractGS(bifloads$C1, "C1"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_affect_diff 0.8773317 0.0343516 0.8429801
PF_identity 0.8992468 0.0835040 0.8157428
PF_affect_tolrnce 0.8331981 0.0512780 0.7819201
PF_self_reflection 0.8343048 0.1069562 0.7273486
DEP_rumination 0.7239010 0.1313503 0.5925508
DEP_psycmot_agit 0.7193257 0.1301100 0.5892158
OCD_sympt 0.6246479 0.0389749 0.5856730
DEP_decision_probl 0.7028229 0.1810625 0.5217604
NA_sep_insecur 0.6050895 0.1276779 0.4774116
DEP_concentration 0.6719667 0.2077033 0.4642633
NA_perseveration 0.6224160 0.1701744 0.4522417
PF_self_est_reg 0.6727053 0.2397426 0.4329627
PF_intern_relshp_mod 0.6653440 0.2405760 0.4247680
Somatic_symptoms 0.6484632 0.2303061 0.4181571
DEP_depr_mood 0.7099425 0.3187860 0.3911566
DEP_dimin_interest 0.6802629 0.3069734 0.3732895
DI_perfectionism 0.4599910 0.0877897 0.3722013
PS_eccentricity 0.6883059 0.3198817 0.3684242
DT_suspiciousness 0.5820089 0.2355388 0.3464702
DEP_suicid_intent 0.5738838 0.2650273 0.3088565
GAD_excess_worry 0.7755949 0.4799814 0.2956135
Spec_phob_avoid 0.5992515 0.3078137 0.2914377
DI_impulsivity 0.5960081 0.3145372 0.2814709
Hypochondriasis 0.4845673 0.2102239 0.2743434
DT_anhedonia 0.5637751 0.2938324 0.2699427
DEP_dimin_selfconf 0.6612594 0.3985691 0.2626903
DEP_crying_inab 0.5518681 0.2939159 0.2579522
DEP_crying 0.4728567 0.2173773 0.2554794
DEP_loss_appetite 0.4588860 0.2052493 0.2536368
SAD_performing 0.5823672 0.3335051 0.2488621
DEP_reduc_energy 0.6704321 0.4282355 0.2421965
DEP_guilt 0.6779905 0.4435870 0.2344036
GAD_irritability 0.6785392 0.4508697 0.2276695
PF_affect_comm 0.6852147 0.4881088 0.1971059
GAD_nervousness 0.7382860 0.5439174 0.1943686
Panic_avoid_behv 0.5946925 0.4090167 0.1856758
DT_restr_affectivity 0.5584746 0.3728413 0.1856334
PF_impulse_reg 0.5601929 0.3804897 0.1797032
PF_holistic_percptn 0.5524188 0.3759825 0.1764363
Agoraphobia 0.5548322 0.3793919 0.1754404
PF_anticipation 0.6027077 0.4300309 0.1726767
DEP_psycmot_inhib 0.5389022 0.3678696 0.1710326
GAD_free_float_anx 0.7404018 0.5738524 0.1665494
DEP_emot_numbn 0.5848492 0.4296287 0.1552205
DEP_worthlessn 0.6566297 0.5024429 0.1541868
PF_forming_relshps 0.4473497 0.3027474 0.1446023
DEP_circad_mood_fluct 0.4038005 0.2673822 0.1364184
SAD_devaluation 0.7016032 0.5898837 0.1117195
DT_withdrawal 0.4555961 0.3594268 0.0961693
SAD_eating 0.6044559 0.5232438 0.0812122
DEP_hypersomnia 0.3658414 0.3124151 0.0534263
SAD_being_observ 0.6019159 0.5571282 0.0447878
DEP_hopelessn 0.5977995 0.5538264 0.0439731
Panic_fear_recurr 0.5764508 0.5922435 -0.0157927
SAD_attractive_pers 0.4542025 0.4769194 -0.0227169
DEP_loss_libido 0.2464860 0.2752614 -0.0287754
SAD_avoidance 0.6270000 0.6742581 -0.0472581
Panic_dysf_thought 0.5911244 0.6416912 -0.0505668
DT_intimcy_avoid 0.4216477 0.5046464 -0.0829987
SAD_soc_inter 0.5690332 0.7065286 -0.1374954
Panic_attacks 0.5079343 0.7029512 -0.1950169
Spec_phob_blood 0.3138637 0.5118179 -0.1979542
Spec_phob_animals 0.3613604 0.5612901 -0.1999296
Panic_phys_symp 0.4980147 0.7052859 -0.2072713
Spec_phob_fear 0.5011746 0.7731322 -0.2719576
Panic_doctor_visits 0.2989427 0.7263221 -0.4273794

H7: Externalizing and Detachment

H7base = "

#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + PF_impulse_reg + DI_impulsivity + DI_irresponsibility + PF_holistic_percptn

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness

#N14
N14_EXT_Dis =~  Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity

"

H7bifact ="
H7 =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity + AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity


#orthogonal
N8_PF_Problems  ~~ 0*N11_EXT_Ant
N8_PF_Problems  ~~ 0*N10_Detachment
N8_PF_Problems  ~~ 0*N14_EXT_Dis
N11_EXT_Ant  ~~ 0*N10_Detachment
N11_EXT_Ant  ~~ 0*N14_EXT_Dis
N10_Detachment  ~~ 0*N14_EXT_Dis

H7  ~~ 0*N8_PF_Problems
H7  ~~ 0*N11_EXT_Ant
H7  ~~ 0*N10_Detachment
H7  ~~ 0*N14_EXT_Dis

"


#G1basemodel <- cfa(model = paste0(G1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
H7bifactmodel = cfa(model = paste0(H7base, H7bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(H7bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0603724
usrmr.se usrmr.se 0.0004744
usrmr.ci.lower usrmr.ci.lower 0.0595920
usrmr.ci.upper usrmr.ci.upper 0.0611528
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.3318132
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(H7bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0474024
summary(H7bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 45 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       112
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              83882.402
##   Degrees of freedom                                518
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems =~
##     PF_anticipatin     0.258    0.007   35.307    0.000    0.258    0.204
##     PF_affect_comm     0.202    0.006   31.759    0.000    0.202    0.167
##     PF_ntrn_rlshp_     0.132    0.007   19.820    0.000    0.132    0.111
##     NA_sep_insecur     0.444    0.007   60.041    0.000    0.444    0.364
##     DT_suspicisnss     0.072    0.008    8.695    0.000    0.072    0.052
##     PF_hlstc_prcpt     0.177    0.006   28.506    0.000    0.177    0.163
##     PF_self_est_rg     0.247    0.006   41.015    0.000    0.247    0.231
##     NA_perseveratn     0.246    0.006   39.359    0.000    0.246    0.232
##     PF_affct_tlrnc     0.767    0.006  124.248    0.000    0.767    0.621
##     PF_impulse_reg     0.284    0.006   48.661    0.000    0.284    0.261
##     DI_impulsivity     0.293    0.006   49.954    0.000    0.293    0.268
##     PF_frmng_rlshp    -0.056    0.008   -6.912    0.000   -0.056   -0.043
##     DEP_rumination     0.503    0.008   66.872    0.000    0.503    0.377
##     PF_affect_diff     0.706    0.006  113.511    0.000    0.706    0.549
##     PS_eccentricty     0.317    0.007   46.947    0.000    0.317    0.262
##     PF_identity        0.529    0.005  105.032    0.000    0.529    0.492
##   N11_EXT_Ant =~
##     AN_callousness     0.298    0.004   76.544    0.000    0.298    0.470
##     AN_hostility       0.405    0.005   73.791    0.000    0.405    0.423
##     AN_deceitflnss     0.504    0.005   92.841    0.000    0.504    0.553
##     AN_manipultvns     0.428    0.005   79.683    0.000    0.428    0.501
##     AN_entitlement     0.352    0.005   70.641    0.000    0.352    0.472
##     AN_grandiosity     0.396    0.007   60.108    0.000    0.396    0.367
##     PF_impulse_reg     0.443    0.006   74.961    0.000    0.443    0.408
##     DI_impulsivity     0.322    0.006   55.455    0.000    0.322    0.295
##     DI_irrspnsblty     0.135    0.005   28.051    0.000    0.135    0.180
##     PF_hlstc_prcpt     0.284    0.006   46.400    0.000    0.284    0.262
##   N10_Detachment =~
##     DT_intimcy_avd     0.085    0.006   13.221    0.000    0.085    0.083
##     DT_rstr_ffctvt    -0.093    0.007  -13.925    0.000   -0.093   -0.078
##     DT_withdrawal     -0.078    0.007  -11.003    0.000   -0.078   -0.067
##     DEP_emot_numbn    -0.463    0.007  -65.734    0.000   -0.463   -0.373
##     DEP_crying_inb    -0.275    0.008  -35.006    0.000   -0.275   -0.218
##     DT_anhedonia      -0.637    0.007  -93.760    0.000   -0.637   -0.519
##     DEP_dimn_ntrst    -0.600    0.007  -91.141    0.000   -0.600   -0.496
##     PF_ntrn_rlshp_     0.274    0.006   44.577    0.000    0.274    0.232
##     DT_suspicisnss     0.381    0.008   48.177    0.000    0.381    0.277
##   N14_EXT_Dis =~
##     Subst_use_drug     0.310    0.004   71.357    0.000    0.310    0.498
##     DI_normviolatn     0.693    0.007   96.775    0.000    0.693    0.690
##     Subst_use_alc      0.260    0.005   49.467    0.000    0.260    0.359
##     DI_risk_taking     0.319    0.005   58.358    0.000    0.319    0.391
##     DI_irrspnsblty     0.159    0.005   32.018    0.000    0.159    0.212
##     Manic_sympt        0.210    0.004   52.257    0.000    0.210    0.354
##     DI_impulsivity     0.245    0.006   41.193    0.000    0.245    0.224
##   H7 =~
##     PF_anticipatin     0.805    0.007  113.318    0.000    0.805    0.638
##     PF_affect_comm     0.914    0.006  142.425    0.000    0.914    0.756
##     PF_ntrn_rlshp_     0.913    0.006  144.674    0.000    0.913    0.772
##     NA_sep_insecur     0.609    0.007   83.628    0.000    0.609    0.499
##     DT_suspicisnss     0.966    0.008  126.546    0.000    0.966    0.702
##     PF_hlstc_prcpt     0.626    0.006  100.329    0.000    0.626    0.578
##     PF_self_est_rg     0.713    0.006  119.576    0.000    0.713    0.666
##     NA_perseveratn     0.639    0.006  105.290    0.000    0.639    0.602
##     PF_affct_tlrnc     0.764    0.007  105.324    0.000    0.764    0.619
##     PF_impulse_reg     0.592    0.006   93.248    0.000    0.592    0.545
##     DI_impulsivity     0.620    0.006   97.748    0.000    0.620    0.567
##     PF_frmng_rlshp     0.773    0.008  102.494    0.000    0.773    0.588
##     DEP_rumination     0.811    0.008  105.378    0.000    0.811    0.607
##     PF_affect_diff     0.883    0.007  121.245    0.000    0.883    0.686
##     PS_eccentricty     0.806    0.007  119.553    0.000    0.806    0.667
##     PF_identity        0.794    0.006  134.533    0.000    0.794    0.738
##     AN_callousness     0.266    0.004   69.708    0.000    0.266    0.419
##     AN_hostility       0.518    0.006   93.532    0.000    0.518    0.542
##     AN_deceitflnss     0.395    0.005   72.374    0.000    0.395    0.433
##     AN_manipultvns     0.301    0.005   57.753    0.000    0.301    0.352
##     AN_entitlement     0.142    0.005   30.525    0.000    0.142    0.191
##     AN_grandiosity     0.515    0.006   80.503    0.000    0.515    0.476
##     DT_intimcy_avd     0.616    0.006  105.743    0.000    0.616    0.601
##     DT_rstr_ffctvt     0.874    0.006  136.981    0.000    0.874    0.733
##     DT_withdrawal      0.726    0.007  110.915    0.000    0.726    0.624
##     DEP_emot_numbn     0.805    0.007  114.953    0.000    0.805    0.649
##     DEP_crying_inb     0.721    0.007   98.809    0.000    0.721    0.570
##     DT_anhedonia       0.817    0.007  116.927    0.000    0.817    0.665
##     DEP_dimn_ntrst     0.827    0.007  121.498    0.000    0.827    0.683
##     Subst_use_drug     0.154    0.004   40.098    0.000    0.154    0.249
##     DI_normviolatn     0.310    0.006   50.303    0.000    0.310    0.309
##     Subst_use_alc      0.003    0.005    0.751    0.453    0.003    0.005
##     DI_risk_taking     0.306    0.005   61.941    0.000    0.306    0.376
##     DI_irrspnsblty     0.306    0.005   67.609    0.000    0.306    0.407
##     Manic_sympt        0.214    0.004   59.287    0.000    0.214    0.361
##
## Covariances:
##                     Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems ~~
##     N11_EXT_Ant        0.000                               0.000    0.000
##     N10_Detachment     0.000                               0.000    0.000
##     N14_EXT_Dis        0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     N10_Detachment     0.000                               0.000    0.000
##     N14_EXT_Dis        0.000                               0.000    0.000
##   N10_Detachment ~~
##     N14_EXT_Dis        0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     H7                 0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     H7                 0.000                               0.000    0.000
##   N10_Detachment ~~
##     H7                 0.000                               0.000    0.000
##   N14_EXT_Dis ~~
##     H7                 0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .PF_anticipatin    0.877    0.008  112.721    0.000    0.877    0.551
##    .PF_affect_comm    0.586    0.005  108.087    0.000    0.586    0.401
##    .PF_ntrn_rlshp_    0.473    0.006   85.180    0.000    0.473    0.338
##    .NA_sep_insecur    0.918    0.008  111.894    0.000    0.918    0.618
##    .DT_suspicisnss    0.809    0.009   86.924    0.000    0.809    0.428
##    .PF_hlstc_prcpt    0.670    0.006  110.832    0.000    0.670    0.571
##    .PF_self_est_rg    0.577    0.005  112.019    0.000    0.577    0.503
##    .NA_perseveratn    0.657    0.006  113.326    0.000    0.657    0.583
##    .PF_affct_tlrnc    0.354    0.005   75.412    0.000    0.354    0.232
##    .PF_impulse_reg    0.553    0.006   99.841    0.000    0.553    0.468
##    .DI_impulsivity    0.562    0.006  101.554    0.000    0.562    0.470
##    .PF_frmng_rlshp    1.130    0.010  109.550    0.000    1.130    0.653
##    .DEP_rumination    0.873    0.008  110.217    0.000    0.873    0.490
##    .PF_affect_diff    0.378    0.004   86.133    0.000    0.378    0.228
##    .PS_eccentricty    0.713    0.006  111.791    0.000    0.713    0.487
##    .PF_identity       0.248    0.003   91.407    0.000    0.248    0.214
##    .AN_callousness    0.243    0.002  101.593    0.000    0.243    0.604
##    .AN_hostility      0.481    0.005  102.027    0.000    0.481    0.527
##    .AN_deceitflnss    0.421    0.005   91.835    0.000    0.421    0.507
##    .AN_manipultvns    0.455    0.005  100.029    0.000    0.455    0.625
##    .AN_entitlement    0.412    0.004  103.755    0.000    0.412    0.741
##    .AN_grandiosity    0.745    0.007  107.567    0.000    0.745    0.639
##    .DI_irrspnsblty    0.426    0.004  111.649    0.000    0.426    0.757
##    .DT_intimcy_avd    0.662    0.006  108.833    0.000    0.662    0.632
##    .DT_rstr_ffctvt    0.649    0.006  106.558    0.000    0.649    0.457
##    .DT_withdrawal     0.819    0.007  111.164    0.000    0.819    0.606
##    .DEP_emot_numbn    0.676    0.007   99.514    0.000    0.676    0.439
##    .DEP_crying_inb    1.002    0.009  111.017    0.000    1.002    0.627
##    .DT_anhedonia      0.436    0.006   68.899    0.000    0.436    0.289
##    .DEP_dimn_ntrst    0.419    0.006   71.496    0.000    0.419    0.287
##    .Subst_use_drug    0.267    0.003   94.901    0.000    0.267    0.690
##    .DI_normviolatn    0.432    0.008   54.381    0.000    0.432    0.429
##    .Subst_use_alc     0.458    0.004  107.844    0.000    0.458    0.871
##    .DI_risk_taking    0.469    0.005  103.755    0.000    0.469    0.706
##    .Manic_sympt       0.263    0.002  106.697    0.000    0.263    0.745
##     N8_PF_Problems    1.000                               1.000    1.000
##     N11_EXT_Ant       1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     N14_EXT_Dis       1.000                               1.000    1.000
##     H7                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$H7 = data.frame(lavInspect(H7bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(G1basemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_H7 = data.frame(bifloads$H7$H7 - abs(bifloads$H7[,1]) - abs(bifloads$H7[,2])- abs(bifloads$H7[,3]) - abs(bifloads$H7[,4]))
#
# rownames(loadingschange_H7) = rownames(bifloads$H7)
# names(loadingschange_H7) = "std_G_loading_minus_S_loading"
# loadingschange_H7 = loadingschange_H7 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_H7)[1] = "scale"

kable(extractGS(bifloads$H7, "H7"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
DT_restr_affectivity 0.7330423 0.0778980 0.6551443
PF_intern_relshp_mod 0.7718884 0.1717021 0.6001863
PF_affect_comm 0.7557376 0.1673191 0.5884185
DT_withdrawal 0.6244150 0.0673549 0.5570601
PF_forming_relshps 0.5876124 0.0427178 0.5448945
DT_suspiciousness 0.7021779 0.1646622 0.5375157
DT_intimcy_avoid 0.6012748 0.0829500 0.5183248
PF_self_est_reg 0.6658926 0.2307812 0.4351114
PF_anticipation 0.6381471 0.2043121 0.4338351
PS_eccentricity 0.6665606 0.2617598 0.4048008
NA_perseveration 0.6023928 0.2320985 0.3702942
PF_holistic_percptn 0.5778727 0.2126796 0.3651931
DEP_crying_inab 0.5702714 0.2176059 0.3526655
DI_impulsivity 0.5671249 0.2619130 0.3052119
DEP_emot_numbn 0.6491629 0.3729556 0.2762073
PF_identity 0.7377132 0.4916531 0.2460601
DEP_rumination 0.6070118 0.3767886 0.2302232
DI_irresponsibility 0.4074743 0.1957378 0.2117365
PF_impulse_reg 0.5449636 0.3346119 0.2103516
DEP_dimin_interest 0.6834223 0.4963644 0.1870578
DT_anhedonia 0.6647186 0.5186030 0.1461156
PF_affect_diff 0.6863212 0.5485835 0.1377377
NA_sep_insecur 0.4994994 0.3642623 0.1352371
AN_hostility 0.5421808 0.4234772 0.1187037
AN_grandiosity 0.4763671 0.3667732 0.1095939
Manic_sympt 0.3605787 0.3538504 0.0067283
PF_affect_tolrnce 0.6185543 0.6207177 -0.0021634
DI_risk_taking 0.3755422 0.3913846 -0.0158424
AN_callousness 0.4188799 0.4700501 -0.0511702
AN_deceitfulness 0.4333812 0.5526953 -0.1193141
AN_manipulativns 0.3522492 0.5013304 -0.1490813
Subst_use_drug 0.2485854 0.4982161 -0.2496307
AN_entitlement 0.1907825 0.4718528 -0.2810703
Subst_use_alc 0.0047338 0.3590443 -0.3543105
DI_normviolation 0.3090129 0.6898582 -0.3808454

D3: EXT-THO-DET

D3base = "

#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + PF_impulse_reg + DI_impulsivity + DI_irresponsibility + PF_holistic_percptn

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness

#N14
N14_EXT_Dis =~  Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity

#N7
N7_Thought_Disorder =~ PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PS_eccentricity + PF_identity + Manic_sympt + PF_affect_tolrnce + DEP_crying_inab + PF_self_reflection + OCD_sympt


"

D3bifact ="
D3 =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity + AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity + PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PF_self_reflection + OCD_sympt


#orthogonal
N8_PF_Problems  ~~ 0*N11_EXT_Ant
N8_PF_Problems  ~~ 0*N10_Detachment
N8_PF_Problems  ~~ 0*N14_EXT_Dis
N8_PF_Problems  ~~ 0*N7_Thought_Disorder
N11_EXT_Ant  ~~ 0*N10_Detachment
N11_EXT_Ant  ~~ 0*N14_EXT_Dis
N11_EXT_Ant  ~~ 0*N7_Thought_Disorder
N10_Detachment  ~~ 0*N14_EXT_Dis
N10_Detachment  ~~ 0*N7_Thought_Disorder
N14_EXT_Dis  ~~ 0*N7_Thought_Disorder

D3  ~~ 0*N8_PF_Problems
D3  ~~ 0*N11_EXT_Ant
D3  ~~ 0*N10_Detachment
D3  ~~ 0*N14_EXT_Dis
D3  ~~ 0*N7_Thought_Disorder

"


#G1basemodel <- cfa(model = paste0(G1base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
D3bifactmodel = cfa(model = paste0(D3base, D3bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(D3bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0623866
usrmr.se usrmr.se 0.0004907
usrmr.ci.lower usrmr.ci.lower 0.0615794
usrmr.ci.upper usrmr.ci.upper 0.0631938
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.3339054
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(D3bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0490027
summary(D3bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 52 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       135
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              102357.494
##   Degrees of freedom                                 726
##   P-value (Chi-square)                             0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems =~
##     PF_anticipatin          0.463    0.007   63.600    0.000    0.463    0.367
##     PF_affect_comm          0.533    0.006   83.391    0.000    0.533    0.440
##     PF_ntrn_rlshp_          0.315    0.007   48.144    0.000    0.315    0.267
##     NA_sep_insecur          0.109    0.008   14.434    0.000    0.109    0.090
##     DT_suspicisnss          0.393    0.008   47.282    0.000    0.393    0.286
##     PF_hlstc_prcpt          0.237    0.006   37.158    0.000    0.237    0.220
##     PF_self_est_rg          0.150    0.006   24.511    0.000    0.150    0.141
##     NA_perseveratn          0.153    0.006   24.084    0.000    0.153    0.144
##     PF_affct_tlrnc         -0.141    0.006  -23.684    0.000   -0.141   -0.114
##     PF_impulse_reg          0.146    0.006   23.993    0.000    0.146    0.134
##     DI_impulsivity          0.103    0.006   16.926    0.000    0.103    0.093
##     PF_frmng_rlshp          0.403    0.009   46.909    0.000    0.403    0.306
##     DEP_rumination         -0.060    0.008   -7.950    0.000   -0.060   -0.045
##     PF_affect_diff         -0.186    0.006  -31.422    0.000   -0.186   -0.144
##     PS_eccentricty          0.260    0.006   42.940    0.000    0.260    0.216
##     PF_identity            -0.149    0.004  -33.296    0.000   -0.149   -0.138
##   N11_EXT_Ant =~
##     AN_callousness          0.354    0.004   90.238    0.000    0.354    0.559
##     AN_hostility            0.450    0.006   81.461    0.000    0.450    0.470
##     AN_deceitflnss          0.494    0.005   93.946    0.000    0.494    0.543
##     AN_manipultvns          0.446    0.005   84.677    0.000    0.446    0.523
##     AN_entitlement          0.351    0.005   71.776    0.000    0.351    0.470
##     AN_grandiosity          0.453    0.007   68.958    0.000    0.453    0.419
##     PF_impulse_reg          0.402    0.006   69.230    0.000    0.402    0.371
##     DI_impulsivity          0.284    0.006   49.574    0.000    0.284    0.258
##     DI_irrspnsblty          0.147    0.005   31.067    0.000    0.147    0.196
##     PF_hlstc_prcpt          0.265    0.006   44.751    0.000    0.265    0.246
##   N10_Detachment =~
##     DT_intimcy_avd          0.301    0.006   46.788    0.000    0.301    0.295
##     DT_rstr_ffctvt          0.468    0.007   71.046    0.000    0.468    0.392
##     DT_withdrawal           0.433    0.007   61.077    0.000    0.433    0.373
##     DEP_emot_numbn          0.590    0.007   88.416    0.000    0.590    0.476
##     DEP_crying_inb          0.382    0.007   51.878    0.000    0.382    0.302
##     DT_anhedonia            0.697    0.007  106.459    0.000    0.697    0.568
##     DEP_dimn_ntrst          0.533    0.006   89.186    0.000    0.533    0.441
##     PF_ntrn_rlshp_          0.078    0.006   13.032    0.000    0.078    0.066
##     DT_suspicisnss          0.057    0.008    7.372    0.000    0.057    0.041
##   N14_EXT_Dis =~
##     Subst_use_drug          0.315    0.004   71.527    0.000    0.315    0.507
##     DI_normviolatn          0.674    0.007   92.464    0.000    0.674    0.671
##     Subst_use_alc           0.267    0.005   50.270    0.000    0.267    0.368
##     DI_risk_taking          0.311    0.006   56.345    0.000    0.311    0.382
##     DI_irrspnsblty          0.154    0.005   30.842    0.000    0.154    0.205
##     Manic_sympt             0.167    0.004   42.925    0.000    0.167    0.285
##     DI_impulsivity          0.247    0.006   40.906    0.000    0.247    0.224
##   N7_Thought_Disorder =~
##     PS_unusul_blfs          0.516    0.004  123.556    0.000    0.516    0.677
##     PS_prcpt_dysrg          0.390    0.005   82.016    0.000    0.390    0.437
##     Psychtc_symptm          0.493    0.004  112.547    0.000    0.493    0.609
##     Dissociation            0.322    0.005   66.060    0.000    0.322    0.333
##     PS_eccentricty          0.346    0.006   61.465    0.000    0.346    0.287
##     PF_identity             0.066    0.004   17.097    0.000    0.066    0.061
##     Manic_sympt             0.153    0.004   42.031    0.000    0.153    0.261
##     PF_affct_tlrnc          0.083    0.005   15.418    0.000    0.083    0.067
##     DEP_crying_inb          0.146    0.007   20.814    0.000    0.146    0.116
##     PF_self_rflctn         -0.021    0.005   -3.975    0.000   -0.021   -0.016
##     OCD_sympt               0.198    0.006   34.637    0.000    0.198    0.195
##   D3 =~
##     PF_anticipatin          0.816    0.007  116.309    0.000    0.816    0.647
##     PF_affect_comm          0.887    0.007  136.288    0.000    0.887    0.733
##     PF_ntrn_rlshp_          0.813    0.006  127.319    0.000    0.813    0.690
##     NA_sep_insecur          0.735    0.007  107.970    0.000    0.735    0.603
##     DT_suspicisnss          0.820    0.008  105.846    0.000    0.820    0.597
##     PF_hlstc_prcpt          0.626    0.006  102.803    0.000    0.626    0.581
##     PF_self_est_rg          0.740    0.006  128.451    0.000    0.740    0.691
##     NA_perseveratn          0.681    0.006  116.548    0.000    0.681    0.642
##     PF_affct_tlrnc          1.022    0.006  165.505    0.000    1.022    0.827
##     PF_impulse_reg          0.646    0.006  106.185    0.000    0.646    0.595
##     DI_impulsivity          0.694    0.006  113.892    0.000    0.694    0.629
##     PF_frmng_rlshp          0.636    0.008   82.524    0.000    0.636    0.483
##     DEP_rumination          0.960    0.007  135.523    0.000    0.960    0.719
##     PF_affect_diff          1.123    0.006  180.093    0.000    1.123    0.872
##     PS_eccentricty          0.851    0.006  131.820    0.000    0.851    0.708
##     PF_identity             0.977    0.005  192.437    0.000    0.977    0.908
##     AN_callousness          0.192    0.004   50.062    0.000    0.192    0.303
##     AN_hostility            0.462    0.006   83.315    0.000    0.462    0.484
##     AN_deceitflnss          0.410    0.005   76.833    0.000    0.410    0.450
##     AN_manipultvns          0.284    0.005   55.408    0.000    0.284    0.333
##     AN_entitlement          0.144    0.005   31.576    0.000    0.144    0.194
##     AN_grandiosity          0.457    0.006   71.750    0.000    0.457    0.423
##     DT_intimcy_avd          0.464    0.006   77.375    0.000    0.464    0.453
##     DT_rstr_ffctvt          0.709    0.007  106.230    0.000    0.709    0.595
##     DT_withdrawal           0.554    0.007   81.963    0.000    0.554    0.477
##     DEP_emot_numbn          0.741    0.007  106.789    0.000    0.741    0.597
##     DEP_crying_inb          0.696    0.007   96.720    0.000    0.696    0.551
##     DT_anhedonia            0.720    0.007  104.419    0.000    0.720    0.586
##     DEP_dimn_ntrst          0.821    0.007  125.641    0.000    0.821    0.679
##     Subst_use_drug          0.159    0.004   41.933    0.000    0.159    0.255
##     DI_normviolatn          0.322    0.006   53.226    0.000    0.322    0.321
##     Subst_use_alc           0.016    0.004    3.643    0.000    0.016    0.023
##     DI_risk_taking          0.307    0.005   63.158    0.000    0.307    0.376
##     DI_irrspnsblty          0.304    0.004   68.417    0.000    0.304    0.405
##     Manic_sympt             0.211    0.004   59.893    0.000    0.211    0.359
##     PS_unusul_blfs          0.374    0.004   83.399    0.000    0.374    0.490
##     PS_prcpt_dysrg          0.530    0.005  105.445    0.000    0.530    0.594
##     Psychtc_symptm          0.426    0.005   90.651    0.000    0.426    0.526
##     Dissociation            0.655    0.005  124.949    0.000    0.655    0.678
##     PF_self_rflctn          1.093    0.006  172.600    0.000    1.093    0.848
##     OCD_sympt               0.607    0.006  107.034    0.000    0.607    0.599
##
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N8_PF_Problems ~~
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N10_Detachment          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N10_Detachment ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N14_EXT_Dis ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     D3                      0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     D3                      0.000                               0.000    0.000
##   N10_Detachment ~~
##     D3                      0.000                               0.000    0.000
##   N14_EXT_Dis ~~
##     D3                      0.000                               0.000    0.000
##   N7_Thought_Disorder ~~
##     D3                      0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .PF_anticipatin    0.711    0.007   98.075    0.000    0.711    0.447
##    .PF_affect_comm    0.392    0.005   73.319    0.000    0.392    0.268
##    .PF_ntrn_rlshp_    0.621    0.006  105.680    0.000    0.621    0.448
##    .NA_sep_insecur    0.934    0.008  113.776    0.000    0.934    0.629
##    .DT_suspicisnss    1.053    0.010  107.426    0.000    1.053    0.559
##    .PF_hlstc_prcpt    0.642    0.006  108.078    0.000    0.642    0.553
##    .PF_self_est_rg    0.576    0.005  111.324    0.000    0.576    0.502
##    .NA_perseveratn    0.640    0.006  112.306    0.000    0.640    0.568
##    .PF_affct_tlrnc    0.457    0.005  101.042    0.000    0.457    0.299
##    .PF_impulse_reg    0.577    0.006  104.470    0.000    0.577    0.490
##    .DI_impulsivity    0.583    0.006  104.967    0.000    0.583    0.479
##    .PF_frmng_rlshp    1.164    0.011  108.344    0.000    1.164    0.672
##    .DEP_rumination    0.859    0.008  110.501    0.000    0.859    0.482
##    .PF_affect_diff    0.362    0.004   87.431    0.000    0.362    0.219
##    .PS_eccentricty    0.535    0.005  102.305    0.000    0.535    0.370
##    .PF_identity       0.178    0.002   77.044    0.000    0.178    0.153
##    .AN_callousness    0.240    0.002   96.144    0.000    0.240    0.596
##    .AN_hostility      0.498    0.005  101.005    0.000    0.498    0.545
##    .AN_deceitflnss    0.418    0.004   94.099    0.000    0.418    0.503
##    .AN_manipultvns    0.448    0.005   99.380    0.000    0.448    0.615
##    .AN_entitlement    0.412    0.004  104.840    0.000    0.412    0.741
##    .AN_grandiosity    0.753    0.007  106.151    0.000    0.753    0.645
##    .DI_irrspnsblty    0.425    0.004  111.630    0.000    0.425    0.756
##    .DT_intimcy_avd    0.742    0.007  111.558    0.000    0.742    0.708
##    .DT_rstr_ffctvt    0.699    0.007  103.645    0.000    0.699    0.492
##    .DT_withdrawal     0.857    0.008  107.599    0.000    0.857    0.634
##    .DEP_emot_numbn    0.641    0.007   93.878    0.000    0.641    0.417
##    .DEP_crying_inb    0.948    0.009  109.646    0.000    0.948    0.592
##    .DT_anhedonia      0.504    0.007   75.997    0.000    0.504    0.334
##    .DEP_dimn_ntrst    0.505    0.005   92.947    0.000    0.505    0.345
##    .Subst_use_drug    0.262    0.003   92.004    0.000    0.262    0.678
##    .DI_normviolatn    0.451    0.008   55.713    0.000    0.451    0.447
##    .Subst_use_alc     0.454    0.004  106.868    0.000    0.454    0.864
##    .DI_risk_taking    0.474    0.005  103.898    0.000    0.474    0.713
##    .Manic_sympt       0.248    0.002  107.069    0.000    0.248    0.721
##    .PS_unusul_blfs    0.175    0.003   63.264    0.000    0.175    0.301
##    .PS_prcpt_dysrg    0.362    0.004  102.814    0.000    0.362    0.456
##    .Psychtc_symptm    0.232    0.003   78.852    0.000    0.232    0.353
##    .Dissociation      0.400    0.004  107.357    0.000    0.400    0.429
##    .PF_self_rflctn    0.467    0.005  103.078    0.000    0.467    0.281
##    .OCD_sympt         0.619    0.005  113.467    0.000    0.619    0.603
##     N8_PF_Problems    1.000                               1.000    1.000
##     N11_EXT_Ant       1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     N14_EXT_Dis       1.000                               1.000    1.000
##     N7_Thght_Dsrdr    1.000                               1.000    1.000
##     D3                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$D3 = data.frame(lavInspect(D3bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(G1basemodel, what="std")$lambda)
#
# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_D3 = data.frame(bifloads$D3$D3 - abs(bifloads$D3[,1]) - abs(bifloads$D3[,2])- abs(bifloads$D3[,3]) - abs(bifloads$D3[,4]) - abs(bifloads$D3[,5]))
#
# rownames(loadingschange_D3) = rownames(bifloads$D3)
# names(loadingschange_D3) = "std_G_loading_minus_S_loading"
# loadingschange_D3 = loadingschange_D3 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_D3)[1] = "scale"

kable(extractGS(bifloads$D3, "D3"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_self_reflection 0.8476303 0.0164417 0.8311885
PF_identity 0.9076665 0.0997995 0.8078671
PF_affect_tolrnce 0.8266385 0.0904646 0.7361740
PF_affect_diff 0.8721897 0.1441538 0.7280359
DEP_rumination 0.7185496 0.0448771 0.6736725
PF_self_est_reg 0.6913835 0.1405064 0.5508771
PF_intern_relshp_mod 0.6903089 0.1666987 0.5236102
NA_sep_insecur 0.6027749 0.0896423 0.5131326
NA_perseveration 0.6415037 0.1443909 0.4971128
PS_eccentricity 0.7076187 0.2517263 0.4558924
DI_impulsivity 0.6292934 0.1915046 0.4377888
DT_suspiciousness 0.5974124 0.1638300 0.4335824
OCD_sympt 0.5988738 0.1954858 0.4033880
PF_holistic_percptn 0.5811208 0.2331438 0.3479770
Dissociation 0.6780439 0.3331265 0.3449173
PF_impulse_reg 0.5951861 0.2525494 0.3426367
DEP_crying_inab 0.5505571 0.2089177 0.3416394
PF_affect_comm 0.7333680 0.4404546 0.2929134
PF_anticipation 0.6468334 0.3671316 0.2797017
DEP_dimin_interest 0.6789392 0.4405010 0.2384382
DI_irresponsibility 0.4051653 0.2003136 0.2048517
DT_restr_affectivity 0.5946547 0.3924799 0.2021748
PF_forming_relshps 0.4834249 0.3063209 0.1771040
DT_intimcy_avoid 0.4530468 0.2945127 0.1585341
PS_percept_dysreg 0.5940710 0.4369915 0.1570795
DEP_emot_numbn 0.5972543 0.4758330 0.1214213
DT_withdrawal 0.4768503 0.3727506 0.1040997
Manic_sympt 0.3590510 0.2732914 0.0857596
DT_anhedonia 0.5864535 0.5676673 0.0187862
AN_hostility 0.4835388 0.4702991 0.0132397
AN_grandiosity 0.4230871 0.4193922 0.0036949
DI_risk_taking 0.3762569 0.3815712 -0.0053144
Psychotic_symptoms 0.5258895 0.6086139 -0.0827244
AN_deceitfulness 0.4500375 0.5425578 -0.0925202
PS_unusual_beliefs 0.4902771 0.6771158 -0.1868387
AN_manipulativns 0.3330449 0.5231706 -0.1901257
Subst_use_drug 0.2551078 0.5065502 -0.2514423
AN_callousness 0.3025269 0.5588905 -0.2563636
AN_entitlement 0.1935904 0.4701908 -0.2766004
Subst_use_alc 0.0225403 0.3680813 -0.3455411
DI_normviolation 0.3205487 0.6712687 -0.3507199

B2: Eeating Disorder

B2base = "

#N13
N13_EAT_thoughts =~  EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + EATA_exces_exercise + EATB_soc_disguised

#N6
N6_EAT_purging =~ EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg

#N5
N5_EAT_restr =~ EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg


"

B2bifact ="
B2 =~  EATA_body_selfest + EATB_worries + EATA_fear_weightl +  EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised  + EATA_fear_weightg + EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise

N13_EAT_thoughts  ~~ 0*N6_EAT_purging
N13_EAT_thoughts  ~~ 0*N5_EAT_restr
N6_EAT_purging  ~~ 0*N5_EAT_restr

B2  ~~ 0*N13_EAT_thoughts
B2  ~~ 0*N6_EAT_purging
B2  ~~ 0*N5_EAT_restr
"

#B2basemodel <- cfa(model = paste0(B2base), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
B2bifactmodel = cfa(model = paste0(B2base, B2bifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(B2bifactmodel)
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0289521
usrmr.se usrmr.se 0.0005679
usrmr.ci.lower usrmr.ci.lower 0.0280179
usrmr.ci.upper usrmr.ci.upper 0.0298863
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.1244133
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(B2bifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0725022
summary(B2bifactmodel, std=T)
## lavaan 0.6.16 ended normally after 58 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        57
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              12208.246
##   Degrees of freedom                                 79
##   P-value (Chi-square)                            0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N13_EAT_thoughts =~
##     EATA_bdy_slfst       0.909    0.007  136.171    0.000    0.909    0.609
##     EATB_worries         0.821    0.006  141.371    0.000    0.821    0.591
##     EATA_fer_wghtg       0.825    0.007  126.033    0.000    0.825    0.538
##     EATA_fer_wghtl       0.275    0.006   42.393    0.000    0.275    0.267
##     EATA_excs_xrcs      -0.020    0.005   -4.181    0.000   -0.020   -0.024
##     EATB_soc_dsgsd       0.415    0.006   74.898    0.000    0.415    0.311
##   N6_EAT_purging =~
##     EATB_loss_ctrl       1.298    0.006  207.706    0.000    1.298    0.884
##     EATB_cope_ngff       1.277    0.007  181.937    0.000    1.277    0.838
##     EATB_overeatng       1.370    0.007  190.426    0.000    1.370    0.852
##     EATB_ntrs_thgh       0.660    0.005  125.966    0.000    0.660    0.614
##     DEP_incr_apptt       0.537    0.006   94.346    0.000    0.537    0.514
##     EATB_soc_dsgsd       0.562    0.006   96.317    0.000    0.562    0.422
##     EATA_bdy_slfst       0.404    0.007   55.248    0.000    0.404    0.270
##     EATB_worries         0.440    0.007   67.289    0.000    0.440    0.317
##     EATA_fer_wghtg       0.489    0.007   68.283    0.000    0.489    0.319
##   N5_EAT_restr =~
##     EATA_restrictd       0.613    0.012   52.719    0.000    0.613    0.487
##     EATA_omit_meal       0.326    0.009   35.434    0.000    0.326    0.350
##     EATA_time_frms       0.309    0.009   35.907    0.000    0.309    0.339
##     EATA_cont_clrs       0.199    0.009   23.206    0.000    0.199    0.220
##     EATA_prgng_bhv      -0.160    0.006  -28.942    0.000   -0.160   -0.284
##     EATA_excs_xrcs      -0.338    0.009  -39.595    0.000   -0.338   -0.409
##     EATB_soc_dsgsd      -0.035    0.009   -3.979    0.000   -0.035   -0.026
##     EATA_bdy_slfst      -0.080    0.011   -7.445    0.000   -0.080   -0.053
##     EATB_worries         0.003    0.010    0.323    0.747    0.003    0.002
##     EATA_fer_wghtg      -0.067    0.011   -6.215    0.000   -0.067   -0.044
##   B2 =~
##     EATA_bdy_slfst       0.880    0.009  101.369    0.000    0.880    0.589
##     EATB_worries         0.855    0.008  107.914    0.000    0.855    0.616
##     EATA_fer_wghtl       0.323    0.006   51.666    0.000    0.323    0.314
##     EATB_loss_ctrl       0.550    0.009   62.491    0.000    0.550    0.374
##     EATB_cope_ngff       0.471    0.009   50.952    0.000    0.471    0.309
##     EATB_overeatng       0.546    0.010   56.331    0.000    0.546    0.340
##     EATB_ntrs_thgh       0.485    0.006   76.709    0.000    0.485    0.451
##     DEP_incr_apptt       0.344    0.006   54.511    0.000    0.344    0.329
##     EATB_soc_dsgsd       0.878    0.007  119.348    0.000    0.878    0.659
##     EATA_fer_wghtg       0.962    0.009  110.327    0.000    0.962    0.627
##     EATA_restrictd       1.005    0.009  109.903    0.000    1.005    0.798
##     EATA_omit_meal       0.824    0.006  146.090    0.000    0.824    0.886
##     EATA_time_frms       0.742    0.006  131.502    0.000    0.742    0.814
##     EATA_cont_clrs       0.731    0.005  144.851    0.000    0.731    0.807
##     EATA_prgng_bhv       0.446    0.003  130.226    0.000    0.446    0.793
##     EATA_excs_xrcs       0.674    0.006  119.131    0.000    0.674    0.814
##
## Covariances:
##                       Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N13_EAT_thoughts ~~
##     N6_EAT_purging       0.000                               0.000    0.000
##     N5_EAT_restr         0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     N5_EAT_restr         0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     B2                   0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     B2                   0.000                               0.000    0.000
##   N5_EAT_restr ~~
##     B2                   0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .EATA_bdy_slfst    0.459    0.006   75.618    0.000    0.459    0.206
##    .EATB_worries      0.330    0.005   70.504    0.000    0.330    0.171
##    .EATA_fer_wghtg    0.501    0.006   86.287    0.000    0.501    0.213
##    .EATA_fer_wghtl    0.882    0.008  114.578    0.000    0.882    0.830
##    .EATA_excs_xrcs    0.116    0.005   25.412    0.000    0.116    0.169
##    .EATB_soc_dsgsd    0.516    0.005  107.239    0.000    0.516    0.291
##    .EATB_loss_ctrl    0.170    0.003   54.138    0.000    0.170    0.079
##    .EATB_cope_ngff    0.470    0.005   93.764    0.000    0.470    0.202
##    .EATB_overeatng    0.409    0.005   85.274    0.000    0.409    0.158
##    .EATB_ntrs_thgh    0.484    0.004  110.774    0.000    0.484    0.419
##    .DEP_incr_apptt    0.687    0.006  113.994    0.000    0.687    0.628
##    .EATA_restrictd    0.200    0.003   64.217    0.000    0.200    0.126
##    .EATA_omit_meal    0.080    0.001   64.430    0.000    0.080    0.093
##    .EATA_time_frms    0.185    0.002   98.639    0.000    0.185    0.223
##    .EATA_cont_clrs    0.247    0.002  106.347    0.000    0.247    0.300
##    .EATA_prgng_bhv    0.092    0.002   58.318    0.000    0.092    0.291
##     N13_EAT_thghts    1.000                               1.000    1.000
##     N6_EAT_purging    1.000                               1.000    1.000
##     N5_EAT_restr      1.000                               1.000    1.000
##     B2                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$B2 = data.frame(lavInspect(B2bifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(B2basemodel, what="std")$lambda)
#
# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_B2 = data.frame(bifloads$B2$B2 - abs(bifloads$B2[,1]) - abs(bifloads$B2[,2]) - abs(bifloads$B2[,3]))
#
# rownames(loadingschange_B2) = rownames(bifloads$B2)
# names(loadingschange_B2) = "std_G_loading_minus_S_loading"
# loadingschange_B2 = loadingschange_B2 %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_B2)[1] = "scale"

kable(extractGS(bifloads$B2, "B2"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
EATA_exces_exercise 0.8142906 0.2165690 0.5977216
EATA_count_calories 0.8068954 0.2201207 0.5867747
EATA_omit_meal 0.8858559 0.3499764 0.5358795
EATA_purging_behv 0.7929947 0.2835470 0.5094477
EATA_time_frames 0.8140213 0.3388760 0.4751453
EATB_soc_disguised 0.6587277 0.2529928 0.4057349
EATA_fear_weightg 0.6273154 0.3002503 0.3270651
EATB_worries 0.6156541 0.3033943 0.3122598
EATA_restricted 0.7980256 0.4867282 0.3112974
EATA_body_selfest 0.5892376 0.3108827 0.2783548
EATA_fear_weightl 0.3137768 0.2670959 0.0466809
EATB_intrus_thoughts 0.4510917 0.6143477 -0.1632560
DEP_incr_appetite 0.3290726 0.5135475 -0.1844749
EATB_loss_ctrl 0.3742908 0.8838846 -0.5095938
EATB_overeating 0.3396508 0.8522766 -0.5126259
EATB_cope_negaff 0.3088681 0.8380341 -0.5291661

General Psychopathology

GPbase= "

#N9
N9_Somatic_Dep =~ DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms + NA_perseveration


#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + PF_self_reflection + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + PF_identity + PF_self_est_reg + DEP_reduc_energy + DEP_concentration + DT_anhedonia

#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity

#N4
N4_GAD_OCD =~ GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit + PF_affect_diff + OCD_sympt + DI_perfectionism + PF_identity + PF_affect_tolrnce + DEP_concentration + DEP_decision_probl + PF_self_reflection

#N1
N1_Soc_Phob =~ SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + PF_forming_relshps + Spec_phob_avoid + Agoraphobia + DT_restr_affectivity + DT_withdrawal

#N3
N3_Panic =~ Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis

#N12
N12_Spec_Phob =~ Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid

#N13
N13_EAT_thoughts =~  EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + EATA_exces_exercise + EATB_soc_disguised

#N6
N6_EAT_purging =~ EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg

#N5
N5_EAT_restr =~ EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg

#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + PF_intern_relshp_mod + DT_suspiciousness

#N7
N7_Thought_Disorder =~ PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PS_eccentricity + PF_identity + Manic_sympt + PF_affect_tolrnce + DEP_crying_inab + PF_self_reflection + OCD_sympt

#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity + PF_impulse_reg + DI_impulsivity + DI_irresponsibility + PF_holistic_percptn


#N14
N14_EXT_Dis =~  Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity

"

GPbifact = "
# Orthogonal
N5_EAT_restr ~~ 0*N1_Soc_Phob
N5_EAT_restr ~~ 0*N2_Depression
N5_EAT_restr ~~ 0*N3_Panic
N5_EAT_restr ~~ 0*N4_GAD_OCD
N5_EAT_restr ~~ 0*N6_EAT_purging
N5_EAT_restr ~~ 0*N7_Thought_Disorder
N5_EAT_restr ~~ 0*N8_PF_Problems
N5_EAT_restr ~~ 0*N9_Somatic_Dep
N5_EAT_restr ~~ 0*N10_Detachment
N5_EAT_restr ~~ 0*N11_EXT_Ant
N5_EAT_restr ~~ 0*N12_Spec_Phob
N5_EAT_restr ~~ 0*N13_EAT_thoughts
N5_EAT_restr ~~ 0*N14_EXT_Dis

N1_Soc_Phob  ~~ 0*N2_Depression
N1_Soc_Phob  ~~ 0*N3_Panic
N1_Soc_Phob  ~~ 0*N4_GAD_OCD
N1_Soc_Phob  ~~ 0*N6_EAT_purging
N1_Soc_Phob  ~~ 0*N7_Thought_Disorder
N1_Soc_Phob  ~~ 0*N8_PF_Problems
N1_Soc_Phob  ~~ 0*N9_Somatic_Dep
N1_Soc_Phob  ~~ 0*N10_Detachment
N1_Soc_Phob  ~~ 0*N11_EXT_Ant
N1_Soc_Phob  ~~ 0*N12_Spec_Phob
N1_Soc_Phob  ~~ 0*N13_EAT_thoughts
N1_Soc_Phob  ~~ 0*N14_EXT_Dis

N2_Depression  ~~ 0*N3_Panic
N2_Depression  ~~ 0*N4_GAD_OCD
N2_Depression  ~~ 0*N6_EAT_purging
N2_Depression  ~~ 0*N7_Thought_Disorder
N2_Depression  ~~ 0*N8_PF_Problems
N2_Depression  ~~ 0*N9_Somatic_Dep
N2_Depression  ~~ 0*N10_Detachment
N2_Depression  ~~ 0*N11_EXT_Ant
N2_Depression  ~~ 0*N12_Spec_Phob
N2_Depression  ~~ 0*N13_EAT_thoughts
N2_Depression  ~~ 0*N14_EXT_Dis

N3_Panic  ~~ 0*N4_GAD_OCD
N3_Panic  ~~ 0*N6_EAT_purging
N3_Panic  ~~ 0*N7_Thought_Disorder
N3_Panic  ~~ 0*N8_PF_Problems
N3_Panic  ~~ 0*N9_Somatic_Dep
N3_Panic  ~~ 0*N10_Detachment
N3_Panic  ~~ 0*N11_EXT_Ant
N3_Panic  ~~ 0*N12_Spec_Phob
N3_Panic  ~~ 0*N13_EAT_thoughts
N3_Panic  ~~ 0*N14_EXT_Dis

N4_GAD_OCD  ~~ 0*N6_EAT_purging
N4_GAD_OCD  ~~ 0*N7_Thought_Disorder
N4_GAD_OCD  ~~ 0*N8_PF_Problems
N4_GAD_OCD  ~~ 0*N9_Somatic_Dep
N4_GAD_OCD  ~~ 0*N10_Detachment
N4_GAD_OCD  ~~ 0*N11_EXT_Ant
N4_GAD_OCD  ~~ 0*N12_Spec_Phob
N4_GAD_OCD  ~~ 0*N13_EAT_thoughts
N4_GAD_OCD  ~~ 0*N14_EXT_Dis

N6_EAT_purging~~ 0*N7_Thought_Disorder
N6_EAT_purging~~ 0*N8_PF_Problems
N6_EAT_purging~~ 0*N9_Somatic_Dep
N6_EAT_purging~~ 0*N10_Detachment
N6_EAT_purging~~ 0*N11_EXT_Ant
N6_EAT_purging~~ 0*N12_Spec_Phob
N6_EAT_purging~~ 0*N13_EAT_thoughts
N6_EAT_purging~~ 0*N14_EXT_Dis

N7_Thought_Disorder ~~ 0*N8_PF_Problems
N7_Thought_Disorder ~~ 0*N9_Somatic_Dep
N7_Thought_Disorder ~~ 0*N10_Detachment
N7_Thought_Disorder ~~ 0*N11_EXT_Ant
N7_Thought_Disorder ~~ 0*N12_Spec_Phob
N7_Thought_Disorder ~~ 0*N13_EAT_thoughts
N7_Thought_Disorder ~~ 0*N14_EXT_Dis

N8_PF_Problems  ~~ 0*N9_Somatic_Dep
N8_PF_Problems  ~~ 0*N10_Detachment
N8_PF_Problems  ~~ 0*N11_EXT_Ant
N8_PF_Problems  ~~ 0*N12_Spec_Phob
N8_PF_Problems  ~~ 0*N13_EAT_thoughts
N8_PF_Problems  ~~ 0*N14_EXT_Dis

N9_Somatic_Dep  ~~ 0*N10_Detachment
N9_Somatic_Dep  ~~ 0*N11_EXT_Ant
N9_Somatic_Dep  ~~ 0*N12_Spec_Phob
N9_Somatic_Dep  ~~ 0*N13_EAT_thoughts
N9_Somatic_Dep  ~~ 0*N14_EXT_Dis

N10_Detachment~~ 0*N11_EXT_Ant
N10_Detachment~~ 0*N12_Spec_Phob
N10_Detachment~~ 0*N13_EAT_thoughts
N10_Detachment~~ 0*N14_EXT_Dis

N11_EXT_Ant ~~ 0*N12_Spec_Phob
N11_EXT_Ant ~~ 0*N13_EAT_thoughts
N11_EXT_Ant ~~ 0*N14_EXT_Dis

N12_Spec_Phob ~~ 0*N13_EAT_thoughts
N12_Spec_Phob ~~ 0*N14_EXT_Dis

N13_EAT_thoughts ~~ 0*N14_EXT_Dis


GP =~  PF_affect_comm + PF_affect_diff + PF_affect_tolrnce +  PF_forming_relshps + PF_holistic_percptn + PF_identity + PF_impulse_reg +PF_intern_relshp_mod + PF_self_reflection + PF_self_est_reg + PF_anticipation +
SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers  + Spec_phob_avoid + Agoraphobia + DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl  + Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis + GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit  + OCD_sympt + DI_perfectionism + EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PS_eccentricity  + Manic_sympt    + NA_sep_insecur + DT_suspiciousness   + NA_perseveration  + DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity  + DI_impulsivity + Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility

GP ~~ 0*N5_EAT_restr
GP ~~ 0*N1_Soc_Phob
GP ~~ 0*N2_Depression
GP ~~ 0*N3_Panic
GP ~~ 0*N4_GAD_OCD
GP ~~ 0*N6_EAT_purging
GP ~~ 0*N7_Thought_Disorder
GP ~~ 0*N9_Somatic_Dep
GP ~~ 0*N10_Detachment
GP ~~ 0*N11_EXT_Ant
GP ~~ 0*N12_Spec_Phob
GP ~~ 0*N13_EAT_thoughts
GP ~~ 0*N14_EXT_Dis
GP ~~ 0*N8_PF_Problems
"



#GPbasemodel <- cfa(model = paste0(GPbase), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)
GPbifactmodel = cfa(model = paste0(GPbase, GPbifact), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# calculate unbiased SRMR and highest standardized residual covariance and average R2 for manifest variables according to Shi et al. 2018
test = lavResiduals(GPbifactmodel)
save(test, file= "residGP.rda")
uSRMR = data.frame(test$summary)
uSRMR$value = uSRMR$cov
names(uSRMR) = c("fitindex", "value")
uSRMR$fitindex = rownames(uSRMR)
uSRMR = uSRMR[5:8,]

kable(uSRMR)
fitindex value
usrmr usrmr 0.0547488
usrmr.se usrmr.se 0.0003053
usrmr.ci.lower usrmr.ci.lower 0.0542465
usrmr.ci.upper usrmr.ci.upper 0.0552510
kable(data.frame(max_std_cov = max(test$cov)))
max_std_cov
0.384288
kable(data.frame(average_R2_manifest_vars_x_0.10 =mean(lavInspect(GPbifactmodel, what = "rsquare")) * .1))
average_R2_manifest_vars_x_0.10
0.0567604
summary(GPbifactmodel, std=T)
## lavaan 0.6.16 ended normally after 78 iterations
##
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                       345
##
##   Number of observations                         27173
##
## Model Test User Model:
##
##   Test statistic                              409926.460
##   Degrees of freedom                                4506
##   P-value (Chi-square)                             0.000
##
## Parameter Estimates:
##
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N9_Somatic_Dep =~
##     DEP_psycmt_nhb          0.359    0.006   63.536    0.000    0.359    0.367
##     DEP_reduc_nrgy          0.528    0.004  120.093    0.000    0.528    0.505
##     DEP_hypersomni          0.314    0.007   47.679    0.000    0.314    0.310
##     DEP_crcd_md_fl          0.319    0.008   42.351    0.000    0.319    0.274
##     DEP_concentrtn          0.413    0.006   69.368    0.000    0.413    0.335
##     DEP_loss_apptt          0.170    0.005   31.855    0.000    0.170    0.200
##     DEP_loss_libid          0.329    0.008   41.207    0.000    0.329    0.283
##     DT_anhedonia            0.301    0.006   49.048    0.000    0.301    0.251
##     DEP_depr_mood           0.215    0.005   46.740    0.000    0.215    0.197
##     DEP_dmn_slfcnf          0.348    0.005   71.139    0.000    0.348    0.298
##     DEP_dimn_ntrst          0.462    0.005   93.013    0.000    0.462    0.392
##     DEP_decsn_prbl          0.260    0.006   42.248    0.000    0.260    0.199
##     Somatc_symptms          0.192    0.005   40.878    0.000    0.192    0.207
##     NA_perseveratn          0.149    0.006   25.586    0.000    0.149    0.140
##   N2_Depression =~
##     DEP_hopelessn           0.711    0.006  116.387    0.000    0.711    0.569
##     DEP_depr_mood           0.538    0.005  113.016    0.000    0.538    0.493
##     DEP_dmn_slfcnf          0.619    0.005  120.106    0.000    0.619    0.528
##     DEP_worthlessn          0.683    0.006  107.416    0.000    0.683    0.501
##     DEP_suicd_ntnt          0.327    0.006   51.478    0.000    0.327    0.284
##     DEP_dimn_ntrst          0.470    0.005   92.149    0.000    0.470    0.399
##     DEP_guilt               0.618    0.006   98.341    0.000    0.618    0.460
##     DEP_crying              0.292    0.007   41.381    0.000    0.292    0.248
##     DEP_decsn_prbl          0.436    0.006   71.477    0.000    0.436    0.335
##     PF_self_rflctn          0.144    0.005   27.185    0.000    0.144    0.112
##     DEP_rumination          0.430    0.006   70.563    0.000    0.430    0.326
##     DEP_psycmot_gt          0.287    0.006   47.288    0.000    0.287    0.227
##     PF_affect_diff          0.111    0.005   22.647    0.000    0.111    0.087
##     PF_identity             0.138    0.004   36.873    0.000    0.138    0.128
##     PF_self_est_rg          0.367    0.005   71.782    0.000    0.367    0.343
##     DEP_reduc_nrgy          0.415    0.005   91.364    0.000    0.415    0.397
##     DEP_concentrtn          0.342    0.006   57.782    0.000    0.342    0.277
##     DT_anhedonia            0.329    0.006   55.064    0.000    0.329    0.275
##   N8_PF_Problems =~
##     PF_anticipatin          0.548    0.007   75.801    0.000    0.548    0.435
##     PF_affect_comm          0.557    0.006   89.516    0.000    0.557    0.461
##     PF_ntrn_rlshp_          0.301    0.006   47.918    0.000    0.301    0.256
##     NA_sep_insecur          0.172    0.007   23.026    0.000    0.172    0.141
##     DT_suspicisnss          0.329    0.008   41.035    0.000    0.329    0.240
##     PF_hlstc_prcpt          0.244    0.006   38.586    0.000    0.244    0.226
##     PF_self_est_rg          0.201    0.005   36.759    0.000    0.201    0.188
##     NA_perseveratn          0.193    0.006   31.184    0.000    0.193    0.181
##     PF_affct_tlrnc         -0.057    0.006  -10.014    0.000   -0.057   -0.046
##     PF_impulse_reg          0.197    0.006   32.528    0.000    0.197    0.182
##     DI_impulsivity          0.136    0.006   22.488    0.000    0.136    0.123
##     PF_frmng_rlshp          0.337    0.008   44.003    0.000    0.337    0.260
##     DEP_rumination          0.042    0.006    6.559    0.000    0.042    0.032
##     PF_affect_diff         -0.083    0.005  -15.588    0.000   -0.083   -0.065
##     PS_eccentricty          0.280    0.006   46.794    0.000    0.280    0.232
##     PF_identity            -0.087    0.004  -21.550    0.000   -0.087   -0.080
##   N4_GAD_OCD =~
##     GAD_fre_flt_nx          0.924    0.006  165.115    0.000    0.924    0.644
##     GAD_nervousnss          0.926    0.006  153.849    0.000    0.926    0.615
##     GAD_irritablty          0.809    0.007  110.752    0.000    0.809    0.504
##     GAD_excss_wrry          0.719    0.005  142.390    0.000    0.719    0.552
##     DEP_rumination          0.240    0.006   42.023    0.000    0.240    0.182
##     DEP_psycmot_gt          0.194    0.006   33.409    0.000    0.194    0.154
##     PF_affect_diff          0.098    0.005   20.479    0.000    0.098    0.076
##     OCD_sympt               0.130    0.005   24.992    0.000    0.130    0.128
##     DI_perfectinsm          0.145    0.007   21.283    0.000    0.145    0.125
##     PF_identity            -0.054    0.004  -15.208    0.000   -0.054   -0.050
##     PF_affct_tlrnc         -0.005    0.005   -0.971    0.331   -0.005   -0.004
##     DEP_concentrtn          0.069    0.005   13.418    0.000    0.069    0.056
##     DEP_decsn_prbl          0.101    0.005   18.496    0.000    0.101    0.077
##     PF_self_rflctn         -0.077    0.005  -15.310    0.000   -0.077   -0.060
##   N1_Soc_Phob =~
##     SAD_soc_inter           1.029    0.006  167.692    0.000    1.029    0.694
##     SAD_avoidance           1.013    0.006  171.857    0.000    1.013    0.677
##     SAD_performing          0.740    0.005  140.780    0.000    0.740    0.615
##     SAD_devaluatin          0.949    0.006  157.462    0.000    0.949    0.590
##     SAD_being_bsrv          0.751    0.006  123.816    0.000    0.751    0.549
##     SAD_eating              0.640    0.006  112.714    0.000    0.640    0.505
##     SAD_ttrctv_prs          0.705    0.008   89.627    0.000    0.705    0.473
##     PF_frmng_rlshp          0.537    0.007   79.447    0.000    0.537    0.415
##     Spec_phob_avod          0.515    0.007   73.799    0.000    0.515    0.346
##     Agoraphobia             0.417    0.006   71.833    0.000    0.417    0.361
##     DT_rstr_ffctvt          0.239    0.005   44.907    0.000    0.239    0.202
##     DT_withdrawal           0.348    0.006   58.954    0.000    0.348    0.302
##   N3_Panic =~
##     Panc_dctr_vsts          0.549    0.004  143.470    0.000    0.549    0.739
##     Panic_attacks           0.882    0.006  155.674    0.000    0.882    0.705
##     Panc_phys_symp          1.131    0.007  155.924    0.000    1.131    0.713
##     Pnc_dysf_thght          0.795    0.005  149.714    0.000    0.795    0.644
##     Panic_fer_rcrr          0.884    0.007  131.958    0.000    0.884    0.602
##     Panic_avod_bhv          0.576    0.007   84.750    0.000    0.576    0.414
##     Somatc_symptms          0.227    0.004   52.970    0.000    0.227    0.245
##     Hypochondriass          0.263    0.007   38.019    0.000    0.263    0.213
##   N12_Spec_Phob =~
##     Spec_phob_fear          0.997    0.008  131.085    0.000    0.997    0.777
##     Spec_phob_nmls          0.712    0.008   91.560    0.000    0.712    0.556
##     Spec_phob_blod          0.506    0.006   82.547    0.000    0.506    0.509
##     SAD_performing          0.061    0.004   13.535    0.000    0.061    0.050
##     Spec_phob_avod          0.446    0.007   61.450    0.000    0.446    0.300
##   N13_EAT_thoughts =~
##     EATA_bdy_slfst          0.913    0.006  144.612    0.000    0.913    0.636
##     EATB_worries            0.781    0.005  143.532    0.000    0.781    0.587
##     EATA_fer_wghtg          0.873    0.006  139.350    0.000    0.873    0.599
##     EATA_fer_wghtl          0.279    0.007   42.790    0.000    0.279    0.271
##     EATA_excs_xrcs          0.171    0.004   39.233    0.000    0.171    0.208
##     EATB_soc_dsgsd          0.452    0.005   84.537    0.000    0.452    0.359
##   N6_EAT_purging =~
##     EATB_loss_ctrl          1.367    0.006  212.226    0.000    1.367    0.931
##     EATB_cope_ngff          1.306    0.007  183.685    0.000    1.306    0.857
##     EATB_overeatng          1.420    0.007  193.390    0.000    1.420    0.883
##     EATB_ntrs_thgh          0.703    0.005  133.686    0.000    0.703    0.655
##     DEP_incr_apptt          0.556    0.006   98.502    0.000    0.556    0.531
##     EATB_soc_dsgsd          0.586    0.006  100.953    0.000    0.586    0.467
##     EATA_bdy_slfst          0.401    0.007   57.269    0.000    0.401    0.279
##     EATB_worries            0.426    0.006   69.668    0.000    0.426    0.320
##     EATA_fer_wghtg          0.508    0.007   72.380    0.000    0.508    0.348
##   N5_EAT_restr =~
##     EATA_restrictd          1.093    0.006  189.652    0.000    1.093    0.868
##     EATA_omit_meal          0.827    0.004  208.800    0.000    0.827    0.890
##     EATA_time_frms          0.738    0.004  176.400    0.000    0.738    0.810
##     EATA_cont_clrs          0.722    0.004  162.860    0.000    0.722    0.796
##     EATA_prgng_bhv          0.312    0.003  103.824    0.000    0.312    0.555
##     EATA_excs_xrcs          0.437    0.005   97.023    0.000    0.437    0.532
##     EATB_soc_dsgsd          0.471    0.006   82.679    0.000    0.471    0.374
##     EATA_bdy_slfst          0.435    0.007   60.482    0.000    0.435    0.303
##     EATB_worries            0.434    0.006   69.241    0.000    0.434    0.326
##     EATA_fer_wghtg          0.519    0.007   72.219    0.000    0.519    0.356
##   N10_Detachment =~
##     DT_intimcy_avd          0.488    0.006   77.626    0.000    0.488    0.476
##     DT_rstr_ffctvt          0.614    0.006   96.879    0.000    0.614    0.519
##     DT_withdrawal           0.463    0.007   69.817    0.000    0.463    0.403
##     DEP_emot_numbn          0.513    0.007   74.405    0.000    0.513    0.414
##     DEP_crying_inb          0.341    0.007   45.795    0.000    0.341    0.270
##     DT_anhedonia            0.448    0.006   72.166    0.000    0.448    0.374
##     DEP_dimn_ntrst          0.217    0.005   47.749    0.000    0.217    0.184
##     PF_ntrn_rlshp_          0.203    0.006   34.209    0.000    0.203    0.173
##     DT_suspicisnss          0.205    0.008   26.943    0.000    0.205    0.150
##   N7_Thought_Disorder =~
##     PS_unusul_blfs          0.479    0.004  111.479    0.000    0.479    0.629
##     PS_prcpt_dysrg          0.327    0.005   68.538    0.000    0.327    0.367
##     Psychtc_symptm          0.439    0.004   98.943    0.000    0.439    0.542
##     Dissociation            0.233    0.005   48.152    0.000    0.233    0.241
##     PS_eccentricty          0.291    0.006   51.129    0.000    0.291    0.240
##     PF_identity            -0.020    0.004   -5.389    0.000   -0.020   -0.019
##     Manic_sympt             0.127    0.004   34.361    0.000    0.127    0.216
##     PF_affct_tlrnc         -0.057    0.005  -10.588    0.000   -0.057   -0.046
##     DEP_crying_inb          0.042    0.007    5.783    0.000    0.042    0.033
##     PF_self_rflctn         -0.099    0.005  -18.255    0.000   -0.099   -0.077
##     OCD_sympt               0.158    0.006   27.948    0.000    0.158    0.156
##   N11_EXT_Ant =~
##     AN_callousness          0.363    0.004   91.991    0.000    0.363    0.572
##     AN_hostility            0.454    0.006   81.651    0.000    0.454    0.475
##     AN_deceitflnss          0.469    0.005   89.084    0.000    0.469    0.514
##     AN_manipultvns          0.420    0.005   79.717    0.000    0.420    0.492
##     AN_entitlement          0.343    0.005   69.905    0.000    0.343    0.460
##     AN_grandiosity          0.452    0.007   68.534    0.000    0.452    0.419
##     PF_impulse_reg          0.388    0.006   66.951    0.000    0.388    0.358
##     DI_impulsivity          0.265    0.006   46.416    0.000    0.265    0.240
##     DI_irrspnsblty          0.149    0.005   31.347    0.000    0.149    0.199
##     PF_hlstc_prcpt          0.253    0.006   42.628    0.000    0.253    0.234
##   N14_EXT_Dis =~
##     Subst_use_drug          0.311    0.004   70.256    0.000    0.311    0.501
##     DI_normviolatn          0.656    0.007   89.546    0.000    0.656    0.653
##     Subst_use_alc           0.279    0.005   52.098    0.000    0.279    0.385
##     DI_risk_taking          0.296    0.006   53.511    0.000    0.296    0.364
##     DI_irrspnsblty          0.151    0.005   29.894    0.000    0.151    0.201
##     Manic_sympt             0.160    0.004   40.865    0.000    0.160    0.272
##     DI_impulsivity          0.236    0.006   39.049    0.000    0.236    0.213
##   GP =~
##     PF_affect_comm          0.866    0.006  134.089    0.000    0.866    0.716
##     PF_affect_diff          1.095    0.006  173.879    0.000    1.095    0.852
##     PF_affct_tlrnc          1.027    0.006  167.236    0.000    1.027    0.831
##     PF_frmng_rlshp          0.581    0.008   76.640    0.000    0.581    0.450
##     PF_hlstc_prcpt          0.633    0.006  104.492    0.000    0.633    0.587
##     PF_identity             0.966    0.005  189.057    0.000    0.966    0.897
##     PF_impulse_reg          0.644    0.006  106.126    0.000    0.644    0.594
##     PF_ntrn_rlshp_          0.806    0.006  127.128    0.000    0.806    0.686
##     PF_self_rflctn          1.068    0.006  166.363    0.000    1.068    0.829
##     PF_self_est_rg          0.704    0.006  120.626    0.000    0.704    0.659
##     PF_anticipatin          0.779    0.007  110.858    0.000    0.779    0.618
##     SAD_soc_inter           0.861    0.008  103.342    0.000    0.861    0.581
##     SAD_avoidance           0.937    0.008  113.324    0.000    0.937    0.626
##     SAD_performing          0.703    0.007  104.059    0.000    0.703    0.584
##     SAD_devaluatin          1.126    0.009  130.897    0.000    1.126    0.700
##     SAD_being_bsrv          0.835    0.008  109.888    0.000    0.835    0.611
##     SAD_eating              0.789    0.007  112.640    0.000    0.789    0.623
##     SAD_ttrctv_prs          0.684    0.009   78.618    0.000    0.684    0.459
##     Spec_phob_avod          0.861    0.008  102.853    0.000    0.861    0.578
##     Agoraphobia             0.659    0.006  101.469    0.000    0.659    0.572
##     DEP_hopelessn           0.722    0.007  102.078    0.000    0.722    0.578
##     DEP_depr_mood           0.740    0.006  124.769    0.000    0.740    0.677
##     DEP_dmn_slfcnf          0.744    0.006  114.938    0.000    0.744    0.636
##     DEP_worthlessn          0.884    0.007  118.104    0.000    0.884    0.649
##     DEP_suicd_ntnt          0.653    0.007  100.228    0.000    0.653    0.567
##     DEP_dimn_ntrst          0.774    0.006  120.087    0.000    0.774    0.657
##     DEP_guilt               0.891    0.007  121.543    0.000    0.891    0.664
##     DEP_crying              0.540    0.007   78.389    0.000    0.540    0.458
##     DEP_decsn_prbl          0.886    0.007  125.622    0.000    0.886    0.680
##     Panc_dctr_vsts          0.209    0.005   46.464    0.000    0.209    0.281
##     Panic_attacks           0.632    0.007   87.609    0.000    0.632    0.505
##     Panc_phys_symp          0.773    0.009   84.089    0.000    0.773    0.487
##     Pnc_dysf_thght          0.727    0.007  105.200    0.000    0.727    0.589
##     Panic_fer_rcrr          0.827    0.008   99.749    0.000    0.827    0.564
##     Panic_avod_bhv          0.824    0.008  105.785    0.000    0.824    0.592
##     Somatc_symptms          0.613    0.005  121.585    0.000    0.613    0.661
##     Hypochondriass          0.603    0.007   84.025    0.000    0.603    0.487
##     GAD_fre_flt_nx          0.976    0.008  124.680    0.000    0.976    0.681
##     GAD_nervousnss          1.023    0.008  124.568    0.000    1.023    0.680
##     GAD_irritablty          1.028    0.009  115.773    0.000    1.028    0.640
##     GAD_excss_wrry          0.947    0.007  136.345    0.000    0.947    0.726
##     DEP_rumination          0.905    0.007  126.732    0.000    0.905    0.685
##     DEP_psycmot_gt          0.868    0.007  127.491    0.000    0.868    0.687
##     OCD_sympt               0.629    0.006  111.480    0.000    0.629    0.618
##     DI_perfectinsm          0.528    0.007   77.653    0.000    0.528    0.454
##     EATA_restrictd          0.341    0.008   44.663    0.000    0.341    0.271
##     EATA_omit_meal          0.334    0.006   60.211    0.000    0.334    0.360
##     EATA_time_frms          0.316    0.005   57.931    0.000    0.316    0.347
##     EATA_cont_clrs          0.215    0.006   38.986    0.000    0.215    0.237
##     EATA_prgng_bhv          0.185    0.003   54.701    0.000    0.185    0.329
##     EATA_excs_xrcs          0.229    0.005   46.053    0.000    0.229    0.279
##     EATB_loss_ctrl          0.362    0.009   40.507    0.000    0.362    0.246
##     EATB_cope_ngff          0.368    0.009   39.611    0.000    0.368    0.241
##     EATB_overeatng          0.395    0.010   40.352    0.000    0.395    0.246
##     EATB_ntrs_thgh          0.433    0.006   68.148    0.000    0.433    0.403
##     DEP_incr_apptt          0.336    0.006   53.459    0.000    0.336    0.321
##     EATB_soc_dsgsd          0.537    0.007   72.706    0.000    0.537    0.428
##     PS_unusul_blfs          0.427    0.004   98.115    0.000    0.427    0.561
##     PS_prcpt_dysrg          0.567    0.005  115.288    0.000    0.567    0.636
##     Psychtc_symptm          0.481    0.005  105.378    0.000    0.481    0.594
##     Dissociation            0.694    0.005  135.435    0.000    0.694    0.718
##     PS_eccentricty          0.871    0.006  135.793    0.000    0.871    0.721
##     Manic_sympt             0.239    0.003   68.461    0.000    0.239    0.405
##     NA_sep_insecur          0.726    0.007  106.498    0.000    0.726    0.596
##     DT_suspicisnss          0.835    0.008  109.510    0.000    0.835    0.610
##     NA_perseveratn          0.667    0.006  113.784    0.000    0.667    0.628
##     DEP_psycmt_nhb          0.544    0.006   98.142    0.000    0.544    0.556
##     DEP_reduc_nrgy          0.674    0.006  117.221    0.000    0.674    0.644
##     DEP_hypersomni          0.387    0.006   64.292    0.000    0.387    0.382
##     DEP_crcd_md_fl          0.471    0.007   68.180    0.000    0.471    0.403
##     DEP_concentrtn          0.811    0.007  120.424    0.000    0.811    0.658
##     DEP_loss_apptt          0.409    0.005   82.737    0.000    0.409    0.480
##     DEP_loss_libid          0.270    0.007   38.133    0.000    0.270    0.232
##     DT_intimcy_avd          0.461    0.006   76.900    0.000    0.461    0.450
##     DT_rstr_ffctvt          0.680    0.007  102.220    0.000    0.680    0.576
##     DT_withdrawal           0.541    0.007   80.818    0.000    0.541    0.470
##     DEP_emot_numbn          0.739    0.007  106.588    0.000    0.739    0.596
##     DEP_crying_inb          0.712    0.007   99.691    0.000    0.712    0.564
##     DT_anhedonia            0.671    0.007   98.726    0.000    0.671    0.560
##     AN_callousness          0.192    0.004   50.110    0.000    0.192    0.302
##     AN_hostility            0.459    0.006   82.729    0.000    0.459    0.480
##     AN_deceitflnss          0.432    0.005   81.627    0.000    0.432    0.474
##     AN_manipultvns          0.314    0.005   61.827    0.000    0.314    0.369
##     AN_entitlement          0.157    0.005   34.431    0.000    0.157    0.210
##     AN_grandiosity          0.460    0.006   72.417    0.000    0.460    0.426
##     DI_impulsivity          0.708    0.006  116.510    0.000    0.708    0.640
##     Spec_phob_fear          0.643    0.007   86.888    0.000    0.643    0.501
##     Spec_phob_nmls          0.470    0.008   61.422    0.000    0.470    0.366
##     Spec_phob_blod          0.314    0.006   52.453    0.000    0.314    0.316
##     EATA_bdy_slfst          0.649    0.008   77.302    0.000    0.649    0.452
##     EATB_worries            0.671    0.008   87.493    0.000    0.671    0.504
##     EATA_fer_wghtg          0.593    0.009   68.845    0.000    0.593    0.407
##     EATA_fer_wghtl          0.265    0.006   42.263    0.000    0.265    0.257
##     Subst_use_drug          0.171    0.004   45.315    0.000    0.171    0.275
##     DI_normviolatn          0.349    0.006   58.119    0.000    0.349    0.348
##     Subst_use_alc           0.011    0.004    2.399    0.016    0.011    0.015
##     DI_risk_taking          0.320    0.005   66.254    0.000    0.320    0.393
##     DI_irrspnsblty          0.302    0.004   68.033    0.000    0.302    0.403
##
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##   N1_Soc_Phob ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N2_Depression ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N3_Panic ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N5_EAT_restr ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N5_EAT_restr ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N5_EAT_restr            0.000                               0.000    0.000
##   N5_EAT_restr ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N2_Depression ~~
##     N1_Soc_Phob             0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     N3_Panic                0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N1_Soc_Phob             0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N1_Soc_Phob             0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N1_Soc_Phob             0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N2_Depression ~~
##     N3_Panic                0.000                               0.000    0.000
##     N4_GAD_OCD              0.000                               0.000    0.000
##     N6_EAT_purging          0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##     N8_PF_Problems          0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N2_Depression           0.000                               0.000    0.000
##   N2_Depression ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N3_Panic                0.000                               0.000    0.000
##   N3_Panic ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N3_Panic                0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N3_Panic                0.000                               0.000    0.000
##   N3_Panic ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N4_GAD_OCD              0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N4_GAD_OCD              0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N6_EAT_purging          0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N10_Detachment ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N7_Thought_Disorder ~~
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N7_Thght_Dsrdr          0.000                               0.000    0.000
##   N7_Thought_Disorder ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N8_PF_Problems          0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     N10_Detachment          0.000                               0.000    0.000
##     N11_EXT_Ant             0.000                               0.000    0.000
##     N12_Spec_Phob           0.000                               0.000    0.000
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N10_Detachment ~~
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N10_Detachment          0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N10_Detachment          0.000                               0.000    0.000
##   N10_Detachment ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N11_EXT_Ant             0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     N13_EAT_thghts          0.000                               0.000    0.000
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     N14_EXT_Dis             0.000                               0.000    0.000
##   N5_EAT_restr ~~
##     GP                      0.000                               0.000    0.000
##   N1_Soc_Phob ~~
##     GP                      0.000                               0.000    0.000
##   N2_Depression ~~
##     GP                      0.000                               0.000    0.000
##   N3_Panic ~~
##     GP                      0.000                               0.000    0.000
##   N4_GAD_OCD ~~
##     GP                      0.000                               0.000    0.000
##   N6_EAT_purging ~~
##     GP                      0.000                               0.000    0.000
##   N7_Thought_Disorder ~~
##     GP                      0.000                               0.000    0.000
##   N9_Somatic_Dep ~~
##     GP                      0.000                               0.000    0.000
##   N10_Detachment ~~
##     GP                      0.000                               0.000    0.000
##   N11_EXT_Ant ~~
##     GP                      0.000                               0.000    0.000
##   N12_Spec_Phob ~~
##     GP                      0.000                               0.000    0.000
##   N13_EAT_thoughts ~~
##     GP                      0.000                               0.000    0.000
##   N14_EXT_Dis ~~
##     GP                      0.000                               0.000    0.000
##   N8_PF_Problems ~~
##     GP                      0.000                               0.000    0.000
##
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
##    .DEP_psycmt_nhb    0.533    0.005  104.438    0.000    0.533    0.556
##    .DEP_reduc_nrgy    0.188    0.003   71.046    0.000    0.188    0.172
##    .DEP_hypersomni    0.778    0.007  110.552    0.000    0.778    0.758
##    .DEP_crcd_md_fl    1.038    0.009  111.745    0.000    1.038    0.762
##    .DEP_concentrtn    0.572    0.005  107.378    0.000    0.572    0.376
##    .DEP_loss_apptt    0.528    0.005  113.300    0.000    0.528    0.730
##    .DEP_loss_libid    1.171    0.010  112.330    0.000    1.171    0.866
##    .DT_anhedonia      0.586    0.006   97.631    0.000    0.586    0.409
##    .DEP_depr_mood     0.310    0.003  102.215    0.000    0.310    0.260
##    .DEP_dmn_slfcnf    0.313    0.003   96.121    0.000    0.313    0.228
##    .DEP_dimn_ntrst    0.308    0.003   91.035    0.000    0.308    0.222
##    .DEP_decsn_prbl    0.647    0.006  111.593    0.000    0.647    0.380
##    .Somatc_symptms    0.395    0.004  109.523    0.000    0.395    0.459
##    .NA_perseveratn    0.623    0.006  110.904    0.000    0.623    0.552
##    .DEP_hopelessn     0.533    0.006   94.783    0.000    0.533    0.342
##    .DEP_worthlessn    0.607    0.006   99.525    0.000    0.607    0.327
##    .DEP_suicd_ntnt    0.793    0.007  113.407    0.000    0.793    0.598
##    .DEP_guilt         0.627    0.006  103.146    0.000    0.627    0.348
##    .DEP_crying        1.010    0.009  114.653    0.000    1.010    0.729
##    .PF_self_rflctn    0.484    0.005  102.537    0.000    0.484    0.291
##    .DEP_rumination    0.681    0.006  109.540    0.000    0.681    0.391
##    .DEP_psycmot_gt    0.722    0.006  113.063    0.000    0.722    0.453
##    .PF_affect_diff    0.424    0.004  103.761    0.000    0.424    0.257
##    .PF_identity       0.197    0.002   85.987    0.000    0.197    0.170
##    .PF_self_est_rg    0.469    0.004  105.689    0.000    0.469    0.412
##    .PF_anticipatin    0.683    0.007   91.372    0.000    0.683    0.429
##    .PF_affect_comm    0.403    0.006   73.127    0.000    0.403    0.275
##    .PF_ntrn_rlshp_    0.600    0.006  105.215    0.000    0.600    0.435
##    .NA_sep_insecur    0.929    0.008  113.606    0.000    0.929    0.625
##    .DT_suspicisnss    1.027    0.009  109.009    0.000    1.027    0.548
##    .PF_hlstc_prcpt    0.639    0.006  108.412    0.000    0.639    0.550
##    .PF_affct_tlrnc    0.465    0.005  100.903    0.000    0.465    0.305
##    .PF_impulse_reg    0.570    0.006  103.672    0.000    0.570    0.486
##    .DI_impulsivity    0.578    0.005  105.270    0.000    0.578    0.472
##    .PF_frmng_rlshp    0.933    0.009  106.362    0.000    0.933    0.558
##    .PS_eccentricty    0.539    0.005  102.731    0.000    0.539    0.369
##    .GAD_fre_flt_nx    0.249    0.004   66.858    0.000    0.249    0.121
##    .GAD_nervousnss    0.361    0.004   81.487    0.000    0.361    0.159
##    .GAD_irritablty    0.864    0.008  106.003    0.000    0.864    0.336
##    .GAD_excss_wrry    0.287    0.003   90.331    0.000    0.287    0.169
##    .OCD_sympt         0.597    0.005  113.747    0.000    0.597    0.577
##    .DI_perfectinsm    1.054    0.009  115.719    0.000    1.054    0.778
##    .SAD_soc_inter     0.398    0.004   90.319    0.000    0.398    0.181
##    .SAD_avoidance     0.337    0.004   86.834    0.000    0.337    0.150
##    .SAD_performing    0.403    0.004  103.292    0.000    0.403    0.278
##    .SAD_devaluatin    0.422    0.004   95.434    0.000    0.422    0.163
##    .SAD_being_bsrv    0.609    0.006  107.600    0.000    0.609    0.326
##    .SAD_eating        0.573    0.005  109.505    0.000    0.573    0.357
##    .SAD_ttrctv_prs    1.258    0.011  112.778    0.000    1.258    0.566
##    .Spec_phob_avod    1.012    0.009  108.727    0.000    1.012    0.456
##    .Agoraphobia       0.721    0.006  113.877    0.000    0.721    0.542
##    .DT_rstr_ffctvt    0.500    0.006   79.876    0.000    0.500    0.358
##    .DT_withdrawal     0.696    0.007  100.579    0.000    0.696    0.525
##    .Panc_dctr_vsts    0.207    0.002   96.026    0.000    0.207    0.375
##    .Panic_attacks     0.390    0.004   89.638    0.000    0.390    0.249
##    .Panc_phys_symp    0.639    0.007   89.488    0.000    0.639    0.254
##    .Pnc_dysf_thght    0.362    0.004   92.940    0.000    0.362    0.238
##    .Panic_fer_rcrr    0.687    0.007  101.291    0.000    0.687    0.319
##    .Panic_avod_bhv    0.928    0.008  111.176    0.000    0.928    0.479
##    .Hypochondriass    1.103    0.010  115.094    0.000    1.103    0.718
##    .Spec_phob_fear    0.240    0.011   21.582    0.000    0.240    0.146
##    .Spec_phob_nmls    0.916    0.010   93.755    0.000    0.916    0.557
##    .Spec_phob_blod    0.635    0.006  101.866    0.000    0.635    0.642
##    .EATA_bdy_slfst    0.459    0.006   76.659    0.000    0.459    0.222
##    .EATB_worries      0.342    0.004   77.559    0.000    0.342    0.193
##    .EATA_fer_wghtg    0.483    0.006   82.189    0.000    0.483    0.227
##    .EATA_fer_wghtl    0.914    0.008  114.420    0.000    0.914    0.861
##    .EATA_excs_xrcs    0.403    0.004  113.336    0.000    0.403    0.596
##    .EATB_soc_dsgsd    0.522    0.005  106.894    0.000    0.522    0.330
##    .EATB_loss_ctrl    0.158    0.003   50.703    0.000    0.158    0.073
##    .EATB_cope_ngff    0.481    0.005   95.705    0.000    0.481    0.207
##    .EATB_overeatng    0.414    0.005   86.375    0.000    0.414    0.160
##    .EATB_ntrs_thgh    0.472    0.004  110.454    0.000    0.472    0.409
##    .DEP_incr_apptt    0.672    0.006  113.938    0.000    0.672    0.614
##    .EATA_restrictd    0.276    0.003   88.856    0.000    0.276    0.174
##    .EATA_omit_meal    0.069    0.001   56.971    0.000    0.069    0.079
##    .EATA_time_frms    0.186    0.002   98.628    0.000    0.186    0.224
##    .EATA_cont_clrs    0.254    0.002  104.269    0.000    0.254    0.310
##    .EATA_prgng_bhv    0.185    0.002  113.436    0.000    0.185    0.584
##    .DT_intimcy_avd    0.598    0.006   97.202    0.000    0.598    0.571
##    .DEP_emot_numbn    0.729    0.007   98.537    0.000    0.729    0.474
##    .DEP_crying_inb    0.971    0.009  110.116    0.000    0.971    0.608
##    .PS_unusul_blfs    0.168    0.003   57.202    0.000    0.168    0.290
##    .PS_prcpt_dysrg    0.366    0.004  103.796    0.000    0.366    0.461
##    .Psychtc_symptm    0.233    0.003   77.882    0.000    0.233    0.354
##    .Dissociation      0.397    0.004  108.775    0.000    0.397    0.426
##    .Manic_sympt       0.249    0.002  107.786    0.000    0.249    0.715
##    .AN_callousness    0.234    0.002   93.618    0.000    0.234    0.581
##    .AN_hostility      0.497    0.005   99.932    0.000    0.497    0.544
##    .AN_deceitflnss    0.424    0.004   95.773    0.000    0.424    0.511
##    .AN_manipultvns    0.453    0.004  100.935    0.000    0.453    0.622
##    .AN_entitlement    0.414    0.004  104.956    0.000    0.414    0.744
##    .AN_grandiosity    0.750    0.007  105.672    0.000    0.750    0.643
##    .DI_irrspnsblty    0.427    0.004  111.509    0.000    0.427    0.758
##    .Subst_use_drug    0.260    0.003   91.302    0.000    0.260    0.673
##    .DI_normviolatn    0.456    0.008   56.896    0.000    0.456    0.452
##    .Subst_use_alc     0.447    0.004  105.203    0.000    0.447    0.852
##    .DI_risk_taking    0.474    0.005  104.590    0.000    0.474    0.713
##     N9_Somatic_Dep    1.000                               1.000    1.000
##     N2_Depression     1.000                               1.000    1.000
##     N8_PF_Problems    1.000                               1.000    1.000
##     N4_GAD_OCD        1.000                               1.000    1.000
##     N1_Soc_Phob       1.000                               1.000    1.000
##     N3_Panic          1.000                               1.000    1.000
##     N12_Spec_Phob     1.000                               1.000    1.000
##     N13_EAT_thghts    1.000                               1.000    1.000
##     N6_EAT_purging    1.000                               1.000    1.000
##     N5_EAT_restr      1.000                               1.000    1.000
##     N10_Detachment    1.000                               1.000    1.000
##     N7_Thght_Dsrdr    1.000                               1.000    1.000
##     N11_EXT_Ant       1.000                               1.000    1.000
##     N14_EXT_Dis       1.000                               1.000    1.000
##     GP                1.000                               1.000    1.000

Highest loading scales with lowest S loading

# investigate change in loadings in bifactor
bifloads$GP = data.frame(lavInspect(GPbifactmodel, what="std")$lambda)
#corload = data.frame(lavInspect(GPbasemodel, what="std")$lambda)

# ## standardized loading on G minus change in loading of specific factor in comparison with the correlated factors model
# loadingschange_GP = data.frame(bifloads$GP$GP - abs(bifloads$GP[,1]) - abs(bifloads$GP[,2]) - abs(bifloads$GP[,3]) - abs(bifloads$GP[,4]) - abs(bifloads$GP[,5]) - abs(bifloads$GP[,6]) - abs(bifloads$GP[,7]) - abs(bifloads$GP[,8]) -abs(bifloads$GP[,9]) - abs(bifloads$GP[,10]) -abs(bifloads$GP[,11]) -abs(bifloads$GP[,12]) -abs(bifloads$GP[,13]) -abs(bifloads$GP[,14]))
#
# rownames(loadingschange_GP) = rownames(bifloads$GP)
# names(loadingschange_GP) = "std_G_loading_minus_S_loading"
# loadingschange_GP = loadingschange_GP %>%   tibble::rownames_to_column() %>%
#   arrange(desc(std_G_loading_minus_S_loading))
# names(loadingschange_GP)[1] = "scale"


kable(extractGSmax(bifloads$GP, "GP"),table.attr = "style='width:30%;'") %>%kable_paper
scale G S G_minus_S
PF_affect_tolrnce 0.8311848 [.05;N8] 0.7850840
PF_identity 0.8970665 [.13;N2] 0.7692039
PF_affect_diff 0.8519559 [.09;N2] 0.7654384
PF_self_reflection 0.8285663 [.11;N2] 0.7165933
PS_eccentricity 0.7206385 [.24;N7] 0.4801701
Dissociation 0.7183185 [.24;N7] 0.4773561
OCD_sympt 0.6184295 [.16;N7] 0.4627056
DEP_psycmot_agit 0.6871162 [.23;N2] 0.4596985
NA_sep_insecur 0.5955991 [.14;N8] 0.4547132
NA_perseveration 0.6284763 [.18;N8] 0.4470613
PF_intern_relshp_mod 0.6855950 [.26;N8] 0.4297258
Somatic_symptoms 0.6613914 [.25;N3] 0.4162841
DI_impulsivity 0.6401189 [.24;N11] 0.4005104
DT_suspiciousness 0.6098842 [.24;N8] 0.3696533
DEP_rumination 0.6849262 [.33;N2] 0.3591419
PF_holistic_percptn 0.5868806 [.23;N11] 0.3526696
DEP_decision_probl 0.6797180 [.33;N2] 0.3449620
DI_perfectionism 0.4541396 [.12;N4] 0.3291693
DEP_concentration 0.6576309 [.33;N9] 0.3230967
PF_self_est_reg 0.6593495 [.34;N2] 0.3159788
DEP_crying_inab 0.5637434 [.27;N10] 0.2935905
DEP_suicid_intent 0.5670257 [.28;N2] 0.2830169
DEP_loss_appetite 0.4800411 [.2;N9] 0.2804681
Hypochondriasis 0.4866509 [.21;N3] 0.2740827
PS_percept_dysreg 0.6361544 [.37;N7] 0.2692768
DEP_dimin_interest 0.6567251 [.4;N2] 0.2575871
PF_affect_comm 0.7159511 [.46;N8] 0.2552467
PF_impulse_reg 0.5940934 [.36;N11] 0.2358449
Spec_phob_avoid 0.5783826 [.35;N1] 0.2328107
DEP_crying 0.4583686 [.25;N2] 0.2106866
Agoraphobia 0.5719315 [.36;N1] 0.2105726
DEP_guilt 0.6635697 [.46;N2] 0.2033397
DI_irresponsibility 0.4026481 [.2;N14] 0.2018741
DEP_psycmot_inhib 0.5561784 [.37;N9] 0.1894177
DT_anhedonia 0.5598427 [.37;N10] 0.1861167
DEP_depr_mood 0.6772788 [.49;N2] 0.1846163
PF_anticipation 0.6178132 [.43;N8] 0.1829380
DEP_emot_numbn 0.5955721 [.41;N10] 0.1817033
Panic_avoid_behv 0.5918880 [.41;N3] 0.1782381
GAD_excess_worry 0.7261270 [.55;N4] 0.1746227
DEP_worthlessn 0.6493201 [.5;N2] 0.1480861
DEP_reduc_energy 0.6444830 [.5;N9] 0.1396712
GAD_irritability 0.6403630 [.5;N4] 0.1360527
Manic_sympt 0.4054109 [.27;N14] 0.1337262
DEP_circad_mood_fluct 0.4033768 [.27;N9] 0.1295583
SAD_eating 0.6227840 [.51;N1] 0.1174864
SAD_devaluation 0.6995617 [.59;N1] 0.1098401
DEP_dimin_selfconf 0.6356901 [.53;N2] 0.1075330
DEP_hypersomnia 0.3821683 [.31;N9] 0.0725504
DT_withdrawal 0.4704482 [.4;N10] 0.0677948
GAD_nervousness 0.6798650 [.62;N4] 0.0647255
SAD_being_observ 0.6105366 [.55;N1] 0.0614302
DT_restr_affectivity 0.5756072 [.52;N10] 0.0561425
Psychotic_symptoms 0.5936670 [.54;N7] 0.0518897
GAD_free_float_anx 0.6809165 [.64;N4] 0.0365995
PF_forming_relshps 0.4495166 [.42;N1] 0.0342644
DI_risk_taking 0.3928529 [.36;N14] 0.0291878
DEP_hopelessn 0.5779567 [.57;N2] 0.0086401
AN_grandiosity 0.4261881 [.42;N11] 0.0076619
AN_hostility 0.4800536 [.47;N11] 0.0052166
EATA_fear_weightl 0.2567208 [.27;N13] -0.0139423
SAD_attractive_pers 0.4589347 [.47;N1] -0.0140290
DT_intimcy_avoid 0.4499418 [.48;N10] -0.0265322
SAD_performing 0.5840514 [.62;N1] -0.0311252
Panic_fear_recurr 0.5638648 [.6;N3] -0.0384549
EATB_soc_disguised 0.4276226 [.47;N6] -0.0389031
AN_deceitfulness 0.4744157 [.51;N11] -0.0397320
DEP_loss_libido 0.2324183 [.28;N9] -0.0503637
SAD_avoidance 0.6258414 [.68;N1] -0.0508064
Panic_dysf_thought 0.5892904 [.64;N3] -0.0550810
PS_unusual_beliefs 0.5606941 [.63;N7] -0.0685032
EATB_worries 0.5040266 [.59;N13] -0.0828118
SAD_soc_inter 0.5807191 [.69;N1] -0.1133709
AN_manipulativns 0.3685998 [.49;N11] -0.1234048
EATA_body_selfest 0.4518863 [.64;N13] -0.1836989
Spec_phob_animals 0.3662612 [.56;N12] -0.1893438
EATA_fear_weightg 0.4069186 [.6;N13] -0.1919755
Spec_phob_blood 0.3157621 [.51;N12] -0.1929094
Panic_attacks 0.5048716 [.7;N3] -0.1996784
DEP_incr_appetite 0.3214622 [.53;N6] -0.2098164
Panic_phys_symp 0.4871283 [.71;N3] -0.2261212
EATA_purging_behv 0.3285251 [.55;N5] -0.2261932
Subst_use_drug 0.2745980 [.5;N14] -0.2265656
AN_entitlement 0.2104371 [.46;N11] -0.2494845
EATB_intrus_thoughts 0.4031345 [.65;N6] -0.2513866
EATA_exces_exercise 0.2788756 [.53;N5] -0.2528840
AN_callousness 0.3024338 [.57;N11] -0.2694757
Spec_phob_fear 0.5010041 [.78;N12] -0.2758036
DI_normviolation 0.3478604 [.65;N14] -0.3053677
Subst_use_alc 0.0148290 [.39;N14] -0.3701857
Panic_doctor_visits 0.2814468 [.74;N3] -0.4570540
EATA_time_frames 0.3467611 [.81;N5] -0.4631265
EATA_omit_meal 0.3595219 [.89;N5] -0.5300356
EATA_count_calories 0.2374333 [.8;N5] -0.5587664
EATA_restricted 0.2707860 [.87;N5] -0.5968116
EATB_cope_negaff 0.2411374 [.86;N6] -0.6159840
EATB_overeating 0.2455115 [.88;N6] -0.6374247
EATB_loss_ctrl 0.2464254 [.93;N6] -0.6840788

Table with highest loading scales with lowest S factor loading vor every higher order factor

# GStable = data.frame(matrix(nrow = 98, ncol = 10))
# names(GStable) = c("GP", "G1","D1","G3","C1","D2","B2","D3","M8","H7")
#
# for(i in 1:10){
#   temp = extractGS(bifloads[[names(GStable)[i]]], names(GStable)[i])
#   temp = temp[order(temp$G_minus_S, decreasing = T),]
#   for (k in 1:nrow(temp)){
#     # #two lines
#     # GStable[k,i] = paste(temp$scale[k],"<br>", paste0("GL = ", sub("0.", ".",round(temp$G[k], digits=2)),"; SL = ", sub("0.", ".",round(temp$S[k], digits = 2))),sep="")
#
#         GStable[k,i] = paste0(temp$scale[k],": ", paste0(sub("0.", ".",round(temp$G[k], digits=2))," [", sub("0.", ".",round(temp$S[k], digits = 2)),"]"))
#   }
#   GStable[1:length(temp$G_minus_S), paste0(names(GStable)[i], "_col")] = temp$G_minus_S
# }
#
# names(GStable)[1:10] = c("GP", "G1: Som Dep Det","D1: Distress","G3: GAD & PF","C1: Distress & Fear","D2: Fear","B2: Eating Disorder","D3: Psychosis & Ext","M8: Antagonism & PF","H7: EXT & Detachment")

# kable(GStable[,1:10],table.attr = "style='width:30%;'", escape = F)%>%  kable_styling("striped") %>%
#          kable_paper %>% add_footnote("Table 2. Factor loadings from bifactor models of all higher order factors identified in the bass ackwards procedure. Depicted are the 10 scales with the highest loading on the G factor and the lowest averaged S loadings in the bifactor model of the respective higher order factor depicted in the column header. GL = Standardized loading on G factor, SL = Averaged absolute standardized loadings on S factors.")


## with max S loadings
GStablemax = data.frame(matrix(nrow = 98, ncol = 10))
names(GStablemax) = c("GP", "G1","D1","G3","C1","D2","B2","D3","M8","H7")

for(i in 1:10){
  temp = extractGSmax(bifloads[[names(GStablemax)[i]]], names(GStablemax)[i])
  temp = temp[order(temp$G_minus_S, decreasing = T),]
  for (k in 1:nrow(temp)){
    # #two lines
    # GStablemax[k,i] = paste(temp$scale[k],"<br>", paste0("GL = ", sub("0.", ".",round(temp$G[k], digits=2)),"; SL = ", sub("0.", ".",round(temp$S[k], digits = 2))),sep="")

        GStablemax[k,i] = paste0(temp$scale[k],": ", paste0(sub("0.", ".",round(temp$G[k], digits=2)), temp$S[k]))
  }
  GStablemax[1:length(temp$G_minus_S), paste0(names(GStablemax)[i], "_col")] = temp$G_minus_S
}

names(GStablemax)[1:10] = c("GP", "G1: Depression & Detachment","D1: Distress","G3: GAD & PF","C1: Internalizing","D2: Fear","B2: Eating Disorder","D3: Thought Disorder & Externalizing","M8: Antagonism & PF","H7: Externalizing & Detachment")



## create colorful table
library(gt)
#GStable$colorval = temp$G_minus_S
gt(GStablemax) %>%
  data_color(
    columns = paste0(c("GP", "G1","D1","G3","C1","D2","B2","D3","M8","H7"), "_col"),
    colors = scales::col_numeric(
     # palette = c("red","white", "blue"),
      palette = c("red","white", "blue"),
      domain = c(-1,0,1),
      na.color = "#F1F1F1"
    ),
    target_columns = names(GStablemax)[1:10],

  ) %>% cols_hide(columns = names(GStablemax)[11:20])%>%
  fmt_markdown(columns = everything()) %>%
  fmt_missing(
  columns = everything(),
  rows = everything(),
  missing_text = "") %>%
  tab_style(
    style = cell_text(size=12),
    locations = cells_body(
      columns = everything()))%>%
   cols_align(
    align = "center") %>%
   tab_source_note (source_note = "Table 2. Standardized loadings on G factor for every scale from separate bifactor models defined for each higher order factor depicted in the column header and its respective lower order components as specific factors. Highest loading on specific factors in brackets. Scales in red have higher loadings on specific factors, scales in blue have higher loadings on the respective general factor.")
## Warning: Since gt v0.6.0 the `fmt_missing()` function is deprecated and will soon be
## removed.
## • Use the `sub_missing()` function instead.
## This warning is displayed once every 8 hours.
## Warning: Since gt v0.9.0, the `colors` argument has been deprecated.
## • Please use the `fn` argument instead.
## This warning is displayed once every 8 hours.
GP G1: Depression & Detachment D1: Distress G3: GAD & PF C1: Internalizing D2: Fear B2: Eating Disorder D3: Thought Disorder & Externalizing M8: Antagonism & PF H7: Externalizing & Detachment

PF_affect_tolrnce: .83[.05;N8]

PF_identity: .91[.07;N2]

PF_affect_diff: .89[.01;N8]

PF_affect_diff: .88[.04;N4]

PF_affect_diff: .88[.06;N8]

Agoraphobia: .69[.2;N1]

EATA_count_calories: .81[.22;N5]

PF_self_reflection: .85[.02;N7]

PF_affect_comm: .85[.09;N8]

DT_restr_affectivity: .73[.08;N10]

PF_identity: .9[.13;N2]

PF_self_reflection: .86[.09;N2]

PF_identity: .91[.09;N4]

PF_identity: .89[.12;N4]

PF_identity: .9[.13;N4]

Spec_phob_avoid: .7[.23;N1]

EATA_omit_meal: .89[.35;N5]

PF_identity: .91[.14;N8]

PF_intern_relshp_mod: .74[.04;N8]

PF_affect_comm: .76[.17;N8]

PF_affect_diff: .85[.09;N2]

PF_affect_diff: .87[.11;N2]

PF_affect_tolrnce: .83[.07;N8]

DEP_decision_probl: .75[.01;N4]

PF_affect_tolrnce: .83[.08;N4]

Somatic_symptoms: .62[.24;N3]

EATA_purging_behv: .79[.28;N5]

PF_affect_diff: .87[.14;N8]

PF_anticipation: .74[.04;N8]

DT_withdrawal: .62[.07;N10]

PF_self_reflection: .83[.11;N2]

DEP_psycmot_agit: .74[.07;N2]

PF_self_reflection: .85[.11;N4]

DEP_rumination: .77[.07;N4]

PF_self_reflection: .83[.13;N4]

Hypochondriasis: .49[.18;N3]

EATA_time_frames: .81[.34;N5]

PF_affect_tolrnce: .83[.11;N8]

PS_eccentricity: .75[.07;N8]

PF_forming_relshps: .59[.04;N8]

PS_eccentricity: .72[.24;N7]

DEP_rumination: .75[.19;N2]

DEP_psycmot_agit: .73[.16;N2]

PF_affect_tolrnce: .81[.11;N8]

OCD_sympt: .62[.04;N4]

SAD_eating: .7[.4;N1]

EATA_exces_exercise: .81[.41;N5]

DEP_rumination: .72[.04;N8]

DT_suspiciousness: .67[.03;N8]

PF_intern_relshp_mod: .77[.23;N10]

Dissociation: .72[.24;N7]

DEP_decision_probl: .74[.22;N2]

OCD_sympt: .61[.08;N4]

DEP_psycmot_agit: .75[.05;N4]

DEP_psycmot_agit: .72[.17;N2]

SAD_being_observ: .71[.42;N1]

EATA_restricted: .8[.49;N5]

PF_self_est_reg: .69[.14;N8]

NA_perseveration: .64[.13;N8]

DT_intimcy_avoid: .6[.08;N10]

OCD_sympt: .62[.16;N7]

NA_perseveration: .62[.11;N9]

DEP_rumination: .73[.26;N2]

PF_self_reflection: .85[.16;N4]

NA_sep_insecur: .61[.13;N8]

Panic_avoid_behv: .61[.39;N3]

EATB_soc_disguised: .66[.42;N6]

NA_sep_insecur: .6[.09;N8]

PF_self_est_reg: .67[.18;N8]

PF_self_est_reg: .67[.23;N8]

DEP_psycmot_agit: .69[.23;N2]

PF_self_est_reg: .7[.26;N2]

NA_sep_insecur: .58[.17;N8]

DEP_concentration: .71[.02;N4]

DEP_rumination: .72[.27;N2]

SAD_devaluation: .73[.54;N1]

EATA_fear_weightg: .63[.54;N13]

NA_perseveration: .64[.14;N8]

PF_forming_relshps: .56[.08;N8]

PF_anticipation: .64[.2;N8]

NA_sep_insecur: .6[.14;N8]

Somatic_symptoms: .62[.2;N9]

DEP_decision_probl: .67[.31;N2]

PF_self_est_reg: .7[.14;N8]

NA_perseveration: .62[.2;N8]

SAD_performing: .67[.52;N1]

EATA_fear_weightl: .31[.27;N13]

PF_intern_relshp_mod: .69[.27;N8]

PF_holistic_percptn: .64[.21;N11]

DT_suspiciousness: .7[.28;N10]

NA_perseveration: .63[.18;N8]

DEP_depr_mood: .76[.35;N2]

DI_perfectionism: .44[.12;N4]

OCD_sympt: .61[.05;N4]

DEP_decision_probl: .7[.3;N2]

Spec_phob_animals: .53[.39;N12]

EATB_worries: .62[.59;N13]

PS_eccentricity: .71[.29;N7]

NA_sep_insecur: .58[.22;N8]

PS_eccentricity: .67[.26;N8]

PF_intern_relshp_mod: .69[.26;N8]

DEP_suicid_intent: .59[.21;N2]

NA_perseveration: .56[.24;N8]

NA_sep_insecur: .6[.15;N8]

Somatic_symptoms: .65[.25;N3]

SAD_avoidance: .72[.58;N1]

EATA_body_selfest: .59[.61;N13]

OCD_sympt: .6[.2;N7]

DI_impulsivity: .63[.32;N11]

NA_perseveration: .6[.23;N8]

Somatic_symptoms: .66[.25;N3]

DEP_concentration: .7[.32;N9]

DEP_suicid_intent: .57[.27;N2]

NA_perseveration: .63[.19;N8]

PF_intern_relshp_mod: .67[.29;N8]

Panic_fear_recurr: .64[.53;N3]

EATB_intrus_thoughts: .45[.61;N6]

DI_impulsivity: .63[.26;N11]

PF_identity: .76[.46;N8]

DEP_crying_inab: .57[.22;N10]

DI_impulsivity: .64[.24;N11]

DEP_crying_inab: .58[.2;N10]

PF_self_est_reg: .64[.36;N2]

DI_perfectionism: .45[.1;N4]

DI_perfectionism: .46[.09;N4]

Spec_phob_blood: .46[.37;N12]

DEP_incr_appetite: .33[.51;N6]

Dissociation: .68[.33;N7]

PF_impulse_reg: .63[.34;N11]

PF_holistic_percptn: .58[.26;N11]

DT_suspiciousness: .61[.24;N8]

DEP_guilt: .73[.36;N2]

DEP_crying: .48[.21;N2]

GAD_excess_worry: .78[.47;N4]

PS_eccentricity: .69[.32;N8]

SAD_soc_inter: .65[.62;N1]

EATB_loss_ctrl: .37[.88;N6]

PF_holistic_percptn: .58[.25;N11]

DEP_rumination: .62[.36;N8]

DEP_emot_numbn: .65[.37;N10]

DEP_rumination: .68[.33;N2]

PF_intern_relshp_mod: .65[.29;N10]

PS_eccentricity: .63[.38;N8]

PS_eccentricity: .65[.39;N8]

PF_self_est_reg: .67[.33;N2]

Panic_dysf_thought: .63[.6;N3]

EATB_overeating: .34[.85;N6]

DT_suspiciousness: .6[.29;N8]

PF_affect_tolrnce: .71[.48;N8]

DI_impulsivity: .57[.29;N11]

PF_holistic_percptn: .59[.23;N11]

DEP_dimin_interest: .72[.4;N9]

DEP_depr_mood: .69[.44;N2]

PF_intern_relshp_mod: .63[.38;N8]

DEP_concentration: .67[.34;N9]

Spec_phob_fear: .66[.68;N12]

EATB_cope_negaff: .31[.84;N6]

PF_affect_comm: .73[.44;N8]

PF_affect_diff: .73[.53;N8]

PF_identity: .74[.49;N8]

DEP_decision_probl: .68[.33;N2]

DEP_emot_numbn: .62[.31;N10]

DEP_concentration: .61[.37;N9]

GAD_nervousness: .75[.53;N4]

DEP_suicid_intent: .57[.27;N2]

SAD_attractive_pers: .44[.51;N1]

PF_anticipation: .65[.37;N8]

DI_irresponsibility: .42[.24;N11]

DEP_rumination: .61[.38;N8]

DI_perfectionism: .45[.12;N4]

DEP_crying: .48[.18;N2]

GAD_excess_worry: .75[.51;N4]

GAD_irritability: .67[.46;N4]

GAD_excess_worry: .78[.48;N4]

DT_withdrawal: .38[.45;N1]

DEP_crying_inab: .55[.3;N10]

AN_hostility: .55[.4;N11]

DI_irresponsibility: .41[.21;N14]

DEP_concentration: .66[.33;N9]

DT_anhedonia: .6[.3;N10]

DEP_guilt: .68[.44;N2]

DI_impulsivity: .56[.37;N8]

DEP_dimin_interest: .68[.39;N9]

Panic_phys_symp: .57[.64;N3]

DEP_dimin_interest: .68[.44;N10]

AN_grandiosity: .46[.37;N11]

DEP_dimin_interest: .68[.5;N10]

PF_self_est_reg: .66[.34;N2]

DEP_worthlessn: .72[.42;N2]

DI_impulsivity: .55[.35;N8]

PF_forming_relshps: .45[.26;N8]

DI_impulsivity: .6[.31;N8]

DT_restr_affectivity: .38[.48;N1]

PF_impulse_reg: .6[.37;N11]

AN_deceitfulness: .48[.53;N11]

DT_anhedonia: .66[.52;N10]

DEP_crying_inab: .56[.27;N10]

DEP_dimin_selfconf: .72[.43;N2]

PF_intern_relshp_mod: .53[.34;N8]

GAD_free_float_anx: .75[.56;N4]

DT_suspiciousness: .58[.3;N8]

Panic_attacks: .51[.72;N3]

DT_restr_affectivity: .59[.39;N10]

AN_callousness: .36[.52;N11]

PF_affect_diff: .69[.55;N8]

DEP_suicid_intent: .57[.28;N2]

DEP_loss_appetite: .47[.18;N9]

DEP_loss_appetite: .41[.23;N9]

PF_anticipation: .59[.43;N8]

Spec_phob_avoid: .6[.32;N1]

PF_forming_relshps: .34[.6;N1]

DI_irresponsibility: .41[.21;N14]

AN_manipulativns: .33[.54;N11]

PF_impulse_reg: .54[.41;N11]

DEP_loss_appetite: .48[.2;N9]

DT_suspiciousness: .55[.29;N10]

GAD_irritability: .65[.48;N4]

DT_suspiciousness: .54[.41;N8]

Hypochondriasis: .48[.21;N3]

Panic_doctor_visits: .37[.68;N3]

PF_forming_relshps: .48[.31;N8]

AN_entitlement: .22[.45;N11]

NA_sep_insecur: .5[.36;N8]

Hypochondriasis: .49[.21;N3]

DEP_reduc_energy: .71[.48;N9]

GAD_nervousness: .72[.57;N4]

PF_affect_comm: .65[.53;N8]

DEP_depr_mood: .71[.44;N2]

DT_intimcy_avoid: .45[.29;N10]

AN_hostility: .54[.42;N11]

PS_percept_dysreg: .64[.37;N7]

DEP_hopelessn: .67[.46;N2]

DEP_worthlessn: .65[.51;N2]

PF_impulse_reg: .52[.44;N8]

DEP_crying_inab: .55[.29;N10]

PS_percept_dysreg: .59[.44;N7]

AN_grandiosity: .48[.37;N11]

DEP_dimin_interest: .66[.4;N2]

DEP_psycmot_inhib: .55[.34;N9]

GAD_free_float_anx: .72[.6;N4]

PF_holistic_percptn: .52[.43;N8]

DEP_crying: .47[.22;N2]

DEP_emot_numbn: .6[.48;N10]

Manic_sympt: .36[.35;N14]

PF_affect_comm: .72[.46;N8]

DEP_circad_mood_fluct: .4[.26;N9]

DEP_dimin_interest: .57[.46;N9]

DEP_loss_appetite: .46[.21;N9]

DT_withdrawal: .48[.37;N10]

PF_affect_tolrnce: .62[.62;N8]

PF_impulse_reg: .59[.36;N11]

DEP_hypersomnia: .37[.29;N9]

DEP_crying_inab: .43[.33;N10]

DEP_guilt: .68[.44;N2]

Manic_sympt: .36[.29;N14]

DI_risk_taking: .38[.39;N14]

Spec_phob_avoid: .58[.35;N1]

DT_restr_affectivity: .58[.57;N10]

DEP_dimin_selfconf: .61[.53;N2]

GAD_irritability: .68[.45;N4]

DT_anhedonia: .59[.57;N10]

AN_callousness: .42[.47;N11]

DEP_crying: .46[.25;N2]

DEP_loss_libido: .26[.27;N9]

PF_impulse_reg: .5[.42;N8]

DT_anhedonia: .56[.37;N10]

AN_hostility: .48[.47;N11]

AN_deceitfulness: .43[.55;N11]

Agoraphobia: .57[.36;N1]

DT_withdrawal: .47[.49;N10]

DT_suspiciousness: .43[.36;N8]

PF_affect_comm: .69[.49;N8]

AN_grandiosity: .42[.42;N11]

AN_manipulativns: .35[.5;N11]

DEP_guilt: .66[.46;N2]

DT_intimcy_avoid: .43[.56;N10]

DEP_circad_mood_fluct: .34[.29;N9]

GAD_nervousness: .74[.54;N4]

DI_risk_taking: .38[.38;N14]

Subst_use_drug: .25[.5;N14]

DI_irresponsibility: .4[.2;N14]

PF_holistic_percptn: .48[.43;N8]

Panic_avoid_behv: .59[.41;N3]

Psychotic_symptoms: .53[.61;N7]

AN_entitlement: .19[.47;N11]

DEP_psycmot_inhib: .56[.37;N9]

DEP_psycmot_inhib: .46[.41;N9]

PF_impulse_reg: .56[.38;N8]

AN_deceitfulness: .45[.54;N11]

Subst_use_alc: 0[.36;N14]

DT_anhedonia: .56[.37;N10]

PF_anticipation: .53[.48;N8]

PF_holistic_percptn: .55[.38;N8]

PS_unusual_beliefs: .49[.68;N7]

DI_normviolation: .31[.69;N14]

DEP_depr_mood: .68[.49;N2]

DEP_hopelessn: .6[.56;N2]

Agoraphobia: .55[.38;N1]

AN_manipulativns: .33[.52;N11]

PF_anticipation: .62[.43;N8]

DEP_reduc_energy: .58[.55;N9]

PF_anticipation: .6[.43;N8]

Subst_use_drug: .26[.51;N14]

DEP_emot_numbn: .6[.41;N10]

PF_affect_comm: .6[.57;N8]

DEP_psycmot_inhib: .54[.37;N9]

AN_callousness: .3[.56;N11]

Panic_avoid_behv: .59[.41;N3]

DEP_hypersomnia: .29[.34;N9]

DEP_reduc_energy: .67[.5;N9]

AN_entitlement: .19[.47;N11]

GAD_excess_worry: .73[.55;N4]

DT_anhedonia: .35[.42;N10]

GAD_free_float_anx: .74[.57;N4]

Subst_use_alc: .02[.37;N14]

DEP_worthlessn: .65[.5;N2]

DEP_emot_numbn: .41[.49;N10]

DEP_dimin_selfconf: .66[.5;N2]

DI_normviolation: .32[.67;N14]

DEP_reduc_energy: .64[.5;N9]

DEP_loss_libido: .18[.29;N9]

DEP_emot_numbn: .58[.43;N10]

GAD_irritability: .64[.5;N4]

Somatic_symptoms: 0[.37;N9]

DEP_worthlessn: .66[.5;N2]

Manic_sympt: .41[.27;N14]

PF_forming_relshps: 0[.38;N8]

DEP_circad_mood_fluct: .4[.27;N9]

DEP_circad_mood_fluct: .4[.27;N9]

DT_intimcy_avoid: .11[.65;N10]

SAD_devaluation: .7[.59;N1]

SAD_eating: .62[.51;N1]

DT_withdrawal: 0[.67;N10]

SAD_eating: .6[.52;N1]

SAD_devaluation: .7[.59;N1]

DT_restr_affectivity: 0[.8;N10]

DEP_hypersomnia: .37[.31;N9]

DEP_dimin_selfconf: .64[.53;N2]

DT_withdrawal: .46[.41;N10]

DEP_hypersomnia: .38[.31;N9]

SAD_being_observ: .6[.56;N1]

DT_withdrawal: .47[.4;N10]

DEP_hopelessn: .6[.55;N2]

GAD_nervousness: .68[.62;N4]

DT_restr_affectivity: .56[.54;N10]

SAD_being_observ: .61[.55;N1]

PF_forming_relshps: .45[.43;N1]

DT_restr_affectivity: .58[.52;N10]

Panic_fear_recurr: .58[.59;N3]

Psychotic_symptoms: .59[.54;N7]

SAD_attractive_pers: .45[.48;N1]

GAD_free_float_anx: .68[.64;N4]

DEP_loss_libido: .25[.28;N9]

PF_forming_relshps: .45[.42;N1]

SAD_performing: .58[.62;N1]

DI_risk_taking: .39[.36;N14]

SAD_avoidance: .63[.67;N1]

DEP_hopelessn: .58[.57;N2]

Panic_dysf_thought: .59[.64;N3]

AN_grandiosity: .43[.42;N11]

DT_intimcy_avoid: .42[.5;N10]

AN_hostility: .48[.47;N11]

SAD_soc_inter: .57[.71;N1]

EATA_fear_weightl: .26[.27;N13]

Panic_attacks: .51[.7;N3]

SAD_attractive_pers: .46[.47;N1]

Spec_phob_blood: .31[.51;N12]

DT_intimcy_avoid: .45[.48;N10]

Spec_phob_animals: .36[.56;N12]

SAD_performing: .58[.62;N1]

Panic_phys_symp: .5[.71;N3]

Panic_fear_recurr: .56[.6;N3]

Spec_phob_fear: .5[.77;N12]

EATB_soc_disguised: .43[.47;N6]

Panic_doctor_visits: .3[.73;N3]

AN_deceitfulness: .47[.51;N11]

DEP_loss_libido: .23[.28;N9]

SAD_avoidance: .63[.68;N1]

Panic_dysf_thought: .59[.64;N3]

PS_unusual_beliefs: .56[.63;N7]

EATB_worries: .5[.59;N13]

SAD_soc_inter: .58[.69;N1]

AN_manipulativns: .37[.49;N11]

EATA_body_selfest: .45[.64;N13]

Spec_phob_animals: .37[.56;N12]

EATA_fear_weightg: .41[.6;N13]

Spec_phob_blood: .32[.51;N12]

Panic_attacks: .5[.7;N3]

DEP_incr_appetite: .32[.53;N6]

Panic_phys_symp: .49[.71;N3]

EATA_purging_behv: .33[.55;N5]

Subst_use_drug: .27[.5;N14]

AN_entitlement: .21[.46;N11]

EATB_intrus_thoughts: .4[.65;N6]

EATA_exces_exercise: .28[.53;N5]

AN_callousness: .3[.57;N11]

Spec_phob_fear: .5[.78;N12]

DI_normviolation: .35[.65;N14]

Subst_use_alc: .01[.39;N14]

Panic_doctor_visits: .28[.74;N3]

EATA_time_frames: .35[.81;N5]

EATA_omit_meal: .36[.89;N5]

EATA_count_calories: .24[.8;N5]

EATA_restricted: .27[.87;N5]

EATB_cope_negaff: .24[.86;N6]

EATB_overeating: .25[.88;N6]

EATB_loss_ctrl: .25[.93;N6]

Table 2. Standardized loadings on G factor for every scale from separate bifactor models defined for each higher order factor depicted in the column header and its respective lower order components as specific factors. Highest loading on specific factors in brackets. Scales in red have higher loadings on specific factors, scales in blue have higher loadings on the respective general factor.
# %>%
#   tab_options(., container.width = 1500)



# %>%
#   tab_row_group(
#     label = "Factor loadings of the 10 scales with the highest loading on the G factor and the lowest averaged S loadings in the bifactor model of the respective higher order factor depicted in the column header. GL = Standardized loading on G factor, SL = Averaged absolute standardized loadings on S factors.",
#     rows = 1:10, id= "t1") %>%
#   tab_row_group(
#     label = "Pearson correlations with Holm-Bonferroni adjusted confidence intervals between separately estimated lower order components without crossloadings of PF scales, i.e. only the PF Problems (N8) factor loading on PF scales, and higher order components estimated using bifactor models.",
#     rows = 11:24, id = "t2" ) %>%
#    row_group_order(groups = c("t1","t2")) %>%

# tab_source_note(html('<pre><span style="background-color: blue;"
#                        >        </span> = Higher</pre>'))

Table with latent correlation between the 14 factors and higher order factors from bifactor models (PF scales only loading on N8)

## function for factor scores with id
fsnidextr.func = function(model, data,var){
  Data_id <- data[c("id", lavNames(model, "ov") )]
  CompleteData_id <- na.omit(Data_id)
  CompleteData_id[,var] <-  predict(model, CompleteData_id)[,var]
  return(CompleteData_id[,c("id",var)])
}



## estimate all 14 factors separately (without PF)

n9model="
#N9
N9_Somatic_Dep =~ DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms + NA_perseveration
"
n9model = cfa(n9model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n2model="
#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl + DEP_rumination + DEP_psycmot_agit + DEP_reduc_energy + DEP_concentration + DT_anhedonia
"
n2model = cfa(n2model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n8model="
#N8
N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity
"
n8model = cfa(n8model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


n4model="
#N4
N4_GAD_OCD =~ GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit  + OCD_sympt + DI_perfectionism  + DEP_concentration + DEP_decision_probl
"
n4model = cfa(n4model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


n1model="
#N1
N1_Soc_Phob =~ SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers  + Spec_phob_avoid + Agoraphobia + DT_restr_affectivity + DT_withdrawal
"
n1model = cfa(n1model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


n3model="
#N3
N3_Panic =~ Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis
"
n3model = cfa(n3model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


n12model="
#N12
N12_Spec_Phob =~ Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid
"
n12model = cfa(n12model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n13model="
#N13
N13_EAT_thoughts =~  EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + EATA_exces_exercise + EATB_soc_disguised
"
n13model = cfa(n13model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n6model="
#N6
N6_EAT_purging =~ EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg
"
n6model = cfa(n6model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n5model="
#N5
N5_EAT_restr =~ EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg
"
n5model = cfa(n5model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n10model="
#N10
N10_Detachment =~ DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest + DT_suspiciousness
"
n10model = cfa(n10model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n7model="
#N7
N7_Thought_Disorder =~ PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PS_eccentricity  + Manic_sympt  + DEP_crying_inab  + OCD_sympt
"
n7model = cfa(n7model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n11model="
#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity  + DI_impulsivity + DI_irresponsibility
"
n11model = cfa(n11model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

n14model="
#N14
N14_EXT_Dis =~  Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt + DI_impulsivity
"
n14model = cfa(n14model, sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)





# create data frame with factor scores of higher order and base factors
scoreframe = data.frame(fsnidextr.func(M8bifactmodel, data_scale, "M8"))
scoreframe = merge(scoreframe,fsnidextr.func(GPbifactmodel, data_scale, "GP"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(G1bifactmodel, data_scale, "G1"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(G3bifactmodel, data_scale, "G3") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(D1bifactmodel, data_scale, "D1"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(D2bifactmodel, data_scale, "D2"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(C1bifactmodel, data_scale, "C1"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(H7bifactmodel, data_scale, "H7") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(D3bifactmodel, data_scale, "D3"), all.x = T )
scoreframe = merge(scoreframe,fsnidextr.func(B2bifactmodel, data_scale, "B2") , all.x = T)

scoreframe = merge(scoreframe,fsnidextr.func(n8model, data_scale, "N8_PF_Problems") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n9model, data_scale, "N9_Somatic_Dep") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n2model, data_scale, "N2_Depression") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n4model, data_scale, "N4_GAD_OCD") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n1model, data_scale, "N1_Soc_Phob") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n3model, data_scale, "N3_Panic") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n12model, data_scale, "N12_Spec_Phob") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n13model, data_scale, "N13_EAT_thoughts") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n6model, data_scale, "N6_EAT_purging") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n5model, data_scale, "N5_EAT_restr") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n10model, data_scale, "N10_Detachment") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n7model, data_scale, "N7_Thought_Disorder") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n11model, data_scale, "N11_EXT_Ant") , all.x = T)
scoreframe = merge(scoreframe,fsnidextr.func(n14model, data_scale, "N14_EXT_Dis") , all.x = T)



##correlation frame
scoreframe = scoreframe[,-1]
cordata = corr.test(scoreframe[,11:24], scoreframe[,c(2,3,5,4,7,6,10,9,1,8)] ,use="pairwise.complete.obs")
corframe = data.frame(cordata$r)
corframe$cormean = rowMeans(corframe)
corframe = round(corframe, digits =2)
ciframe = cordata$ci.adj
ciframe = round(ciframe, digits =2)

## create table with r and holm corrected CIs
for (i in 1:nrow(corframe)){
  for (k in 1: (ncol(corframe) - 1)){
    corframe[i,k] = sub("0.", ".",paste0(ciframe$r[((k-1) * 14) + i], " [", ciframe$lower.adj[((k-1) * 14) + i], ", ", ciframe$upper.adj[((k-1) * 14) + i], "]"))
  }

}


kable(corframe,table.attr = "style='width:30%;'") %>%
        kable_styling("striped") %>%
         kable_paper %>% add_footnote("Table 3. Correlations between separately estimated lower order components without crossloadings of PF scales, i.e. only the PF Problems (N8) factor loading on PF scales, and higher order components estimated using bifactor models.")

#corframe = corframe[order(rownames(corframe)),]
# test = corswithconf.func(pfscores,hiermodelscores)
# #kable(corswithconf.func(pfscores,hiermodelscores)) %>% kable_classic


# openxlsx::write.xlsx(corswithconf.func(pfscores,hiermodelscores[,c(19,16,15,1,11,2,4,3,17,5,6,7,18,8,9,10,21,12,20,13,14)]), "Tables/pfhiercor.xlsx",rowNames = T)

Estimate S-1 and print correlogram comparing it with correlated factors model (PF scales only loading on n8)

compswoPFcrossload = "

#N9
N9_Somatic_Dep =~  DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_anhedonia + DEP_depr_mood + DEP_dimin_selfconf + DEP_dimin_interest + DEP_decision_probl + Somatic_symptoms

#N2
N2_Depression =~  DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl  + DEP_psycmot_agit + DEP_reduc_energy + DEP_concentration + DT_anhedonia

# #N8
# N8_PF_Problems =~  DEP_rumination  + PS_eccentricity + NA_sep_insecur + DT_suspiciousness + NA_perseveration + DI_impulsivity

#N4
N4_GAD_OCD =~  GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry  + DEP_psycmot_agit  + OCD_sympt + DI_perfectionism + DEP_concentration + DEP_decision_probl

#N1
N1_Soc_Phob =~ SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers + Spec_phob_avoid + Agoraphobia + DT_restr_affectivity + DT_withdrawal

#N3
N3_Panic =~ Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis

#N12
N12_Spec_Phob =~  Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + SAD_performing + Spec_phob_avoid

#N13
N13_EAT_thoughts =~  EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + EATA_exces_exercise + EATB_soc_disguised

#N6
N6_EAT_purging =~ EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg

#N5
N5_EAT_restr =~ EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_soc_disguised + EATA_body_selfest + EATB_worries + EATA_fear_weightg

#N10
N10_Detachment =~  DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + DEP_dimin_interest

#N7
N7_Thought_Disorder =~   PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation  + Manic_sympt  + DEP_crying_inab + OCD_sympt

#N11
N11_EXT_Ant =~  AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity   + DI_irresponsibility


#N14
N14_EXT_Dis =~  Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility + Manic_sympt

"

s1wn8asref = "
# general factor
N8_PF_Problems =~  PF_affect_comm + PF_affect_diff + PF_affect_tolrnce +  PF_forming_relshps + PF_holistic_percptn + PF_identity + PF_impulse_reg +PF_intern_relshp_mod + PF_self_reflection + PF_self_est_reg + PF_anticipation +
SAD_soc_inter + SAD_avoidance + SAD_performing + SAD_devaluation + SAD_being_observ + SAD_eating + SAD_attractive_pers  + Spec_phob_avoid + Agoraphobia + DEP_hopelessn + DEP_depr_mood + DEP_dimin_selfconf + DEP_worthlessn + DEP_suicid_intent + DEP_dimin_interest + DEP_guilt + DEP_crying + DEP_decision_probl  + Panic_doctor_visits + Panic_attacks + Panic_phys_symp + Panic_dysf_thought + Panic_fear_recurr + Panic_avoid_behv + Somatic_symptoms + Hypochondriasis + GAD_free_float_anx + GAD_nervousness + GAD_irritability + GAD_excess_worry + DEP_rumination + DEP_psycmot_agit  + OCD_sympt + DI_perfectionism + EATA_restricted + EATA_omit_meal + EATA_time_frames + EATA_count_calories + EATA_purging_behv + EATA_exces_exercise + EATB_loss_ctrl + EATB_cope_negaff + EATB_overeating + EATB_intrus_thoughts + DEP_incr_appetite + EATB_soc_disguised + PS_unusual_beliefs + PS_percept_dysreg + Psychotic_symptoms + Dissociation + PS_eccentricity  + Manic_sympt    + NA_sep_insecur + DT_suspiciousness   + NA_perseveration  + DEP_psycmot_inhib + DEP_reduc_energy + DEP_hypersomnia + DEP_circad_mood_fluct + DEP_concentration + DEP_loss_appetite + DEP_loss_libido + DT_intimcy_avoid + DT_restr_affectivity + DT_withdrawal + DEP_emot_numbn + DEP_crying_inab + DT_anhedonia + AN_callousness + AN_hostility + AN_deceitfulness + AN_manipulativns + AN_entitlement + AN_grandiosity  + DI_impulsivity + Spec_phob_fear + Spec_phob_animals + Spec_phob_blood + EATA_body_selfest + EATB_worries + EATA_fear_weightg + EATA_fear_weightl + Subst_use_drug + DI_normviolation + Subst_use_alc + DI_risk_taking + DI_irresponsibility



#P Functioning as S factor
N8_PF_Problems ~~ 0*N5_EAT_restr
N8_PF_Problems ~~ 0*N1_Soc_Phob
N8_PF_Problems ~~ 0*N2_Depression
N8_PF_Problems ~~ 0*N3_Panic
N8_PF_Problems ~~ 0*N4_GAD_OCD
N8_PF_Problems ~~ 0*N6_EAT_purging
N8_PF_Problems ~~ 0*N7_Thought_Disorder
N8_PF_Problems ~~ 0*N9_Somatic_Dep
N8_PF_Problems ~~ 0*N10_Detachment
N8_PF_Problems ~~ 0*N11_EXT_Ant
N8_PF_Problems ~~ 0*N12_Spec_Phob
N8_PF_Problems ~~ 0*N13_EAT_thoughts
N8_PF_Problems ~~ 0*N14_EXT_Dis
"

#N8
N8comp =
"N8_PF_Problems =~ PF_anticipation + PF_affect_comm + PF_intern_relshp_mod + NA_sep_insecur + DT_suspiciousness + PF_holistic_percptn + PF_self_est_reg + NA_perseveration + PF_affect_tolrnce + PF_impulse_reg + DI_impulsivity + PF_forming_relshps + DEP_rumination + PF_affect_diff + PS_eccentricity + PF_identity "


#### estimate standard bifactor and correlated factors model
## ML
basemodel.ml <- cfa(model = paste0(compswoPFcrossload, N8comp), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)

s1model.ml <- cfa(model = paste0(compswoPFcrossload, s1wn8asref), sample.cov = scale_cov, sample.nobs = 27173, std.lv = T)


# basemodel.wlsmv <- cfa(model = paste0(basemodel), data_scale, missing = "pairwise", estimator = "WLSMV",start = "Mplus", std.lv = T)
#
#
# basebifactor.wlsmv = cfa(model = paste0(basemodel,orth, pfuncbifact), data_scale, missing = "pairwise", estimator = "WLSMV",start = "Mplus", std.lv = T)


## correlogram of correlated and S1 model:
svars = c( "N8_PF_Problems",
 "N9_Somatic_Dep" ,      "N2_Depression"  ,
  "N4_GAD_OCD"  ,
 "N1_Soc_Phob"      ,   "N3_Panic"       ,     "N12_Spec_Phob"      ,
    "N13_EAT_thoughts"  ,  "N6_EAT_purging"   ,
 "N5_EAT_restr"         ,   "N7_Thought_Disorder", "N10_Detachment",
      "N11_EXT_Ant"   ,      "N14_EXT_Dis"        )


scors.corm = data.frame(inspect(basemodel.ml, what = "cor.all"))[svars,svars]
names(scors.corm) = c("N8:PF Problems", "N9:Som. Depr.", "N2:Cogn. Depr.", "N4:GAD & OCD", "N1:SAD & Agor.", "N3:Panic & Som.", "N12:Spec. Phob.", "N13:ED Thoughts", "N6:ED Bulimic", "N5:ED Anorectic", "N7:Thought Dis.", "N10:Detachment", "N11:Antagonism", "N14:Disinhibition")
rownames(scors.corm) = names(scors.corm)
corPlot(scors.corm, xlas = 2, xpd = TRUE,mar = c(6, 6, 6, 6))

scors.s1 = data.frame(inspect(s1model.ml, what = "cor.all"))[svars,svars]
names(scors.s1) = names(scors.corm)
rownames(scors.s1) = names(scors.s1)
corPlot(scors.s1, xlas = 2, xpd = TRUE,mar = c(6, 6, 6, 6))

compare models and other stuff