Learn R Programming

mgwrsar (version 1.3.2)

kernel_matW: 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.

Description

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.

Usage

kernel_matW(H,kernels,coords,NN,TP=NULL,Type='GD',adaptive=FALSE,
diagnull=TRUE,alpha=1,dists=NULL,indexG=NULL,extrapol=FALSE,QP=NULL,K=0)

Value

A sparse Matrix of weights (dgCMatrix).

Arguments

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

Numeric exponent for the generalized kernel product, default 1.

dists

A precomputed list of distance matrices (output of prep_d), default NULL.

indexG

A precomputed matrix of neighbor indices (output of prep_d), default NULL.

extrapol

Logical. If TRUE, compute weights for extrapolation (out-of-sample), default FALSE.

QP

A matrix with variables used in kernel (neighbors), default NULL (if NULL coord_j=coord_i).

K

Integer, number of folds for block computation, default 0 (no blocking).

Examples

Run this code
# \donttest{
 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)
# }

Run the code above in your browser using DataLab