[R-sig-Geo] spml and logLik, help!

Ariel Ortiz-Bobea aortizbobea at arec.umd.edu
Sun Nov 4 08:20:11 CET 2012


Hello,

I would greatly appreciate some help on this. Any tips are more than
welcome.

I'm trying to obtain the log-likelihood at the optimum parameter values
using spml() from the splm package. The created fit object contains a slot
called "logLik" which is supposed to have that value but I find it to be
empty. However, when I allow all the verbiage to be printed (quiet=F), the
function prints all the MLE iterations with the values of the likelihood
function each time... but somehow the last value is not stored.

Is this a bug in the function? I'm looking for a way to to obtain the logLik
value automatically and any ideas would be appreciated (even on how to
capture the last line of the returned text if need be).

Thanks in advance for the help!

Ariel


#### Reproducible code below ########

# Load pacakge
    library(splm)
	
# Generate spatial object
    temp <- expand.grid(lon=1:10, lat=1:10 )
    temp$id        <- 1:dim(temp)[1]    
    rownames(temp) <- 1:dim(temp)[1]
    n        <- dim(temp)[1]
    mylist         <- vector('list', n)
    for(i in 1:n) { 
		mylist[[i]] = Polygons(list(Polygon(
   		cbind( c(temp[i,"lon"]-0.5, temp[i,"lon"]-0.5, temp[i,"lon"]+0.5,
temp[i,"lon"]+0.5, temp[i,"lon"]-0.5), 
	
c(temp[i,"lat"]-0.5,temp[i,"lat"]+0.5,temp[i,"lat"]+0.5,temp[i,"lat"]-0.5,temp[i,"lat"]-0.5)))),i) 
    } 
    map      <- SpatialPolygons(mylist, 1:n) 
    map          <- SpatialPolygonsDataFrame(map, temp) 
    plot(map)
    rm(temp,i,mylist)   

# Generate weight matrix/neighbor lists
   dmatrix <- spDists(map)
   coords  <- coordinates(map)  
   nb<- poly2nb(map, queen=TRUE) # contiguity queen neighbors
   plot(map, lwd=0.1, col="cornsilk")
   plot(nb , coordinates(map), add=T, col="blue") 
   dlist <- nbdists(nb, coords) 
   idlist  <- lapply(dlist, function(x) 1/x) # inverse distance
   nbw <- nb2listw(nb, glist=idlist , style="W") # inverse distance
    
    
# Generate fake data
    years <- 1993:1996
    dataset  <- data.frame( id  = as.numeric(paste(map at data$id)),
year=rep(years, each=n) )
    dataset$X <-  rnorm(length(years)*n, mean=10, sd=5) 
    dataset$a  <- rep(rnorm(n,mean=50,sd=sqrt(30)), times=length(years)) 	
    dataset$y  <- dataset$X * 1 + dataset$a + rnorm(4*20, mean=0, sd=2)

# Run model 
	fit   <- spml(formula = y ~ X , data = dataset, model="within",
effect=c("individual"), index = c("id","year"), listw = nbw, lag = FALSE,
spatial.error = "b", quiet=F)        

# Check results
    summary(fit)
    fit$logLik # nothing was stored there.



-----
Ariel Ortiz-Bobea
PhD Candidate in Agricultural & Resource Economics
University of Maryland - College Park
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/spml-and-logLik-help-tp7581581.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list