#options
options(
digits = 3
)
#packages
library(pacman)
p_load(
kirkegaard,
rms,
mirt,
sirt,
readxl,
lavaan,
lavaanPlot,
ggeffects,
ggrepel
)
#set the theme for all plots
theme_set(theme_bw())
#describe modification
describe2 = function(...) {
y = psych::describe(...)
class(y) = "data.frame"
y %>% rownames_to_column(var = "var") %>% select(var, n, mean, median, sd, mad, min, max, skew)
}
#print return
print2 = function(x) {
print(x)
x
}
#define a convenience function for DIF testing
#this is reused from the VES measurement study
#
DIF_test = function(items, model, group, fscores_pars = list(full.scores = T, full.scores.SE = T), messages = T, method = "EM", technical = list()) {
# browser()
#regular fit joint group
if (messages) message("There are 8 steps")
if (messages) message("Step 1: Initial joint fit\n")
mirt_fit = mirt(items, model = model, method = method, technical = technical)
#step 3
if (!is.character(group) && !is.factor(group)) group = factor(group)
if (messages) message("\nStep 2: Initial MI fit")
mirt_fit_MI = multipleGroup(items, model = model, group = group, invariance = c('intercepts','slopes', 'free_means', 'free_var'), method = method, technical = technical)
#DIFs
if (messages) message("\nStep 3: Leave one out MI testing")
DIFs = DIF(mirt_fit_MI,
which.par = c('a1', 'd'),
scheme = 'drop',
method = method,
technical = technical
)
DIFs = DIFs %>% rownames_to_column("item")
DIFs$number = 1:nrow(DIFs)
#adjust p values
DIFs$p_adj = DIFs$p * nrow(DIFs)
#with significant DIF
DIFs_detected_liberal = DIFs %>% filter(p < .05)
DIFs_detected_conservative = DIFs %>% filter(p_adj < .05)
#subset itmes
items_noDIF_liberal = items %>% select(!!setdiff(DIFs$item, DIFs_detected_liberal$item))
items_noDIF_conservative = items %>% select(!!setdiff(DIFs$item, DIFs_detected_conservative$item))
#subset models
#tricky!
#if its a g only model, we dont have to do anything
#but if its complex we need name format or Q matrix format
#extract loadings matrix
#convert to Q matrix
# browser()
mirt_fit_loadings = mirt_fit@Fit$`F`
model_noDIF_liberal_Q = mirt_fit_loadings %>% apply(MARGIN = 2, as.logical) %>% set_rownames(rownames(mirt_fit_loadings))
model_noDIF_conservative_Q = model_noDIF_liberal_Q
#set unused items' rows to FALSE
model_noDIF_liberal_Q[DIFs_detected_liberal$item, ] = F
model_noDIF_conservative_Q[DIFs_detected_conservative$item, ] = F
#fit together without DIF
if (messages) message("\nStep 4: Fit without DIF items, liberal threshold")
mirt_fit_noDIF_liberal = mirt(items, model = mirt.model(model_noDIF_liberal_Q), method = method, technical = technical)
if (messages) message("\nStep 5: Fit without DIF items, conservative threshold")
mirt_fit_noDIF_conservative = mirt(items, model = mirt.model(model_noDIF_conservative_Q), method = method, technical = technical)
#with anchors
if (messages) message("\nStep 6: Fit with anchor items, liberal threshold")
mirt_fit_anchors_liberal = multipleGroup(items, model = model, group = group, invariance = c(items_noDIF_liberal %>% names(), 'free_means', 'free_var'), method = method, technical = technical)
if (messages) message("\nStep 7: Fit with anchor items, conservative threshold")
mirt_fit_anchors_conservative = multipleGroup(items, model = model, group = group, invariance = c(items_noDIF_conservative %>% names(), 'free_means', 'free_var'), method = method, technical = technical)
#get scores
if (messages) message("\nStep 8: Get scores")
orig_scores = do.call(what = mirt::fscores, args = c(list(object = mirt_fit), fscores_pars))
noDIF_scores_liberal = do.call(what = mirt::fscores, args = c(list(object = mirt_fit_noDIF_liberal), fscores_pars))
noDIF_scores_conservative = do.call(what = mirt::fscores, args = c(list(object = mirt_fit_noDIF_conservative), fscores_pars))
anchor_scores_liberal = do.call(what = mirt::fscores, args = c(list(object = mirt_fit_anchors_liberal), fscores_pars))
anchor_scores_conservative = do.call(what = mirt::fscores, args = c(list(object = mirt_fit_anchors_conservative), fscores_pars))
#in a data frame
scores = list(
#original scores
original = orig_scores,
#after DIF removal
noDIF_liberal = noDIF_scores_liberal,
noDIF_conservative = noDIF_scores_conservative,
#anchor scores
anchor_liberal = anchor_scores_liberal,
anchor_conservative = anchor_scores_conservative
)
#effect sizes
#this only works with 1 dimensional models
#https://groups.google.com/forum/#!topic/mirt-package/hAj7jfdzsxY
if (ncol(mirt_fit_loadings) == 1) {
#item level
effect_size_items = list(
liberal = empirical_ES(mirt_fit_anchors_liberal, DIF = T, plot = F),
conservative = empirical_ES(mirt_fit_anchors_conservative, DIF = T, plot = F)
)
#test level
effect_size_test = list(
liberal = empirical_ES(mirt_fit_anchors_liberal, DIF = F, plot = F),
conservative = empirical_ES(mirt_fit_anchors_conservative, DIF = F, plot = F)
)
} else {
#we fill in NULLS to keep structure
#item
effect_size_items = list(
liberal = NULL,
conservative = NULL
)
#test
effect_size_test = list(
liberal = NULL,
conservative = NULL
)
}
#out
list(
scores = scores,
fits = list(
original = mirt_fit,
noDIF_liberal = mirt_fit_noDIF_liberal,
noDIF_conservative = mirt_fit_noDIF_conservative,
anchor_liberal = mirt_fit_anchors_liberal,
anchor_conservative = mirt_fit_anchors_conservative
),
DIF_stats = DIFs,
effect_size_items = effect_size_items,
effect_size_test = effect_size_test
)
}
Read the data from various files.
#datasets
d = read_rds("data/VES merged.rds")
dysgenics = readxl::read_excel("data/Emil_DYSCHILD.xlsx") %>% df_legalize_names()
dysgenics_vars = df_var_table(dysgenics)
dysgenics2 = readxl::read_excel("data/Aldo_dysgenics_VES.xlsx")
ncv = haven::read_sav("data/nerve conduction_workfile_3.sav")
vestotal = haven::read_sav("data/VESTOTAL.sav")
vars = read_csv("data/VES_dataset_variables.csv")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## number = col_double(),
## code = col_character(),
## name = col_character()
## )
MMPI_items = d %>% select(MM010001:MM010566)
MMPI_questions = read_excel("data/MMPI-1 items.xlsx")
cog_items = read_tsv("data/VES_items_binary.tsv")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## .default = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
#move fertility counts to main
d$fertility = dysgenics2$`TOTBRTH1 (TOTAL [ BIRTHS VETERAN FATHERED)`
d$fertility_confirmed = dysgenics2$`TOTBRTH2 (TOTAL [ QUALIFIED BIRTHS VET FATHERED)`
#standardize some variables
std_vars = c("education", "income")
for (v in std_vars) d[[v]] = d[[v]] %>% standardize(focal_group = d$race == "White")
#g tests
g_tests_early = c("VE_time1", "AR_time1", "PA", "GIT", "AFQT")
g_tests_later = c("VE_time2", "AR_time2", "WAIS_BD", "WAIS_GI", "WRAT", "PASAT", "WLGT", "copy_direct", "copy_immediate", "copy_delayed", "CVLT", "WCST", "GPT_left", "GPT_right")
g_tests = c(g_tests_early, g_tests_later)
#standardize some variables
for (v in g_tests) d[[v]] = d[[v]] %>% standardize(focal_group = d$race == "White")
#all tests g
fa_g = fa(d[g_tests])
fa_g
## Factor Analysis using method = minres
## Call: fa(r = d[g_tests])
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR1 h2 u2 com
## VE_time1 0.82 0.67 0.33 1
## AR_time1 0.81 0.66 0.34 1
## PA 0.70 0.50 0.50 1
## GIT 0.69 0.47 0.53 1
## AFQT 0.85 0.73 0.27 1
## VE_time2 0.82 0.67 0.33 1
## AR_time2 0.82 0.67 0.33 1
## WAIS_BD 0.67 0.45 0.55 1
## WAIS_GI 0.76 0.58 0.42 1
## WRAT 0.73 0.53 0.47 1
## PASAT 0.57 0.32 0.68 1
## WLGT 0.49 0.24 0.76 1
## copy_direct 0.47 0.22 0.78 1
## copy_immediate 0.55 0.30 0.70 1
## copy_delayed 0.55 0.30 0.70 1
## CVLT 0.42 0.18 0.82 1
## WCST 0.46 0.21 0.79 1
## GPT_left 0.34 0.12 0.88 1
## GPT_right 0.33 0.11 0.89 1
##
## MR1
## SS loadings 7.93
## Proportion Var 0.42
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## The degrees of freedom for the null model are 171 and the objective function was 12.5 with Chi Square of 55829
## The degrees of freedom for the model are 152 and the objective function was 3.86
##
## The root mean square of the residuals (RMSR) is 0.09
## The df corrected root mean square of the residuals is 0.1
##
## The harmonic number of observations is 4426 with the empirical chi square 12980 with prob < 0
## The total number of observations was 4462 with Likelihood Chi Square = 17178 with prob < 0
##
## Tucker Lewis Index of factoring reliability = 0.656
## RMSEA index = 0.158 and the 90 % confidence intervals are 0.156 0.16
## BIC = 15901
## Fit based upon off diagonal values = 0.95
## Measures of factor score adequacy
## MR1
## Correlation of (regression) scores with factors 0.97
## Multiple R square of scores with factors 0.95
## Minimum correlation of possible factor scores 0.89
#earlier tests only
fa_g_time1 = fa(d[g_tests_early])
fa_g_time1
## Factor Analysis using method = minres
## Call: fa(r = d[g_tests_early])
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR1 h2 u2 com
## VE_time1 0.82 0.67 0.33 1
## AR_time1 0.82 0.68 0.32 1
## PA 0.70 0.49 0.51 1
## GIT 0.73 0.53 0.47 1
## AFQT 0.92 0.84 0.16 1
##
## MR1
## SS loadings 3.20
## Proportion Var 0.64
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## The degrees of freedom for the null model are 10 and the objective function was 3.1 with Chi Square of 13826
## The degrees of freedom for the model are 5 and the objective function was 0.15
##
## The root mean square of the residuals (RMSR) is 0.04
## The df corrected root mean square of the residuals is 0.06
##
## The harmonic number of observations is 4377 with the empirical chi square 169 with prob < 9.5e-35
## The total number of observations was 4462 with Likelihood Chi Square = 690 with prob < 8.8e-147
##
## Tucker Lewis Index of factoring reliability = 0.901
## RMSEA index = 0.175 and the 90 % confidence intervals are 0.164 0.186
## BIC = 648
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy
## MR1
## Correlation of (regression) scores with factors 0.96
## Multiple R square of scores with factors 0.92
## Minimum correlation of possible factor scores 0.85
#later tests only
fa_g_time2 = fa(d[g_tests_later])
fa_g_time2
## Factor Analysis using method = minres
## Call: fa(r = d[g_tests_later])
## Standardized loadings (pattern matrix) based upon correlation matrix
## MR1 h2 u2 com
## VE_time2 0.78 0.61 0.39 1
## AR_time2 0.79 0.62 0.38 1
## WAIS_BD 0.67 0.45 0.55 1
## WAIS_GI 0.72 0.52 0.48 1
## WRAT 0.71 0.50 0.50 1
## PASAT 0.58 0.33 0.67 1
## WLGT 0.50 0.25 0.75 1
## copy_direct 0.51 0.26 0.74 1
## copy_immediate 0.61 0.37 0.63 1
## copy_delayed 0.61 0.37 0.63 1
## CVLT 0.45 0.20 0.80 1
## WCST 0.47 0.22 0.78 1
## GPT_left 0.37 0.14 0.86 1
## GPT_right 0.36 0.13 0.87 1
##
## MR1
## SS loadings 5.00
## Proportion Var 0.36
##
## Mean item complexity = 1
## Test of the hypothesis that 1 factor is sufficient.
##
## The degrees of freedom for the null model are 91 and the objective function was 7.16 with Chi Square of 31892
## The degrees of freedom for the model are 77 and the objective function was 2.8
##
## The root mean square of the residuals (RMSR) is 0.11
## The df corrected root mean square of the residuals is 0.12
##
## The harmonic number of observations is 4457 with the empirical chi square 9373 with prob < 0
## The total number of observations was 4462 with Likelihood Chi Square = 12463 with prob < 0
##
## Tucker Lewis Index of factoring reliability = 0.54
## RMSEA index = 0.19 and the 90 % confidence intervals are 0.187 0.193
## BIC = 11816
## Fit based upon off diagonal values = 0.92
## Measures of factor score adequacy
## MR1
## Correlation of (regression) scores with factors 0.95
## Multiple R square of scores with factors 0.90
## Minimum correlation of possible factor scores 0.80
#save scores, standardize to white
d$g = fa_g$scores[, 1] %>% standardize(focal_group = d$race == "White")
d$g_time1 = fa_g_time1$scores[, 1] %>% standardize(focal_group = d$race == "White")
d$g_time2 = fa_g_time2$scores[, 1] %>% standardize(focal_group = d$race == "White")
#IQ scale
d$IQ = d$g * 15 + 100
d$IQ_time1 = d$g_time1 * 15 + 100
d$IQ_time2 = d$g_time2 * 15 + 100
#quintiles
d$IQ_quintile = discretize(d$IQ, equal_range = F, breaks = 5)
#plot dist
GG_denhist(d, "IQ", vline = F)
## Warning: Removed 142 rows containing non-finite values (stat_bin).
## Warning: Removed 142 rows containing non-finite values (stat_density).
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 142 rows containing non-finite values (stat_bin).
## Warning: Removed 142 rows containing non-finite values (stat_density).
GG_save("figs/IQ_dist.png")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 142 rows containing non-finite values (stat_bin).
## Warning: Removed 142 rows containing non-finite values (stat_density).
#race distribution
d$race %>% table2()
#age summary stats
d %>% select(age, fertility, fertility_confirmed) %>% describe2()
#basic scatterplots
GG_scatter(d, "IQ_time1", "fertility")
## `geom_smooth()` using formula 'y ~ x'
#LOESS
GG_scatter(d, "IQ_time1", "fertility") +
geom_smooth(method = "loess")
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
#correlation by race
map_df(unique(d$race), function(v) {
d %>% filter(race == v) -> tmp
cor.test(tmp$g_time1, tmp$fertility) %>% broom::tidy() %>% mutate(race = v) %>% rename(n = parameter)
})
#race
ggplot(d, aes(IQ_time1, fertility, color = race)) +
# geom_point() +
geom_smooth()
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## Warning: Removed 114 rows containing non-finite values (stat_smooth).
#standardized data
d_std = d %>% select(g, g_time1, g_time2, fertility, fertility_confirmed, age, race) %>% df_standardize(messages = F)
#early life g
list(
simple = ols(fertility ~ g_time1, data = d_std),
basic_controls = ols(fertility ~ g_time1 + age + race, data = d_std),
SES_controls = ols(fertility ~ g_time1 + age + race, data = d_std),
race_interaction = ols(fertility ~ g_time1*race + age + race, data = d_std),
nonlinear_g = ols(fertility ~ rcs(g_time1) + age + race, data = d_std),
basic_controls_whites = ols(fertility ~ g_time1 + age, data = d_std %>% filter(race == "White")),
nonlinear_g_whites = ols(fertility ~ rcs(g_time1) + age, data = d_std %>% filter(race == "White"))
) -> models_early_g
models_early_g %>% summarize_models()
#nonlinear g plots in real units
ols(fertility ~ rcs(IQ_time1) + age + race, data = d) %>% ggpredict(terms = "IQ_time1") %>% plot() +
xlab("IQ, measured at about age 19") +
ylab("Number of children, measured at about age 38")
#whites only
ols(fertility ~ rcs(IQ_time1) + age, data = d %>% filter(race == "White")) %>% ggpredict(terms = "IQ_time1") %>% plot() +
xlab("IQ, measured at about age 19") +
ylab("Number of children, measured at about age 38")
#full g models
list(
simple = ols(fertility ~ g, data = d_std),
basic_controls = ols(fertility ~ g + age + race, data = d_std),
SES_controls = ols(fertility ~ g + age + race, data = d_std),
race_interaction = ols(fertility ~ g*race + age + race, data = d_std),
nonlinear_g = ols(fertility ~ rcs(g) + age + race, data = d_std),
basic_controls_whites = ols(fertility ~ g + age, data = d_std %>% filter(race == "White")),
nonlinear_g_whites = ols(fertility ~ rcs(g) + age, data = d_std %>% filter(race == "White"))
) -> models_full_g
models_full_g %>% summarize_models()
#real units
ols(fertility ~ rcs(IQ) + age + race, data = d) %>% ggpredict(terms = "IQ") %>% plot() +
xlab("IQ, measured at about age 19") +
ylab("Number of children, measured at about age 38")
#confirmed fertility, early g
list(
simple = ols(fertility_confirmed ~ g_time1, data = d_std),
basic_controls = ols(fertility_confirmed ~ g_time1 + age + race, data = d_std),
SES_controls = ols(fertility_confirmed ~ g_time1 + age + race, data = d_std),
race_interaction = ols(fertility_confirmed ~ g_time1*race + age + race, data = d_std),
nonlinear_g = ols(fertility_confirmed ~ rcs(g_time1) + age + race, data = d_std),
basic_controls_whites = ols(fertility_confirmed ~ g_time1 + age, data = d_std %>% filter(race == "White")),
nonlinear_g_whites = ols(fertility_confirmed ~ rcs(g_time1) + age, data = d_std %>% filter(race == "White"))
) -> models_early_g_confirmed_fert
models_early_g_confirmed_fert %>% summarize_models()
#nonlinear g plots in real units
ols(fertility_confirmed ~ rcs(IQ_time1) + age + race, data = d) %>% ggpredict(terms = "IQ_time1") %>% plot() +
xlab("IQ, measured at about age 19") +
ylab("Number of children that could be confirmed, measured at about age 38")
path1 = "
income ~ education + g_time1 + age
fertility ~ income + education + g_time1 + age
education ~ g_time1 + age
"
#fit
path1_fit = sem(
model = path1,
data = d,
std.lv = T,
std.ov = T
)
#plot
#https://cran.r-project.org/web/packages/lavaanPlot/vignettes/Intro_to_lavaanPlot.html
#https://cran.r-project.org/web/packages/lavaanPlot/vignettes/Save_and_embed.html
lavaanPlot::lavaanPlot(
model = path1_fit,
coefs = T,
# stars = "regress", #all are p < .05
digits = 3
) -> pl
pl
save_png(pl, "figs/path1.png")
#full test set
fa_Jensens_method(fa_g, d, "fertility", repel_names = T) +
xlab("g-loading") +
ylab("Correlation with fertility")
## Using Pearson correlations for the criterion-indicators relationships.
## `geom_smooth()` using formula 'y ~ x'
GG_save("figs/jensen_method_tests.png")
## `geom_smooth()` using formula 'y ~ x'
#reduced
fa_Jensens_method(fa_g_time1, d, "fertility")
## Using Pearson correlations for the criterion-indicators relationships.
## `geom_smooth()` using formula 'y ~ x'
fa_Jensens_method(fa_g_time2, d, "fertility")
## Using Pearson correlations for the criterion-indicators relationships.
## `geom_smooth()` using formula 'y ~ x'
#regressions
test_data = tibble(
test = g_tests,
loading = fa_g$loadings[, 1],
r_fertility = map_dbl(g_tests, function(v) {
wtd.cors(d[[v]], d$fertility)
}),
r_fertility_confirmed = map_dbl(g_tests, function(v) {
wtd.cors(d[[v]], d$fertility_confirmed)
})
)
test_data[-1] %>% wtd.cors()
## loading r_fertility r_fertility_confirmed
## loading 1.000 -0.725 -0.695
## r_fertility -0.725 1.000 0.988
## r_fertility_confirmed -0.695 0.988 1.000
ols(r_fertility ~ loading, data = test_data)
## Linear Regression Model
##
## ols(formula = r_fertility ~ loading, data = test_data)
##
## Model Likelihood Discrimination
## Ratio Test Indexes
## Obs 19 LR chi2 14.18 R2 0.526
## sigma0.0281 d.f. 1 R2 adj 0.498
## d.f. 17 Pr(> chi2) 0.0002 g 0.034
##
## Residuals
##
## Min 1Q Median 3Q Max
## -0.046233 -0.021589 0.001831 0.018674 0.051705
##
##
## Coef S.E. t Pr(>|t|)
## Intercept 0.0386 0.0250 1.55 0.1400
## loading -0.1678 0.0386 -4.34 0.0004
##
ols(r_fertility_confirmed ~ loading, data = test_data)
## Linear Regression Model
##
## ols(formula = r_fertility_confirmed ~ loading, data = test_data)
##
## Model Likelihood Discrimination
## Ratio Test Indexes
## Obs 19 LR chi2 12.53 R2 0.483
## sigma0.0270 d.f. 1 R2 adj 0.453
## d.f. 17 Pr(> chi2) 0.0004 g 0.030
##
## Residuals
##
## Min 1Q Median 3Q Max
## -0.0439489 -0.0196431 0.0009913 0.0144318 0.0536219
##
##
## Coef S.E. t Pr(>|t|)
## Intercept 0.0673 0.0240 2.81 0.0120
## loading -0.1478 0.0371 -3.98 0.0010
##
#fit measures
fit_meas = c("rmsea", "cfi", "tli", "gfi", "srmr")
#main model
VESBF_model = '
VER =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2
FD =~ copy_direct + copy_immediate + copy_delayed + CVLT
MAT =~ PASAT + AR_time1 + AR_time2
SP =~ PA + AFQT + WAIS_BD
intel =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2 + copy_direct + copy_immediate + copy_delayed + PASAT + AR_time1 + AR_time2 + PA + AFQT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
#other covars
FD ~~ SP
GPT_right ~~ GPT_left
#times
time1 =~ VE_time1 + AR_time1 + AFQT + PA + GIT
time2 =~ VE_time2 + AR_time2 + WRAT + WAIS_GI + WLGT + copy_direct + copy_immediate + copy_delayed + PASAT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
'
#standard fit
bf_fit = cfa(VESBF_model,
data = d,
orthogonal = T,
std.ov = T,
std.lv = T,
mimic = "EQS"
)
bf_fit %>% summary()
## lavaan 0.6-7 ended normally after 58 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 75
##
## Used Total
## Number of observations 4320 4462
##
## Model Test User Model:
##
## Test statistic 901.269
## Degrees of freedom 115
## 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|)
## VER =~
## WRAT 0.488 0.013 36.573 0.000
## WAIS_GI 0.291 0.014 20.832 0.000
## WLGT 0.297 0.017 17.113 0.000
## GIT 0.153 0.015 10.237 0.000
## VE_time1 0.448 0.012 38.470 0.000
## VE_time2 0.438 0.012 37.364 0.000
## FD =~
## copy_direct 0.318 0.015 21.917 0.000
## copy_immediate 0.827 0.013 65.566 0.000
## copy_delayed 0.844 0.013 67.466 0.000
## CVLT 0.146 0.015 9.661 0.000
## MAT =~
## PASAT 0.297 0.022 13.488 0.000
## AR_time1 0.317 0.019 16.480 0.000
## AR_time2 0.329 0.019 17.173 0.000
## SP =~
## PA 0.497 0.016 30.806 0.000
## AFQT 0.270 0.012 23.024 0.000
## WAIS_BD 0.479 0.017 28.426 0.000
## intel =~
## WRAT 0.686 0.014 47.791 0.000
## WAIS_GI 0.752 0.014 54.580 0.000
## WLGT 0.425 0.016 26.593 0.000
## GIT 0.672 0.015 46.339 0.000
## VE_time1 0.774 0.014 56.821 0.000
## VE_time2 0.803 0.013 60.118 0.000
## copy_direct 0.419 0.016 26.953 0.000
## copy_immediate 0.430 0.016 27.581 0.000
## copy_delayed 0.426 0.016 27.333 0.000
## PASAT 0.521 0.016 33.186 0.000
## AR_time1 0.816 0.013 60.477 0.000
## AR_time2 0.838 0.013 64.180 0.000
## PA 0.643 0.015 44.178 0.000
## AFQT 0.826 0.013 62.850 0.000
## WAIS_BD 0.606 0.015 41.220 0.000
## GPT_right 0.275 0.016 17.080 0.000
## GPT_left 0.283 0.016 17.632 0.000
## CVLT 0.390 0.016 24.960 0.000
## WCST 0.447 0.015 28.988 0.000
## time1 =~
## VE_time1 0.242 0.015 16.400 0.000
## AR_time1 0.214 0.016 13.493 0.000
## AFQT 0.310 0.016 19.213 0.000
## PA 0.193 0.019 10.142 0.000
## GIT 0.242 0.018 13.169 0.000
## time2 =~
## VE_time2 0.040 0.016 2.565 0.010
## AR_time2 0.081 0.018 4.399 0.000
## WRAT 0.119 0.017 6.872 0.000
## WAIS_GI -0.025 0.019 -1.309 0.191
## WLGT 0.295 0.024 12.541 0.000
## copy_direct 0.169 0.023 7.233 0.000
## copy_immediate 0.166 0.023 7.310 0.000
## copy_delayed 0.173 0.023 7.635 0.000
## PASAT 0.365 0.024 14.914 0.000
## WAIS_BD 0.189 0.019 9.815 0.000
## GPT_right 0.283 0.025 11.139 0.000
## GPT_left 0.253 0.025 9.966 0.000
## CVLT 0.176 0.024 7.401 0.000
## WCST 0.175 0.023 7.526 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## FD ~~
## SP 0.438 0.019 23.081 0.000
## .GPT_right ~~
## .GPT_left 0.484 0.018 27.463 0.000
## VER ~~
## FD 0.000
## MAT 0.000
## SP 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## FD ~~
## MAT 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## MAT ~~
## SP 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## SP ~~
## intel 0.000
## time1 0.000
## time2 0.000
## intel ~~
## time1 0.000
## time2 0.000
## time1 ~~
## time2 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .WRAT 0.279 0.008 33.503 0.000
## .WAIS_GI 0.349 0.009 39.220 0.000
## .WLGT 0.648 0.018 36.244 0.000
## .GIT 0.464 0.011 41.466 0.000
## .VE_time1 0.135 0.007 18.190 0.000
## .VE_time2 0.163 0.006 29.034 0.000
## .copy_direct 0.693 0.015 44.810 0.000
## .copy_immediate 0.099 0.010 9.628 0.000
## .copy_delayed 0.071 0.011 6.721 0.000
## .CVLT 0.794 0.018 44.259 0.000
## .PASAT 0.507 0.019 26.714 0.000
## .AR_time1 0.190 0.011 17.439 0.000
## .AR_time2 0.183 0.011 16.854 0.000
## .PA 0.302 0.012 25.301 0.000
## .AFQT 0.149 0.007 21.487 0.000
## .WAIS_BD 0.361 0.014 26.693 0.000
## .GPT_right 0.844 0.021 39.582 0.000
## .GPT_left 0.856 0.021 40.927 0.000
## .WCST 0.770 0.018 43.259 0.000
## VER 1.000
## FD 1.000
## MAT 1.000
## SP 1.000
## intel 1.000
## time1 1.000
## time2 1.000
#add dysgenics
VESBF_model2 = '
VER =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2
FD =~ copy_direct + copy_immediate + copy_delayed + CVLT
MAT =~ PASAT + AR_time1 + AR_time2
SP =~ PA + AFQT + WAIS_BD
intel =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2 + copy_direct + copy_immediate + copy_delayed + PASAT + AR_time1 + AR_time2 + PA + AFQT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
#other covars
FD ~~ SP
GPT_right ~~ GPT_left
#times
time1 =~ VE_time1 + AR_time1 + AFQT + PA + GIT
time2 =~ VE_time2 + AR_time2 + WRAT + WAIS_GI + WLGT + copy_direct + copy_immediate + copy_delayed + PASAT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
#dysgenics
fertility ~ VER + FD + MAT + SP + intel
'
#fit
dysgenics_fit = cfa(VESBF_model2,
data = d,
orthogonal = T,
std.ov = T,
std.lv = T,
mimic = "EQS"
)
dysgenics_fit %>% summary()
## lavaan 0.6-7 ended normally after 59 iterations
##
## Estimator ML
## Optimization method NLMINB
## Number of free parameters 81
##
## Used Total
## Number of observations 4313 4462
##
## Model Test User Model:
##
## Test statistic 944.644
## Degrees of freedom 129
## 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|)
## VER =~
## WRAT 0.489 0.013 36.725 0.000
## WAIS_GI 0.293 0.014 21.107 0.000
## WLGT 0.296 0.017 17.008 0.000
## GIT 0.155 0.015 10.360 0.000
## VE_time1 0.450 0.012 38.709 0.000
## VE_time2 0.439 0.012 37.511 0.000
## FD =~
## copy_direct 0.320 0.014 22.044 0.000
## copy_immediate 0.829 0.013 65.849 0.000
## copy_delayed 0.844 0.012 67.538 0.000
## CVLT 0.146 0.015 9.629 0.000
## MAT =~
## PASAT 0.302 0.022 13.782 0.000
## AR_time1 0.305 0.018 16.715 0.000
## AR_time2 0.338 0.019 17.886 0.000
## SP =~
## PA 0.495 0.016 30.640 0.000
## AFQT 0.269 0.012 22.843 0.000
## WAIS_BD 0.482 0.017 28.480 0.000
## intel =~
## WRAT 0.686 0.014 47.717 0.000
## WAIS_GI 0.751 0.014 54.531 0.000
## WLGT 0.424 0.016 26.502 0.000
## GIT 0.671 0.015 46.268 0.000
## VE_time1 0.773 0.014 56.789 0.000
## VE_time2 0.802 0.013 60.077 0.000
## copy_direct 0.421 0.016 27.108 0.000
## copy_immediate 0.431 0.016 27.648 0.000
## copy_delayed 0.427 0.016 27.399 0.000
## PASAT 0.520 0.016 33.189 0.000
## AR_time1 0.816 0.013 60.527 0.000
## AR_time2 0.839 0.013 64.282 0.000
## PA 0.643 0.015 44.187 0.000
## AFQT 0.826 0.013 62.848 0.000
## WAIS_BD 0.607 0.015 41.319 0.000
## GPT_right 0.277 0.016 17.224 0.000
## GPT_left 0.285 0.016 17.758 0.000
## CVLT 0.391 0.016 24.971 0.000
## WCST 0.448 0.015 29.090 0.000
## time1 =~
## VE_time1 0.240 0.015 16.511 0.000
## AR_time1 0.215 0.016 13.657 0.000
## AFQT 0.313 0.016 19.624 0.000
## PA 0.196 0.019 10.444 0.000
## GIT 0.244 0.018 13.324 0.000
## time2 =~
## VE_time2 0.040 0.016 2.576 0.010
## AR_time2 0.070 0.018 3.832 0.000
## WRAT 0.127 0.017 7.372 0.000
## WAIS_GI -0.023 0.019 -1.262 0.207
## WLGT 0.308 0.024 12.932 0.000
## copy_direct 0.160 0.023 6.875 0.000
## copy_immediate 0.161 0.023 7.096 0.000
## copy_delayed 0.169 0.023 7.449 0.000
## PASAT 0.364 0.025 14.820 0.000
## WAIS_BD 0.181 0.019 9.416 0.000
## GPT_right 0.274 0.025 10.820 0.000
## GPT_left 0.244 0.025 9.654 0.000
## CVLT 0.179 0.024 7.516 0.000
## WCST 0.165 0.023 7.112 0.000
##
## Regressions:
## Estimate Std.Err z-value P(>|z|)
## fertility ~
## VER -0.100 0.024 -4.108 0.000
## FD -0.014 0.019 -0.766 0.443
## MAT 0.095 0.032 3.013 0.003
## SP 0.011 0.028 0.382 0.703
## intel -0.104 0.018 -5.630 0.000
##
## Covariances:
## Estimate Std.Err z-value P(>|z|)
## FD ~~
## SP 0.439 0.019 23.146 0.000
## .GPT_right ~~
## .GPT_left 0.488 0.018 27.823 0.000
## VER ~~
## FD 0.000
## MAT 0.000
## SP 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## FD ~~
## MAT 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## MAT ~~
## SP 0.000
## intel 0.000
## time1 0.000
## time2 0.000
## SP ~~
## intel 0.000
## time1 0.000
## time2 0.000
## intel ~~
## time1 0.000
## time2 0.000
## time1 ~~
## time2 0.000
##
## Variances:
## Estimate Std.Err z-value P(>|z|)
## .WRAT 0.277 0.008 33.290 0.000
## .WAIS_GI 0.348 0.009 39.308 0.000
## .WLGT 0.643 0.018 35.392 0.000
## .GIT 0.464 0.011 41.415 0.000
## .VE_time1 0.135 0.007 18.460 0.000
## .VE_time2 0.163 0.006 29.104 0.000
## .copy_direct 0.693 0.015 44.873 0.000
## .copy_immediate 0.097 0.010 9.474 0.000
## .copy_delayed 0.072 0.010 6.854 0.000
## .CVLT 0.793 0.018 44.085 0.000
## .PASAT 0.504 0.019 26.230 0.000
## .AR_time1 0.197 0.010 19.794 0.000
## .AR_time2 0.176 0.011 16.002 0.000
## .PA 0.303 0.012 25.526 0.000
## .AFQT 0.149 0.007 21.339 0.000
## .WAIS_BD 0.360 0.014 26.496 0.000
## .GPT_right 0.848 0.021 39.958 0.000
## .GPT_left 0.859 0.021 41.242 0.000
## .WCST 0.772 0.018 43.423 0.000
## .fertility 0.970 0.021 45.351 0.000
## VER 1.000
## FD 1.000
## MAT 1.000
## SP 1.000
## intel 1.000
## time1 1.000
## time2 1.000
#plot
#https://cran.r-project.org/web/packages/lavaanPlot/vignettes/Intro_to_lavaanPlot.html
#https://cran.r-project.org/web/packages/lavaanPlot/vignettes/Save_and_embed.html
lavaanPlot::lavaanPlot(
model = dysgenics_fit,
coefs = T,
# stars = "regress", #all are p < .05
digits = 3
) -> pl
pl
#fits
fitmeasures(bf_fit, fit.measures = fit_meas)
## rmsea cfi tli gfi srmr
## 0.040 0.985 0.978 0.977 0.026
fitmeasures(dysgenics_fit, fit.measures = fit_meas)
## rmsea cfi tli gfi srmr
## 0.038 0.985 0.978 0.977 0.026
#LSEM
lsem_fert = lsem.estimate(
data = d %>% as.data.frame(),
moderator = "fertility",
moderator.grid = seq(0, 4, by = 1),
lavmodel = VESBF_model,
h = 5,
meanstructure = TRUE,
residualize = TRUE,
standardized = TRUE,
orthogonal = T
)
## ** Residualize Data
## ** Fit lavaan model
## |*****|
## |-----|
## ** Parameter summary
summary(lsem_fert)
## -----------------------------------------------------------------
## Local Structural Equation Model
##
## sirt 3.9-4 (2020-02-17 12:57:09)
## lavaan 0.6-7 (2020-07-31 06:10:07 UTC)
##
## R version 4.0.4 (2021-02-15) x86_64, linux-gnu | nodename=desktop | login=unknown
##
## Function 'sirt::lsem.estimate', type='LSEM'
##
##
## Call:
## lsem.estimate(data = d %>% as.data.frame(), moderator = "fertility",
## moderator.grid = seq(0, 4, by = 1), lavmodel = VESBF_model,
## h = 5, residualize = TRUE, standardized = TRUE, meanstructure = TRUE,
## orthogonal = T)
##
## Date of Analysis: 2021-02-24 22:41:52
## Time difference of 4.5 secs
## Computation Time: 4.5
##
## Number of observations = 4455
## Used samping weights: FALSE
## Bandwidth factor = 5
## Bandwidth = 1.264
## Number of focal points for moderator = 5
##
## Used joint estimation: FALSE
## Used sufficient statistics: FALSE
## Used pseudo weights: FALSE
## Used lavaan package: TRUE
## Used lavaan.survey package: FALSE
##
## Mean structure modelled: TRUE
##
## lavaan Model
##
## VER =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2
## FD =~ copy_direct + copy_immediate + copy_delayed + CVLT
## MAT =~ PASAT + AR_time1 + AR_time2
## SP =~ PA + AFQT + WAIS_BD
##
## intel =~ WRAT + WAIS_GI + WLGT + GIT + VE_time1 + VE_time2 + copy_direct + copy_immediate + copy_delayed + PASAT + AR_time1 + AR_time2 + PA + AFQT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
##
## #other covars
## FD ~~ SP
## GPT_right ~~ GPT_left
##
## #times
## time1 =~ VE_time1 + AR_time1 + AFQT + PA + GIT
## time2 =~ VE_time2 + AR_time2 + WRAT + WAIS_GI + WLGT + copy_direct + copy_immediate + copy_delayed + PASAT + WAIS_BD + GPT_right + GPT_left + CVLT + WCST
##
##
## Parameter Estimate Summary
##
## par parindex M SD MAD Min
## 1 VER=~WRAT 1 1.000 0.000 0.000 1.000
## 2 VER=~WAIS_GI 2 0.583 0.055 0.046 0.488
## 3 VER=~WLGT 3 0.593 0.044 0.034 0.509
## 4 VER=~GIT 4 0.343 0.015 0.012 0.319
## 5 VER=~VE_time1 5 0.957 0.029 0.022 0.904
## 6 VER=~VE_time2 6 0.951 0.025 0.020 0.920
## 7 FD=~copy_direct 7 1.000 0.000 0.000 1.000
## 8 FD=~copy_immediate 8 2.602 0.141 0.129 2.382
## 9 FD=~copy_delayed 9 2.638 0.156 0.142 2.387
## 10 FD=~CVLT 10 0.460 0.026 0.025 0.424
## 11 MAT=~PASAT 11 1.000 0.000 0.000 1.000
## 12 MAT=~AR_time1 12 1.074 0.068 0.052 0.962
## 13 MAT=~AR_time2 13 1.167 0.054 0.051 1.081
## 14 SP=~PA 14 1.000 0.000 0.000 1.000
## 15 SP=~AFQT 15 0.562 0.011 0.008 0.524
## 16 SP=~WAIS_BD 16 0.963 0.052 0.047 0.910
## 17 intel=~WRAT 17 1.000 0.000 0.000 1.000
## 18 intel=~WAIS_GI 18 1.078 0.009 0.008 1.053
## 19 intel=~WLGT 19 0.608 0.007 0.005 0.597
## 20 intel=~GIT 20 1.036 0.014 0.011 1.010
## 21 intel=~VE_time1 21 1.153 0.010 0.008 1.133
## 22 intel=~VE_time2 22 1.236 0.020 0.016 1.201
## 23 intel=~copy_direct 23 0.622 0.011 0.009 0.614
## 24 intel=~copy_immediate 24 0.628 0.006 0.005 0.616
## 25 intel=~copy_delayed 25 0.617 0.009 0.007 0.601
## 26 intel=~PASAT 26 0.778 0.008 0.006 0.763
## 27 intel=~AR_time1 27 1.218 0.003 0.003 1.213
## 28 intel=~AR_time2 28 1.272 0.014 0.013 1.248
## 29 intel=~PA 29 0.939 0.010 0.007 0.904
## 30 intel=~AFQT 30 1.226 0.011 0.009 1.209
## 31 intel=~WAIS_BD 31 0.900 0.010 0.007 0.865
## 32 intel=~GPT_right 32 0.405 0.022 0.019 0.383
## 33 intel=~GPT_left 33 0.433 0.010 0.009 0.418
## 34 intel=~CVLT 34 0.573 0.020 0.018 0.542
## 35 intel=~WCST 35 0.650 0.010 0.009 0.641
## 36 FD~~SP 36 0.072 0.008 0.007 0.065
## 37 GPT_right~~GPT_left 37 0.520 0.038 0.034 0.487
## 38 time1=~VE_time1 38 1.000 0.000 0.000 1.000
## 39 time1=~AR_time1 39 0.902 0.062 0.052 0.772
## 40 time1=~AFQT 40 1.246 0.154 0.144 1.062
## 41 time1=~PA 41 0.746 0.079 0.072 0.677
## 42 time1=~GIT 42 1.036 0.149 0.134 0.805
## 43 time2=~VE_time2 43 1.000 0.000 0.000 1.000
## 44 time2=~AR_time2 44 2.086 1.007 0.818 0.251
## 45 time2=~WRAT 45 3.825 2.691 2.137 1.796
## 46 time2=~WAIS_GI 46 -0.431 0.682 0.535 -0.936
## 47 time2=~WLGT 47 9.575 6.223 4.988 4.675
## 48 time2=~copy_direct 48 4.920 1.777 1.559 2.306
## 49 time2=~copy_immediate 49 4.976 0.772 0.668 3.853
## 50 time2=~copy_delayed 50 5.242 0.764 0.638 4.013
## 51 time2=~PASAT 51 10.344 2.616 2.054 7.115
## 52 time2=~WAIS_BD 52 5.400 1.141 1.105 4.150
## 53 time2=~GPT_right 53 7.996 1.564 1.440 6.071
## 54 time2=~GPT_left 54 7.384 1.374 1.217 4.853
## 55 time2=~CVLT 55 5.980 2.888 2.313 3.395
## 56 time2=~WCST 56 4.556 1.438 1.322 2.331
## 57 WRAT~~WRAT 57 0.295 0.011 0.010 0.278
## 58 WAIS_GI~~WAIS_GI 58 0.356 0.009 0.007 0.349
## 59 WLGT~~WLGT 59 0.640 0.046 0.036 0.553
## 60 GIT~~GIT 60 0.542 0.009 0.007 0.534
## 61 VE_time1~~VE_time1 61 0.147 0.008 0.007 0.136
## 62 VE_time2~~VE_time2 62 0.189 0.002 0.002 0.185
## 63 copy_direct~~copy_direct 63 0.764 0.015 0.011 0.739
## 64 copy_immediate~~copy_immediate 64 0.104 0.007 0.006 0.094
## 65 copy_delayed~~copy_delayed 65 0.072 0.003 0.002 0.063
## 66 CVLT~~CVLT 66 0.833 0.009 0.007 0.817
## 67 PASAT~~PASAT 67 0.562 0.014 0.012 0.531
## 68 AR_time1~~AR_time1 68 0.208 0.007 0.005 0.202
## 69 AR_time2~~AR_time2 69 0.198 0.004 0.003 0.195
## 70 PA~~PA 70 0.320 0.005 0.004 0.306
## 71 AFQT~~AFQT 71 0.160 0.006 0.005 0.154
## 72 WAIS_BD~~WAIS_BD 72 0.382 0.008 0.006 0.372
## 73 GPT_right~~GPT_right 73 0.881 0.046 0.041 0.840
## 74 GPT_left~~GPT_left 74 0.954 0.047 0.042 0.917
## 75 WCST~~WCST 75 0.811 0.019 0.017 0.793
## 76 VER~~VER 76 0.242 0.004 0.004 0.237
## 77 FD~~FD 77 0.106 0.017 0.015 0.092
## 78 MAT~~MAT 78 0.094 0.009 0.007 0.080
## 79 SP~~SP 79 0.260 0.008 0.007 0.248
## 80 intel~~intel 80 0.488 0.005 0.004 0.482
## 81 time1~~time1 81 0.068 0.006 0.005 0.060
## 82 time2~~time2 82 0.001 0.001 0.000 0.000
## 83 VER~~FD 83 0.000 0.000 0.000 0.000
## 84 VER~~MAT 84 0.000 0.000 0.000 0.000
## 85 VER~~SP 85 0.000 0.000 0.000 0.000
## 86 VER~~intel 86 0.000 0.000 0.000 0.000
## 87 VER~~time1 87 0.000 0.000 0.000 0.000
## 88 VER~~time2 88 0.000 0.000 0.000 0.000
## 89 FD~~MAT 89 0.000 0.000 0.000 0.000
## 90 FD~~intel 90 0.000 0.000 0.000 0.000
## 91 FD~~time1 91 0.000 0.000 0.000 0.000
## 92 FD~~time2 92 0.000 0.000 0.000 0.000
## 93 MAT~~SP 93 0.000 0.000 0.000 0.000
## 94 MAT~~intel 94 0.000 0.000 0.000 0.000
## 95 MAT~~time1 95 0.000 0.000 0.000 0.000
## 96 MAT~~time2 96 0.000 0.000 0.000 0.000
## 97 SP~~intel 97 0.000 0.000 0.000 0.000
## 98 SP~~time1 98 0.000 0.000 0.000 0.000
## 99 SP~~time2 99 0.000 0.000 0.000 0.000
## 100 intel~~time1 100 0.000 0.000 0.000 0.000
## 101 intel~~time2 101 0.000 0.000 0.000 0.000
## 102 time1~~time2 102 0.000 0.000 0.000 0.000
## 103 WRAT~1 103 0.001 0.006 0.005 -0.007
## 104 WAIS_GI~1 104 0.007 0.004 0.004 0.000
## 105 WLGT~1 105 0.000 0.006 0.006 -0.009
## 106 GIT~1 106 0.006 0.007 0.006 -0.004
## 107 VE_time1~1 107 0.003 0.007 0.007 -0.007
## 108 VE_time2~1 108 0.009 0.007 0.006 -0.001
## 109 copy_direct~1 109 0.007 0.003 0.003 0.003
## 110 copy_immediate~1 110 0.005 0.003 0.002 0.002
## 111 copy_delayed~1 111 0.006 0.003 0.002 0.003
## 112 CVLT~1 112 0.008 0.005 0.004 0.001
## 113 PASAT~1 113 0.002 0.006 0.005 -0.007
## 114 AR_time1~1 114 0.005 0.008 0.007 -0.007
## 115 AR_time2~1 115 0.009 0.006 0.006 -0.001
## 116 PA~1 116 0.001 0.006 0.006 -0.008
## 117 AFQT~1 117 0.003 0.007 0.006 -0.007
## 118 WAIS_BD~1 118 0.003 0.009 0.008 -0.009
## 119 GPT_right~1 119 -0.003 0.006 0.005 -0.012
## 120 GPT_left~1 120 0.000 0.008 0.007 -0.011
## 121 WCST~1 121 0.005 0.003 0.003 0.000
## 122 VER~1 122 0.000 0.000 0.000 0.000
## 123 FD~1 123 0.000 0.000 0.000 0.000
## 124 MAT~1 124 0.000 0.000 0.000 0.000
## 125 SP~1 125 0.000 0.000 0.000 0.000
## 126 intel~1 126 0.000 0.000 0.000 0.000
## 127 time1~1 127 0.000 0.000 0.000 0.000
## 128 time2~1 128 0.000 0.000 0.000 0.000
## 129 std__VER=~WRAT 129 0.482 0.004 0.003 0.478
## 130 std__VER=~WAIS_GI 130 0.285 0.024 0.021 0.246
## 131 std__VER=~WLGT 131 0.292 0.021 0.017 0.251
## 132 std__VER=~GIT 132 0.156 0.007 0.006 0.145
## 133 std__VER=~VE_time1 133 0.452 0.013 0.011 0.432
## 134 std__VER=~VE_time2 134 0.435 0.005 0.004 0.431
## 135 std__FD=~copy_direct 135 0.311 0.026 0.023 0.289
## 136 std__FD=~copy_immediate 136 0.827 0.015 0.013 0.810
## 137 std__FD=~copy_delayed 137 0.845 0.010 0.009 0.836
## 138 std__FD=~CVLT 138 0.145 0.004 0.003 0.138
## 139 std__MAT=~PASAT 139 0.296 0.011 0.009 0.277
## 140 std__MAT=~AR_time1 140 0.313 0.007 0.005 0.301
## 141 std__MAT=~AR_time2 141 0.337 0.007 0.006 0.320
## 142 std__SP=~PA 142 0.498 0.008 0.007 0.486
## 143 std__SP=~AFQT 143 0.275 0.005 0.004 0.265
## 144 std__SP=~WAIS_BD 144 0.477 0.019 0.017 0.458
## 145 std__intel=~WRAT 145 0.685 0.002 0.002 0.682
## 146 std__intel=~WAIS_GI 146 0.750 0.009 0.007 0.735
## 147 std__intel=~WLGT 147 0.426 0.007 0.005 0.415
## 148 std__intel=~GIT 148 0.670 0.009 0.008 0.653
## 149 std__intel=~VE_time1 149 0.773 0.008 0.007 0.758
## 150 std__intel=~VE_time2 150 0.803 0.003 0.002 0.798
## 151 std__intel=~copy_direct 151 0.415 0.007 0.007 0.409
## 152 std__intel=~copy_immediate 152 0.431 0.006 0.005 0.419
## 153 std__intel=~copy_delayed 153 0.427 0.008 0.007 0.413
## 154 std__intel=~PASAT 154 0.526 0.004 0.003 0.520
## 155 std__intel=~AR_time1 155 0.813 0.003 0.002 0.809
## 156 std__intel=~AR_time2 156 0.839 0.005 0.004 0.835
## 157 std__intel=~PA 157 0.641 0.003 0.002 0.631
## 158 std__intel=~AFQT 158 0.824 0.006 0.005 0.813
## 159 std__intel=~WAIS_BD 159 0.611 0.005 0.004 0.597
## 160 std__intel=~GPT_right 160 0.276 0.013 0.011 0.266
## 161 std__intel=~GPT_left 161 0.286 0.003 0.003 0.284
## 162 std__intel=~CVLT 162 0.390 0.013 0.012 0.372
## 163 std__intel=~WCST 163 0.443 0.006 0.004 0.439
## 164 std__FD~~SP 164 0.433 0.022 0.020 0.410
## 165 std__GPT_right~~GPT_left 165 0.566 0.013 0.012 0.555
## 166 std__time1=~VE_time1 166 0.249 0.011 0.011 0.235
## 167 std__time1=~AR_time1 167 0.223 0.008 0.005 0.202
## 168 std__time1=~AFQT 168 0.310 0.026 0.023 0.283
## 169 std__time1=~PA 169 0.189 0.014 0.012 0.175
## 170 std__time1=~GIT 170 0.248 0.026 0.022 0.203
## 171 std__time2=~VE_time2 171 0.032 0.008 0.006 0.020
## 172 std__time2=~AR_time2 172 0.074 0.037 0.029 0.005
## 173 std__time2=~WRAT 173 0.112 0.042 0.038 0.077
## 174 std__time2=~WAIS_GI 174 -0.019 0.019 0.015 -0.033
## 175 std__time2=~WLGT 175 0.289 0.088 0.075 0.222
## 176 std__time2=~copy_direct 176 0.168 0.067 0.053 0.046
## 177 std__time2=~copy_immediate 177 0.169 0.041 0.036 0.096
## 178 std__time2=~copy_delayed 178 0.178 0.036 0.032 0.114
## 179 std__time2=~PASAT 179 0.330 0.020 0.018 0.303
## 180 std__time2=~WAIS_BD 180 0.185 0.056 0.048 0.085
## 181 std__time2=~GPT_right 181 0.275 0.079 0.064 0.128
## 182 std__time2=~GPT_left 182 0.243 0.063 0.049 0.125
## 183 std__time2=~CVLT 183 0.183 0.030 0.026 0.158
## 184 std__time2=~WCST 184 0.161 0.063 0.054 0.047
## 185 std__WRAT~~WRAT 185 0.284 0.011 0.010 0.266
## 186 std__WAIS_GI~~WAIS_GI 186 0.354 0.003 0.003 0.350
## 187 std__WLGT~~WLGT 187 0.642 0.047 0.037 0.554
## 188 std__GIT~~GIT 188 0.464 0.005 0.004 0.460
## 189 std__VE_time1~~VE_time1 189 0.136 0.007 0.006 0.125
## 190 std__VE_time2~~VE_time2 190 0.164 0.006 0.005 0.150
## 191 std__copy_direct~~copy_direct 191 0.698 0.003 0.002 0.692
## 192 std__copy_immediate~~copy_immediate 192 0.100 0.007 0.006 0.088
## 193 std__copy_delayed~~copy_delayed 193 0.070 0.003 0.002 0.062
## 194 std__CVLT~~CVLT 194 0.792 0.006 0.006 0.782
## 195 std__PASAT~~PASAT 195 0.526 0.009 0.008 0.511
## 196 std__AR_time1~~AR_time1 196 0.190 0.006 0.004 0.184
## 197 std__AR_time2~~AR_time2 197 0.176 0.004 0.003 0.171
## 198 std__PA~~PA 198 0.305 0.003 0.002 0.297
## 199 std__AFQT~~AFQT 199 0.148 0.006 0.005 0.142
## 200 std__WAIS_BD~~WAIS_BD 200 0.361 0.007 0.005 0.352
## 201 std__GPT_right~~GPT_right 201 0.842 0.030 0.026 0.817
## 202 std__GPT_left~~GPT_left 202 0.855 0.025 0.020 0.831
## 203 std__WCST~~WCST 203 0.773 0.012 0.011 0.756
## 204 std__VER~~VER 204 1.000 0.000 0.000 1.000
## 205 std__FD~~FD 205 1.000 0.000 0.000 1.000
## 206 std__MAT~~MAT 206 1.000 0.000 0.000 1.000
## 207 std__SP~~SP 207 1.000 0.000 0.000 1.000
## 208 std__intel~~intel 208 1.000 0.000 0.000 1.000
## 209 std__time1~~time1 209 1.000 0.000 0.000 1.000
## 210 std__time2~~time2 210 1.000 0.000 0.000 1.000
## 211 std__VER~~FD 211 0.000 0.000 0.000 0.000
## 212 std__VER~~MAT 212 0.000 0.000 0.000 0.000
## 213 std__VER~~SP 213 0.000 0.000 0.000 0.000
## 214 std__VER~~intel 214 0.000 0.000 0.000 0.000
## 215 std__VER~~time1 215 0.000 0.000 0.000 0.000
## 216 std__VER~~time2 216 0.000 0.000 0.000 0.000
## 217 std__FD~~MAT 217 0.000 0.000 0.000 0.000
## 218 std__FD~~intel 218 0.000 0.000 0.000 0.000
## 219 std__FD~~time1 219 0.000 0.000 0.000 0.000
## 220 std__FD~~time2 220 0.000 0.000 0.000 0.000
## 221 std__MAT~~SP 221 0.000 0.000 0.000 0.000
## 222 std__MAT~~intel 222 0.000 0.000 0.000 0.000
## 223 std__MAT~~time1 223 0.000 0.000 0.000 0.000
## 224 std__MAT~~time2 224 0.000 0.000 0.000 0.000
## 225 std__SP~~intel 225 0.000 0.000 0.000 0.000
## 226 std__SP~~time1 226 0.000 0.000 0.000 0.000
## 227 std__SP~~time2 227 0.000 0.000 0.000 0.000
## 228 std__intel~~time1 228 0.000 0.000 0.000 0.000
## 229 std__intel~~time2 229 0.000 0.000 0.000 0.000
## 230 std__time1~~time2 230 0.000 0.000 0.000 0.000
## 231 std__WRAT~1 231 0.001 0.005 0.005 -0.007
## 232 std__WAIS_GI~1 232 0.007 0.004 0.004 0.000
## 233 std__WLGT~1 233 0.000 0.006 0.006 -0.009
## 234 std__GIT~1 234 0.005 0.006 0.006 -0.004
## 235 std__VE_time1~1 235 0.003 0.007 0.006 -0.007
## 236 std__VE_time2~1 236 0.008 0.006 0.006 -0.001
## 237 std__copy_direct~1 237 0.007 0.003 0.003 0.003
## 238 std__copy_immediate~1 238 0.005 0.003 0.002 0.002
## 239 std__copy_delayed~1 239 0.006 0.003 0.002 0.003
## 240 std__CVLT~1 240 0.008 0.005 0.004 0.001
## 241 std__PASAT~1 241 0.002 0.006 0.005 -0.007
## 242 std__AR_time1~1 242 0.005 0.007 0.007 -0.006
## 243 std__AR_time2~1 243 0.008 0.006 0.005 0.000
## 244 std__PA~1 244 0.001 0.006 0.006 -0.008
## 245 std__AFQT~1 245 0.003 0.007 0.006 -0.007
## 246 std__WAIS_BD~1 246 0.003 0.009 0.008 -0.009
## 247 std__GPT_right~1 247 -0.003 0.006 0.005 -0.012
## 248 std__GPT_left~1 248 0.000 0.007 0.006 -0.010
## 249 std__WCST~1 249 0.005 0.003 0.003 0.000
## 250 std__VER~1 250 0.000 0.000 0.000 0.000
## 251 std__FD~1 251 0.000 0.000 0.000 0.000
## 252 std__MAT~1 252 0.000 0.000 0.000 0.000
## 253 std__SP~1 253 0.000 0.000 0.000 0.000
## 254 std__intel~1 254 0.000 0.000 0.000 0.000
## 255 std__time1~1 255 0.000 0.000 0.000 0.000
## 256 std__time2~1 256 0.000 0.000 0.000 0.000
## 257 rmsea 257 0.041 0.002 0.002 0.039
## 258 cfi 258 0.984 0.002 0.001 0.982
## 259 tli 259 0.977 0.002 0.002 0.973
## 260 gfi 260 0.976 0.002 0.002 0.973
## 261 srmr 261 0.025 0.002 0.002 0.023
## Max lin_int lin_slo SD_nonlin
## 1 1.000 1.000 0.000 0.000
## 2 0.670 0.662 -0.046 0.007
## 3 0.625 0.547 0.027 0.030
## 4 0.372 0.362 -0.011 0.008
## 5 1.009 0.994 -0.022 0.014
## 6 1.001 0.919 0.019 0.011
## 7 1.000 1.000 0.000 0.000
## 8 2.742 2.478 0.072 0.112
## 9 2.788 2.486 0.089 0.115
## 10 0.488 0.439 0.013 0.022
## 11 1.000 1.000 0.000 0.000
## 12 1.208 0.977 0.057 0.014
## 13 1.215 1.097 0.041 0.025
## 14 1.000 1.000 0.000 0.000
## 15 0.568 0.572 -0.006 0.009
## 16 1.050 1.034 -0.041 0.018
## 17 1.000 1.000 0.000 0.000
## 18 1.090 1.085 -0.004 0.008
## 19 0.617 0.601 0.004 0.004
## 20 1.048 1.019 0.010 0.007
## 21 1.159 1.142 0.006 0.007
## 22 1.261 1.209 0.016 0.006
## 23 0.655 0.610 0.007 0.008
## 24 0.632 0.622 0.004 0.005
## 25 0.626 0.606 0.007 0.004
## 26 0.792 0.789 -0.006 0.003
## 27 1.222 1.217 0.001 0.003
## 28 1.293 1.292 -0.012 0.002
## 29 0.947 0.948 -0.005 0.008
## 30 1.234 1.220 0.003 0.010
## 31 0.907 0.912 -0.007 0.006
## 32 0.443 0.434 -0.017 0.008
## 33 0.449 0.447 -0.008 0.002
## 34 0.607 0.543 0.017 0.002
## 35 0.668 0.661 -0.006 0.007
## 36 0.086 0.082 -0.006 0.005
## 37 0.585 0.568 -0.028 0.020
## 38 1.000 1.000 0.000 0.000
## 39 0.981 0.991 -0.052 0.008
## 40 1.475 1.461 -0.125 0.043
## 41 0.874 0.838 -0.054 0.046
## 42 1.243 1.250 -0.125 0.025
## 43 1.000 1.000 0.000 0.000
## 44 2.902 0.957 0.659 0.640
## 45 9.024 7.116 -1.919 1.453
## 46 0.869 0.303 -0.428 0.457
## 47 21.707 16.986 -4.323 3.566
## 48 6.963 3.640 0.747 1.543
## 49 5.850 4.719 0.150 0.751
## 50 5.940 5.339 -0.056 0.761
## 51 15.339 13.463 -1.819 1.496
## 52 6.714 4.537 0.504 0.973
## 53 9.952 7.116 0.514 1.442
## 54 9.164 7.180 0.119 1.366
## 55 11.606 9.407 -1.999 1.666
## 56 6.011 3.026 0.893 0.980
## 57 0.311 0.279 0.009 0.002
## 58 0.372 0.368 -0.007 0.004
## 59 0.675 0.589 0.030 0.030
## 60 0.571 0.534 0.005 0.008
## 61 0.157 0.159 -0.007 0.003
## 62 0.192 0.192 -0.002 0.001
## 63 0.795 0.743 0.012 0.004
## 64 0.118 0.094 0.006 0.001
## 65 0.076 0.076 -0.003 0.001
## 66 0.853 0.820 0.007 0.004
## 67 0.581 0.578 -0.009 0.009
## 68 0.221 0.217 -0.005 0.003
## 69 0.205 0.196 0.001 0.004
## 70 0.325 0.326 -0.003 0.003
## 71 0.174 0.152 0.005 0.001
## 72 0.400 0.370 0.007 0.002
## 73 0.959 0.938 -0.033 0.023
## 74 1.037 1.012 -0.034 0.025
## 75 0.843 0.829 -0.011 0.015
## 76 0.249 0.244 -0.001 0.004
## 77 0.136 0.125 -0.011 0.011
## 78 0.108 0.106 -0.007 0.001
## 79 0.273 0.249 0.006 0.002
## 80 0.503 0.485 0.002 0.005
## 81 0.076 0.060 0.004 0.002
## 82 0.003 0.001 0.000 0.000
## 83 0.000 0.000 0.000 0.000
## 84 0.000 0.000 0.000 0.000
## 85 0.000 0.000 0.000 0.000
## 86 0.000 0.000 0.000 0.000
## 87 0.000 0.000 0.000 0.000
## 88 0.000 0.000 0.000 0.000
## 89 0.000 0.000 0.000 0.000
## 90 0.000 0.000 0.000 0.000
## 91 0.000 0.000 0.000 0.000
## 92 0.000 0.000 0.000 0.000
## 93 0.000 0.000 0.000 0.000
## 94 0.000 0.000 0.000 0.000
## 95 0.000 0.000 0.000 0.000
## 96 0.000 0.000 0.000 0.000
## 97 0.000 0.000 0.000 0.000
## 98 0.000 0.000 0.000 0.000
## 99 0.000 0.000 0.000 0.000
## 100 0.000 0.000 0.000 0.000
## 101 0.000 0.000 0.000 0.000
## 102 0.000 0.000 0.000 0.000
## 103 0.008 -0.007 0.005 0.001
## 104 0.012 0.001 0.003 0.001
## 105 0.009 -0.009 0.005 0.001
## 106 0.015 -0.004 0.006 0.001
## 107 0.012 -0.007 0.006 0.002
## 108 0.018 -0.001 0.006 0.001
## 109 0.012 0.003 0.003 0.001
## 110 0.010 0.001 0.002 0.001
## 111 0.010 0.003 0.002 0.001
## 112 0.014 0.002 0.004 0.002
## 113 0.008 -0.006 0.005 0.002
## 114 0.013 -0.005 0.006 0.003
## 115 0.016 0.000 0.005 0.002
## 116 0.009 -0.007 0.005 0.002
## 117 0.011 -0.006 0.005 0.003
## 118 0.018 -0.010 0.008 0.001
## 119 0.004 -0.012 0.005 0.001
## 120 0.014 -0.011 0.007 0.001
## 121 0.008 0.001 0.002 0.002
## 122 0.000 0.000 0.000 0.000
## 123 0.000 0.000 0.000 0.000
## 124 0.000 0.000 0.000 0.000
## 125 0.000 0.000 0.000 0.000
## 126 0.000 0.000 0.000 0.000
## 127 0.000 0.000 0.000 0.000
## 128 0.000 0.000 0.000 0.000
## 129 0.490 0.485 -0.002 0.003
## 130 0.323 0.320 -0.020 0.003
## 131 0.305 0.270 0.013 0.015
## 132 0.169 0.166 -0.006 0.003
## 133 0.475 0.470 -0.011 0.004
## 134 0.447 0.432 0.002 0.004
## 135 0.357 0.341 -0.018 0.016
## 136 0.852 0.848 -0.012 0.005
## 137 0.862 0.858 -0.007 0.004
## 138 0.153 0.151 -0.003 0.002
## 139 0.314 0.312 -0.009 0.002
## 140 0.324 0.305 0.005 0.003
## 141 0.345 0.336 0.000 0.007
## 142 0.514 0.486 0.007 0.001
## 143 0.281 0.274 0.001 0.005
## 144 0.509 0.503 -0.015 0.007
## 145 0.687 0.684 0.001 0.002
## 146 0.760 0.739 0.007 0.003
## 147 0.441 0.418 0.004 0.005
## 148 0.678 0.658 0.007 0.004
## 149 0.786 0.761 0.007 0.002
## 150 0.806 0.800 0.002 0.002
## 151 0.433 0.412 0.002 0.007
## 152 0.436 0.423 0.005 0.003
## 153 0.437 0.415 0.007 0.002
## 154 0.531 0.525 0.001 0.004
## 155 0.818 0.809 0.002 0.000
## 156 0.848 0.844 -0.003 0.003
## 157 0.642 0.643 -0.001 0.002
## 158 0.830 0.816 0.005 0.002
## 159 0.618 0.618 -0.004 0.002
## 160 0.300 0.293 -0.009 0.006
## 161 0.293 0.290 -0.002 0.002
## 162 0.412 0.371 0.011 0.002
## 163 0.454 0.450 -0.004 0.003
## 164 0.471 0.464 -0.018 0.007
## 165 0.587 0.582 -0.009 0.006
## 166 0.265 0.234 0.009 0.005
## 167 0.233 0.233 -0.005 0.004
## 168 0.353 0.345 -0.021 0.008
## 169 0.213 0.200 -0.007 0.012
## 170 0.286 0.285 -0.022 0.002
## 171 0.047 0.024 0.005 0.005
## 172 0.105 0.027 0.027 0.017
## 173 0.183 0.165 -0.031 0.020
## 174 0.018 0.003 -0.013 0.012
## 175 0.450 0.399 -0.064 0.046
## 176 0.227 0.102 0.039 0.048
## 177 0.202 0.115 0.031 0.018
## 178 0.208 0.130 0.028 0.015
## 179 0.363 0.315 0.009 0.017
## 180 0.230 0.113 0.042 0.025
## 181 0.334 0.180 0.055 0.045
## 182 0.298 0.178 0.038 0.045
## 183 0.235 0.219 -0.022 0.016
## 184 0.217 0.078 0.048 0.027
## 185 0.295 0.269 0.008 0.004
## 186 0.362 0.352 0.001 0.003
## 187 0.676 0.587 0.032 0.028
## 188 0.480 0.459 0.003 0.003
## 189 0.144 0.145 -0.005 0.002
## 190 0.172 0.173 -0.005 0.001
## 191 0.701 0.697 0.000 0.003
## 192 0.114 0.089 0.006 0.001
## 193 0.073 0.074 -0.002 0.001
## 194 0.798 0.791 0.001 0.006
## 195 0.536 0.527 -0.001 0.009
## 196 0.200 0.197 -0.004 0.002
## 197 0.184 0.173 0.002 0.003
## 198 0.309 0.309 -0.002 0.002
## 199 0.162 0.140 0.005 0.001
## 200 0.380 0.351 0.006 0.002
## 201 0.894 0.877 -0.020 0.017
## 202 0.899 0.879 -0.014 0.018
## 203 0.792 0.790 -0.010 0.003
## 204 1.000 1.000 0.000 0.000
## 205 1.000 1.000 0.000 0.000
## 206 1.000 1.000 0.000 0.000
## 207 1.000 1.000 0.000 0.000
## 208 1.000 1.000 0.000 0.000
## 209 1.000 1.000 0.000 0.000
## 210 1.000 1.000 0.000 0.000
## 211 0.000 0.000 0.000 0.000
## 212 0.000 0.000 0.000 0.000
## 213 0.000 0.000 0.000 0.000
## 214 0.000 0.000 0.000 0.000
## 215 0.000 0.000 0.000 0.000
## 216 0.000 0.000 0.000 0.000
## 217 0.000 0.000 0.000 0.000
## 218 0.000 0.000 0.000 0.000
## 219 0.000 0.000 0.000 0.000
## 220 0.000 0.000 0.000 0.000
## 221 0.000 0.000 0.000 0.000
## 222 0.000 0.000 0.000 0.000
## 223 0.000 0.000 0.000 0.000
## 224 0.000 0.000 0.000 0.000
## 225 0.000 0.000 0.000 0.000
## 226 0.000 0.000 0.000 0.000
## 227 0.000 0.000 0.000 0.000
## 228 0.000 0.000 0.000 0.000
## 229 0.000 0.000 0.000 0.000
## 230 0.000 0.000 0.000 0.000
## 231 0.008 -0.007 0.005 0.001
## 232 0.012 0.001 0.003 0.001
## 233 0.009 -0.009 0.005 0.001
## 234 0.014 -0.004 0.005 0.001
## 235 0.011 -0.006 0.006 0.002
## 236 0.017 -0.001 0.005 0.001
## 237 0.011 0.002 0.002 0.001
## 238 0.009 0.001 0.002 0.001
## 239 0.010 0.003 0.002 0.001
## 240 0.014 0.002 0.004 0.002
## 241 0.008 -0.006 0.004 0.002
## 242 0.013 -0.004 0.006 0.003
## 243 0.015 0.000 0.005 0.002
## 244 0.009 -0.007 0.005 0.002
## 245 0.011 -0.006 0.005 0.002
## 246 0.017 -0.009 0.007 0.001
## 247 0.004 -0.012 0.005 0.001
## 248 0.014 -0.010 0.006 0.001
## 249 0.008 0.001 0.002 0.002
## 250 0.000 0.000 0.000 0.000
## 251 0.000 0.000 0.000 0.000
## 252 0.000 0.000 0.000 0.000
## 253 0.000 0.000 0.000 0.000
## 254 0.000 0.000 0.000 0.000
## 255 0.000 0.000 0.000 0.000
## 256 0.000 0.000 0.000 0.000
## 257 0.044 0.044 -0.002 0.001
## 258 0.986 0.982 0.001 0.000
## 259 0.979 0.974 0.002 0.001
## 260 0.979 0.973 0.002 0.001
## 261 0.029 0.028 -0.002 0.001
##
## Distribution of Moderator: Density and Effective Sample Size
##
## M=1.836 | SD=1.357
##
## moderator wgt Neff
## 1 0 0.206 1981
## 2 1 0.197 2829
## 3 2 0.342 3037
## 4 3 0.190 2430
## 5 4 0.066 1438
##
## variable M SD min max
## 1 moderator 1.84 1.357 0.000 12.000
## 2 wgt 0.20 0.098 0.066 0.342
## 3 Neff 2343.04 647.093 1437.909 3036.516
#get index names
pars = lsem_fert$parameters %>% filter(!duplicated(parindex)) %>% pull(par)
#plot specific indexes
for (idx in fit_meas) {
#plot, save
png(str_glue("figs/{idx}_fert.png"))
sirt:::plot.lsem(lsem_fert, parindex = which(pars == idx), ask = F)
dev.off()
}
#items with variation
#items without extreme pass rates
pass_rates = cog_items %>% colMeans(na.rm = T)
#subset
cog_items_all = cog_items
cog_items = cog_items[pass_rates > .05 & pass_rates < .95]
#item stats
#ne = no extreme items
item_stats = tibble(
item = colnames(cog_items),
# test = item %>% str_replace_all("_?\\d+", ""),
test = item %>% str_extract("^[A-Z_]+") %>% str_replace("_$", "") %>% str_replace("_ITEM", ""),
pass_rate = pass_rates[item]
)
item_stats$test %>% table2()
#fit mirt
items_g = mirt(cog_items, model = 1)
##
Iteration: 1, Log-Lik: -480455.419, Max-Change: 2.49939
Iteration: 2, Log-Lik: -472610.462, Max-Change: 0.39114
Iteration: 3, Log-Lik: -472064.522, Max-Change: 0.10918
Iteration: 4, Log-Lik: -471887.093, Max-Change: 0.05710
Iteration: 5, Log-Lik: -471816.474, Max-Change: 0.04637
Iteration: 6, Log-Lik: -471777.198, Max-Change: 0.04012
Iteration: 7, Log-Lik: -471749.024, Max-Change: 0.03390
Iteration: 8, Log-Lik: -471727.070, Max-Change: 0.02893
Iteration: 9, Log-Lik: -471709.549, Max-Change: 0.02667
Iteration: 10, Log-Lik: -471695.410, Max-Change: 0.02351
Iteration: 11, Log-Lik: -471684.526, Max-Change: 0.02136
Iteration: 12, Log-Lik: -471675.739, Max-Change: 0.01884
Iteration: 13, Log-Lik: -471668.825, Max-Change: 0.01656
Iteration: 14, Log-Lik: -471663.408, Max-Change: 0.01449
Iteration: 15, Log-Lik: -471659.172, Max-Change: 0.01263
Iteration: 16, Log-Lik: -471645.666, Max-Change: 0.00288
Iteration: 17, Log-Lik: -471645.425, Max-Change: 0.00226
Iteration: 18, Log-Lik: -471645.234, Max-Change: 0.00321
Iteration: 19, Log-Lik: -471644.727, Max-Change: 0.00348
Iteration: 20, Log-Lik: -471644.622, Max-Change: 0.00161
Iteration: 21, Log-Lik: -471644.573, Max-Change: 0.00116
Iteration: 22, Log-Lik: -471644.484, Max-Change: 0.00082
Iteration: 23, Log-Lik: -471644.452, Max-Change: 0.00091
Iteration: 24, Log-Lik: -471644.425, Max-Change: 0.00083
Iteration: 25, Log-Lik: -471644.304, Max-Change: 0.00078
Iteration: 26, Log-Lik: -471644.286, Max-Change: 0.00091
Iteration: 27, Log-Lik: -471644.272, Max-Change: 0.00062
Iteration: 28, Log-Lik: -471644.259, Max-Change: 0.00070
Iteration: 29, Log-Lik: -471644.250, Max-Change: 0.00054
Iteration: 30, Log-Lik: -471644.242, Max-Change: 0.00057
Iteration: 31, Log-Lik: -471644.230, Max-Change: 0.00057
Iteration: 32, Log-Lik: -471644.225, Max-Change: 0.00047
Iteration: 33, Log-Lik: -471644.220, Max-Change: 0.00039
Iteration: 34, Log-Lik: -471644.215, Max-Change: 0.00040
Iteration: 35, Log-Lik: -471644.212, Max-Change: 0.00034
Iteration: 36, Log-Lik: -471644.210, Max-Change: 0.00033
Iteration: 37, Log-Lik: -471644.206, Max-Change: 0.00042
Iteration: 38, Log-Lik: -471644.204, Max-Change: 0.00028
Iteration: 39, Log-Lik: -471644.202, Max-Change: 0.00025
Iteration: 40, Log-Lik: -471644.200, Max-Change: 0.00027
Iteration: 41, Log-Lik: -471644.199, Max-Change: 0.00026
Iteration: 42, Log-Lik: -471644.198, Max-Change: 0.00020
Iteration: 43, Log-Lik: -471644.197, Max-Change: 0.00029
Iteration: 44, Log-Lik: -471644.196, Max-Change: 0.00018
Iteration: 45, Log-Lik: -471644.196, Max-Change: 0.00017
Iteration: 46, Log-Lik: -471644.195, Max-Change: 0.00020
Iteration: 47, Log-Lik: -471644.194, Max-Change: 0.00018
Iteration: 48, Log-Lik: -471644.194, Max-Change: 0.00012
Iteration: 49, Log-Lik: -471644.193, Max-Change: 0.00020
Iteration: 50, Log-Lik: -471644.193, Max-Change: 0.00012
Iteration: 51, Log-Lik: -471644.193, Max-Change: 0.00012
Iteration: 52, Log-Lik: -471644.193, Max-Change: 0.00014
Iteration: 53, Log-Lik: -471644.192, Max-Change: 0.00013
Iteration: 54, Log-Lik: -471644.192, Max-Change: 0.00008
#save pars
item_stats$loading = items_g@Fit$`F`[, 1]
item_stats$difficulty = items_g %>% coef() %>% {
.[-length(.)] %>% map_dbl(~.[2]) %>% multiply_by(-1)
}
#item correlations with religiousness
#these have obnoxious print problem
sink("/dev/null")
item_stats$r_fert = map_dbl(cog_items, ~mixedCor(cbind(i = ., r = d$fertility))$rho[2, 1])
item_stats$r_fert_confirmed = map_dbl(cog_items, ~mixedCor(cbind(i = ., r = d$fertility_confirmed))$rho[2, 1])
sink()
#Jensen items
GG_scatter(item_stats, "loading", "r_fert", color = "test") +
scale_color_discrete("Test") +
xlab("g-loading") + ylab("Latent correlation with fertility")
## `geom_smooth()` using formula 'y ~ x'
GG_save("figs/jensen_method_items_fert.png")
## `geom_smooth()` using formula 'y ~ x'
GG_scatter(item_stats, "loading", "r_fert_confirmed", color = "test") +
scale_color_discrete("Test")
## `geom_smooth()` using formula 'y ~ x'
#cors
item_stats[-c(1:2)] %>% wtd.cors()
## pass_rate loading difficulty r_fert r_fert_confirmed
## pass_rate 1.0000 0.119 -0.9861 -0.0119 0.122
## loading 0.1190 1.000 -0.1425 -0.4355 -0.223
## difficulty -0.9861 -0.142 1.0000 0.0184 -0.123
## r_fert -0.0119 -0.435 0.0184 1.0000 0.937
## r_fert_confirmed 0.1222 -0.223 -0.1230 0.9373 1.000
#models
ols(r_fert ~ loading + difficulty, data = item_stats)
## Linear Regression Model
##
## ols(formula = r_fert ~ loading + difficulty, data = item_stats)
##
## Model Likelihood Discrimination
## Ratio Test Indexes
## Obs 193 LR chi2 41.04 R2 0.192
## sigma0.0336 d.f. 2 R2 adj 0.183
## d.f. 190 Pr(> chi2) 0.0000 g 0.018
##
## Residuals
##
## Min 1Q Median 3Q Max
## -0.14618 -0.01846 0.00486 0.02060 0.06803
##
##
## Coef S.E. t Pr(>|t|)
## Intercept 0.0048 0.0057 0.84 0.3997
## loading -0.1062 0.0158 -6.70 <0.0001
## difficulty -0.0015 0.0022 -0.68 0.4996
##
ols(r_fert_confirmed ~ loading + difficulty, data = item_stats)
## Linear Regression Model
##
## ols(formula = r_fert_confirmed ~ loading + difficulty, data = item_stats)
##
## Model Likelihood Discrimination
## Ratio Test Indexes
## Obs 193 LR chi2 14.89 R2 0.074
## sigma0.0318 d.f. 2 R2 adj 0.064
## d.f. 190 Pr(> chi2) 0.0006 g 0.010
##
## Residuals
##
## Min 1Q Median 3Q Max
## -0.144734 -0.017975 0.004206 0.019760 0.066069
##
##
## Coef S.E. t Pr(>|t|)
## Intercept 0.0058 0.0054 1.08 0.2799
## loading -0.0523 0.0150 -3.48 0.0006
## difficulty -0.0046 0.0021 -2.24 0.0262
##
list(
ols(r_fert ~ loading + difficulty, data = item_stats),
ols(r_fert ~ loading + difficulty + test, data = item_stats)
) %>% summarize_models()
list(
ols(r_fert_confirmed ~ loading + difficulty, data = item_stats),
ols(r_fert_confirmed ~ loading + difficulty + test, data = item_stats)
) %>% summarize_models()
#DIF testing on each item
#we need to use a median split
d$fertility_mediansplit = d$fertility <= 1
#fit
DIF_fits = cache_object({
DIF_test(
items = cog_items,
group = d$fertility_mediansplit,
model = 1
)
}, filename = "cache/DIF_fit.rds")
## Cache found, reading object from disk
#test effect size results
DIF_fits$effect_size_test
## $liberal
## Effect Size Value
## 1 STDS 0.4450
## 2 UTDS 0.9882
## 3 UETSDS 0.4450
## 4 ETSSD 0.0226
## 5 Starks.DTFR 0.4396
## 6 UDTFR 0.9881
## 7 UETSDN 0.4397
## 8 theta.of.max.test.D -0.2524
## 9 Test.Dmax 0.5053
##
## $conservative
## Effect Size Value
## 1 STDS 0.4688
## 2 UTDS 0.4688
## 3 UETSDS 0.4688
## 4 ETSSD 0.0238
## 5 Starks.DTFR 0.4658
## 6 UDTFR 0.4658
## 7 UETSDN 0.4658
## 8 theta.of.max.test.D 0.4704
## 9 Test.Dmax 0.5079
#all item results
DIF_fits$DIF_stats
#which items are bad?
bad_items = DIF_fits$DIF_stats %>% filter(p_adj < .05)
bad_items
#redo plot with bad items marked
item_stats$bad = item_stats$item %in% bad_items$item
GG_scatter(item_stats, "loading", "r_fert", color = "test") +
scale_color_discrete("Test") +
xlab("g-loading") + ylab("Latent correlation with fertility") +
#highlight
geom_point(data = item_stats %>% filter(bad),
color = 'red',
size = 3,
shape = 1) +
geom_text_repel(data = item_stats %>% filter(bad),
mapping = aes(label = item, color = NULL), size = 3)
## `geom_smooth()` using formula 'y ~ x'
GG_save("figs/jensen_method_items_fert_dif.png")
## `geom_smooth()` using formula 'y ~ x'
write_sessioninfo()
## R version 4.0.4 (2021-02-15)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Linux Mint 19.3
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=de_DE.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] ggrepel_0.9.1 ggeffects_1.0.1 lavaanPlot_0.6.0
## [4] lavaan_0.6-7 readxl_1.3.1 sirt_3.9-4
## [7] mirt_1.33.2 rms_6.1-0 SparseM_1.78
## [10] kirkegaard_2021-02-08 metafor_2.4-0 Matrix_1.3-2
## [13] psych_2.0.12 magrittr_2.0.1 assertthat_0.2.1
## [16] weights_1.0.1 mice_3.13.0 gdata_2.18.0
## [19] Hmisc_4.4-2 Formula_1.2-4 survival_3.2-7
## [22] lattice_0.20-41 forcats_0.5.1 stringr_1.4.0
## [25] dplyr_1.0.4 purrr_0.3.4 readr_1.4.0
## [28] tidyr_1.1.2 tibble_3.0.6 ggplot2_3.3.3
## [31] tidyverse_1.3.0 pacman_0.5.1
##
## loaded via a namespace (and not attached):
## [1] TAM_3.5-19 TH.data_1.0-10 colorspace_2.0-0
## [4] ellipsis_0.3.1 sjlabelled_1.1.7 snakecase_0.11.0
## [7] htmlTable_2.1.0 base64enc_0.1-3 fs_1.5.0
## [10] rstudioapi_0.13 farver_2.0.3 Deriv_4.1.2
## [13] MatrixModels_0.4-1 mvtnorm_1.1-1 lubridate_1.7.9.2
## [16] xml2_1.3.2 codetools_0.2-18 splines_4.0.4
## [19] mnormt_2.0.2 knitr_1.31 jsonlite_1.7.2
## [22] broom_0.7.4 cluster_2.1.1 dbplyr_2.0.0
## [25] png_0.1-7 DiagrammeR_1.0.6.1 compiler_4.0.4
## [28] httr_1.4.2 backports_1.2.1 cli_2.3.0
## [31] visNetwork_2.0.9 htmltools_0.5.1.1 quantreg_5.82
## [34] tools_4.0.4 gtable_0.3.0 glue_1.4.2
## [37] rsvg_2.1 V8_3.4.0 Rcpp_1.0.6
## [40] cellranger_1.1.0 vctrs_0.3.6 nlme_3.1-152
## [43] conquer_1.0.2 DiagrammeRsvg_0.1 multilevel_2.6
## [46] insight_0.12.0 xfun_0.20 rvest_0.3.6
## [49] lifecycle_0.2.0 dcurver_0.9.2 gtools_3.8.2
## [52] polspline_1.1.19 MASS_7.3-53.1 zoo_1.8-8
## [55] scales_1.1.1 hms_1.0.0 parallel_4.0.4
## [58] sandwich_3.0-0 RColorBrewer_1.1-2 psychometric_2.2
## [61] curl_4.3 yaml_2.2.1 gridExtra_2.3
## [64] rpart_4.1-15 latticeExtra_0.6-29 stringi_1.5.3
## [67] highr_0.8 checkmate_2.0.0 permute_0.9-5
## [70] polycor_0.7-10 rlang_0.4.10 pkgconfig_2.0.3
## [73] matrixStats_0.57.0 evaluate_0.14 labeling_0.4.2
## [76] htmlwidgets_1.5.3 tidyselect_1.1.0 plyr_1.8.6
## [79] R6_2.5.0 generics_0.1.0 multcomp_1.4-15
## [82] DBI_1.1.1 pillar_1.4.7 haven_2.3.1
## [85] foreign_0.8-81 withr_2.4.1 mgcv_1.8-33
## [88] nnet_7.3-15 modelr_0.1.8 crayon_1.4.0
## [91] tmvnsim_1.0-2 rmarkdown_2.6 jpeg_0.1-8.1
## [94] grid_4.0.4 pbivnorm_0.6.0 CDM_7.5-15
## [97] data.table_1.13.6 vegan_2.5-7 reprex_1.0.0.9000
## [100] digest_0.6.27 GPArotation_2014.11-1 munsell_0.5.0
#just the main dataset, less cluttered
d %>%
select(
g, g_time1, g_time2, IQ, IQ_time1, IQ_time2,
race, age, income, education,
fertility, fertility_confirmed
) %>%
write_rds("data/data_out_main_variables.rds", compress = "xz")
#all
#just the main dataset, less cluttered
d %>% write_rds("data/data_out_all_variables.rds", compress = "xz")
if (F) {
#init if not done
renv::init()
library(osfr)
osf_auth(read_lines("~/.config/osf_token"))
osf_proj = osf_retrieve_node("https://osf.io/wndb4/")
osf_upload(osf_proj, conflicts = "overwrite", path =
c(
"data", "figs", "renv.lock",
"notebook.html", "notebook.Rmd",
"sessions_info.txt"
))
}