Movatterモバイル変換


[0]ホーム

URL:


Type:Package
Title:Spatial Seemingly Unrelated Regression Models
Version:1.0.2.6
Date:2025-09-02
Maintainer:Roman Minguez <roman.minguez@uclm.es>
Description:A collection of functions to test and estimate Seemingly Unrelated Regression (usually called SUR) models, with spatial structure, by maximum likelihood and three-stage least squares. The package estimates the most common spatial specifications, that is, SUR with Spatial Lag of X regressors (called SUR-SLX), SUR with Spatial Lag Model (called SUR-SLM), SUR with Spatial Error Model (called SUR-SEM), SUR with Spatial Durbin Model (called SUR-SDM), SUR with Spatial Durbin Error Model (called SUR-SDEM), SUR with Spatial Autoregressive terms and Spatial Autoregressive Disturbances (called SUR-SARAR), SUR-SARAR with Spatial Lag of X regressors (called SUR-GNM) and SUR with Spatially Independent Model (called SUR-SIM). The methodology of these models can be found in next references Minguez, R., Lopez, F.A., and Mur, J. (2022) <doi:10.18637/jss.v104.i11> Mur, J., Lopez, F.A., and Herrera, M. (2010) <doi:10.1080/17421772.2010.516443> Lopez, F.A., Mur, J., and Angulo, A. (2014) <doi:10.1007/s00168-014-0624-2>.
LazyData:true
Encoding:UTF-8
License:GPL-3
Depends:R (≥ 4.1), methods (≥ 4.1), stats (≥ 4.1)
Imports:Formula (≥ 1.2-5), ggplot2 (≥ 3.5.2), gmodels (≥ 2.19.1),gridExtra (≥ 2.3), MASS (≥ 7.3-65), Matrix (≥ 1.4-1), minqa(≥ 1.2.8), numDeriv (≥ 2016.8-1.1), Rdpack (≥ 2.6.4), rlang(≥ 1.1.6), sparseMVN (≥ 0.2.2), spatialreg (≥ 1.3-6), spdep(≥ 1.4-1), sphet(≥ 2.1-1)
Suggests:bookdown (≥ 0.44), dplyr (≥ 1.1.4), kableExtra (≥ 1.4.0),knitr (≥ 1.50), rmarkdown (≥ 2.29), sf (≥ 1.0-20)
VignetteBuilder:knitr
RoxygenNote:7.3.2
RdMacros:Rdpack
URL:https://CRAN.R-project.org/package=spsur
BugReports:https://github.com/rominsal/spsur/issues
NeedsCompilation:no
Packaged:2025-09-03 09:01:44 UTC; roman
Author:Ana Angulo [aut], Fernando A Lopez [aut], Roman Minguez [aut, cre], Jesus Mur [aut]
Repository:CRAN
Date/Publication:2025-09-03 09:20:02 UTC

Spatial Seemingly Unrelated Regression Models.

Description

spsur offers the user a collection of functions to estimate Spatial Seemingly Unrelated Regression (SUR) models by maximum likelihood or three-stage least squares, using spatial instrumental variables. Moreover,spsur obtains a collection of misspecificationtests for omitted or wrongly specified spatial structure. The user will find spatial models more popular in applied research such as the SUR-SLX, SUR-SLM, SUR-SEM, SUR-SDM, SUR-SDEM SUR-SARAR and SUR-GNM plus the spatially independent SUR, or SUR-SIM.

Details

Some functionalities that have been included inspsur package are:

1. Testing for spatial effects

The functionlmtestspsur provides a collection of Lagrange Multipliers, LM, for testing different forms of spatial dependence in SUR models. They are extended versions ofthe well-known LM tests for omitted lags of the explained variable in the right hand side of the equation, LM-SLM, the LM tests for omitted spatial errors, LM-SEM, the join test of omitted spatial lags and spatial errors, LM-SARAR, and the robust version of the firttwo Lagrange Multipliers, LM*-SLM and LM*-SEM.
These tests can be applied to models always with a SUR nature. Roughly, we may distinguish two situations:

2. Estimation of the Spatial SUR models

As indicated above,spsur package may work with a list of different spatial specifications.They are the following:

wherey_{tg},u_{tg} and\epsilon_{tg} are(Nx1) vectors;X_{tg} is a matrix of regressors of order(NxP);\rho_{g} and\lambda_{g} are parameters of spatial dependence andW is the(NxN) spatial weighting matrix.

These specifications can be estimated by maximum-likelihood methods, using the functionspsurml. Moroever, the models that include spatial lags of the explainedvariables in the right hand side of the equations, and the errors are assumed to be spatially incorrelated (namely, the SUR-SLM and the SUR-SDM), can also be estimated usingthree-stage least-squares,spsur3sls, using spatial instrumental variable to correct for the problem ofendogeneity present in these cases.

3. Diagnostic tests

Testing for inconsistencies or misspecifications in the results of an estimated (SUR) model should be a primary task for the user.spsur focuses, especifically, on two main question such as omittedor wrongly specified spatial structure and the existence of structural breaks or relevant restrictionsin the parameters of the model. In this sense, the user will find:

  1. Marginal tests
    The Marginal Multipliers test for omitted or wrongly specified spatial structure in the equations. They are routinely part of the output of the maximum-likelihood estimation, shown byspsurml. In particular, the LM(\rho|\lambda) tests for omitted spatial lags in a model specified with spatial errors (SUR-SEM; SUR-SDEM). The LM(\lambda|\rho) tests for omitted spatial error in a model specified with spatial lagsof the explained variable (SUR-SLM; SUR-SDM).

  2. Coefficients stability tests
    spsur includes two functions designed to test for linear restrictions on the\beta coefficients of the models and on the spatial coefficients (\rhos and\lambdas terms). The function for the first case iswald_betas andwald_deltas that of the second case. The user has ample flexibility to define different forms of linear restrictions, so that it is possible, for example,to test for their time constancy to identify structural breaks.

4. Marginal effects

In recent years, since the publication of LeSage and Pace (2009), it has become popular inspatial econometrics to evaluate the multiplier effects that a change in the value of a regressor, in a point in the space, has on the explained variable.spsur includes a function,impactspsur, that computes these effects. Specifically,impactspsur obtainsthe average, over theN spatial units andTm time periods, of such a change on the contemporaneous value of the explained variable located in the same point as the modified variable. This is the so-calledAverage Direct effect. TheAverage Indirect effect measure the proportion of the impact that spills-over to other locations. The sum of the two effects is theAverage Total effect.
These estimates are complemented with a measure of statistical significance, following the randomization approach suggested by LeSage and Pace (2009).

5. Additional functionalities

A particular feature ofspsur is that the package allows to obtain simulated datasets with a SUR nature and the spatial structure decided by the user. This is the purpose of the functiondgp_spsur. The function can be inserted into a more general code to solve, for example, Monte Carlo studies related to these type of models or, simply, to show some of the stylized characteristics of a SUR model with certain spatial structure.

Datasets

spsur includes three different datasets: spc, NCOVR and spain.covid. These sets are used to illustrate the capabilities of different functions. Briefly, their main characteristics are the following

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

Useful links:


Homicides in U.S. counties

Description

Homicides and selected socio-economic characteristics for continentalU.S. counties. Data for four decennial census years: 1960, 1970, 1980and 1990.

Usage

NCOVR.sf

Format

An spatial feature (sf) object with 3085 rows and 41 variables:

NAME

County coded as a name (factor)

STATE_NAME

state fips code (factor)

FIPS

state fips code (factor)

SOUTH

dummy variable for Southern counties (South = 1)

HR60, HR70, HR80, HR90

homicide rate per 100,000 (1960, 1970,1980, 1990)

HC60, HC70, HC80, HC90

homicide count, three year average centeredon 1960, 1970, 1980, 1990

PO60, PO70, PO80, PO90

county population, 1960, 1970, 1980, 1990

RD60, RD70, RD80, RD90

resource deprivation 1960, 1970, 1980,1990 (principal component, see Codebook for details)

PS60, PS70, PS80, PS90

population structure 1960, 1970, 1980,1990 (principal component, see Codebook for details)

UE60, UE70, UE80, UE90

unemployment rate 1960, 1970, 1980, 1990

DV60, DV70, DV80, DV90

divorce rate 1960, 1970, 1980, 1990(% males over 14 divorced)

MA60, MA70, MA80, MA90

median age 1960, 1970, 1980, 1990

FP59, FP69, FP79, FP89

% families below poverty 1960, 1970, 1980,1990 (see Codebook for details)

geometry

Multipolygon geometry of the spatial feature object

Source

S. Messner, L. Anselin, D. Hawkins, G. Deane, S. Tolnay, R. Baller(2000). An Atlas of the Spatial Patterning of County-LevelHomicide, 1960-1990. Pittsburgh, PA, National Consortium onViolence Research (NCOVR)https://geodacenter.github.io/data-and-lab/ncovr/

References


Spatial weight matrix for South-West Ohio Counties to estimateSpatial Phillips-Curve

Description

A spatial weight matrix row-standardized based on first ordercontiguity criterium.

Usage

Wspc

Format

A row-standardized squared matrix with 25 rows and columns.The rows and columns follow the same order than provinces included inspc data frame.

Source

Anselin (1988, p. 207)

References


Generation of a random dataset with a spatial SUR structure.

Description

The purpose of the functiondgp_spsur is to generate a random dataset with the dimensions and spatial structure decided by the user. This function may be useful in pure simulation experiments or with the aim of showing specific properties and characteristicsof a spatial SUR dataset and inferential procedures related to them.

The user ofdgp_spsur should think in terms of a Monte Carlo experiment. The arguments of the function specify the dimensions of the dataset to be generated, the spatial mechanism underlying the data, the intensity of the SUR structure among the equations and the values of the parameters to be used to obtain the simulated data, which includes the error terms, the regressors and the explained variables.

Usage

dgp_spsur(Sigma, Tm = 1, G, N, Betas, Thetas = NULL,                  rho = NULL, lambda = NULL, p = NULL, listw = NULL,                  X = NULL, type = "matrix", pdfU = "nvrnorm",                  pdfX = "nvrnorm")

Arguments

Sigma

Covariance matrix between theG equations of the SUR model. This matrix should be definite positive and the user must check for that.

