[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
> 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
> 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
> 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"),  ...){
  np<- length(coef(s))
  N<- nrow(s$model)
    aic<- -2*l+k*np
    bic<- -2*l+log(N)*np
      warning("parameter <k> not used for BIC")


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:

There is an R squared reported in the model output:


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


> 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