Title: | Space-Time Change of Support |
---|---|
Description: | Spatio-temporal change of support (STCOS) methods are designed for statistical inference on geographic and time domains which differ from those on which the data were observed. In particular, a parsimonious class of STCOS models supporting Gaussian outcomes was introduced by Bradley, Wikle, and Holan <doi:10.1002/sta4.94>. The 'stcos' package contains tools which facilitate use of STCOS models. |
Authors: | Andrew M. Raim [aut, cre], Scott H. Holan [aut, res], Jonathan R. Bradley [aut, res], Christopher K. Wikle [aut, res] |
Maintainer: | Andrew M. Raim <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1 |
Built: | 2024-11-13 06:40:25 UTC |
Source: | CRAN |
An sf
object with ACS estimates for:
Boone County, Missouri
Table B19013
Block group level geography
Years 2013 - 2017
acs5_2013 acs5_2014 acs5_2015 acs5_2016 acs5_2017
acs5_2013 acs5_2014 acs5_2015 acs5_2016 acs5_2017
sf
objects.
An object of class sf
(inherits from data.frame
) with 87 rows and 9 columns.
An object of class sf
(inherits from data.frame
) with 87 rows and 9 columns.
An object of class sf
(inherits from data.frame
) with 85 rows and 9 columns.
An object of class sf
(inherits from data.frame
) with 87 rows and 9 columns.
An object of class sf
(inherits from data.frame
) with 87 rows and 9 columns.
This dataset was assembled using shapefiles from the tigris
package
and ACS estimates from the American FactFinder website on 2/28/2019.
See data-prep-aff.R
in the Columbia example code for details.
American FactFinder has since been deprecated, and similar data are
available at http://data.census.gov.
A convenience function to convert output from sf::st_touches
to a sparse matrix as defined in the Matrix
package.
adjacency_matrix(dom)
adjacency_matrix(dom)
dom |
An |
Returns a matrix A
whose (i,j)th entry contains a 1 if
areal units dom[i,]
and dom[j,]
are adjacent;
0 otherwise.
An adjacency matrix
data("acs_sf") dom = acs5_2013[1:4,] A = adjacency_matrix(dom)
data("acs_sf") dom = acs5_2013[1:4,] A = adjacency_matrix(dom)
Space-Time bisquare basis on areal data.
areal_spacetime_bisquare(dom, period, knots, w_s, w_t, control = NULL)
areal_spacetime_bisquare(dom, period, knots, w_s, w_t, control = NULL)
dom |
An |
period |
A numeric vector of time periods |
knots |
Spatio-temporal knots
|
w_s |
Spatial radius for the basis. |
w_t |
Temporal radius for the basis. |
control |
A |
Notes about arguments:
knots
may be provided as either an sf
or sfc
object, or as a
matrix of points.
If an sf
or sfc
object is provided for knots
,
three-dimensional
POINT
entries are expected in st_geometry(knots)
.
Otherwise, knots
will be interpreted as an numeric matrix.
If knots
is an sf
or sfc
object, it is checked
to ensure the coordinate system matches dom
.
For each area in the given domain, and time period
compute the basis
functions
for . Here,
represent spacetime_bisquare basis functions defined at the point
level using
,
,
, and
.
The basis requires an integration which may be computed using one
of two methods. The mc
method uses a Monte Carlo approximation
based on a random sample of locations from
a uniform distribution on area
. The
rect
method uses
a simple quadrature approximation
Here, the bounding box st_bbox(A)
is divided evenly into a grid of
rectangles, each of size
.
Each
is a point from the
th
rectangle, for
and
.
Due to the treatment of and
as objects in a
Euclidean space, this basis is more suitable for coordinates from a map
projection than coordinates based on a globe representation.
The control
argument is a list which may provide any of the following:
method
specifies computation method: mc
or rect
.
Default is mc
.
mc_reps
is number of repetitions to use for mc
.
Default is 1000.
nx
is number of x-axis points to use for rect
method. Default is 50.
ny
is number of y-axis points to use for rect
method. Default is 50.
report_period
is an integer; print a message with progress each
time this many areas are processed. Default is Inf
so that message
is suppressed.
verbose
is a logical; if TRUE
print descriptive
messages about the computation. Default is FALSE
.
mc_sampling_factor
is a positive number; an oversampling factor
used to compute blocksize
in the rdomain function. I.e.,
blocksize = ceiling(mc_sampling_factor * mc_reps)
. Default
is 1.2.
A sparse matrix whose
th row
is
Other bisquare:
areal_spatial_bisquare()
,
spacetime_bisquare()
,
spatial_bisquare()
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) seq_t = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y, t = seq_t) knots_sf = st_as_sf(knots, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") # Create a simple domain (of rectangles) to evaluate shape1 = matrix(c(0.0,0.0, 0.5,0.0, 0.5,0.5, 0.0,0.5, 0.0,0.0), ncol=2, byrow=TRUE) shape2 = shape1 + cbind(rep(0.5,5), rep(0.0,5)) shape3 = shape1 + cbind(rep(0.0,5), rep(0.5,5)) shape4 = shape1 + cbind(rep(0.5,5), rep(0.5,5)) sfc = st_sfc( st_polygon(list(shape1)), st_polygon(list(shape2)), st_polygon(list(shape3)), st_polygon(list(shape4)) ) dom = st_sf(data.frame(geoid = 1:length(sfc), geom = sfc)) rad = 0.5 period = c(0.4, 0.7) areal_spacetime_bisquare(dom, period, knots, w = rad, w_t = 1) areal_spacetime_bisquare(dom, period, knots_sf, w_s = rad, w_t = 1) # Plot the (spatial) knots and the (spatial) domain at which we evaluated # the basis. plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") plot(dom[,1], col = NA, add = TRUE) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) seq_t = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y, t = seq_t) knots_sf = st_as_sf(knots, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") # Create a simple domain (of rectangles) to evaluate shape1 = matrix(c(0.0,0.0, 0.5,0.0, 0.5,0.5, 0.0,0.5, 0.0,0.0), ncol=2, byrow=TRUE) shape2 = shape1 + cbind(rep(0.5,5), rep(0.0,5)) shape3 = shape1 + cbind(rep(0.0,5), rep(0.5,5)) shape4 = shape1 + cbind(rep(0.5,5), rep(0.5,5)) sfc = st_sfc( st_polygon(list(shape1)), st_polygon(list(shape2)), st_polygon(list(shape3)), st_polygon(list(shape4)) ) dom = st_sf(data.frame(geoid = 1:length(sfc), geom = sfc)) rad = 0.5 period = c(0.4, 0.7) areal_spacetime_bisquare(dom, period, knots, w = rad, w_t = 1) areal_spacetime_bisquare(dom, period, knots_sf, w_s = rad, w_t = 1) # Plot the (spatial) knots and the (spatial) domain at which we evaluated # the basis. plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") plot(dom[,1], col = NA, add = TRUE) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
Spatial bisquare basis on areal data.
areal_spatial_bisquare(dom, knots, w, control = NULL)
areal_spatial_bisquare(dom, knots, w, control = NULL)
dom |
An |
knots |
Knots |
w |
Radius for the basis. |
control |
A |
Notes about arguments:
knots
may be provided as either an sf
or sfc
object, or as a
matrix of points.
If an sf
or sfc
object is provided for knots
,
two-dimensional
POINT
entries are expected in st_geometry(knots)
.
Otherwise, knots
will be interpreted as an numeric matrix.
If knots
is an sf
or sfc
object, it is checked
to ensure the coordinate system matches dom
.
For each area in the given domain, compute an the basis functions
for . Here,
represent
spatial_bisquare basis functions defined at the point level
using
and
.
The basis requires an integration which may be computed using one
of two methods. The mc
method uses
based on a random sample of locations from
a uniform distribution on area
. The
rect
method uses
a simple quadrature approximation
Here, the bounding box st_bbox(A)
is divided evenly into a grid of
rectangles, each of size
.
Each
is a point from the
th
rectangle, for
and
.
Due to the treatment of and
as objects in a
Euclidean space, this basis is more suitable for coordinates from a map
projection than coordinates based on a globe representation.
The control
argument is a list which may provide any of the following:
method
specifies computation method: mc
or rect
.
Default is mc
.
mc_reps
is number of repetitions to use for mc
.
Default is 1000.
nx
is number of x-axis points to use for rect
method. Default is 50.
ny
is number of y-axis oints to use for rect
method. Default is 50.
report_period
is an integer; print a message with progress each
time this many areas are processed. Default is Inf
so that message
is suppressed.
verbose
is a logical; if TRUE
print descriptive
messages about the computation. Default is FALSE
.
mc_sampling_factor
is a positive number; an oversampling factor
used to compute blocksize
in the rdomain function. I.e.,
blocksize = ceiling(mc_sampling_factor * mc_reps)
. Default
is 1.2.
A sparse matrix whose
th row
is
Other bisquare:
areal_spacetime_bisquare()
,
spacetime_bisquare()
,
spatial_bisquare()
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y) knots_sf = st_as_sf(knots, coords = c("x","y"), crs = NA, agr = "constant") # Create a simple domain (of rectangles) to evaluate shape1 = matrix(c(0.0,0.0, 0.5,0.0, 0.5,0.5, 0.0,0.5, 0.0,0.0), ncol=2, byrow=TRUE) shape2 = shape1 + cbind(rep(0.5,5), rep(0.0,5)) shape3 = shape1 + cbind(rep(0.0,5), rep(0.5,5)) shape4 = shape1 + cbind(rep(0.5,5), rep(0.5,5)) sfc = st_sfc( st_polygon(list(shape1)), st_polygon(list(shape2)), st_polygon(list(shape3)), st_polygon(list(shape4)) ) dom = st_sf(data.frame(geoid = 1:length(sfc), geom = sfc)) rad = 0.5 areal_spatial_bisquare(dom, knots, rad) areal_spatial_bisquare(dom, knots_sf, rad) # Plot the knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") plot(dom[,1], col = NA, add = TRUE) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y) knots_sf = st_as_sf(knots, coords = c("x","y"), crs = NA, agr = "constant") # Create a simple domain (of rectangles) to evaluate shape1 = matrix(c(0.0,0.0, 0.5,0.0, 0.5,0.5, 0.0,0.5, 0.0,0.0), ncol=2, byrow=TRUE) shape2 = shape1 + cbind(rep(0.5,5), rep(0.0,5)) shape3 = shape1 + cbind(rep(0.0,5), rep(0.5,5)) shape4 = shape1 + cbind(rep(0.5,5), rep(0.5,5)) sfc = st_sfc( st_polygon(list(shape1)), st_polygon(list(shape2)), st_polygon(list(shape3)), st_polygon(list(shape4)) ) dom = st_sf(data.frame(geoid = 1:length(sfc), geom = sfc)) rad = 0.5 areal_spatial_bisquare(dom, knots, rad) areal_spatial_bisquare(dom, knots_sf, rad) # Plot the knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") plot(dom[,1], col = NA, add = TRUE) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
Compute the autocovariance matrix for a VAR(1) process.
autocov_VAR1(A, Sigma, lag_max)
autocov_VAR1(A, Sigma, lag_max)
A |
Coefficient matrix |
Sigma |
Covariance matrix |
lag_max |
maximum number of lags to compute. |
Computes the autocovariance matrix of the
-dimensional VAR(1) process
For the required computation of , this function
solves the
system
without directly computing matrices.
An array Gamma
of dimension c(m, m, lag_max + 1)
,
where the slice Gamma[,,h]
represents the autocovariance at lag
h = 0, 1, ..., lag_max
.
U = matrix(NA, 3, 3) U[,1] = c(1, 1, 1) / sqrt(3) U[,2] = c(1, 0, -1) / sqrt(2) U[,3] = c(0, 1, -1) / sqrt(2) B = U %*% diag(c(0.5, 0.2, 0.1)) %*% t(U) A = (B + t(B)) / 2 Sigma = diag(x = 2, nrow = 3) autocov_VAR1(A, Sigma, lag_max = 5)
U = matrix(NA, 3, 3) U[,1] = c(1, 1, 1) / sqrt(3) U[,2] = c(1, 0, -1) / sqrt(2) U[,3] = c(0, 1, -1) / sqrt(2) B = U %*% diag(c(0.5, 0.2, 0.1)) %*% t(U) A = (B + t(B)) / 2 Sigma = diag(x = 2, nrow = 3) autocov_VAR1(A, Sigma, lag_max = 5)
A convenience function to compute the CAR precision matrix based on a given adjacency matrix.
car_precision(A, tau = 1, scale = FALSE)
car_precision(A, tau = 1, scale = FALSE)
A |
An adjacency matrix. |
tau |
The CAR dependency parameter |
scale |
Whether to scale matrix entries. See "Value".
Default: |
Suppose is an
adjacency matrix and
If
scale
is FALSE
, return the CAR precision matrix
If scale
is TRUE
, return a scaled version
An error is thrown if scale = TRUE
and any of
are equal to 0.
Taking
corresponds to the Intrinsic CAR
precision matrix.
Typically in a modeling context, the precision matrix will be
multiplied by a scaling parameter; e.g., a CAR model for
random effects could be
where .
CAR precision matrix.
data("acs_sf") dom = acs5_2013[1:4,] A = adjacency_matrix(dom) Q = car_precision(A)
data("acs_sf") dom = acs5_2013[1:4,] A = adjacency_matrix(dom) Q = car_precision(A)
An sf
object containing the geometry of four neighborhoods in the
City of Columbia, Boone County, Missouri. Based on shapefiles provided by
the Office of Information Technology / GIS, City of Columbia, Missouri.
columbia_neighbs
columbia_neighbs
An sf
object with 4 features (neighborhoods).
Compute the best positive approximant for use in the STCOS model, under several prespecified covariance structures.
cov_approx_randwalk(Delta, S) cov_approx_blockdiag(Delta, S)
cov_approx_randwalk(Delta, S) cov_approx_blockdiag(Delta, S)
Delta |
Covariance ( |
S |
Design matrix ( |
Let be an
symmetric and positive-definite
covariance matrix and
be an
matrix with
rank
. The objective is to compute a matrix
which minimizes
the Frobenius norm
over symmetric positive-definite matrices . The
solution is given by
In the STCOS model, represents the design matrix from a basis
function computed from a fine-level support having
areas, using
time steps. Therefore
represents the dimension of
covariance for the fine-level support.
We provide functions to handle some possible structures for target covariance matrices of the form
where each is an
matrix.
cov_approx_randwalk
assumes is based on the
autocovariance function of a random walk
so that
cov_approx_blockdiag
assumes is based on
which are independent across , so that
The block structure is used to reduce the computational burden, as
may be large.
Generic function to calculate Deviance Information Criterion (DIC) for a given model object.
DIC(object, ...)
DIC(object, ...)
object |
A fitted model object. |
... |
Additional arguments. |
A numeric value of the DIC.
Gibbs Sampler for STCOS Model
gibbs_stcos( z, v, H, S, Kinv, R, report_period = R + 1, burn = 0, thin = 1, init = NULL, fixed = NULL, hyper = NULL ) ## S3 method for class 'stcos_gibbs' logLik(object, ...) ## S3 method for class 'stcos_gibbs' DIC(object, ...) ## S3 method for class 'stcos_gibbs' print(x, ...) ## S3 method for class 'stcos_gibbs' fitted(object, H, S, ...) ## S3 method for class 'stcos_gibbs' predict(object, H, S, ...)
gibbs_stcos( z, v, H, S, Kinv, R, report_period = R + 1, burn = 0, thin = 1, init = NULL, fixed = NULL, hyper = NULL ) ## S3 method for class 'stcos_gibbs' logLik(object, ...) ## S3 method for class 'stcos_gibbs' DIC(object, ...) ## S3 method for class 'stcos_gibbs' print(x, ...) ## S3 method for class 'stcos_gibbs' fitted(object, H, S, ...) ## S3 method for class 'stcos_gibbs' predict(object, H, S, ...)
z |
Vector which represents the outcome; assumed to be direct estimates from the survey. |
v |
Vector which represents direct variance estimates from the survey. |
H |
Matrix of overlaps between source and fine-level supports. |
S |
Design matrix for basis decomposition. |
Kinv |
The precision matrix |
R |
Number of MCMC reps. |
report_period |
Gibbs sampler will report progress each time this many iterations are completed. |
burn |
Number of the |
thin |
After burn-in period, save one out of every |
init |
A list containing the following initial values for the MCMC:
|
fixed |
A list specifying which parameters to keep fixed in the MCMC.
This can normally be left blank. If elements |
hyper |
A list containing the following hyperparameter values:
|
object |
A result from |
... |
Additional arguments. |
x |
A result from |
Fits the model
using a Gibbs sampler with closed-form draws.
Helper functions produce the following outputs:
logLik
computes the log-likelihood for each saved draw.
DIC
computes the Deviance information criterion for each saved draw.
print
displays a summary of the draws.
fitted
computes the mean for each observation
, for each saved draw.
predict
draws for each observation
, using the parameter values for each saved
Gibbs sampler draw.
gibbs_stcos
returns an stcos
object which contains
draws from the sampler. Helper functions take this object as an input
and produce various outputs (see details).
## Not run: demo = prepare_stcos_demo() out = gibbs_stcos(demo$z, demo$v, demo$H, demo$S, solve(demo$K), R = 100, burn = 0, thin = 1) print(out) logLik(out) DIC(out) fitted(out, demo$H, demo$S) predict(out, demo$H, demo$S) ## End(Not run)
## Not run: demo = prepare_stcos_demo() out = gibbs_stcos(demo$z, demo$v, demo$H, demo$S, solve(demo$K), R = 100, burn = 0, thin = 1) print(out) logLik(out) DIC(out) fitted(out, demo$H, demo$S) predict(out, demo$H, demo$S) ## End(Not run)
Extract a linearly independent set of columns of a matrix.
licols(X, tol = 1e-10, quiet = FALSE)
licols(X, tol = 1e-10, quiet = FALSE)
X |
A matrix. |
tol |
A tolerance for rank estimation. Default is 1e-10. |
quiet |
logical; if FALSE, print a warning about computation time if |
An R version of a Matlab licols
function given in
this MathWorks forum post.
Xsub
contains the extracted columns of X
and idx
contains the indices (into X) of those columns. The elapsed time is stored in
elapsed.sec
.
x = 0:19 %% 3 + 1 Z = model.matrix(~ as.factor(x) - 1) X = cbind(1, Z) licols(X)
x = 0:19 %% 3 + 1 Z = model.matrix(~ as.factor(x) - 1) X = cbind(1, Z) licols(X)
MLE for STCOS Model
mle_stcos( z, v, H, S, K, init = NULL, optim_control = list(), optim_method = "L-BFGS-B" )
mle_stcos( z, v, H, S, K, init = NULL, optim_control = list(), optim_method = "L-BFGS-B" )
z |
Vector which represents the outcome; assumed to be direct estimates from the survey. |
v |
Vector which represents direct variance estimates from the survey.
The diagonal of the matrix |
H |
Matrix of overlaps between source and fine-level supports. |
S |
Design matrix for basis decomposition. |
K |
Variance of the random coefficient |
init |
A list containing the initial values in the MCMC for
|
optim_control |
This is passed as the |
optim_method |
Method to be used for likelihood maximization by
|
Maximize the likelihood of the STCOS model
by numerical maximization of the profile likelihood
using
A list containing maximum likelihood estimates.
## Not run: demo = prepare_stcos_demo() mle_out = mle_stcos(demo$z, demo$v, demo$S, demo$H, demo$K) sig2K_hat = mle_out$sig2K_hat sig2xi_hat = mle_out$sig2xi_hat mu_hat = mle_out$mu_hat ## End(Not run)
## Not run: demo = prepare_stcos_demo() mle_out = mle_stcos(demo$z, demo$v, demo$S, demo$H, demo$K) sig2K_hat = mle_out$sig2K_hat sig2xi_hat = mle_out$sig2xi_hat mu_hat = mle_out$mu_hat ## End(Not run)
A convenience function to convert output from sf::st_intersection
to a sparse matrix as defined in the Matrix
package.
overlap_matrix(dom1, dom2, proportion = TRUE)
overlap_matrix(dom1, dom2, proportion = TRUE)
dom1 |
An |
dom2 |
An |
proportion |
Logical; if |
Returns a matrix H
whose (i,j)th entry represent the area of the overlap
between areal units dom1[i,]
and dom2[j,]
.
An matrix of overlaps.
data("acs_sf") dom1 = acs5_2013[1:10,] dom2 = acs5_2016[1:10,] H1 = overlap_matrix(dom1, dom2) H2 = overlap_matrix(dom1, dom2, proportion = FALSE)
data("acs_sf") dom1 = acs5_2013[1:10,] dom2 = acs5_2016[1:10,] H1 = overlap_matrix(dom1, dom2) H2 = overlap_matrix(dom1, dom2, proportion = FALSE)
Create demo data based on ACS example, making a few simple model choices. The purpose of this function is to facilitate examples in other functions. Uses functions in the package to create model terms from shapefiles.
prepare_stcos_demo(num_knots_sp = 200, basis_mc_reps = 200, eigval_prop = 0.65)
prepare_stcos_demo(num_knots_sp = 200, basis_mc_reps = 200, eigval_prop = 0.65)
num_knots_sp |
Number of spatial knots to use in areal space-time basis. |
basis_mc_reps |
Number of monte carlo reps to use in areal space-time basis. |
eigval_prop |
Proportion of variability to keep in dimension reduction of basis expansions. |
A list containing the following:
z
direct estimates.
v
direct variance estimates.
H
overlap matrix.
S
design matrix of basis expansion.
K
covariance matrix of the random effect.
## Not run: out = prepare_stcos_demo() ## End(Not run)
## Not run: out = prepare_stcos_demo() ## End(Not run)
An alternative to sf::st_sample
which draws uniformly distributed
points using a simple accept-reject method.
rdomain(n, dom, blocksize = n, itmax = Inf)
rdomain(n, dom, blocksize = n, itmax = Inf)
n |
Number of points desired in the final sample. |
dom |
An |
blocksize |
Number of candidate points to draw on each pass of
accept-reject sampling (see details). Defaults to |
itmax |
Maximum number of accept-reject samples to attempt. Defaults
to |
Draws a sample of blocksize
points uniformly from a bounding box on
dom
, and accepts only the points which belong to dom
. This
yields a uniform sample on dom
. The process is repeated until n
accepted draws are obtained, or until it has been attempted itmax
times. If itmax
iterations are reached without accepting n
draws, an error is thrown.
This seems to be an order of magnitude faster than the current
implementation of st_sample
, although the latter can accomplish
the same objective and is more general. The improved performance is
worthwhile when used in the areal basis functions,
which sample repeatedly from the domain.
Performance will degrade when areal units have small area relative to their
bounding box, as many candidate points may need to be discarded. For
example, this will occur if dom
contains a set of small scattered
islands in an ocean. In this case, it would be more efficient to sample
from each island at a time.
An sf
object with 2-dimensional points.
dom = acs5_2013[c(1,5,8,12),] pts = rdomain(10000, dom)
dom = acs5_2013[c(1,5,8,12),] pts = rdomain(10000, dom)
Space-time bisquare basis on point data.
spacetime_bisquare(dom, knots, w_s, w_t)
spacetime_bisquare(dom, knots, w_s, w_t)
dom |
Space-time points |
knots |
Spatio-temporal knots
|
w_s |
Spatial radius for the basis. |
w_t |
Temporal radius for the basis. |
Notes about arguments:
Both dom
and knots
may be provided as either sf
or
sfc
objects, or as matrices of points.
If an sf
or sfc
object is provided for dom
,
three-dimensional
POINT
entries are expected in st_geometry(dom)
.
Otherwise, dom
will be interpreted as an numeric matrix.
If an sf
or sfc
object is provided for knots
,
three-dimensional
POINT
entries are expected in st_geometry(knots)
.
Otherwise, knots
will be interpreted as an numeric matrix.
If both dom
and knots_s
are given as sf
or sfc
objects,
they will be checked to ensure a common coordinate system.
For each , compute the basis functions
for .
Due to the treatment of and
as points in a
Euclidean space, this basis is more suitable for coordinates from a map
projection than coordinates based on a globe representation.
A sparse matrix whose
th row
is
Other bisquare:
areal_spacetime_bisquare()
,
areal_spatial_bisquare()
,
spatial_bisquare()
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) seq_t = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y, t = seq_t) knots_sf = st_as_sf(knots, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") # Points to evaluate x = runif(50) y = runif(50) t = sample(1:3, size = 50, replace = TRUE) pts = data.frame(x = x, y = y, t = t) dom = st_as_sf(pts, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") rad = 0.5 spacetime_bisquare(cbind(x,y,t), knots, w_s = rad, w_t = 1) spacetime_bisquare(dom, knots_sf, w_s = rad, w_t = 1) # Plot the (spatial) knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") text(x, y, labels = t, cex = 0.75) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) seq_t = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y, t = seq_t) knots_sf = st_as_sf(knots, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") # Points to evaluate x = runif(50) y = runif(50) t = sample(1:3, size = 50, replace = TRUE) pts = data.frame(x = x, y = y, t = t) dom = st_as_sf(pts, coords = c("x","y","t"), crs = NA, dim = "XYM", agr = "constant") rad = 0.5 spacetime_bisquare(cbind(x,y,t), knots, w_s = rad, w_t = 1) spacetime_bisquare(dom, knots_sf, w_s = rad, w_t = 1) # Plot the (spatial) knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") text(x, y, labels = t, cex = 0.75) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
Spatial bisquare basis on point data.
spatial_bisquare(dom, knots, w)
spatial_bisquare(dom, knots, w)
dom |
Points |
knots |
Knots |
w |
Radius for the basis. |
Notes about arguments:
Both dom
and knots
may be provided as either sf
or
sfc
objects, or as matrices of points.
If an sf
or sfc
object is provided for dom
,
two-dimensional
POINT
entries are expected in st_geometry(dom)
.
Otherwise, dom
will be interpreted as an numeric matrix.
If an sf
or sfc
object is provided for knots
,
two-dimensional
POINT
entries are expected in st_geometry(knots)
.
Otherwise, knots
will be interpreted as an numeric matrix.
If both dom
and knots
are given as sf
or sfc
objects,
they will be checked to ensure a common coordinate system.
For each , compute the basis functions
for .
Due to the treatment of and
as points in a
Euclidean space, this basis is more suitable for coordinates from a map
projection than coordinates based on a globe representation.
A sparse matrix whose
th row
is
Other bisquare:
areal_spacetime_bisquare()
,
areal_spatial_bisquare()
,
spacetime_bisquare()
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y) knots_sf = st_as_sf(knots, coords = c("x","y"), crs = NA, agr = "constant") # Points to evaluate x = runif(50) y = runif(50) pts = data.frame(x = x, y = y) dom = st_as_sf(pts, coords = c("x","y"), crs = NA, agr = "constant") rad = 0.5 spatial_bisquare(cbind(x,y), knots, rad) spatial_bisquare(dom, knots, rad) # Plot the knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") points(x, y, cex = 0.5) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
set.seed(1234) # Create knot points seq_x = seq(0, 1, length.out = 3) seq_y = seq(0, 1, length.out = 3) knots = expand.grid(x = seq_x, y = seq_y) knots_sf = st_as_sf(knots, coords = c("x","y"), crs = NA, agr = "constant") # Points to evaluate x = runif(50) y = runif(50) pts = data.frame(x = x, y = y) dom = st_as_sf(pts, coords = c("x","y"), crs = NA, agr = "constant") rad = 0.5 spatial_bisquare(cbind(x,y), knots, rad) spatial_bisquare(dom, knots, rad) # Plot the knots and the points at which we evaluated the basis plot(knots[,1], knots[,2], pch = 4, cex = 1.5, col = "red") points(x, y, cex = 0.5) # Draw a circle representing the basis' radius around one of the knot points tseq = seq(0, 2*pi, length=100) coords = cbind(rad * cos(tseq) + seq_x[2], rad * sin(tseq) + seq_y[2]) lines(coords, col = "red")
An R Package for Space-Time Change of Support (STCOS) modeling.
Supports building and running STCOS and related models. A guide on package use is given in <arXiv:1904.12092>.
Jonathan R. Bradley, Christopher K. Wikle, and Scott H. Holan (2015). Spatio-temporal change of support with application to American Community Survey multi-year period estimates. STAT 4 pp.255-270. doi:10.1002/sta4.94.
Andrew M. Raim, Scott H. Holan, Jonathan R. Bradley, and Christopher K. Wikle (2017). A model selection study for spatio-temporal change of support. In JSM Proceedings, Government Statistics Section. Alexandria, VA: American Statistical Association, pp.1524-1540.
Andrew M. Raim, Scott H. Holan, Jonathan R. Bradley, and Christopher K. Wikle (2020+). Spatio-Temporal Change of Support Modeling with R. https://arxiv.org/abs/1904.12092.