|
103 | 103 | #' |
104 | 104 | #' ## now speed things up by defining the inner resampling |
105 | 105 | #' ## function with parallelization based on mclapply (does not work on Windows) |
| 106 | +#' isWindows <- Sys.info()['sysname']=="Windows" |
106 | 107 | #' |
107 | 108 | #' my_inner_fun <- function(object){ |
108 | 109 | #' cvrisk(object, folds = cvLong(id = object$id, weights = |
109 | 110 | #' model.weights(object), |
110 | 111 | #' B = 10 # 10-fold for inner resampling |
111 | | -#' ), mc.cores = 10) # use ten cores |
| 112 | +#' ), mc.cores = if(isWindows) 1 else 10) # use ten cores |
112 | 113 | #' } |
113 | 114 | #' |
114 | 115 | #' \donttest{ |
115 | | -#' bootCIs <- bootstrapCI(m1, resampling_fun_inner = my_inner_fun) |
| 116 | +#' bootCIs <- bootstrapCI(m1, resampling_fun_inner = my_inner_fun, |
| 117 | +#' B_outer = 5) # small B_outer to speed up |
116 | 118 | #' } |
117 | 119 | #' |
118 | 120 | #' ## We can also use the ... argument to parallelize the applyFolds |
119 | 121 | #' ## function in the outer resampling |
120 | 122 | #' |
121 | 123 | #' \donttest{ |
122 | | -#' bootCIs <- bootstrapCI(m1, mc.cores = 30) |
| 124 | +#' bootCIs <- bootstrapCI(m1, mc.cores = if(isWindows) 1 else 30, |
| 125 | +#' B_inner = 5, B_outer = 3) |
123 | 126 | #' } |
124 | 127 | #' |
125 | 128 | #' ## Now let's parallelize the outer resampling and use |
|
128 | 131 | #' my_inner_fun <- function(object){ |
129 | 132 | #' cvrisk(object, folds = cvLong(id = object$id, weights = |
130 | 133 | #' model.weights(object), type = "kfold", # use CV |
131 | | -#' B = 10, # 10-fold for inner resampling |
| 134 | +#' B = 5, # 5-fold for inner resampling |
132 | 135 | #' ), |
133 | | -#' mc.cores = 10) # use ten cores |
| 136 | +#' mc.cores = if(isWindows) 1 else 5) # use five cores |
134 | 137 | #' } |
135 | 138 | #' |
136 | 139 | #' # use applyFolds for outer function to avoid messing up weights |
137 | 140 | #' my_outer_fun <- function(object, fun){ |
138 | 141 | #' applyFolds(object = object, |
139 | 142 | #' folds = cv(rep(1, length(unique(object$id))), |
140 | | -#' type = "bootstrap", B = 100), fun = fun, |
141 | | -#' mc.cores = 10) # parallelize on 10 cores |
| 143 | +#' type = "bootstrap", B = 10), fun = fun, |
| 144 | +#' mc.cores = if(isWindows) 1 else 10) # parallelize on 10 cores |
| 145 | +#' } |
| 146 | +#' |
| 147 | +#' \donttest{ |
| 148 | +#' bootCIs <- bootstrapCI(m1, resampling_fun_inner = my_inner_fun, |
| 149 | +#' resampling_fun_outer = my_outer_fun, |
| 150 | +#' B_inner = 5, B_outer = 10) |
| 151 | +# -> provide B_inner & B_outer only for enabling default plot |
142 | 152 | #' } |
143 | 153 | #' |
144 | 154 | #' ######## Example for scalar-on-function-regression with bsignal() |
|
165 | 175 | #' |
166 | 176 | #' \donttest{ |
167 | 177 | #' # takes some time, because of defaults: B_outer = 100, B_inner = 25 |
168 | | -#' bootCIs <- bootstrapCI(mod2) |
| 178 | +#' bootCIs <- bootstrapCI(mod2, B_outer = 10, B_inner = 5) |
| 179 | +#' # in practice, rather set B_outer = 1000 |
169 | 180 | #' } |
170 | 181 | #' |
171 | | -#' ## run with a larger number of outer bootstrap samples |
172 | | -#' ## and only 10-fold for validation of each outer fold |
173 | | -#' ## WARNING: This may take very long! |
174 | | -#' \donttest{ |
175 | | -#' bootCIs <- bootstrapCI(mod2, B_outer = 1000, B_inner = 10) |
176 | | -#' } |
177 | 182 | #' |
178 | 183 | #' @export |
179 | 184 | bootstrapCI <- function(object, which = NULL, |
|
0 commit comments