Skip to content

Commit

Permalink
Merge pull request #46 from sfcheung/devel
Browse files Browse the repository at this point in the history
Update to 0.1.3.5
  • Loading branch information
sfcheung authored Apr 7, 2024
2 parents e888596 + eadc463 commit 791ccea
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 66 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: modelbpp
Title: Model BIC Posterior Probability
Version: 0.1.3.4
Version: 0.1.3.5
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
Expand Down
16 changes: 10 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# modelbpp 0.1.3.4
# modelbpp 0.1.3.5

## New Features

Expand All @@ -9,15 +9,15 @@
covariances involving a predictor
and an outcome variable (including
those linked by indirect paths).
Default values are `FALSE` for now
to maintain backward compatibility but
will be changed to `TRUE` in the
future. (0.1.3.2)
Default values has been changed
to `TRUE` since 0.1.3.5. To
reproduce results from previous version,
set them to `FALSE`. (0.1.3.2, 0.1.3.5)

- Added `min_bpp_labelled` to
`model_graph()`, to hide the labels
of models with small BPPs.
(0.1.3.4)
(0.1.3.5)

## Bug Fixes

Expand All @@ -26,6 +26,10 @@
not be recognized as interchangeable.
(0.1.3.1)

- Fixed a bug in `must_not_drop` and
`must_drop` of `get_drop()`. They
should work properly now. (0.1.3.5)

