Skip to content

Commit

Permalink
Fixed tiny negative variances on 32 bit architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
pwbogaart committed Oct 31, 2016
1 parent f6170e8 commit 590aa04
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/R/trim_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@
J <- length(tt)
var_tau <- numeric(J)
for (j in 1:J) {
d <- matrix(c(-tt[j] / tt[b]^2, 1/tt[b]))
V <- var_tt[c(b,j), c(b,j)]
var_tau[j] <- t(d) %*% V %*% d
if (j==b) {
# SE in the base year is always 0. In principle this is also the result
# from the algorihtm below applied to $j=b$, but in practice this may result
# in very small negative values, causing NaN's when send to sqrt().
var_tau[j] <- 0.0
} else {
d <- matrix(c(-tt[j] / tt[b]^2, 1/tt[b]))
V <- var_tt[c(b,j), c(b,j)]
var_tau[j] <- t(d) %*% V %*% d
}
}

out <- list(tau=tau, var_tau=var_tau)
Expand Down

0 comments on commit 590aa04

Please sign in to comment.