|
22 | 22 |
|
23 | 23 |
|
24 | 24 | # TODO: |
25 | | -# Forest plot |
26 | | -# - allow aggregation of studies by a factor (then show simple REML aggregation within and overlaying shaded estimates) |
27 | 25 | # AIC/BIC Model-averaging |
28 | 26 | # Diagnostics |
29 | 27 | # - model re-run on presence of influential cases |
|
97 | 95 | if (options[["diagnosticsResidualFunnel"]]) |
98 | 96 | .maResidualFunnelPlot(jaspResults, options) |
99 | 97 |
|
100 | | - |
101 | 98 | # additional |
102 | 99 | if (options[["showMetaforRCode"]]) |
103 | 100 | .maShowMetaforRCode(jaspResults, options) |
104 | 101 |
|
| 102 | + # export the variance-covariance matrix if requested |
| 103 | + if (.maIsMultilevelMultivariate(options) && options[["varianceCovarianceMatrixSaveComputedVarianceCovarianceMatrix"]] != "") |
| 104 | + .mammExportVarianceCovarianceMatrix(dataset, options) |
| 105 | + |
105 | 106 | return() |
106 | 107 | } |
107 | 108 |
|
|
154 | 155 | subgroupIndx <- dataset[[options[["subgroup"]]]] == subgroupLevel |
155 | 156 | subgroupData <- droplevels(dataset[subgroupIndx, ]) |
156 | 157 |
|
157 | | - # forward NAs information |
| 158 | + # forward NAs information and additional attributes |
158 | 159 | tempNasIds <- attr(dataset, "NasIds")[!attr(dataset, "NasIds")] |
159 | | - attr(subgroupData, "NAs") <- sum(tempNasIds[subgroupIndx]) |
160 | | - attr(subgroupData, "NasIds") <- tempNasIds[subgroupIndx] |
| 160 | + attr(subgroupData, "NAs") <- sum(tempNasIds[subgroupIndx]) |
| 161 | + attr(subgroupData, "NasIds") <- tempNasIds[subgroupIndx] |
| 162 | + attr(subgroupData, "subgroupIndx") <- subgroupIndx |
161 | 163 |
|
162 | 164 | # fit the model |
163 | 165 | fitOutput[[paste0("subgroup", subgroupLevel)]] <- .maFitModelFun(subgroupData, options, subgroupName = as.character(subgroupLevel)) |
|
178 | 180 |
|
179 | 181 | # specify the effect size and outcome |
180 | 182 | if (options[["module"]] == "metaAnalysis") { |
| 183 | + # specify the univariate input |
181 | 184 | rmaInput <- list( |
182 | 185 | yi = as.name(options[["effectSize"]]), |
183 | 186 | sei = as.name(options[["effectSizeStandardError"]]), |
184 | 187 | data = dataset |
185 | 188 | ) |
186 | 189 | } else if (options[["module"]] == "metaAnalysisMultilevelMultivariate") { |
187 | | - # TODO: extend to covariance matrices |
| 190 | + # specify the multivariate input |
188 | 191 | rmaInput <- list( |
189 | 192 | yi = as.name(options[["effectSize"]]), |
190 | | - V = as.name("samplingVariance"), # precomputed on data load |
| 193 | + V = if (.mammVarianceCovarianceMatrixReady(options)) .mammGetVarianceCovarianceMatrix(dataset, options) else as.name("samplingVariance"), |
191 | 194 | data = dataset |
192 | 195 | ) |
193 | 196 | } |
|
757 | 760 | ) |
758 | 761 | } |
759 | 762 |
|
| 763 | + # add multivariate settings notes |
| 764 | + if (.maIsMultilevelMultivariate(options)) { |
| 765 | + multivariateReadyNotes <- attr(.mammVarianceCovarianceMatrixReady(options), "messages") |
| 766 | + for (i in seq_along(multivariateReadyNotes)) { |
| 767 | + testsTable$addFootnote(multivariateReadyNotes[i]) |
| 768 | + } |
| 769 | + } |
| 770 | + |
760 | 771 | # bind and clean rows |
761 | 772 | tests <- .maSafeRbind(tests) |
762 | 773 | tests <- .maSafeOrderAndSimplify(tests, "test", options) |
|
3316 | 3327 | data = as.name("dataset") |
3317 | 3328 | ) |
3318 | 3329 | } else if (options[["module"]] == "metaAnalysisMultilevelMultivariate") { |
3319 | | - # TODO: extend to covariance matrices |
| 3330 | + |
| 3331 | + if (.mammVarianceCovarianceMatrixReady(options)) { |
| 3332 | + vcalcInput <-.mammGetVarianceCovarianceMatrix(NULL, options, returnCall = TRUE) |
| 3333 | + vcalcInput$data <- as.name("dataset") |
| 3334 | + } |
| 3335 | + |
3320 | 3336 | rmaInput <- list( |
3321 | 3337 | yi = as.name(options[["effectSize"]]), |
3322 | | - V = paste0(options[["effectSizeStandardError"]], "^2"), # precomputed on data load |
| 3338 | + V = if (.mammVarianceCovarianceMatrixReady(options)) "effectSizeVarianceCovarianceMatrix" else paste0(options[["effectSizeStandardError"]], "^2"), |
3323 | 3339 | data = as.name("dataset") |
3324 | 3340 | ) |
3325 | 3341 | } |
|
3401 | 3417 | fit <- paste0("fit <- rma(\n\t", paste(names(rmaInput), "=", rmaInput, collapse = ",\n\t"), "\n)\n") |
3402 | 3418 | } |
3403 | 3419 |
|
| 3420 | + if (.maIsMultilevelMultivariate(options) && .mammVarianceCovarianceMatrixReady(options)) { |
| 3421 | + if (options[["varianceCovarianceMatrixType"]] == "precomputed") { |
| 3422 | + fit <- paste0( |
| 3423 | + paste0("effectSizeVarianceCovarianceMatrix <- ", vcalcInput[["file"]], "\n"), "\n", |
| 3424 | + fit |
| 3425 | + ) |
| 3426 | + } else { |
| 3427 | + fit <- paste0( |
| 3428 | + paste0("effectSizeVarianceCovarianceMatrix <- vcalc(\n\t", paste(names(vcalcInput), "=", vcalcInput, collapse = ",\n\t"), "\n)\n"), "\n", |
| 3429 | + fit |
| 3430 | + ) |
| 3431 | + } |
| 3432 | + } |
3404 | 3433 |
|
3405 | 3434 | # add clustering if specified |
3406 | 3435 | if (options[["clustering"]] != "") { |
|
0 commit comments