Title: | Spatial Dynamic Panel Data Modeling |
---|---|
Description: | Spatial model calculation for static and dynamic panel data models, weights matrix creation and Bayesian model comparison. Bayesian model comparison methods were described by 'LeSage' (2014) <doi:10.1016/j.spasta.2014.02.002>. The 'Lee'-'Yu' transformation approach is described in 'Yu', 'De Jong' and 'Lee' (2008) <doi:10.1016/j.jeconom.2008.08.002>, 'Lee' and 'Yu' (2010) <doi:10.1016/j.jeconom.2009.08.001> and 'Lee' and 'Yu' (2010) <doi:10.1017/S0266466609100099>. |
Authors: | Rozeta Simonovska [aut, cre] |
Maintainer: | Rozeta Simonovska <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.0.5 |
Built: | 2025-02-06 04:57:29 UTC |
Source: | https://github.com/rozetasimonovska/sdpdmod |
Calculates log-marginal posterior probabilities for model comparison purposes.
blmpSDPD( formula, data, W, index, model = list("ols", "slx", "sar", "sdm", "sem", "sdem"), effect = "individual", ldet = NULL, lndetspec = list(m = NULL, p = NULL, sd = NULL), dynamic = FALSE, tlaginfo = list(ind = NULL), LYtrans = FALSE, incr = NULL, rintrv = TRUE, prior = "uniform", bprarg = 1.01 )
blmpSDPD( formula, data, W, index, model = list("ols", "slx", "sar", "sdm", "sem", "sdem"), effect = "individual", ldet = NULL, lndetspec = list(m = NULL, p = NULL, sd = NULL), dynamic = FALSE, tlaginfo = list(ind = NULL), LYtrans = FALSE, incr = NULL, rintrv = TRUE, prior = "uniform", bprarg = 1.01 )
formula |
a symbolic description for the model to be estimated |
data |
a data.frame |
W |
spatial weights matrix (row-normalized) |
index |
the indexes (names of the variables for the spatial and time component) |
model |
a list of models for which the Bayesian log-marginal posterior probabilities need to be calculated, list("ols","slx","sar","sdm","sem","sdem") |
effect |
type of fixed effects, c("none","individual","time","twoways"), default ="individual" |
ldet |
Type of computation of log-determinant, c("full","mc"). Default "full" for smaller problems, "mc" for large problems. |
lndetspec |
specifications for the calculation of the log-determinant |
dynamic |
logical, if TRUE time lag of the dependent variable is included. Default = FALSE |
tlaginfo |
specification for the time lag, default = list(ind=NULL), ind - i-th column in the data frame which represents the time lag |
LYtrans |
logical, default FALSE. If Lee-Yu transformation should be used for demeaning of the variables |
incr |
increment for vector of values for rho |
rintrv |
logical, default TRUE, calculates eigenvalues of W. If FALSE, the interval for rho is (-1,1). |
prior |
type of prior to be used c("uniform","beta"). Default "uniform" |
bprarg |
argument for the beta prior. Default = 1.01 |
For the Spatial Durbin Error Model (SDEM) the marginal distribution is:
For the Spatial Durbin Model (SDM) the marginal distribution is:
where is prior on
and
is prior on
,
either uniform
,
or beta prior;
No priors on beta and sige;
and
are the maximum and minimum eigenvalues of
W - spatial weights matrix;
for lag or error model and
for Durbin model;
X - matrix of
covariates.
For more details, see LeSage (2014).
Based on MatLab function log_marginal_panelprob.m.
In tlaginfo = list(ind = NULL):
ind i-th column in data which represents the time lag, if not specified then the lag from the dependent variable is created and the panel is reduced from nt to n(t-1)
A list
lmarginal |
log-marginal posterior |
probs |
model probability |
Rozeta Simonovska
LeSage, J. P., & Parent, O. (2007). Bayesian model averaging for spatial econometric models. Geographical Analysis, 39(3), 241-267.
LeSage, J. P. (2014). Spatial econometric panel data model specification: A Bayesian approach. Spatial Statistics, 9, 122-145.
## US States Production data data(Produc, package = "plm") ## Spatial weights row-normalized matrix of 48 US states data(usaww, package = "splm") isrownor(usaww) form1 <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp res1 <- blmpSDPD(formula = form1, data=Produc, W = usaww, index = c("state","year"), model = list("sar","sdm","sem","sdem"), effect = "twoways") res1 res2 <- blmpSDPD(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = list("sar","sdm","sem","sdem"), effect = "twoways", dynamic = TRUE) res2
## US States Production data data(Produc, package = "plm") ## Spatial weights row-normalized matrix of 48 US states data(usaww, package = "splm") isrownor(usaww) form1 <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp res1 <- blmpSDPD(formula = form1, data=Produc, W = usaww, index = c("state","year"), model = list("sar","sdm","sem","sdem"), effect = "twoways") res1 res2 <- blmpSDPD(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = list("sar","sdm","sem","sdem"), effect = "twoways", dynamic = TRUE) res2
Method for extracting coefficients of objects of class "SDPDm"
## S3 method for class 'SDPDm' coef(object, ...)
## S3 method for class 'SDPDm' coef(object, ...)
object |
object of class "SDPDm" |
... |
additional arguments to be passed |
Coefficients extracted from the model object of class "SDPDm".
Rozeta Simonovska
SDPDm
This function calculates the double-power distance matrix, for a given distance cutoff and a positive exponent.
DDistMat(distMat, distCutOff = NULL, powr = 2, mevn = FALSE)
DDistMat(distMat, distCutOff = NULL, powr = 2, mevn = FALSE)
distMat |
distance matrix |
distCutOff |
distance cutoff. Default = the maximal value from the distance matrix. |
powr |
power (positive exponent), default 2 |
mevn |
logical, default FALSE. If TRUE, max-eigenvalue normalization is performed. |
W is an nxn matrix with elements ,
, where
, if
and
, if
or
.
D is the cut-off distance point (maximum radius of influence),
is the distance between spatial units i and j,
and p is the power value (e.g. p = 2, 3, 4,...).
W |
spatial weights matrix (Default, not normalized) |
Rozeta Simonovska
data(gN3dist) ##distance in meters W1 <- DDistMat(distMat = gN3dist, distCutOff = 300000, powr = 3) ##distance cutoff in meters dist2 <- gN3dist/1000 ##in km W2 <- DDistMat(distMat = dist2, 300, 3) ##distance cutoff in kilometers
data(gN3dist) ##distance in meters W1 <- DDistMat(distMat = gN3dist, distCutOff = 300000, powr = 3) ##distance cutoff in meters dist2 <- gN3dist/1000 ##in km W2 <- DDistMat(distMat = dist2, 300, 3) ##distance cutoff in kilometers
This function calculates the spatial distance weights matrix (inverse, exponential or double-distance), with a given cutoff distance and a positive exponent (alpha).
DistWMat( distMat, distCutOff = NULL, type = "inverse", alpha = NULL, mevn = FALSE )
DistWMat( distMat, distCutOff = NULL, type = "inverse", alpha = NULL, mevn = FALSE )
distMat |
distance matrix |
distCutOff |
cutoff distance. Default = the maximal value from the distance matrix. |
type |
the type of distance matrix c("inverse","expo","doubled"). Default = "inverse". |
alpha |
power (positive exponent), default 1 if type="inverse", 0.01 if type="expo" and 2 if type="double" |
mevn |
logical, default FALSE. If TRUE, max-eigenvalue normalization is performed. |
W |
spatial weights matrix (Default, not normalized) |
Rozeta Simonovska
InvDistMat
ExpDistMat
DDistMat
vignette("spatial_matrices", package = "SDPDmod")
## distance between centroids of NUTS3 regions in Germany (in meters) data(gN3dist, package = "SDPDmod") ##inverse distance matrix with cutoff 100000 meters W1 <- DistWMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##distance in km ## normalized exponential distance matrix W2 <- DistWMat(distMat=dist2, distCutOff = 100, type = "expo", alpha = 2, mevn = TRUE)
## distance between centroids of NUTS3 regions in Germany (in meters) data(gN3dist, package = "SDPDmod") ##inverse distance matrix with cutoff 100000 meters W1 <- DistWMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##distance in km ## normalized exponential distance matrix W2 <- DistWMat(distMat=dist2, distCutOff = 100, type = "expo", alpha = 2, mevn = TRUE)
Maximum eigenvalue row normalization of a spatial weights matrix.
eignor(W)
eignor(W)
W |
spatial weights matrix |
W |
Eigenvalue normalized spatial weights matrix |
Rozeta Simonovska
data(gN3dist) dist2 <- gN3dist/1000 ##distance in km W <- InvDistMat(distMat = dist2, distCutOff = 100, powr = 2) Wnor <- eignor(W)
data(gN3dist) dist2 <- gN3dist/1000 ##distance in km W <- InvDistMat(distMat = dist2, distCutOff = 100, powr = 2) Wnor <- eignor(W)
This function calculates the (negative) exponential distance matrix, with a given cutoff distance and a positive exponent value.
ExpDistMat(distMat, distCutOff = NULL, expn = 0.01, mevn = FALSE)
ExpDistMat(distMat, distCutOff = NULL, expn = 0.01, mevn = FALSE)
distMat |
distance matrix |
distCutOff |
cutoff distance. Default = the maximal value from the distance matrix. |
expn |
positive exponent, default = 0.01 |
mevn |
logical, default FALSE. If TRUE, max-eigenvalue normalization is performed. |
W is an nxn matrix with elements , i, j = 1,..n, where
, if
and
, if
or
.
D is the distance cutoff point (maximum radius of influence),
is the distance between spatial units i and j, and
is the positive exponent (e.g.
= 0.01, 0.02,...).
W |
spatial weights matrix (Default, not normalized) |
Rozeta Simonovska
data(gN3dist) ##distance in meters W1 <- ExpDistMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##in km W2 <- ExpDistMat(distMat = dist2, distCutOff = 100, expn = 0.02) W2nor <- ExpDistMat(distMat = dist2, 100000, 0.001, mevn = TRUE)
data(gN3dist) ##distance in meters W1 <- ExpDistMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##in km W2 <- ExpDistMat(distMat = dist2, distCutOff = 100, expn = 0.02) W2nor <- ExpDistMat(distMat = dist2, 100000, 0.001, mevn = TRUE)
Distance between the centroids of NUTS3 regions in Germany
gN3dist
gN3dist
matrix of distances
Direct and indirect effects estimates
impactsSDPDm(res, NSIM = 200, sd = 12345)
impactsSDPDm(res, NSIM = 200, sd = 12345)
res |
an object of class 'SDPDm' |
NSIM |
number of simulations to be performed, default = 200 |
sd |
starting seed, default = 12345 |
For spatial dynamic panel data model:
Short term effects for kth explanatory variable:
Long term effects for kth explanatory variable:
The direct effect is the average of the diagonal elements, and the indirect effect is the average of the row sums of the non-diagonal elements of the matrix.
An object of class 'impactsSDPDm'
Rozeta Simonovska
This function calculates the inverse distances, with a given cutoff distance and a positive exponent.
InvDistMat(distMat, distCutOff = NULL, powr = 1, mevn = FALSE)
InvDistMat(distMat, distCutOff = NULL, powr = 1, mevn = FALSE)
distMat |
distance matrix |
distCutOff |
cutoff distance. Default = the maximal value from the distance matrix. |
powr |
power (positive exponent), default = 1 |
mevn |
logical, default FALSE. If TRUE, max-eigenvalue normalization is performed. |
W is an nxn matrix with elements , i,j=1,..n, where
, if
and
, if
or
.
D is the distance cutoff point (maximum radius of influence),
is the distance between spatial units i and j,
and
is the value for the exponent (e.g.
= 1, 2, 3, 4,...).
W |
weights matrix (Default, not normalized) |
Rozeta Simonovska
## distance between centroids of NUTS3 regions in Germany (in meters) data(gN3dist, package = "SDPDmod") ## inverse distance matrix with cutoff 100000 meters W1 <- InvDistMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##distance in km ## normalized distance matrix with cutoff 100km W2 <- InvDistMat(distMat = dist2, distCutOff=100, powr = 2, mevn = TRUE)
## distance between centroids of NUTS3 regions in Germany (in meters) data(gN3dist, package = "SDPDmod") ## inverse distance matrix with cutoff 100000 meters W1 <- InvDistMat(distMat = gN3dist, distCutOff = 100000) dist2 <- gN3dist/1000 ##distance in km ## normalized distance matrix with cutoff 100km W2 <- InvDistMat(distMat = dist2, distCutOff=100, powr = 2, mevn = TRUE)
Checks if a spatial weights matrix is row-normalized.
isrownor(W)
isrownor(W)
W |
spatial weights matrix |
Logical value. If the weights matrix is row-normalized such that all rows sum up to 1, the value is TRUE.
Rozeta Simonovska
data("usa46", package="SDPDmod") isrownor(usa46)
data("usa46", package="SDPDmod") isrownor(usa46)
This function finds the m nearest neighbors, given a matrix of distances.
mNearestN(distMat, m = 5, listv = FALSE, rn = FALSE)
mNearestN(distMat, m = 5, listv = FALSE, rn = FALSE)
distMat |
distance matrix |
m |
number of nearest neighbors, default value 5 |
listv |
logical, default FALSE. If TRUE the list of neighbors should also be returned |
rn |
logical, default FALSE. If TRUE, the spatial weights matrix will be row-normalized |
W |
spatial weights matrix |
nlist |
list of indexes of the m nearest neighbors |
Rozeta Simonovska
data(gN3dist, package = "SDPDmod") fournn <- mNearestN(gN3dist, m = 4) mat1 <- rownor(fournn) tennn <- mNearestN(gN3dist, 10, listv = TRUE, rn = TRUE) mat2 <- tennn$W
data(gN3dist, package = "SDPDmod") fournn <- mNearestN(gN3dist, m = 4) mat1 <- rownor(fournn) tennn <- mNearestN(gN3dist, 10, listv = TRUE, rn = TRUE) mat2 <- tennn$W
Finds the 1th to m-th order neighbors matrix.
mOrdNbr(sf_pol = NULL, m = 1, neigbs = NULL, listv = FALSE, rn = FALSE)
mOrdNbr(sf_pol = NULL, m = 1, neigbs = NULL, listv = FALSE, rn = FALSE)
sf_pol |
spatial polygons object |
m |
the order of neighbors up to which they will be included in the weights matrix, default 1 |
neigbs |
neighbors list, default NULL |
listv |
logical, default FALSE. If TRUE the list of neighbors should also be returned |
rn |
logical, default FALSE. If TRUE, the weight matrix will be row-normalized |
W |
spatial weights matrix |
nlist |
list of neighbors |
Rozeta Simonovska
library("sf") ger <- st_read(system.file("shape/GermanyNUTS3.shp", package = "SDPDmod")) m1thn <- mOrdNbr(ger) m4thn <- mOrdNbr(ger, 4) mat1 <- rownor(m4thn) m4thn2<- mOrdNbr(ger, 4, listv = TRUE, rn = TRUE) mat2 <- m4thn2$W
library("sf") ger <- st_read(system.file("shape/GermanyNUTS3.shp", package = "SDPDmod")) m1thn <- mOrdNbr(ger) m4thn <- mOrdNbr(ger, 4) mat1 <- rownor(m4thn) m4thn2<- mOrdNbr(ger, 4, listv = TRUE, rn = TRUE) mat2 <- m4thn2$W
Method for printing the results of objects of class "blmpSDPD"
## S3 method for class 'blmpSDPD' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'blmpSDPD' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
object of class "blmpSDPD" |
digits |
number of digits |
... |
additional arguments to be passed |
No return value
Rozeta Simonovska
Method for sprinting the results of objects of class "SDPDm"
## S3 method for class 'SDPDm' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'SDPDm' print(x, digits = max(3, getOption("digits") - 3), ...)
x |
object of class "SDPDm" |
digits |
number of digits |
... |
additional arguments to be passed |
No return value
Rozeta Simonovska
SDPDm
Method for printing the summary the results of objects of class "impactsSDPDm"
## S3 method for class 'summary.impactsSDPDm' print(x, ...)
## S3 method for class 'summary.impactsSDPDm' print(x, ...)
x |
summary object of class "impactsSDPDm" |
... |
additional arguments to be passed |
Rozeta Simonovska
Method for printing the summary the results of objects of class "SDPDm"
## S3 method for class 'summary.SDPDm' print(x, ...)
## S3 method for class 'summary.SDPDm' print(x, ...)
x |
summary object of class "SDPDm" |
... |
additional arguments to be passed |
No return value
Rozeta Simonovska
SDPDm
Row-normalization of a spatial weights matrix.
rownor(W)
rownor(W)
W |
spatial weights matrix |
W |
row-normalized spatial weights matrix |
Rozeta Simonovska
library("sf") ger <- st_read(system.file("shape/GermanyNUTS3.shp", package = "SDPDmod")) W <- mOrdNbr(ger, 3) Wnor <- rownor(W)
library("sf") ger <- st_read(system.file("shape/GermanyNUTS3.shp", package = "SDPDmod")) W <- mOrdNbr(ger, 3) Wnor <- rownor(W)
This function estimates spatial panel model with fixed effects for static or dynamic model. It includes the transformation approach suggested by Yu et al (2008) and Lee and Yu (2010).
SDPDm( formula, data, W, index, model = "sar", effect = "individual", ldet = NULL, lndetspec = list(p = NULL, m = NULL, sd = NULL), dynamic = FALSE, tlaginfo = list(ind = NULL, tl = TRUE, stl = TRUE), LYtrans = FALSE, incr = NULL, rintrv = TRUE, demn = FALSE, DIRtrans = FALSE )
SDPDm( formula, data, W, index, model = "sar", effect = "individual", ldet = NULL, lndetspec = list(p = NULL, m = NULL, sd = NULL), dynamic = FALSE, tlaginfo = list(ind = NULL, tl = TRUE, stl = TRUE), LYtrans = FALSE, incr = NULL, rintrv = TRUE, demn = FALSE, DIRtrans = FALSE )
formula |
a symbolic description for the (static) model to be estimated, not including the dynamic component |
data |
a data.frame |
W |
spatial weights matrix |
index |
the indexes (Names of the variables for the spatial and time component. The spatial is first and the time second.) |
model |
a models to be calculated, c("sar","sdm"), default = "sar" |
effect |
type of fixed effects, c("none","individual","time","twoways"), default ="individual" |
ldet |
type of computation of log-determinant, c("full","mc"). Default "full" for smaller problems, "mc" for large problems. |
lndetspec |
specifications for the calculation of the log-determinant for mcmc calculation. Default list(p=NULL,m=NULL,sd=NULL), if the number of spatial units is >1000 then list(p=30,m=30,sd=12345) |
dynamic |
logical, if TRUE time lag of the dependent variable is included. Default = FALSE |
tlaginfo |
specification for the time lag, default = list(ind=NULL,tl=FALSE,stl=FALSE), see details |
LYtrans |
logical, default FALSE. If the Lee-Yu transformation should be used for bias correction |
incr |
increment for vector of values for rho |
rintrv |
logical, default TRUE, calculates eigenvalues of W. If FALSE, the interval for rho is (-1,1) |
demn |
logical, if Lee-Yu transformation for demeaning of the variables to remove fixed effects is performed (only used in static models). Default FALSE |
DIRtrans |
logical, if direct transformation of variables should be used. Default, FALSE (only used in dynamic models with "twoways" effects) |
Based on MatLab functions sar_jihai.m, sar_jihai_time.m and sar_panel_FE.m
In tlaginfo = list(ind = NULL, tl = TRUE, stl = TRUE):
ind i-th column in data which represents the time lag, if not specified then the lag from the dependent variable is created and the panel is reduced from nt to n(t-1)
tl logical, default TRUE. If TRUE
(the lagged dependent variable in time is included)
stl logical, default TRUE. If TRUE
(the lagged dependent variable in space and time is included)
An object of class "SDPDm"
coefficients |
coefficients estimate of the model parameters (coefficients1 for dynamic model) |
rho |
spatial coefficient |
sige |
residuals variance |
llik |
the value of the log likelihood function |
... |
Rozeta Simonovska
Yu, J., De Jong, R., & Lee, L. F. (2008). Quasi-maximum likelihood estimators for spatial dynamic panel data with fixed effects when both n and T are large. Journal of Econometrics, 146(1), 118-134.
Lee, L. F., & Yu, J. (2010). Estimation of spatial autoregressive panel data models with fixed effects. Journal of Econometrics, 154(2), 165-185.
Lee, L. F., & Yu, J. (2010). A spatial dynamic panel data model with both time and individual fixed effects. Econometric Theory, 564-597.
vignette("spatial_model", package = "SDPDmod")
library("SDPDmod") data(Produc, package = "plm") data(usaww, package = "splm") form1 <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp mod1 <- SDPDm(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = "sar", effect = "individual", LYtrans = TRUE) summary(mod1) imp1 <- impactsSDPDm(mod1) summary(imp1) mod2 <- SDPDm(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = "sdm", effect = "twoways", LYtrans = TRUE, dynamic = TRUE, tlaginfo=list(ind = NULL, tl = TRUE, stl = TRUE)) summary(mod2)
library("SDPDmod") data(Produc, package = "plm") data(usaww, package = "splm") form1 <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp mod1 <- SDPDm(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = "sar", effect = "individual", LYtrans = TRUE) summary(mod1) imp1 <- impactsSDPDm(mod1) summary(imp1) mod2 <- SDPDm(formula = form1, data = Produc, W = usaww, index = c("state","year"), model = "sdm", effect = "twoways", LYtrans = TRUE, dynamic = TRUE, tlaginfo=list(ind = NULL, tl = TRUE, stl = TRUE)) summary(mod2)
Method for summarizing the results of objects of class "impactsSDPDm"
## S3 method for class 'impactsSDPDm' summary(object, ...)
## S3 method for class 'impactsSDPDm' summary(object, ...)
object |
object of class "impactsSDPDm" |
... |
additional arguments to be passed |
Summary of impacts
Rozeta Simonovska
SDPDm
Method for summarizing the results of objects of class "SDPDm"
## S3 method for class 'SDPDm' summary(object, ...)
## S3 method for class 'SDPDm' summary(object, ...)
object |
object of class "SDPDm" |
... |
additional arguments to be passed |
Summary of SDPDm
Rozeta Simonovska
SDPDm
Spatial weights matrix of 46 USA states
usa46
usa46
binary coded matrix