[Splm-commits] r111 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon May 9 22:27:31 CEST 2011
Author: the_sculler
Date: 2011-05-09 22:27:31 +0200 (Mon, 09 May 2011)
New Revision: 111
Added:
pkg/R/spml.R
pkg/man/sphtest.Rd
pkg/man/spml.Rd
Log:
Added spml.R, spml.Rd, sphtest.Rd (see changelog)
Added: pkg/R/spml.R
===================================================================
--- pkg/R/spml.R (rev 0)
+++ pkg/R/spml.R 2011-05-09 20:27:31 UTC (rev 111)
@@ -0,0 +1,59 @@
+spml <- function(formula, data, index=NULL, listw, listw2=listw,
+ model=c("within","random","pooling"),
+ effect=c("individual","time","twoways"),
+ lag=FALSE, spatial.error=c("b","kkp","none"),
+ ...) {
+
+ ## wrapper function for all ML models
+
+ ## check class(listw)
+ checklw <- function(x) {
+ if(!("listw" %in% class(x))) {
+ if("matrix" %in% class(x)) {
+ require(spdep)
+ x <- listw2mat(x)
+ } else {
+ stop("'listw' has to be either a 'listw' or a 'matrix' object")
+ }}
+ return(x)
+ }
+ checklw(listw)
+ checklw(listw2)
+
+ ## dimensions check is moved downstream
+
+ switch(match.arg(model), within={
+ if(lag) {
+ model <- switch(match.arg(spatial.error), b="sarar",
+ kkp="sarar", none="lag")
+ } else {
+ model <- "error"
+ }
+ effects <- switch(match.arg(effect), individual="spfe",
+ time="tpfe", twoways="sptpfe")
+ res <- spfeml(formula=formula, data=data, index=index,
+ listw=listw, listw2=listw2,
+ model=model, effects=effects,
+ ...)
+ }, random={
+ switch(match.arg(effect),
+ time={stop("time random effects not implemented")},
+ twoways={stop("twoway random effects not implemented")},
+ individual={
+ errors <- switch(match.arg(spatial.error),
+ b="semre", kkp="sem2re", none="re")})
+ res <- spreml(formula=formula, data=data, index=index,
+ w=listw2mat(listw), w2=listw2mat(listw2),
+ lag=lag, errors=errors, ...)
+ }, pooling={
+ errors <- switch(match.arg(spatial.error),
+ b="sem", kkp="sem", none="ols")
+ res <- spreml(formula=formula, data=data, index=index,
+ w=listw2mat(listw), w2=listw2mat(listw2),
+ lag=lag, errors=errors, ...)
+ })
+
+ return(res)
+}
+
+
Added: pkg/man/sphtest.Rd
===================================================================
--- pkg/man/sphtest.Rd (rev 0)
+++ pkg/man/sphtest.Rd 2011-05-09 20:27:31 UTC (rev 111)
@@ -0,0 +1,48 @@
+\name{sphtest}
+\alias{sphtest}
+\alias{sphtest.formula}
+\alias{sphtest.splm}
+
+\title{Hausman test for spatial panel data models}
+\description{
+Hausman specification test for spatial panel data models
+}
+\usage{
+sphtest(x, ...)
+\method{sphtest}{formula}(x, data, index = NULL, listw, spatial.model = c("lag", "error", "sarar"), method = c("ML", "GM"), errors = c("KKP", "BSK"),...)
+\method{sphtest}{splm}(x, x2, ...)
+}
+
+\arguments{
+\item{x}{an object of class \code{formula} or \code{splm} }
+\item{x2}{an object of class \code{splm} }
+ \item{data}{an object of class \code{\link{data.frame}} or \code{pdata.frame}. An optional data frame containing the variables
+ in the model. When the obect is a \code{\link{data.frame}}, the first two columns may contain the indexes. See \code{index}}
+\item{index}{if not NULL (default), a character vector to identify the indexes among the columns of the \code{\link{data.frame}}}
+\item{listw}{an object of class \code{listw} created for example by \code{nb2listw} }
+\item{spatial.model}{one of \code{c("lag","error","sarar")}, the model to be estimated (only lag, only error, both lag and error dependence)}
+\item{method}{one of \code{c("ML","GM"}}
+\item{errors}{one of \code{c("BSK","KPP"}. When \code{method} is \code{"ML"} defines the specification of the innovations}
+\item{...}{additional arguments to be passed}
+}
+
+\value{
+an object of class \code{htest}
+}
+\author{Gianfranco Piras}
+
+\seealso{\code{\link{spgm}}}
+
+\examples{
+data(Produc, package="Ecdat")
+Produc <- Produc[Produc$year<1975, ]
+data(usaww)
+fm <- log(gsp)~log(pcap)+log(pc)+log(emp)+unemp
+test1<-sphtest(fm,data=Produc, listw = mat2listw(usaww), spatial.model = "error", method="GM")
+test1
+mod1<- spgm(fm, data=Produc, listw = usaww, model = "random", spatial.error = TRUE, moments="fullweights")
+mod2<- spgm(fm, data=Produc, listw = usaww, model = "within", spatial.error = TRUE)
+test2<-sphtest(mod1, mod2)
+summary(test2)
+}
+\keyword{htest}
\ No newline at end of file
Added: pkg/man/spml.Rd
===================================================================
--- pkg/man/spml.Rd (rev 0)
+++ pkg/man/spml.Rd 2011-05-09 20:27:31 UTC (rev 111)
@@ -0,0 +1,91 @@
+\name{spml}
+\alias{spml}
+\title{Spatial Panel Model by Maximum Likelihood}
+\description{Maximum likelihood (ML) estimation of spatial panel models, possibly with fixed or random effects.}
+
+
+\usage{
+spml(formula, data, index = NULL, listw, listw2=listw,
+ model=c("within","random","pooling"),
+ effect=c("individual","time","twoways"),
+ lag=FALSE, spatial.error=c("b","kkp","none"),
+ ...)
+}
+
+\arguments{
+ \item{formula}{a symbolic description of the model to be estimated}
+ \item{data}{an object of class \code{\link{data.frame}} or \code{pdata.frame}. A data frame containing the variables
+ in the model. When the object is a \code{\link{data.frame}}, the first two columns shall contain the indexes, unless otherwise specified. See \code{index}}
+ \item{index}{if not NULL (default), a character vector to identify the indexes among the columns of the \code{\link{data.frame}}}
+ \item{listw}{an object of class \code{listw} or a \code{matrix}. It represents the spatial weights to be used in estimation.}
+ \item{listw2}{an object of class \code{listw} or a
+ \code{matrix}. Second of set spatial weights for estimation, if
+ different from the first (e.g., in a 'sarar' model).}
+ \item{model}{one of \code{c("within", "random", "pooling").}}
+ \item{effect}{one of \code{c("individual","time","twoways")}; the
+ effects introduced in the model.}
+ \item{lag}{default=\code{FALSE}. If \code{TRUE}, a spatial lag of the dependent variable is added.}
+ \item{spatial.error}{one of \code{c("b","kkp","none")}. The type of
+ spatial error in the specification, if any. See details.}
+ \item{...}{additional argument to pass over to other functions}
+}
+\details{
+ The models are estimated by two-step Maximum Likelihood.
+ Further optional parameters to be passed on to the estimator may be:
+pvar: if \code{TRUE} the \code{pvar} function is called
+hess: if \code{TRUE} use numerical Hessian instead of GLS for the
+standard errors of the estimates
+quiet: if \code{FALSE} report function and parameters values during
+optimization
+initval: one of \code{c("zeros", "estimate")}, the initial values for
+ the parameters. If \code{"zeros"} a vector of zeros is used. if
+ \code{"estimate"} the initial values are retreived from the estimation
+ of the nested specifications. Alternatively, a numeric vector can be
+ specified.
+ x.tol: Tolerance. See \code{\link{nlminb}} for details.
+ rel.tol: Relative tolerance. See \code{\link{nlminb}} for details.
+}
+\value{
+ An object of class \code{"splm"}.
+ \item{coefficients}{coefficients estimate of the model parameters }
+ \item{arcoef}{the coefficient for the spatial lag on \code{y}}
+ \item{errcomp}{the estimates of the error variance components}
+ \item{vcov}{the asymptotic variance covariance matrix of the estimated coefficients}
+ \item{vcov.arcoef}{the asymptotic variance of the
+ estimated spatial lag parameter}
+ \item{vcov.errcomp}{the asymptotic variance covariance matrix of the
+ estimated error covariance parameters}
+ \item{type}{'random effects ML'}
+ \item{residuals}{the model residuals}
+ \item{fitted.values}{the fitted values, calculated as \eqn{\hat{y}=X \hat{\beta}}}
+ \item{sigma2}{GLS residuals variance}
+ \item{model}{the matrix of the data used}
+ \item{call}{the call used to create the object}
+ \item{logLik}{the value of the log likelihood function at the optimum }
+ \item{errors}{the value of the \code{errors} argument}
+}
+\references{
+Baltagi, B.H., Song, S.H., Jung B. and Koh, W. (2007)
+Testing panel data regression models with spatial and serial error correlation.
+\emph{Journal of Econometrics}, \bold{140}, 5-51.
+}
+
+\author{Giovanni Millo}
+
+\seealso{\code{\link{spgm}}, \code{\link{spfeml}}}
+
+\examples{
+data(Produc, package = "Ecdat")
+data(usaww)
+Produc <- Produc[Produc$year<1974, ]
+fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
+## the two standard specifications:
+## random effects panel with spatial errors
+respaterr <- spml(fm, data = Produc, listw = mat2listw(usaww), model="random", spatial.error="b")
+summary(respaterr)
+## random effects panel with spatial lag
+respatlag <- spml(fm, data = Produc, listw = mat2listw(usaww), model="random", spatial.error="b", lag=TRUE)
+summary(respatlag)
+}
+
+\keyword{spatial}
\ No newline at end of file
More information about the Splm-commits
mailing list