1

Using for self-defined variables, I am receiving the following error when trying to run odds ratio analysis.

dat1 <- escalc(measure="OR", ai=a, bi=b, ci=c, di=d, data=dat.turnover)
warnings(dat1)

Warning messages: 1: In Ops.factor(ai, bi) : ‘+’ not meaningful for factors Error in cat(list(...), file, sep, fill, labels, append) : argument 2 (type 'list') cannot be handled by 'cat'

All the data I am using for a, b, c, and d are numeric.

rawr
  • 20,481
  • 4
  • 44
  • 78
Bear Racha
  • 11
  • 1
  • 1
  • 2

1 Answers1

3

Without having access to your data, the best I can say is that any attempt to sum factor variables (try checking their str() to ensure R knows they are numeric and hasn't factored them) will cause NA values to be imputed, or an exception. The only time I have seen this Ops.factor() error is when the data are factors and not numeric.

That said, to ensure numeric calculations (being mindful of what divibisan mentioned in the comments below) I would try:

dat.turnover$a <- as.numeric(as.character(dat.turnover$a))
dat.turnover$b <- as.numeric(as.character(dat.turnover$b))
dat.turnover$c <- as.numeric(as.character(dat.turnover$c))
dat.turnover$d <- as.numeric(as.character(dat.turnover$d))

dat1 <- escalc(measure="OR", ai=a, bi=b, ci=c, di=d, data=dat.turnover)
Phantom Photon
  • 768
  • 2
  • 10
  • 20
  • 3
    This could be dangerous: calling `as.numeric` on a factor returns the numeric code used to encode the values as a factor, not the value itself. So it's generally safer to do `as.numeric(as.character(...))` which will get the factors value and then try to convert that to a numeric – divibisan Apr 24 '19 at 22:10