confint.var | R Documentation |
Computes the standard normal (i.e., chi-square) confidence intervals for a sample variance or standard deviation.
## S3 method for class 'var'
confint(object, parm, level=0.95, ...)
## S3 method for class 'sd'
confint(object, parm, level=0.95, ...)
object |
a numeric vector possibly with a |
parm |
degrees of freedom in the estimated variance or standard deviation. |
level |
the confidence level required |
... |
optional arguments not used. |
1. If object
is not numeric, throw
an error.
2. If parm
is missing, look for an
attribute of object
starting with
df
. If present, use that for
parm
. If parm
is absent or
not numeric, throw an error.
3. replicate object
, parm
, and
level
to the same length. Issue a warning
if the longest is not a multiple of the others.
4. alph2 <- (1-level)/2
5. Qntls <- cbind(lower=qchisq(alph2, parm,
lower=FALSE), upper=qchisq(alph2, parm))
6. CI <- (object*parm/Qntls)
7. attr(CI, 'level') <-
Level
7. return(CI)
a matrix with columns "lower" and "upper",
nrow
= the longest of the lengths
of object
, parm
, and level
,
and an attribute "level".
Spencer Graves
Wikipedia, "Standard deviation", accessed 2016-07-06.
cor.test
,
VarCI
##
## 1. simple examples
##
(CI.v <- confint.var(c(1,1,4), c(1, 9, 9)))
(CI.s <- confint.sd(c(1,1,2), c(1, 9, 9)))
# Compare with the examples on Wikipedia
all.equal(CI.s, sqrt(CI.v))
WikipEx <- t(matrix(c(0.45, 31.9, 0.69, 1.83, 1.38, 3.66),
nrow=2))
colnames(WikipEx) <- c('lower', 'upper')
(dCI <- (CI.s-WikipEx))
#Confirm within 2-digit roundoff
max(abs(dCI))<0.0102
##
## 2. test df attributes
##
v <- c(1,1,4)
attr(v, 'df.') <- c(1, 9, 9)
class(v) <- 'var'
vCI <- confint(v)
# check
all.equal(vCI, CI.v)
s <- sqrt(v)
class(s) <- 'sd'
sCI <- confint(s)
# check
all.equal(sCI, CI.s)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.