Have a look at up
and low
. The values are far too large for a standard-normal distribution.
mean(up) mean(low)
[1] 81.47071 [1] -81.43904
You probably have a thinking error somewhere in your CI()
function. If I understand it correctly, you have a multidimensional standard-normal distribution dat
and want to get the span of the confidence interval for each dimension (column) of dat
.
I would suggest doing it as follows:
CI_span <- function(Int, dat) {
alpha <- (1 - Int) / 2
p_range <- c(alpha, 1 - alpha)
apply(dat, 2, function(iColDat) as.numeric(diff(quantile(iColDat, probs = p_range))))
}
This returns the spans of each columns CI. R has a built in function for computing empirical quantiles called quantile
.
Hth, D