Skip to content
Prev 29189 / 29559 Next

Error in splm random effects ML model

Dear Roger,

This is incredibly helpful and much appreciated! I re-ran the model using the method = "BFGS" argument and I can confirm that it worked.?

Best regards,
Denys
On Thursday, February 16, 2023 at 03:49:45 AM EST, Roger Bivand <roger.bivand at nhh.no> wrote:

        
On Wed, 15 Feb 2023, Denys Dukhovnov wrote:

            
This is where the problem lies:

library(spam)
csrw <- as.spam(wgts)
n <- nrow(wgts)
I <- diag.spam(1, n, n)
lambda <- 0
B <-? I - lambda * csrw

is OK. If lambda is NaN:

lambda <- NaN
B <-? I - lambda * csrw
Error in .C64("aplsb1", SIGNATURE = c(SS$signature, SS$signature, 
"double",? :
? NAs in argument 7 and 'NAOK = FALSE' (dotCall64)

If lambda is Inf:

lambda <- Inf
B <-? I - lambda * csrw
Error in .C64("aplsb1", SIGNATURE = c(SS$signature, SS$signature, 
"double",? :
? NAs in argument 7 and 'NAOK = FALSE' (dotCall64)

and so on. The default method="nlminb" can be changed to "BFGS":
data = analysis.subset, listw = listw.wgts, effect = "individual", model = 
"random", lag = FALSE, spatial.error = "b", index = c("Group", "Year"), 
method="BFGS")
+ )
? ? user? system? elapsed
4191.258? 391.390 4597.724
[1] 76.62873

taking just over 75 minutes to complete
ML panel with , random effects, spatial error correlation

Call:
spreml(formula = formula, data = data, index = index, w = 
listw2mat(listw),
? ? w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl,
? ? method = "BFGS")

Residuals:
? ? ? Min.? 1st Qu.? ? Median? ? ? Mean? 3rd Qu.? ? ? Max.
-5.75e-03 -1.08e-03? 2.42e-05 -7.50e-06? 1.07e-03? 8.02e-03

Error variance parameters:
? ? Estimate Std. Error t-value Pr(>|t|)
phi 0.045798? ? ? ? NaN? ? NaN? ? ? NaN
rho 0.725055? ? ? ? NaN? ? NaN? ? ? NaN

Coefficients:
? ? ? ? ? ? ? Estimate Std. Error? t-value? Pr(>|t|)
(Intercept) 1.0284e-02 5.0441e-05 203.8892 < 2.2e-16 ***
I.score? ? 5.2369e-03 1.0438e-03? 5.0173 5.239e-07 ***
---
Signif. codes:? 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

The code involves inversion of the nxn matrix I - \lambda W in each call 
to the log likelihood function, hence the long run time. I've added the 
splm maintainer to CC in case this thread didn't yet reach him. I think 
that checking that lambda is finite and returning an infinite ll value if 
not may work, but the documentation of maxLik() and nlminb would need 
checking to see how to signal an invalid lambda.

Hope this clarifies,

Roger

PS. With traceback, it is as simple as setting debug(splm:::semREmod) and 
then setting more debug()s - reading the code also helps; patience is 
however essential.