Skip to content

Commit

Permalink
Report timing experiment in README
Browse files Browse the repository at this point in the history
  • Loading branch information
haziqj committed May 28, 2024
1 parent 8a94d4e commit bf5bb08
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
32 changes: 32 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,38 @@ list(fit, fit_lav, fit_blav, fit_blavvb) |>
purrr::map_dbl(\(x) x@timing$total)
```

A little experiment to see how sample size affects run time:

```{r}
#| fig-width: 8
#| fig-height: 5
#| echo: false
#| warning: false
#| message: false
load("inst/timing.RData")
res |>
unnest(c(res_blav, res_blavvb, res_inla), names_sep = "_") |>
select(n, ends_with("time")) |>
rename(
blavaan = res_blav_time,
blavaan_vb = res_blavvb_time,
INLAvaan = res_inla_time
) |>
pivot_longer(
cols = -n,
names_to = "method",
values_to = "time"
) |>
ggplot(aes(n, time, col = method)) +
geom_point() +
geom_smooth(se = FALSE) +
scale_x_continuous(labels = scales::comma) +
theme_bw() +
labs(x = "Sample size", y = "Run time (s)",
title = "Total run time to fit two factor SEM with varying sample sizes",
caption = "For MCMC sampling, 1000 burnin and 2000 samples were obtained.")
```

## Outro

```{r}
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ mod <- "
dplyr::glimpse(dat)
#> Rows: 10,000
#> Columns: 6
#> $ y1 <dbl> -1.186116189, 0.235382053, 0.001330662, -1.116578957, -0.537370063,
#> $ y2 <dbl> -2.34516559, 0.55765819, -0.83882171, -0.77999471, -0.79058597, 1.3
#> $ y3 <dbl> -1.5417462, 1.1229198, -0.3525473, -0.9698537, -1.5521626, 2.163050
#> $ y4 <dbl> 1.37136308, 0.20452593, -0.19729736, 0.67467441, 1.01417142, 0.6074
#> $ y5 <dbl> 0.93313963, 0.26060807, -0.81823192, 1.12356724, 0.36066546, 0.2903
#> $ y6 <dbl> 2.22602893, 1.22153810, -0.88099143, 0.84524435, 0.10090842, 0.4738
#> $ y1 <dbl> 1.02192841, 0.29113577, -1.47070927, 0.65444305, -0.77219144, -1.17
#> $ y2 <dbl> 0.57817049, 0.39498437, -1.42764854, 0.80022760, -0.37544841, -2.34
#> $ y3 <dbl> 0.6068068, 0.3128205, -1.1559359, 1.4147742, -0.1831977, -2.5209732
#> $ y4 <dbl> 1.07363543, 0.97521562, 0.12599742, -0.73024295, 0.28783171, 1.5970
#> $ y5 <dbl> 1.30085521, 0.62574636, -0.53820263, -0.99175403, 0.80177352, 0.822
#> $ y6 <dbl> 1.2908936, 0.7196049, 0.6252699, -1.0316967, 1.3074426, 2.0141520,
```

To fit this model using `{INLAvaan}`, use the familiar `{lavaan}`
Expand Down Expand Up @@ -196,6 +196,10 @@ as variational Bayes):
#> INLAvaan lavaan blavaan blavaan_vb
#> 27.785 0.032 47.276 90.578

A little experiment to see how sample size affects run time:

<img src="man/figures/README-unnamed-chunk-6-1.png" width="100%" />

## Outro

``` r
Expand Down Expand Up @@ -289,6 +293,7 @@ sessioninfo::session_info()
#> MASS 7.3-60.2 2024-04-24 [1] local
#> Matrix 1.7-0 2024-03-22 [1] CRAN (R 4.4.0)
#> matrixStats 1.3.0 2024-04-11 [1] CRAN (R 4.4.0)
#> mgcv 1.9-1 2023-12-21 [1] CRAN (R 4.4.0)
#> mi 1.1 2022-06-06 [1] CRAN (R 4.4.0)
#> minqa 1.2.7 2024-05-20 [1] CRAN (R 4.4.0)
#> mnormt 2.1.1 2022-09-26 [1] CRAN (R 4.4.0)
Expand Down
5 changes: 0 additions & 5 deletions inst/demo.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ mod <- "
"
fit <- isem(model = mod, data = dat, meanstructure = FALSE, verbose = TRUE)



tmp <- fit
do.call("inlav_model_test", tmp)

# Political democracy SEM example ----------------------------------------------
myModel <- '
# latent variables
Expand Down
3 changes: 2 additions & 1 deletion inst/timing.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ run_inlav_sim <- function(N) {

# Run simulations --------------------------------------------------------------
res <-
tibble(n = rep(c(100, 250, 500, 1000, 2000), each = 10)) |>
tibble(n = rep(c(100, 250, 500, 1000, 2500, 5000, 7500, 10000), each = 10)) |>
mutate(
res_blav = future_map(
.x = n,
Expand All @@ -94,6 +94,7 @@ res <-
.progress = TRUE
),
)
save(res, file = "inst/timing.RData")

res |>
unnest(c(res_blav, res_blavvb, res_inla), names_sep = "_") |>
Expand Down
Binary file added inst/timing.RData
Binary file not shown.
Binary file added man/figures/README-unnamed-chunk-6-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 bf5bb08

Please sign in to comment.