0
votes

I am trying to apply the Cochrane Orcutt procedure to my data with an AR(1) process. When I use the cochrane.orcutt function from the orcutt package, the following error is returned:

Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases

I first made sure that all of the data set was free of incomplete cases.

library(orcutt) foo <- na.omit(foo) model <- lm(1-ef ~ as.factor(dtype) + as.factor(p) + inc + ed + marg + as.factor(period) + as.factor(id), data = foo) cochrane.orcutt(model)

The line of code cochrane.orcutt(model) produces the error.

Here's what I've tried so far:

1) To further problem shoot, I started with the first independent variable and added them one by one to see where the code breaks down. They all work alone and in combination except for "as.factor(id)", which seems to be the offending variable.

2) I thought perhaps there was something about the string nature of the id variable, so I created a factor variable with numbers that represent each individual (called id2 in the data below). When I don't convert the variable "id2" to a factor variable and run it as a numeric variable, the code works without problem in both the full model and the bivariate model.

When I regress "1-ef" on the "as.factor(id2)" variable in a bivariate regression and then perform the Cochrane Orcutt procedure, R stalls while on the procedure.

3) I then thought perhaps unused levels were causing the problem so I tried: foo$id <- droplevels(foo$id) and also tried converting the id variable to a character variable. Neither approach solved the problem.

Summary from my attempts to solve:

From what I can tell, there is something about by a factor "id" variable that is causing an error with the cochrane.orcutt function. Either R stalls or it produces the error saying that there are no non-NA cases (which I had made sure wasn't the case with the na.omit.

In all of the above cases, R has no problem running the regression, just the Cochrane Orcutt estimation.

Any ideas? Thank you for your help!

Here is a subset of the data that demonstrates the error:

foo <- structure(list(ef = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.9232, 1, 1, 1, 1, 1, 1, 0.68, 0.847222222222222), dtype = c("5", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "5", "5"), p = c("0", "1", "1", "1", "0", "0", "1", "1", "1", "0", "1", "1", "1", "1", "1", "1", "1", "0", "0"), inc = c(65327L, 38517L, 38888L, 39147L, 62022L, 63938L, 74663L, 37203L, 36548L, 57582L, 50425L, 50880L, 50372L, 51780L, 54763L, 54341L, 53988L, 36379L, 37290L), ed = c(0.400399151, 0.140407741, 0.158387284488, 0.167404993465, 0.278612155, 0.307604827205, 0.459637019, 0.174936986, 0.165744029552, 0.379544685, 0.23472389, 0.301241844, 0.296150413967, 0.308115565224, 0.229996365, 0.244502536866, 0.251595155313, 0.241661234658, 0.257054165719), marg = c(-27.04, 100, 48.14, 100, -28.98, -38.96, 39.94, 100, 100, -1.62, 31.7, 22.86, 8.72, 19.5, 31.94, 22.78, 40.36, -59.26, -50.7), period = c("112", "112", "113", "114", "112", "113", "112", "112", "113", "112", "112", "112", "113", "114", "112", "113", "114", "113", "114"), id = c("A000022", "A000055", "A000055", "A000055", "A000210", "A000210", "A000358", "A000361", "A000361", "A000362", "A000365", "A000367", "A000367", "A000367", "A000369", "A000369", "A000369", "A000370", "A000370"), id2 = c(1, 2, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 8, 9, 9, 9, 10, 10)), .Names = c("ef", "dtype", "p", "inc", "ed", "marg", "period", "id", "id2"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L), na.action = structure(12L, .Names = "12", class = "omit"), class = "data.frame")

1

1 Answers

0
votes

coef(model) has some NA values indicating over-parameterization which lm can handle but cochrane.orcutt cannot.

As you discovered already you will need to remove some predictors.