optimum_allocation(
data = iris, strata = "Species", y = "Sepal.Width",
nsample = 40, method = "WrightII"
)
# Or if input data is summary of strata sd and N:
iris_summary <- data.frame(
strata = unique(iris$Species),
size = c(50, 50, 50),
sd = c(0.3791, 0.3138, 0.3225)
)
optimum_allocation(
data = iris_summary, strata = "strata",
sd_h = "sd", N_h = "size",
nsample = 40, method = "WrightII"
)
# A-optimal allocation to minimize the sum of variances if a vector is
# supplied for y or sd_h
optimum_allocation(
data = iris, strata = "Species", y = c("Sepal.Width", "Sepal.Length"),
weights = c(0.5,0.5),
nsample = 40, method = "WrightII"
)
iris_summary2 <- data.frame(
strata = unique(iris$Species),
size = c(50, 50, 50),
sd1 = c(0.3791, 0.3138, 0.3225),
sd2 = c(0.3525, 0.5162, 0.6359)
)
optimum_allocation(
data = iris_summary2, strata = "strata",
sd_h = c("sd1", "sd2"), weights = c(0.5,0.5),
N_h = "size",
nsample = 40, method = "WrightII"
)
Run the code above in your browser using DataLab