Skip to content

Commit

Permalink
Avoid using set.seed
Browse files Browse the repository at this point in the history
  • Loading branch information
kolesarm committed Mar 21, 2024
1 parent dbb09ef commit 9826d15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ notes.org
^cran-comments\.md$
^CRAN-RELEASE$
^\.github$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.0
Date: 2024-03-20 01:40:54 UTC
SHA: dbb09ef6eae8689c3cc8a16aa9dcbdcdc6589db8
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Encoding: UTF-8
LazyData: true
Imports:
stats,
Formula
Formula,
withr
Suggests:
spelling,
ggplot2,
Expand Down
15 changes: 8 additions & 7 deletions R/Cbound.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,32 @@ RDSmoothnessBound <- function(object, s, separate=FALSE, multiple=TRUE,
hatM <- function(D) {
ts <- abs(D[1, ]/D[2, ]) # sup_t statistic
maxt <- D[, which.max(ts)]
set.seed(42)

Z <- matrix(stats::rnorm(10000*ncol(D)), ncol=ncol(D))
## median unbiased point estimate and lower CI
hatM <- lower <- 0
hatm <- lower <- 0
if (max(ts) > cv(0, Z, D[2, ], 1/2)) {
hatM <- FindZero(function(m) max(ts)-cv(m, Z, D[2, ], 1/2),
hatm <- FindZero(function(m) max(ts)-cv(m, Z, D[2, ], 1/2),
negative=FALSE)
}
if (max(ts) >= cv(0, Z, D[2, ], alpha)) {
lower <- FindZero(function(m) max(ts)-cv(m, Z, D[2, ], alpha),
negative=FALSE)
}
list(estimate=hatM, conf.low=lower,
list(estimate=hatm, conf.low=lower,
diagnostics=c(Delta=maxt[1], sdDelta=maxt[2],
y1=maxt[3], y2=maxt[4], y3=maxt[5],
I1=maxt[6:7], I2=maxt[8:9], I3=maxt[10:11]))
}

if (separate) {
po <- hatM(Dp)
ne <- hatM(Dm)
withr::with_seed(42, po <- hatM(Dp))
withr::with_seed(42, ne <- hatM(Dm))
ret <- data.frame(rbind("Below cutoff"=unlist(ne[1:2]),
"Above cutoff"=unlist(po[1:2])))
} else {
ret <- data.frame((hatM(cbind(Dm, Dp))[1:2]))
ret <- withr::with_seed(42,
data.frame((hatM(cbind(Dm, Dp))[1:2])))
rownames(ret) <- c("Pooled")
}
ret
Expand Down
14 changes: 8 additions & 6 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Resubmission
This is a resubmission. In this version I have:

* avoided using set.seed() inside a function (in R/Cbound.R). Instead, I use
withr::with_seed() to ensure that the results are reproducible without
modifying the global environment.


## Test environments
* local Debian 12 (bookworm) install, R 4.3.1
* Github actions
Expand All @@ -23,12 +31,6 @@ Possibly misspelled words in DESCRIPTION:
Rothe (17:47)
covariates (18:42)

Found the following (possibly) invalid DOIs:
DOI: 10.1257/aer.20160945.
From: man/RDHonestBME.Rd
Status: 404
Message: Not Found

The misspelled words are correct, "covariates" refers to independent variables
in a regression. "Rothe" is a surname.

Expand Down

0 comments on commit 9826d15

Please sign in to comment.