Learn R Programming

sphet (version 2.0)

impacts.ols_sphet: Generate impacts for objects of class ols_sphet created in sphet

Description

Generate impacts for objects of class ols_sphet created in sphet

Usage

# S3 method for ols_sphet
impacts(
  obj,
  ...,
  tr = NULL,
  R = NULL,
  listw = NULL,
  evalues = NULL,
  tol = 1e-06,
  empirical = FALSE,
  Q = NULL
)

Value

Estimate of the Average Total, Average Direct, and Average Indirect Effects

Arguments

obj

A spreg spatial regression object created by spreg with model ="lag"

...

Arguments passed through to methods in the coda package

tr

A vector of traces of powers of the spatial weights matrix created using trW, 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

R

If given, simulations are used to compute distributions for the impact measures, returned as mcmc objects

listw

a listw object

evalues

vector of eigenvalues of spatial weights matrix for impacts calculations

tol

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

empirical

Argument passed to mvrnorm (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 if tr is given

Examples

Run this code
data(boston, package="spData")
Wb <- as(spdep::nb2listw(boston.soi), "CsparseMatrix") 
ev <- eigen(Wb)$values
trMatb <- spatialreg::trW(Wb, type="mult")

lm.D <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) +  AGE + log(DIS), 
          data = boston.c, listw = Wb, model = "ols", Durbin =  TRUE)
summary(lm.D)
impacts(lm.D)
summary(impacts(lm.D))

lm.D2 <- spreg(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) +  AGE + log(DIS), 
               data = boston.c, listw = Wb, model = "ols", Durbin =  ~AGE)
summary(lm.D2)
impacts(lm.D2)
summary(impacts(lm.D2))

lm.D3 <- spreg(log(CMEDV) ~ CRIM + ZN +  CHAS + I(NOX^2) + I(RM^2) +  AGE, 
               data = boston.c, listw = Wb, model = "ols", Durbin =  ~AGE + INDUS )
summary(lm.D3)
impacts(lm.D3)
summary(impacts(lm.D3))

require("sf", quietly=TRUE)
columbus <- st_read(system.file("shapes/columbus.shp", package="spData")[1], quiet=TRUE)
col.gal.nb <- spdep::read.gal(system.file("weights/columbus.gal", package="spData")[1])
listw <- spdep::nb2listw(col.gal.nb)
knear <- spdep::knearneigh(cbind(columbus$X, columbus$Y), 5)
knb <- spdep::knn2nb(knear)
dist <- spdep::nbdists(knb, cbind(columbus$X, columbus$Y))
k5d <- spdep::nb2listw(knb, glist = dist, style = "B")
class(k5d) <- c("listw", "nb", "distance")
lm.D4 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin=TRUE,
               model = "ols")
summary(lm.D4)
impacts(lm.D4)

lm.D5 <- spreg(CRIME ~ INC + HOVAL, columbus, listw, Durbin= ~ INC,
               model = "ols")
summary(lm.D5)
impacts(lm.D5)
summary(impacts(lm.D5))

lm.D6 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC,
               model = "ols")
summary(lm.D6)
summary(impacts(lm.D6))
if (FALSE) {
lm.D7 <- spreg(CRIME ~ INC + HOVAL, columbus, listw,
                 model = "ols", HAC = TRUE, distance = k5d, 
                                  type = "Triangular")
summary(lm.D7)
impacts(lm.D7)
summary(impacts(lm.D7))
}
lm.D8 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin=TRUE,
               model = "ols", distance = k5d, type = "Triangular")
summary(lm.D8)
impacts(lm.D8)
summary(impacts(lm.D8))


lmD.9 <- spreg(CRIME ~ INC + HOVAL, data = columbus, listw = listw, Durbin= ~ INC,
               model = "ols", distance = k5d, type = "Parzen")
               
impacts(lmD.9)

lmD.10 <- spreg(CRIME ~ HOVAL, columbus, listw, Durbin= ~ INC,
                model = "ols", distance = k5d, type = "Bisquare")
summary(lmD.10)
summary(impacts(lmD.10))

Run the code above in your browser using DataLab