Essential Wavelets for Statistical
Applications and Data Analysis

R.T. Ogden, University of South Carolina
0-8176-3864-4 * 1996 * $40.00 * Hardcover * 285 pages * 40 Illustrations

Fig8.1n <- function(n = 2048)
{
#  postscript(file = "Fig8.1.ps", horizontal = F, width = 3.5, height = 4.5)
  par(mfrow = c(3, 2), mar = c(2.5, 2.5, 1.5, 0.5), mgp = c(1.5, 0.4, 0))
  rs <- c(57, 14, 55, 51, 30, 0, 53, 44, 34, 53, 49, 2)
  .Random.seed <- rs
  x <- (1:n)/n
  f <- fblocks(x)
  ssig <- sqrt(var(f))
  f <- ((f - mean(f)) * 5)/ssig
  fnoise <- f + rnorm(n)
  fwd <- wd(fnoise, filter.number = 5)
                                        # Coefficients for level 10
  level10 <- sort(abs(extract(fwd, 10)))
  possiblet <- sort(c(0, level10, sqrt(2 * log(n))))
  surevec <- sapply(possiblet, sure, level10)
  thresh <- possiblet[match(min(surevec), surevec)]
  plot(level10, ylab = "values", ylim = c(0, max(level10)), pch = "+")
  lines(c(1, 2^10), rep(thresh, 2), type = "l", lty = 2)
  mtext("Level 10 coefficients", side = 3, line = 0.1)
  plot(possiblet, surevec, type = "l", ylab = "SURE(t;x)", xlab = "t", 
       xlim = c(0, min(sqrt(2 * log(n)), max(level10))))
  mtext("SURE(t;x) for level 10", side = 3, line = 0.1) 
                                        # Coefficients for level 9
  level9 <- sort(abs(extract(fwd, 9)))
  possiblet <- sort(c(0, level9, sqrt(2 * log(n))))
  surevec <- sapply(possiblet, sure, level9)
  thresh <- possiblet[match(min(surevec), surevec)]
  plot(level9, ylab = "values", ylim = c(0, max(level9)), pch = "+")
  lines(c(1, 2^9), rep(thresh, 2), type = "l", lty = 2)
  mtext("Level 9 coefficients", side = 3, line = 0.1)
  plot(possiblet, surevec, type = "l", ylab = "SURE(t;x)", xlab = "t", 
       xlim = c(0, min(sqrt(2 * log(n)), max(level9))))
  mtext("SURE(t;x) for level 9", side = 3, line = 0.1)  
                                        # Coefficients for level 8
  level8 <- sort(abs(extract(fwd, 8)))
  possiblet <- sort(c(0, level8, sqrt(2 * log(n))))
  surevec <- sapply(possiblet, sure, level8)
  thresh <- possiblet[match(min(surevec), surevec)]
  plot(level8, ylab = "values", ylim = c(0, max(level8)), pch = "+")
  lines(c(1, 2^8), rep(thresh, 2), type = "l", lty = 2)
  mtext("Level 8 coefficients", side = 3, line = 0.1)
  plot(possiblet, surevec, type = "l", ylab = "SURE(t;x)", xlab = "t", 
       xlim = c(0, min(sqrt(2 * log(n)), max(level8))))
  mtext("SURE(t;x) for level 8", side = 3, line = 0.1)
#  graphics.off()
  NULL
}

sure <- function(t, x)
{
  ax <- sort(abs(x))    
                                        #  num gives the number of elements
                                        # in x that are <= t
  num <- match(F, ax <= t, nomatch = length(ax) + 1) - 1
  length(ax) - 2 * num + sum(pmin(ax, t)^2)
}