Title: | Spatial Misalignment: Interpolation, Linkage, and Estimation |
---|---|
Description: | Provides functions to estimate, predict and interpolate areal data. For estimation and prediction we assume areal data is an average of an underlying continuous spatial process as in Moraga et al. (2017) <doi:10.1016/j.spasta.2017.04.006>, Johnson et al. (2020) <doi:10.1186/s12942-020-00200-w>, and Wilson and Wakefield (2020) <doi:10.1093/biostatistics/kxy041>. The interpolation methodology is (mostly) based on Goodchild and Lam (1980, ISSN:01652273). |
Authors: | Lucas da Cunha Godoy [aut, cre] |
Maintainer: | Lucas da Cunha Godoy <[email protected]> |
License: | GPL-3 |
Version: | 1.0.6 |
Built: | 2024-11-15 23:22:09 UTC |
Source: | https://github.com/lcgodoy/smile |
This function estimates variables observed at a "source" region into a "target" region. "Source" and "target" regions represent two different ways to divide a city, for example. For more details, see https://lcgodoy.me/smile/articles/sai.html.
ai(source, target, vars) ai_var(source, target, vars, vars_var, sc_vars = FALSE, var_method = "CS")
ai(source, target, vars) ai_var(source, target, vars, vars_var, sc_vars = FALSE, var_method = "CS")
source |
a |
target |
a |
vars |
a |
vars_var |
a scalar of type |
sc_vars |
boolean indicating whether |
var_method |
a |
the target (of type sf
) with estimates of the variables
observed at the source data.
Function designed to find the phi parameter such that the
correlation between points within a given distance d
is at most a
given value.
find_phi( d, nu, kappa, mu2, family = "matern", range = c(1e-04, 1000), cut = 0.05 )
find_phi( d, nu, kappa, mu2, family = "matern", range = c(1e-04, 1000), cut = 0.05 )
d |
maximum distance for spatial dependence equal to |
nu |
smoothness parameter associated with the Matern cov. function. |
kappa |
one of the smoothness parameters associated with the Generalized Wendland covariance function |
mu2 |
one of the smoothness parameters associated with the Generalized Wendland covariance function |
family |
covariance function family, the options are |
range |
Minimum and maximum distance to be considered. The default is
|
cut |
desired spatial correlation at a distance |
a numeric
value indicating the range parameter such that the
spatial correlation between two points at distance d
is
cut
.
Fitting an underlying continuous process to areal data
fit_spm(x, ...) ## S3 method for class 'spm' fit_spm( x, model, theta_st, nu = NULL, tr = NULL, kappa = 1, mu2 = 1.5, apply_exp = FALSE, opt_method = "Nelder-Mead", control_opt = list(), comp_hess = TRUE, ... ) fit_spm2( x, model, nu, tr, kappa = 1, mu2 = 1.5, comp_hess = TRUE, phi_min, phi_max, nphi = 10, cores = getOption("mc.cores", 1L) )
fit_spm(x, ...) ## S3 method for class 'spm' fit_spm( x, model, theta_st, nu = NULL, tr = NULL, kappa = 1, mu2 = 1.5, apply_exp = FALSE, opt_method = "Nelder-Mead", control_opt = list(), comp_hess = TRUE, ... ) fit_spm2( x, model, nu, tr, kappa = 1, mu2 = 1.5, comp_hess = TRUE, phi_min, phi_max, nphi = 10, cores = getOption("mc.cores", 1L) )
x |
an object of type |
... |
additional parameters, either passed to stats::optim. |
model |
a |
theta_st |
a |
nu |
a |
tr |
tapper range |
kappa |
|
mu2 |
the smoothness parameter |
apply_exp |
a |
opt_method |
a |
control_opt |
a named |
comp_hess |
a |
phi_min |
a |
phi_max |
a |
nphi |
a |
cores |
a |
This function uses the stats::optim function optimization
algorithms to find the Maximum Likelihood estimators, and their standard
errors, from a model adapted from. The function allows the user to input
the control parameters from the stats::optim function through the argument
control_opt
, which is a named list. Additionally, the one can
input lower and upper boundaries for the optimization problem, as well
as the preferred optimization algorithm (as long as it is available for
stats::optim). The preferred algorithm is selected by the argument
opt_method
. In addition to the control of the optimization, the
user can select a covariance function among the following: Matern,
Exponential, Powered Exponential, Gaussian, and Spherical. The parameter
apply_exp
is a logical
scalar such that, if set to
TRUE
, the function is applied to the nonnegative
parameters, allowing the optimization algorithm to search for all the
parameters over the real numbers.
The model assumes \deqn{Y(\mathbf{s}) = \mu + S(\mathbf{s})} at the point level. Where \eqn{S ~ GP(0, \sigma^2 C(\lVert \mathbf{s} - \mathbf{s}_2 \rVert; \theta))}. Further, the observed data is supposed to be \eqn{Y(B) = \lvert B \rvert^{-1} \int_{B} Y(\mathbf{s}) \, \textrm{d} \mathbf{s}}.
a spm_fit
object containing the information about the
estimation of the model parameters.
data(liv_lsoa) ## loading the LSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 500, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est") ## fitting model theta_st_msoa <- c("phi" = 1) # initial value for the range parameter fit_msoa <- fit_spm(x = msoa_spm, theta_st = theta_st_msoa, model = "matern", nu = .5, apply_exp = TRUE, opt_method = "L-BFGS-B", control = list(maxit = 500)) AIC(fit_msoa) summary_spm_fit(fit_msoa, sig = .05)
data(liv_lsoa) ## loading the LSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 500, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est") ## fitting model theta_st_msoa <- c("phi" = 1) # initial value for the range parameter fit_msoa <- fit_spm(x = msoa_spm, theta_st = theta_st_msoa, model = "matern", nu = .5, apply_exp = TRUE, opt_method = "L-BFGS-B", control = list(maxit = 500)) AIC(fit_msoa) summary_spm_fit(fit_msoa, sig = .05)
spm_fit
objects.Akaike's (and Bayesian) An Information Criterion for spm_fit
objects.
## S3 method for class 'spm_fit' AIC(object, ..., k = 2) ## S3 method for class 'spm_fit' BIC(object, ...)
## S3 method for class 'spm_fit' AIC(object, ..., k = 2) ## S3 method for class 'spm_fit' BIC(object, ...)
object |
a |
... |
optionally more fitted model objects. |
k |
|
a numeric
scalar corresponding to the goodness of fit
measure.
A dataset containing containing the LSOA's for Liverpool along with estimates for Index of Multiple Deprivation. Data taken from Johnson et al. 2020
liv_lsoa
liv_lsoa
A sf
data frame with 298 rows and 6 variables:
LSOA code
LSOA name
Male population
Female population
Index of Multiple Deprivation
LMSOA area, in
The data was projected to EPSG 27700 and units changed to km
https://ij-healthgeographics.biomedcentral.com/articles/10.1186/s12942-020-00200-w
A dataset containing containing the MSOA's for Liverpool along with estimates for Life Expectancy at Birth. Data taken from Johnson et al. 2020
liv_msoa
liv_msoa
A sf
data frame with 61 rows and 4 variables:
MSOA code
MSOA name
Estimated life expectancy at birth, in years
MSOA area, in
The data was projected to EPSG 27700 and units changed to km
https://ij-healthgeographics.biomedcentral.com/articles/10.1186/s12942-020-00200-w
A dataset containing containing the census tracts for the city of Nova Lima in Minas Gerais - Brazil.
nl_ct
nl_ct
A sf
data frame with 113 rows and 14 variables:
unique identifier
average household density
variance of the household density
average income per household
variance of the income per household
population in the census tract
average age of the inhabitants in the census tract
variance of the variable age in the census tract
proportion of women
proportion of people with 55 years of age or older
illiteracy rate
proportion of self-declared white people
proportion of self-declared black people
proportion of self-declared native people
The data is project using the SIRGAS 2000.
Realizes predictions that can be useful when researchers are interested in predict a variable observed in one political division of a city (or state) on another division of the same region.
predict_spm(x, ...) ## S3 method for class 'spm_fit' predict_spm(x, .aggregate = TRUE, ...) ## S3 method for class 'sf' predict_spm(x, spm_obj, n_pts, type, outer_poly = NULL, id_var, ...)
predict_spm(x, ...) ## S3 method for class 'spm_fit' predict_spm(x, .aggregate = TRUE, ...) ## S3 method for class 'sf' predict_spm(x, spm_obj, n_pts, type, outer_poly = NULL, id_var, ...)
x |
a |
... |
additional parameters |
.aggregate |
|
spm_obj |
an object of either class |
n_pts |
a |
type |
|
outer_poly |
(object) |
id_var |
if |
a list
of size 4 belonging to the class spm_pred
. This
list contains the predicted values and the mean and covariance matrix
associated with the conditional distribution used to compute the
predictions.
data(liv_lsoa) ## loading the LSOA data data(liv_msoa) ## loading the MSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 500, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est") ## fitting model theta_st_msoa <- c("phi" = 1) # initial value for the range parameter fit_msoa <- fit_spm(x = msoa_spm, theta_st = theta_st_msoa, model = "matern", nu = .5, apply_exp = TRUE, opt_method = "L-BFGS-B", control = list(maxit = 500)) pred_lsoa <- predict_spm(x = liv_lsoa, spm_obj = fit_msoa, id_var = "lsoa11cd")
data(liv_lsoa) ## loading the LSOA data data(liv_msoa) ## loading the MSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 500, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est") ## fitting model theta_st_msoa <- c("phi" = 1) # initial value for the range parameter fit_msoa <- fit_spm(x = msoa_spm, theta_st = theta_st_msoa, model = "matern", nu = .5, apply_exp = TRUE, opt_method = "L-BFGS-B", control = list(maxit = 500)) pred_lsoa <- predict_spm(x = liv_lsoa, spm_obj = fit_msoa, id_var = "lsoa11cd")
sf
to spm
Transforming a sf
into a spm
object (Internal use)
single_sf_to_spm( sf_obj, n_pts, type = "regular", by_polygon = FALSE, poly_ids = NULL, var_ids = NULL, trunc_d = NULL ) sf_to_spm( sf_obj, n_pts, type = "regular", by_polygon = FALSE, poly_ids = NULL, var_ids = NULL, trunc_d = NULL )
single_sf_to_spm( sf_obj, n_pts, type = "regular", by_polygon = FALSE, poly_ids = NULL, var_ids = NULL, trunc_d = NULL ) sf_to_spm( sf_obj, n_pts, type = "regular", by_polygon = FALSE, poly_ids = NULL, var_ids = NULL, trunc_d = NULL )
sf_obj |
a |
n_pts |
a |
type |
a |
by_polygon |
a |
poly_ids |
a |
var_ids |
a scalar or vector of type |
trunc_d |
truncation distance for grid points. Consider using half of the maximum distance between polygons |
a named list
of size 6 belonging to the class
spm
. This list stores all the objects necessary to fit models
using the fit_spm
.
data(liv_lsoa) # loading the LSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 1000, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est")
data(liv_lsoa) # loading the LSOA data msoa_spm <- sf_to_spm(sf_obj = liv_msoa, n_pts = 1000, type = "regular", by_polygon = FALSE, poly_ids = "msoa11cd", var_ids = "leb_est")
spm_fit
Provides a data.frame
with point estimates and
confidence intervals for the parameters of the model fitted using the
spm_fit
function.
summary_spm_fit(x, sig = 0.05)
summary_spm_fit(x, sig = 0.05)
x |
a |
sig |
a real number between 0 and 1 indicating significance level to be used to compute the confidence intervals for the parameter estimates. |
a data.frame
summarizing the parameters estimated by the
fit_spm
function.
Reminder, have to create an example. This will be exported after we submit the paper for publication.
vdl(coords_sf, areal_sf, vars, buff)
vdl(coords_sf, areal_sf, vars, buff)
coords_sf |
|
areal_sf |
|
vars |
a |
buff |
scalar |
a sf
object for the coords_sf
spatial data set.
Reminder, have to create an example. This will be exported after we submit the paper for publication.
vdl_var(coords_sf, areal_sf, res_var, variance, var_method = "CS", buff)
vdl_var(coords_sf, areal_sf, res_var, variance, var_method = "CS", buff)
coords_sf |
|
areal_sf |
|
res_var |
a |
variance |
a |
var_method |
a |
buff |
scalar |
a sf
object, containing the id_coords
variable and the
list_vars
for the coords_sf
spatial data set.