How to plot a normal distribution curve and a shaded tail with alpha?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to plot a normal distribution curve and a shaded tail with alpha?

Wu Gong
I want to create a graph to express the idea of the area under a pdf curve, like

pdf curve

Thank you for any help.
Reply | Threaded
Open this post in threaded view
|

Re: How to plot a normal distribution curve and a shaded tail with alpha?

David Winsemius

On Nov 8, 2010, at 11:18 AM, Wu Gong wrote:

>
> I want to create a graph to express the idea of the area under a pdf  
> curve,
> like
>
> http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg

I think you could have titled this request:
Yet Another Request to Do My Searching For Me:

http://search.r-project.org/cgi-bin/namazu.cgi?query=plot+normal+curve+with+shading&max=100&result=normal&sort=score&idxname=functions&idxname=Rhelp08&idxname=Rhelp10&idxname=Rhelp02

The R "search space" is littered with examples and that search string  
is not likely to uncover them all, but is rather  just one example.

--
David

>
> Thank you for any help.
>
> -----
> A R learner.
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to plot a normal distribution curve and a shaded tail with alpha?

Greg Snow-2
In reply to this post by Wu Gong
Look at power.examp in the TeachingDemos package.  If that plot is not good enough, you can steal the code and modify to your specifications.

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Wu Gong
> Sent: Monday, November 08, 2010 9:18 AM
> To: [hidden email]
> Subject: [R] How to plot a normal distribution curve and a shaded tail
> with alpha?
>
>
> I want to create a graph to express the idea of the area under a pdf
> curve,
> like
>
> http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
>
> Thank you for any help.
>
> -----
> A R learner.
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-
> plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-
> tp3032194p3032194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to plot a normal distribution curve and a shaded tail with alpha?

James Long
In reply to this post by Wu Gong
Here's an example of a PDF with the tails shaded:

http://stackoverflow.com/q/3494593/37751

-JD


On Mon, Nov 8, 2010 at 10:18 AM, Wu Gong <[hidden email]> wrote:

>
> I want to create a graph to express the idea of the area under a pdf curve,
> like
>
> http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
>
> Thank you for any help.
>
> -----
> A R learner.
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to plot a normal distribution curve and a shaded tail with alpha?

Joshua Wiley-2
In reply to this post by Wu Gong
I wrote this a bit ago, its far from perfect, but might give you
ideas/serve your purpose.

HTH,

Josh

plot.dist <- function(alpha, from = -5, to = 5, n = 1000, filename = NULL,
alternative = c("two.tailed", "greater", "lesser"),
distribution = c("normal", "t", "F", "chisq", "binomial"),
colour = "black", fill = "skyblue2", ...) {
alternative <- match.arg(alternative)
## Calculate alpha level given hypothesis
alt.alpha <- switch(alternative,
two.tailed = alpha/2,
greater = alpha,
lesser = alpha)
## use a ’switch’ to pick the right functions based on distribution
my.den <- switch(distribution,
normal = dnorm,
t = dt,
F = df,
chisq = dchisq,
binomial = dbinom)
my.dist <- switch(distribution,
normal = qnorm,
t = qt,
F = qf,
chisq = qchisq,
binomial = qbinom)
## Additional arguments passed via ’...’ e.g., degrees of freedom
crit.lower <- my.dist(p = alt.alpha, lower.tail = TRUE, ...)
crit.upper <- my.dist(p = alt.alpha, lower.tail = FALSE, ...)
## Calculate alpha (lower) region coordinates
cord.x1 <- c(from, seq(from = from, to = crit.lower,
length.out = 100), crit.lower)
cord.y1 <- c(0, my.den(x = seq(from = from, to = crit.lower,
length.out = 100), ...), 0)
## Calculate alpha (upper) region coordinates
cord.x2 <- c(crit.upper, seq(from = crit.upper, to = to,
length.out = 100), to)
cord.y2 <- c(0, my.den(x = seq(from = crit.upper, to = to,
length.out = 100), ...), 0)
## Logic test to choose which graphic device to open
if(is.null(filename)) {
dev.new()
} else {
pdf(file = filename)
}
## plot distribution
curve(my.den(x, ...), from = from, to = to,
n = n, col = colour, lty = 1, lwd = 2,
ylab = "Density", xlab = "Values")
## Add alpha region(s) based on given hypothesis
if(!identical(alternative, "greater")) {
polygon(x = cord.x1, y = cord.y1, col = fill)
}
if(!identical(alternative, "lesser")) {
polygon(x = cord.x2, y = cord.y2, col = fill)
}
## If the PDF device was started, shut it down
if(!is.null(filename)) {dev.off()}
}


On Mon, Nov 8, 2010 at 8:18 AM, Wu Gong <[hidden email]> wrote:

>
> I want to create a graph to express the idea of the area under a pdf curve,
> like
>
> http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
>
> Thank you for any help.
>
> -----
> A R learner.
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to plot a normal distribution curve and a shaded tail with alpha?

Richard M. Heiberger
In reply to this post by Wu Gong
You can use the
normal.and.t.dist()
function in the HH package, available from CRAN with
install.packages("HH")
This works on all platforms.  There is menu access to the function through
Rcmdr if you install
install.packages("RcmdrPlugin.HH")

If you are on Windows, you can additionally control that function
interactively
from an Excel spreadsheet with the RExcel package.
Install with the
RthroughExcelWorkbooksInstaller package from CRAN.

Rich

On Mon, Nov 8, 2010 at 11:18 AM, Wu Gong <[hidden email]> wrote:

>
> I want to create a graph to express the idea of the area under a pdf curve,
> like
>
> http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
>
> Thank you for any help.
>
> -----
> A R learner.
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.