This function estimates the standard error (SE) from the mean and 95% confidence interval (CI) for normal, beta, and gamma distributions.
Arguments
- mean
A numeric value representing the mean of the distribution.
- lower_ci
A numeric value representing the lower bound of the 95% confidence interval.
- upper_ci
A numeric value representing the upper bound of the 95% confidence interval.
- distribution
A character string specifying the type of distribution. Options are "normal", "beta", and "gamma".
Value
A named list containing the mean and a value representing the estimated standard error (SE), upper and lower bounds of the 95% confidence interval, and the parameter distribution.
Details
The standard error (SE) is calculated using different formulas depending on the specified distribution:
- Normal Distribution
The margin of error is calculated as \((upper\_ci - lower\_ci) / 2\). The standard error is then calculated as: $$SE = \frac{margin\_of\_error}{1.96}$$
- Beta Distribution
First, the parameters \(\alpha\) and \(\beta\) are estimated using the method of moments: $$\alpha = mean \times \left( \frac{mean \times (1 - mean)} {\left( \frac{margin\_of\_error}{1.96} \right)^2} - 1 \right)$$ $$\beta = \alpha \times \left( \frac{1}{mean} - 1 \right)$$ The standard error is then calculated as: $$SE = \sqrt{\frac{\alpha \times \beta}{(\alpha + \beta)^2 \times (\alpha + \beta + 1)}}$$
- Gamma Distribution
First, the shape parameter \(k\) and the scale parameter \(\theta\) are estimated: $$k = \frac{mean^2}{(margin\_of\_error / 1.96)^2}$$ $$\theta = \frac{(margin\_of\_error / 1.96)^2}{mean}$$ The standard error is then calculated as: $$SE = \frac{\sqrt{k} \times \theta}{\sqrt{mean}}$$
Examples
if (FALSE) {
# Example usage for normal distribution
mean <- 50
lower_ci <- 45
upper_ci <- 55
distribution <- "normal"
se <- estimate_se(mean, lower_ci, upper_ci, distribution)
print(paste("Estimated Standard Error for", distribution, "distribution:", se))
# Example usage for beta distribution
mean <- 0.5
lower_ci <- 0.4
upper_ci <- 0.6
distribution <- "beta"
se <- estimate_se(mean, lower_ci, upper_ci, distribution)
print(paste("Estimated Standard Error for", distribution, "distribution:", se))
# Example usage for gamma distribution
mean <- 10
lower_ci <- 8
upper_ci <- 12
distribution <- "gamma"
se <- estimate_se(mean, lower_ci, upper_ci, distribution)
print(paste("Estimated Standard Error for", distribution, "distribution:", se))
}