- Fixed a bug in `model_graph()`.
Short names should now be properly
constructed. (0.1.3.3)
Expand Down
4 changes: 2 additions & 2 deletions R/get_drop.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ get_drop <- function(sem_out,
# User specified parameters
if (!is.null(must_drop)) {
id_must_drop <- syntax_to_id(must_drop, ptable = pt)
id_to_drop <- union(id_to_drop, id_must_drop)
id_to_drop[id_must_drop] <- TRUE
}
if (!is.null(must_not_drop)) {
id_must_not_drop <- syntax_to_id(must_not_drop, ptable = pt)
id_to_drop <- setdiff(id_to_drop, id_must_not_drop)
id_to_drop[id_must_not_drop] <- FALSE
}
if (any(id_to_drop)) {
# Determine the sets of changes
Expand Down
29 changes: 16 additions & 13 deletions R/model_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@
#' loop. For example, if there is
#' path from `x` through `m` to `y`,
#' then the path `x ~ y` will create
#' a feedback loop. Default is `FALSE`
#' for now, to maintain backward
#' compatibility.
#' Do not rely on the default value
#' because it will be changed to `TRUE`
#' in a future major version.
#' a feedback loop. Default has been
#' changed to
#' `TRUE` since Version 0.1.3.5 because
#' feedback loops are usually
#' not included except when theoretically
#' justified. To reproduce results
#' based on previous version, set this
#' argument to `FALSE`.
#'
#' @param exclude_xy_cov Exclude
#' covariance between two variables,
Expand All @@ -120,11 +122,12 @@
#' which denotes the covariance between
#' `x` and the error term of `y`, will
#' be excluded if this argument is
#' `TRUE`. Default is `FALSE` for now,
#' to maintain backward compatibility.
#' Do not rely on the default value
#' because it will be changed to `TRUE`
#' in a future major version.
#' `TRUE`. Default has been changed to
#' `TRUE` since Version 0.1.3.5 because
#' these covariances rarely are
#' interpretable. To reproduce results
#' based on previous version, set this
#' argument to `FALSE`.
#'
#' @param must_drop A character vector
#' of parameters, named in
Expand Down Expand Up @@ -319,8 +322,8 @@ model_set <- function(sem_out,
must_not_drop = NULL,
remove_constraints = TRUE,
exclude_error_cov = TRUE,
exclude_feedback = FALSE,
exclude_xy_cov = FALSE,
exclude_feedback = TRUE,
exclude_xy_cov = TRUE,
df_change_add = 1,
df_change_drop = 1,
remove_duplicated = TRUE,
Expand Down
17 changes: 11 additions & 6 deletions R/print.model_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,25 +300,30 @@ print.model_set <- function(x,
cat("- Cumulative: Cumulative BIC posterior probability.\n")
}
if (gt_max_models) {
x <- paste(fit_n,
tmp <- paste(fit_n,
"models were fitted but",
max_models,
"were printed. Call print() and",
"set 'max_models' to a larger number",
"to print more models, or set it to",
"NA to print all models.")
catwrap(x, initial = "- ", exdent = 2)
catwrap(tmp, initial = "- ", exdent = 2)
}
if (models_fitted &&
(k_converged != fit_n) &&
any(is.na(postprob_tmp))) {
x <- "BPP and/or prior not computed because one or more models not converged."
catwrap(x, initial = "- ", exdent = 2)
tmp <- "BPP and/or prior not computed because one or more models not converged."
catwrap(tmp, initial = "- ", exdent = 2)
}
if (models_fitted &&
(k_post_check != fit_n)) {
x <- "Interpret with caution. One or more models failed lavaan's post.check."
catwrap(x, initial = "- ", exdent = 2)
tmp <- "Interpret with caution. One or more models failed lavaan's post.check."
catwrap(tmp, initial = "- ", exdent = 2)
}
tmp <- paste0("Since Version 0.1.3.5, the default values of ",
"exclude_feedback and exclude_xy_cov changed to TRUE. ",
"Set them to FALSE to reproduce results from previous versions.")
catwrap(tmp, initial = "- ", exdent = 2)

invisible(x)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# modelbpp: Model BIC Posterior Probability <img src="man/figures/logo.png" align="right" />

(Version 0.1.3.4 updated on 2024-04-06, [release history](https://sfcheung.github.io/modelbpp/news/index.html))
(Version 0.1.3.5 updated on 2024-04-07, [release history](https://sfcheung.github.io/modelbpp/news/index.html))

This package is for assessing model uncertainty in structural
equation modeling (SEM) by the BIC posterior
Expand Down
29 changes: 16 additions & 13 deletions man/model_set.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified vignettes/graph1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/graph1_df2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed vignettes/graph1_no_cov-1.png
Binary file not shown.
53 changes: 29 additions & 24 deletions vignettes/modelbpp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ out1_bpp_2 <- sort(out1_bpp, decreasing = TRUE)[2]
```

The total number of models examined,
including the original model, is 9.
including the original model, is `r length(out1$models)`.

(Note: The total number of models
was 9 in previous version. Please
refer to the Note in the printout for
the changes.)

The BIC posterior probabilities
(BPPs) suggest that
Expand Down Expand Up @@ -186,17 +191,17 @@ equally probable before having data
prior probabilities). A researcher
fits the original model because

- its
prior probability is higher than other
models, at least other neighboring
models (otherwise, it is not worthy
of collecting data assess thi original
model), but
- its
prior probability is higher than other
models, at least other neighboring
models (otherwise, it is not worthy
of collecting data assess thi original
model), but

- the prior probability
is not so high to eliminate the need
for collecting data to see how much it is
supported by data.
- the prior probability
is not so high to eliminate the need
for collecting data to see how much it is
supported by data.

Suppose we decide that the prior probability
of the original model is .50: probable, but
Expand Down Expand Up @@ -258,15 +263,15 @@ out1_df2 <- model_set(fit1,
```

This is the printout. By default, when there
are more than 10 models, only the top 10
are more than 20 models, only the top 20
models on BPP will be printed:

```{r}
out1_df2
```

The number of models examined, including
the original model, is 18.
the original model, is `r length(out1_df2$models)`.

This is the output of `model_graph()`:

Expand All @@ -289,32 +294,32 @@ specify parameters that must be excluded
from the list to be added (`must_not_add`),
or must not be dropped (`must_not_drop`).

For example, it may not make sense To
add the error covariance between `m1`
and `y` (`m1~~y`). We can exclude it
For example, suppose it is well
established that `m1~x` exists and should
not be dropped, we can exclude it
when calling `model_set()`

```{r results = FALSE}
out1_no_cov <- model_set(fit1,
must_not_add = "m1~~y")
out1_no_m1_x <- model_set(fit1,
must_not_drop = "m1~x")
```

This is the output:

```{r}
out1_no_cov
out1_no_m1_x
```

The number of models reduced to 8.
The number of models reduced to `r length(out1_df2$models)`.

This is the plot:

```{r graph1_no_cov, ig.height = 8, fig.width = 8, eval = FALSE}
graph1_no_cov <- model_graph(out1_no_cov)
plot(graph1_no_cov)
```{r out1_no_m1_x, ig.height = 8, fig.width = 8, eval = FALSE}
out1_no_m1_x <- model_graph(out1_no_m1_x)
plot(out1_no_m1_x)
```

![](graph1_no_cov-1.png)
![](out1_no_m1_x-1.png)

## Models With Constraints

Expand Down
Binary file added vignettes/out1_no_m1_x-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/out1_prior-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 791ccea

Please sign in to comment.