Skip to content

Commit 1000727

Browse files
author
Colman Humphrey
authored
v0.6.0: Making glmmTMB conditional + removing deprecated (#8)
* removing `call. = FALSE` - originally inspired by https://adv-r.hadley.nz/conditions.html?q=call.%20=%20FALSE#errors-1 but I think it's not as helpful now * removing deprecated functions - it's time now. * document updates: - removed (previously deprecated) functions no longer in exported - docs updated (with roxygen update) * need glmmTMB for the last few tests * adding future.seed = TRUE to solve RNG from future.apply * increasing minimum version of glmmTMB * update the readme - run glmmTMB-dependent blocks conditionally - minor cleanup * adding conditional eval to vignette * adding clarification about non-parametric bootstrap * increasing version to 0.6.0 * adding cran-comments and news updates * spelling error * adding test envs to cran comments
1 parent 27bb38c commit 1000727

17 files changed

+101
-175
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: glmmboot
22
Type: Package
33
Title: Bootstrap Resampling for Mixed Effects and Plain Models
4-
Version: 0.5.1
4+
Version: 0.6.0
55
Authors@R: person("Colman", "Humphrey", email = "humphrc@tcd.ie",
66
role = c("aut", "cre"))
77
Description: Performs bootstrap resampling for most models that update() works for. There
@@ -19,12 +19,12 @@ Depends:
1919
Imports: methods,
2020
stats
2121
Suggests:
22-
glmmTMB (>= 0.2.1),
22+
glmmTMB (>= 1.1.0),
2323
testthat (>= 0.11.0),
2424
parallel (>= 3.0.0),
2525
future.apply (>= 1.1.0),
2626
knitr,
2727
rmarkdown,
2828
covr
29-
RoxygenNote: 7.0.2
29+
RoxygenNote: 7.1.1
3030
VignetteBuilder: knitr

NAMESPACE

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

3-
export(BootCI)
4-
export(BootGlmm)
5-
export(CombineResampledLists)
63
export(bootstrap_ci)
74
export(bootstrap_model)
85
export(combine_resampled_lists)

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# glmmboot 0.6.0
2+
3+
* Removing previously deprecated functions (deprecated as of 0.4.0)
4+
* Adding conditional evaluation for tests and the vignette (and the readme)
5+
for `glmmTMB`, in case it's not present / installable on a given system (as
6+
it's only a suggested package)
7+
* Removing `call. = FALSE` for errors and warnings
8+
* adding `future.seed = TRUE` to `future.apply::future_lapply` call for better RNG
9+
* Minor vignette and README copy edits
10+
111
# glmmboot 0.5.1
212

313
* Changing a `donttest` to a `dontrun` within an example.

R/bootstrap_ci.R

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ bootstrap_individual_ci <- function(base_matrix = NULL,
9191
if (is.null(probs)) {
9292
if (alpha_level < 0 | alpha_level > 0.5) {
9393
stop("Can't calculate a two-sided CI with this alpha value, ",
94-
"must be in (0, 0.5)", call. = FALSE)
94+
"must be in (0, 0.5)")
9595
}
9696
probs <- sort(c(alpha_level / 2, 1 - alpha_level / 2))
9797
}
9898
if (max(probs) > 1 || min(probs) < 0) {
99-
stop("Probabilities should be in (0,1)", call. = FALSE)
99+
stop("Probabilities should be in (0,1)")
100100
}
101101

102102
base_row_names <- rownames(base_matrix)
@@ -107,7 +107,7 @@ bootstrap_individual_ci <- function(base_matrix = NULL,
107107
}))
108108

109109
if (mean(name_match) != 1) {
110-
stop("Naming mismatch from base to list of coefs", call. = FALSE)
110+
stop("Naming mismatch from base to list of coefs")
111111
}
112112

