Skip to content

Lattice Histogram Scaling

2 messages · Roger Koenker, Richard M. Heiberger

#
My apologies,  the data can now be found at:

url <- "http://www.econ.uiuc.edu/~roger/research/ebayes/velo.d"
x <- scan(url,skip = 1)

If I could get each of the histograms to mimic what is produced by

hist(x, 100, freq = FALSE)

I?ve experimented with xlim, ylim, without success so far...

url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker at uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Urbana, IL 61801
#
The original was conditioning the entire histogram, not just the kernel
estimate, on bw.  I am assuming that the bw in the condition should be
bandwidths.

What you want is easily done by using the latticeExtra package.
This works from a new R session:


url <- "http://www.econ.uiuc.edu/~roger/research/ebayes/velo.d"
x <- scan(url,skip = 1)
bandwidths <- (1:4)*10

library(latticeExtra)

H <- histogram( ~ x, nint = 100, border = grey(.9), col = grey(.9),
               type = "density")

DD <- lapply(bandwidths, FUN=density, x=x)

DDplot <- lapply(DD, FUN=function(bw) xyplot(y ~ x, data=bw, type="l",
col="blue", lwd=1.5))
names(DDplot) <- bandwidths

do.call(c, DDplot) ## warning message that I am not chasing down

DDplot.together <- do.call(c, c(DDplot, list(x.same = TRUE, y.same = TRUE)))
DDplot.together + H  ## wrong plot on top

DDplot.together.H <- c(H+DDplot[[1]], H+DDplot[[2]], H+DDplot[[3]],
H+DDplot[[4]], x.same = TRUE, y.same = TRUE)
dimnames(DDplot.together.H)[[1]] <- as.character(bandwidths)
DDplot.together.H <- update(DDplot.together.H, strip=TRUE)
DDplot.together.H ## correct plot on top
On Tue, Aug 15, 2017 at 10:13 AM, Roger Koenker <rkoenker at illinois.edu> wrote: