library(orcutt)
df = data.frame(t(data.frame(
c(20.96, 127.3),
c(21.40, 130.0),
c(21.96, 132.7),
c(21.52, 129.4),
c(22.39, 135.0),
c(22.76, 137.1),
c(23.48, 141.2),
c(23.66, 142.8),
c(24.10, 145.5),
c(24.01, 145.3),
c(24.54, 148.3),
c(24.30, 146.4),
c(25.00, 150.2),
c(25.64, 153.1),
c(26.36, 157.3),
c(26.98, 160.7),
c(27.52, 164.2),
c(27.78, 165.6),
c(28.24, 168.7),
c(28.78, 171.7))))
rownames(df) <- NULL
colnames(df) <- c("y", "x")
my_lm = lm(y ~ x, data=df)
coch = cochrane.orcutt(my_lm)
The R-implementation is kind of…silly.
The above works- converges at 318 iterations- the transformed DW is 1.72, yet the rho is
.95882. After 318 iteartions, this will also report a rho of .95882 (which sugguests SEVERE
autocorrelation- nothing close to 1.72.
They also note on p492:
“… If the process does not terminate after one or two iterations, a different procedure
should be employed.”
This differs from the logic found elsewhere, and the method presented in R where, in the simple
example in the prototype, the procedure runs for 318 iterations. This is why the default
maximum iteratoins are 3, and should be left as such.
Also, the prototype and ‘correct answers’ are based on the example presented in Kunter et. al on
p492-4 (including dataset).
val alsmBlaisdellCo = drmParallelize( dense(
(20.96, 127.3),
(21.40, 130.0),
(21.96, 132.7),
(21.52, 129.4),
(22.39, 135.0),
(22.76, 137.1),
(23.48, 141.2),
(23.66, 142.8),
(24.10, 145.5),
(24.01, 145.3),
(24.54, 148.3),
(24.30, 146.4),
(25.00, 150.2),
(25.64, 153.1),
(26.36, 157.3),
(26.98, 160.7),
(27.52, 164.2),
(27.78, 165.6),
(28.24, 168.7),
(28.78, 171.7) ))
val drmY = alsmBlaisdellCo(::, 0 until 1)
val drmX = alsmBlaisdellCo(::, 1 until 2)
var coModel = new CochraneOrcutt[Int]().fit(drmX, drmY , ('iterations -> 2))
println(coModel.rhos)
println(coModel.summary)