113113
resampled_ests_vecs <- lapply(1:nrow(base_matrix), function(j){
@@ -239,24 +239,6 @@ ci_variable <- function(base_est,
239239
}
240240

241241

242-
#' @rdname bootstrap_ci
243-
#' @export
244-
#' @param alp_level
245-
#' now alpha_level
246-
BootCI <- function(base_coef_se = NULL, # nocov start
247-
resampled_coef_se = NULL,
248-
orig_df = NULL,
249-
alp_level = 0.05,
250-
probs = NULL){
251-
.Deprecated("bootstrap_ci")
252-
bootstrap_ci(base_coef_se = base_coef_se,
253-
resampled_coef_se = resampled_coef_se,
254-
orig_df = orig_df,
255-
alpha_level = alp_level,
256-
probs = probs)
257-
} # nocov end
258-
259-
260242
#' Combines output from multiple bootstrap_model calls
261243
#'
262244
#' If you run glmmboot on e.g. a grid of computers,
@@ -333,12 +315,3 @@ combine_resampled_lists <- function(...,
333315
bootstrap_ci(base_coef_se = reg_base_coef,
334316
resampled_coef_se = reg_resampled)
335317
}
336-
337-
#' @rdname combine_resampled_lists
338-
#' @export
339-
CombineResampledLists <- function(..., # nocov start
340-
return_combined_list = FALSE){
341-
.Deprecated("combine_resampled_lists")
342-
combine_resampled_lists(...,
343-
return_combined_list = return_combined_list)
344-
} # nocov end

R/bootstrap_methods.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ gen_resampling_index <- function(orig_list,
122122
sampled_list){
123123
if (length(orig_list) != length(sampled_list)) {
124124
stop("lists must be the same length ",
125-
"(the original variables and the sampled variables)",
126-
call. = FALSE)
125+
"(the original variables and the sampled variables)")
127126
}
128127

129128
## coercing to character means this works for all types

R/bootstrap_model.R

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ bootstrap_model <- function(base_model,
127127
} else {
128128
stop("base_data cannot be automatically inferred, ",
129129
"please supply data as base_data ",
130-
"to this function", call. = FALSE)
130+
"to this function")
131131
}
132132

133133
warning("Please supply data through the argument base_data; ",
134134
"automatic reading from your model can produce ",
135-
"unforeseeable bugs.", call. = FALSE)
135+
"unforeseeable bugs.")
136136
}
137137

138138
if (missing(parallelism)) {
@@ -142,7 +142,7 @@ bootstrap_model <- function(base_model,
142142
if (!requireNamespace("parallel", quietly = TRUE)) { # nocov start
143143
stop("setting `num_cores` greater than 1 without setting ",
144144
"`parallelism` uses `package:parallel`, ",
145-
"but it's not installed", call. = FALSE)
145+
"but it's not installed")
146146
}
147147
parallelism <- "parallel" # nocov end
148148
} else {
@@ -152,25 +152,23 @@ bootstrap_model <- function(base_model,
152152
parallelism <- match.arg(parallelism)
153153
if (parallelism == "none" && !is.null(num_cores) && num_cores > 1) {
154154
stop("contradiction between `parallelism = \"none\"` ",
155-
"and `num_cores = ", num_cores, "`; please resolve",
156-
call. = FALSE)
155+
"and `num_cores = ", num_cores, "`; please resolve")
157156
}
158157
if (parallelism == "future") {
159158
if (!requireNamespace("future.apply", quietly = TRUE)) { # nocov start
160159
stop("`parallelism = \"future\"` uses `package:future.apply`, ",
161-
"but it's not installed", call. = FALSE)
160+
"but it's not installed")
162161
} # nocov end
163162
if (!is.null(num_cores)) {
164163
stop("with `parallelism = \"future\"`, the `num_cores` ",
165164
"argument is not used to set up the backend; ",
166-
"use `future::plan` instead",
167-
call. = FALSE)
165+
"use `future::plan` instead")
168166
}
169167
}
170168
if (parallelism == "parallel") {
171169
if (!requireNamespace("parallel", quietly = TRUE)) { # nocov start
172170
stop("`parallelism = \"parallel\"` uses `package:parallel`, ",
173-
"but it's not installed", call. = FALSE)
171+
"but it's not installed")
174172
} # nocov end
175173

