Title: | GWR, Mixed GWR and Multiscale GWR with Spatial Autocorrelation |
---|---|
Description: | Functions for computing (Mixed and Multiscale) Geographically Weighted Regression with spatial autocorrelation, Geniaux and Martinetti (2017) <doi:10.1016/j.regsciurbeco.2017.04.001>. |
Authors: | Ghislain Geniaux [aut, cre], Davide Martinetti [aut], César Martinez [aut] |
Maintainer: | Ghislain Geniaux <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1 |
Built: | 2025-02-20 14:25:06 UTC |
Source: | CRAN |
This function performs a Geographically Weighted Regression (GWR) using a top-down scaling approach, adjusting GWR coefficients with a progressively decreasing bandwidth as long as the AICc criterion improves.
atds_gwr(formula,data,coords,kernels='triangle',fixed_vars=NULL, control_tds=list(nns=30),control=list(adaptive=TRUE,verbose=FALSE))
atds_gwr(formula,data,coords,kernels='triangle',fixed_vars=NULL, control_tds=list(nns=30),control=list(adaptive=TRUE,verbose=FALSE))
formula |
a formula. |
data |
a dataframe. |
coords |
default NULL, a dataframe or a matrix with coordinates |
kernels |
A vector containing the kernel types. Possible types: triangle ("triangle"), bisquare ("bisq"), tricube ("tcub"), epanechnikov ("epane"). |
fixed_vars |
a vector with the names of spatiallay constant coefficient for mixed model. All other variables present in formula are supposed to be spatially varying. If empty or NULL (default), all variables in formula are supposed to be spatially varying. |
control_tds |
list of extra control arguments for tds_mgwr model - see tds_gwr Help |
control |
list of extra control arguments for MGWRSAR wrapper - see MGWRSAR Help |
tds_mgwr, gwr_multiscale, MGWRSAR, bandwidths_mgwrsar, summary_mgwrsar.
coef for mgwrsar model
## S4 method for signature 'mgwrsar' coef(object, ...)
## S4 method for signature 'mgwrsar' coef(object, ...)
object |
A model of class |
... |
coef parameters forwarded. |
A named list with a matrix of varying coefficients and a vector or non varying coefficients.
Search of a suitable set of target points. find_TP is a wrapper function that identifies a set of target points based on spatial smoothed OLS residuals.
find_TP(formula, data,coords,kt,ks=16,Wtp=NULL,type='residuals', model_residuals=NULL,verbose=0,prev_TP=NULL,nTP=NULL)
find_TP(formula, data,coords,kt,ks=16,Wtp=NULL,type='residuals', model_residuals=NULL,verbose=0,prev_TP=NULL,nTP=NULL)
formula |
a formula |
data |
a dataframe or a spatial dataframe (SP package) |
coords |
a dataframe or a matrix with coordinates, not required if data is a spatial dataframe |
kt |
the minimum number of first neighbors with lower (resp.higer) absolute value of the smoothed residuals. |
ks |
the number of first neighbors for computing the smoothed residuals, default 16. |
Wtp |
a precomputed matrix of weights, default NULL. |
type |
method for choosing TP, could be 'residuals', ' kdtree','random', default 'residuals' |
model_residuals |
(optional) a vector of residuals. |
verbose |
verbose mode, default FALSE. |
prev_TP |
index of already used TP (version length(kt)>1), default NULL. |
nTP |
numbeer of target points for random choice of target points, default NULL. |
find_TP is a wrapper function that identifies a set of target points, based on spatial smoothed residuals by default. If no vector of residuals are provided, OLS residuals are computed. The function first computes the smooth of model residuals using a Shepard's kernel with ks neighbors (default 16). Then it identifies local maxima (resp. minima) that fits the requirement of having at least kt neighbors with lower (resp.higer) absolute value of the smoothed residuals. As kt increases the number of target points decreases.
find_TP returns an index vector of Target Points set.
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) TP=find_TP(formula = 'Y_gwr~X1+X2+X3', data =mydata,coords=coords,kt=6, type='residuals') # only 60 targets points are used length(TP) model_GWR_tp<-MGWRSAR(formula = 'Y_gwr~X1+X2+X3', data = mydata, coords=coords, fixed_vars=NULL,kernels=c('gauss'), H=0.03, Model = 'GWR', control=list(SE=TRUE,TP=TP,ks=12)) summary(model_GWR_tp@Betav)
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) TP=find_TP(formula = 'Y_gwr~X1+X2+X3', data =mydata,coords=coords,kt=6, type='residuals') # only 60 targets points are used length(TP) model_GWR_tp<-MGWRSAR(formula = 'Y_gwr~X1+X2+X3', data = mydata, coords=coords, fixed_vars=NULL,kernels=c('gauss'), H=0.03, Model = 'GWR', control=list(SE=TRUE,TP=TP,ks=12)) summary(model_GWR_tp@Betav)
fitted for mgwrsar model
## S4 method for signature 'mgwrsar' fitted(object, ...)
## S4 method for signature 'mgwrsar' fitted(object, ...)
object |
A model of class |
... |
fitted parameters forwarded. |
A vector of fitted values.
golden_search_bandwidth to be documented
golden_search_bandwidth(formula,H2=NULL,data, coords, fixed_vars, kernels, Model, control,lower.bound, upper.bound,tolerance=0.000001)
golden_search_bandwidth(formula,H2=NULL,data, coords, fixed_vars, kernels, Model, control,lower.bound, upper.bound,tolerance=0.000001)
formula |
to be documented |
H2 |
to be documented |
data |
to be documented |
coords |
to be documented |
fixed_vars |
to be documented |
kernels |
to be documented |
Model |
to be documented |
control |
to be documented |
lower.bound |
to be documented |
upper.bound |
to be documented |
tolerance |
to be documented |
a list(minimum=res,objective=objective,model=model).
kernel_matW A function that returns a sparse weight matrix based computed with a specified kernel (gauss,bisq,tcub,epane,rectangle,triangle) considering coordinates provides in S and a given bandwidth. If NN<nrow(S) only NN firts neighbours are considered. If Type!='GD' then S should have additional columns and several kernels and bandwidths should be be specified by the user.
kernel_matW(H,kernels,coords,NN,TP=NULL,Type='GD',adaptive=FALSE, diagnull=TRUE,alpha=1,theta=1,dists=NULL,indexG=NULL,extrapol=FALSE,QP=NULL,K=0)
kernel_matW(H,kernels,coords,NN,TP=NULL,Type='GD',adaptive=FALSE, diagnull=TRUE,alpha=1,theta=1,dists=NULL,indexG=NULL,extrapol=FALSE,QP=NULL,K=0)
H |
A vector of bandwidths |
kernels |
A vector of kernel types |
coords |
A matrix with variables used in kernel (reference) |
NN |
Number of spatial Neighbours for kernels computations |
TP |
A vector with index of target points |
Type |
Type of Genelarized kernel product ('GD' only spatial,'GDC' spatial + a categorical variable,'GDX' spatial + a continuous variable, 'GDT' spatial + a time index, and other combinations 'GDXXC','GDTX',...) |
adaptive |
A vector of boolean to choose adaptive version for each kernel |
diagnull |
Zero on diagonal, default FALSE |
alpha |
TO BE DOCUMENTED |
theta |
TO BE DOCUMENTED |
dists |
TO BE DOCUMENTED |
indexG |
TO BE DOCUMENTED |
extrapol |
TO BE DOCUMENTED |
QP |
A matrix with variables used in kernel (neighbors), default NULL (if NULL coord_j=coord_i) |
K |
TO BE DOCUMENTED |
A sparse Matrix of weights (dgCMatrix).
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) of 4 nearest neighbors with 0 in diagonal W=kernel_matW(H=4,kernels='rectangle',coords=coords,NN=4,adaptive=TRUE,diagnull=TRUE)
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) of 4 nearest neighbors with 0 in diagonal W=kernel_matW(H=4,kernels='rectangle',coords=coords,NN=4,adaptive=TRUE,diagnull=TRUE)
MGWRSAR is is a wrapper function for estimating linear and local linear models with spatial autocorrelation (SAR models with spatially varying coefficients).
MGWRSAR(formula, data, coords, fixed_vars = NULL, kernels, H, Model = "GWR", control = list())
MGWRSAR(formula, data, coords, fixed_vars = NULL, kernels, H, Model = "GWR", control = list())
formula |
a formula. |
data |
a dataframe or a spatial dataframe (sp package). |
coords |
default NULL, a dataframe or a matrix with coordinates, not required if data is a spatial dataframe. |
fixed_vars |
a vector with the names of spatiallay constant coefficient for mixed model. All other variables present in formula are supposed to be spatially varying. If empty or NULL (default), all variables in formula are supposed to be spatially varying. |
kernels |
A vector containing the kernel types. Possible types: rectangle ("rectangle"), bisquare ("bisq"), tricube ("tcub"), epanechnikov ("epane"), gaussian ("gauss")) . |
H |
vector containing the bandwidth parameters for the kernel functions. |
Model |
character containing the type of model: Possible values are "OLS", "SAR", "GWR" (default), "MGWR" , "MGWRSAR_0_0_kv","MGWRSAR_1_0_kv", "MGWRSAR_0_kc_kv", "MGWRSAR_1_kc_kv", "MGWRSAR_1_kc_0". See Details for more explanation. |
control |
list of extra control arguments for MGWRSAR wrapper - see Details below |
A matrix of variables for genralized kernel product, default NULL.
A row-standardized spatial weight matrix for Spatial Aurocorrelation, default NULL.
Verbose mode, default FALSE.
A vector of boolean to choose adaptive version for each kernel.
The type of kernel for computing W, default NULL.
The bandwidth value for computing W, default 0.
Estimation method for computing the models with Spatial Dependence. '2SLS' or 'B2SLS', default '2SLS'.
Avector of target points, default NULL.
Parallel computation, default FALSE. If TRUE and control_tds$doMC is also TRUE, then control$doMC is set to FALSE.
Number of CPU core for parallel computation, default 1
If TRUE, compute a LOOCV criteria, default FALSE.
If TRUE, simplify the computation of CV criteria (remove or not i when using local instruments for model with lambda spatially varying), default TRUE.
When n >NmaxDist, only the maxknn first neighbours are used for distance compution, default 500.
When n >NmaxDist only the maxknn first neighbours are used for distance compution, default 5000
Verbose mode, default FALSE.
MGWRSAR returns an object of class mgwrsar with at least the following components:
matrix of coefficients of dim(n,kv) x kv.
vector of coefficients of length kc.
The sum of square residuals.
The dependent variable.
The explanatory variables with constant coefficients.
The explanatory variables with varying coefficients.
The explanatory variables.
The spatial weight matrix for spatial dependence.
if gcv has been computed.
The estimated degrees of freedom.
The formula.
The dataframe used for computation.
The type of model.
The spatial coordinates of observations.
The bandwidth vector.
The names of constant coefficients.
The kernel vector.
The sum of square residuals.
The vector of residuals.
the vector of fitted values.
local standard error of parameters.
Boolean, if trace of hat matrix Tr(S) should be stored.
Maximum number of neighbors for weights computation
MGWRSAR is is a wrapper function for estimating linear and local linear model
with spatial autocorrelation that allows to estimate the following models :
(OLS)
(GWR)
(MGWR)
(MGWR-SAR(0,k,0))
(MGWR-SAR(0,0,k))
(MGWR-SAR(0,k_c,k_v))
(MGWR-SAR(1,k,0))
(MGWR-SAR(1,0,k))
(MGWR-SAR(1,k_c,k_v))
When model imply spatial autocorrelation, a row normalized spatial weight matrix must be provided. 2SLS and Best 2SLS method can be used. When model imply local regression, a bandwidth and a kernel type must be provided. Optimal bandwidth can be estimated using bandwidths_mgwrsar function. When model imply mixed local regression, the names of stationary covariates must be provided.
#' In addition to the ability of considering spatial autocorrelation in GWR/MGWR like models, MGWRSAR function introduces several useful technics for estimating local regression with space coordinates:
it uses RCCP and RCCPeigen code that speed up computation and allows parallel computing via doMC package;
it allows to drop out variables with not enough local variance in local regression, which allows to consider dummies in GWR/MGWR framework without trouble.
it allows to drop out local outliers in local regression.
it allows to consider additional variable for kernel, including time (asymetric kernel) and categorical variables (see Li and Racine 2010). Experimental version.
Geniaux, G. and Martinetti, D. (2017). A new method for dealing simultaneously with spatial autocorrelation and spatial heterogeneity in regression models. Regional Science and Urban Economics. (https://doi.org/10.1016/j.regsciurbeco.2017.04.001)
McMillen, D. and Soppelsa, M. E. (2015). A conditionally parametric probit model of microdata land use in chicago. Journal of Regional Science, 55(3):391-415.
Loader, C. (1999). Local regression and likelihood, volume 47. springer New York.
Franke, R. and Nielson, G. (1980). Smooth interpolation of large sets of scattered data. International journal for numerical methods in engineering, 15(11):1691-1704.
bandwidths_mgwrsar, summary, plot, predict, kernel_matW
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) ## of 4 nearest neighbors with 0 in diagonal W=kernel_matW(H=4,kernels='rectangle',coords=coords,NN=4,adaptive=TRUE, diagnull=TRUE) mgwrsar_0_kc_kv<-MGWRSAR(formula = 'Y_mgwrsar_0_kc_kv~X1+X2+X3', data = mydata, coords=coords, fixed_vars='X2',kernels=c('gauss'),H=20, Model = 'MGWRSAR_0_kc_kv', control=list(SE=FALSE,adaptive=TRUE,W=W)) summary(mgwrsar_0_kc_kv)
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) ## of 4 nearest neighbors with 0 in diagonal W=kernel_matW(H=4,kernels='rectangle',coords=coords,NN=4,adaptive=TRUE, diagnull=TRUE) mgwrsar_0_kc_kv<-MGWRSAR(formula = 'Y_mgwrsar_0_kc_kv~X1+X2+X3', data = mydata, coords=coords, fixed_vars='X2',kernels=c('gauss'),H=20, Model = 'MGWRSAR_0_kc_kv', control=list(SE=FALSE,adaptive=TRUE,W=W)) summary(mgwrsar_0_kc_kv)
A bootstrap test for Betas for mgwrsar class model.
mgwrsar_bootstrap_test(x0,x1,B=100,doMC=FALSE,ncore=1,type='standard' ,eps='H1',df='H1',focal='median',D=NULL)
mgwrsar_bootstrap_test(x0,x1,B=100,doMC=FALSE,ncore=1,type='standard' ,eps='H1',df='H1',focal='median',D=NULL)
x0 |
The H0 mgwrsar model |
x1 |
The H1 mgwrsar model |
B |
number of bootstrap repetitions, default 100 |
doMC |
If TRUE, doParallel parallelization |
ncore |
number of cores |
type |
type of bootstap : 'wild','Rademacher','spatial' or 'standard' (default) |
eps |
Hypothesis under wich residuals are simulated, 'H0' or 'H1' (default) |
df |
Hypothesis under wich degree of freedom is estimated. |
focal |
see sample_stat help |
D |
A matrix of distance |
The value of the statictics test and a p ratio.
mgwrsar_bootstrap_test_all
A bootstrap test for testing nullity of all Betas for mgwrsar class model,
mgwrsar_bootstrap_test_all(model,B=100,doMC=FALSE,ncore=1, type='standard')
mgwrsar_bootstrap_test_all(model,B=100,doMC=FALSE,ncore=1, type='standard')
model |
A mgwrsar model |
B |
number of bootstrap replications, default 100 |
doMC |
If TRUE, doMC parallelization |
ncore |
number of cores. |
type |
type of boostrap ('spatial','wild','random') |
a matrix with statistical test values and p ratios
mgwrsar_bootstrap_test
Class of mgwrsar Model.
Betav
matrix, the estimated varying coefficients, dim(n,kv).
Betac
numeric, the estimated constant coefficients, length kc.
Model
character, The type of model.
fixed_vars
character, a vector with name of constant covarariate.
Y
numeric, the dependent variable.
XC
matrix, the explanatory variables with constant coefficients.
XV
matrix, the explanatory variables with varying coefficients.
X
matrix, the explanatory variables.
W
SparseMatrix, the spatial weight matrix for spatial dependence.
isgcv
logical, if gcv has been computed.
edf
numeric, the estimated degrees of freedom.
formula
formula
data
dataframe, The dataframe used for computation.
Method
character, the estimation technique for computing the models with Spatial Dependence. '2SLS' or 'B2SLS', default '2SLS'.
coords
matrix, the spatial coordinates of observations.
H
numeric, the bandwidth vector.
H2
numeric, the time bandwidth vector.
kernels
character, the type of kernel.
adaptive
logical, adaptive kernel.
Type
character, the type of General Kernel Product.
TP
numeric, index of target points.
SSRtp
numeric, the sum of square residuals for TP.
SSR
numeric, the sum of square residuals.
residuals
numeric, the vector of residuals.
fit
numeric, the vector of fitted values.
pred
numeric, the vector of predicted values.
sev
matrix, local standard error of varying coefficients.
se
numeric, standard error of constant coefficients.
tS
numeric, Trace(S).
Shat,
hat matrix
R_k,
list of hat matrix by var
h_w
numeric, the bandwidth value for computing W, default 0.
kernel_w
the type of kernel for computing W, default NULL.
RMSE
numeric, Root Mean Square Error for Target Points.
RMSEtp
numeric, Root Mean Square Error for all Points.
CV
numeric, Leave One Out CV.
AIC
numeric, Akaike Criteria.
AICc
numeric, Corrected Akaike Criteria.
AICctp
numeric, Corrected Akaike Criteria for TP
BIC
numeric, Bayesian Information Criteria.
R2
numeric, R2.
R2_adj
numeric, adjusted R2.
get_ts
logical, if trace of hat matrix Tr(S) should be stored.
NN
numeric, the maximum number of neighbors for weights computation
doMC
logical, parallel computation.
ncore
numeric, number of cores.
mycall
a call, the call of the model.
ctime
numeric, the computing times in seconds.
HRMSE
matrix, RMSE log.
HBETA
list, estimated BETA at each iteration.
loglik
numeric, value of loglik.
G
list, list of neighboring index and distances (knn object from nabor package).
V
numeric, neighbors sequence for TDS.
Vt
numeric, neighbors sequence for TDS.
Z
numeric, time for GDT kernel type
TS
numeric, Diagonal of Hat Matrix
alpha
numeric, ratio for GDT kernels
theta
numeric, ratio for GDT kernels
modc is a set of models to correct approximation of hat matrix trace
Ghislain Geniaux and Davide Martinetti [email protected]
doi:10.1016/j.regsciurbeco.2017.04.001
multiscale_gwr This function adapts the multiscale Geographically Weighted Regression (GWR) methodology proposed by Fotheringam et al. in 2017, employing a backward fitting procedure within the MGWRSAR subroutines. The consecutive bandwidth optimizations are performed by minimizing the corrected Akaike criteria.
multiscale_gwr(formula,data,coords,kernels='bisq',init='GWR', maxiter=20,nstable=6,tolerance=0.000001,doMC=FALSE,ncore=1,HF=NULL, H0=NULL,H2=NULL,Model=NULL,model=NULL,get_AICg=FALSE,verbose=FALSE, control=list(SE=FALSE,adaptive=TRUE,NN=800,isgcv=FALSE,family=gaussian()))
multiscale_gwr(formula,data,coords,kernels='bisq',init='GWR', maxiter=20,nstable=6,tolerance=0.000001,doMC=FALSE,ncore=1,HF=NULL, H0=NULL,H2=NULL,Model=NULL,model=NULL,get_AICg=FALSE,verbose=FALSE, control=list(SE=FALSE,adaptive=TRUE,NN=800,isgcv=FALSE,family=gaussian()))
formula |
A formula. |
data |
A dataframe. |
coords |
default NULL, a dataframe or a matrix with coordinates. |
kernels |
A vector containing the kernel types. Possible types: rectangle ("rectangle"), bisquare ("bisq"), tricube ("tcub"), epanechnikov ("epane") |
init |
starting model (lm or GWR) |
maxiter |
maximum number of iterations in the back-fitting procedure. |
nstable |
required number of consecutive unchanged optimal bandwidth (by covariate) before leaving optimisation of bandwidth size, default 3. |
tolerance |
value to terminate the back-fitting iterations (ratio of change in RMSE) |
doMC |
A boolean for Parallel computation, default FALSE. |
ncore |
number of CPU cores for parallel computation, default 1. |
HF |
if available, a vector containing the optimal bandwidth parameters for each covariate, default NULL. |
H0 |
A bandwidth value for the starting GWR model, default NULL. |
H2 |
A bandwidth temporal value for the starting GWR model, default NULL. |
Model |
Type of Model. |
model |
A previous model estimated using multiscale_gwr function, default NULL |
get_AICg |
Boolean, should Global AICc be estimated. |
verbose |
Boolean, verbose mode. |
control |
a list of extra control arguments, see MGWRSAR help. |
Return an object of class mgwrsar
mydata is a simulated data set of a mgwrsar model
A data frames with 1000 rows 22 variables and a matrix of coordinates with two columns
Ghislain Geniaux and Davide Martinetti [email protected]
doi:10.1016/j.regsciurbeco.2017.04.001
mydataf is a Simple Feature object with real estate data in south of France.
A sf object with 1403 rows, 5 columns
Ghislain Geniaux [email protected]
https://www.data.gouv.fr/fr/datasets/demandes-de-valeurs-foncieres/
normW row normalization of dgCMatrix
normW(W)
normW(W)
W |
A dgCMatrix class matrix |
A row normalized dgCMatrix
plot_effect plot_effect is a function that plots the effect of a variable X_k with spatially varying coefficient, i.e X_k * Beta_k(u_i,v_i) for comparing the magnitude of effects of between variables.
plot_effect(model,sampling=TRUE,nsample=2000,nsample_max=5000,title='')
plot_effect(model,sampling=TRUE,nsample=2000,nsample_max=5000,title='')
model |
a model of mgwrsar class with some spatially varying coefficients. |
sampling |
Bolean, if nrow(model@Betav)> nsample_max a sample of size nsample is randomly selected, default TRUE. |
nsample |
integer, size of the sample if sampling is TRUE, default 2000. |
nsample_max |
integer, size max to engage sampling if sampling is TRUE, default 5000. |
title |
a title for the plot. |
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) ## of 8 nearest neighbors with 0 in diagonal model_GWR0<-MGWRSAR(formula = 'Y_gwr~X1+X2+X3', data = mydata,coords=coords, fixed_vars=NULL,kernels=c('gauss'),H=0.13, Model = 'GWR',control=list(SE=TRUE)) plot_effect(model_GWR0)
library(mgwrsar) ## loading data example data(mydata) coords=as.matrix(mydata[,c("x","y")]) ## Creating a spatial weight matrix (sparce dgCMatrix) ## of 8 nearest neighbors with 0 in diagonal model_GWR0<-MGWRSAR(formula = 'Y_gwr~X1+X2+X3', data = mydata,coords=coords, fixed_vars=NULL,kernels=c('gauss'),H=0.13, Model = 'GWR',control=list(SE=TRUE)) plot_effect(model_GWR0)
Plot method for mgwrsar model
## S4 method for signature 'mgwrsar,missing' plot( x, y, type = "coef", var = NULL, crs = NULL, mypalette = "RdYlGn", opacity = 0.5, fopacity = 0.5, nbins = 8, radius = 500, mytile = "Stadia.StamenTonerBackground", myzoom = 8, myresolution = 150, LayersControl = TRUE, myzoomControl = TRUE, mytile2 = NULL, ScaleBar = NULL, ScaleBarOptions = list(maxWidth = 200, metric = TRUE, imperial = FALSE, updateWhenIdle = TRUE), MyLegendTitle = NULL, lopacity = 0.5 )
## S4 method for signature 'mgwrsar,missing' plot( x, y, type = "coef", var = NULL, crs = NULL, mypalette = "RdYlGn", opacity = 0.5, fopacity = 0.5, nbins = 8, radius = 500, mytile = "Stadia.StamenTonerBackground", myzoom = 8, myresolution = 150, LayersControl = TRUE, myzoomControl = TRUE, mytile2 = NULL, ScaleBar = NULL, ScaleBarOptions = list(maxWidth = 200, metric = TRUE, imperial = FALSE, updateWhenIdle = TRUE), MyLegendTitle = NULL, lopacity = 0.5 )
x |
A model of class |
y |
missing |
type |
default 'coef', for plotting the value of the coefficients. Local t-Student could also be plot using 't_coef', residuals using 'residuals' and fitted using 'fitted'. |
var |
Names of variable to plot. |
crs |
A CRS projection. |
mypalette |
A leaflet palette. |
opacity |
Opacity of border color. |
fopacity |
Opacity of fill color. |
nbins |
nbins. |
radius |
radius of circle for plot of points. |
mytile |
tile 1. |
myzoom |
level of zoom for tile 1. |
myresolution |
resolution for tile 1. |
LayersControl |
layers contols. |
myzoomControl |
zoem control. |
mytile2 |
tile 2. |
ScaleBar |
ScaleBar. |
ScaleBarOptions |
options for ScaleBar. |
MyLegendTitle |
Legend title. |
lopacity |
opacity for legend. |
A Interactive Web Maps with local parameters plot and Open Street Map layer.
predict method for mgwrsar model
## S4 method for signature 'mgwrsar' predict( object, newdata, newdata_coords, W = NULL, type = "BPN", h_w = 100, kernel_w = "rectangle", maxobs = 4000, beta_proj = FALSE, method_pred = "TP", k_extra = 8, ... )
## S4 method for signature 'mgwrsar' predict( object, newdata, newdata_coords, W = NULL, type = "BPN", h_w = 100, kernel_w = "rectangle", maxobs = 4000, beta_proj = FALSE, method_pred = "TP", k_extra = 8, ... )
object |
A model of class |
newdata |
a matrix or data.frame of new data. |
newdata_coords |
a matrix of new coordinates, and eventually other variables if a General Kernel Product is used. |
W |
the spatial weight matrix for models with spatial autocorrelation. |
type |
Type for BLUP estimator, default "BPN". If NULL use predictions without spatial bias correction. |
h_w |
A bandwidth value for the spatial weight matrix |
kernel_w |
kernel type for the spatial weight matrix. Possible types: rectangle ("rectangle"), bisquare ("bisq"), tricube ("tcub"), epanechnikov ("epane"), gaussian ("gauss")) . |
maxobs |
maximum number of observations for exact calculation of solve(I- rho*W), default maxobs=4000. |
beta_proj |
A boolean, if TRUE the function then return a two elements list(Y_predicted,Beta_proj_out) |
method_pred |
If method_pred = 'TP' (default) prediction is done by recomputing a MGWRSAR model with new-data as target points, else if method_pred in ('tWtp_model','model','shepard') a matrix for projecting estimated betas is used (see details). |
k_extra |
number of neighboors for local parameter extrapolation if shepard kernel is used, default 8. |
... |
predict parameters forwarded. |
if method_pred ='tWtp_model', the weighting matrix for prediction is based on the expected weights of outsample data if they were had been added to insample data to estimate the corresponding MGWRSAR (see Geniaux 2022 for further detail), if method_pred ='shepard'a shepard kernel with k_extra neighbours (default 8) is used and if method_pred='kernel_model' the same kernel and number of neighbors as for computing the MGWRSAR model is used.
A vector of predictions if beta_proj is FALSE or a list with a vector named Y_predicted and a matrix named Beta_proj_out.
A vector of predictions.
residuals for mgwrsar model
## S4 method for signature 'mgwrsar' residuals(object, ...)
## S4 method for signature 'mgwrsar' residuals(object, ...)
object |
A model of class |
... |
residuals parameters forwarded. |
A vector of residuals.
The simu_multiscale function is designed for simulating a spatially varying coefficient DGP (Data Generating Process) based on formulations proposed by Fotheringam et al. (2017), Gao et al. (2021), or Geniaux (2024).
simu_multiscale(n=1000,myseed=1,type='GG2024',constant=NULL, nuls=NULL,config_beta='default',config_snr=0.7,config_eps='normal', ratiotime=1)
simu_multiscale(n=1000,myseed=1,type='GG2024',constant=NULL, nuls=NULL,config_beta='default',config_snr=0.7,config_eps='normal', ratiotime=1)
n |
An integer number of observations |
myseed |
An integer seed used for the simulation. |
type |
Type of DGP used 'FT2017', 'Gao2021' or 'GG2024', default 'GG2024'. |
constant |
A boolean parameter indicating whether the intercept term should be spatially varying (TRUE) or not (FALSE). |
nuls |
A vector of null parameters, default NULL |
config_beta |
name of the type of spatial pattern of Beta coefficients |
config_snr |
a value of signal noise ratio |
config_eps |
name of the distribution of error ('normal','unif' or 'Chi2') |
ratiotime |
multiplicating factor, for spacetime DGP. |
A named list with simulated data ('mydata') and coords ('coords')
library(mgwrsar) library(ggplot2) library(gridExtra) library(grid) simu=simu_multiscale(1000) mydata=simu$mydata coords=simu$coords p1<-ggplot(mydata,aes(x,y,col=Beta1))+geom_point() +scale_color_viridis_c() p2<-ggplot(mydata,aes(x,y,col=Beta2))+geom_point() +scale_color_viridis_c() p3<-ggplot(mydata,aes(x,y,col=Beta3))+geom_point() +scale_color_viridis_c() p4<-ggplot(mydata,aes(x,y,col=Beta4))+geom_point() +scale_color_viridis_c() grid.arrange(p1,p2,p3,p4,nrow=2,ncol=2, top = textGrob("DGP Geniaux (2024)" ,gp=gpar(fontsize=20,font=3)))
library(mgwrsar) library(ggplot2) library(gridExtra) library(grid) simu=simu_multiscale(1000) mydata=simu$mydata coords=simu$coords p1<-ggplot(mydata,aes(x,y,col=Beta1))+geom_point() +scale_color_viridis_c() p2<-ggplot(mydata,aes(x,y,col=Beta2))+geom_point() +scale_color_viridis_c() p3<-ggplot(mydata,aes(x,y,col=Beta3))+geom_point() +scale_color_viridis_c() p4<-ggplot(mydata,aes(x,y,col=Beta4))+geom_point() +scale_color_viridis_c() grid.arrange(p1,p2,p3,p4,nrow=2,ncol=2, top = textGrob("DGP Geniaux (2024)" ,gp=gpar(fontsize=20,font=3)))
summary_Matrix to be documented
summary_Matrix(object, ...)
summary_Matrix(object, ...)
object |
to be documented |
... |
to be documented |
to be documented
summary for mgwrsar model
## S4 method for signature 'mgwrsar' summary(object, ...)
## S4 method for signature 'mgwrsar' summary(object, ...)
object |
A model of class |
... |
summary parameters forwarded. |
A summary object.
This function performs a multiscale Geographically Weighted Regression (GWR) using a top-down scaling approach, adjusting GWR coefficients with a progressively decreasing bandwidth as long as the AICc criterion improves.
tds_mgwr(formula,data,coords,Model='tds_mgwr',kernels='triangle', fixed_vars=NULL,H2=NULL,control_tds=list(nns=30,get_AIC=FALSE), control=list(adaptive=TRUE))
tds_mgwr(formula,data,coords,Model='tds_mgwr',kernels='triangle', fixed_vars=NULL,H2=NULL,control_tds=list(nns=30,get_AIC=FALSE), control=list(adaptive=TRUE))
formula |
a formula. |
data |
a dataframe. |
coords |
default NULL, a dataframe or a matrix with coordinates |
Model |
character containing the type of model: Possible values are "tds_mgwr" and "atds_mgwr", See Details for more explanation. |
kernels |
A vector containing the kernel types. Possible types: triangle ("triangle"), rectangle ("rectangle"), bisquare ("bisq"), tricube ("tcub"), gaussian ("gauss"), epanechnikov ("epane"). |
fixed_vars |
a vector with the names of spatiallay constant coefficient for mixed model. All other variables present in formula are supposed to be spatially varying. If empty or NULL (default), all variables in formula are supposed to be spatially varying. |
H2 |
A scalar or vector of time bandwidths. |
control_tds |
list of extra control arguments for tds_mgwr models |
control |
list of extra control arguments for MGWRSAR wrapper |
Length of the sequence of decreasing bandwidth. Should be between 20 and 100, default 30
Boolean, if the Global AICc using Yu et al 2019 should be computed. Required if the second stage 'atds_mgwr' has to be estimated. default FALSE
Starting model, 'GWR' or 'OLS', 'default OLS'.
If model='tds_mgwr', model_stage1 can be used as a starting model (either a GWR model or a preious tds_mgwr model). For model='atds_mgwr, the user can specified an tds_mgwr model already computed with get_AIC=TRUE. default NULL.
Parallel computation, default FALSE.
number of CPU core for parallel computation, default 1
Tolerance for stopping criteria, default 0.0001
Number of nrounds for 'atds_mgwr' model. Default 3.
verbose mode, default FALSE.
A vector of decreasing bandwidths given by the user, default NULL
The value of the highest bandwidth for the sequence of decreasing bandwidth, default NULL.
The value of the smallest bandwidth for the sequence of decreasing bandwidth, default number of covariates + 2 .
A vector of bandwidth, default NULL
A matrix of variables for genralized kernel product, default NULL.
A row-standardized spatial weight matrix for Spatial Aurocorrelation, default NULL.
Verbose mode, default FALSE.
A vector of boolean to choose adaptive version for each kernel.
The type of kernel for computing W, default NULL.
The bandwidth value for computing W, default 0.
Estimation method for computing the models with Spatial Dependence. '2SLS' or 'B2SLS', default '2SLS'.
Avector of target points, default NULL.
Parallel computation, default FALSE. If TRUE and control_tds$doMC is also TRUE, then control$doMC is set to FALSE.
Number of CPU core for parallel computation, default 1
If TRUE, compute a LOOCV criteria, default FALSE.
If TRUE, simplify the computation of CV criteria (remove or not i when using local instruments for model with lambda spatially varying), default TRUE.
When n >NmaxDist, only the maxknn first neighbours are used for distance compution, default 500.
When n >NmaxDist only the maxknn first neighbours are used for distance compution, default 5000
Verbose mode, default FALSE.
gwr_multiscale, MGWRSAR, bandwidths_mgwrsar, summary_mgwrsar.