Skip to content

jpkeller/spconf

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
R
 
 
man
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

spconf

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 Szprio (2020).

Installation

The spconf package can be installed by running

devtools::install_github("jpkeller/spconf")

Computing Effective Range

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

References

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.

About

R Package for Spatial Confounding Adjustment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages