assignStrataLabel: Function to assign the optimized strata labels

View source: R/assignStrataLabel.R

assignStrataLabelR Documentation

Function to assign the optimized strata labels

Description

Function to assign the optimized strata labels to new sampling units in the frame on the basis of the strata structure obtained by executing the function 'summaryStrata' after optimizing with 'optimizeStrata2'

Usage

assignStrataLabel(dataset, s)

Arguments

dataset

dataset with new sampling units in the frame

s

structure of the strata

Value

The same dataset in input with the label of the optimized stratum

Examples

## Not run: 
library(SamplingStrata)
data("swissmunicipalities")
data("errors")
errors$CV1 <- 0.1
errors$CV2 <- 0.1
errors <- errors[rep(row.names(errors),7),]
errors$domainvalue <- c(1:7)
errors
swissmunicipalities$id <- c(1:nrow(swissmunicipalities))
swissmunicipalities$domain = 1
frame <- buildFrameDF(swissmunicipalities,
                      id = "id",
                      domainvalue = "REG",
                      X = c("Surfacesbois","Surfacescult"),
                      Y = c("Pop020", "Pop2040")
)
solution <- optimizeStrata2 (
  errors, 
  frame,
  nStrata = 5,
  iter = 10, 
  pops = 10, 
  writeFiles = FALSE, 
  showPlot = TRUE, 
  parallel = FALSE) 
strataStructure <- summaryStrata(solution$framenew, solution$aggr_strata)
strataStructure


newset <- assignStrataLabel(solution$framenew,strataStructure)

## End(Not run)

barcaroli/SamplingStrata documentation built on Oct. 13, 2023, 8:56 a.m.