Skip to content

Commit 9e7ed3c

Browse files
committed
merge cran accepted version with main
Merge branch 'cran-submission' # Conflicts: # man/outstandR-package.Rd
2 parents 5184679 + 89a5ee1 commit 9e7ed3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2182
-4228
lines changed

.Rbuildignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ scripts/create_package_data\.R
2828
^R/conversion-functions\.R$
2929
^cran-comments\.md$
3030
^.*\.qmd$
31-
^.*\.Rmd$
31+
^.*\.Rmd$
32+
^check_results$

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
inst/doc
66
/Meta/
77
/doc/
8+
inst/jss-section.html
9+
inst/jss-section.qmd
10+
inst/jss-section_files/
11+
check_results/

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Authors@R: c(
1111
Description:
1212
For the problem of indirect treatment comparison with limited subject-level data, this
1313
package provides tools for model-based standardisation with several different computation approaches.
14-
See Remiro‐Azócar A, Heath A, Baio G (2022. Parametric G‐computation for compatible
15-
indirect treatment comparisons with limited individual patient data,
16-
Res. Synth. Methods, 1–31. ISSN 1759-2879, <doi:10.1002/jrsm.1565>.)
14+
See Remiro‐Azócar A, Heath A, Baio G (2022) ``Parametric G‐computation for compatible
15+
indirect treatment comparisons with limited individual patient data'',
16+
Res. Synth. Methods, 1–31. ISSN 1759-2879, <doi:10.1002/jrsm.1565>.
1717
License: GPL (>= 3)
1818
Encoding: UTF-8
1919
Language: en-GB

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(add_seed,default)
4+
S3method(add_seed,gcomp_bayes)
35
S3method(calc_IPD_stats,default)
46
S3method(calc_IPD_stats,gcomp_bayes)
57
S3method(calc_IPD_stats,gcomp_ml)

R/calc_IPD_stats.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ IPD_stat_factory <- function(ipd_fun) {
9595
var_est <- var(hat.delta.AC, na.rm = TRUE)
9696
} else if (var_method == "rubin") {
9797

98-
if (is.null(out$model$hats.v) || is.null(out$model$M)) {
99-
stop("Rubin's rules require 'hats.v' and 'M' in the model output.", call. = FALSE)
98+
if (is.null(out$model$hats.v) || is.null(out$model$n_imp)) {
99+
stop("Rubin's rules require 'hats.v' and 'n_imp' in the model output.", call. = FALSE)
100100
}
101101

102-
M <- out$model$M
102+
n_imp <- out$model$n_imp
103103
bar.v <- mean(out$model$hats.v)
104104
b <- var(hat.delta.AC, na.rm = TRUE)
105105

106-
var_est <- var_by_pooling(M, bar.v, b)
107-
out$model$nu <- wald_type_interval(M, bar.v, b)
106+
var_est <- var_by_pooling(n_imp, bar.v, b)
107+
out$model$nu <- wald_type_interval(n_imp, bar.v, b)
108108

109109
} else {
110110
# This should be caught by get_var_method, but serves as a failsafe

R/cor2cov.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
#' Compute covariance matrix
33
#'
4-
#' @param R correlation matrix
4+
#' @param cormat correlation matrix
55
#' @param S vector of standard deviations covariance matrix
66
#' @return Required input for \code{mvrnorm}.
77
#' @keywords internal
88
#'
9-
cor2cov <- function(R, S) {
10-
# R * S %*% t(S) # alternative
11-
sweep(sweep(R, 1, S, "*"), 2, S, "*")
9+
cor2cov <- function(cormat, S) {
10+
# cormat * S %*% t(S) # alternative
11+
sweep(sweep(cormat, 1, S, "*"), 2, S, "*")
1212
}

R/gcomp_bayes.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,19 @@
5959
calc_gcomp_bayes <- function(strategy,
6060
analysis_params, ...) {
6161

62+
# extract seed, or default to a random integer if missing/NULL
63+
bayes_seed <- analysis_params$seed
64+
65+
if (is.null(bayes_seed)) {
66+
bayes_seed <- sample.int(.Machine$integer.max, 1)
67+
}
68+
6269
default_stan_args <- list(
6370
algorithm = "sampling",
6471
chains = 2,
6572
iter = 2000,
66-
refresh = 0 # quiet
73+
refresh = 0, # quiet
74+
seed = bayes_seed
6775
)
6876

6977
# merge with user-provided dots
@@ -144,7 +152,7 @@ calc_gcomp_bayes <- function(strategy,
144152
#' family = binomial(),
145153
#' rho = NA,
146154
#' N = 1000L,
147-
#' R = 100L,
155+
#' n_boot = 100L,
148156
#' marginal_distns = NA,
149157
#' marginal_params = NA,
150158
#' trt_var = "trt")
@@ -188,7 +196,7 @@ calc_gcomp_ml <- function(strategy,
188196
args_boot <- c(
189197
common_args, list(
190198
data = analysis_params$ipd,
191-
R = strategy$R))
199+
R = strategy$n_boot))
192200

193201
gcomp_boot <- do.call(boot::boot, c(statistic = gcomp_ml.boot, args_boot))
194202

R/gcomp_ml.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#' @keywords internal
2424
#'
2525
gcomp_ml.boot <- function(data, indices,
26-
R, formula = NULL,
26+
R,
27+
formula = NULL,
2728
family, trt_var,
2829
ref_trt = NA,
2930
comp_trt = NA,

R/maic.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ maic.boot <- function(ipd, indices = 1:nrow(ipd),
189189
calc_maic <- function(strategy,
190190
analysis_params) {
191191
args_list <-
192-
list(R = strategy$R,
192+
list(R = strategy$n_boot,
193193
formula = strategy$formula,
194194
family = strategy$family,
195195
trt_var = strategy$trt_var,

R/mim.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
#' @param ... Additional argument to pass to Stan model
88
#'
99
#' @return A list containing:
10-
#' * `means`: A list containing vectors of posterior means (one per synthesis `M`):
10+
#' * `means`: A list containing vectors of posterior means (one per synthesis `n_imp`):
1111
#' * `A`: Comparator means.
1212
#' * `C`: Reference means.
1313
#' * `model`: A list containing:
1414
#' * `fit`: The first-stage [rstanarm::stan_glm()] object.
1515
#' * `hats.v`: Vector of variance point estimates for each synthesis.
16-
#' * `M`: Number of posterior prediction draws (syntheses).
16+
#' * `n_imp`: Number of posterior prediction draws (syntheses).
1717
#' * `rho`, `N`, `stan_args`: Strategy and model parameters.
1818
#'
1919
#' @importFrom rstanarm posterior_predict stan_glm
@@ -72,10 +72,10 @@ calc_mim <- function(strategy,
7272

7373
# ANALYSIS STAGE ---
7474

75-
M <- nrow(y_star)
75+
n_imp <- nrow(y_star)
7676

7777
# fit second-stage regression to each synthesis using maximum-likelihood estimation
78-
reg2.fits <- lapply(1:M, function(m) {
78+
reg2.fits <- lapply(1:n_imp, function(m) {
7979
data_m <- aug.target
8080
data_m$y <- y_star[m, ]
8181
glm(as.formula(paste("y ~", trt_var)), data = data_m, family = family)
@@ -103,7 +103,7 @@ calc_mim <- function(strategy,
103103
model = list(
104104
fit = outcome_model,
105105
hats.v = hats.v,
106-
M = M,
106+
n_imp = n_imp,
107107
rho = rho,
108108
N = N,
109109
stan_args = stan_args)
@@ -114,27 +114,27 @@ calc_mim <- function(strategy,
114114
#'
115115
#' Constructed using t-distribution with nu degrees of freedom.
116116
#'
117-
#' @param M Number of syntheses used in analysis stage (high for low Monte Carlo error)
117+
#' @param n_imp Number of syntheses used in analysis stage (high for low Monte Carlo error)
118118
#' @param bar.v "within" variance (average of variance point estimates)
119119
#' @param b "between" variance (sample variance of point estimates)
120120
#' @return Numeric value of Wald-type interval estimates.
121121
#' @keywords internal
122122
#'
123-
wald_type_interval <- function(M, bar.v, b) {
124-
(M - 1) * (1 + bar.v / ((1 + 1 / M) * b)) ^ 2
123+
wald_type_interval <- function(n_imp, bar.v, b) {
124+
(n_imp - 1) * (1 + bar.v / ((1 + 1 / n_imp) * b)) ^ 2
125125
}
126126

127127
#' Variance estimate by pooling
128128
#'
129129
#' Use combining rules to estimate.
130130
#'
131-
#' @param M Number of syntheses used in analysis stage (high for low Monte Carlo error)
131+
#' @param n_imp Number of syntheses used in analysis stage (high for low Monte Carlo error)
132132
#' @param bar.v "within" variance (average of variance point estimates)
133133
#' @param b "between" variance (sample variance of point estimates)
134134
#' @return Numeric value of variance estimate using pooling.
135135
#' @keywords internal
136136
#'
137-
var_by_pooling <- function(M, bar.v, b) {
138-
(1 + (1 / M)) * b - bar.v
137+
var_by_pooling <- function(n_imp, bar.v, b) {
138+
(1 + (1 / n_imp)) * b - bar.v
139139
}
140140

0 commit comments

Comments
 (0)