Skip to content
Merged
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: power4mome
Title: Power Analysis for Moderation and Mediation
Version: 0.1.1.75
Version: 0.1.1.77
Authors@R:
c(person(given = "Shu Fai",
family = "Cheung",
Expand Down
15 changes: 14 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# power4mome 0.1.1.75
# power4mome 0.1.1.77

- Improve the function for extending the
initial interval before doing a
Expand Down Expand Up @@ -448,6 +448,19 @@
`mode` of `q_power_mediation()`
and friends. (0.1.1.75)

- If the model is a multigroup model,
descriptive statistics for the
generated data are printed by
group, using `psych::describeBy()`.
(0.1.1.76)

- Response proportions will be printed
with `data_long = TRUE` if a variable
has 10 or fewer unique values
(e.g., ordinal variables),
using `psych::responseFrequency()`.
(0.1.1.77)

# power4mome 0.1.1

- Updated to be compatible with the
Expand Down
47 changes: 44 additions & 3 deletions R/sim_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,52 @@ print.sim_data <- function(x,
hw = .4,
prefix = "\n",
suffix = "\n\n"))
if (ngroups > 1) {
tmp <- which(colnames(all_data) == x_i$group_name)
print(psych::describeBy(
all_data[, -tmp],
group = all_data[[x_i$group_name]],
range = FALSE),
digits = digits_descriptive)
} else {
print(psych::describe(all_data,
range = FALSE),
digits = digits_descriptive)
}

print(psych::describe(all_data,
range = FALSE),
digits = digits_descriptive)
# ==== Response Frequencies ====

response_count <- sapply(
all_data[seq_len(n * nrep), ],
\(x) length(unique(x))
)
tmp1 <- response_count <= 10
if (!is.null(x_i$group_name)) {
tmp1[x_i$group_name] <- FALSE
}

if (any(tmp1)) {
cat(header_str("Response Proportions",
hw = .4,
prefix = "\n",
suffix = "\n"))
tmp2 <- unique(response_count[tmp1])
if (ngroups > 1) {
group <- all_data[[x_i$group_name]]
} else {
group <- rep("Single Group", nrow(all_data))
}
for (zz in tmp2) {
tmp3 <- (response_count == zz)
tmp5 <- by(all_data[, tmp3, drop = FALSE],
INDICES = group,
psych::responseFrequency,
simplify = FALSE)
cat("\n")
print(tmp5,
digits = digits_descriptive)
}
}
# Print missing data pattern

mp <- tryCatch(miss_pattern(all_data),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![R-CMD-check](https://github.com/sfcheung/power4mome/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/sfcheung/power4mome/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

(Version 0.1.1.75, updated on 2026-03-15, [release history](https://sfcheung.github.io/power4mome/news/index.html))
(Version 0.1.1.77, updated on 2026-03-17, [release history](https://sfcheung.github.io/power4mome/news/index.html))

# power4mome <a href="https://sfcheung.github.io/power4mome/"><img src="man/figures/logo.png" align="right" height="120" alt="power4mome website" /></a>

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-ordinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ sim_only1 <- power4test(
parallel = FALSE,
iseed = 1234)

expect_output(print(sim_only1, data_long = TRUE),
" Response Proportions ")

tmp <- pool_sim_data(sim_only1)

expect_equal(length(table(tmp$m1)), 4)
Expand Down
33 changes: 33 additions & 0 deletions tests/testthat/test-sim_data_print_mg_des.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
library(testthat)
suppressMessages(library(lavaan))

test_that("sim_out: descriptive for multigroup model", {

mod <-
"
m ~ x
y ~ m + x
"

es <-
"
y ~ m: l
m ~ x:
- nil
- s
y ~ x: nil
"

data_all <- sim_data(nrep = 2,
model = mod,
pop_es = es,
n = 100,
progress = !is_testing(),
iseed = 1234)

expect_output(print(data_all),
"Descriptive statistics by group",
fixed = TRUE)


})
27 changes: 26 additions & 1 deletion vignettes/articles/n_from_power_mediation_ordinal_lav_simple.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Sample Size Determination with Ordinal Variables: Latent Variable Models"
date: "2026-03-16"
date: "2026-03-17"
output:
html_document:
fig.align: "center"
Expand Down Expand Up @@ -263,6 +263,31 @@ to linear transformation of the variables,
which is usually the case for most common
tests.

If there are variables with 10 or few
unique values, the response proportions
are also printed:


```
#> ===== Response Proportions =====
#>
#> group: Single Group
#> 1 2 miss
#> x1 0.5 0.5 0
#> x2 0.5 0.5 0
#> x3 0.5 0.5 0
#> x4 0.5 0.5 0
#> y1 0.5 0.5 0
#> y2 0.5 0.5 0
#> y3 0.5 0.5 0
#>
#> group: Single Group
#> 1 2 3 4 5 miss
#> m1 0.067 0.24 0.38 0.24 0.068 0
#> m2 0.067 0.24 0.38 0.24 0.066 0
#> m3 0.068 0.24 0.38 0.24 0.067 0
```

If necessary, the data generated can be
retrieved by `pool_sim_data()` and
inspected directly:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ to linear transformation of the variables,
which is usually the case for most common
tests.

If there are variables with 10 or few
unique values, the response proportions
are also printed:

```{r des2, echo=FALSE}
i1 <- which(grepl("= Response Proportions =", tmp))
i2 <- which(grepl("==== Parameter Estimates ", tmp))
cat(tmp[i1:(i2 - 1)], sep = "\n")
```

If necessary, the data generated can be
retrieved by `pool_sim_data()` and
inspected directly:
Expand Down
Loading