Skip to content

Commit 1b39e3b

Browse files
authored
Merge pull request #7 from leibniz-psychology/staging
Release 1.1.2
2 parents 3b80844 + 8d11af4 commit 1b39e3b

5 files changed

Lines changed: 193 additions & 187 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11

2+
## Release 1.1.2
3+
### future
4+
5+
## Release 1.1.2
6+
### 02.2026
7+
* fixed minor problem in createJSON function
8+
* fixed forest plot and cumul forest plot functions to load data session correctly
9+
10+
211
## Release 1.1.1
312
### 03.2025
413
* Changed how the r functions ingest the data. Former, the data was loaded from the package.
@@ -57,7 +66,4 @@ Features:
5766
### 21.06.2021 / Online 21.06.2021
5867
Features:
5968
* Minimal viable product
60-
* All functions still need some optimization in the future
61-
62-
63-
69+
* All functions still need some optimization in the future

R/createJsonFromData.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ library(jsonlite)
55
createJsonFromData <- function(d) {
66
dat <- checkData(d)
77

8-
json_data <- toJSON(dat, pretty = TRUE, digits = NA)
8+
json_data <- jsonlite::toJSON(dat, pretty = TRUE, digits = NA)
99

1010
write(json_data, paste0(d, ".json"))
1111

R/cumulForestPlot.R

Lines changed: 92 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,92 @@
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+
}

R/forestPlot.R

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
#' @title Forest plot
2-
#' @description
3-
#' Using metafor package to create a forest plot and metaviz package to create a rain forest plot.
4-
#' @param yi
5-
#' 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)
6-
#' @param vi
7-
#' A \code{string} of the variable which holds the vector of length k with the corresponding sampling variances in the selected dataset (d)
8-
#' @param d
9-
#' A \code{string} representing the dataset name that should be used for fitting.
10-
#' @param effect
11-
#' A \code{string} representing the effect name that should be printed as label. defaults to "Effect"
12-
#' @param measure
13-
#' A character string indicating underlying summary measure.
14-
#' @return
15-
#' creates a forest and rainforest plot
16-
#' also creates a json file (imgHeight.json) that is used in a later api call to define the height of the plots
17-
#' @author Robert Studtrucker
18-
#' @export
19-
forest <- function(yi,vi,measure,d,effect="Effect") {
20-
21-
requireNamespace("metafor")
22-
requireNamespace("ggplot2")
23-
requireNamespace("metaviz")
24-
requireNamespace("jsonlite")
25-
requireNamespace("psych")
26-
27-
#load the in variable d defined dataset from the package
28-
dat <- checkData(d)
29-
30-
if(measure == "COR") {
31-
32-
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))
33-
34-
fp <- metaviz::viz_forest(x = rma_model,
35-
variant = "classic",
36-
study_labels = rma_model$slab,
37-
text_size =4,
38-
xlab = effect,
39-
annotate_CI = TRUE,
40-
method = "REML",
41-
x_trans_function = tanh,
42-
type = "standard")
43-
44-
rainfp <-metaviz::viz_forest(x = rma_model,
45-
variant = "rain",
46-
study_labels = rma_model$slab,
47-
text_size =4,
48-
xlab = effect,
49-
annotate_CI = TRUE,
50-
method = "REML",
51-
x_trans_function = tanh,
52-
type = "standard")
53-
54-
55-
height<-list("height" = length(rma_model$yi))
56-
jsonlite::write_json(height, "imgHeight.json")
57-
58-
print(fp)
59-
print(rainfp)
60-
61-
invisible();
62-
63-
}else{
64-
rma_model <- metafor::rma.uni(yi=dat[,yi],vi=dat[,vi],measure=measure,slab=paste(dat$r_author, dat$r_year))
65-
66-
fp <- metaviz::viz_forest(x = rma_model,
67-
variant = "classic",
68-
study_labels = rma_model$slab,
69-
text_size =4,
70-
xlab = effect,
71-
annotate_CI = TRUE,
72-
type = "standard")
73-
74-
rainfp <- metaviz::viz_forest(x = rma_model,
75-
variant = "rain",
76-
study_labels = rma_model$slab,
77-
text_size =4,
78-
xlab = effect,
79-
annotate_CI = TRUE,
80-
type = "standard")
81-
82-
height<-list("height" = length(rma_model$yi))
83-
jsonlite::write_json(height, "imgHeight.json")
84-
85-
print(fp)
86-
print(rainfp)
87-
88-
invisible();
89-
}
90-
}
1+
#' @title Forest plot
2+
#' @description
3+
#' Using metafor package to create a forest plot and metaviz package to create a rain forest plot.
4+
#' @param yi
5+
#' 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)
6+
#' @param vi
7+
#' A \code{string} of the variable which holds the vector of length k with the corresponding sampling variances in the selected dataset (d)
8+
#' @param d
9+
#' A \code{string} representing the dataset name that should be used for fitting.
10+
#' @param effect
11+
#' A \code{string} representing the effect name that should be printed as label. defaults to "Effect"
12+
#' @param measure
13+
#' A character string indicating underlying summary measure.
14+
#' @return
15+
#' creates a forest and rainforest plot
16+
#' also creates a json file (imgHeight.json) that is used in a later api call to define the height of the plots
17+
#' @author Robert Studtrucker
18+
#' @export
19+
forest <- function(yi,vi,measure,d,effect="Effect") {
20+
21+
requireNamespace("metafor")
22+
requireNamespace("ggplot2")
23+
requireNamespace("metaviz")
24+
requireNamespace("jsonlite")
25+
requireNamespace("psych")
26+
27+
#load the in variable d defined dataset from the package
28+
#dat <- checkData(d)
29+
dat <- d
30+
if(measure == "COR") {
31+
32+
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))
33+
34+
fp <- metaviz::viz_forest(x = rma_model,
35+
variant = "classic",
36+
study_labels = rma_model$slab,
37+
text_size =4,
38+
xlab = effect,
39+
annotate_CI = TRUE,
40+
method = "REML",
41+
x_trans_function = tanh,
42+
type = "standard")
43+
44+
rainfp <-metaviz::viz_forest(x = rma_model,
45+
variant = "rain",
46+
study_labels = rma_model$slab,
47+
text_size =4,
48+
xlab = effect,
49+
annotate_CI = TRUE,
50+
method = "REML",
51+
x_trans_function = tanh,
52+
type = "standard")
53+
54+
55+
height<-list("height" = length(rma_model$yi))
56+
jsonlite::write_json(height, "imgHeight.json")
57+
58+
print(fp)
59+
print(rainfp)
60+
61+
invisible();
62+
63+
}else{
64+
rma_model <- metafor::rma.uni(yi=dat[,yi],vi=dat[,vi],measure=measure,slab=paste(dat$r_author, dat$r_year))
65+
66+
fp <- metaviz::viz_forest(x = rma_model,
67+
variant = "classic",
68+
study_labels = rma_model$slab,
69+
text_size =4,
70+
xlab = effect,
71+
annotate_CI = TRUE,
72+
type = "standard")
73+
74+
rainfp <- metaviz::viz_forest(x = rma_model,
75+
variant = "rain",
76+
study_labels = rma_model$slab,
77+
text_size =4,
78+
xlab = effect,
79+
annotate_CI = TRUE,
80+
type = "standard")
81+
82+
height<-list("height" = length(rma_model$yi))
83+
jsonlite::write_json(height, "imgHeight.json")
84+
85+
print(fp)
86+
print(rainfp)
87+
88+
invisible();
89+
}
90+
}

0 commit comments

Comments
 (0)