SpatialPOP: package for generation of spatial data along with spatial coordinates and spatially varying model parameters

Introduction

****
In this R package, a spatial dataset can be generated under the assumption that observations are collected from a two dimensional uniform grid consists of (m2) lattice points having unit distance between any two neighbouring points along the horizontal and vertical directions.

****

Generation of simulated dataset based on spatially varying regression model

****

generation of spatial coordinates of locations

The size of the population is N= m2. The spatial coordinates of the locations of observations can be computed by the following expressions

( Latitudei, Longitudei )= ( mod(i-1,m), [(i-1)/m] ), i= 1,…, m2

where, mod(i-1,m) is the remainder of (i-1) divided by m and [(i-1)/m] is the integer part of the number (i-1)/m

generation of auxiliary variable from uniform distribution

X =runif(N,0,1)

error term drawn independently from normal distribution i.e. N(0,1)

e =rnorm(N, mean=0, sd=1)

generation of spatially varying regression coefficients

B0=(Latitudei+Longitudei)/6

B1=(Latitudei/3)

spatially varying regression model for generating the response variable

Yi = B0( Latitudei,Longitudei ) + B1( Latitudei,Longitudei )*Xi + ei ; i= 1,…, N

# Examples: generate an uniform two dimensional grid of lattice points 

library(SpatialPOP)
coord_grid=spatial_grid(c(1:5),c(1:5))
coord_grid=as.data.frame(coord_grid)
names(coord_grid)=cbind("x","y")
coord_grid
##    x y
## 1  1 1
## 2  2 1
## 3  3 1
## 4  4 1
## 5  5 1
## 6  1 2
## 7  2 2
## 8  3 2
## 9  4 2
## 10 5 2
## 11 1 3
## 12 2 3
## 13 3 3
## 14 4 3
## 15 5 3
## 16 1 4
## 17 2 4
## 18 3 4
## 19 4 4
## 20 5 4
## 21 1 5
## 22 2 5
## 23 3 5
## 24 4 5
## 25 5 5
plot(coord_grid)

# Examples: simulated data along with spatial coordinates and spatially varying model parameters

library(SpatialPOP)

coord_grid=spatial_grid(c(1:5),c(1:5))
coord_grid=as.data.frame(coord_grid)
names(coord_grid)=cbind("x","y")
coord_grid
##    x y
## 1  1 1
## 2  2 1
## 3  3 1
## 4  4 1
## 5  5 1
## 6  1 2
## 7  2 2
## 8  3 2
## 9  4 2
## 10 5 2
## 11 1 3
## 12 2 3
## 13 3 3
## 14 4 3
## 15 5 3
## 16 1 4
## 17 2 4
## 18 3 4
## 19 4 4
## 20 5 4
## 21 1 5
## 22 2 5
## 23 3 5
## 24 4 5
## 25 5 5
N<-nrow(coord_grid)
N
## [1] 25
m<-sqrt(nrow(coord_grid))
m
## [1] 5
spatial_data<-spatialPOP(25,5,c(1:5),c(1:5))
spatial_data
##              Y          X latitude longitude        B0        B1
## 1  -1.05933556 0.75720344        0         0 0.0000000 0.0000000
## 2  -1.95262460 0.12203700        1         0 0.1666667 0.3333333
## 3   0.98110106 0.23175341        2         0 0.3333333 0.6666667
## 4   0.76762249 0.96280613        3         0 0.5000000 1.0000000
## 5   0.69533170 0.67198425        4         0 0.6666667 1.3333333
## 6  -0.26959830 0.20771006        0         1 0.1666667 0.0000000
## 7   0.52930406 0.11334830        1         1 0.3333333 0.3333333
## 8   1.74154798 0.24197594        2         1 0.5000000 0.6666667
## 9   0.43629029 0.77760356        3         1 0.6666667 1.0000000
## 10  1.20277535 0.96573816        4         1 0.8333333 1.3333333
## 11  1.43733272 0.22971666        0         2 0.3333333 0.0000000
## 12 -0.52495415 0.91109954        1         2 0.5000000 0.3333333
## 13  0.61210058 0.27271729        2         2 0.6666667 0.6666667
## 14  2.99949307 0.81141608        3         2 0.8333333 1.0000000
## 15  2.71262848 0.62634909        4         2 1.0000000 1.3333333
## 16  0.11029462 0.61563372        0         3 0.5000000 0.0000000
## 17  0.05976224 0.86840142        1         3 0.6666667 0.3333333
## 18 -1.65625467 0.06615634        2         3 0.8333333 0.6666667
## 19  1.80491819 0.64978061        3         3 1.0000000 1.0000000
## 20  3.23481104 0.85583566        4         3 1.1666667 1.3333333
## 21  2.48457528 0.61436772        0         4 0.6666667 0.0000000
## 22  1.41686026 0.45674801        1         4 0.8333333 0.3333333
## 23 -0.31369738 0.48102453        2         4 1.0000000 0.6666667
## 24  1.45131015 0.76594872        3         4 1.1666667 1.0000000
## 25  2.80121315 0.10185962        4         4 1.3333333 1.3333333