[Rd] postscript problem (PR#1147)

kjetilh@umsanet.edu.bo kjetilh@umsanet.edu.bo
Fri, 26 Oct 2001 21:23:19 +0200 (MET DST)


I reported this earlier, and have got reports that others have the same
promlem on UNIX machines, so it is not only a windows problem
S I file a bug report.

The function (boot.stat) given at the end produces a postscript file, 
which cannot be included correctly in LaTeX. Specifically, 
the image in LaTeX (when translated by dvips to postscript)
becomes very small, not using the bounding box, and turned on its head!

Kjetil Halvorsen

boot.stat <-
function (x, B = 1000, norm = FALSE) 
{
    xname <- deparse(substitute(x))
    means <- meds <- numeric(B)
    for (i in 1:B) {
        s <- sample(x, replace = TRUE)
        means[i] <- mean(s)
        meds[i] <- median(s)
    }
    CImedian <- quantile(meds, c(0.025, 0.5, 0.975))
    CImean <- quantile(means, c(0.025, 0.5, 0.975))
    hmean <- hist(means, freq = FALSE, plot = FALSE)
    hmeds <- hist(meds, freq = FALSE, plot = FALSE)
    split.screen(c(1, 2))
    xlims <- range(c(hmean$breaks, hmeds$breaks))
    ymax <- max(c(hmean$density, hmeds$density))
    screen(1)
    plot(hmean, freq = FALSE, col = "red", xlim = xlims, ylim = c(0, 
        ymax), xlab = paste("Sampling dist. of mean of ", xname), 
        main = "")
    if (norm) {
        n <- length(x)
        mu <- mean(x)
        sd <- sqrt(var(x)/n)
        ps <- seq(xlims[1], xlims[2], len = 100)
        lines(ps, dnorm(ps, mu, sd), col = "darkgreen")
    }
    lines(CImean, rep(ymax/2, 3))
    points(CImean[2], ymax/2, cex = 2, col = "black")
    screen(2)
    plot(hmeds, freq = FALSE, col = "lightblue", xlim = xlims, 
        ylim = c(0, ymax), xlab = paste("Sampling dist. of median of ",
            xname), main = "")
    if (norm) {
        n <- length(x)
        p <- 1/2
        mu <- median(x)
        d <- density(x, n = 1, from = mu, to = mu)$y
        sd <- sqrt(p * (1 - p)/n)/d
        ps <- seq(xlims[1], xlims[2], len = 100)
        lines(ps, dnorm(ps, mu, sd), col = "darkgreen")
    }
    lines(CImedian, rep(ymax/2, 3))
    points(CImedian[2], ymax/2, cex = 2, col = "black")
    names(B) <- "Number of bootstrap replicactions"
    invisible(list(CImean = CImean, CImedian = CImedian, B, means =
means, 
        meds = meds))
}


call with for example

boot.stat( rnorm(100), norm=TRUE)

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._