kernel_matW: kernel_matW A function that returns a sparse weight matrix...

View source: R/kernel_matW.R

kernel_matWR Documentation

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,coord_i,coord_j=NULL,NN,ncolX=1,
Type='GD',adaptive=F,diagnull=TRUE,rowNorm=TRUE,noisland=FALSE)

Arguments

H

A vector of bandwidths

kernels

A vector of kernel types

coord_i

A matrix with variables used in kernel (reference)

coord_j

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

NN

Number of spatial Neighbours for kernels computations

ncolX

control parameter

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

rowNorm

A boolean, row normalization of weights, default TRUE

noisland

A boolean to avoid isle with no neighbours for non adaptive kernel, default FALSE

Value

A sparse Matrix of weights (dgCMatrix).

Examples


 library(mgwrsar)
 ## loading data example
 data(mydata)
 coord=as.matrix(mydata[,c("x_lat","y_lon")])
 ## Creating a spatial weight matrix (sparce dgCMatrix) of 4 nearest neighbors with 0 in diagonal
 W=kernel_matW(H=4,kernels='rectangle',coord_i=coord,NN=4,adaptive=TRUE,diagnull=TRUE,rowNorm=TRUE)


mgwrsar documentation built on April 17, 2023, 9:09 a.m.