R/isoMean.r

Defines functions isoMean

Documented in isoMean

isoMean <- function(y, w) {
  n <- length(y)
  k <- 1:n * 0
  gew <- 1:n * 0
  ghat <- 1:n * 0
  c <- 1
  k[c] <- 1
  gew[c] <- w[1]
  ghat[c] <- y[1]
  for (j in 2:n) {
    c <- c + 1
    k[c] <- j
    gew[c] <- w[j]
    ghat[c] <- y[j]
    while (c >= 2 && ghat[max(1, c - 1)] >= ghat[c]) {
      neu <- gew[c] + gew[c - 1]
      ghat[c - 1] <- ghat[c - 1] + (gew[c] / neu) * (ghat[c] - ghat[c - 1])
      gew[c - 1] <- neu
      c <- c - 1
    }
  }
  while (n >= 1) {
    for (j in k[c]:n) {
      ghat[j] <- ghat[c]
    }
    n <- k[c] - 1
    c <- c - 1
  }
  return(ghat)
}

Try the logcondens package in your browser

Any scripts or data that you put into this service are public.

logcondens documentation built on Aug. 22, 2023, 5:06 p.m.