Tm

Number of time periods. Default =1

G

Number of equations.

N

Number of cross-section or spatial units

Betas

A row vector of order(1xP) showing the values for thebeta coefficients.The firstP_{1} terms correspond to the first equation (where the first element is the intercept), the secondP_{2} terms to the coefficients of the second equation and so on.

Thetas

Values for the\theta coefficients in theG equations of the model, when the type of spatial SUR model to be simulated is a "slx", "sdm" or "sdem".Thetas is a row vector of order1xPTheta, wherePThetas=p-G; let us note that the intercept cannot appear among the spatial lags of the regressors. The first1xKTheta_{1} terms correspond to the first equation, the second1xPTheta_{2} terms correspond to thesecond equation, and so on. Default =NULL.

rho

Values of the coefficients\rho_{g}; g=1,2,..., G related to the spatial lag of the explained variable of the g-th equation. Ifrho is an scalar and there areG equations in the model, the same value will be used for all the equations. Ifrho is a row vector, of order(1xG), the functiondgp_spsur will use these values, one for each equation. Default =NULL.

lambda

Values of the coefficients\lambda_{g}; g=1,2,..., G related to the spatial lag of the errors in theG equations. Iflambda is an scalar and there areG equationsin the model, the same value will be used for all the equations. Iflambda is a row vector, of order(1xG), the functiondgp_spsur will use these values, one for each equation of the spatial errors. Default =NULL.

p

Number of regressors by equation, including the intercept.p can be a row vector of order(1xG), if the number of regressors is not the same for all the equations, or a scalar, if theG equations have the same number of regressors.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

X

This argument tells the functiondgp_spsur whichX matrix should be used to generate the SUR dataset. IfX is different fromNULL,{dgp_spsur} will upload theX matrix selected in this argument. Note that theX must be consistentwith the dimensions of the model. IfX isNULL,dgp_spsur will generate the desired matrix of regressors from a multivariate Normal distribution with mean value zero and identity(PxP) covariance matrix. As an alternative, the user may change this probability distribution function to the uniform case,U(0,1), through the argumentpdfX. Default =NULL.

type

Selection of the type of output. The alternatives arematrix,df,panel,all. Defaultmatrix

pdfU

Multivariate probability distribution function, Mpdf, from which the values of the error terms will be drawn. The covariance matrix is the\Sigma matrix specified by the user in the argument. Two alternatives"lognvrnorm","nvrnorm". Default"nvrnorm".

Sigma.The functiondgp_spsur provides two Mpdf, the multivariate Normal, which is the default, and the log-Normal distribution function which means just exponenciate the sampling drawn form aN(0,\Sigma)distribution. Default ="nvrnorm".

pdfX

Multivariate probability distribution function (Mpdf), from which the values of the regressors will be drawn. The regressors are assumed to be independent.dgp_spsur provides two Mpdf, the multivariate Normal, which is the default, and the uniform in the intervalU[0,1], using the dunif function.dunif, from thestats package. Two alternatives"nvrunif","nvrnorm". Default"nvrnorm".

Details

The purpose of the functiondgp_spsur is to generate random datasets, of a SUR nature, with the spatial structure decided by the user. The function requires certain information to be supplied externally because, in fact,dgp_spsur constitutes a Data GenerationProcess, DGP. The following aspects should be addressed:

dgp_spsur provides two multivariate distribution functions, namely, the Normal and the log-Normal for the errors (the second should be taken as a clear departure from the standard assumption ofnormality). In both cases, random matrices of order(TmNxG) are obtained from a multivariate normal distribution, with a mean value of zero and the covariance matrix specified in the argumentSigma; then, this matrix is exponentiated for the log-Normal case. Roughly, the same procedure applies for drawing the values of the regressor. There are two distribution functions available, thenormal and the uniform in the intervalU[0,1]; the regressors are always independent.

Value

