• It is now available the function SamplingStrataApp that allows to interactively use the package

  • The function prepareSuggestion that prepares suggestion for the optimization with “continuous” method has been completely redefined and improved.

  • New argument mut_factor of optimStrata (methods “continuous” and “spatial”): amplitude of the mutation of the cut points in the genetic algorithm, previously fixed to 0.5. The new default, 0.05, allows a finer local search of the boundaries.

  • Now optimStrata, when using method=“spatial”, accepts also cases in which spatial correlation is not calculated: in this case, set “0” for each element of the vector “range” (or “1” for each element of the new vector “nugget”); “fitting” can be omitted (default 1).

  • Implemented a new function buildErrorsDF that produces a template of the dataframe containing the precision constraints on the target variables of the sampling survey.

  • Implemented a new Rcpp version, much more performant, of the functions

  1. buildStrataDF, to increase the efficiency of the “atomic” and “continuous” methods
  2. buildStrataDFSpatial, to increase the efficiency of the “spatial” method in OptimStrata
  • Moreover, implemented an Rcpp version of the bethel function (namely, bethel_cpp), that is used internally in all the optimization functions, to speed up their execution.

  • Encoding of the cut points in the genetic algorithm of the “continuous” and “spatial” methods. Each gene g in [0, 1] is now the cut point min(X) + g (max(X) - min(X)), with min and max of the stratification variable X in the domain; until now it was g max(X). With variables far from zero (for instance logarithms) most of the genes fell below min(X) and produced empty strata: the solution depended strongly on the seed and often had fewer strata than requested. The results no longer depend on a shift of the X variables, which can now also be negative. prepareSuggestion and evalSuggestion use the same encoding: with variables whose minimum is 0 the results are unchanged, but suggestions computed with the previous version must be recomputed.

Changes to the “spatial” method

The model of the stratum variance used by the “spatial” method (optimStrata with method=“spatial”, optimizeStrataSpatial, KmeansSolutionSpatial, buildStrataDFSpatial, aggrStrataSpatial) and by models of type “spatial” (buildStrataDF, aggrStrata2) has been revised. The variance of stratum h is now

S2_h = Var(predictions) / fitting + sum_{i != j} [s2_i + s2_j - 2 (1 - nugget) s_i s_j exp(-kappa d_ij / range)] / (2 n_h^2)

where s2_i is the prediction-error variance of unit i and d_ij is the distance between units i and j.

  • Additive correction (de Gruijter et al., 2016). The prediction-error variances are added to the variance of the predictions, which is no longer divided by the R2 of the model. Dividing by R2 and adding the error variances counted the error variance twice. The parameter fitting is kept, with default 1: a value lower than 1 together with positive prediction-error variances now gives an error. If only the R2 of the prediction model is known, use fitting = 1 with a constant variance equal to var(predictions) * (1 - R2) / R2.

  • New parameter nugget (default 0): the relative nugget c0 / (c0 + c1) of the variogram of the prediction errors. The correlation between the errors of two distinct units is (1 - nugget) exp(-kappa d / range). With nugget = 1 or range = 0 there is no spatial correlation. Pairs i = j no longer contribute to the variance.

  • Parameter kappa. Use kappa = 1 when range is the range parameter of an exponential variogram (as returned by gstat), kappa = 3 when it is the practical range. Other values are accepted with a warning (in general kappa = -ln p, where p is the correlation left at distance range); values not finite or lower than or equal to 0 give an error.

  • New parameter vgm_model (default “exponential”) in optimStrata (method=“spatial”), optimizeStrataSpatial, KmeansSolutionSpatial, buildStrataDFSpatial and aggrStrataSpatial: the model of the variogram fitted on the prediction errors, which defines the correlation function rho(d) in the covariance (1 - nugget) s_i s_j rho(d_ij). Available models: “exponential”, rho(d) = exp(-kappa d / range); “spherical”, rho(d) = 1 - 1.5 (d / range) + 0.5 (d / range)^3 for d < range and 0 beyond (kappa not used); “gaussian”, rho(d) = exp(-kappa (d / range)^2). The gstat abbreviations “Exp”, “Sph” and “Gau” are also accepted. One model for all the Y’s, one for each Y, or (in optimStrata and optimizeStrataSpatial) a dataframe with one row per domain. With the default, results are unchanged. The same models are available for models of type “spatial” in buildStrataDF and aggrStrata2 (methods “atomic” and “continuous”), through the optional column vgm_model of the model dataframe (default exponential).

  • Same covariance in K-means and in the genetic algorithm. aggrStrataSpatial (used by KmeansSolutionSpatial) used the covariance (s2_i + s2_j) / 2 exp(…), the genetic algorithm s_i s_j exp(…). Both now use s_i s_j, which is a valid covariance when s_i differs from s_j.

  • Models of type “spatial” in buildStrataDF and aggrStrata2 aligned with buildStrataDFSpatial: optional columns fitting (default 1), nugget (default 0) and kappa (default 3, as in optimStrata and optimizeStrataSpatial; the previous code implicitly used kappa = 1, which must now be given explicitly when range is the range parameter returned by gstat); aggrStrata2 no longer adds a covariance term between predictions and errors, and uses gamma. Results of aggrStrata2 with a “spatial” model therefore change.

  • In buildStrataDF all checks on data and model are done, and all data and model parameters are extracted, before the parallel (OpenMP) loop over the domains, which no longer calls the R API: an error raised inside the loop terminated the R session, and with more than one thread the previous code could give “stack imbalance” warnings or random errors.

  • With missing values of a target variable, buildStrataDF now uses the coordinates of the same units as Y in the spatial term (before, the distances could be computed between the wrong units), and aggrStrata2 selects W on the missing values of Y (before, it stopped with an error).

  • The vignette on the spatial method has been rewritten accordingly (theory, variogram models, choice of kappa, estimation of range and nugget on out-of-sample residuals, example with an exponential variogram).

  • Minor changes due to fixing some bugs
  • Minor changes due to the introduction of R 4.3.0

