how to obtain AIC and BIC for spatial error panel data model and spatial autoregressive combined panel data model in R? i try the following code but give me this error:
Error in names(aic) <- "AIC" : 'names' attribute [1] must be the same length as the vector [0]
AICsplm = function(object, k=2, criterion=c("AIC", "BIC")){
sp = summary(object)
l = sp$logLik
np = length(coef(sp))
N = nrow(sp$model)
if (sp$effects=="sptpfe") {
n = length(sp$res.eff[[1]]$res.sfe)
T = length(sp$res.eff[[1]]$res.tfe)
np = np+n+T
}
if (sp$effects=="spfe") {
n = length(sp$res.eff[[1]]$res.sfe)
np = np+n+1
}
if (sp$effects=="tpfe") {
T = length(sp$res.eff[[1]]$res.tfe)
np = np+T+1
}
if (criterion=="AIC"){
aic = -2*l+k*np
names(aic) = "AIC"
return(aic)
}
if (criterion=="BIC"){
bic = -2*l+log(N)*np
names(bic) = "BIC"
return(bic)
}
}