-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_lavaan.R
115 lines (99 loc) · 2.22 KB
/
benchmark_lavaan.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
library(lavaan)
library(dplyr)
library(purrr)
library(readr)
set.seed(73647820)
source("cfa/functions.R")
args <- commandArgs(trailingOnly = TRUE)
date <- args[1]
results <- read_csv("cfa/config.csv")
results <- filter(results, meanstructure == 0)
results <-
mutate(results,
model_lavaan =
pmap_chr(
results,
~with(
list(...),
lavaan_model(n_factors, n_items, meanstructure))))
results <-
mutate(results,
data = pmap(
results,
~with(
list(...),
read_csv(paste(
"cfa/data/",
"n_factors_",
n_factors,
"_n_items_",
n_items,
"_meanstructure_",
meanstructure,
".csv", sep = ""))
)
)
)
# results$model_lavaan[[24]] <- str_remove_all(results$model_lavaan[[24]], "NA")
# results$model_lavaan[[12]] <- str_remove_all(results$model_lavaan[[12]], "NA")
results <-
mutate(results,
start =
pmap(
results,
~with(
list(...),
cfa(model_lavaan,
data,
estimator = "ml",
std.lv = TRUE,
do.fit = FALSE))))
results <-
mutate(results,
start =
map(
start,
parTable))
results <- mutate(
results,
n_par = map2_dbl(
n_factors,
n_items,
~ 2*(.x*.y) + .x*(.x-1)/2
)
)
const <- 3*(results$n_par[length(results$n_par)]^2)
results <- mutate(
results,
n_repetitions = round(const/(n_par^2)))
#!!!
# results$n_repetitions <- 10
##
benchmarks <- pmap(
results,
~with(list(...),
benchmark_lavaan(
model_lavaan,
data,
n_repetitions,
Estimator)
)
)
benchmark_summary <- map_dfr(benchmarks, extract_results)
results <- bind_cols(results, benchmark_summary)
write_csv2(
select(
results,
Estimator,
n_factors,
n_items,
meanstructure,
n_repetitions,
mean_time,
median_time,
sd_time,
error,
warnings,
messages),
paste("cfa/results/benchmarks_lavaan_", date, ".csv", sep = ""))
# write_rds(results, "results.rds")