dmphillippo / multinma

Network meta-analysis of individual and aggregate data in Stan
https://dmphillippo.github.io/multinma
35 stars 16 forks source link

Replace NA values without tidyr #11

Closed ndunnewind closed 2 years ago

ndunnewind commented 2 years ago

Using tidyr::replace_na() on a matrix does not appear to work anymore in tidyr 1.2.0. This base R alternative should fix this.

For example, the first nma() call in the Plaque psoriasis HTA report example results in the error Stan does not support NA (in agd_arm_r) in data:

library(multinma)

pso_net <- set_agd_arm(hta_psoriasis, 
                       study = paste(studyc, year), 
                       trt = trtc, 
                       r = multi(r0 = sample_size - rowSums(cbind(PASI50, PASI75, PASI90), na.rm = TRUE), 
                                 PASI50, PASI75, PASI90,
                                 inclusive = FALSE, 
                                 type = "ordered"))

pso_fit_FE <- nma(pso_net, 
                  trt_effects = "fixed",
                  link = "probit",
                  prior_intercept = normal(scale = 100),
                  prior_trt = normal(scale = 10),
                  prior_aux = flat())
dmphillippo commented 2 years ago

Thanks @ndunnewind, that's excellent. I'll try to get this fix up to CRAN today.

I think this bug/change with tidyr::replace_na() should probably be raised as an issue with tidyr (https://github.com/tidyverse/tidyr/issues), do you agree?

ndunnewind commented 2 years ago

I don't think tidyr::replace_na() was ever intended to work on matrices. At least, not according to the documentation.