Skip to content

Commit 79f197d

Browse files
committed
handle other issues raised by CRAN
1 parent ab27d72 commit 79f197d

39 files changed

+344
-245
lines changed

.sandbox/Sim_study_with_logit/Sim_study_with_logit.Rmd

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,11 @@ All method use the logistic link function. We will do three runs of experiments
4040

4141
where correct or incorrect binning intervals refers to whether or not we bin at the same time where the coefficient are simulated to change. For example, we bin correctly where we simulate the coefficients to change at time $1,2,\dots,d$ and we estimate the coefficient at time $1,2,\dots,d$. The models will be compared in terms of Brier score, median absolute residuals and standard deviation of the absolute residuals. All metrics will be reported on out-sample data or out-of-time data. All plots will have true coefficients as continuous lines while dashed lines are estimates.
4242

43-
You can install the version of the library used to make this vignettes from github with the `devtools` library as follows:
44-
45-
```{r echo=FALSE}
46-
current_sha <- httr::content(
47-
httr::GET("https://api.github.com/repos/boennecd/dynamichazard/git/refs/heads/master")
48-
)$object$sha
49-
50-
stopifnot(length(current_sha) > 0 && class(current_sha) == "character")
51-
52-
current_version <- paste0("boennecd/dynamichazard@", current_sha)
53-
```
54-
55-
```{r}
56-
current_version # The string to pass devtools::install_github
57-
```
43+
You can install the version of the library used to make this vignettes from github with the `remotes` library as follows:
5844

5945
```{r eval=FALSE}
60-
devtools::install_github(current_version)
46+
# install.packages("remotes")
47+
remotes::install_github("boennecd/dynamichazard")
6148
```
6249

6350
You can also get the latest version on CRAN by calling:

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# dynamichazard 0.6.8
22
* fix issue due to changes in speedglm.
33
* add documentation and fix other issues raised by CRAN.
4+
* `getOption("ddhazard_max_threads")` defaults to one.
45

56
# dynamichazard 0.6.7
67
* solve issue because of changes in `all.equal`.

