predIntNormHalfWidth {EnvStats}  R Documentation 
k
Observations from a Normal Distribution
Compute the halfwidth of a prediction interval for the next k
observations
from a normal distribution.
predIntNormHalfWidth(n, df = n  1, n.mean = 1, k = 1, sigma.hat = 1,
method = "Bonferroni", conf.level = 0.95)
n 
numeric vector of positive integers greater than 1 indicating the sample size upon
which the prediction interval is based.
Missing ( 
df 
numeric vector of positive integers indicating the degrees of freedom associated
with the prediction interval. The default is 
n.mean 
numeric vector of positive integers specifying the sample size associated with
the 
k 
numeric vector of positive integers specifying the number of future observations
or averages the prediction interval should contain with confidence level

sigma.hat 
numeric vector specifying the value(s) of the estimated standard deviation(s).
The default value is 
method 
character string specifying the method to use if the number of future observations
( 
conf.level 
numeric vector of values between 0 and 1 indicating the confidence level of the
prediction interval. The default value is 
If the arguments n
, k
, n.mean
, sigma.hat
, and
conf.level
are not all the same length, they are replicated to be the
same length as the length of the longest argument.
The help files for predIntNorm
and predIntNormK
give formulas for a twosided prediction interval based on the sample size, the
observed sample mean and sample standard deviation, and specified confidence level.
Specifically, the twosided prediction interval is given by:
[\bar{x}  Ks, \bar{x} + Ks] \;\;\;\;\;\; (1)
where \bar{x}
denotes the sample mean:
\bar{x} = \frac{1}{n} \sum_{i=1}^n x_i \;\;\;\;\;\; (2)
s
denotes the sample standard deviation:
s^2 = \frac{1}{n1} \sum_{i=1}^n (x_i  \bar{x})^2 \;\;\;\;\;\; (3)
and K
denotes a constant that depends on the sample size n
, the
confidence level, the number of future averages k
, and the
sample size associated with the future averages, m
(see the help file for
predIntNormK
). Thus, the halfwidth of the prediction interval is
given by:
HW = Ks \;\;\;\;\;\; (4)
numeric vector of halfwidths.
See the help file for predIntNorm
.
Steven P. Millard (EnvStats@ProbStatInfo.com)
See the help file for predIntNorm
.
predIntNorm
, predIntNormK
,
predIntNormN
, plotPredIntNormDesign
.
# Look at how the halfwidth of a prediction interval increases with
# increasing number of future observations:
1:5
#[1] 1 2 3 4 5
hw < predIntNormHalfWidth(n = 10, k = 1:5)
round(hw, 2)
#[1] 2.37 2.82 3.08 3.26 3.41
#
# Look at how the halfwidth of a prediction interval decreases with
# increasing sample size:
2:5
#[1] 2 3 4 5
hw < predIntNormHalfWidth(n = 2:5)
round(hw, 2)
#[1] 15.56 4.97 3.56 3.04
#
# Look at how the halfwidth of a prediction interval increases with
# increasing estimated standard deviation for a fixed sample size:
seq(0.5, 2, by = 0.5)
#[1] 0.5 1.0 1.5 2.0
hw < predIntNormHalfWidth(n = 10, sigma.hat = seq(0.5, 2, by = 0.5))
round(hw, 2)
#[1] 1.19 2.37 3.56 4.75
#
# Look at how the halfwidth of a prediction interval increases with
# increasing confidence level for a fixed sample size:
seq(0.5, 0.9, by = 0.1)
#[1] 0.5 0.6 0.7 0.8 0.9
hw < predIntNormHalfWidth(n = 5, conf = seq(0.5, 0.9, by = 0.1))
round(hw, 2)
#[1] 0.81 1.03 1.30 1.68 2.34
#==========
# The data frame EPA.92c.arsenic3.df contains arsenic concentrations (ppb)
# collected quarterly for 3 years at a background well and quarterly for
# 2 years at a compliance well. Using the data from the background well, compute
# the halfwidth associated with sample sizes of 12 (3 years of quarterly data),
# 16 (4 years of quarterly data), and 20 (5 years of quarterly data) for a
# twosided 90% prediction interval for k=4 future observations.
EPA.92c.arsenic3.df
# Arsenic Year Well.type
#1 12.6 1 Background
#2 30.8 1 Background
#3 52.0 1 Background
#...
#18 3.8 5 Compliance
#19 2.6 5 Compliance
#20 51.9 5 Compliance
mu.hat < with(EPA.92c.arsenic3.df,
mean(Arsenic[Well.type=="Background"]))
mu.hat
#[1] 27.51667
sigma.hat < with(EPA.92c.arsenic3.df,
sd(Arsenic[Well.type=="Background"]))
sigma.hat
#[1] 17.10119
hw < predIntNormHalfWidth(n = c(12, 16, 20), k = 4, sigma.hat = sigma.hat,
conf.level = 0.9)
round(hw, 2)
#[1] 46.16 43.89 42.64
#==========
# Clean up
#
rm(hw, mu.hat, sigma.hat)