Error in abs(c(deltas, deltas2)) : non-numeric argument to mathematical function - RStudio

44 Views Asked by At

I'm trying to use the BugsNet package for NMA with contrast date. However, when performing the random effects model operation, the message above appears.

data set used

I'm using the code below:

library(BUGSnet)
osdataset1 <- read_excel("C:/Users/Usuario/Desktop/doacnma.xlsx", na = "NA")
contrast_prep <- data.prep(arm.data = osdataset1, varname.t = "treatment", varname.s = "study")
random_effects_model <- nma.model.contrast(
    data=contrast_prep, differences="lor", 
    se.diffs = "se", reference = "1", effects = "random",
    scale = "Log-odds ratio")
1

There are 1 best solutions below

0
r2evans On

I'm not a BUGS user, but I suspect that your problem is that they are not numbers (as the error and Roland's comment states). Your numbers use comma as a decimal point, so we need to fix that.

Try:

osdataset1[,c("lor", "se")] <- lapply(
  osdataset1[,c("lor", "se")],
  function(val) suppressWarnings(as.numeric(sub(",", ".", val))))

and then repeat your code.

The sub replaces the first , with a ., then we convert it to numbers with as.numeric. Since as.numeric("NA") is going to emit a warning in R, we suppressWarnings for that.