Skip to content

Commit

Permalink
Release: 1.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaiconstantin committed Nov 14, 2021
2 parents 725d118 + 73c562e commit 8f58480
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: powerly
Title: Sample Size Analysis for Psychological Networks and More
Version: 1.7.1
Version: 1.7.2
Authors@R:
person(given = "Mihai",
family = "Constantin",
Expand Down
24 changes: 24 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# `powerly` `1.7.2`

## Improvements

* Update GGM estimation test to check if the estimation fails when variables
with zero standard deviation are present in the generated data.

* Update GGM estimation to fail when the generated data contains at least one
variable that has a standard deviation equal to zero (i.e., as a result of
generating data with a sample size value that is too low).

* Add GitHub badges with latest release version and number of open issues.

## Bug fixes

* Add tolerance (i.e., `0.0000001` for test checking whether the spline
coefficients are estimated correctly).

* Fix test for the updating of the bounds of a `Range` instance to run only when
the the 2.5th and 97.5th selected sample sizes are different quantities.

* Fix bug in GGM data generating test where the number of nodes to generate data
for were incorrectly sampled.

# `powerly` `1.7.1`

## Improvements
Expand Down
5 changes: 5 additions & 0 deletions R/GgmModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ GgmModel <- R6::R6Class("GgmModel",
},

estimate = function(data, gamma = 0.5) {
# Ensure all variables show variance.
if (sum(apply(data, 2, sd) == 0) > 0) {
stop("Variable(s) with SD = 0 detected. Increase the sample size.")
}

# Estimate network using `qgraph`.
network <- suppressMessages(suppressWarnings(
qgraph::EBICglasso(
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
</p>

<p align="center">
<a align="center" href="https://github.com/mihaiconstantin/powerly/actions"><img src="https://github.com/mihaiconstantin/powerly/workflows/R-CMD-check/badge.svg" alt="R-CMD-check" /></a>
<a href="https://github.com/mihaiconstantin/powerly/releases"><img src="https://img.shields.io/github/v/release/mihaiconstantin/powerly?display_name=tag&sort=semver"/></a>
<a href="https://www.r-pkg.org/pkg/powerly"><img src="https://www.r-pkg.org/badges/version/powerly" alt="CRAN version"/></a>
<a href="https://cranchecks.info/pkgs/powerly"><img src="https://cranchecks.info/badges/worst/powerly" alt="CRAN checks"/></a>
<a href="https://app.codecov.io/gh/mihaiconstantin/powerly"><img src="https://codecov.io/gh/mihaiconstantin/powerly/branch/main/graph/badge.svg?token=YUCO8ULBCM" alt="Code coverage"/></a>
<a href="https://www.repostatus.org/#active"><img src="https://www.repostatus.org/badges/latest/active.svg" alt="Repository status"/></a>
<a href="https://app.codecov.io/gh/mihaiconstantin/powerly"><img src="https://codecov.io/gh/mihaiconstantin/powerly/branch/main/graph/badge.svg?token=YUCO8ULBCM" alt="Code coverage"/></a>
<a href="https://github.com/mihaiconstantin/powerly/issues"><img src="https://img.shields.io/github/issues/mihaiconstantin/powerly"/></a>
<a href="https://www.r-pkg.org/pkg/powerly"><img src="https://cranlogs.r-pkg.org/badges/grand-total/powerly" alt="CRAN RStudio mirror downloads"/></a>
<a href="https://github.com/mihaiconstantin/powerly/actions"><img src="https://github.com/mihaiconstantin/powerly/workflows/R-CMD-check/badge.svg" alt="R-CMD-check" /></a>
<a href="https://cranchecks.info/pkgs/powerly"><img src="https://cranchecks.info/badges/worst/powerly" alt="CRAN checks"/></a>
</p>

## Description
Expand Down
14 changes: 10 additions & 4 deletions tests/testthat/test-ggm.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_that("'GgmModel' generates data correctly", {
max_level <- sample(3:5, 1)

# Nodes.
nodes <- sample(10:20)
nodes <- sample(10:20, 1)

# Density.
density <- sample(seq(.2, .5, .1), 1)
Expand Down Expand Up @@ -40,7 +40,7 @@ test_that("'GgmModel' generated data matches bootnet data", {
max_level <- sample(3:5, 1)

# Nodes.
nodes <- sample(10:20)
nodes <- sample(10:20, 1)

# Density.
density <- sample(seq(.2, .5, .1), 1)
Expand Down Expand Up @@ -75,7 +75,7 @@ test_that("'GgmModel' estimates model parameters correctly", {
max_level <- sample(3:5, 1)

# Nodes.
nodes <- sample(10:20)
nodes <- sample(10:20, 1)

# Density.
density <- sample(seq(.2, .5, .1), 1)
Expand All @@ -97,6 +97,12 @@ test_that("'GgmModel' estimates model parameters correctly", {

# The parameters should be identical across both methods.
expect_equal(network_qgraph, network_ggm_model, ignore_attr = TRUE)

# Make one variable invariant.
data[, 1] <- data[1, 1]

# Expect the estimation to throw an error due to invariant variables.
expect_error(ggm$estimate(data), "Variable\\(s\\) with SD = 0 detected. Increase the sample size.")
})


Expand All @@ -108,7 +114,7 @@ test_that("'GgmModel' computes the correct measure", {
max_level <- sample(3:5, 1)

# Nodes.
nodes <- sample(10:20)
nodes <- sample(10:20, 1)

# Density.
density <- sample(seq(.2, .5, .1), 1)
Expand Down
13 changes: 8 additions & 5 deletions tests/testthat/test-range.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ test_that("'Range' updates bounds correctly based on 'StepThree' confidence inte
expect_equal(min(range$partition), as.numeric(step_3$samples["2.5%"]))
expect_equal(max(range$partition), as.numeric(step_3$samples["97.5%"]))

# Expect that the bounds are of increasing size.
expect_error(
range$update_bounds(step_3, lower_ci = 0.975, upper_ci = 0.025),
"The lower bound cannot be greater that the upper bound."
)
# If the selected samples are not a single quantity.
if(step_3$samples["2.5%"] < step_3$samples["97.5%"]) {
# Expect that the bounds are of increasing size.
expect_error(
range$update_bounds(step_3, lower_ci = 0.975, upper_ci = 0.025),
"The lower bound cannot be greater that the upper bound."
)
}
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-step-two.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test_that("'StepTwo' fits and interpolates a spline correctly", {
expect_equal(step_2$spline$basis$matrix, basis)

# The estimated spline coefficients should be equal.
expect_equal(step_2$spline$alpha, alpha)
expect_equal(step_2$spline$alpha, alpha, tolerance = 0.0000001)

# The fitted values should be equal.
expect_equal(step_2$spline$fitted, fitted)
Expand Down

0 comments on commit 8f58480

Please sign in to comment.