-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
57 lines (40 loc) · 1.7 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
library(spconf)
```
# 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 Szpiro (2020).
## Installation
The `spconf` package can be installed by running
```
devtools::install_github("kpkeller/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.
```{r}
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)
```
## 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.