The default output ("matrix") is a list with a vectorY of order(TmNGx1) with the values generated for the explained variable in the G equations of the SUR and a matrixXX of order ((TmNGxsum(p)), with the valuesgenerated for the regressors of the SUR, including an intercept for each equation.

In case of Tm = 1 or G = 1 several alternatives output can be select:

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,spsur3sls,spsurtime

Examples

## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_dgp_spsur, package="spsur")################################################### PANEL DATA (Tm = 1 or G = 1)              ###################################################################################################### Example 1: DGP SLM model. G equations################################################rm(list = ls()) # Clean memoryTm <- 1 # Number of time periodsG <- 3 # Number of equationsN <- 200 # Number of spatial elementsp <- 3 # Number of independent variablesSigma <- matrix(0.3, ncol = G, nrow = G)diag(Sigma) <- 1Betas <- c(1, 2, 3, 1, -1, 0.5, 1, -0.5, 2)rho <- 0.5 # level of spatial dependencelambda <- 0.0 # spatial autocorrelation error term = 0##  random coordinatesco <- cbind(runif(N,0,1),runif(N,0,1))lw <- spdep::nb2listw(spdep::knn2nb(spdep::knearneigh(co, k = 5,                                                   longlat = FALSE)))DGP <- dgp_spsur(Sigma = Sigma, Betas = Betas,                 rho = rho, lambda = lambda, Tm = Tm,                 G = G, N = N, p = p, listw = lw)SLM <- spsurml(X = DGP$X, Y = DGP$Y, Tm = Tm, N = N, G = G,                p = c(3, 3, 3), listw = lw, type = "slm") summary(SLM)################################################### MULTI-DIMENSIONAL PANEL DATA G>1 and Tm>1 ##################################################rm(list = ls()) # Clean memoryTm <- 10 # Number of time periodsG <- 3 # Number of equationsN <- 100 # Number of spatial elementsp <- 3 # Number of independent variablesSigma <- matrix(0.5, ncol = G, nrow = G)diag(Sigma) <- 1Betas <- rep(1:3, G)rho <- c(0.5, 0.1, 0.8)lambda <- 0.0 # spatial autocorrelation error term = 0## random coordinatesco <- cbind(runif(N,0,1),runif(N,0,1))lw <- spdep::nb2listw(spdep::knn2nb(spdep::knearneigh(co, k = 5,                                                   longlat = FALSE)))DGP4 <- dgp_spsur(Sigma = Sigma, Betas = Betas, rho = rho,                   lambda = lambda, Tm = Tm, G = G, N = N, p = p,                   listw = lw)SLM4  <- spsurml(Y = DGP4$Y, X = DGP4$X, G = G, N = N, Tm = Tm,                 p = p, listw = lw, type = "slm")summary(SLM4)

Direct, indirect and total effects estimated for a spatial SUR model

Description

This function is a wrapper forimpacts methodused inspatialreg package. Nevertheless, in this case the same method is used for bothlagsarlm andlmSLX objects. For details of implementation, see the documentation ofimpacts function inspatialreg package.
The function obtains the multiplier effects, on the explained variable, of a change in a regressor for the model that has been estimated. For reasons given below, this function only applies to models with an autoregressive structure ("slm", "sdm", "sarar" and "gnm") or with spatial lags of the regressors ("slx", "sdem").
The measurement of the multiplier effects is a bit more complicated than in a pure time series context because, due to the spatial structure of the model, part of the impacts spills over non uniformly over the space. Using the notation introduced by LeSage and Pace (2009) we distinguish between:

The information on the three estimated effects is supplement with an indirect measure of statistical significance obtained from the randomization approach introduced in LeSage and Pace (2009).

Usage

impactspsur (obj, ..., tr = NULL, R = NULL, listw = NULL,                       evalues = NULL,tol = 1e-06,                       empirical = FALSE, Q = NULL)

Arguments

obj

Anspsur object created byspsurml,spsur3sls orspsurtime.

...

Arguments passed through to methods in thecoda package

tr

A vector of traces of powers of the spatial weights matrix created usingtrW, for approximate impact measures; if not given,listw must be given for exact measures (for small to moderate spatial weights matrices); the traces must be for the same spatial weights as were used in fitting the spatial regression, and must be row-standardised

R

If given, simulations are used to compute distributions for the impact measures, returned asmcmc objects; the objects are used for convenience but are not output by an MCMC process

listw

Iftr is not given, a spatial weights object as created bynb2listw; they must be the same spatial weights as were used in fitting the spatial regression, but do not have to be row-standardised

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

Argument passed tomvrnorm: tolerance (relative to largest variance) for numerical lack of positive-definiteness in the coefficient covariance matrix

empirical

Argument passed tomvrnorm (default FALSE): if true, the coefficients and their covariance matrix specify the empirical not population mean and covariance matrix

Q

default NULL, else an integer number of cumulative power series impacts to calculate iftr is given

Details

LeSage and Pace (2009) adapt the classical notion of'economic multiplier' to the problem of measuring the impact that a unitary change in the value of a regressor, produced in a certain point in space, has on the explained variable. The question is interesting because, due to the spatial structure of the model, the impacts of such change spill non uniformly over the space. In fact, the reaction of the explained variable depends on its relative location in relation to the point of intervention.
To simplify matters, LeSage and Pace (2009) propose to obtain aggregated multipliers for each regressor, just averaging theN^{2} impacts that results from intervening the value of each regressor on each of theN points in Space, on the explained variable, measured also in each of theN points in space. This aggregated average is the so-calledTotal effect.
Part of this impact will be absorved by the explained variable located in the same point of the regressor whose value has been changed (for example, the k-th regresor in the g-th equation, in the n-th spatial unit) or,in other words, we expect that[d y_{tgn}]/[d x_{ktgn}] ne 0. The aggregated average for theN points in space (n=1,2,...,N) andTm time periods is the so-calledDirect effect.The difference between theTotal effect and theDirect effect measures the portion of the impact on the explained variable that leakes to other points in space,[d y_{tgn}]/[d x_{ktgm}] for n ne m;this is theIndirect effect.

impactspsur obtains the three multipliers together with an indirect measure of statistical significance, according to the randomization approach described in Lesage and Pace (2009). Briefly, they suggest to obtain a sequence ofnsim random matrices of order(NTmxG) from a multivariate normal distribution N(0;Sigma), beingSigma the estimated covariance matrix of theG equations in the SUR model. These random matrices, combined with the observed values of the regressors and the estimated values of the parameters of the corresponding spatial SUR model, are used to obtain simulated values of the explained variables. Then, for each one of thensim experiments, the SUR model is estimated, and the effectsare evaluated. The functionimpactspsur obtains the standard deviations of thensim estimated effects in the randomization procedure, which are used to test the significance of the estimated effects for the original data.

Finally, let us note that this is a SUR model where theG equations are connected only through the error terms. This means that if we intervene a regressor in equationg, in any point is space, only the explained variable of the same equationg should react. The impacts do not spill over equations. Moreover, the impact of a regressor, intervened in the spatial unitn, will cross the borders of this spatial unit only if in the right hand side of the equation there are spatial lags of the explained variables or of the regressors. In other words, theIndirect effect is zero for the "sim" and "sem" models.impactspsur produces no output for these two models.Lastly, it is clear that all the impacts are contemporaneous because the equations in the SUR model have no time dynamics.

Value

A list ofG objects either of classlagImpact orWXImpact.

For each of the G objects of the list, if no simulation is carried out the object returned is a list with:

direct numeric vector
indirect numeric vector
total numeric vector

and a matchingQres list attribute ifQ was given.

On the other hand, for each of the G objects of the list, if simulation is carried out the object returned is a list with:

resa list with three components as for the non-simulation case, with a matchingQres list attribute ifQ was given.
sres a list with threemcmc matrices, for the direct, indirect and total impacts with a matchingQmcmclist attribute ifQ was given.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

impacts,spsurml,spsur3sls

Examples

## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_impactspsur, package="spsur")################################################## PURE CROSS SECTIONAL DATA(G>1; Tm=1) ######################################################### Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203) rm(list = ls()) # Clean memory data(spc) lwspc <- spdep::mat2listw(Wspc, style = "W") Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA## For SLM, SDM and SARAR models the output is a list of "lagImpact" objects## See spatialreg::impacts for details. spcsur_slm <-spsurml(formula = Tformula, data = spc,                       type = "slm", listw = lwspc) summary(spcsur_slm) impacts_slm <- impactspsur(spcsur_slm, listw = lwspc, R = 1000)## Impacts equation 1 summary(impacts_slm[[1]], zstats = TRUE, short = TRUE)## Impacts equation 2 summary(impacts_slm[[2]], zstats = TRUE, short = TRUE)## For SLX and SDEM models the output is a list of "WXImpact" objects## See spatialreg::impacts for details.## A SUR-SLX model spcsur_slx <-spsurml(formula = Tformula, data = spc,                       type = "slx", listw = lwspc) summary(spcsur_slx) impacts_slx <- impactspsur(spcsur_slx, listw = lwspc) summary(impacts_slx[[1]], zstats = TRUE, short = TRUE) summary(impacts_slx[[2]], zstats = TRUE, short = TRUE)## A SUR-SDM model spcsur_sdm <-spsurml(formula = Tformula, data = spc,                       type = "sdm", listw = lwspc) impacts_sdm <- impactspsur(spcsur_sdm, listw = lwspc, R = 1000) summary(impacts_sdm[[1]], zstats = TRUE, short = TRUE) summary(impacts_sdm[[2]], zstats = TRUE, short = TRUE)## A SUR-SDM model with different spatial lags in each equation TformulaD <- ~ UN83 + NMR83 + SMSA | UN80 spcsur_sdm2 <-spsurml(formula = Tformula, data = spc, type = "sdm",                        listw = lwspc, Durbin = TformulaD) summary(spcsur_sdm2)                        impacts_sdm2 <- impactspsur(spcsur_sdm2, listw = lwspc, R = 1000) summary(impacts_sdm2[[1]], zstats = TRUE, short = TRUE) summary(impacts_sdm2[[2]], zstats = TRUE, short = TRUE) ## A SUR-SLX model with different spatial lags in each equation spcsur_slx2 <-spsurml(formula = Tformula, data = spc,                       type = "slx", listw = lwspc, Durbin = TformulaD) summary(spcsur_slx2) impacts_slx2 <- impactspsur(spcsur_slx2, listw = lwspc) summary(impacts_slx2[[1]], zstats = TRUE, short = TRUE) summary(impacts_slx2[[2]], zstats = TRUE, short = TRUE) # ##################################### ######## G=1; Tm>1               #### ##################################### rm(list = ls()) # Clean memory data(NCOVR, package="spsur") nbncovr <- spdep::poly2nb(NCOVR.sf, queen = TRUE)### Some regions with no links... lwncovr <- spdep::nb2listw(nbncovr, style = "W", zero.policy = TRUE) Tformula <- HR80  | HR90 ~ PS80 + UE80 | PS90 + UE90### A SUR-SLM model NCOVRSUR_slm <-spsurml(formula = Tformula, data = NCOVR.sf,                         type = "slm", listw = lwncovr,                         method = "Matrix", zero.policy = TRUE,                         control = list(fdHess = TRUE)) summary(NCOVRSUR_slm)### Use of trW to compute. Wncovr <- Matrix::Matrix(spdep::listw2mat(lwncovr)) trwncovr <- spatialreg::trW(Wncovr, type = "MC") impacts_NCOVRSUR_slm <- impactspsur(NCOVRSUR_slm, tr = trwncovr,                                 R = 1000) summary(impacts_NCOVRSUR_slm[[1]], zstats = TRUE, short = TRUE) summary(impacts_NCOVRSUR_slm[[2]], zstats = TRUE, short = TRUE)

Testing for the presence of spatial effects in Seemingly Unrelated Regressions

Description

The functionspsurml reports a collection of Lagrange Multipliers designed to test for the presence of different forms of spatial dependence in aSUR model of the "sim" type. That is, the approach of this function is from'specific to general'. As said, the model of the null hypothesis is the "sim" model whereas the model of the alternative depends on the effect whose omission we want to test.

The collection of Lagrange Multipliers obtained bylmtestspsur are standard in the literature and take into account the multivariate nature of theSUR model. As a limitation, note that each Multiplier tests for the omission of the same spatial effects in all the cross-sections of theG equations.

Usage

lmtestspsur(...)## S3 method for class 'formula'lmtestspsur(  formula,  data,  listw,  na.action,  time = NULL,  Tm = 1,  zero.policy = NULL,  R = NULL,  b = NULL,  ...)## Default S3 method:lmtestspsur(Y, X, G, N, Tm = 1, listw, p, R = NULL, b = NULL, ...)

Arguments

...

further arguments passed to the method.

formula

An object typeFormula similar to objects created with the packageFormula describing the equations to be estimated in the model. This model may contain several responses (explained variables) and a varying number of regressors in each equation.

data

An object of class data.frame or a matrix.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

na.action

A function (defaultoptions("na.action")),can also bena.omit orna.exclude with consequences for residuals and fitted values. It may be necessary to setzero.policy toTRUE because this subsetting may create no-neighbour observations.

time

time index for the spatial panel SUR data.

Tm

Number of time periods.

zero.policy

Similar to the corresponding parameter oflagsarlm function inspatialreg package. IfTRUE assign zero to the lagged value of zones without neighbours, ifFALSE assignNA - causingspsurml() to terminate with an error. Default =NULL.

R

A row vector of order(1xpr) with the set ofr linear constraints on thebeta parameters. Thefirst restriction appears in the firstp terms,the second restriction in the nextp terms and so on. Default =NULL.

b

A column vector of order(rx1) with the values of the linear restrictions on thebeta parameters. Default =NULL.

Y

A column vector of order(NTmGx1), with the observations of the explained variables. The ordering of the data must be (first) equation, (second) time dimension and (third) cross-sectional/spatial units. The specification ofY is only necessary if not available aFormulaand a data frame. Default =NULL.

X

A data matrix of order(NTmGxp) with the observationsof the regressors. The number of covariates in the SUR model isp =sum(p_{g}) wherep_{g} is the number of regressors (including the intercept) in the g-th equation,g = 1,...,G). The specification of "X" is only necessary if not available aFormula and a data frame. Default =NULL.

G

Number of equations.

N

Number of cross-section or spatial units

p

Number of regressors by equation, including the intercept.p can be a row vector of order(1xG), if the number of regressors is not the same for all the equations, or a scalar, if theG equations have the same number of regressors. The specification ofp is only necessary if not available aFormula and a data frame.

Details

lmtestspsur tests for the omission of spatial effects in the "sim" version of theSUR model:

y_{tg} = X_{tg} \beta_{g} + u_{tg}

E[u_{tg}u_{th}']= \sigma_{gh}I_{N} \quad E[u_{tg}u_{sh}']= 0 \mbox{ if } t ne s

wherey_{tg} andu_{tg} are(Nx1) vectors, corresponding to the g-th equation and time period t;X_{tg} is the matrix of exogenous variables, of order(Nxp_{g}). Moreover,\beta_{g} is an unknown(p_{g}x1) vector of coefficients and\sigma_{gh}I_{N} the covariance between equationsg andh,being\sigma_{gh} and scalar andI_{N} the identity matrix of orden N.

The Lagrange Multipliers reported by this function are the followings:

Value

A list ofhtest objects each one including the Waldstatistic, the corresponding p-value and the degrees offreedom.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,anova

Examples

######################################################### CROSS SECTION DATA (G>1; Tm=1) # ############################################################ Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)rm(list = ls()) # Clean memorydata("spc")Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSAlwspc <- spdep::mat2listw(Wspc, style = "W")lmtestspsur(formula = Tformula, data = spc, listw = lwspc)## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_lmtestspsur, package="spsur")######################################################### PANEL DATA (G>1; Tm>1)          ############################################################# Example 2: Homicides & Socio-Economics (1960-90)# Homicides and selected socio-economic characteristics for# continental U.S. counties.# Data for four decennial census years: 1960, 1970, 1980 and 1990.# https://geodacenter.github.io/data-and-lab/ncovr/data(NCOVR, package="spsur")nbncovr <- spdep::poly2nb(NCOVR.sf, queen = TRUE)### Some regions with no links...lwncovr <- spdep::nb2listw(nbncovr, style = "W", zero.policy = TRUE)### With different number of exogenous variables in each equationTformula <- HR70 | HR80  | HR90 ~ PS70 + UE70 | PS80 + UE80 +RD80 |            PS90 + UE90 + RD90 + PO90lmtestspsur(formula = Tformula, data = NCOVR.sf,             listw = lwncovr)########################################################################## PANEL DATA: TEMPORAL CORRELATIONS (G=1; Tm>1) ############################################################################## Example 3: NCOVR in panel data formYear <- as.numeric(kronecker(c(1960,1970,1980,1990),                    matrix(1,nrow = dim(NCOVR.sf)[1])))HR <- c(NCOVR.sf$HR60,NCOVR.sf$HR70,NCOVR.sf$HR80,NCOVR.sf$HR90)PS <- c(NCOVR.sf$PS60,NCOVR.sf$PS70,NCOVR.sf$PS80,NCOVR.sf$PS90)UE <- c(NCOVR.sf$UE60,NCOVR.sf$UE70,NCOVR.sf$UE80,NCOVR.sf$UE90)NCOVRpanel <- as.data.frame(cbind(Year,HR,PS,UE))Tformula <- HR ~ PS + UElmtestspsur(formula = Tformula, data = NCOVRpanel, time = Year, listw = lwncovr)

