Learn R Programming

archetypal (version 1.1.1)

dirichlet_sample: Function which performs Dirichlet sampling

Description

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

Usage

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

Value

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.

See Also

grouped_resample

Examples

Run this code
# NOT RUN {
## 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")
# }

Run the code above in your browser using DataLab