R/sample_spat.R

Defines functions sample_spat

#' A sampling method for bootstrap test with spatial data using distance bisquare kernel.
#'
#' @usage sample_spat(D,h,focal='median')
#' @param D  A square matrix of distance.
#' @param h  A distance bandwidth.
#' @param focal  If focal is NULL, the ith residuals can not be selected for the ith observation, if focal=='median' it could be selected with a probability equals to the median probability of neighbors.
#' @noRd
#' @return a vector of bootstrapped index
sample_spat <-
function(D,h,focal='median'){
mysample=c()
	for(i in 1:nrow(D)){
	h0=h
	while(sum(bisq(D[i,], h0)>0)<10) h0=h0*1.2
	prob_i= bisq(D[i,], h0)
	#cat('sum(prob_i>0)',sum(prob_i>0))
	if(focal=='median') prob_i[i]<-median(prob_i[-i][prob_i[-i]>0]) else prob_i[i]<-0
	mysample<-c(mysample,sample(1:nrow(D),1,prob=prob_i))
	}
mysample
}

Try the mgwrsar package in your browser

Any scripts or data that you put into this service are public.

mgwrsar documentation built on May 29, 2024, 1:27 a.m.