0

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)   
 }  
}
kangaroo_cliff
  • 6,067
  • 3
  • 29
  • 42
  • You might want to use a small example. – kangaroo_cliff Dec 18 '20 at 00:41
  • What libraries do you use for this? Do you have a small subset of your data to provide to test your code? Please read this: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – John Polo Dec 18 '20 at 17:22

0 Answers0