View source: R/adjust_samples_to_budget.R
adjust_samples_to_budget | R Documentation |
Adds a new column with an adjusted sample number per selected unit. The total sample size is adjusted to be in accord with the total budgeted sample number.
adjust_samples_to_budget(
data,
group = NULL,
budget,
sample_to_adjust,
adjusted_sample = "justert_ant_prover",
adjust_by = 1
)
data |
[ |
group |
[ |
budget |
[ |
sample_to_adjust |
[ |
adjusted_sample |
[ |
adjust_by |
[ |
The sample number per unit should first have been estimated, for example can the sample number per abattoir be the total number of samples distributed on the abattoirs in accord with the slaughter volume at each abattoir. Often will rounding errors lead to a difference between the total budgeted sample number and the total estimated sample number. Therefore, the estimated sample number need to be adjusted.
The estimated sample number is first adjusted for the unit with the largest sample number. Thereafter, for the unit with the next largest sample number and so on.
The sample number will often be estimated so that it is a multiplicand
multiplied by of a given number (multiplier). For example, if equal
number of samples should be taken every month the multiplier can be 12,
if the samples are pooled five and five, the multiplier can be 5. If the
argument adjust_by
is given the multiplier, the sample number will
be adjusted by the multiplier unless the difference that should be adjusted
is less than the multiplier. In that case, the sample number will be
adjusted by a number less than the adjust_by
.
A data frame with a new column with an adjusted sample number.
Petter Hopp Petter.Hopp@vetinst.no
library(OKplan)
# Add data frame with sample number to adjust
x <- as.data.frame(cbind(c(1:10),
c(24, 30, 36, 12, 6, 18, 6, 0, 0, 0)))
colnames(x) <- c("id", "sample")
# Adjust total sample number to budget
x <- adjust_samples_to_budget(data = x,
budget = 150,
sample_to_adjust = "sample",
adjusted_sample = "new_sample",
adjust_by = 4)
# Adjust total sample number to budget per group
total_budget <- 60 # same budget for all groups
# Add data frame with sample number to adjust
x <- as.data.frame(cbind(c(1:10),
c(rep("x", 5), rep("y", 5)),
c(24, 18, 6, 0, 30, 36, 12, 6, 0, 0)))
colnames(x) <- c("id", "xy", "sample")
x2 <- adjust_samples_to_budget(data = x,
group = "xy",
budget = total_budget,
sample_to_adjust = "sample",
adjusted_sample = "new_sample",
adjust_by = 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.