Skip to content

Commit

Permalink
version 0.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
sfcheung authored and cran-robot committed Feb 23, 2024
1 parent e3b7572 commit e9b58eb
Show file tree
Hide file tree
Showing 28 changed files with 514 additions and 136 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: stdmod
Title: Standardized Moderation Effect and Its Confidence Interval
Version: 0.2.9
Version: 0.2.10
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
Expand All @@ -22,15 +22,15 @@ BugReports: https://github.com/sfcheung/stdmod/issues
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests: testthat, knitr, rmarkdown, visreg, lm.beta
Depends: R (>= 4.0.0)
Imports: boot, ggplot2, stats, utils, lavaan, manymome, rlang
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-09-11 11:30:09 UTC; sfcheung
Packaged: 2024-02-22 13:26:37 UTC; sfcheung
Author: Shu Fai Cheung [aut, cre] (<https://orcid.org/0000-0002-9871-9448>),
David Weng Ngai Vong [ctb]
Maintainer: Shu Fai Cheung <shufai.cheung@gmail.com>
Repository: CRAN
Date/Publication: 2023-09-11 14:10:02 UTC
Date/Publication: 2024-02-22 14:10:02 UTC
51 changes: 27 additions & 24 deletions MD5
@@ -1,10 +1,10 @@
8e3ed4e5c3120c92172361986ac46cf4 *DESCRIPTION
84d58b755ec05446d92870081518805d *NAMESPACE
6e4c9cad544cfb77e693e8e73494e08a *NEWS.md
6d88250e3ec6833a1536bacfa81ef358 *DESCRIPTION
f5612283ed58f6203f842393def5c22a *NAMESPACE
df72c8e0a592b04036fa40898b3f9882 *NEWS.md
c91012ec543a1d47a5f0676fc59c49e4 *R/add1_stdmod.R
dabd63219c02abc577b7ccc3b63330ea *R/coef_condeff.R
d813390126f8534f38f7c9497d717f95 *R/coef_stdmod_lavaan.R
39e569056326a758809369c18cd47857 *R/condeff.R
b8d030ec435c9b60cf77128c25a51513 *R/condeff.R
d6938324e28a6c3aeaba524d45a32b97 *R/condeff_boot.R
ce833597ea9cab7a7f571788b1f2b69b *R/confint_condeff.R
c7906d55a49c4dd79c452bc63fd1af94 *R/confint_stdmod.R
Expand All @@ -14,26 +14,26 @@ bcb17baebae7df70b1db3fef7fb27f33 *R/data_2.R
b819d8629b065aab2f664e5f47a023ce *R/data_3.R
49b5410e95b7747809ed3ad1911ab86c *R/data_4.R
687854d151b006cdd910d6f6bdfee6ec *R/helpers.R
9dae6709bd8d4e73d8727b89c4071d42 *R/plotmod.R
d2dba9a32d4c52825e51d89da6b7b40b *R/plotmod.R
436a80d659ba0c1cc1d04f24f4eb91f0 *R/plotmod_helpers.R
f94d22597a6b0de284fa6a96871d3299 *R/plotmod_helpers_2.R
dbbfb6f352b94f6eff13decaea3bf62c *R/print_cond_eff.R
6d1e26948567c8d37108b1bb8d6adc8a *R/print_stdmod.R
40bacea7c71b852f53d6de215d4ef709 *R/print_stdmod_lavaan.R
fa608b4a8a98987c842f2d97315a2524 *R/print_summary_stdmod.R
c1df4287a32b0169979be556e8ee0a03 *R/print_summary_stdmod.R
8dc85d9a885415575f66ea5f330f5353 *R/std_selected.R
a5de0499adb12177a8875e7f6d032451 *R/std_selected_boot.R
1cb169eb2acf4fac9bbee453abe220de *R/stdmod-package.R
582687ed0f63ef323470db4643ea7d66 *R/stdmod.R
f94c6ce9a91686b315a67d30fc57622d *R/stdmod_bootci.R
f3c64e8811a9daa4e3252b02a212e5e4 *R/stdmod_lavaan.R
1eb65f93ba1ea4383f02beed9b277acb *R/summary_stdmod.R
71533d9957cb2ccecb2a1fd94b011de0 *R/summary_stdmod.R
fbdb46b8f7b74a8f9cf683552fc62c12 *R/sweep2.R
828d5dc9e324c120eb600c0d6aaef4f2 *R/update_stdmod.R
a72daa571e2b0c95c6c7513f551865fa *R/update_stdmod.R
22421b57671dae1837ae82e6e9bfd4a5 *R/vcov_stdmod.R
ba75730b942c26b7a21dc29ae3885138 *README.md
2836b2c5db38c9819380bd093383d89d *build/partial.rdb
73747744a9763e54ea1ff25191855195 *build/vignette.rds
fcb19f43597a5c4952eb3dd44e498d5c *README.md
b943a1546a1e17be4eea235ec7b4616b *build/partial.rdb
f134b5fbe12ed83b63d3a665c54d6367 *build/vignette.rds
cfac528a204b0a0ae0235a1f99bafb6a *data/sleep_emo_con.rda
f1f88af1d468fc13dca3e58e09e7c83a *data/test_mod1.rda
7b8802b1880748751497209ff8ca2362 *data/test_mod2.rda
Expand All @@ -45,37 +45,37 @@ d8e41d1a7cc5addf942e6b195e7c1234 *data/test_x_1_w_1_v_1_cat1_n_500.rda
3faf7434efb51873a4810b1dcc0f0e06 *inst/CITATION
73a9eceb039d8ed57db5d33ccfe5ad48 *inst/doc/cond_effect.Rmd
8e599016d126cb89d12e06c007240554 *inst/doc/cond_effect.html
e73069c427d036a04fd3aecfef7f8f3d *inst/doc/moderation.R
43250abdb6be9c06801b9e3c2dcf9167 *inst/doc/moderation.R
4c927d744634fe6f5fcb9caae23e138c *inst/doc/moderation.Rmd
2d5c44f03c1ead62689a2cb4aac4f5dd *inst/doc/moderation.html
0e21aa9bed1d163a7dbb95b1a5c8d5fe *inst/doc/plotmod.R
846b9ea6d1447ad8168f3bd90b2cb814 *inst/doc/moderation.html
de62b6958b6ebc23a2d1c81c421a6f0a *inst/doc/plotmod.R
e9168b3410d5be28dd5138111908ae1b *inst/doc/plotmod.Rmd
217796e00d43f1a117da02412a100c8a *inst/doc/plotmod.html
57d8f7d5d6426fb662e7fcd4531fd50f *inst/doc/std_selected.R
41101be85275e3316376f84d25c34fb0 *inst/doc/plotmod.html
440596292906dfb9234f99db0078ff5f *inst/doc/std_selected.R
fb0927ee277d4f7981bc473829c4341c *inst/doc/std_selected.Rmd
4ba60e95666279890ad83cfc252ddaba *inst/doc/std_selected.html
1099cc957a4a6c6ac75f81ce4a0280f8 *inst/doc/stdmod.R
43981e888dea6a3e7f4a2e42f5ccc8e3 *inst/doc/std_selected.html
ea304269c32b44bf366d63813e77203a *inst/doc/stdmod.R
6541b8b78f7b5c95c5151a81eb838fb1 *inst/doc/stdmod.Rmd
726a2a1f6565c9b6d2364e7cf5e59646 *inst/doc/stdmod.html
0360b8dce832ccc14f306b938b303f1b *inst/doc/stdmod_lavaan.R
7af8a163e4d8b2bb24846d1916016f02 *inst/doc/stdmod.html
f63dbce088afcffe244ad962eff5db1c *inst/doc/stdmod_lavaan.R
c791bdd1939f6b284c31c817af259ebb *inst/doc/stdmod_lavaan.Rmd
8caa0ee07dd3776540a6602f1d2898f7 *inst/doc/stdmod_lavaan.html
1c0a02fa9308d0f17d3dfdfcb5a01488 *inst/doc/stdmod_lavaan.html
e4cc05d13f860685b23f976542a241ba *man/add1.std_selected.Rd
0f406a5327f9e87c2677e1427acea0f6 *man/coef.cond_effect.Rd
c108330ccd79cd6f63d864a462aea078 *man/coef.stdmod_lavaan.Rd
e659c642f668da1b5e3a9fff360c186c *man/cond_effect.Rd
35975cb64dccb1e99eb685236695d63a *man/cond_effect.Rd
795d16c4d387ce0cd29a7a0e64248307 *man/confint.cond_effect.Rd
c3654c6f0355f5a4cd9f15b1bb99ae4e *man/confint.std_selected.Rd
f2743f33206293bf12eb7cb969b53be4 *man/confint.stdmod_lavaan.Rd
bb82e296e58d2ea526ae3f656c9ad2c0 *man/figures/logo.png
bfe49e3c62ff4f7bbd5b335759c1206e *man/plotmod.Rd
a963076cd91ef3abfb5230514249e89b *man/plotmod.Rd
1b169ca01ea84708be6288efe9a4e674 *man/print.cond_effect.Rd
7a5ea08bac5422af15d6116f3889c2b7 *man/print.std_selected.Rd
8fb33c898d6066932fc76b3c13708c13 *man/print.stdmod_lavaan.Rd
f5e487b4cd46a3c8b0d32434c6cbcd23 *man/print.summary.std_selected.Rd
3f5183cfef6a509a391c972386ddec31 *man/sleep_emo_con.Rd
ab61678dcb1af28f24c860b913ef3c28 *man/std_selected.Rd
27a58940e43ae87a56bbf68fbe4a8fc1 *man/stdmod-package.Rd
911859903b700a24577587a2a9af2007 *man/stdmod-package.Rd
6bac7bd9b0026fc8f4a6512d26d06097 *man/stdmod.Rd
6837efd969c2734c39fad15ce7e84b04 *man/stdmod_lavaan.Rd
34638a9746f61ae47249437d53c03ca8 *man/summary.std_selected.Rd
Expand All @@ -93,10 +93,12 @@ ef5a016dfb84e5a0b807214950e8cc12 *man/test_x_1_w_1_v_2_n_500.Rd
6e847adbb57cfae6c8db5405034735bd *tests/testthat/test_condeff_boot.R
53e541030c06662d65209e6f11b3eaf9 *tests/testthat/test_condeff_boot_methods.R
8fbc0aff90b2f4d0f14b1982a9a2ae4a *tests/testthat/test_condeff_methods.R
0ab8ae971f58a373f05f872f32651579 *tests/testthat/test_condeff_user_value.R
d8833fdc2c45cd8d204b8fc3d7214fc8 *tests/testthat/test_methods_stdmod_lavaan.R
2da4234c4ecda23ee99caf953a99a5ae *tests/testthat/test_plotmod.R
1a5c74f3f30a1e5452c0f4f00d86bae1 *tests/testthat/test_plotmod_percentile_more_levels.R
a6915c8ac83a614ca673467b0aa4e7ea *tests/testthat/test_plotmod_tumble.R
aeb58ab43abb69c3744fe23f54237782 *tests/testthat/test_plotmod_user_value.R
66a05a4f86230a6dad0e33fc1999a7b0 *tests/testthat/test_stdmod.R
ae024e39fa03a714e4095a36f5e6d36e *tests/testthat/test_stdmod_cat.R
cf2313e1050b1e0bbe62a3c98b3d9aae *tests/testthat/test_stdmod_lavaan.R
Expand All @@ -109,6 +111,7 @@ ce14ffeb97dd862eeb2a52b4bec8a549 *tests/testthat/test_stdmod_lavaan_2.R
a20f09dcf7ba6ab243e2c70b2429e4e4 *tests/testthat/test_stdmod_selected_confint.R
a48b3233ecd66001c173f098364ce25b *tests/testthat/test_stdmod_selected_fac.R
3fbce7cd8dfe2a25d9fd701602acb80a *tests/testthat/test_stdmod_selected_print_summary.R
3b6de8af9aac71691c0c23f1dc941350 *tests/testthat/test_stdmod_selected_print_summary_rsq.R
306aa52355cc517ca587f6352dbf476f *tests/testthat/test_stdmod_selected_update.R
436288a2f8303dc81863cb2cb765e0b7 *tests/testthat/test_stdmod_selected_vcov.R
26295d6ce031783107376927e1088383 *tests/testthat/test_stdmod_selectedj_to_std.R
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -22,3 +22,4 @@ export(stdmod)
export(stdmod_boot)
export(stdmod_lavaan)
importFrom(rlang,.data)
importFrom(stats,anova)
28 changes: 28 additions & 0 deletions NEWS.md
@@ -1,3 +1,31 @@
# stdmod 0.2.10

## New Features

- Improved the printout of the `summary()`
of `std_selected()`
and `std_selected_boot()` outputs.
It now prints the R-squared increase
of the highest order term, as well as
the *F* test for the increase, if the
model has one and only one highest
order term (e.g., an interaction
term). (0.2.9.1)

- Added the argument `w_values` to
`cond_effect()` and `plolmod()`.
Users can specify the
values of the moderator (`w`)
to be used to compute the conditional
effects. (0.2.9.2)

## Miscellaneous

- Revised `update.std_selected()`. Though
still not recommended, it should now
work more reliably if it needs to be
called. (0.2.9.1)

# stdmod 0.2.9

- Fixed the issue with `stdmod-package`. (0.2.8.9001)
Expand Down
39 changes: 29 additions & 10 deletions R/condeff.R
Expand Up @@ -102,6 +102,19 @@
#' "high" for the moderator. Default is 1.
#' Ignored if `w` is categorical.
#'
#' @param w_values The values of `w` to
#' be used. Default is `NULL`. If a
#' numeric vector is supplied, these
#' values will be used to compute the
#' conditional effects. Other arguments
#' on generating levels are ignored.
#' Note that, if `w` has been standardized
#' or centered, these values are for
#' the standardized or centered `w`.
#' The values will always be sorted.
#' This argument is ignored if `w` is
#' categorical.
#'
#' @author Shu Fai Cheung <https://orcid.org/0000-0002-9871-9448>
#'
#'
Expand Down Expand Up @@ -133,7 +146,8 @@ cond_effect <- function(output,
w_method = c("sd", "percentile"),
w_percentiles = c(.16, .50, .84),
w_sd_to_percentiles = NA,
w_from_mean_in_sd = 1
w_from_mean_in_sd = 1,
w_values = NULL
) {
mf0 <- stats::model.frame(output)
w_method <- match.arg(w_method)
Expand Down Expand Up @@ -165,15 +179,20 @@ cond_effect <- function(output,
class(output0) <- tmp[!(tmp %in% "std_selected")]
}
if (w_numeric) {
w_levels <- gen_levels(mf0[, w],
method = w_method,
from_mean_in_sd = w_from_mean_in_sd,
levels = c(-1, 0, 1),
sd_levels = c(-1, 0, 1),
sd_to_percentiles = w_sd_to_percentiles,
percentiles = w_percentiles)
w_levels <- sort(w_levels, decreasing = TRUE)
w_levels_labels <- c("High", "Medium", "Low")
if (is.numeric(w_values)) {
w_levels <- sort(w_values, decreasing = TRUE)
w_levels_labels <- as.character(w_levels)
} else {
w_levels <- gen_levels(mf0[, w],
method = w_method,
from_mean_in_sd = w_from_mean_in_sd,
levels = c(-1, 0, 1),
sd_levels = c(-1, 0, 1),
sd_to_percentiles = w_sd_to_percentiles,
percentiles = w_percentiles)
w_levels <- sort(w_levels, decreasing = TRUE)
w_levels_labels <- c("High", "Medium", "Low")
}
} else {
w_levels <- levels(as.factor(mf0[, w]))
w_levels_labels <- w_levels
Expand Down
70 changes: 45 additions & 25 deletions R/plotmod.R
Expand Up @@ -117,6 +117,20 @@
#' `x_sd_to_percentiles` is set to 1, then the lower
#' and upper percentiles are 16th and 84th,
#' respectively. Default is `NA`.
#'
#' @param w_values The values of `w` to
#' be used. Default is `NULL`. If a
#' numeric vector is supplied, these
#' values will be used to compute the
#' conditional effects. Other arguments
#' on generating levels are ignored.
#' Note that, if `w` has been standardized
#' or centered, these values are for
#' the standardized or centered `w`.
#' The values will always be sorted.
#' This argument is ignored if `w` is
#' categorical.
#'
#' @param note_standardized If `TRUE`, will check whether a variable has SD
#' nearly equal to one. If yes, will report this in the
#' plot.
Expand Down Expand Up @@ -192,6 +206,7 @@ plotmod <- function(output, x, w,
x_percentiles = c(.16, .84),
w_sd_to_percentiles = NA,
x_sd_to_percentiles= NA,
w_values = NULL,
note_standardized = TRUE,
no_title = FALSE,
line_width = 1,
Expand Down Expand Up @@ -225,32 +240,37 @@ plotmod <- function(output, x, w,
stop("x variable must be a numeric variable.")
}
if (w_numeric) {
w_levels <- gen_levels(mf0[, w],
method = w_method,
from_mean_in_sd = w_from_mean_in_sd,
levels = c(-1, 1),
sd_levels = c(-1, 1),
sd_to_percentiles = w_sd_to_percentiles,
percentiles = w_percentiles)
tmp <- length(w_levels)
if (tmp == 2) {
w_levels_labels <- c("Low", "High")
}
if (tmp == 3) {
w_levels_labels <- c("Low", "Medium", "High")
}
if (tmp > 3) {
if (w_method == "percentile") {
w_levels_labels <- paste0(formatC(w_percentiles * 100,
digits = 0,
format = "f"),
"%")
} else {
w_levels_labels <- formatC(w_levels,
digits = 2,
format = "f")
if (is.numeric(w_values)) {
w_levels <- sort(w_values, decreasing = TRUE)
w_levels_labels <- as.character(w_levels)
} else {
w_levels <- gen_levels(mf0[, w],
method = w_method,
from_mean_in_sd = w_from_mean_in_sd,
levels = c(-1, 1),
sd_levels = c(-1, 1),
sd_to_percentiles = w_sd_to_percentiles,
percentiles = w_percentiles)
tmp <- length(w_levels)
if (tmp == 2) {
w_levels_labels <- c("Low", "High")
}
if (tmp == 3) {
w_levels_labels <- c("Low", "Medium", "High")
}
}
if (tmp > 3) {
if (w_method == "percentile") {
w_levels_labels <- paste0(formatC(w_percentiles * 100,
digits = 0,
format = "f"),
"%")
} else {
w_levels_labels <- formatC(w_levels,
digits = 2,
format = "f")
}
}
}
} else {
w_lo <- NA
w_hi <- NA
Expand Down
37 changes: 37 additions & 0 deletions R/print_summary_stdmod.R
Expand Up @@ -171,6 +171,19 @@ print.summary.std_selected <- function(x, ...,
p_digits = ceiling(-log10(pvalue_less_than)))
cat("\n")
}
if (!is.na(x$highest_order) && !identical(x$f_highest, NA)) {
rsq_highest <- formatC(x$f_highest[2, "R.sq.change"],
digits = est_digits,
format = "f")
cat("= Test the highest order term =",
paste0("The highest order term : ", x$highest_order),
paste0("R-squared increase adding this term: ", rsq_highest),
sep = "\n")
print_fstatistic_change(x$f_highest,
f_digits = t_digits,
p_digits = ceiling(-log10(pvalue_less_than)))
cat("\n")
}
tmp <- character(0)
if (scaled_or_centered) {
tmp1 <- paste("- Estimates and their statistics are based on the data after",
Expand Down Expand Up @@ -241,12 +254,36 @@ print_fstatistic <- function(fstatistic,
p <- stats::pf(f, df1, df2, lower.tail = FALSE)
p_txt <- format_pvalue(p,
eps = 10^(-p_digits))
if (!grepl("^<", p_txt)) {
p_txt <- paste0("= ", p_txt)
}
cat("ANOVA test of R-squared : ",
f_txt, ", p ", p_txt, "\n", sep = "")
}

#' @noRd

print_fstatistic_change <- function(fstatistic,
f_digits = 4,
p_digits = 3) {
f <- fstatistic[2, "F"]
df1 <- fstatistic[2, "Df"]
df2 <- fstatistic[2, "Res.Df"]
f_txt <- paste0("F(",
df1, ", ", df2, ") = ",
round(f, f_digits))
p <- fstatistic[2, "Pr(>F)"]
p_txt <- format_pvalue(p,
eps = 10^(-p_digits))
if (!grepl("^<", p_txt)) {
p_txt <- paste0("= ", p_txt)
}
cat("F test of R-squared increase : ",
f_txt, ", p ", p_txt, "\n", sep = "")
}

#' @noRd

format_pvalue <- function(p,
eps = 1e-3) {
p_digits <- ceiling(-log10(eps))
Expand Down

0 comments on commit e9b58eb

Please sign in to comment.