[R-sig-Geo] AIC/R^2 in splm

Tobias Rüttenauer ruettenauer at sowi.uni-kl.de
Fri Feb 19 19:37:05 CET 2016


> -----Ursprüngliche Nachricht-----
> Von: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] Im Auftrag von
> Maryia Bakhtsiyarava
> Gesendet: Montag, 15. Februar 2016 03:59
> An: R-sig-geo Mailing List <r-sig-geo at r-project.org>
> Betreff: [R-sig-Geo] AIC/R^2 in splm
> 
> Dear list members,
> 
> I am estimating a spatial lag model with time-period fixed effects using
> package splm. I would like to obtain some goodness-of-fit measures for my
> models but I cannot figure out how to do it. The traditional AIC
extraction
> function doesn't work for a an object of class "splm".

Most extract functions do not support "splm" class. You can try to access
the functions for objects of a similar class and rearrange it for splm.

> 
> The only thing I can extract is the log likelihood, using which in theory
I can
> calculate AIC, but even in that case I am not sure about the degrees of
> freedom to use in the calculation (do I count time dummies, lag and
intercept
> as parameters?). I tried df.residual(model) but I got NULL.

If you use the same data for different models (having the same number of
time dummies), it does not matter if you include or exclude these dummies. 

> 
> Is there another way to obtain AIC and/or R^2? I am sure people
> encountered this problem before, so if you have any advice on how to
obtain
> model statistics, I would greatly appreciate it.

If you receive the log Likelihood in your spml model output (
summary(fesar.mod)$logLik ), you can use the following function to calculate
the AIC (it includes the spatial lag as one parameter and the spatial error
as one parameter):

#### AIC function for spml ####

godf.spml<-function(object, k=2, criterion=c("AIC", "BIC"),  ...){
  s<-summary(object)
  l<-s$logLik[1,1]
  np<- length(coef(s))
  N<- nrow(s$model)
  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"
    if(k!=2){
      warning("parameter <k> not used for BIC")
    }
    return(bic)
  }
}

Example:

require(splm)
fesar.mod<-spml(formula= y~x1+x2, data=data.pd, ...)
godf.spml(fesar.mod, criterion="AIC")


If your spml model output does not contain a value for logLik, see here how
to fix this:
http://r-sig-geo.2731867.n2.nabble.com/spml-and-logLik-help-td7581581.html

There is an R squared reported in the model output:

summary(fesar.mod)$rsqr

Unfortunately it is not documented what kind of (Pseudo)-R squared this is
(to my knowledge).

Best
Tobi

> 
> Thank you,
> Maryia
> --
> Maryia Bakhtsiyarava
> Graduate student
> Department of Geography, Environment and Society University of
> Minnesota, Twin Cities
> 
> Research Assistant
> TerraPop Project
> Minnesota Population Center
> 
> 414 Social Sciences, 267 19th Ave S, Minneapolis, MN 55455
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list