Skip to content

Fixed R examples with uninitialized random effects terms (which triggered valgrind errors in CRAN checks) #145

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

Merged
merged 2 commits into from
Feb 8, 2025
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ SystemRequirements: C++17
Imports:
R6,
stats
URL: https://stochtree.ai
URL: https://stochtree.ai/, https://github.com/StochasticTree/stochtree
BugReports: https://github.com/StochasticTree/stochtree/issues
Config/testthat/edition: 3
52 changes: 44 additions & 8 deletions R/random_effects.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ createRandomEffectsModel <- function(num_components, num_groups) {
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' alpha_init <- rep(1,num_components)
#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups)
#' sigma_alpha_init <- diag(1,num_components,num_components)
#' sigma_xi_init <- diag(1,num_components,num_components)
#' sigma_xi_shape <- 1
#' sigma_xi_scale <- 1
#' rfx_model$set_working_parameter(alpha_init)
#' rfx_model$set_group_parameters(xi_init)
#' rfx_model$set_working_parameter_cov(sigma_alpha_init)
#' rfx_model$set_group_parameter_cov(sigma_xi_init)
#' rfx_model$set_variance_prior_shape(sigma_xi_shape)
#' rfx_model$set_variance_prior_scale(sigma_xi_scale)
#' for (i in 1:3) {
#' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome,
#' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples,
Expand Down Expand Up @@ -458,6 +470,18 @@ resetRandomEffectsModel <- function(rfx_model, rfx_samples, sample_num, sigma_al
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' alpha_init <- rep(1,num_components)
#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups)
#' sigma_alpha_init <- diag(1,num_components,num_components)
#' sigma_xi_init <- diag(1,num_components,num_components)
#' sigma_xi_shape <- 1
#' sigma_xi_scale <- 1
#' rfx_model$set_working_parameter(alpha_init)
#' rfx_model$set_group_parameters(xi_init)
#' rfx_model$set_working_parameter_cov(sigma_alpha_init)
#' rfx_model$set_group_parameter_cov(sigma_xi_init)
#' rfx_model$set_variance_prior_shape(sigma_xi_shape)
#' rfx_model$set_variance_prior_scale(sigma_xi_scale)
#' for (i in 1:3) {
#' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome,
#' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples,
Expand Down Expand Up @@ -493,15 +517,21 @@ resetRandomEffectsTracker <- function(rfx_tracker, rfx_model, rfx_dataset, resid
#' rng <- createCppRNG(1234)
#' num_groups <- length(unique(rfx_group_ids))
#' num_components <- ncol(rfx_basis)
#' alpha_init <- c(1)
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' alpha_init <- rep(1,num_components)
#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups)
#' sigma_alpha_init <- diag(1,num_components,num_components)
#' sigma_xi_init <- diag(1,num_components,num_components)
#' sigma_xi_shape <- 1
#' sigma_xi_scale <- 1
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' rfx_model$set_working_parameter(alpha_init)
#' rfx_model$set_group_parameters(xi_init)
#' rfx_model$set_working_parameter_cov(sigma_alpha_init)
#' rfx_model$set_group_parameter_cov(sigma_xi_init)
#' rfx_model$set_variance_prior_shape(sigma_xi_shape)
#' rfx_model$set_variance_prior_scale(sigma_xi_scale)
#' for (i in 1:3) {
#' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome,
#' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples,
Expand Down Expand Up @@ -540,15 +570,21 @@ rootResetRandomEffectsModel <- function(rfx_model, alpha_init, xi_init, sigma_al
#' rng <- createCppRNG(1234)
#' num_groups <- length(unique(rfx_group_ids))
#' num_components <- ncol(rfx_basis)
#' alpha_init <- c(1)
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' alpha_init <- rep(1,num_components)
#' xi_init <- matrix(rep(alpha_init, num_groups),num_components,num_groups)
#' sigma_alpha_init <- diag(1,num_components,num_components)
#' sigma_xi_init <- diag(1,num_components,num_components)
#' sigma_xi_shape <- 1
#' sigma_xi_scale <- 1
#' rfx_model <- createRandomEffectsModel(num_components, num_groups)
#' rfx_tracker <- createRandomEffectsTracker(rfx_group_ids)
#' rfx_samples <- createRandomEffectSamples(num_components, num_groups, rfx_tracker)
#' rfx_model$set_working_parameter(alpha_init)
#' rfx_model$set_group_parameters(xi_init)
#' rfx_model$set_working_parameter_cov(sigma_alpha_init)
#' rfx_model$set_group_parameter_cov(sigma_xi_init)
#' rfx_model$set_variance_prior_shape(sigma_xi_shape)
#' rfx_model$set_variance_prior_scale(sigma_xi_scale)
#' for (i in 1:3) {
#' rfx_model$sample_random_effect(rfx_dataset=rfx_dataset, residual=outcome,
#' rfx_tracker=rfx_tracker, rfx_samples=rfx_samples,
Expand Down
17 changes: 17 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ We have converted `T` and `F` to `TRUE` and `FALSE` in the R code.
> Some code lines in examples are commented out. Please never do that.

We no longer do this, and apologize for the oversight.

## CRAN comments (20250207)

Below we address issues raised by CRAN on Feb 7, 2025

### Valgrind

A valgrind-instrumented version of R exposed memory issues in several examples
in the `stochtree` documentation. The specific issue is

> Conditional jump or move depends on uninitialised value(s)

The examples that triggered this were in fact working with Eigen matrices
with uninitialized values.

This has been corrected and we have verified that running the `stochtree`
examples no longer produce this memcheck error.
12 changes: 12 additions & 0 deletions man/resetRandomEffectsModel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions man/resetRandomEffectsTracker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/rootResetRandomEffectsModel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/rootResetRandomEffectsTracker.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/stochtree-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading