The functions contained in this R package can be used to fit a multivariable geographically weighted regression model to spatial data measured with sampling error. Please see the paper for a more complete description of its motivation and adjustment it makes.
An example implementation in R is the following:
### generating simulated data
spatial_covariance=0.5^toeplitz(0:99) # AR(1) spatial covariance matrix
X=cbind(1,matrix(rnorm(100*3),100,3)) # simulated covariates (true and fixed)
b=c(0,1,0,-1) # true fixed effects of X on outcome Y
Y=c(mvnfast::rmvn(1,X%*%b,spatial_covariance)) # simulated outcome (true)
u=cbind(0,matrix(rnorm(100*3,0,1/10),100,3)) # measurement error variances for X
q=rnorm(100,0,1/10) # measurement error variances for Y
x=X+u # observed covariates
y=Y+q # observed outcome
distance_matrix=toeplitz(0:99) # matrix of distances between spatial locations
u_matrix=cbind(0,matrix(1/10,100,3)) # matrix of X's measurement error standard deviations
q_vector=rep(1/10,100) # vector of Y's measurement error standard deviations
### fitting the measurement error bias-corrected geographically weighted regression model
fit=spatialME(x,y,u_matrix,q_vector,distance_matrix,1)
str(fit)
List of 4
$ Est : num [1:100, 1:4] 0.5494 -0.4894 -0.8088 -0.4229 0.0999 ...
$ SE : num [1:100, 1:4] 0.834 1.933 2.046 4.472 0.281 ...
$ CI_Lo: num [1:100, 1:4] -1.09 -4.28 -4.82 -9.19 -0.45 ...
$ CI_Up: num [1:100, 1:4] 2.18 3.3 3.2 8.34 0.65 ...str(fit) displays the location-specific estimated covariate effect sizes (fit$Est), their jackknife standard errors (fit$SE), and their corresponding 95% confidence intervals (fit$CI_Lo, fit$CI_Up).