# Confidence interval for sample variance or standard deviation

### Description

Computes the standard normal (i.e., chi-square) confidence intervals for a sample variance or standard deviation.

### Usage

1 2 3 4 |

### Arguments

`object` |
a numeric vector possibly with a "df" or "df.residuals" attribute assumed to represent a sample variance, possibly computed as root mean square of residuals from a model. |

`parm` |
degrees of freedom in the estimated variance or standard deviation. |

`level` |
the confidence level required |

`...` |
optional arguments not used. |

### Details

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)

### Value

a matrix with columns "lower" and "upper",
`nrow`

= the longest of the lengths
of `object`

, `parm`

, and `level`

,
and an attribute "level".

### Author(s)

Spencer Graves

### References

Wikipedia, "Standard deviation", accessed 2016-07-06.

### See Also

`cor.test`

,
`VarCI`

### 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ```
##
## 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)
``` |

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.