R/03-sim_comp_preconf.R

Defines functions sim_comp_popVar sim_comp_popMean sim_comp_N sim_comp_n

Documented in sim_comp_n sim_comp_N sim_comp_popMean sim_comp_popVar

#' Preconfigured computation components
#' 
#' \code{sim_comp_n} and \code{sim_comp_N} will add the sample and population size in each domain respectively. \code{sim_comp_popMean} and \code{sim_comp_popVar} the population mean and variance of the variable \code{y}. The data is expected to have a variable \code{idD} identifying domains.
#' 
#' @inheritParams sim_agg
#' 
#' @export
#' @rdname sim_comp_preconf
sim_comp_n <- function(simSetup) {
  sim_comp_sample(simSetup, function(dat) 
    as.data.frame(mutate_(dat, n = nrow(dat))), by = "idD")
}

#' @export
#' @rdname sim_comp_preconf
sim_comp_N <- function(simSetup) {
  sim_comp_pop(simSetup, function(dat) 
    as.data.frame(mutate_(dat, N = nrow(dat))), by = "idD")
}

#' @export
#' @rdname sim_comp_preconf
sim_comp_popMean <- function(simSetup) {
  sim_comp_pop(simSetup, function(dat) 
    as.data.frame(mutate_(dat, popMean = "mean(y)")), by = "idD")
}

#' @export
#' @rdname sim_comp_preconf
sim_comp_popVar <- function(simSetup) {
  sim_comp_pop(simSetup, function(dat) 
    as.data.frame(mutate_(dat, popVar = "var(y)")), by = "idD")
}

Try the saeSim package in your browser

Any scripts or data that you put into this service are public.

saeSim documentation built on Feb. 7, 2022, 5:07 p.m.