Likelihood ratio for testing homogeneity constraints on beta coefficients of the SUR equations.

Description

Functionlr_betas obtains a Likelihood Ratio test, LR in what follows,with the purpose of testing if some of the\beta coefficients in theG equations of theSUR model are equal. This function has a straightforward application, especially whenG=1,to the case of testing for the existence of structural breaks in the\beta parameters.

The function can test for the homogeneity of only one coefficient, of a few of themor even the homogeneity of all the slope terms. The testing procedure implies,first,the estimation of both a constrained and a unconstrained model and,second, the comparisonof the log-likelihoods to compute the LR statistics.

@usage lr_betas (obj, R, b)

Usage

lr_betas(obj, R, b)

Arguments

obj

Anspsur object created byspsurml,spsur3sls orspsurtime.

R

A row vector of order(1xPr) showing the setofr linear constraints on the\beta parameters. Thefirst restriction appears in the firstK terms inR, thesecond restriction in the nextK terms and so on.

b

A column vector of order(rx1) with the values of the linear restrictions on the\beta parameters.

Value

Object ofhtest including the LRstatistic, the corresponding p-value, the degrees offreedom and the values of the sample estimates.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,spsurtime,wald_betas

Examples

## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_lr_betas, package="spsur")#' ######################################################### CROSS SECTION DATA (G>1; Tm=1)  ############################################################# Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)rm(list = ls()) # Clean memorydata(spc)lwspc <- spdep::mat2listw(Wspc, style = "W")Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA### H0: equal beta for SMSA in both equations.R <- matrix(c(0,0,0,1,0,0,0,-1), nrow=1)b <- matrix(0, ncol=1)spcsur.slm <- spsurml(formula = Tformula, data = spc,                       type = "slm", listw = lwspc)summary(spcsur.slm)lr_betas(spcsur.slm, R = R, b = b)### Estimate restricted SUR-SLM modelspcsur.slmr <- spsurml(formula = Tformula, data = spc,                       type = "slm", listw = lwspc,                      R = R, b = b)summary(spcsur.slmr)

Methods for class spsur

Description

Theanova() function provides tables of fitted spsur models including information criteria (AIC and BIC), log-likelihood and degrees of freedom of each fitted model. The argumentlrtest allows to perform LR tests between nested models.Theplot() function allows the user to plot both beta and spatialcoefficients for all equations of the spsur model. The argumentviewplot is used to choose between interactive or non-interactiveplots. Theprint() function is used to print short tables including the values of beta andspatial coefficients as well as p-values of significance test for each coefficient. This can be used as an alternative tosummary.spsur when a brief output is needed. The rest of methods works in the usual way.

Usage

## S3 method for class 'spsur'anova(object, ..., lrtest = TRUE)## S3 method for class 'spsur'coef(object, ...)## S3 method for class 'spsur'fitted(object, ...)## S3 method for class 'spsur'logLik(object, ...)## S3 method for class 'spsur'residuals(object, ...)## S3 method for class 'spsur'vcov(object, ...)## S3 method for class 'spsur'print(x, digits = max(3L, getOption("digits") - 3L), ...)## S3 method for class 'spsur'plot(x, ci = 0.95, viewplot = TRUE, ...)

Arguments

object

aspsur object created byspsurml,spsur3sls orspsurtime.

...

further arguments passed to or from other methods.

lrtest

logical value to compute likelihood ratiotest for nested models in 'anova' method. Default =TRUE

x

similar toobject argument forprint() andplot functions.

digits

number of digits to show in printed tables.Default: max(3L, getOption("digits") - 3L).

ci

confidence level for the intervals in 'plot' method. Defaultci = 0.95

viewplot

logical value to show interactively the plots. Default =TRUE

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

Examples

rm(list = ls()) # Clean memorydata(spc)Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSAspcsur.sim <-spsurml(formula = Tformula, data = spc, type = "sim")## Print Table       print(spcsur.sim)spcsur.slm <-spsurml(formula = Tformula, data = spc, type = "slm",                      listw = Wspc)# ANOVA table and LR test for nested models:anova(spcsur.sim, spcsur.slm)## Plot spatial and beta coefficients# Interactive plotplot(spcsur.slm)# Non-interactive plotif (require(gridExtra)) {  pl <- plot(spcsur.slm, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}

Print method for objects of class summary.spsur.

Description

Print method for objects of class summary.spsur.

Usage

## S3 method for class 'summary.spsur'print(x, digits = max(3L, getOption("digits") - 3L), ...)

Arguments

x

object of classsummary.spsur.

digits

number of digits to show in printed tables.Default: max(3L, getOption("digits") - 3L).

...

further arguments passed to or from other methods.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

See Also

summary.spsur.

Examples

 # See examples for \code{\link{spsurml}} or # \code{\link{spsur3sls}} functions.

Within/Exit mobility index and incidence COVID-19 at Spain provinces

Description

Weekly within/exit mobility indices and COVID-19 incidence in Spain at provincial level. A total of 17 weeks from February 21 to May 21. Every week starts on a Friday and ends on the following Thursday. All travels are expressed with respect to the pre-COVID week of February 14th-20th, 2020 (week0). A value lower than 1indicate a reduction of the mobility. Upper values than 1 indicate an increase in the mobility with respectto the reference week (week0).

Usage

spain.covid

Format

A data frame with 850 rows and 11 variables:

province

Province name coded as a factor

indiv

Province coded as a number

time

Number of week afther pre-COVID (week0: February 14th-20th, 2020). time=1 (week1, February 21th-27th); time=2 (week2,February 28th-March 5th);....

Within

Mobility index within of the province. See details for a formal definition

Exits

Mobility index of exits of the province. See details for a formal definition

Emergence

Dummy variable. 1 if the Emergence State ("Estado de Alarma") is active in the week "time" but economicactivity of essential services are allowed. 0 in anoter case.The Emergence State was active in Spain from February 14th, 2020 to May 21th, 2020

EmergenceTotal

Dummy variable. 1 if the Emergence State ("Estado de Alarma") is active in the week "time" and economic activity of essential services are not allowed. 0 in anoter case

Old65

Percentage of population aged 65 and older in the province

Density

Inhabitants (in thousands) per km^2 in the province

Essential

Percentage of firms in the province "indiv" with essential activities (food, health) over the total of firms in the province "indiv" in the province (e.g., food, heath and some economic subsectors of industry and construction)

Incidence

Weekly incidence in the week "time-1" in logs

Details

Source

The National Statistics Institute
https://www.ine.es/en/index.htm
Instituto de Salud Carlos III
https://cnecovid.isciii.es/covid19/


Spain geometry

Description

A sf object with the Spanish geometry

Usage

spain.covid.sf

Format

A sf object with the Spanish geometry

PROVINCIA

province name coded as a factor

ID_INE

province coded as a number


A classical Spatial Phillips-Curve

Description

A data set from Anselin (1988, p. 203-2011) used to estimate a SpatialPhillips-Curve for 25 counties in South-West Ohio for two timeperiods (1981 and 1983).

Usage

spc

Format

A data frame with 25 rows and 10 variables:

COUNTY

County coded as a name.

WAGE83

Changes in wage rates for 1983.

UN83

Inverse unemployment rate in 1983.

NMR83

Net migration rate 1983.

SMSA

Dummy variable to identify counties defined asStandard Metropolitan Statistical Areas (SMSA = 1).

WAGE82

Changes in wage rates for 1982.

WAGE81

Changes in wage rates for 1981.

UN80

Inverse unemployment rate in 1980.

NMR80

Net migration rate 1983.

WAGE80

changes in wage rates.

geometry

geometry of sf object.

Source

Anselin (1988, p. 203-211)

References


Three Stages Least Squares estimation,3sls, of spatial SUR models.

Description

The function estimates spatial SUR models using three stagesleast squares, where the instruments are obtained from the spatial lagsof theX variables, assumed to be exogenous. The number of equations, time periods and spatial units is not restricted. The user can choose between a Spatial Durbin Model or a Spatial Lag Model, as described below. The estimation procedure allows for the introduction of linear restrictions on the\beta parameters associated to the regressors.

Usage

spsur3sls (formula = NULL, data = NULL, na.action,                  R = NULL, b = NULL, listw = NULL,                   zero.policy = NULL, X= NULL, Y = NULL, G = NULL,                   N = NULL, Tm = NULL, p = NULL,                    type = "slm", Durbin = NULL, maxlagW = NULL,                  trace = TRUE)

Arguments

formula

An object typeFormula similar to objects created with the packageFormula describing the equations to be estimated in the model. This model may contain several responses (explained variables) and a varying number of regressors in each equation.

data

An object of class data.frame or a matrix.

na.action

A function (defaultoptions("na.action")),can also bena.omit orna.exclude with consequences for residuals and fitted values. It may be necessary to setzero.policy toTRUE because this subsetting may create no-neighbour observations.

R

A row vector of order(1xpr) with the set ofr linear constraints on thebeta parameters. Thefirst restriction appears in the firstp terms,the second restriction in the nextp terms and so on. Default =NULL.

b

A column vector of order(rx1) with the values of the linear restrictions on thebeta parameters. Default =NULL.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

zero.policy

