adjust_samples_to_budget: Adjust the sample size per selected unit

View source: R/adjust_samples_to_budget.R

adjust_samples_to_budgetR Documentation

Adjust the sample size per selected unit

Description

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.

Usage

adjust_samples_to_budget(
  data,
  group = NULL,
  budget,
  sample_to_adjust,
  adjusted_sample = "justert_ant_prover",
  adjust_by = 1
)

Arguments

data

[data.frame]
Data including a column with the sample number that should be adjusted.

group

[character]
Vector with group variables. Defaults to NULL.

budget

[numeric(1) | character(1)]
The total budgeted sample number or a column in data with the budget number of samples (per group).

sample_to_adjust

[character(1)]
The name of the column with the sample number per unit that should be adjusted.

adjusted_sample

[character(1)]
The name of the new column with the adjusted sample number per unit. Defaults to "justert_ant_prover".

adjust_by

[numeric(1)]
The maximum number of samples that a sample can be adjust by. Defaults to 1.

Details

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.

Value

A data frame with a new column with an adjusted sample number.

Author(s)

Petter Hopp Petter.Hopp@vetinst.no

Examples

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)

NorwegianVeterinaryInstitute/OKplan documentation built on Dec. 20, 2024, 10:41 a.m.