Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.4 #191

Merged
merged 4 commits into from
Oct 4, 2024
Merged

0.2.4 #191

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: manymome
Title: Mediation, Moderation and Moderated-Mediation After Model Fitting
Version: 0.2.3.14
Version: 0.2.4
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
Expand Down
14 changes: 12 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# manymome 0.2.3.14
# manymome 0.2.4

## New Features

Expand Down Expand Up @@ -54,9 +54,19 @@

- Added `wrap_computation` to the argument
of `print.indirect()` to wrap the printout
of long computational formulas.
of long computational formulas. Default
set to `TRUE`.
(0.2.3.14)

- Updated `plot_effect_vs_w()` to check
whether a moderator is numeric.
(0.2.3.15)

- Updated `print.cond_indirect_effects()`.
Disabled the printing of the (only)
component path when a path has no
mediator. (0.2.3.16)

## Documentation and Notes

- Corrected `README` to remark that
Expand Down
2 changes: 1 addition & 1 deletion R/plot_effect_vs_w.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ plot_effect_vs_w <- function(object,
if (ncol(wlevels) > 1) {
stop("Only an effect with one moderator is supported.")
}
if (!is.numeric(wlevels[, 1])) {
if (!((isTRUE(w_type == "numeric")) || is.null(w_type))) {
stop("Only numeric moderators are supported.")
}
if (is.null(w)) {
Expand Down
10 changes: 7 additions & 3 deletions R/print_cond_indirect_effect.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,13 @@ print.cond_indirect_effects <- function(x, digits = 3,
i <- which(names(out) == "ind")
j <- length(out)
out <- c(out[1:i], out_original, out[(i + 1):j])
# Drop the component column
}
# Drop the component column if the model has no mediator
if (!has_m) {
i <- which(names(out) %in% names(x_i$components))
out <- out[-i]
if (length(i) > 0) {
out <- out[-i]
}
}
out1 <- data.frame(out, check.names = FALSE)
if (has_wlevels) {
Expand Down Expand Up @@ -557,7 +561,7 @@ print.cond_indirect_effects <- function(x, digits = 3,
ifelse(has_wlevels,
"the moderator(s).",
"the group(s)."))
if (!print_original_se) {
if (has_m) {
cat(strwrap(paste("\n -", paste(sQuote(mcond), collapse = ","),
"is/are the path coefficient(s) along the path",
"conditional on",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![R-CMD-check](https://github.com/sfcheung/manymome/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sfcheung/manymome/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

(Version 0.2.3.14, updated on 2024-10-02, [release history](https://sfcheung.github.io/manymome/news/index.html))
(Version 0.2.4, updated on 2024-10-04, [release history](https://sfcheung.github.io/manymome/news/index.html))

# manymome <img src="man/figures/logo.png" align="right" height="150" />

Expand Down
11 changes: 6 additions & 5 deletions tests/testthat/test_mod_only_plot_vs_w.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ sos_2 <- cond_indirect_effects(wlevels = "w1",
sos_3 <- cond_indirect_effects(wlevels = c("w1", "w2"),
x = "m", y = "y",
fit = fit3)

plot_effect_vs_w(cos_1a, level = .99) + ggplot2::ylim(0, 1)
plot_effect_vs_w(cos_1a) + ggplot2::ylim(0, 1)
plot_effect_vs_w(cos_1a, level = .60) + ggplot2::ylim(0, 1)
plot_effect_vs_w(cos_1a, level = .50) + ggplot2::ylim(0, 1)
test_that("mod only", {
expect_no_error(plot_effect_vs_w(cos_1a, level = .99) + ggplot2::ylim(0, 1))
expect_no_error(plot_effect_vs_w(cos_1a) + ggplot2::ylim(0, 1))
expect_no_error(plot_effect_vs_w(cos_1a, level = .60) + ggplot2::ylim(0, 1))
expect_no_error(plot_effect_vs_w(cos_1a, level = .50) + ggplot2::ylim(0, 1))
})
9 changes: 9 additions & 0 deletions tests/testthat/test_plot_indirect_vs_w.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ test_that("Expand wlevels", {
p1
})

test_that("Detect categorical moderators", {
dat <- data_med_mod_serial_cat
lm_m <- lm(m1 ~ x*w2, dat)
lm_y <- lm(y ~ m1 + x, dat)
lm_all <- lm2list(lm_m, lm_y)
cond_out <- cond_indirect_effects(x = "x", y = "y", m = "m1", wlevels = "w2", fit = lm_all)
expect_error(plot_effect_vs_w(cond_out), "numeric moderators")
})

# Multigroup

# On hold. cond_indirect_effects() does not yet support
Expand Down
29 changes: 18 additions & 11 deletions vignettes/articles/med_mg.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Multigroup Models With Mediation Effects"
author: "Shu Fai Cheung & Sing-Hang Cheung"
date: "2024-09-25"
date: "2024-10-04"
output:
html_document:
fig.align: "center"
Expand Down Expand Up @@ -85,7 +85,7 @@ These are the estimates of the paths:
``` r
summary(fit,
estimates = TRUE)
#> lavaan 0.6-18 ended normally after 1 iteration
#> lavaan 0.6-19 ended normally after 1 iteration
#>
#> Estimator ML
#> Optimization method NLMINB
Expand Down Expand Up @@ -204,7 +204,7 @@ fit_boot_out <- do_boot(fit = fit,
seed = 53253,
ncores = 8)
#> 8 processes started to run bootstrapping.
#> The expected CPU time is about 22.5 second(s).
#> The expected CPU time is about 15 second(s).
```

# Estimate Indirect Effects
Expand Down Expand Up @@ -253,9 +253,11 @@ ind_gpA
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.87989)*(0.46481)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 5000 bootstrap samples.
#>
Expand Down Expand Up @@ -304,9 +306,11 @@ ind_gpB
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.59716)*(1.11040)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 5000 bootstrap samples.
#>
Expand Down Expand Up @@ -512,9 +516,11 @@ std_gpA
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)*sd_x/sd_y
#>
#> Computation:
#> (0.87989)*(0.46481)*(1.10557)/(2.21581)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 5000 bootstrap samples.
#>
Expand Down Expand Up @@ -553,9 +559,11 @@ std_gpB
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)*sd_x/sd_y
#>
#> Computation:
#> (0.59716)*(1.11040)*(1.00943)/(2.58386)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 5000 bootstrap samples.
#>
Expand Down Expand Up @@ -825,15 +833,14 @@ path1
#> Path: m -> y
#> Conditional on group(s): Group A[1], Group B[2]
#>
#> Group Group_ID ind CI.lo CI.hi Sig y~m
#> 1 Group A 1 0.465 0.110 0.819 Sig 0.465
#> 2 Group B 2 1.110 0.765 1.475 Sig 1.110
#> Group Group_ID ind CI.lo CI.hi Sig
#> 1 Group A 1 0.465 0.110 0.819 Sig
#> 2 Group B 2 1.110 0.765 1.475 Sig
#>
#> - [CI.lo to CI.hi] are 95.0% percentile confidence intervals by
#> nonparametric bootstrapping with 5000 samples.
#> - The 'ind' column shows the direct effects.
#> - 'y~m' is/are the path coefficient(s) along the path conditional on
#> the group(s).
#>
```

The difference between the two paths can be tested
Expand All @@ -852,9 +859,9 @@ path1_diff
#> Path: m -> y
#> Conditional on group(s): Group B[2], Group A[1]
#>
#> Group Group_ID ind CI.lo CI.hi Sig y~m
#> 1 Group B 2 1.110 0.765 1.475 Sig 1.110
#> 2 Group A 1 0.465 0.110 0.819 Sig 0.465
#> Group Group_ID ind CI.lo CI.hi Sig
#> 1 Group B 2 1.110 0.765 1.475 Sig
#> 2 Group A 1 0.465 0.110 0.819 Sig
#>
#> == Difference in Conditional Indirect Effect ==
#>
Expand Down
10 changes: 7 additions & 3 deletions vignettes/do_boot.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Generate Bootstrap Estimates"
author: "Shu Fai Cheung & Sing-Hang Cheung"
date: "2024-09-25"
date: "2024-10-04"
output:
rmarkdown::html_vignette:
number_sections: true
Expand Down Expand Up @@ -86,7 +86,7 @@ fit_lavaan <- sem(model = mod, data = dat,
fixed.x = FALSE,
estimator = "MLR")
summary(fit_lavaan)
#> lavaan 0.6-18 ended normally after 1 iteration
#> lavaan 0.6-19 ended normally after 1 iteration
#>
#> Estimator ML
#> Optimization method NLMINB
Expand Down Expand Up @@ -244,9 +244,11 @@ out_lavaan
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.93469)*(0.78469)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 500 bootstrap samples.
#>
Expand Down Expand Up @@ -344,7 +346,7 @@ regression outputs to one object using
fit_lm <- lm2list(lm_m, lm_y)
fit_lm
#>
#> The models:
#> The model(s):
#> m ~ x + c1 + c2
#> y ~ m + x + c1 + c2
```
Expand Down Expand Up @@ -402,9 +404,11 @@ out_lm
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.93469)*(0.78469)
#>
#>
#> Percentile confidence interval formed by nonparametric bootstrapping
#> with 500 bootstrap samples.
#>
Expand Down
6 changes: 4 additions & 2 deletions vignettes/do_mc.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Generate Monte Carlo Estimates"
author: "Shu Fai Cheung & Sing-Hang Cheung"
date: "2024-09-25"
date: "2024-10-04"
output:
rmarkdown::html_vignette:
number_sections: true
Expand Down Expand Up @@ -106,7 +106,7 @@ fit_lavaan <- sem(model = mod, data = dat,
fixed.x = FALSE,
estimator = "MLR")
summary(fit_lavaan)
#> lavaan 0.6-18 ended normally after 1 iteration
#> lavaan 0.6-19 ended normally after 1 iteration
#>
#> Estimator ML
#> Optimization method NLMINB
Expand Down Expand Up @@ -225,9 +225,11 @@ out_lavaan
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.93469)*(0.78469)
#>
#>
#> Monte Carlo confidence interval with 10000 replications.
#>
#> Coefficients of Component Paths:
Expand Down
4 changes: 3 additions & 1 deletion vignettes/do_mc_lavaan_mi.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Monte Carlo Confidence Intervals with Multiple Imputation"
author: "Shu Fai Cheung & Sing-Hang Cheung"
date: "2024-09-25"
date: "2024-10-04"
output:
rmarkdown::html_vignette:
number_sections: true
Expand Down Expand Up @@ -246,9 +246,11 @@ out_lavaan
#>
#> Computation Formula:
#> (b.m~x)*(b.y~m)
#>
#> Computation:
#> (0.89141)*(0.73569)
#>
#>
#> Monte Carlo confidence interval with 10000 replications.
#>
#> Coefficients of Component Paths:
Expand Down
Loading
Loading