-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeta analysis.R
More file actions
105 lines (52 loc) · 2.27 KB
/
Meta analysis.R
File metadata and controls
105 lines (52 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Load required libraries
library(dplyr)
library(meta)
library(metafor)
# Load the data
data <- read.csv("PRT.csv", stringsAsFactors = FALSE)
colnames(data)
# Temp Function to show dataframe in Excel --------------------------------
show_in_excel <- function(.data){
tmp <- paste0(tempfile(), ".csv")
write.csv(.data, tmp)
fs::file_show(path = tmp)
}
#data %>% show_in_excel()
data$Effect.Size <- as.numeric(data$Effect.Size)
data$Sample <- as.numeric(data$Sample)
meta_data <- data[complete.cases(data[, c("Effect.Size", "Sample", "First.Author")]), c("First.Author", "Effect.Size", "Sample")]
meta_data$sei <- 1 / sqrt(meta_data$Sample)
meta_analysis <- rma(yi = Effect.Size, sei = sei, data = meta_data, method = "REML")
summary(meta_analysis)
meta_data <- data %>%
filter(!is.na(`Experimental.Outcome`) & !is.na(`Outcome.Measure`) & !is.na(`Sample`)) %>%
mutate(TE = `Experimental.Outcome` - `Outcome.Measure`,
Variance = ((`Effect.Size` * `Sample`)^2) / `Sample`,
sei = sqrt(Variance / `Sample`)) %>%
select(PMID, `First.Author`, Sample, TE, sei)
ma <- metagen(TE, sei, data = meta_data,
study = paste(meta_data$PMID, meta_data$`First.Author`, sep = "_"),
subset = !is.na(meta_data$TE))
summary(ma)
#write.xlsx(dt$data, "dtdata.xlsx")
# Perform sensitivity analysis using a loop
sensitivity_results <- data.frame(study = character(), SMD = numeric(), lower = numeric(), upper = numeric())
for (i in 1:nrow(meta_data)) {
subset_data <- meta_data[-i, ]
subset_ma <- metagen(TE, sei, data = subset_data,
study = paste(subset_data$PMID, subset_data$`First.Author`, sep = "_"),
subset = !is.na(subset_data$TE))
sensitivity_results <- rbind(sensitivity_results, data.frame(
study = paste("Excluding", meta_data$`First.Author`[i]),
SMD = subset_ma$TE.random,
lower = subset_ma$lower.random,
upper = subset_ma$upper.random
))
}
print(sensitivity_results)
forest(meta_analysis, slab = meta_data$First.Author, xlim = c(-10, 10), alim = c(-10, 10),
xlab = "Effect Size", refline = 0, cex = 0.8, ylim = c(-1, nrow(meta_data) + 1))
print(meta_analysis)
funnel(meta_analysis)
eggers_test <- regtest(meta_analysis)
print(eggers_test)