Calculates symmetric Wald confidence intervals.

wald(
  thetahat,
  sehat,
  null = 0,
  alpha = c(0.001, 0.01, 0.05),
  dist = "z",
  df,
  eval = FALSE,
  theta = 0
)

Arguments

thetahat

Numeric. Parameter estimate \(\left( \hat{\theta} \right)\).

sehat

Numeric. Estimated standard error of thetahat \(\left( \widehat{\mathrm{se}} \left( \hat{\theta} \right) \right)\).

null

Numeric. Hypothesized value of theta \(\left( \theta_{0} \right)\). Set to zero by default.

alpha

Numeric vector. Significance level \(\left( \alpha \right)\) . By default, alpha is set to conventional significance levels alpha = c(0.001, 0.01, 0.05).

dist

Character string. dist = "z" for the standard normal distribution. dist = "t" for the t distribution.

df

Numeric. Degrees of freedom (df) if dist = "t". Ignored if dist = "z".

eval

Logical. Evaluate confidence intervals using zero_hit(), theta_hit(), len(), and shape().

theta

Numeric. Population parameter \( \left( \theta \right) \).

Value

Returns a vector with the following elements:

statistic

Square root of Wald test statistic.

p

p-value.

se

Estimated d=standard error of thetahat \(\left( \widehat{\mathrm{se}} \left( \hat{\theta} \right) \right)\).

ci_

Estimated confidence limits corresponding to alpha.

If eval = TRUE, also returns

zero_hit_

Logical. Tests if confidence interval contains zero.

theta_hit_

Logical. Tests if confidence interval contains theta.

length_

Length of confidence interval.

shape_

Shape of confidence interval.

Details

As the sample size approaches infinity \(\left( n \to \infty \right)\), the distribution of \(\hat{\theta}\) approaches the normal distribution with mean equal to \(\theta\) and variance equal to \(\widehat{\mathrm{Var}} \left( \hat{\theta} \right)\) $$ \hat{\theta} \mathrel{\dot\sim} \mathcal{N} \left( \theta, \widehat{\mathrm{Var}} \left( \hat{\theta} \right) \right) . $$ As such, \( \hat{\theta} \) can be expressed in terms of \(z\)-scores from a standard normal distribution $$ \frac{ \hat{\theta} - \theta } { \widehat{\mathrm{se}} \left( \hat{\theta} \right) } \mathrel{\dot\sim} \mathcal{N} \left( 0, 1 \right) $$ where \( \widehat{\mathrm{se}} \left( \hat{\theta} \right) = \sqrt{ \widehat{\mathrm{Var}} \left( \hat{\theta} \right) } \).

To form a confidence interval around \(\hat{\theta}\), the \(z\)-score associated with a particular alpha level can be plugged-in the equation below. $$ \hat{\theta} \pm z_{\frac{\alpha}{2}} \times \widehat{\mathrm{se}} \left( \hat{\theta} \right) $$

Note that this is valid only when \(n \to \infty\). In finite samples, this is only an approximation. Gosset derived a better approximation in the context of \(\hat{\theta} = \bar{x}\) $$ \frac{ \hat{\theta} - \theta } { \widehat{\mathrm{se}} \left( \hat{\theta} \right) } \mathrel{\dot\sim} t \left( \nu \right) $$ where \(t\) is the Student's \(t\) distribution and \(\nu\), the degrees of freedom \(n - 1\), is the Student's \(t\) distribution parameter. As such, the symmetric Wald confidence interval is given by $$ \hat{\theta} \pm t_{ \left( \frac{ \alpha } { 2 } , \nu \right) } \times \widehat{\mathrm{se}} \left( \hat{\theta} \right) . $$ Note that in large sample sizes, \(t\) converges to \(z\).

References

Wikipedia: Confidence interval

Examples

############################################################# # Generate sample data from a normal distribution # with mu = 0 and sigma^2 = 1. ############################################################# set.seed(42) n <- 10000 x <- rnorm(n = n) ############################################################# # Estimate the population mean mu using the sample mean xbar. ############################################################# # Parameter estimate xbar thetahat <- mean(x) thetahat
#> [1] -0.01130945
# Closed form solution for the standard error of the mean sehat <- sd(x) / sqrt(n) sehat
#> [1] 0.01006135
############################################################# # Generate Wald confidence intervals # for alpha = c(0.001, 0.01, 0.05). ############################################################# wald( thetahat = thetahat, sehat = sehat )
#> statistic p se ci_0.05 ci_0.5 ci_2.5 #> -1.124049082 1.739007796 0.010061348 -0.044416585 -0.037225765 -0.031029329 #> ci_97.5 ci_99.5 ci_99.95 #> 0.008410431 0.014606866 0.021797686