Major changes

  • As in R 4.2.0 a matrix objects now also inherit from class “array”, this invalidates code incorrectly assuming that class(matrix_obj)) has length one. So, changes have been done consequently in SamplingStrata functions where tests on class of an object were performed, otherwise causing errors.

Major changes

  • A new function selectSampleSpatial has been added: if geographical coordinates are available in the frame, in order to obtain spatially distributed selected points this function makes use of the lpm2_kdtree function from the SamplingBigData package (Tillé-Grafstrom).

  • A new function bethelProc has been added: this function allows to execute a complete procedure from the Bethel optimal allocation to the selection of a sample, without having to optimize the strata, that are supposed to be given and fixed.

Major changes

  • As starting from R 4.0.0 ‘stringsAsFactors = FALSE’ becomes a default, in all calls to data.frame the parameter ‘stringAsFactors = TRUE’ has been indicated, in order to ensure the same results

  • Fixed some bugs related to handling take-all strata for ‘atomic’ and ‘spatial’ methods

Major changes

  • A new optimStrata function is available: this function is a wrapper that allows to execute the three different optimization functions: (i) optimizeStrata (method = atomic); (ii) optimizeStrata (method = continuous); (iii) optimizeStrata (method = spatial).

  • A new optimizeStrataSpatial function is available: this function optimizes the frame stratification taking into account also spatial correlation of frame units in a territorial context. As for optimizeStrata2, this function can be used only on continuous stratification variables.

  • A new kMeansSolutionSpatial function has been added: this function is the same than KmeansSolution, but operates in the case of optimization with only continuous stratification variables and has to be used only in conjunction with optimizeStrataSpatial.

  • A new KmeansSolution2 function has been added: this function is the same than KmeansSolution, but operates in the case of optimization with only continuous stratification variables and has to be used only in conjunction with optimizeStrata2.

  • A new prepareSuggestion function has been added: this function operates on the result of kMeanSolution2 or kMeanSolutionSpatial order to prepare the suggestions for the optimization with only continuous stratification variables.

  • A new computeGamma function has been added: this function allows to calculate a heteroscedasticity index, to be passed to optimization step as a model parameter in order to correctly evaluate the variance in the strata.

Major changes

  • A new summaryStrata function has been added, enabling to get structured information regarding the strata produced by the optimizeStrata2 function (operating on only continuous stratification variables).

  • A new assignStrataLabel function has been added, enabling to assign the optimized strata label to new units to be added in the sampling frame.

  • Fixed a bug in the optimization step for continuous variables

Major changes

  • A new function optimizeStrata2 is available. This function performs the same task than optimizeStrata, but with a different Genetic Algorithm, operating on real values genome, instead of an integer one. This pemits to operate directly on the boundaries of the strata, instead of aggregating the initial atomic strata. In some situations (limited size of sampling frame) this new function is much more efficient. The limitation is in the nature of the stratification variables, that are required to be all continuous (though categorical ordinal could be handled).

  • A new function expected_CV has been added to calculate CVs on target variables in different domains that may be expected from a given solution, output of the optimizeStrata execution.

  • Fixed a bug in the optimization step when considering also take-all strata

New functions

  • The optimization of population frame is run in parallel if different domains are considered. To this end, the parameter parallel can be set to TRUE in the optimizeStrata function. If not specified, n-1 of total available cores are used OR if number of domains < (n-1) cores, then number of cores equal to number of domains are used.

  • A new function KmeansSolution produces an initial solution using the kmeans algorithm by clustering atomic strata considering the values of the means of target variables in them. Also, if the parameter nstrata is not indicated, the optimal number of clusters is determined inside each domain, and the overall solution is obtained by concatenating optimal clusters obtained in domains. By indicating this solution as a suggestion to the optimization step, this may greatly speed the convergence to the optimal solution.

  • A new function selectSampleSystematic has been added. It allows to select a stratified sample with the systematic method, that is a selection that begins selecting the first unit by an initial randomly chosen starting point, and proceeding in selecting other units by adding an interval that is the inverse of the sampling rate in the stratum. This selection method can be useful if associated to a particular ordering of the selection frame, where the ordering variable(s) can be considered as additional stratum variable(s).

  • It is now possible to handle anticipated variance by introducing a model linking a proxy variable whose values are available for all units in the sampling frame, with the target variable whose values are not available. In this implementation only linear model can be chosen. When calling the buildStrataDF function, a dataframe is given, containing three parameters (beta, sigma2 and gamma) for each couple target / proxy. On the basis of these parameters, means and standard deviations in sampling strata are calculated accordingly to given formulas.

Major changes

  • The crossover function in the genetic algorithm has been modified by considering the grouping version of this algorithm: instead of mixing chromosomes in an indifferentiate way, groups of them in one parent (representing already aggregated strata) are attributed to the other parent when generating a child, preserving their composition. Moreover, parents are selected with a probability proportional to their fitness (in the previous version selection was completely at random). In many cases this can greatly speed the convergence to an optimal solution.

  • A new function adjustSize has been added. It allows to adjust the sample size and related allocation in strata on the basis of an externally indicated overall sample size. The adjustment of the sample size is perfomed by increasing or decreasing it proportionally in each optimized stratum.

  • A new function buildFrameDF has been added. It allows to create a sampling frame dataframe by indicating the dataset in which the information on all the units are contained, the identifier, the X variables, the Y variable and the variable that indicates the domains of interest.

  • In function optimizeStrata now the initialStrata parameter is a vector, whose length is equal to the number of strata in the different domains.

  • All outputs are written to an .subdirectory.

Major changes

  • Function memoise from the same package (now required) is applied before each evaluation in order to save processing time. This may largely increase the efficiency of the algorithm.

  • A recode function is applied on every generated solution in order to recode a genotype of n genes with k<=n distinct alleles 1, 2, …, k in such a way that the distinct alleles of the recoded genotype appear in the natural order 1, 2, …, k. This avoids to consider as distinct two solutions that are equivalent but make use of a different coding.

Bug fix for old releases

New functions and changes

  • Modified the output to the console or to the file of results: of all the solutions, only the optimal value for each generation is visualised.

  • Now the visualisation of the trend in the optimal and mean values is optional: the plot can be avoided by setting showPlot = FALSE when calling optimizeStrata. It can be advisable when the number of iterations is very high.

Bug fix for old releases.

Major changes

  • The object returned by function optimizeStrata is no more a dataframe but a list: (i) the first element of the list is the solution vector (solutionindices);(ii)thesecondelementofthelististhedataframecontainingaggregatedstrata(solutionindices); (ii) the second element of the list is the dataframe containing aggregated strata (solutionaggr_strata).

  • In all the functions that previously produced .csv files and .pdf plots in the working directory, as a default this is no more the current behaviour. To write these files, it is now necessary to set the writeFiles flag to TRUE.

Major changes

  • Two new functions: (i) evalSolution, to evaluate the found solution in terms of expected target variables precision and bias obtainable by samples drawn from the otpimized frame; (ii) tuneParameters, to determine the best combination of values to assign to the parameters necessary for the execution of the genetic algorithm used for the optimization of the frame stratification.