dirichlet_sample function

Function which performs Dirichlet sampling

Function which performs Dirichlet sampling

It uses Dirichlet weights for creating sub-samples of initial data set.

dirichlet_sample(in_data = NULL, sample_size = NULL, replacement = NULL, rseed = NULL)

Arguments

  • in_data: The initial data frame that must be re-sampled. It must contain:

    1. an ID variable
    2. the variables of interest
    3. a grouping variable
  • sample_size: An integer for the size of the new sample

  • replacement: A logical input: TRUE/FALSE if replacement should be used or not, respectively

  • rseed: The random seed that will be used for setting initial A matrix. Useful for reproducible results

Returns

It returns a data frame with exactly the same variables as the initial one, except that group variable has now only the given value from input data frame.

Author(s)

David Midgley

See Also

grouped_resample

Examples

## Load absolute temperature data set: data("AbsoluteTemperature") df=AbsoluteTemperature ## Find portions for climate zones pcs=table(df$z)/dim(df)[1] ## Choose the approximate size of the new sample and compute resample sizes N=1000 resamplesizes=as.integer(round(N*pcs)) sum(resamplesizes) ## Create the grouping matrix groupmat=data.frame("Group_ID"=1:4,"Resample_Size"=resamplesizes) groupmat ## Dirichlet resampling: resample_dirichlet <- grouped_resample(in_data = df,grp_vector = "z", grp_matrix = groupmat,replace = FALSE, option = "Dirichlet", rseed = 20191220) cat(dim(resample_dirichlet),"\n")
  • Maintainer: Demetris Christopoulos
  • License: GPL (>= 2)
  • Last published: 2024-05-23

Useful links