Similar to the corresponding parameter oflagsarlm function inspatialreg package. IfTRUE assign zero to the lagged value of zones without neighbours, ifFALSE assignNA - causingspsurml() to terminate with an error. Default =NULL.

X

A data matrix of order(NTmGxp) with the observationsof the regressors. The number of covariates in the SUR model isp =sum(p_{g}) wherep_{g} is the number of regressors (including the intercept) in the g-th equation,g = 1,...,G). The specification of "X" is only necessary if not available aFormula and a data frame. Default =NULL.

Y

A column vector of order(NTmGx1), with the observations of the explained variables. The ordering of the data must be (first) equation, (second) time dimension and (third) cross-sectional/spatial units. The specification ofY is only necessary if not available aFormulaand a data frame. Default =NULL.

G

Number of equations.

N

Number of cross-section or spatial units

Tm

Number of time periods.

p

Number of regressors by equation, including the intercept.p can be a row vector of order(1xG), if the number of regressors is not the same for all the equations, or a scalar, if theG equations have the same number of regressors. The specification ofp is only necessary if not available aFormula and a data frame.

type

Type of spatial model, restricted to cases where lags of the explained variable appear in the rigth hand side of the equations. There are two possibilities: "slm" or "sdm". Default = "slm".

Durbin

If a formula object and model is type "sdm" the subset of explanatory variables to lag for each equation.

maxlagW

Maximum spatial lag order of the regressors employed to produce spatial instruments for the spatial lags of the explained variables. Default = 2. Note that in case oftype="sdm", the default value formaxlagW is set to 3 because the first lag of the regressors,WX_{tg}, can not be used as spatial instruments.

trace

A logical value to show intermediate results during the estimation process. Default =TRUE.

Details

spsur3sls can be used to estimate two groups of spatial models:

wherey_{tg} and\epsilon_{tg} are(Nx1) vectors,corresponding to the g-th equation and time period t;X_{tg} is the matrix of regressors, of orderN \times p_g. Moreover,\rho_{g} is a spatial coefficient andW is a(NxN) spatial weighting matrix.

By default, the input of this function is an object created withFormula and a data frame. However,spsur3sls also allows for the direct specification of vectorY and matrixX, with the explained variables and regressors respectively, as inputs (these terms may be the result, for example, ofdgp_spsur).

spsur3sls is a Least-Squares procedure in three-stages designed to circumvent the endogeneity problems due to the presence of spatial lags of the explained variable in the right hand side of the equations do the SUR. The instruments are produced internally byspsur3sls using a sequence of spatial lags of theX variables, which are assumed to be exogenous. The user must define the number of (spatial) instruments to be used in the procedure, through the argumentmaxlagW (i.e. maxlagW = 3). Then, the collection of instruments generated is[WX_{tg}; W*WX_{tg}; W*W*WX_{tg}]. In the case of aSDM, the first lag of theX matrix already is in the equation and cannot be used as instrument. In the example above, the list of instruments for aSDM model would be[W^{2}X_{tg}; W^{3}X_{tg}].

Thefirst stage of the procedure consists in the least squares of theY variables on the set of instruments. From this estimation, the procedure retains the estimates ofYin the so-calledYls variables. In thesecond stage, theY variables that appear in the right hand side of the equation are substituted byYls and the SUR modelis estimated by Least Squares. Thethird stage improves the estimates of the second stage through a Feasible Generalized Least Squares estimation of the parameters of the model,using the residuals of thesecond stage to estimate theSigma matrix.

The argumentsR andb allows to introduce linear restrictions on thebeta coefficients of theG equations.spsur3sls, first, introduces the linear restrictions in the SUR model and builds, internally, the corresponding constrainedSUR model. Then, the function estimates the restricted model which is shown in the output. The function does not compute the unconstrained model nor test for the linear restrictions. The user may ask for the unconstrained estimation using anotherspsurmlestimation. Moreover, the functionwald_betas obtains the Wald test of a set of linear restrictions for an object created previously byspsurml orspsur3sls.

Value

Object ofspsur class with the output of the three-stages least-squares estimation of the specified spatial model.A list with:

call Matched call.
type Type of model specified.
Durbin Value ofDurbin argument.
coefficients Estimated coefficients for the regressors.
deltas Estimated spatial coefficients.
rest.se Estimated standard errors for the estimates of\beta coefficients.
deltas.se Estimated standard errors for the estimates of the spatial coefficients.
resvar Estimated covariance matrix for the estimates ofbeta's and spatial coefficients.
R2 Coefficient of determination for each equation, obtained as the squared of the correlation coefficient between the corresponding explained variable and fitted values.
R2 pooledGlobal coefficient of determination obtained for the set of theG equations. It is computed in the same way than uniequationalR2 but joining the dependent variable and fitted values in single vectors instead of one vector for each equation.
Sigma Estimated covariance matrix for the residuals of theG equations.
residuals Residuals of the model.
df.residuals Degrees of freedom for the residuals.
fitted.values Estimated values for the dependent variables.
G Number of equations.
N Number of cross-sections or spatial units.
Tm Number of time periods.
p Number of regressors by equation (including intercepts).
Y Ifdata isNULL, vectorY of the explained variables of the SUR model.
X Ifdata isNULL, matrixX of the regressors of the SUR model.
W Spatial weighting matrix.
zero.policy Logical value ofzero.policy .
listw_styleStyle of neighborhood matrixW.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,stsls,wald_betas

Examples

######################################################### CLASSIC PANEL DATA (G=1; Tm>1)  ############################################################# Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)## A SUR model without spatial effectsrm(list = ls()) # Clean memorydata(spc)lwspc <- spdep::mat2listw(Wspc, style = "W")Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA## A SUR-SLM model (3SLS Estimation)spcsur_slm_3sls <-spsur3sls(formula = Tformula, data = spc,                            type = "slm", listw = lwspc)summary(spcsur_slm_3sls)print(spcsur_slm_3sls)if (require(gridExtra)) {  pl <- plot(spcsur_slm_3sls, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_spsur3sls, package="spsur")## A SUR-SDM model (3SLS Estimation)spcsur_sdm_3sls <- spsur3sls(formula = Tformula, data = spc,                             type = "sdm", listw = lwspc)summary(spcsur_sdm_3sls)if (require(gridExtra)) {  pl <- plot(spcsur_sdm_3sls, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}rm(spcsur_sdm_3sls)## A SUR-SDM model with different spatial lags in each equation TformulaD <-  ~ UN83 + NMR83 + SMSA | UN80 + NMR80   spcsur_sdm2_3sls <-spsur3sls(formula = Tformula, data = spc,                             type = "sdm", listw = lwspc,                             Durbin = TformulaD) summary(spcsur_sdm2_3sls)if (require(gridExtra)) {  pl <- plot(spcsur_sdm2_3sls, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}rm(spcsur_sdm2_3sls)####################################################  MULTI-DIMENSIONAL PANEL DATA (G>1; Tm>1) ######################################################## Example 3: Homicides + Socio-Economics (1960-90)# Homicides and selected socio-economic characteristics for continental# U.S. counties.# Data for four decennial census years: 1960, 1970, 1980 and 1990.# https://geodacenter.github.io/data-and-lab/ncovr/rm(list = ls()) # Clean memorydata(NCOVR, package = "spsur")nbncovr <- spdep::poly2nb(NCOVR.sf, queen = TRUE)## Some regions with no links...lwncovr <- spdep::nb2listw(nbncovr, style = "W", zero.policy = TRUE)Tformula <- HR80  | HR90 ~ PS80 + UE80 | PS90 + UE90## A SUR-SLM modelNCOVRSUR_slm_3sls <- spsur3sls(formula = Tformula, data = NCOVR.sf,                                type = "slm", zero.policy = TRUE,                               listw = lwncovr, trace = FALSE)summary(NCOVRSUR_slm_3sls)if (require(gridExtra)) {  pl <- plot(NCOVRSUR_slm_3sls, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}rm(NCOVRSUR_slm_3sls)

General Spatial 3SLS for systems of spatial equations.

Description

The function estimates spatial SUR models using general spatial three stages least squares. This is a system instrumental variable procedure which also include GMM estimation when there is spatial correlations in the errors.The procedure allows for additional endogenous regressors inaddition to spatial lags of the dependent variable. It could be applied to "slm", "sdm", "sem" and "sarar" spatial models. Furthermore, for non-spatial models including endogenous regressors ("iv"), it could be used to estimate using instrumental variables and Feasible Generalized Least Squares.

Usage

spsurgs3sls(formula = NULL, data = NULL, na.action,                  listw = NULL, zero.policy = NULL,                   type = "slm", Durbin = FALSE,                  endog = NULL, instruments = NULL,                  lag.instr = FALSE, initial.value = 0.2,                   het = FALSE, trace = TRUE)

Arguments

formula

An object typeFormula similar to objects created with the packageFormula describing the equations to be estimated in the model. This model may contain several responses (explained variables) and a varying number of regressors in each equation.

data

An object of class data.frame or a matrix.

na.action

A function (defaultoptions("na.action")),can also bena.omit orna.exclude with consequences for residuals and fitted values. It may be necessary to setzero.policy toTRUE because this subsetting may create no-neighbour observations.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

zero.policy

Similar to the corresponding parameter oflagsarlm function inspatialreg package. (NxN) instead of a listw object. Default = NULL.

type

Type of spatial model specification: "sim", "iv","slm", "sem", "sdm" or "sarar" . Default = "slm".

Durbin

If a formula object and model is type "sdm"the subset of explanatory variables to lag for each equation.

endog

Additional endogenous variables. DefaultNULL. If notNULL should be specified as aFormula with no dependent variable. Examples: ~ x1 | x2 (x1 endogeous regressor for the first equation and x2 endogeneous regressor for the second equation) or ~ x1 | . (x1 endogenous regressor for the first equation and none endogenous regressors for the second equation)

instruments

external instruments. DefaultNULL. If notNULL should be specified as a formula with no dependent variable in the same way than previousendog argument.

lag.instr

should the external instruments be spatially lagged?

initial.value

he initial value for rho. It can be either numeric(default is 0.2) or set to 'SAR', in which case the optimization will start from the estimated coefficient of a regression of the 2SLS residuals over their spatial lag (i.e. a spatial AR model)

het

defaultFALSE: ifTRUE uses the methods developed for heteroskedasticity for each equation. Wrapper usingspreg function.

