Learn R Programming

spdgp (version 0.1.0)

sim_slx: Simulate Spatially Lagged X (SLX) model

Description

This function simulates the y values of an SLX model, where the dependent variable is influenced by both the original and spatially lagged x variables.

Usage

sim_slx(u, xb, wxg)

Value

A numeric vector

Arguments

u

an error vector

xb

predicted x values as calculated by make_xb()

wxg

predicted spatial lag effect as calculated by make_wxg()

References

spreg.dgp.dgp_slx

Examples

Run this code
ncol <- 20
n <- ncol^2
listw <- sim_grid_listw(ncol, ncol)  # Create spatial weights for a grid
u <- make_error(n, method = "normal")  # Simulate random errors
x <- make_x(n, method = "uniform")  # Generate x variables
xb <- make_xb(x, c(1, 2))  # Calculate xb using the original x and coefficients
wx <- make_wx(x, listw)  # Generate spatially lagged x variables
wxg <- make_wxg(wx, 0.5)  # Calculate the effect of the spatial lags
y <- sim_slx(u, xb, wxg)  # Simulate the SLX model outcome
df <- data.frame(y, x)
spatialreg::lmSLX(y ~ ., data = df, listw = listw)  # Estimate the SLX model

Run the code above in your browser using DataLab