R/PF.R

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ PF_effective_sample_size <- function(object){
7676
#' The function is still under development so the output and API may change.
7777
#'
7878
#' @examples
79-
#'\dontrun{
79+
#' \donttest{
8080
#'#####
8181
#'# Fit model with lung data set from survival
8282
#'# Warning: long-ish computation time
@@ -94,9 +94,10 @@ PF_effective_sample_size <- function(object){
9494
#' Q_0 = diag(1, 2), Q = diag(.5^2, 2),
9595
#' max_T = 800,
9696
#' control = PF_control(
97-
#' N_fw_n_bw = 500, N_first = 2500, N_smooth = 5000,
97+
#' # these number should be larger! Small for CRAN checks
98+
#' N_fw_n_bw = 100L, N_first = 250L, N_smooth = 100L,
9899
#' n_max = 50, eps = .001, Q_tilde = diag(.2^2, 2), est_a_0 = FALSE,
99-
#' n_threads = max(parallel::detectCores(logical = FALSE), 1)))
100+
#' n_threads = 2))
100101
#'
101102
#'# Plot state vector estimates
102103
#'plot(pf_fit, cov_index = 1)
@@ -105,7 +106,7 @@ PF_effective_sample_size <- function(object){
105106
#'# Plot log-likelihood
106107
#'plot(pf_fit$log_likes)
107108
#'}
108-
#'\dontrun{
109+
#' \donttest{
109110
#'######
110111
#'# example with fixed intercept
111112
#'
@@ -144,11 +145,12 @@ PF_effective_sample_size <- function(object){
144145
#' by = 100, id = pbc2$id,
145146
#' model = "exponential", max_T = 3600,
146147
#' control = PF_control(
147-
#' N_fw_n_bw = 500, N_smooth = 2500, N_first = 1000, eps = 1e-3,
148+
#' # these number should be larger! Small for CRAN checks
149+
#' N_fw_n_bw = 100, N_smooth = 250, N_first = 100, eps = 1e-3,
148150
#' method = "AUX_normal_approx_w_cloud_mean", est_a_0 = FALSE,
149151
#' Q_tilde = as.matrix(.1^2),
150152
#' n_max = 25, # just take a few iterations as an example
151-
#' n_threads = max(parallel::detectCores(logical = FALSE), 1)))
153+
#' n_threads = 2))
152154
#'
153155
#'# compare results
154156
#'plot(ddfit)
@@ -157,7 +159,7 @@ PF_effective_sample_size <- function(object){
157159
#'sqrt(pf_fit$Q)
158160
#'rbind(ddfit$fixed_effects, pf_fit$fixed_effects)
159161
#'}
160-
#'\dontrun{
162+
#' \donttest{
161163
#' #####
162164
#' # simulation example with `random` and `fixed` argument and a restricted
163165
#' # model
@@ -264,35 +266,35 @@ PF_effective_sample_size <- function(object){
264266
#' N_fw_n_bw = 100L, N_smooth = 100L, N_first = 500L,
265267
#' method = "AUX_normal_approx_w_cloud_mean",
266268
#' nu = 5L, # sample from multivariate t-distribution
267-
#' n_max = 100L, averaging_start = 50L,
269+
#' n_max = 60L, averaging_start = 50L,
268270
#' smoother = "Fearnhead_O_N", eps = 1e-4, covar_fac = 1.2,
269-
#' n_threads = 4L # depends on your cpu(s)
271+
#' n_threads = 2L # depends on your cpu(s)
270272
#' ),
271273
#' trace = 1L)
272274
#' plot(fit$log_likes) # log-likelihood approximation at each iterations
273275
#'
274-
#' # take more iterations with more particles
275-
#' cl <- fit$call
276-
#' ctrl <- cl[["control"]]
277-
#' ctrl[c("N_fw_n_bw", "N_smooth", "N_first", "n_max",
278-
#' "averaging_start")] <- list(500L, 2000L, 5000L, 200L, 30L)
279-
#' cl[["control"]] <- ctrl
280-
#' cl[c("phi", "psi", "theta")] <- list(fit$phi, fit$psi, fit$theta)
281-
#' fit_extra <- eval(cl)
276+
#' # you can take more iterations by uncommenting the following
277+
#' # cl <- fit$call
278+
#' # ctrl <- cl[["control"]]
279+
#' # ctrl[c("N_fw_n_bw", "N_smooth", "N_first", "n_max",
280+
#' # "averaging_start")] <- list(500L, 2000L, 5000L, 200L, 30L)
281+
#' # cl[["control"]] <- ctrl
282+
#' # cl[c("phi", "psi", "theta")] <- list(fit$phi, fit$psi, fit$theta)
283+
#' # fit_extra <- eval(cl)
282284
#'
283-
#' plot(fit_extra$log_likes) # log-likelihood approximation at each iteration
285+
#' plot(fit$log_likes) # log-likelihood approximation at each iteration
284286
#'
285287
#' # check estimates
286-
#' sqrt(diag(fit_extra$Q))
288+
#' sqrt(diag(fit$Q))
287289
#' sqrt(diag(Q))
288-
#' cov2cor(fit_extra$Q)
290+
#' cov2cor(fit$Q)
289291
#' cov2cor(Q)
290-
#' fit_extra$F
292+
#' fit$F
291293
#' F.
292294
#'
293295
#' # plot predicted state variables
294296
#' for(i in 1:p){
295-
#' plot(fit_extra, cov_index = i)
297+
#' plot(fit, cov_index = i)
296298
#' abline(h = 0, lty = 2)
297299
#' lines(1:nrow(alphas) - 1, alphas[, i] - beta[i], lty = 3)
298300
#' }
@@ -553,7 +555,7 @@ PF_EM <- function(
553555
#' The function is still under development so the output and API may change.
554556
#'
555557
#' @examples
556-
#' \dontrun{
558+
#' \donttest{
557559
#' # head-and-neck cancer study data. See Efron, B. (1988) doi:10.2307/2288857
558560
#' is_censored <- c(
559561
#' 6, 27, 34, 36, 42, 46, 48:51, 51 + c(15, 30:28, 33, 35:37, 39, 40, 42:45))
@@ -574,7 +576,7 @@ PF_EM <- function(
574576
#' ctrl <- PF_control(
575577
#' N_fw_n_bw = 500, N_smooth = 2500, N_first = 2000,
576578
#' n_max = 1, # set to one as an example
577-
#' n_threads = max(parallel::detectCores(logical = FALSE), 1),
579+
#' n_threads = 2,
578580
#' eps = .001, Q_tilde = as.matrix(.3^2), est_a_0 = FALSE)
579581
#' pf_fit <- suppressWarnings(
580582
#' PF_EM(
@@ -726,12 +728,12 @@ PF_forward_filter.data.frame <- function(
726728
# set the seed
727729
old_seed <- .GlobalEnv$.Random.seed
728730
# to make sure the user has the same `rng.kind`
729-
on.exit(.GlobalEnv$.Random.seed <- old_seed)
731+
on.exit(assign(".Random.seed", old_seed, envir = .GlobalEnv))
730732

731733
stopifnot(length(seed) > 1) # make sure user did not use seed as in
732734
# `set.seed`
733735
if(control$fix_seed)
734-
.GlobalEnv$.Random.seed <- seed
736+
assign(".Random.seed", seed, envir = .GlobalEnv)
735737
}
736738

737739
out <- particle_filter(
@@ -1632,7 +1634,7 @@ get_cloud_quantiles.PF_clouds <- function(
16321634
#' \code{FALSE}.}
16331635
#'
16341636
#' @examples
1635-
#' \dontrun{
1637+
#' \donttest{
16361638
#' library(dynamichazard)
16371639
#' .lung <- lung[!is.na(lung$ph.ecog), ]
16381640
#' # standardize
@@ -1649,7 +1651,7 @@ get_cloud_quantiles.PF_clouds <- function(
16491651
#' control = PF_control(
16501652
#' N_fw_n_bw = 250, N_first = 2000, N_smooth = 500, covar_fac = 1.1,
16511653
#' nu = 6, n_max = 1000L, eps = 1e-4, averaging_start = 200L,
1652-
#' n_threads = max(parallel::detectCores(logical = FALSE), 1)))
1654+
#' n_threads = 2))
16531655
#'
16541656
#' # compute score and observed information matrix
16551657
#' comp_obj <- PF_get_score_n_hess(pf_fit)

R/boot_est.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if(getRversion() >= "2.15.1")
2323
#'
2424
#'
2525
#' @examples
26-
#'\dontrun{
26+
#'\donttest{
2727
#'library(dynamichazard)
2828
#'set.seed(56219373)
2929
#'fit <- ddhazard(

R/get_design_matrix.R

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,22 @@ get_design_matrix <- function(
187187
#'
188188
#' @param object expression that would be used in formula. E.g. \code{x} or \code{poly(x, degree = 3)}.
189189
#'
190-
#'@examples
191-
#'# we can get a time-invariant effect of `x1` by
192-
#'\dontrun{
193-
#' ddhazard(Surv(stop, event) ~ ddFixed(x1), data)
194-
#'}
190+
#' @return
191+
#' Returns the passed object.
195192
#'
196-
#'# all of the calls below will yield the same result with a time-invariant
197-
#'# intercept:
198-
#'\dontrun{
199-
#' ddhazard(Surv(stop, event) ~ ddFixed_intercept() + x1, data)
200-
#' ddhazard(Surv(stop, event) ~ -1 + ddFixed_intercept() + x1, data)
201-
#'}
193+
#' @examples
194+
#' # we can get a time-invariant effect of `x1` by
195+
#' set.seed(1)
196+
#' dat <- data.frame(stop = 1:20, event = rep(c(TRUE, FALSE), 10L), x1 = rnorm(20))
197+
#' ddhazard(Surv(stop, event) ~ ddFixed(x1), dat,
198+
#' Q_0 = diag(1), by = 1, Q = diag(1))
199+
#'
200+
#' # all of the calls below will yield the same result with a time-invariant
201+
#' # intercept:
202+
#' ddhazard(Surv(stop, event) ~ ddFixed_intercept() + x1, dat,
203+
#' Q_0 = diag(1), by = 1, Q = diag(1))
204+
#' ddhazard(Surv(stop, event) ~ -1 + ddFixed_intercept() + x1, dat,
205+
#' Q_0 = diag(1), by = 1, Q = diag(1))
202206
#' @export
203207
ddFixed <- function(object){
204208
if(all(object == 1)){

R/loglike.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#' @param id the individual identifiers as in \code{\link{ddhazard}}.
1212
#' @param ... unused.
1313
#'
14+
#' @return
15+
#' Returns an ojbect of class \code{logLik}. See \code{\link{logLik}}.
16+
#'
1417
#' @examples
1518
#'library(dynamichazard)
1619
#'fit <- ddhazard(

R/options.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ cur_load = if(exists(".onLoad()")) .onLoad else function() { NULL }
99
op <- options()
1010

1111
# TODO: avoid this by doing as e.g., in `boot::boot` by using `getOption`
12-
op.dynhazard <- list(
13-
ddhazard_max_threads = -1)
12+
op.dynhazard <- list(ddhazard_max_threads = 1)
1413
toset <- !(names(op.dynhazard) %in% names(op))
1514
if(any(toset))
1615
options(op.dynhazard[toset])

R/plot.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#' @details
1616
#' Creates a plot of state variables or adds state variables to a plot with indices \code{cov_index}. Pointwise 1.96 std. confidence intervals are provided with the smoothed co-variance matrices from the fit.
1717
#'
18+
#' @return
19+
#' Returns \code{NULL} using \code{\link{invisible}}.
20+
#'
1821
#' @importFrom graphics matplot matpoints
1922
#'
2023
#' @examples
@@ -55,8 +58,8 @@ plot.ddhazard = function(x, xlab = "Time",
5558

5659
n_plots <- length(cov_index)
5760
if(!add && do_alter_mfcol && n_plots > 1){
58-
org_mfcol <- par()$mfcol
59-
on.exit(par(mfcol = org_mfcol))
61+
par_old <- par(no.readonly = TRUE)
62+
on.exit(par(par_old))
6063
par(mfcol =
6164
if(n_plots <= 2) c(2,1) else
6265
if(n_plots <= 4) c(2,2) else
@@ -146,6 +149,9 @@ plot.ddhazard = function(x, xlab = "Time",
146149
#' @param x_tick_loc,x_tick_mark \code{at} and \code{labels} arguments passed to \code{axis}.
147150
#' @param ... arguments passed to \code{\link{plot.default}}.
148151
#'
152+
#' @return
153+
#' Returns \code{NULL} using \code{\link{invisible}}.
154+
#'
149155
#' @importFrom graphics abline axis par plot points
150156
#' @export
151157
plot.ddhazard_space_errors = function(x, mod, cov_index = NA, t_index = NA,

R/predict.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#' \item{\code{istop}}{numeric vector with stop time for each element in \code{fits}.}
4747
#'}
4848
#'
49+
#' @return
50+
#' Returns a list with elements as described in the Term and Response sections.
51+
#'
4952
#' @examples
5053
#' fit <- ddhazard(
5154
#' Surv(time, status == 2) ~ log(bili), pbc, id = pbc$id, max_T = 3600,
@@ -375,7 +378,7 @@ predict_response <- function(
375378
#'
376379
#' # predict with default which is all covariates set to zero
377380
#' ddcurve <- ddsurvcurve(f1)
378-
#' par(mar = c(4.5, 4, .5, .5))
381+
#' par_old <- par(mar = c(4.5, 4, .5, .5))
379382
#' plot(ddcurve, col = "DarkBlue", lwd = 2)
380383
#'
381384
#' # compare with cox model
@@ -448,6 +451,7 @@ predict_response <- function(
448451
#' col = "DarkBlue")
449452
#' lines(survfit(Surv(stop, event) ~ 1, head_neck_cancer, subset = group == 2),
450453
#' col = "DarkOrange")
454+
#' par(par_old) # As per CRAN policy, the settings are reset
451455
#'
452456
#' @export
453457
#' @importFrom utils head

R/print.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#' @description
1010
#' Arguments have the same effects as for an object from a \code{\link{boot}} call. See \code{\link[=print.boot]{print}}.
1111
#'
12+
#' @return
13+
#' Returns \code{x} using \code{\link{invisible}}.
14+
#'
1215
#' @seealso
1316
#' \code{\link{ddhazard_boot}}
1417
#'
@@ -44,7 +47,6 @@ print.ddhazard_boot <-
4447
invisible(boot.out)
4548
}
4649

47-
4850
#' @export
4951
print.ddhazard<- function(x, ...){
5052
cat("Call:", paste(deparse(x$call), sep = "\n", collapse = "\n"), sep = "\n")

0 commit comments

Comments
 (0)