trace

A logical value to show intermediate results during the estimation process. Default =TRUE.

Details

spsurg3sls generalize thespreg functionto multiequational spatial SUR models. The methodology to estimatespatial SUR models by Generalized 3SLS follows the steps outlined inKelejian and Piras (pp. 304-305). The summary of the algorithm isthe next one:

Value

Object ofspsur class with the output of the three-stages least-squares estimation of the specified spatial model.A list with:

call Matched call.
type Type of model specified.
Durbin Value ofDurbin argument.
coefficients Estimated coefficients for the regressors.
deltas Estimated spatial coefficients.
rest.se Estimated standard errors for the estimates of\beta coefficients.
deltas.se Estimated standard errors for the estimates of the spatial coefficients.
resvar Estimated covariance matrix for the estimates ofbeta's and spatial coefficients.
R2 Coefficient of determination for each equation, obtained as the squared of the correlation coefficient between the corresponding explained variable and its estimates.spsur3sls also shows aglobal coefficient of determination obtained, in the same manner, for the set ofG equations.
Sigma Estimated covariance matrix for the residuals of theG equations.
residuals Residuals of the model.
df.residuals Degrees of freedom for the residuals.
fitted.values Estimated values for the dependent variables.
G Number of equations.
N Number of cross-sections or spatial units.
Tm Number of time periods.
p Number of regressors by equation (including intercepts).
Y Ifdata isNULL, vectorY of the explained variables of the SUR model.
X Ifdata isNULL, matrixX of the regressors of the SUR model.
W Spatial weighting matrix.
zero.policy Logical value ofzero.policy .
listw_styleStyle of neighborhood matrixW.

Author(s)

Fernando Lópezfernando.lopez@upct.es
Román Mínguezroman.minguez@uclm.es
Jesús Murjmur@unizar.es

References

See Also

spreg,spsur3sls,stsls,spsurml

Examples

#### Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)rm(list = ls()) # Clean memorydata(spc)lwspc <- spdep::mat2listw(Wspc, style = "W")## No endogenous regressors  Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA## Endogenous regressors and InstrumentsTformula2 <- WAGE83 | WAGE81 ~  NMR83 | NMR80 ## Endogenous regressors: UN83 , UN80## Instrumental variable: SMSA## A IV model with endogenous regressors only in first equationspciv <- spsurgs3sls(formula = Tformula2, data = spc,                      type = "iv", listw = lwspc,                      endog = ~ UN83 | .,                       instruments = ~ SMSA | .)summary(spciv)print(spciv)########################################################################### A SLM model with endogenous regressors spcslm <- spsurgs3sls(formula = Tformula2, data = spc,                              endog = ~ UN83 | .,                               instruments = ~ SMSA |.,                              type = "slm",                               listw = lwspc)summary(spcslm)print(spcslm)                           impacts_spcslm <- impactspsur(spcslm, listw = lwspc, R = 1000)summary(impacts_spcslm[[1]], zstats = TRUE, short = TRUE)summary(impacts_spcslm[[2]], zstats = TRUE, short = TRUE)########################################################################### A SDM model with endogenous regressors spcsdm <- spsurgs3sls(formula = Tformula2, data = spc,                   endog = ~ UN83 | UN80,                    instruments = ~ SMSA | SMSA,                   type = "sdm", listw = lwspc,                   Durbin =  ~  NMR83 | NMR80)summary(spcsdm)## Durbin only in one equationspcsdm2 <- spsurgs3sls(formula = Tformula2, data = spc,                    endog = ~ UN83 | UN80,                     instruments = ~ SMSA | SMSA,                    type = "sdm", listw = lwspc,                    Durbin =  ~  NMR83 | .)summary(spcsdm2)########################################################################### A SEM model with endogenous regressors spcsem <- spsurgs3sls(formula = Tformula2, data = spc,                      endog = ~ UN83 | UN80,                       instruments = ~ SMSA | SMSA,                      type = "sem", listw = lwspc)summary(spcsem)print(spcsem)                           ########################################################################### A SARAR model with endogenous regressors spcsarar <- spsurgs3sls(formula = Tformula2, data = spc,                        endog = ~ UN83 | UN80,                         instruments = ~ SMSA | SMSA,                        type = "sarar", listw = lwspc)summary(spcsarar)print(spcsarar)                           impacts_spcsarar <- impactspsur(spcsarar, listw = lwspc, R = 1000)summary(impacts_spcsarar[[1]], zstats = TRUE, short = TRUE)summary(impacts_spcsarar[[2]], zstats = TRUE, short = TRUE)

Maximum likelihood estimation of spatial SUR model.

Description

This function estimates spatial SUR models using maximum-likelihood methods.The number of equations, time periods and cross-sectional units is not restricted.The user can choose between different spatial specifications as described below.The estimation procedure allows for the introduction of linear restrictions on the\beta parameters associated to the regressors.

Usage

spsurml(formula = NULL, data = NULL, na.action,               listw = NULL, type = "sim", Durbin = NULL,               method = "eigen", zero.policy = NULL, interval = NULL,               trs = NULL, R = NULL, b = NULL, X = NULL, Y = NULL,                G = NULL, N = NULL, Tm = NULL,p = NULL,                control = list() )

Arguments

formula

An object typeFormula similar to objects created with the packageFormula describing the equations to be estimated in the model. This model may contain several responses (explained variables) and a varying number of regressors in each equation.

data

An object of class data.frame or a matrix.

na.action

A function (defaultoptions("na.action")),can also bena.omit orna.exclude with consequences for residuals and fitted values. It may be necessary to setzero.policy toTRUE because this subsetting may create no-neighbour observations.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

type

Type of spatial model specification: "sim","slx", "slm", "sem", "sdm", "sdem", "sarar" or "gnm". Default = "sim".

Durbin

If a formula object and model is type "sdm", "sdem" or "slx" the subset of explanatory variables to lag for each equation.

method

Similar to the corresponding parameter oflagsarlm function inspatialreg package. "eigen" (default) - the Jacobian is computed as the product of (1 - rho*eigenvalue) usingeigenw, and "spam" or "Matrix_J" for strictly symmetric weights lists of styles "B" and "C", or made symmetric by similarity (Ord, 1975, Appendix C) if possible for styles "W" and "S", using code from the spam or Matrix packages to calculate the determinant; "Matrix" and "spam_update" provide updating Cholesky decomposition methods; "LU" provides an alternative sparse matrix decomposition approach. In addition, there are "Chebyshev" and Monte Carlo "MC" approximate log-determinant methods; the Smirnov/Anselin (2009) trace approximation is available as "moments". Three methods: "SE_classic", "SE_whichMin", and "SE_interp" are provided experimentally, the first to attempt to emulate the behaviour of Spatial Econometrics toolbox ML fitting functions. All use grids of log determinant values, and the latter two attempt to ameliorate some features of "SE_classic".

zero.policy

Similar to the corresponding parameter oflagsarlm function inspatialreg package. IfTRUE assign zero to the lagged value of zones without neighbours, ifFALSE assignNA - causingspsurml() to terminate with an error. Default =NULL.

interval

Search interval for autoregressive parameter.Default =NULL.

trs

Similar to the corresponding parameter oflagsarlm function inspatialreg package.DefaultNULL, if given, a vector of powered spatial weights matrix traces output bytrW.

R

A row vector of order(1xpr) with the set ofr linear constraints on thebeta parameters. Thefirst restriction appears in the firstp terms,the second restriction in the nextp terms and so on. Default =NULL.

b

A column vector of order(rx1) with the values of the linear restrictions on thebeta parameters. Default =NULL.

X

A data matrix of order(NTmGxp) with the observationsof the regressors. The number of covariates in the SUR model isp =sum(p_{g}) wherep_{g} is the number of regressors (including the intercept) in the g-th equation,g = 1,...,G). The specification of "X" is only necessary if not available aFormula and a data frame. Default =NULL.

Y

A column vector of order(NTmGx1), with the observations of the explained variables. The ordering of the data must be (first) equation, (second) time dimension and (third) cross-sectional/spatial units. The specification ofY is only necessary if not available aFormulaand a data frame. Default =NULL.

G

Number of equations.

N

Number of cross-section or spatial units

Tm

Number of time periods.

p

Number of regressors by equation, including the intercept.p can be a row vector of order(1xG), if the number of regressors is not the same for all the equations, or a scalar, if theG equations have the same number of regressors. The specification ofp is only necessary if not available aFormula and a data frame.

control

list of additional arguments.

Details

The list of (spatial) models that can be estimated with thespsurml function are:

Value

Object ofspsur class with the output of the maximum-likelihood estimation of the specified spatial SUR model. A list with:

call Matched call.
type Type of model specified.
method Value ofmethod argument to compute the Jacobian
Durbin Value ofDurbin argument.
coefficients Estimated coefficients for the regressors.
deltas Estimated spatial coefficients.
rest.se Estimated standard errors for the estimates ofbeta.
deltas.se Estimated standard errors for the estimates of the spatial coefficients (deltas).
resvar Estimated covariance matrix for the estimates ofbeta's and spatial coefficients (deltas).
LL Value of the likelihood function at the maximum-likelihood estimates.
R2 Coefficient of determination for each equation, obtained as the squared of the correlation coefficient between the corresponding explained variable and fitted values.
R2 pooledGlobal coefficient of determination obtained for the set of theG equations. It is computed in the same way than uniequationalR2 but joining the dependent variable and fitted values in single vectors instead of one vector for each equation.
Sigma Estimated covariance matrix for the residuals of theG equations.
fdHess Logical value offdHess argument when computing numerical covariances.
residuals Residuals of the model.
df.residuals Degrees of freedom for the residuals.
fitted.values Estimated values for the dependent variables.
BP Value of the Breusch-Pagan statistic to test the null hypothesis of diagonality among the errors of theG equations.
LMM Marginal Lagrange Multipliers, LM(\rho|\lambda) and LM(\lambda|\rho), to test for omitted spatial effects in the specification.
G Number of equations.
N Number of cross-sections or spatial units.
Tm Number of time periods.
p Number of regressors by equation (including intercepts).
Y Ifdata isNULL, vectorY of the explained variables of the SUR model.
X Ifdata isNULL, matrixX of the regressors of the SUR model.
W Spatial weighting matrix.
zero.policy Logical value ofzero.policy .
intervalSearch interval for spatial parameter.
listw_styleStyle of neighborhood matrixW.
trs EitherNULL or vector of powered spatial weights matrix traces output bytrW.
insert Logical value to check ifis.null(trs).

