Powerly
`powerly` is an R package for conducting sample size analysis for network models and more.
Install / Use
/learn @mihaiconstantin/PowerlyREADME
Description
powerly is an R package that implements the method by Constantin et al.
(2023) for conducting sample size analysis
for cross-sectional network models. The method implemented is implemented in the
main function powerly(). The implementation takes the form of a three-step
recursive algorithm designed to find an optimal sample size value given a model
specification and an outcome measure of interest. It starts with a Monte Carlo
simulation step for computing the outcome at various sample sizes. Then, it
continues with a monotone curve-fitting step for interpolating the outcome. The
final step employs stratified bootstrapping to quantify the uncertainty around
the fitted curve.
<div align="center"> Check out the documentation and tutorials at <h3> <a href="https://powerly.dev">powerly.dev</a> </h3> </div>
Installation
- to install from CRAN run
install.packages("powerly") - to install the latest version from GitHub run
remotes::install_github("mihaiconstantin/powerly")
Example
The code block below illustrates the main function in the package. For more
information, see the documentation ?powerly, or check out the tutorials at
powerly.dev.
# Suppose we want to find the sample size for observing a sensitivity of `0.6`
# with a probability of `0.8`, for a GGM true model consisting of `10` nodes
# with a density of `0.4`.
# We can run the method for an arbitrarily generated true model that matches
# those characteristics (i.e., number of nodes and density).
results <- powerly(
range_lower = 300,
range_upper = 1000,
samples = 30,
replications = 20,
measure = "sen",
statistic = "power",
measure_value = .6,
statistic_value = .8,
model = "ggm",
nodes = 10,
density = .4,
cores = 2,
verbose = TRUE
)
# Or we omit the `nodes` and `density` arguments and specify directly the edge
# weights matrix via the `model_matrix` argument.
# To get a matrix of edge weights we can use the `generate_model()` function.
true_model <- generate_model(type = "ggm", nodes = 10, density = .4)
# Then, supply the true model to the algorithm directly.
results <- powerly(
range_lower = 300,
range_upper = 1000,
samples = 30,
replications = 20,
measure = "sen",
statistic = "power",
measure_value = .6,
statistic_value = .8,
model = "ggm",
model_matrix = true_model, # Note the change.
cores = 2,
verbose = TRUE
)
To validate the results of the analysis, we can use the validate() method. For
more information, see the documentation ?validate.
# Validate the recommendation obtained during the analysis.
validation <- validate(results, cores = 2)
To visualize the results, we can use the plot function and indicate the step
that should be plotted.
# Step 1.
plot(results, step = 1)
<p align="center">
<img width = "60%" src="./man/figures/example-step-1.png" alt="Example Step 1"/>
</p>
# Step 2.
plot(results, step = 2)
<p align="center">
<img width="60%" src="./man/figures/example-step-2.png" alt="Example Step 2"/>
</p>
# Step 3.
plot(results, step = 3)
<p align="center">
<img width = "60%" src="./man/figures/example-step-3.png" alt="Example Step 3"/>
</p>
# Validation.
plot(validation)
<p align="center">
<img width = "60%" src="./man/figures/example-validation.png" alt="Example Validation"/>
</p>
Contributing
- To support a new model, performance measure, or statistic, please open a pull request on GitHub.
- To request a new model, performance measure, or statistic, please open an issue on GitHub. If possible, also include references discussing the topics you are requesting.
Poster
<p align="center"> <img width = "90%" src="./docs/.vuepress/public/images/materials/powerly-poster-iops-2021-mihai-constantin.png" alt="Method poster IOPS 2021"/> </p>License
The code in this repository is licensed under the MIT license.
To use powerly please cite:
- Constantin, M. A., Schuurman, N. K., & Vermunt, J. K. (2023). A General Monte Carlo Method for Sample Size Analysis in the Context of Network Models. Psychological Methods. https://doi.org/10.1037/met0000555
Related Skills
node-connect
348.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。