1

I'm using xts time series, originally converted from type ts, in a logstic regression, but I get

Error in `*.default`(x[good, , drop = FALSE], w) : non-conformable arrays

Example:

success <- as.xts(ts(sample(0:10, 100, replace=T), start=1970, fr=12))
failure <- 10-success
x <- as.xts(ts(rnorm(100), start=1970, fr=12))
glm(cbind(success, failure) ~ x, family=binomial)

However, if the series are converted to class ts or just a vector than there is no error:

glm(cbind(as.ts(success), as.ts(failure)) ~ as.ts(x), family=binomial)
glm(cbind(as.vector(success), as.vector(failure)) ~ as.vector(x), family=binomial)

Is there a way to avoid the error while working with the original xts series?

Abiel
  • 5,251
  • 9
  • 54
  • 74

1 Answers1

0

The problem is caused by the default of drop=FALSE in [.xts. You can avoid this by specifying the data argument, which will be converted to a data.frame.

glm(cbind(success, failure) ~ x, data=merge(success,failure,x), family=binomial)
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418