-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmake.R
57 lines (46 loc) · 1.51 KB
/
make.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
table(polcom$pp_party)
x <- tidyversity:::fit_glmRob(m)
x
sapply(x, is.double)
polcom %>%
tidy_regression(ambiv_sexism_1>3 ~ pp_party + sex, type = "logistic", robust = TRUE) -> m
tidy_summary()
sem1 <- polcom %>%
mutate(therm_2 = therm_2 / 10,
therm_1 = 10 - therm_1 / 10) %>%
tidy_sem_model(news =~ news_1 + news_2 + news_3 + news_4 + news_5 + news_6,
ambiv_sexism =~ ambiv_sexism_1 + ambiv_sexism_2 + ambiv_sexism_3 +
ambiv_sexism_4 + ambiv_sexism_5 + ambiv_sexism_6,
partisan =~ a*therm_1 + a*therm_2,
ambiv_sexism ~ age + sex + hhinc + edu + news + partisan) %>%
tidy_sem()
tidy_summary(sem1)
model <- model_
measurement_and_structural <- function(model) {
## if no regression equation, then they're the same
if (grepl("(<==)\\s{0,}~", model_)) {
return(list(measurement = model, structural = model))
}
## store as structural model
sm <- model
## drop regression lines for measurement model
mm <- strsplit(model, "\\n")[[1]]
mm <- grep("(?<==)\\s{0,}~", mm, perl = TRUE, invert = FALSE, value = TRUE)
mm <- paste(mm, collapse = "\n")
## return model list
list(measurement = mm, structural = sm)
}
measurement_and_structural(model)
update(sem1)
compare2cfa <- function(.data, model, robust = robust) {
model <- measurement_and_structural(model)
if (identical(model$measurement, model$structural)) {
return(NULL)
}
if (robust) {
estimator <- "mlr"
} else {
estimator <- "ml"
}
lavaan::cfa(model$measurement, data = .data, estimator = estimator)
}