Control arguments

tol Numerical value for the tolerance for the estimation algorithm until convergence. Default = 1e-3.
maxit Maximum number of iterations until convergence; it must be an integer value. Default = 200.
trace A logical value to show intermediate results during the estimation process. Default =TRUE.
fdHess Compute variance-covariance matrix using the numerical hessian. Suited for large samples. Default =FALSE
Imult default 2; used for preparing the Cholesky decompositions for updating in the Jacobian function
super ifNULL (default), set toFALSE to use a simplicial decomposition for the sparse Cholesky decomposition and method "Matrix_J", set to as.logical(NA) for method "Matrix", ifTRUE, use a supernodal decomposition
cheb_q default 5; highest power of the approximating polynomial for the Chebyshev approximation
MC_p default 16; number of random variates
MC_m default 30; number of products of random variates matrix and spatial weights matrix
spamPivot default "MMD", alternative "RCM"
in_coef default 0.1, coefficient value for initial Cholesky decomposition in "spam_update"
type default "MC", used with method "moments"; alternatives "mult" and "moments", for use if trs is missing
correct defaultTRUE, used with method "moments" to compute the Smirnov/Anselin correction term
trunc defaultTRUE, used with method "moments" to truncate the Smirnov/Anselin correction term
SE_method default "LU", may be "MC"
nrho default 200, as in SE toolbox; the size of the first stage lndet grid; it may be reduced to for example 40
interpn default 2000, as in SE toolbox; the size of the second stage lndet grid
SElndet defaultNULL, may be used to pass a pre-computed SE toolbox style matrix of coefficients and their lndet values to the "SE_classic" and "SE_whichMin" methods
LU_order defaultFALSE; used in "LU_prepermutate", note warnings given for lu method
pre_eig defaultNULL; may be used to pass a pre-computed vector of eigenvalues

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsur3sls,lagsarlm,lmtestspsur,wald_betas,lr_betas

Examples

######################################################### CROSS SECTION DATA (G>1; Tm=1) ############################################################# Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)rm(list = ls()) # Clean memorydata(spc)Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSAspcsur.sim <- spsurml(formula = Tformula, data = spc, type = "sim")summary(spcsur.sim)# All the coefficients in a single table.print(spcsur.sim)# Plot of the coefficients of each equation in different graphsplot(spcsur.sim) ## A SUR-SLX model ## (listw argument can be either a matrix or a listw object )spcsur.slx <- spsurml(formula = Tformula, data = spc, type = "slx",   listw = Wspc, Durbin = TRUE)summary(spcsur.slx)# All the coefficients in a single table.print(spcsur.slx)# Plot of the coefficients in a single graphif (require(gridExtra)) {  pl <- plot(spcsur.slx, viewplot = FALSE)  grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                         nrow = 2)} ## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_spsurml, package="spsur")  ### A SUR-SLM modelspcsur.slm <- spsurml(formula = Tformula, data = spc, type = "slm",                      listw = Wspc)summary(spcsur.slm)if (require(gridExtra)) {  pl <- plot(spcsur.slm, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}### A SUR-SDM modelspcsur.sdm <- spsurml(formula = Tformula, data = spc, type = "sdm",                      listw = Wspc)summary(spcsur.sdm)print(spcsur.sdm)if (require(gridExtra)) {  pl <- plot(spcsur.sdm, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}## A SUR-SDM model with different spatial lags in each equationTformulaD <- ~ UN83 + NMR83 + SMSA | UN80spcsur.sdm2 <- spsurml(formula = Tformula, data = spc, type = "sdm",                       listw = Wspc, Durbin = TformulaD)summary(spcsur.sdm2)if (require(gridExtra)) {  pl <- plot(spcsur.sdm2, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}###########################################################  CLASSIC PANEL DATA G=1; Tm>1   ################################################################ Example 2: Homicides + Socio-Economics (1960-90)## Homicides and selected socio-economic characteristics for continental## U.S. counties.## Data for four decennial census years: 1960, 1970, 1980 and 1990.## \url{https://geodacenter.github.io/data-and-lab/ncovr/}### It usually requires 1-2 minutes maximum...rm(list = ls()) # Clean memory### Read NCOVR.sf objectdata(NCOVR, package = "spsur")nbncovr <- spdep::poly2nb(NCOVR.sf, queen = TRUE)### Some regions with no links...lwncovr <- spdep::nb2listw(nbncovr, style = "W", zero.policy = TRUE)Tformula <- HR80  | HR90 ~ PS80 + UE80 | PS90 + UE90### A SUR-SIM modelNCOVRSUR.sim <- spsurml(formula = Tformula, data = NCOVR.sf, type = "sim")summary(NCOVRSUR.sim)if (require(gridExtra)) {  pl <- plot(NCOVRSUR.sim, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]], nrow = 3)}### A SUR-SLX modelNCOVRSUR.slx <- spsurml(formula = Tformula, data = NCOVR.sf, type = "slx",                        listw = lwncovr, zero.policy = TRUE)print(NCOVRSUR.slx)if (require(gridExtra)) {  pl <- plot(NCOVRSUR.slx, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]], nrow = 2)}### A SUR-SLM model### method = "Matrix" (Cholesky) instead of "eigen"### (fdHess = TRUE to compute numerical covariances )NCOVRSUR.slm <- spsurml(formula = Tformula, data = NCOVR.sf,                        type = "slm", listw = lwncovr, method = "Matrix",                        zero.policy = TRUE, control = list(fdHess = TRUE))summary(NCOVRSUR.slm)if (require(gridExtra)) {  pl <- plot(NCOVRSUR.slm, viewplot = FALSE)   grid.arrange(pl$lplbetas[[1]], pl$lplbetas[[2]],                pl$pldeltas, nrow = 3)}# LR test for nested modelsanova(NCOVRSUR.sim, NCOVRSUR.slm)

Estimation of SUR models for simple spatial panels (G=1).

Description

This function estimates SUR models for simple spatial panel datasets.spsurtime is restricted, specifically, to cases where there is only one equation,G=1, and a varying number of spatial units,N, and time periods,Tm. The SUR structure appearsin form of serial dependence among the error terms corresponding to the same spatial unit.Note that it is assumed that all spatial units share a common pattern of serial dependence.

The user can choose between different types of spatial specifications, as described below, and the estimation algorithms allow for the introduction of linear restrictions on the\beta parametersassociated to the regressors. The spatial panels with SUR structure can be estimated by maximum-likelihood methods or three-stages least squares procedures, using spatial instrumental variables.

Usage

spsurtime (formula, data, time, na.action,                  listw = NULL, type = "sim", Durbin = NULL,                   method = "eigen", fit_method = "ml", maxlagW = NULL,                  zero.policy = NULL, interval = NULL, trs = NULL,                  R = NULL, b = NULL, demean = FALSE, control = list() )

Arguments

formula

An object typeFormula similar to objects created with the packageFormula describing the equations to be estimated in the model. This model may contain several responses (explained variables) and a varying number of regressors in each equation.

data

An object of class data.frame or a matrix.

time

Time variable.

na.action

A function (defaultoptions("na.action")),can also bena.omit orna.exclude with consequences for residuals and fitted values. It may be necessary to setzero.policy toTRUE because this subsetting may create no-neighbour observations.

listw

Alistw object created for example bynb2listw fromspatialreg package; ifnb2listw not given, set to the same spatial weights as thelistw argument. It canalso be a spatial weighting matrix of order(NxN) instead ofalistw object. Default =NULL.

type

Type of spatial model specification: "sim","slx", "slm", "sem", "sdm", "sdem", "sarar" or "gnm". Default = "sim".

Durbin

If a formula object and model is type "sdm", "sdem" or "slx" the subset of explanatory variables to lag for each equation.

method

Similar to the corresponding parameter oflagsarlm function inspatialreg package. "eigen" (default) - the Jacobian is computed as the product of (1 - rho*eigenvalue) usingeigenw, and "spam" or "Matrix_J" for strictly symmetric weights lists of styles "B" and "C", or made symmetric by similarity (Ord, 1975, Appendix C) if possible for styles "W" and "S", using code from the spam or Matrix packages to calculate the determinant; "Matrix" and "spam_update" provide updating Cholesky decomposition methods; "LU" provides an alternative sparse matrix decomposition approach. In addition, there are "Chebyshev" and Monte Carlo "MC" approximate log-determinant methods; the Smirnov/Anselin (2009) trace approximation is available as "moments". Three methods: "SE_classic", "SE_whichMin", and "SE_interp" are provided experimentally, the first to attempt to emulate the behaviour of Spatial Econometrics toolbox ML fitting functions. All use grids of log determinant values, and the latter two attempt to ameliorate some features of "SE_classic".

fit_method

Method of estimation for the spatial panel SUR model, eitherml or3sls. Default =ml.

maxlagW

Maximum spatial lag order of the regressors employed to produce spatial instruments for the spatial lags of the explained variables. Default = 2. Note that in case oftype = "sdm", the default value formaxlagW is set to 3 because the first lag of the regressors,WX_{tg}, can not be used as spatial instruments.

zero.policy

Similar to the corresponding parameter oflagsarlm function inspatialreg package. IfTRUE assign zero to the lagged value of zones without neighbours, ifFALSE assignNA - causingspsurml() to terminate with an error. Default =NULL.

interval

Search interval for autoregressive parameter.Default =NULL.

trs

EitherNULL or vector of powered spatial weights matrix traces output bytrW. Default =NULL.

R

A row vector of order(1xpr) with the set ofr linear constraints on thebeta parameters. Thefirst restriction appears in the firstp terms,the second restriction in the nextp terms and so on. Default =NULL.

b

A column vector of order(rx1) with the values of the linear restrictions on thebeta parameters. Default =NULL.

demean

Logical value to allow for the demeaning of panel data. In this case,spsurml subtracts the individual mean to each spatial or cross-sectional unit. Default =FALSE.

control

list of additional arguments.

Details

