Skip to content

Commit bd710c5

Browse files
committed
allow for both bounds= and rstarts= opion (github issue 411)
1 parent 63c4678 commit bd710c5

4 files changed

+36
-34
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: lavaan
22
Title: Latent Variable Analysis
3-
Version: 0.6-20.2262
3+
Version: 0.6-20.2263
44
Authors@R: c(person(given = "Yves", family = "Rosseel",
55
role = c("aut", "cre"),
66
email = "[email protected]",

R/lav_lavaan_step11_optim.R

+9-7
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,17 @@ lav_lavaan_step11_estoptim <- function(lavdata = NULL, # nolint
228228
}
229229

230230
# pick best solution (if any)
231-
x.noerror <- x.rstarts[!sapply(
232-
x.rstarts,
233-
inherits, "try-error"
234-
)]
235231
x.converged <- vector("list", length = 0L)
236232
fx.rstarts <- numeric(0L)
237-
if (length(x.noerror) > 0L) {
238-
x.converged <-
239-
x.noerror[sapply(x.rstarts, "attr", "converged")]
233+
ok.flag <- sapply(x.rstarts, function(x) {
234+
if (inherits(x, "try-error")) {
235+
return(FALSE)
236+
} else {
237+
return(attr(x, "converged"))
238+
}
239+
})
240+
if (sum(ok.flag) > 0L) {
241+
x.converged <- x.rstarts[ok.flag]
240242
}
241243
if (length(x.converged) > 0L) {
242244
fx.rstarts <- sapply(x.converged, "attr", "fx")

R/lav_options_default.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ lav_options_default <- function() {
330330
elm("bounds", "none", chr = c(
331331
"none", "default", "standard", "user", "wide", "wide.zerovar", "pos.var",
332332
"pos.ov.var", "pos.lv.var")) # new in 0.6-6
333-
elm("rstarts", 0L, nm = "[0, 1000]", num2int = TRUE) # new in 0.6-18
333+
elm("rstarts", 0L, nm = "[0, 10000]", num2int = TRUE) # new in 0.6-18
334334

335335
# inference
336336
elm("se", "default", chr = c(

R/lav_partable_random.R

+25-25
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ lav_partable_random <- function(lavpartable = NULL,
1010
# needed if we still need to compute bounds:
1111
lavh1 = NULL, lavdata = NULL,
1212
lavsamplestats = NULL, lavoptions = NULL) {
13-
# check if we have bounds; if not, add them
13+
1414
lavpta <- lav_partable_attributes(lavpartable)
15-
if (is.null(lavpartable$lower) ||
16-
is.null(lavpartable$upper)) {
17-
lavoptions2 <- lavoptions
18-
lavoptions2$bounds <- "standard"
19-
lavoptions2$optim.bounds <-
20-
list(
21-
lower = c(
22-
"ov.var", "lv.var", "loadings",
23-
"covariances"
24-
),
25-
upper = c(
26-
"ov.var", "lv.var", "loadings",
27-
"covariances"
28-
),
29-
lower.factor = c(1.0, 1.0, 1.0, 0.999),
30-
upper.factor = c(1.0, 1.0, 1.0, 0.999),
31-
min.reliability.marker = 0.1,
32-
min.var.lv.endo = 0.005
33-
)
34-
lavpartable <- lav_partable_add_bounds(
35-
partable = lavpartable,
36-
lavh1 = lavh1, lavdata = lavdata,
37-
lavsamplestats = lavsamplestats, lavoptions = lavoptions2
15+
16+
# ALWAYS (recompute) bounds, as user may have provide other
17+
# bounds (eg "pos.var") (0.6-20)
18+
lavoptions2 <- lavoptions
19+
lavoptions2$bounds <- "standard"
20+
lavoptions2$optim.bounds <-
21+
list(
22+
lower = c(
23+
"ov.var", "lv.var", "loadings",
24+
"covariances"
25+
),
26+
upper = c(
27+
"ov.var", "lv.var", "loadings",
28+
"covariances"
29+
),
30+
lower.factor = c(1.0, 1.0, 1.0, 0.999),
31+
upper.factor = c(1.0, 1.0, 1.0, 0.999),
32+
min.reliability.marker = 0.1,
33+
min.var.lv.endo = 0.005
3834
)
39-
}
35+
lavpartable <- lav_partable_add_bounds(
36+
partable = lavpartable,
37+
lavh1 = lavh1, lavdata = lavdata,
38+
lavsamplestats = lavsamplestats, lavoptions = lavoptions2
39+
)
4040

4141
# replace -Inf/Inf by -1/1 * .Machine$double.eps (for runif)
4242
inf.idx <- which(lavpartable$lower < -1e+16)

0 commit comments

Comments
 (0)