Skip to contents

This function converts the mean and standard error (SE) into the appropriate parameters for the normal, gamma, and beta distributions. It returns the parameters needed for R's `rnorm()`, `rgamma()`, and `rbeta()` functions.

Usage

get_sampling_params(mean, se, distribution)

Arguments

mean

A numeric value representing the mean of the distribution.

se

A numeric value representing the standard error of the distribution.

distribution

A character string specifying the type of distribution. Options are "normal", "gamma", and "beta".

Value

A named list containing the parameters for the specified distribution.

dist_func

A scalar (length one vector) naming the distribution.

dist_params

A named list with elements for R's sampling functions from specified distribution:

for normal distribution:

A list with elements `mean` and `sd`.

for gamma distribution:

A list with elements `shape` and `scale`.

for beta distribution:

A list with elements `alpha` and `beta`.

Details

The parameters for each distribution are calculated as follows:

Normal Distribution

The parameters for the normal distribution are directly the mean and standard deviation: $$mean = \text{mean}$$ $$sd = \text{se}$$

Gamma Distribution

The shape (\(\alpha\)) and scale (\(\beta\)) parameters for the gamma distribution are calculated using: $$\alpha = \left( \frac{\text{mean}}{\text{se}} \right)^2$$ $$\beta = \frac{\text{se}^2}{\text{mean}}$$

Beta Distribution

The alpha (\(\alpha\)) and beta (\(\beta\)) parameters for the beta distribution are calculated using: $$\text{variance} = \text{se}^2$$ $$\text{common\_factor} = \frac{\text{mean} \times (1 - \text{mean})}{\text{variance}} - 1$$ $$\alpha = \text{mean} \times \text{common\_factor}$$ $$\beta = (1 - \text{mean}) \times \text{common\_factor}$$

Examples

if (FALSE) {
mean <- 0.5
se <- 0.1

# Normal distribution parameters
normal_params <- get_sampling_params(mean, se, "normal")
print(normal_params)

# Gamma distribution parameters
gamma_params <- get_sampling_params(mean, se, "gamma")
print(gamma_params)

# Beta distribution parameters
beta_params <- get_sampling_params(mean, se, "beta")
print(beta_params)
}