|
53 | 53 | #'set the confidence level for power intervals, which are printed when `detailedoutput = TRUE`.
|
54 | 54 | #'@param parallel Default `FALSE`. If `TRUE`, the Monte Carlo power calculation will use all but one of the available cores. If the user wants to set the number of cores manually, they can do this by setting `options("cores")` to the desired number (e.g. `options("cores" = parallel::detectCores())`).
|
55 | 55 | #' NOTE: If you have installed BLAS libraries that include multicore support (e.g. Intel MKL that comes with Microsoft R Open), turning on parallel could result in reduced performance.
|
| 56 | +#'@param candidate_set Default `NA`. If you generated your design externally from skpr and there are disallowed combinations in your design, |
| 57 | +#'the calculated I-optimality values will not be correct, as it assumes an unconstrained unit hypercube. To calculate the restricted regions, |
| 58 | +#'skpr will find the convex hull of the point set and generate a higher density of points in that region. Note that this only supports |
| 59 | +#'convex constraints. |
| 60 | +#'@param mm_sample_density Default `20`. The density of points to sample when calculating the moment matrix to compute I-optimality. Only |
| 61 | +#'required if the design was generated outside of skpr and there are disallowed combinations. |
56 | 62 | #'@param ... Additional arguments.
|
57 | 63 | #'@return A data frame consisting of the parameters and their powers, with supplementary information
|
58 | 64 | #'stored in the data frame's attributes. The parameter estimates from the simulations are stored in the "estimates"
|
@@ -254,6 +260,8 @@ eval_design_mc = function(
|
254 | 260 | detailedoutput = FALSE,
|
255 | 261 | progress = TRUE,
|
256 | 262 | advancedoptions = NULL,
|
| 263 | + candidate_set = NA, |
| 264 | + mm_sample_density = 20, |
257 | 265 | ...
|
258 | 266 | ) {
|
259 | 267 | if (!firth || glmfamily != "binomial") {
|
@@ -1294,25 +1302,31 @@ eval_design_mc = function(
|
1294 | 1302 | imported_mm = FALSE
|
1295 | 1303 | if(!is.null(attr(design, "generating.model"))) {
|
1296 | 1304 | og_design_factors = attr(terms.formula(attr(design, "generating.model")),"factors")
|
1297 |
| - new_model_factors = attr(terms.formula(model),"factors") |
1298 |
| - identical_main_effects = all(rownames(og_design_factors) == rownames(new_model_factors)) |
1299 |
| - identical_interactions = all(colnames(og_design_factors) == colnames(new_model_factors)) |
1300 |
| - if(identical_interactions && identical_main_effects) { |
1301 |
| - mm = attr(design, "moments.matrix") |
1302 |
| - imported_mm = TRUE |
| 1305 | + new_model_factors = attr(terms.formula(model_formula),"factors") |
| 1306 | + if(all(dim(og_design_factors) == dim(new_model_factors))) { |
| 1307 | + identical_main_effects = all(rownames(og_design_factors) == rownames(new_model_factors)) |
| 1308 | + identical_interactions = all(colnames(og_design_factors) == colnames(new_model_factors)) |
| 1309 | + if(identical_interactions && identical_main_effects) { |
| 1310 | + mm = attr(design, "moments.matrix") |
| 1311 | + imported_mm = TRUE |
| 1312 | + } |
1303 | 1313 | }
|
1304 | 1314 | }
|
1305 | 1315 | if(!imported_mm) {
|
1306 |
| - if(all(classvector)) { |
1307 |
| - mm = gen_momentsmatrix(colnames(attr(run_matrix_processed, "modelmatrix")), levelvector, classvector) |
1308 |
| - } else { |
1309 |
| - if(!is.null(attr(design, "candidate_set"))) { |
1310 |
| - mm = gen_momentsmatrix_continuous(formula = model, |
1311 |
| - candidate_set = attr(design, "candidate_set"), |
1312 |
| - n_samples_per_dimension = 20) |
| 1316 | + mm = gen_momentsmatrix(colnames(ModelMatrix), levelvector, classvector) |
| 1317 | + if(!is.na(candidate_set)) { |
| 1318 | + if(!all(classvector)) { |
| 1319 | + hash_mm = digest::digest(list(model_formula, candidate_set, mm_sample_density)) |
| 1320 | + if(!exists(hash_mm, envir = skpr_moment_matrix_cache)) { |
| 1321 | + mm = gen_momentsmatrix_continuous(formula = model_formula, |
| 1322 | + candidate_set = candidate_set, |
| 1323 | + n_samples_per_dimension = mm_sample_density) |
| 1324 | + assign(hash_mm, mm, envir = skpr_moment_matrix_cache) |
| 1325 | + } else { |
| 1326 | + mm = get(hash_mm,envir = skpr_moment_matrix_cache) |
| 1327 | + } |
1313 | 1328 | } else {
|
1314 |
| - warning("Candidate set not included with design: assuming no disallowed combinations when calculating moment matrix.") |
1315 |
| - mm = gen_momentsmatrix(colnames(attr(run_matrix_processed, "modelmatrix")), levelvector, classvector) |
| 1329 | + mm = gen_momentsmatrix(colnames(ModelMatrix), levelvector, classvector) |
1316 | 1330 | }
|
1317 | 1331 | }
|
1318 | 1332 | }
|
|
0 commit comments