Hello,
I have written a function that demonstrates the CLT by
generating samples following the exponential distribution,
calculating the means, plotting the histogram, and drawing
the limiting normal curve as an overlay. I have the title
of each histogram state the sample size and rate (1/theta)
for the exponential (the output is actually 4 histograms),
but I can't get the greek letter theta to appear in the
heading. Is this possible? I can get nontext for the xlab
and ylab pretty easily.
Thanks, Jason
Below is my code. Currently it just writes out "theta."
function (theta)
{
layout(matrix(c(1:4),2,2,byrow=TRUE))
par(bg = "cornsilk")
n <- c(1,10,25,50)
for(i in 1:4) {
xbar <- rep(0, 1000)
for (j in 1:1000)
xbar[j] <- mean(rexp(n[i], rate = 1/theta))
heading <- paste("Exp w/ theta =", theta, ", n = ",
n[i])
hist(xbar, prob = TRUE, breaks = "FD", main = title(heading,
font.main = 6),
col = "lightgray", xlab = expression(bar(x)))
xbar <- sort(xbar)
points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])),
type = "l", col = 2)
}
}
Hi,
change the name of function argument "theta" to
something else say "thta" and then use the following
....
heading <- expression(paste("Exp w/ ", theta, "=",
thta, ", n = ", n[i]))
Hope it will help...
Mahbub.
--- Oldradio69 at aol.com wrote:> Hello,
>
> I have written a function that demonstrates the CLT
> by
> generating samples following the exponential
> distribution,
> calculating the means, plotting the histogram, and
> drawing
> the limiting normal curve as an overlay. I have the
> title
> of each histogram state the sample size and rate
> (1/theta)
> for the exponential (the output is actually 4
> histograms),
> but I can't get the greek letter theta to appear in
> the
> heading. Is this possible? I can get nontext for
> the xlab
> and ylab pretty easily.
>
> Thanks, Jason
>
> Below is my code. Currently it just writes out
> "theta."
>
> function (theta)
> {
> layout(matrix(c(1:4),2,2,byrow=TRUE))
> par(bg = "cornsilk")
> n <- c(1,10,25,50)
> for(i in 1:4) {
> xbar <- rep(0, 1000)
> for (j in 1:1000)
> xbar[j] <- mean(rexp(n[i], rate = 1/theta))
> heading <- paste("Exp w/ theta =", theta, ", n
> = ", n[i])
> hist(xbar, prob = TRUE, breaks = "FD", main >
title(heading, font.main = 6),
> col = "lightgray", xlab > expression(bar(x)))
> xbar <- sort(xbar)
> points(xbar, dnorm(xbar, mean = theta, sd > theta/sqrt(n[i])),
> type = "l", col = 2)
> }
> }
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
>
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
__________________________________
Yahoo! SiteBuilder - Free, easy-to-use web site design software
I was not able to get theta italicized, but I otherwise got something
matching my understanding of what you wanted. Consider the following:
plotExpNormal <-
function (theta)
{
layout(matrix(c(1:4),2,2,byrow=TRUE))
par(bg = "cornsilk")
n <- c(1,10,25,50)
for(i in 1:4) {
xbar <- rep(0, 1000)
for (j in 1:1000)
xbar[j] <- mean(rexp(n[i], rate = 1/theta))
heading <- substitute(exp(italic(theta)) == th, list(th=theta))
hist(xbar, prob = TRUE, breaks = "FD", main = title(heading,
font.main = 6),
col = "lightgray", xlab = expression(bar(x)))
xbar <- sort(xbar)
points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])),
type = "l", col = 2)
}
}
plotExpNormal(2)
################
What do you think?
Spencer Graves
p.s. I'm running R 1.7.1 under Windows 2000.
Oldradio69 at aol.com wrote:> Hello,
>
> I have written a function that demonstrates the CLT by
> generating samples following the exponential distribution,
> calculating the means, plotting the histogram, and drawing
> the limiting normal curve as an overlay. I have the title
> of each histogram state the sample size and rate (1/theta)
> for the exponential (the output is actually 4 histograms),
> but I can't get the greek letter theta to appear in the
> heading. Is this possible? I can get nontext for the xlab
> and ylab pretty easily.
>
> Thanks, Jason
>
> Below is my code. Currently it just writes out "theta."
>
> function (theta)
> {
> layout(matrix(c(1:4),2,2,byrow=TRUE))
> par(bg = "cornsilk")
> n <- c(1,10,25,50)
> for(i in 1:4) {
> xbar <- rep(0, 1000)
> for (j in 1:1000)
> xbar[j] <- mean(rexp(n[i], rate = 1/theta))
> heading <- paste("Exp w/ theta =", theta, ", n =
", n[i])
> hist(xbar, prob = TRUE, breaks = "FD", main = title(heading,
font.main = 6),
> col = "lightgray", xlab = expression(bar(x)))
> xbar <- sort(xbar)
> points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])),
> type = "l", col = 2)
> }
> }
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Hi -- your solution looses the ability to assign the values of theta and n[i] in the simulation... you get thta and n_i in the titles. In a message dated 7/22/2003 10:44:59 AM Eastern Standard Time, ahmlatif at yahoo.com writes:> Hi, > > change the name of function argument "theta" to > something else say "thta" and then use the following > .... > > heading <- expression(paste("Exp w/ ", theta, "=", > thta, ", n = ", n[i])) > > Hope it will help... > > Mahbub. > > --- Oldradio69 at aol.com wrote: > > Hello, > > > > I have written a function that demonstrates the CLT > > by > > generating samples following the exponential > > distribution, > > calculating the means, plotting the histogram, and > > drawing > > the limiting normal curve as an overlay. I have the > > title > > of each histogram state the sample size and rate > > (1/theta) > > for the exponential (the output is actually 4 > > histograms), > > but I can't get the greek letter theta to appear in > > the > > heading. Is this possible? I can get nontext for > > the xlab > > and ylab pretty easily. > > > > Thanks, Jason > > > > Below is my code. Currently it just writes out > > "theta." > > > > function (theta) > > { > > layout(matrix(c(1:4),2,2,byrow=TRUE)) > > par(bg = "cornsilk") > > n <- c(1,10,25,50) > > for(i in 1:4) { > > xbar <- rep(0, 1000) > > for (j in 1:1000) > > xbar[j] <- mean(rexp(n[i], rate = 1/theta)) > > heading <- paste("Exp w/ theta =", theta, ", n > > = ", n[i]) > > hist(xbar, prob = TRUE, breaks = "FD", main > > title(heading, font.main = 6), > > col = "lightgray", xlab > > expression(bar(x))) > > xbar <- sort(xbar) > > points(xbar, dnorm(xbar, mean = theta, sd > > theta/sqrt(n[i])), > > type = "l", col = 2) > > } > > } > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > __________________________________ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site design > software > http://sitebuilder.yahoo.com
Here is another solution. I'm not sure what you are trying to accomplish
with font.main=6, though. See ?par for details: have a closer look at the
description for "font" option.
Cheers,
Jerome
theta <- 2
layout(matrix(c(1:4),2,2,byrow=TRUE))
par(bg = "cornsilk")
n <- c(1,10,25,50)
for(i in 1:4) {
xbar <- rep(0, 1000)
for (j in 1:1000)
xbar[j] <- mean(rexp(n[i], rate = 1/theta))
heading <- paste("paste(plain('Exp w/ '),theta,' =
", theta,
", n = ", n[i],"')",sep="")
hist(xbar, prob = TRUE, breaks = "FD", main=parse(text=heading),
font.main = 6,
col = "lightgray", xlab = expression(bar(x)))
xbar <- sort(xbar)
points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])),
type = "l", col = 2)
}
On July 22, 2003 08:11 am, Oldradio69 at aol.com wrote:> Content-Length: 1269
> Status: R
> X-Status: N
>
> Hello,
>
> I have written a function that demonstrates the CLT by
> generating samples following the exponential distribution,
> calculating the means, plotting the histogram, and drawing
> the limiting normal curve as an overlay. I have the title
> of each histogram state the sample size and rate (1/theta)
> for the exponential (the output is actually 4 histograms),
> but I can't get the greek letter theta to appear in the
> heading. Is this possible? I can get nontext for the xlab
> and ylab pretty easily.
>
> Thanks, Jason
>
> Below is my code. Currently it just writes out "theta."
>
> function (theta)
> {
> layout(matrix(c(1:4),2,2,byrow=TRUE))
> par(bg = "cornsilk")
> n <- c(1,10,25,50)
> for(i in 1:4) {
> xbar <- rep(0, 1000)
> for (j in 1:1000)
> xbar[j] <- mean(rexp(n[i], rate = 1/theta))
> heading <- paste("Exp w/ theta =", theta, ", n =
", n[i])
> hist(xbar, prob = TRUE, breaks = "FD", main = title(heading,
> font.main = 6), col = "lightgray", xlab = expression(bar(x)))
> xbar <- sort(xbar)
> points(xbar, dnorm(xbar, mean = theta, sd = theta/sqrt(n[i])),
> type = "l", col = 2)
> }
> }
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help