| strata.data | R Documentation |
This function takes in the univariate population data (argument data)
and a fixed sample size (n) to compute the optimum stratum boundaries (OSB)
for a given number of strata (L), optimum sample sizes (nh), etc. directly
from the data. The main idea used is from Khan et al (2008) whereby the
problem of stratification is formulated into a Mathematical Programming
Problem (MPP) using the best-fit frequency distribution and its parameters
estimated from the data. This MPP is then solved for the OSB using a Dynamic
Programming (DP) solution procedure.
strata.data(
data,
h,
n,
cost = FALSE,
ch = NULL,
method = c("dp", "cobyla", "global", "exact"),
n_starts = 20L,
max_iter = 2000L,
tol = 1e-09,
verbose = FALSE,
fpc = FALSE,
takeall = FALSE
)
data |
A numeric vector with the values of the stratification
variable for every unit of the population. It must have no missing or
infinite values and at least |
h |
The number of strata, a whole number of at least 2. |
n |
The total sample size, a whole number between |
cost |
A logical: has default cost=FALSE. If it is a stratum-cost problem, cost=TRUE, with which, one must provide the Ch parameter. |
ch |
A numeric: denotes a vector of stratum costs. When cost=FALSE, it has a default of NULL. |
method |
Character. Optimisation method. |
n_starts |
Integer. Number of random restarts for the COBYLA solver.
Default |
max_iter |
Integer. Maximum function evaluations per COBYLA start.
Default |
tol |
Numeric. Convergence tolerance for COBYLA. Default |
verbose |
Logical. Print per-start progress. Default |
fpc |
Logical. With |
takeall |
Logical. With |
strata.data returns an object of class "stratifyR" with
the Optimum Strata Boundaries (OSB; the upper boundary of each stratum, the
last being the largest data value), stratum weights (Wh), stratum variances
(Vh), Optimum Sample Sizes (nh), stratum population sizes (Nh) and sampling
fraction (fh). It also contains variance, the variance of the
stratified mean with the finite population correction for the final
allocation, takeall, the number of units in a take-all top stratum (0
if there is none), and fpc, which records whether the full variance
was minimised. Use boundaries, allocation,
objective and variance to get the results, and
summary() for the full table.
Karuna Reddy <karuna.reddy@auckland.ac.nz>
MGM Khan
<mgm.khan@usp.ac.fj>
strata.distr, boundaries,
summary.stratifyR, compare_designs,
plot.stratifyR
data(sugarcane)
dp <- strata.data(sugarcane$Production, h = 4, n = 500)
exact <- strata.data(sugarcane$Production, h = 4, n = 500, method = "exact")
c(dp = dp$WhShTot, exact = exact$WhShTot)
# minimise the full variance, allowing a take-all top stratum
set.seed(1)
x <- (runif(2000)^(-1/2) - 1) # heavy-tailed (Pareto II) population
ta <- strata.data(x, h = 4, n = 200, method = "exact", takeall = TRUE)
c(variance = ta$variance, takeall = ta$takeall)
## Not run:
data <- rweibull(1000, shape=2, scale = 1.5)
hist(data)
obj <- strata.data(data, h = 2, n=300)
summary(obj)
#-------------------------------------------------------------
data(anaemia)
Iron <- anaemia$Iron
res <- strata.data(Iron, h = 2, n=350)
summary(res)
#-------------------------------------------------------------
data(SHS) #Household Spending data from stratification package
weight <- SHS$WEIGHT
hist(weight); length(weight)
res <- strata.data(weight, h = 2, n=500)
summary(res)
#-------------------------------------------------------------
data(sugarcane)
Production <- sugarcane$Production
hist(Production)
res <- strata.data(Production, h = 2, n=1000)
summary(res)
#-------------------------------------------------------------
#The function be dynamically used to visualize the the strata boundaries,
#for 2 strata, over the density (or observations) of the "mag" variable
#from the quakes data (with purrr and ggplot2 packages loaded).
output <- quakes %>%
pluck("mag") %>%
strata.data(h = 2, n = 300)
quakes %>%
ggplot(aes(x = mag)) +
geom_density(fill = "blue", colour = "black", alpha = 0.3) +
geom_vline(xintercept = output$OSB, linetype = "dotted", color = "red")
#-------------------------------------------------------------
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.