-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMIP1a_analysis_FTD_v5.Rmd
508 lines (363 loc) · 18.8 KB
/
MIP1a_analysis_FTD_v5.Rmd
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
---
title: "MIP1a_analysis_v5.Rmd"
author: "Sanjay"
date: "24/12/2022"
output: html_document
---
# corrections from v4
# correction 1 correcting the labelling of estimated values for control and ftd
# correction 2 removing the completes dataframe to prevent duplication with incompletes2 dataframe - subsequent dataframes not renamed for back compatability
# Step 1: run a loop for MIP1a for controls to predict mean and sd where mdian, IQR, range available
```{r}
# Step 3 run a loop for all papers for a specific immune marker (do for controls first)
# Initial part of step 2 is the same - data wrangling to subset immune marker MIP1a
library(readxl)
library(data.table)
library(estmeansd)
library (dplyr)
# Create a dataframe with some subsetted data from FTD meta-analysis
results <-read_excel("/Users/sb930/Documents/PhD/MND_FTD_Metaanalysis/FTD_IF_review.xlsx", sheet = 10)
# sheet 10 is final sheet with Yusuf's results. Use mine for now
results
results2 <- transpose(results)
# transpose then add back in row and column headers
data_rownames = rownames(results)
data_colnames = colnames(results)
data_t <- transpose(results)
rownames(data_t) <- data_colnames
colnames(data_t) <- data_rownames
colnames(data_t) <- data_t[1,]
data_t <- data_t[-1,]
data_t <- data.frame(data_t)
# subset the dataframe to variables of interest
# for each immune marker, choose the appropriate rows - can hover over R to get the column number when viewing
data_t_rownames = rownames(data_t)
MIP1a_df2_con <- data_t %>%
select(n_con, med_MIP1a_con, l_iqr_MIP1a_con, u_iqr_MIP1a_con, l_range_MIP1a_con, u_range_MIP1a_con)
MIP1a_df2_ftd <- data_t %>%
select(n_ftd, med_MIP1a_ftd, l_iqr_MIP1a_ftd, u_iqr_MIP1a_ftd, l_range_MIP1a_ftd, u_range_MIP1a_ftd)
# Alternative way of subsetting columns manually rather than using dplyr
# MIP1a_df2_con <- data_t[c(10,346,347,348,349,350)]
# MIP1a_df2_ftd <- data_t[c(29,353,354,355,356,357)]
#add row header as a column
MIP1a_df2_con$studyid = c(data_t_rownames)
MIP1a_df2_ftd$studyid = c(data_t_rownames)
```
```{r}
# now loop through the incomplete cases for controls
columns <- c("mean","sd","study.id","n_con")
MIP1a_df4_incompletes1_con <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes1_con) <- columns
MIP1a_df4_incompletes2_con <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes2_con) <- columns
MIP1a_df4_incompletes3_con <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes3_con) <- columns
MIP1a_df4_incompletes_con <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes_con) <- columns
# select median and IQR columns then remove range columns to prevent estmeansd errors
MIP1a_df3_incompletes1_con <- subset(MIP1a_df2_con, is.na(l_range_MIP1a_con) & is.na(u_range_MIP1a_con) & !is.na(med_MIP1a_con) & !is.na(l_iqr_MIP1a_con) & !is.na(u_iqr_MIP1a_con))
MIP1a_df3_incompletes1_con <- subset (MIP1a_df3_incompletes1_con, select = -c(l_range_MIP1a_con, u_range_MIP1a_con))
# select median, IQR and range columns
MIP1a_df3_incompletes2_con <- subset(MIP1a_df2_con, !is.na(l_range_MIP1a_con) & !is.na(u_range_MIP1a_con) & !is.na(med_MIP1a_con) & !is.na(l_iqr_MIP1a_con) & !is.na(u_iqr_MIP1a_con))
# MIP1a_df3_completes_con <- subset(MIP1a_df2_con, complete.cases(MIP1a_df2_con[, c("l_range_MIP1a_con", "l_iqr_MIP1a_con", "med_MIP1a_con", "u_iqr_MIP1a_con", "u_range_MIP1a_con")]))
# select median and range columns then remove IQR columns to prevent estmeansd errors
MIP1a_df3_incompletes3_con <- subset(MIP1a_df2_con, !is.na(l_range_MIP1a_con) & !is.na(u_range_MIP1a_con) & !is.na(med_MIP1a_con) & is.na(l_iqr_MIP1a_con) & is.na(u_iqr_MIP1a_con))
MIP1a_df3_incompletes3_con <- subset (MIP1a_df3_incompletes3_con, select = -c(l_iqr_MIP1a_con, u_iqr_MIP1a_con))
# first loop for median and IQR
for (i in 1:nrow(MIP1a_df3_incompletes1_con)) {
if (nrow(MIP1a_df3_incompletes1_con) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
#for (i in 1:nrow(MIP1a_df3_incompletes1_con)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes1_con[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(q1.val = as.numeric(row$l_iqr_MIP1a_con), med.val = as.numeric(row$med_MIP1a_con), q3.val = as.numeric(row$u_iqr_MIP1a_con), n = as.numeric(row$n_con))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_con <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes1_con <- rbind(MIP1a_df4_incompletes1_con, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_con = row$n_con))
}
}
#}
print(MIP1a_df4_incompletes1_con)
# second loop for median, IQR and range
for (i in 1:nrow(MIP1a_df3_incompletes2_con)) {
if (nrow(MIP1a_df3_incompletes2_con) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
#for (i in 1:nrow(MIP1a_df3_incompletes2_con)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes2_con[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(min.val = as.numeric(row$l_range_MIP1a_con), q1.val = as.numeric(row$l_iqr_MIP1a_con), med.val = as.numeric(row$med_MIP1a_con), q3.val = as.numeric(row$u_iqr_MIP1a_con), max.val = as.numeric(row$u_range_MIP1a_con), n = as.numeric(row$n_con))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_con <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes2_con <- rbind(MIP1a_df4_incompletes2_con, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_con = row$n_con))
}
}
print(MIP1a_df4_incompletes2_con)
# third loop for median and range
for (i in 1:nrow(MIP1a_df3_incompletes3_con)) {
if (nrow(MIP1a_df3_incompletes3_con) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
# for (i in 1:nrow(MIP1a_df3_incompletes3_con)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes3_con[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(min.val = as.numeric(row$l_range_MIP1a_con), med.val = as.numeric(row$med_MIP1a_con), max.val = as.numeric(row$u_range_MIP1a_con), n = as.numeric(row$n_con))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_con <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes3_con <- rbind(MIP1a_df4_incompletes3_con, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_con = row$n_con))
}
}
print(MIP1a_df4_incompletes3_con)
# Bind the rows of the three tables together
MIP1a_df4_incompletes_con <- rbind(MIP1a_df4_incompletes1_con, MIP1a_df4_incompletes2_con, MIP1a_df4_incompletes3_con)
for (i in 1:nrow(MIP1a_df4_incompletes_con)) {
if (nrow(MIP1a_df4_incompletes_con) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
MIP1a_df4_incompletes_con$sd <- format(as.numeric(MIP1a_df4_incompletes_con$sd), scientific = FALSE)
}
}
print(MIP1a_df4_incompletes_con)
```
```{r}
# Step 3 final part a - create combined dataframe of estimated values
# Combine the data frames
# MIP1a_df4_all_con <- rbind(MIP1a_df4_completes_con, MIP1a_df4_incompletes_con)
# Rename dataframe for further processes
MIP1a_df4_all_con <- MIP1a_df4_incompletes_con
# Order the data frame by the "study.id" column
# for (i in 1:nrow(MIP1a_df4_all_con)) {
# if (nrow(MIP1a_df4_all_con) == 0) {
# # If the subset command returned no values, skip the rest of the code chunk
# next
# } else {
# MIP1a_df4_all_con <- MIP1a_df4_all_con[order(MIP1a_df4_all_con$study.id),]
# }
# }
# Order the data frame by the "study.id" column redone as a if x>0 statement
if (nrow(MIP1a_df4_all_con) > 0) {
MIP1a_df4_all_con <- MIP1a_df4_all_con[order(MIP1a_df4_all_con$study.id),]
}
```
```{r}
# Step 3 final part b - merge estimated values with extracted values
# Subset data_t to include only rows where "mean_MIP1a_con" and "SD_MIP1a_con" have a value
data_t_MIP1a_con <- data_t[!is.na(data_t$mean_MIP1a_con) & !is.na(data_t$SD_MIP1a_con),]
# Extract only the "mean_MIP1a_con" and "SD_MIP1a_con" columns
data_t_MIP1a_con <- data_t_MIP1a_con[, c("mean_MIP1a_con", "SD_MIP1a_con", "n_con")]
# Extract the row names from data_t
row_names <- rownames(data_t_MIP1a_con)
# Create a "study.id" column in data_t_MIP1a_con using the row names
data_t_MIP1a_con$study.id <- row_names
# Rename the "mean" column to "mean_MIP1a_con"
names(MIP1a_df4_all_con)[names(MIP1a_df4_all_con) == "mean"] <- "mean_MIP1a_con"
# Rename the "sd" column to "SD_MIP1a_con"
names(MIP1a_df4_all_con)[names(MIP1a_df4_all_con) == "sd"] <- "SD_MIP1a_con"
# Add column "value" to both tables so source of mean and sd is clear
# Add a "value" column to the MIP1a_df4_all_con data frame with estimated
if (nrow(MIP1a_df4_all_con) > 0) {
MIP1a_df4_all_con$value <- "estimated"
}
# Add a "value" column to the data_t_MIP1a_con data frame with extracted
if (nrow(data_t_MIP1a_con) > 0) {
data_t_MIP1a_con$value <- "extracted"
}
# Combine data_t_MIP1a_con with MIP1a_df4_all_con
MIP1a_combined_con <- rbind(data_t_MIP1a_con, MIP1a_df4_all_con)
# Reorder the rows based on the "studyid" column
MIP1a_combined_con <- MIP1a_combined_con[order(MIP1a_combined_con$study.id),]
# For rows with the same "studyid" value, use the values from data_t_MIP1a_con
MIP1a_combined_con <- unique(MIP1a_combined_con, by = "studyid", fromLast = TRUE)
```
# Step 2 add repeat for ftd
```{r}
# now loop through the incomplete cases for ftd patients
columns <- c("mean","sd","study.id","n_ftd")
MIP1a_df4_incompletes1_ftd <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes1_ftd) <- columns
MIP1a_df4_incompletes2_ftd <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes2_ftd) <- columns
MIP1a_df4_incompletes3_ftd <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes3_ftd) <- columns
MIP1a_df4_incompletes_ftd <- (matrix(nrow = 0, ncol = length(columns)))
colnames(MIP1a_df4_incompletes_ftd) <- columns
# select median and IQR columns then remove range columns to prevent estmeansd errors
MIP1a_df3_incompletes1_ftd <- subset(MIP1a_df2_ftd, is.na(l_range_MIP1a_ftd) & is.na(u_range_MIP1a_ftd) & !is.na(med_MIP1a_ftd) & !is.na(l_iqr_MIP1a_ftd) & !is.na(u_iqr_MIP1a_ftd))
MIP1a_df3_incompletes1_ftd <- subset (MIP1a_df3_incompletes1_ftd, select = -c(l_range_MIP1a_ftd, u_range_MIP1a_ftd))
# select median, IQR and range columns
MIP1a_df3_incompletes2_ftd <- subset(MIP1a_df2_ftd, !is.na(l_range_MIP1a_ftd) & !is.na(u_range_MIP1a_ftd) & !is.na(med_MIP1a_ftd) & !is.na(l_iqr_MIP1a_ftd) & !is.na(u_iqr_MIP1a_ftd))
# select median and range columns then remove IQR columns to prevent estmeansd errors
MIP1a_df3_incompletes3_ftd <- subset(MIP1a_df2_ftd, !is.na(l_range_MIP1a_ftd) & !is.na(u_range_MIP1a_ftd) & !is.na(med_MIP1a_ftd) & is.na(l_iqr_MIP1a_ftd) & is.na(u_iqr_MIP1a_ftd))
MIP1a_df3_incompletes3_ftd <- subset (MIP1a_df3_incompletes3_ftd, select = -c(l_iqr_MIP1a_ftd, u_iqr_MIP1a_ftd))
# first loop for median and IQR
for (i in 1:nrow(MIP1a_df3_incompletes1_ftd)) {
if (nrow(MIP1a_df3_incompletes1_ftd) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
#for (i in 1:nrow(MIP1a_df3_incompletes1_ftd)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes1_ftd[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(q1.val = as.numeric(row$l_iqr_MIP1a_ftd), med.val = as.numeric(row$med_MIP1a_ftd), q3.val = as.numeric(row$u_iqr_MIP1a_ftd), n = as.numeric(row$n_ftd))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_ftd <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes1_ftd <- rbind(MIP1a_df4_incompletes1_ftd, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_ftd = row$n_ftd))
}
}
#}
print(MIP1a_df4_incompletes1_ftd)
# second loop for median, IQR and range
for (i in 1:nrow(MIP1a_df3_incompletes2_ftd)) {
if (nrow(MIP1a_df3_incompletes2_ftd) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
#for (i in 1:nrow(MIP1a_df3_incompletes2_ftd)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes2_ftd[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(min.val = as.numeric(row$l_range_MIP1a_ftd), q1.val = as.numeric(row$l_iqr_MIP1a_ftd), med.val = as.numeric(row$med_MIP1a_ftd), q3.val = as.numeric(row$u_iqr_MIP1a_ftd), max.val = as.numeric(row$u_range_MIP1a_ftd), n = as.numeric(row$n_ftd))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_ftd <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes2_ftd <- rbind(MIP1a_df4_incompletes2_ftd, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_ftd = row$n_ftd))
}
}
print(MIP1a_df4_incompletes2_ftd)
# third loop for median and range
for (i in 1:nrow(MIP1a_df3_incompletes3_ftd)) {
if (nrow(MIP1a_df3_incompletes3_ftd) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
# for (i in 1:nrow(MIP1a_df3_incompletes3_ftd)) {
print(i) # Debug statement
# Extract the current row
row <- MIP1a_df3_incompletes3_ftd[i, ]
# Compute the mean and standard deviation using the qe.mean.sd() function
meansd <- qe.mean.sd(min.val = as.numeric(row$l_range_MIP1a_ftd), med.val = as.numeric(row$med_MIP1a_ftd), max.val = as.numeric(row$u_range_MIP1a_ftd), n = as.numeric(row$n_ftd))
# # Store the results in the results data frame
# MIP1a_df4_incompletes_ftd <- cbind(data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid))
# Store the results in the results data frame
MIP1a_df4_incompletes3_ftd <- rbind(MIP1a_df4_incompletes3_ftd, data.frame(mean = meansd$est.mean, sd = meansd$est.sd, study.id = row$studyid, n_ftd = row$n_ftd))
}
}
print(MIP1a_df4_incompletes3_ftd)
# Bind the rows of the three tables together
MIP1a_df4_incompletes_ftd <- rbind(MIP1a_df4_incompletes1_ftd, MIP1a_df4_incompletes2_ftd, MIP1a_df4_incompletes3_ftd)
for (i in 1:nrow(MIP1a_df4_incompletes_ftd)) {
if (nrow(MIP1a_df4_incompletes_ftd) == 0) {
# If the subset command returned no values, skip the rest of the code chunk
next
} else {
MIP1a_df4_incompletes_ftd$sd <- format(as.numeric(MIP1a_df4_incompletes_ftd$sd), scientific = FALSE)
}
}
print(MIP1a_df4_incompletes_ftd)
```
```{r}
# Step 3 final part a - create combined dataframe of estimated values
# Combine the data frames
# MIP1a_df4_all_ftd <- rbind(MIP1a_df4_completes_ftd, MIP1a_df4_incompletes_ftd)
# rename incompletes dataframe for further processing
MIP1a_df4_all_ftd <- MIP1a_df4_incompletes_ftd
# Order the data frame by the "study.id" column
# for (i in 1:nrow(MIP1a_df4_all_ftd)) {
# if (nrow(MIP1a_df4_all_ftd) == 0) {
# # If the subset command returned no values, skip the rest of the code chunk
# next
# } else {
# MIP1a_df4_all_ftd <- MIP1a_df4_all_ftd[order(MIP1a_df4_all_ftd$study.id),]
# }
# }
# Order the data frame by the "study.id" column redone as a if x>0 statement
if (nrow(MIP1a_df4_all_ftd) > 0) {
MIP1a_df4_all_ftd <- MIP1a_df4_all_ftd[order(MIP1a_df4_all_ftd$study.id),]
}
```
```{r}
# Step 3 final part b - merge estimated values with extracted values
# Subset data_t to include only rows where "mean_MIP1a_ftd" and "SD_MIP1a_ftd" have a value
data_t_MIP1a_ftd <- data_t[!is.na(data_t$mean_MIP1a_ftd) & !is.na(data_t$SD_MIP1a_ftd),]
# Extract only the "mean_MIP1a_ftd" and "SD_MIP1a_ftd" columns
data_t_MIP1a_ftd <- data_t_MIP1a_ftd[, c("mean_MIP1a_ftd", "SD_MIP1a_ftd", "n_ftd")]
# Extract the row names from data_t
row_names <- rownames(data_t_MIP1a_ftd)
# Create a "study.id" column in data_t_MIP1a_ftd using the row names
data_t_MIP1a_ftd$study.id <- row_names
# Rename the "mean" column to "mean_MIP1a_ftd"
names(MIP1a_df4_all_ftd)[names(MIP1a_df4_all_ftd) == "mean"] <- "mean_MIP1a_ftd"
# Rename the "sd" column to "SD_MIP1a_ftd"
names(MIP1a_df4_all_ftd)[names(MIP1a_df4_all_ftd) == "sd"] <- "SD_MIP1a_ftd"
# Add column "value" to both tables so source of mean and sd is clear
# Add a "value" column to the MIP1a_df4_all_con data frame with estimated
if (nrow(MIP1a_df4_all_ftd) > 0) {
MIP1a_df4_all_ftd$value <- "estimated"
}
# Add a "value" column to the data_t_MIP1a_con data frame with extracted
if (nrow(data_t_MIP1a_ftd) > 0) {
data_t_MIP1a_ftd$value <- "extracted"
}
# Combine data_t_MIP1a_ftd with MIP1a_df4_all_ftd
MIP1a_combined_ftd <- rbind(data_t_MIP1a_ftd, MIP1a_df4_all_ftd)
# Reorder the rows based on the "studyid" column
MIP1a_combined_ftd <- MIP1a_combined_ftd[order(MIP1a_combined_ftd$study.id),]
# For rows with the same "studyid" value, use the values from data_t_MIP1a_ftd
MIP1a_combined_ftd <- unique(MIP1a_combined_ftd, by = "studyid", fromLast = TRUE)
```
# Step 3 add effect size calculations
```{r}
# load libraries
library(metafor)
library(dplyr)
library(robumeta)
library(data.table)
```
```{r}
# combine control and FTD data frames
MIP1a_combined <- full_join(MIP1a_combined_con, MIP1a_combined_ftd, by="study.id")
# make data frame columns except study id numeric
MIP1a_combined <- mutate_at(MIP1a_combined, vars(contains("_")), function(x) as.numeric(as.character(x)))
```
```{r}
# use escalc to calculate effect sizes
# change name of immune marker for each of the terms
df2 <- escalc(data=MIP1a_combined, measure="SMD", m2i=mean_MIP1a_con, m1i=mean_MIP1a_ftd,
sd2i=SD_MIP1a_con, sd1i=SD_MIP1a_ftd,
n2i=n_con, n1i=n_ftd,slab=paste("ID", study.id))
```
```{r}
#random effects model
res <- rma (yi, vi, method="REML", data=df2)
```
```{r}
# construct forest plot
forest(res)
```
```{r}
# construct funnel plot
funnel(res)
```
```{r}
# heterogeneity measures
res.CA <- rma(yi, vi, method="HE", data=df2)
res.CA
```