176174
if (is.null(num_cores)) { # nocov start
@@ -183,7 +181,7 @@ bootstrap_model <- function(base_model,
183181

184182
if (parallelism != "future" && !is.null(future_packages)) {
185183
stop("Argument `future_packages` should only be set when ",
186-
"using `parallelism = \"future\"`", call. = FALSE)
184+
"using `parallelism = \"future\"`")
187185
}
188186

189187
##------------------------------------
@@ -205,7 +203,7 @@ bootstrap_model <- function(base_model,
205203
} else {
206204
if (!list_of_matrices(base_coef)) {
207205
stop("currently this method needs `coef(summary(base_model))` ", # nocov start
208-
"to be a matrix, or a list of them", call. = FALSE) # nocov end
206+
"to be a matrix, or a list of them") # nocov end
209207
}
210208
## only calc not_null once, but local scope the result
211209
extract_coef <- (function(not_null){
@@ -234,7 +232,7 @@ bootstrap_model <- function(base_model,
234232
if (sum(rand_cols %in% resample_specific_blocks) == 0 &&
235233
length(rand_cols) > 0) {
236234
stop("No random columns from formula found ",
237-
"in resample_specific_blocks", call. = FALSE)
235+
"in resample_specific_blocks")
238236
}
239237
rand_cols <- rand_cols[rand_cols %in% resample_specific_blocks]
240238
}
@@ -338,8 +336,7 @@ bootstrap_model <- function(base_model,
338336
}
339337
if (any(error_ind)) {
340338
stop("could not generate error-free resamples in ", # nocov start
341-
max_redos, " attempts",
342-
call. = FALSE) # nocov end
339+
max_redos, " attempts") # nocov end
343340
}
344341

345342
if (return_coefs_instead) {
@@ -361,37 +358,6 @@ bootstrap_model <- function(base_model,
361358
}
362359

363360

364-
#' @export
365-
#' @rdname bootstrap_model
366-
#' @param suppress_loading_bar
367-
#' defunct now
368-
#' @param allow_conv_error
369-
#' defunct now
370-
BootGlmm <- function(base_model, # nocov start
371-
resamples = 9999,
372-
base_data = NULL,
373-
return_coefs_instead = FALSE,
374-
resample_specific_blocks = NULL,
375-
unique_resample_lim = NULL,
376-
narrowness_avoid = TRUE,
377-
num_cores = NULL,
378-
suppress_sampling_message = FALSE,
379-
suppress_loading_bar = FALSE,
380-
allow_conv_error = FALSE){
381-
.Deprecated("bootstrap_model")
382-
383-
bootstrap_model(base_model = base_model,
384-
base_data = base_data,
385-
resamples = resamples,
386-
return_coefs_instead = return_coefs_instead,
387-
resample_specific_blocks = resample_specific_blocks,
388-
unique_resample_lim = unique_resample_lim,
389-
narrowness_avoid = narrowness_avoid,
390-
num_cores = num_cores,
391-
suppress_sampling_message = suppress_sampling_message)
392-
} # nocov end
393-
394-
395361
#' Runs the bootstrapping of the models.
396362
#'
397363
#' This function gets passed a function that runs a single bootstrap resample
@@ -417,7 +383,8 @@ bootstrap_runner <- function(bootstrap_function,
417383
function(i){
418384
bootstrap_function()
419385
},
420-
future.packages = future_packages))
386+
future.packages = future_packages,
387+
future.seed = TRUE))
421388
}
422389

423390
if (parallelism == "parallel") {

README.Rmd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ options(warnPartialMatchArgs = FALSE,
2525

2626
## Overview
2727

28-
glmmboot provides a simple interface for creating bootstrap
28+
glmmboot provides a simple interface for creating non-parametric bootstrap
2929
confidence intervals using a wide set of models. The primary function
3030
is `bootstrap_model`, which has three primary arguments:
3131

@@ -47,6 +47,8 @@ For models with random effects:
4747

4848
With no random effects, performs case resampling: resamples each row with replacement.
4949

50+
All of these are considered non-parametric.
51+
5052
## Requirements:
5153

5254
1. the model should work with the
@@ -88,7 +90,7 @@ devtools::install_github("ColmanHumphrey/glmmboot")
8890
We'll provide a quick example using glm. First we'll set up some data:
8991

9092
```{r}
91-
set.seed(15278086) # Happy for Nadia and Alan
93+
set.seed(15278086)
9294
x1 <- rnorm(50)
9395
x2 <- runif(50)
9496
@@ -130,7 +132,8 @@ conservative at `N = 50`.
130132

131133
An example with a zero-inflated model (from the `glmmTMB` docs):
132134

133-
```{r}
135+
```{r, eval = requireNamespace("glmmTMB", quietly = TRUE)}
136+
## we'll skip this if glmmTMB not available
134137
library(glmmTMB)
135138
136139
owls <- transform(Owls,
@@ -148,7 +151,7 @@ fit_zipoisson <- glmmTMB(
148151
summary(fit_zipoisson)
149152
```
150153
Let's run the bootstrap (ignore the actual results, 3 resamples is basically meaningless - just for illustration):
151-
```{r}
154+
```{r, eval = requireNamespace("glmmTMB", quietly = TRUE)}
152155
zi_results <- bootstrap_model(base_model = fit_zipoisson,
153156
base_data = owls,
154157
resamples = 3)

0 commit comments

Comments
 (0)