R Package for Computing Scales of Spatial Smoothing for Confounding Adjustment
This package is designed to calculate the effective bandwidth of a spatial smoothing matrix, following the procedure described by Keller and Szpiro (2020).
The spconf
package can be installed by running
devtools::install_github("kpkeller/spconf")
The primary function is compute_effective_range()
. The function takes
a matrix of spline values X
, with the assumption that the splines are
nested to that adding additional columns increases the flexibility of
forms that can be fit. For each choice of degrees of freedom, the
function computes the effective range of the smoothing matrix.
M <- 16
tprs_df <- 8
si <- seq(0, 1, length=M+1)[-(M+1)]
gridcoords <- expand.grid(x=si, y=si)
tprsSC <- mgcv::smoothCon(mgcv::s(x, y, fx=TRUE, k=tprs_df + 1), data= gridcoords)
tprsX <- mgcv::PredictMat(tprsSC[[1]], data= gridcoords)
# Re-order the TPRS to put linear terms first
tprsX <- tprsX[, c(ncol(tprsX) + -1:0, 1:(ncol(tprsX)-2))]
colnames(tprsX) <- 1:ncol(tprsX)
compute_effective_range(X=tprsX,
coords=gridcoords,
newd=seq(0, 1, length=7),
df=3:8,
span=0.15)
#> Df = 3
#> Df = 4
#> Df = 5
#> Df = 6
#> Df = 7
#> Df = 8
#> 3 4 5 6 7 8
#> 3.886970 3.694037 3.543898 3.442408 3.346475 3.176590
Keller and Szpiro (2020). Selecting a scale for spatial confounding adjustment. Journal of the Royal Statistical Society, Series A https://doi.org/10.1111/rssa.12556.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.