daniel1noble / orchaRd

Extending the Orchard Plot for Meta-analysis
https://daniel1noble.github.io/orchaRd/
11 stars 6 forks source link

missing values for the intercept model may be an issue #20

Closed itchyshin closed 1 year ago

itchyshin commented 1 year ago

This issue may be due to the intercept model, not meta-regression models - @daniel1noble - we can probably look at this next time together?

> modelxs <- rma.mv(yi = logX_SET,
+                   V = var_X_SET,
+                   random = ~ 1 | Study_ID,
+                   data = dat,
+                   method = "REML")
Warning message:
Rows with NAs omitted from model fitting. 
> #summary(modelxs)
> orchard_plot(modelxs, mod = "1", data = dat, group = "Study_ID", 
+              xlab = "log risk ratio")
Error in data.frame(yi, vi, moderator, stdy, type) : 
  arguments imply differing number of rows: 46, 1, 50

We have the same issue for mod_results

> modelws <- rma.mv(yi = logW_SET,
+                   V = var_W_SET,
+                   random = ~ 1 | Study_ID,
+                   data = dat,
+                   method = "REML")
Warning message:
Rows with NAs omitted from model fitting. 
> #summary(modelws)
> m2 <- mod_results(modelws, group = "Study_ID", data = dat)
Error in data.frame(yi, vi, moderator, stdy, type) : 
  arguments imply differing number of rows: 46, 1, 50

Gets fixed if you manually trim data

> dat_ws <- dat[complete.cases(dat$logW_SET), ]
> m2 <- mod_results(modelws, group = "Study_ID", data = dat_ws)
> p2 <- orchard_plot(m2, 
+              xlab = "log risk ratio  (singltons: SET)",
+              g = FALSE, k.pos = "left") + 
+   ylim(-1, 1)
itchyshin commented 1 year ago

A few more notes

submerge only works for mod results - make it work for metafor objects? Take out data arguments? group argument needs clarification when people use rma objects rather than rma.mv objects potentially it is good to be able to change the position of k (sample size) or not

itchyshin commented 1 year ago

The issue is one data set has several effect sizes and some have missing data - things start not to work. For example,

> mat <- submerge(m0, m1, m2, 
+          m3, m4,
+          m5, m6, mix = TRUE)
> # renaming
> mat$mod_table$name <- c("DET/SET LBR", 
+                         "signltons: DET", "signltons: SET",
+                         "twins: DET", "twins: SET",
+                         "no births: DET", "not births: SET"
+                         )
> 
> orchard_plot(mat, xlab = "Risk ratio",  g = FALSE)
Error in `$<-.data.frame`(`*tmp*`, "g", value = integer(0)) : 
  replacement has 0 rows, data has 7

If remove ones with missing data, it works

mat0 <- submerge(m0, m1,
                m3, 
                m5,  mix = TRUE)

orchard_plot(mat0, xlab = "Risk ratio",  g = FALSE)

Actually, this is the issue of not re-naming the moderator column in the data frame - so it can be fixed easily

daniel1noble commented 1 year ago

Seems like it’s a missing data issue. If you use complete.cases() to prevent missing data being dropped during model fitting does this error go away? This should be solved regardless, but maybe not. Now that Wolfgang has added back the data ’slot’ we can just do this data in the functions from now on and it should avoid missing data issues. Anyway, can chat about this in our next meeting

Dan

itchyshin commented 1 year ago

Thanks @daniel1noble - we will catch up soon. It may be good to use the trim data from the rma.mv/rma object. This may give a general solution for many missing data cases

daniel1noble commented 1 year ago

Yep, completely agree. We initially had it this way but had to pivot when Wolfgang dropped the data from the model object. Shouldn’t be too much work to re-implement. I think all these missing data issues will go away.

daniel1noble commented 1 year ago

@itchyshin Took a while but I've implemented the switch to data being drawn from model object again. Changes to #20 now live on dev branch. All checks passing, but it would be good we try this out with some more examples before merging with main