R/RcppExports.R
buildStrataDFSpatial.RdThis function allows to build the information regarding strata in the population required as an input by the algorithm of Bethel for the optimal allocation. In order to estimate means and standard deviations for target variables Y's, we need data coming from: (1) a previous round of the survey whose sample we want to plan; (2) sample data from a survey with variables that are proxy to the ones we are interested to; (3) a frame containing values of Y's variables (or proxy variables) for all the population. In all cases, each unit in the dataset must contain auxiliary information (X's variables) and also target variables Y's (or proxy variables) values: under these conditions it is possible to build the dataframe "strata", containing information on the distribution of Y's in the different strata (namely, means and standard deviations), together with information on strata (total population, if it is to be censused or not, the cost per single interview). If the information is contained in a sample dataset, a variable named WEIGHT is expected to be present. In case of a frame, no such variable is given, and the function will define a WEIGHT variable for each unit, whose value is always '1'. Missing values for each Y variable will not be taken into account in the computation of means and standard deviations (in any case, NA's can be present in the dataset). The dataframe "strata" is written to an external file (tab delimited, extension "txt"), and will be used as an input by the function "optimizeStrata".
buildStrataDFSpatial(
dataset,
fitting = as.numeric(c(1)),
range = as.numeric(c(0)),
kappa = 3,
progress = FALSE,
verbose = FALSE,
nugget = as.numeric(c(0)),
vgm_model = as.character(c("exponential"))
)This is the name of the dataframe containing the sample data, or the frame data. It is strictly required that auxiliary information is organised in variables named as X1, X2, ... , Xm (there should be at least one of them) and the target variables are denoted by Y1, Y2, ... , Yn. In addition, in case of sample data, a variable named 'WEIGHT' must be present in the dataframe, containing the weigths associated to each sampling unit
Default is 1, which must be used when the frame contains the prediction-error variances (VAR columns): the additive correction (de Gruijter et al. 2016) already accounts for the levelling of the predictions. A value < 1 (the coefficient of determination R2 of the prediction model) divides the squared differences of the predictions, and is accepted only with all VAR = 0 (rescaling correction): with positive variances the error variance would be counted twice, and the function stops. If only R2 is known, the additive correction can be used with fitting = 1 and a constant variance var(predictions) * (1 - R2) / R2.
Range of the correlation function of the prediction errors (in the units of the coordinates), as defined by the variogram model given in vgm_model. 0 means no spatial correlation.
Factor used in evaluating spatial autocorrelation with the exponential and gaussian models: the correlation between the prediction errors of two units at distance d is (1 - nugget) * exp(-kappa * d / range) (exponential) or (1 - nugget) * exp(-kappa * (d / range)^2) (gaussian). Use kappa = 1 when range is the range parameter of the variogram (as returned by gstat), kappa = 3 when range is the practical range. It is not used by the spherical model. Any finite value > 0 is accepted; 0 or negative values give an error. Default is 3.
If set to TRUE, a progress bar is visualised during the execution. Default is FALSE.
If set to TRUE, information is given about the number of strata generated. Default is FALSE.
Relative nugget c0/(c0+c1) of the variogram of the prediction errors, in [0, 1]: the share of the error variance that is not spatially correlated. Default is 0 (no nugget).
Variogram model fitted on the prediction errors, which defines the correlation function rho(d) used in the covariance (1 - nugget) * s_i * s_j * rho(d_ij): "exponential" (default): rho(d) = exp(-kappa * d / range); "spherical": rho(d) = 1 - 1.5 (d / range) + 0.5 (d / range)^3 for d < range, 0 for d >= range (range is the distance at which the variogram reaches the sill); "gaussian": rho(d) = exp(-kappa * (d / range)^2). The gstat abbreviations "Exp", "Sph" and "Gau" are also accepted (case-insensitive). A single value, or one value for each target variable Y.
A dataframe containing strata
# synthetic spatial frame: one domain, one target variable with its
# prediction variance and the coordinates of each unit
set.seed(1234)
frame <- data.frame(id = 1:100, X1 = runif(100), Y1 = runif(100, 10, 20),
var1 = 0.5, lon = runif(100), lat = runif(100),
domainvalue = 1)
frame$X1 <- var.bin(frame$X1, bins = 3) # stratification variable
strata <- buildStrataDFSpatial(dataset = frame, fitting = 1, range = 0.5,
kappa = 3, nugget = 0.3)
strata
#> STRATO N M1 S1 COST CENS DOM1 X1
#> 1 2 28 14.96384 2.918240 1 0 1 2
#> 2 3 23 15.34802 2.787478 1 0 1 3
#> 3 1 49 15.45067 3.103938 1 0 1 1
# same frame, spherical variogram of the prediction errors
strata_sph <- buildStrataDFSpatial(dataset = frame, fitting = 1, range = 0.5,
nugget = 0.3, vgm_model = "spherical")
strata_sph
#> STRATO N M1 S1 COST CENS DOM1 X1
#> 1 2 28 14.96384 2.917797 1 0 1 2
#> 2 3 23 15.34802 2.787170 1 0 1 3
#> 3 1 49 15.45067 3.103521 1 0 1 1