|
1 | | -#' @title cumulative Forest plot |
2 | | -#' @description |
3 | | -#' Using metafor rma.uni function to fit a meta-analytic multivariate/multilevel fixed- and random/mixed-effects model for the given dataset. |
4 | | -#' The model then is used as input for the metaviz viz_forest function to print a forrest plot |
5 | | -#' See Documentation of metafor and metaviz packages for details. |
6 | | -#' @param yi |
7 | | -#' A \code{string} of the variable which holds the vector of length k with the observed effect sizes or outcomes in the selected dataset (d) |
8 | | -#' @param vi |
9 | | -#' A \code{string} of the variable which holds the vector of length k with the corresponding sampling variances in the selected dataset (d) |
10 | | -#' @param d |
11 | | -#' A \code{string} representing the dataset name that should be used for fitting. |
12 | | -#' @param effectName |
13 | | -#' A \code{string} representing the effect name that should be printed as label. defaults to "Effect" |
14 | | -#' @param measure |
15 | | -#' A character string indicating underlying summary measure. |
16 | | -#' @return |
17 | | -#' creates a cumulative forest plot |
18 | | -#' also creates a json file (imgHeight.json) that is used in a later api call to define the height of the plots |
19 | | -#' @author Robert Studtrucker |
20 | | -#' @export |
21 | | -cumulforest <- function(yi,vi,measure,d,effectName="Effect") { |
22 | | - |
23 | | - #load needed dependencies |
24 | | - |
25 | | - requireNamespace("metafor") |
26 | | - requireNamespace("ggplot2") |
27 | | - requireNamespace("metaviz") |
28 | | - requireNamespace("jsonlite") |
29 | | - |
30 | | - #load the in variable d defined dataset from the package |
31 | | - dat <- checkData(d) |
32 | | - checkParameter(dat,c(yi,vi)) |
33 | | - |
34 | | - #order the loaded data depending on the r_year column |
35 | | - dat <- dat[order(dat$r_year),] |
36 | | - |
37 | | - # depending on the given measure the input for rma.uni model is z transformed |
38 | | - if(measure == "COR") { |
39 | | - |
40 | | - #fitting the rma.uni model based on z transformed data |
41 | | - |
42 | | - rma_model <- metafor::rma.uni(yi=metafor::transf.rtoz(dat[,yi],dat[,o_ni]), vi=metafor::transf.rtoz(dat[,vi],dat[,o_ni]),measure="ZCOR",slab=paste(dat$r_author, dat$r_year)) |
43 | | - |
44 | | - tmp<-metafor::cumul(rma_model, order=order(dat$r_year)) |
45 | | - #creating a cumulative forest plot based on the fitted rma.uni model |
46 | | - |
47 | | - |
48 | | - #fp <- metaviz::viz_forest(x = rma_model, |
49 | | - # variant = "classic", |
50 | | - # study_labels = rma_model$slab, |
51 | | - # text_size =4, |
52 | | - # xlab = effectName, |
53 | | - # annotate_CI = TRUE, |
54 | | - # x_trans_function = tanh, |
55 | | - # type = "cumulative") |
56 | | - |
57 | | - fp<- metafor::forest(x=tmp, |
58 | | - cex=0.75, |
59 | | - xlab = "Correlation Coefficient", |
60 | | - study_labels = tmp$slab, |
61 | | - transf="ztor", |
62 | | - efac=0.2 |
63 | | - ) |
64 | | - }else{ |
65 | | - # 1. Overall-Effekt und Cumulative forest #### |
66 | | - |
67 | | - #fitting the rma.uni model |
68 | | - rma_model <- metafor::rma.uni(yi=dat[,yi],vi=dat[,vi],measure=measure,slab=paste(dat$r_author, dat$r_year)) |
69 | | - |
70 | | - #tmp<-cumul(rma_model, order=order(dat$r_year)) |
71 | | - |
72 | | - #creating a cumulative forest plot based on the fitted rma.uni model |
73 | | - fp <- metaviz::viz_forest(x = rma_model, |
74 | | - variant = "classic", |
75 | | - study_labels = rma_model$slab, |
76 | | - text_size =4, |
77 | | - xlab = effectName, |
78 | | - annotate_CI = TRUE, |
79 | | - type = "cumulative") |
80 | | - } |
81 | | - |
82 | | - # creating a json object with information about the height of the plot |
83 | | - # this information is needed by the web service to define how big the requested image has to be. |
84 | | - # If not specified standard height and wde is used wich may cause deformed plots when there are a lot of rows in the plot. |
85 | | - height<-list("height" = length(rma_model$yi)) |
86 | | - jsonlite::write_json(height, "imgHeight.json") |
87 | | - |
88 | | - # print the cumul forest plot so the corresponding object can be retrieved by the web service |
89 | | - print(fp) |
90 | | - invisible(); |
91 | | -} |
| 1 | +#' @title cumulative Forest plot |
| 2 | +#' @description |
| 3 | +#' Using metafor rma.uni function to fit a meta-analytic multivariate/multilevel fixed- and random/mixed-effects model for the given dataset. |
| 4 | +#' The model then is used as input for the metaviz viz_forest function to print a forrest plot |
| 5 | +#' See Documentation of metafor and metaviz packages for details. |
| 6 | +#' @param yi |
| 7 | +#' A \code{string} of the variable which holds the vector of length k with the observed effect sizes or outcomes in the selected dataset (d) |
| 8 | +#' @param vi |
| 9 | +#' A \code{string} of the variable which holds the vector of length k with the corresponding sampling variances in the selected dataset (d) |
| 10 | +#' @param d |
| 11 | +#' A \code{string} representing the dataset name that should be used for fitting. |
| 12 | +#' @param effectName |
| 13 | +#' A \code{string} representing the effect name that should be printed as label. defaults to "Effect" |
| 14 | +#' @param measure |
| 15 | +#' A character string indicating underlying summary measure. |
| 16 | +#' @return |
| 17 | +#' creates a cumulative forest plot |
| 18 | +#' also creates a json file (imgHeight.json) that is used in a later api call to define the height of the plots |
| 19 | +#' @author Robert Studtrucker |
| 20 | +#' @export |
| 21 | +cumulforest <- function(yi,vi,measure,d,effectName="Effect") { |
| 22 | + |
| 23 | + #load needed dependencies |
| 24 | + |
| 25 | + requireNamespace("metafor") |
| 26 | + requireNamespace("ggplot2") |
| 27 | + requireNamespace("metaviz") |
| 28 | + requireNamespace("jsonlite") |
| 29 | + |
| 30 | + #load the in variable d defined dataset from the package |
| 31 | + #dat <- checkData(d) |
| 32 | + dat <- d |
| 33 | + checkParameter(dat,c(yi,vi)) |
| 34 | + |
| 35 | + #order the loaded data depending on the r_year column |
| 36 | + dat <- dat[order(dat$r_year),] |
| 37 | + |
| 38 | + # depending on the given measure the input for rma.uni model is z transformed |
| 39 | + if(measure == "COR") { |
| 40 | + |
| 41 | + #fitting the rma.uni model based on z transformed data |
| 42 | + |
| 43 | + rma_model <- metafor::rma.uni(yi=metafor::transf.rtoz(dat[,yi],dat[,o_ni]), vi=metafor::transf.rtoz(dat[,vi],dat[,o_ni]),measure="ZCOR",slab=paste(dat$r_author, dat$r_year)) |
| 44 | + |
| 45 | + tmp<-metafor::cumul(rma_model, order=order(dat$r_year)) |
| 46 | + #creating a cumulative forest plot based on the fitted rma.uni model |
| 47 | + |
| 48 | + |
| 49 | + #fp <- metaviz::viz_forest(x = rma_model, |
| 50 | + # variant = "classic", |
| 51 | + # study_labels = rma_model$slab, |
| 52 | + # text_size =4, |
| 53 | + # xlab = effectName, |
| 54 | + # annotate_CI = TRUE, |
| 55 | + # x_trans_function = tanh, |
| 56 | + # type = "cumulative") |
| 57 | + |
| 58 | + fp<- metafor::forest(x=tmp, |
| 59 | + cex=0.75, |
| 60 | + xlab = "Correlation Coefficient", |
| 61 | + study_labels = tmp$slab, |
| 62 | + transf="ztor", |
| 63 | + efac=0.2 |
| 64 | + ) |
| 65 | + }else{ |
| 66 | + # 1. Overall-Effekt und Cumulative forest #### |
| 67 | + |
| 68 | + #fitting the rma.uni model |
| 69 | + rma_model <- metafor::rma.uni(yi=dat[,yi],vi=dat[,vi],measure=measure,slab=paste(dat$r_author, dat$r_year)) |
| 70 | + |
| 71 | + #tmp<-cumul(rma_model, order=order(dat$r_year)) |
| 72 | + |
| 73 | + #creating a cumulative forest plot based on the fitted rma.uni model |
| 74 | + fp <- metaviz::viz_forest(x = rma_model, |
| 75 | + variant = "classic", |
| 76 | + study_labels = rma_model$slab, |
| 77 | + text_size =4, |
| 78 | + xlab = effectName, |
| 79 | + annotate_CI = TRUE, |
| 80 | + type = "cumulative") |
| 81 | + } |
| 82 | + |
| 83 | + # creating a json object with information about the height of the plot |
| 84 | + # this information is needed by the web service to define how big the requested image has to be. |
| 85 | + # If not specified standard height and wde is used wich may cause deformed plots when there are a lot of rows in the plot. |
| 86 | + height<-list("height" = length(rma_model$yi)) |
| 87 | + jsonlite::write_json(height, "imgHeight.json") |
| 88 | + |
| 89 | + # print the cumul forest plot so the corresponding object can be retrieved by the web service |
| 90 | + print(fp) |
| 91 | + invisible(); |
| 92 | +} |
0 commit comments