wald: Confidence Interval - Wald

Description Usage Arguments Details Value Author(s) References Examples

View source: R/wald.R

Description

Calculates symmetric Wald confidence intervals.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 ≤ft( \hat{θ} \right).

sehat

Numeric. Estimated standard error of thetahat ≤ft( \widehat{\mathrm{se}} ≤ft( \hat{θ} \right) \right).

null

Numeric. Hypothesized value of theta ≤ft( θ_{0} \right). Set to zero by default.

alpha

Numeric vector. Significance level ≤ft( α \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 ≤ft( θ \right) .

Details

As the sample size approaches infinity ≤ft( n \to ∞ \right), the distribution of \hat{θ} approaches the normal distribution with mean equal to θ and variance equal to \widehat{\mathrm{Var}} ≤ft( \hat{θ} \right)

\hat{θ} \mathrel{\dot\sim} \mathcal{N} ≤ft( θ, \widehat{\mathrm{Var}} ≤ft( \hat{θ} \right) \right) .

As such, \hat{θ} can be expressed in terms of z-scores from a standard normal distribution

\frac{ \hat{θ} - θ } { \widehat{\mathrm{se}} ≤ft( \hat{θ} \right) } \mathrel{\dot\sim} \mathcal{N} ≤ft( 0, 1 \right)

where \widehat{\mathrm{se}} ≤ft( \hat{θ} \right) = √{ \widehat{\mathrm{Var}} ≤ft( \hat{θ} \right) } .

To form a confidence interval around \hat{θ}, the z-score associated with a particular alpha level can be plugged-in the equation below.

\hat{θ} \pm z_{\frac{α}{2}} \times \widehat{\mathrm{se}} ≤ft( \hat{θ} \right)

Note that this is valid only when n \to ∞. In finite samples, this is only an approximation. Gosset derived a better approximation in the context of \hat{θ} = \bar{x}

\frac{ \hat{θ} - θ } { \widehat{\mathrm{se}} ≤ft( \hat{θ} \right) } \mathrel{\dot\sim} t ≤ft( ν \right)

where t is the Student's t distribution and ν, the degrees of freedom n - 1, is the Student's t distribution parameter. As such, the symmetric Wald confidence interval is given by

\hat{θ} \pm t_{ ≤ft( \frac{ α } { 2 } , ν \right) } \times \widehat{\mathrm{se}} ≤ft( \hat{θ} \right) .

Note that in large sample sizes, t converges to z.

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 ≤ft( \widehat{\mathrm{se}} ≤ft( \hat{θ} \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.

Author(s)

Ivan Jacob Agaloos Pesigan

References

Wikipedia: Confidence interval

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#############################################################
# 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
# Closed form solution for the standard error of the mean
sehat <- sd(x) / sqrt(n)
sehat

#############################################################
# Generate Wald confidence intervals
# for alpha = c(0.001, 0.01, 0.05).
#############################################################
wald(
  thetahat = thetahat,
  sehat = sehat
)

jeksterslabds/jeksterslabRboot documentation built on July 20, 2020, 12:56 p.m.