[Splm-commits] r203 - in pkg: . R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 4 00:11:20 CET 2015
Author: the_sculler
Date: 2015-12-04 00:11:20 +0100 (Fri, 04 Dec 2015)
New Revision: 203
Modified:
pkg/ChangeLog
pkg/DESCRIPTION
pkg/R/print.summary.splm.R
pkg/R/spml.R
pkg/R/spreml.R
Log:
Harmonized and improved print.summary.splm. Various fixes.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2015-11-29 22:04:31 UTC (rev 202)
+++ pkg/ChangeLog 2015-12-03 23:11:20 UTC (rev 203)
@@ -1,3 +1,6 @@
+Changes in Version 1.4-0
+ o Harmonized print.summary for fixed and random models (now fixed print spatial parms separately). Improved header of printout for random type models, now prints a correct description of model type. Fixed cllistw() internal function for checking whether listw is a listw or a matrix and convert if needed.
+
Changes in Version 1.3-11
o Fixed 'itaww.rda' weights matrix for Italian provinces. An '1' was missing between 98 (Lodi) and 19 (Cremona).
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2015-11-29 22:04:31 UTC (rev 202)
+++ pkg/DESCRIPTION 2015-12-03 23:11:20 UTC (rev 203)
@@ -1,7 +1,7 @@
Package: splm
Title: Econometric Models for Spatial Panel Data
-Version: 1.3-11
-Date: 2015-11-25
+Version: 1.4-0
+Date: 2015-12-04
Authors at R: c(person(given = "Giovanni", family = "Millo", role = c("aut", "cre"), email = "giovanni.millo at generali.com"),
person(given = "Gianfranco", family = "Piras", role = c("aut"), email = "gpiras at mac.com"))
Author: Giovanni Millo [aut, cre],
Modified: pkg/R/print.summary.splm.R
===================================================================
--- pkg/R/print.summary.splm.R 2015-11-29 22:04:31 UTC (rev 202)
+++ pkg/R/print.summary.splm.R 2015-12-03 23:11:20 UTC (rev 203)
@@ -1,36 +1,75 @@
-`print.summary.splm` <-
-function(x,digits= max(3, getOption("digits") - 2),width=getOption("width"),...) {
+`print.summary.splm` <- function(x, digits=max(3, getOption("digits") - 2),
+ width=getOption("width"), ...) {
-
- cat(paste("Spatial panel",x$type,"model\n"))
- cat("\nCall:\n")
- print(x$call)
- cat("\nResiduals:\n")
- save.digits <- unlist(options(digits=digits))
- on.exit(options(digits=save.digits))
- print(sumres(x))
-
- if(!is.null(x$ErrCompTable)) {
- cat("\nError variance parameters:\n")
- printCoefmat(x$ErrCompTable,digits=digits,signif.legend=FALSE)
- }
-
- if(is.numeric(x$lambda)) {
- cat("\nEstimated spatial coefficient, variance components and theta:\n")
- print(x$lambda)
- }
-
- if(!is.null(x$ARCoefTable)) {
- cat("\nSpatial autoregressive coefficient:\n")
- printCoefmat(x$ARCoefTable,digits=digits,signif.legend=FALSE)
- }
-
- cat("\nCoefficients:\n")
- printCoefmat(x$CoefTable,digits=digits)
- cat("\n")
-
-
-
- invisible(x)
-}
-
+ ## manage model description
+ if(grepl("random", x$type)) {
+ ## "random" models by spreml() have a more complicated description
+ m.des <- x$type.des
+ } else {
+ m.des <- paste("Spatial panel", x$type,"model\n")
+ }
+ cat(paste(m.des, "\n"))
+
+ ## print call
+ cat("\nCall:\n")
+ print(x$call)
+
+ ## print residual des
+ cat("\nResiduals:\n")
+ save.digits <- unlist(options(digits=digits))
+ on.exit(options(digits=save.digits))
+ print(sumres(x))
+
+ ## if model is of 'random' type ex spreml():
+ if(grepl("random", x$type)) {
+
+ ## print error components' table for 'random' models
+ if(!is.null(x$ErrCompTable)) {
+ cat("\nError variance parameters:\n")
+ printCoefmat(x$ErrCompTable, digits=digits, signif.legend=FALSE)
+ }
+
+ ## print spatial lag coefficient for 'random' models
+ if(!is.null(x$ARCoefTable)) {
+ cat("\nSpatial autoregressive coefficient:\n")
+ printCoefmat(x$ARCoefTable, digits=digits, signif.legend=FALSE)
+ }
+
+ ## print betas
+ cat("\nCoefficients:\n")
+ printCoefmat(x$CoefTable, digits=digits)
+ cat("\n")
+
+ } else {
+
+ ## then it is of 'fixed' type ex spfeml()
+
+ ## print spatial lag coefficient (is this condition ever true??)
+ if(is.numeric(x$lambda)) {
+ cat("\nEstimated spatial coefficient, variance components and theta:\n")
+ print(x$lambda)
+ }
+
+ ## print error components' table for 'random' models
+ if("rho" %in% dimnames(x$CoefTable)[[1]]) {
+ cat("\nSpatial error parameter:\n")
+ printCoefmat(x$CoefTable["rho", , drop=FALSE], digits=digits, signif.legend=FALSE)
+ }
+
+ ## print spatial lag coefficient for 'random' models
+ if("lambda" %in% dimnames(x$CoefTable)[[1]]) {
+ cat("\nSpatial autoregressive coefficient:\n")
+ printCoefmat(x$CoefTable["lambda", , drop=FALSE], digits=digits, signif.legend=FALSE)
+ }
+
+ ## print betas (w/o spatial coefs)
+ cat("\nCoefficients:\n")
+ spat.nam <- dimnames(x$CoefTable)[[1]] %in% c("rho","lambda")
+ printCoefmat(x$CoefTable[!spat.nam, , drop=FALSE], digits=digits)
+ cat("\n")
+
+ }
+
+ invisible(x)
+}
+
Modified: pkg/R/spml.R
===================================================================
--- pkg/R/spml.R 2015-11-29 22:04:31 UTC (rev 202)
+++ pkg/R/spml.R 2015-12-03 23:11:20 UTC (rev 203)
@@ -13,9 +13,10 @@
checklw <- function(x) {
if(!("listw" %in% class(x))) {
+ x <- x
if("matrix" %in% class(x)) {
#require(spdep)
- x <- listw2mat(x)
+ x <- mat2listw(x)
}
else {
stop("'listw' has to be either a 'listw' or a 'matrix' object")
@@ -24,8 +25,8 @@
return(x)
}
- checklw(listw)
- checklw(listw2)
+ listw <- checklw(listw)
+ listw2 <- checklw(listw2)
## dimensions check is moved downstream
@@ -53,7 +54,9 @@
- if(model == "plm") stop("No spatial component, use plm instead")
+ if(model == "plm") stop("No spatial component, use plm instead")
+ ## put call to plm() here, fetch results
+ ## and suitably transform them for compliance
}
effects <- switch(match.arg(effect), individual="spfe",
time="tpfe", twoways="sptpfe")
Modified: pkg/R/spreml.R
===================================================================
--- pkg/R/spreml.R 2015-11-29 22:04:31 UTC (rev 202)
+++ pkg/R/spreml.R 2015-12-03 23:11:20 UTC (rev 203)
@@ -159,7 +159,25 @@
model.data <- data.frame(cbind(y, X[, -1])) # fix case with no intercept
# using has.intercept
dimnames(model.data)[[1]] <- nam.rows
- type <- "random effects ML"
+ ## name model 'type'
+ type <- "random effects ML" # this for consistency
+ ## make more elaborate description for printing
+ type.des <- "ML panel with "
+ type.sar <- if(lag) "spatial lag" else ""
+ type.re <- if(grepl("re", errors.)) {
+ if(grepl("2", errors.)) {
+ ", spatial RE (KKP)"
+ } else {
+ ", random effects"
+ }} else ""
+ type.sr <- if(grepl("sr", errors.)) ", AR(1) serial correlation" else ""
+ type.sem <- if(grepl("sem", errors.)) ", spatial error correlation" else ""
+ if(grepl("ols", errors.)) {
+ cong <- if(type.sar=="") "" else " and "
+ type.des <- paste(type.des, type.sar, cong, "iid errors", sep="")
+ } else {
+ type.des <- paste(type.des, type.sar, paste(type.re, type.sr, type.sem, sep=""), sep="")
+ }
sigma2v <- RES$sigma2
sigma2mu <- if(is.null(RES$errcomp["phi"])) {0} else {
as.numeric(sigma2v*RES$errcomp["phi"])
@@ -169,8 +187,8 @@
spmod <- list(coefficients = RES$betas, arcoef = RES$arcoef,
errcomp = RES$errcomp, vcov = RES$covB, vcov.arcoef = RES$covAR,
vcov.errcomp = RES$covPRL, residuals = res, fitted.values = y.hat,
- sigma2 = sigma2, model = model.data, type = type, call = cl,
- errors = errors, logLik = RES$ll)
+ sigma2 = sigma2, model = model.data, type = type, type.des=type.des,
+ call = cl, errors = errors, logLik = RES$ll)
class(spmod) <- "splm"
return(spmod)
}
More information about the Splm-commits
mailing list