Functionspsurtime only admits a formula, created withFormula and a dataset of classdata.frame ormatrix. That is, the data cannot be uploaded using data matricesY andX provided for other functions in this package.
The argumenttime selects the variable, in thedata.frame, associated to the time dimension in the panel dataset. Thenspsurtime operates as in Anselin (1988), that is,each cross-section is treated as if it were an equation in a SUR model, which now hasTm 'equations' andN individuals.
The SUR structure appears because there is serial dependence in the errors of each individual in the panel. The serial dependence in the errors is not parameterized, but estimated non-parametrically in theSigma covariance matrix returned by the function. An important constraint to mention is that the serial dependence assumed to be the same for all individuals in the sample. Serial dependence among individuals is excluded from Anselin approach.

Value

Anspsur object with the output of the maximum-likelihood or three-stages least-squares estimation of the spatial panel SUR model.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,spsur3sls,wald_betas,wald_deltas,lmtestspsur,lr_betas

Examples

############################################ PANEL DATA (G=1; Tm>1) ######################################### Example 1:rm(list = ls()) # Clean memorydata(spc)lwspc <- spdep::mat2listw(Wspc, style = "W")N <- nrow(spc)Tm <- 2index_time <- rep(1:Tm, each = N)index_indiv <- rep(1:N, Tm)WAGE <- c(spc$WAGE83, spc$WAGE81)UN <- c(spc$UN83, spc$UN80)NMR <- c(spc$NMR83, spc$NMR80)SMSA <- c(spc$SMSA, spc$SMSA)pspc <- data.frame(index_indiv, index_time, WAGE, UN,                    NMR, SMSA)form_pspc <- WAGE ~ UN + NMR + SMSAform2_pspc <- WAGE | NMR ~ UN  | UN + SMSA# SLM pspc_slm <- spsurtime(formula = form_pspc, data = pspc,                       listw = lwspc,                      time = pspc$index_time,                       type = "slm", fit_method = "ml")summary(pspc_slm) pspc_slm2 <- spsurtime(formula = form2_pspc, data = pspc,                       listw = lwspc,                      time = pspc$index_time,                       type = "slm", fit_method = "ml")summary(pspc_slm2)## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_spsurtime, package="spsur") ### Example 2:rm(list = ls()) # Clean memory### Read NCOVR.sf objectdata(NCOVR, package="spsur")nbncovr <- spdep::poly2nb(NCOVR.sf, queen = TRUE)### Some regions with no links...lwncovr <- spdep::nb2listw(nbncovr, style = "W", zero.policy = TRUE)N <- nrow(NCOVR.sf)Tm <- 4index_time <- rep(1:Tm, each = N)index_indiv <- rep(1:N, Tm)pHR <- c(NCOVR.sf$HR60, NCOVR.sf$HR70, NCOVR.sf$HR80, NCOVR.sf$HR90)pPS <- c(NCOVR.sf$PS60, NCOVR.sf$PS70, NCOVR.sf$PS80, NCOVR.sf$PS90)pUE <- c(NCOVR.sf$UE60, NCOVR.sf$UE70, NCOVR.sf$UE80, NCOVR.sf$UE90)pNCOVR <- data.frame(indiv = index_indiv, time = index_time,                     HR = pHR, PS = pPS, UE = pUE)form_pHR <- HR ~ PS + UE## SIMpHR_sim <- spsurtime(formula = form_pHR, data = pNCOVR,                     time = pNCOVR$time, type = "sim", fit_method = "ml")summary(pHR_sim)## SLM by 3SLS. pHR_slm <- spsurtime(formula = form_pHR, data = pNCOVR, listw = lwncovr,                     time = pNCOVR$time, type = "slm",                      fit_method = "3sls")summary(pHR_slm)############################# Wald tests about betas in spatio-temporal models### H0: equal betas for PS in equations 1, 3 and 4.R <- matrix(0, nrow = 2, ncol = 12) ## nrow = number of restrictions ## ncol = number of beta parametersR[1, 2] <- 1; R[1, 8] <- -1 # PS beta coefficient in equations 1 equal to 3R[2, 2] <- 1; R[2, 11] <- -1 # PS beta coefficient in equations 1 equal to 4b <- matrix(0, nrow=2, ncol=1)wald_betas(pHR_sim , R = R , b = b) # SIM modelwald_betas(pHR_slm , R = R , b = b) # SLM model############################# Wald tests about spatial-parameters in############################# spatio-temporal models### H0: equal rhos in slm model for equations 1 and 2.R2 <- matrix(0, nrow = 1, ncol = 4)R2[1, 1] <- 1; R2[1, 2] <- -1b2 <- matrix(0, nrow = 1, ncol = 1)wald_deltas(pHR_slm, R = R2, b = b2)

Summary of estimated objects of classspsur.

Description

This function summarizes estimatedspsur objects. The tables in the outputinclude basic information for each equation. The report also shows other complementary resultscorresponding to the SUR model like the(GxG) covariance matrix of the residuals of theequations of the SUR, the estimated log-likelihood, the Breusch-Pagan diagonality test or the MarginalLagrange Multiplier, LMM, tests of spatial dependence.

Usage

## S3 method for class 'spsur'summary(object, ...)

Arguments

object

Anspsur object estimated usingspsurml,spsur3sls orspsurtime functions.

...

further arguments passed to or from other methods.

Value

An object of classsummary.spsur

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

See Also

print.summary.spsur;spsurml;spsur3sls.

Examples

 # See examples for \code{\link{spsurml}} or # \code{\link{spsur3sls}} functions.

Wald tests on thebeta coefficients

Description

The functionwald_betas can be seen as a complement to the restricted estimation procedures included in the functionsspsurml andspsur3sls.wald_betas obtains Wald tests for sets of linear restrictions on the coefficients\beta of the SUR model.The restrictions may involve coefficients of the same equation or coefficients from different equations. The function has great flexibility in this respect. Note thatwald_betas is more general thanlr_betas in the sense that the last functiononly allows to test for restrictions of homogeneity of subsets of\beta coefficients among the different equations in the SUR model, and in a maximum-likelihood framework.

In order to work withwald_betas, the model on which the linear restrictions are to be tested needs to exists as anspsur object. Using the information contained in the object,wald_betas obtains the corresponding Wald estatistic for the null hypotheses specified by the user through theR row vector andb column vector, used also inspsurml andspsur3sls. The function shows the value of the Wald teststatistics and its associated p-values.

Usage

wald_betas (obj , R , b)

Arguments

obj

Anspsur object created byspsurml,spsur3sls orspsurtime.

R

A row vector of order(1xPr) showing the setofr linear constraints on the\beta parameters. Thefirst restriction appears in the firstK terms inR, thesecond restriction in the nextK terms and so on.

b

A column vector of order(rx1) with the values of the linear restrictions on the\beta parameters.

Value

Object ofhtest class including the Waldstatistic, the corresponding p-value, the degrees offreedom and the values of the sample estimates.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

References

See Also

spsurml,spsur3sls,lr_betas

Examples

## VIP: The output of the whole set of the examples can be examined ## by executing demo(demo_wald_betas, package="spsur")######################################################### CROSS SECTION DATA (G=1; Tm>1) ############################################################## Example 1: Spatial Phillips-Curve. Anselin (1988, p. 203)rm(list = ls()) # Clean memorydata(spc)lwspc <- spdep::mat2listw(Wspc, style = "W")Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA### Estimate SUR-SLM modelspcsur.slm <- spsurml(formula = Tformula, data = spc,                       type = "slm", listw = lwspc)summary(spcsur.slm)### H_0: equality between SMSA coefficients in both equations.R1 <- matrix(c(0,0,0,1,0,0,0,-1), nrow=1)b1 <- matrix(0, ncol=1)wald_betas(spcsur.slm, R = R1, b = b1)

Wald tests for spatial parameters coefficients.

Description

Functionwald_deltas obtains Wald tests for linear restrictions on the spatial coefficients of a SUR model that has been estimated previously through the functionspsurml. The restrictions can affect to coefficients of the same equation(i.e.,\lambda_{g}=\rho_{g} forall g) or can involve coefficients from different equations (i.e.,\lambda_{g}=\lambda_{h}). The function has great flexibility in this respect. Note thatwald_deltas only works in a maximum-likelihood framework.

In order to work withwald_betas, the model on which the linear restrictions are to be tested needs to exists as anspsur object. Using the information contained in the object,wald_deltas obtains the corresponding Wald statistic for the null hypotheses specified by the user through theR row vector andb column vector discussed, used also inspsurml. The function shows the resulting Wald test statistics and their corresponding p-values.

Usage

wald_deltas (obj , R , b)

Arguments

obj

Anspsur object created byspsurml,spsur3sls orspsurtime.

R

A row vector of order(1xGr) or(1x2Gr) showing the set ofr linear constraints on the spatial parameters. The last case is reserved to "sarar" models where there appearG parameters\lambda_{g} andG parameters\rho_{g},2G spatial in total. Thefirst restriction appears in the firstG terms inR (2G for the "sarar" case), the second restriction in the nextG terms (2G for the"sarar" case) and so on.

b

A column vector of order(rx1) with the values of the linear restrictions on the\beta parameters.

Value

Object ofhtest including the Waldstatistic, the corresponding p-value, the degrees offreedom and the values of the sample estimates.

Author(s)

Fernando Lopezfernando.lopez@upct.es
Roman Minguezroman.minguez@uclm.es
Jesus Murjmur@unizar.es

See Also

spsurml,spsur3sls

Examples

######################################################### CROSS SECTION DATA (G>1; Tm=1) #########################################################rm(list = ls()) # Clean memorydata(spc, package = "spsur")lwspc <- spdep::mat2listw(Wspc, style = "W")Tformula <- WAGE83 | WAGE81 ~ UN83 + NMR83 + SMSA | UN80 + NMR80 + SMSA################################### Estimate SUR-SLM modelspcsur.slm <-spsurml(formula = Tformula, data = spc,                        type = "slm", listw = lwspc)summary(spcsur.slm)## H_0: equality of the lambda parameters of both equations.R1 <- matrix(c(1,-1), nrow=1)b1 <- matrix(0, ncol=1)wald_deltas(spcsur.slm, R = R1, b = b1)

[8]ページ先頭

©2009-2025 Movatter.jp