MyNixOS website logo
Description

Weakly Associated Vectors (WAVE) Sampling.

Spatial data are generally auto-correlated, meaning that if two units selected are close to each other, then it is likely that they share the same properties. For this reason, when sampling in the population it is often needed that the sample is well spread over space. A new method to draw a sample from a population with spatial coordinates is proposed. This method is called wave (Weakly Associated Vectors) sampling. It uses the less correlated vector to a spatial weights matrix to update the inclusion probabilities vector into a sample. For more details see Raphaël Jauslin and Yves Tillé (2019) <doi:10.1007/s13253-020-00407-1>.

Weakly Associated Vectors (WAVE) Sampling

Spatial data are generally auto-correlated, meaning that if two units selected are close to each other, then it is likely that they share the same properties. For this reason, when sampling in the population it is often needed that the sample is well spread over space. A new method to draw a sample from a population with spatial coordinates is proposed. This method is called wave (weakly associated vectors) sampling. It uses the less correlated vector to a spatial weights matrix to update the inclusion probabilities vector into a sample. For more details see Raphaël Jauslin and Yves Tillé (2019) https://arxiv.org/abs/1910.13152.

Installation

CRAN version

install.packages("WaveSampling")

Latest version

You can install the latest version of the package WaveSampling with the following command:

# install.packages("devtools")
devtools::install_github("Rjauslin/WaveSampling")

Simple example

This basic example shows you how to solve a common problem. Spatial coordinates from the function runif() are firstly generated.

library(WaveSampling)
#> Le chargement a nécessité le package : Matrix

N <- 144
n <- 48
X <- cbind(runif(N),runif(N))
head(X,10)
#>            [,1]      [,2]
#>  [1,] 0.4357956 0.3757532
#>  [2,] 0.3778253 0.9184581
#>  [3,] 0.4171640 0.7267468
#>  [4,] 0.4993113 0.4654331
#>  [5,] 0.8498832 0.8845685
#>  [6,] 0.5836470 0.6395404
#>  [7,] 0.6874862 0.3310646
#>  [8,] 0.1087650 0.9061414
#>  [9,] 0.3874497 0.4504327
#> [10,] 0.4484322 0.6564196

Inclusion probabilities pik is set up all equal with the function rep().

pik <- rep(n/N,times = N)

It only remains to use the function wave(),

s <- wave(X,pik)

We can also generate a plot to observe the result.

library(ggplot2)
ggplot() +
  geom_point(data = data.frame(x = X[,1],y = X[,2]),
             aes(x = x,y = y),
             shape = 1,
             alpha = 0.2)+
  geom_point(data = data.frame(x = X[s == 1,1],y = X[s == 1,2]),
             aes(x,y),
             shape = 16,
             colour = "black")+
  theme_void()

Performance

As explained on the website of Microsoft R open https://mran.microsoft.com/open, R is designed to use only one thread but could be linked with a multi-threaded version of BLAS/LAPACK. The package is implemented with the package RcppArmadillo http://arma.sourceforge.net/ that provide an integration of various matrix decompositions with LAPACK library. Intel MKL that is used by the Microsoft R open use a multi-threaded version of BLAS/LAPACK. Hence the package could gain time from the Microsoft R open. (Not tested, but linking R with OpenBLAS should also work).

N <- 500
n <- 100
X <- as.matrix(cbind(runif(N),runif(N)))
pik <- rep(n/N,N)
system.time(s <- wave(X,pik,tore = T,shift =T,comment = T))

R 3.6.1

user        system    elapsed 
42.96       0.67      43.74

MRO 3.5.3

user        system     elapsed 
53.63       0.87       9.34 

This test was done on PC with a CPU Intel® Core™ i5-8500 with 6 cores.

Metadata

Version

0.1.3

License

Unknown

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows