Overlay cdf

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Overlay cdf

beetle2
Hi,
Is it possible to  overlay a cummulative distribution function on a histogram of a gamma distribuition.

I have a gamma function

Sample = rgamma(1000,2.5,.8)+1.5
hist(Sample)

regards

Reply | Threaded
Open this post in threaded view
|

Re: Overlay cdf

Bill.Venables
Here are some ideas you might like to consider

par(mar = c(5,4,2,4)+0.1, yaxs = "r")
Sample <- rgamma(1000,2.5,.8)
hist(Sample, main = "", freq = FALSE, ylim = c(0,1))

pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 5000)
y <- pgamma(x, 2.5, 0.8)
par(new = TRUE)
plot(x, y, type = "l", axes = FALSE, ann = FALSE, col = "red")
lines(x, dgamma(x, 2.5, 0.8), col = "darkgreen")

axis(4, col = "red")
mtext(side = 4, text = "Cumulative probability", col = "red", line = 2.5)

x0 <- c(0, sort(Sample))
p0 <- 0:1000/1000
lines(x0, p0, type = "S", col = "blue")


Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of beetle2
Sent: Wednesday, 13 May 2009 3:23 PM
To: [hidden email]
Subject: [R] Overlay cdf


Hi,
Is it possible to  overlay a cummulative distribution function on a
histogram of a gamma distribuition.

I have a gamma function

Sample = rgamma(1000,2.5,.8)+1.5
hist(Sample)

regards


--
View this message in context: http://www.nabble.com/Overlay-cdf-tp23515551p23515551.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: Overlay cdf

beetle2
Thanks alot I found the function

x0 <- c(0, sort(Sample))
p0 <- 0:1000/1000
lines(x0, p0, type = "S", col = "blue")


Very helpfull
As it seems to plot an instantaneous representation of the variables in the gamma distribution


Bill.Venables wrote
Here are some ideas you might like to consider

par(mar = c(5,4,2,4)+0.1, yaxs = "r")
Sample <- rgamma(1000,2.5,.8)
hist(Sample, main = "", freq = FALSE, ylim = c(0,1))

pu <- par("usr")[1:2]
x <- seq(pu[1], pu[2], len = 5000)
y <- pgamma(x, 2.5, 0.8)
par(new = TRUE)
plot(x, y, type = "l", axes = FALSE, ann = FALSE, col = "red")
lines(x, dgamma(x, 2.5, 0.8), col = "darkgreen")

axis(4, col = "red")
mtext(side = 4, text = "Cumulative probability", col = "red", line = 2.5)

x0 <- c(0, sort(Sample))
p0 <- 0:1000/1000
lines(x0, p0, type = "S", col = "blue")


Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-----Original Message-----
From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org] On Behalf Of beetle2
Sent: Wednesday, 13 May 2009 3:23 PM
To: r-help@r-project.org
Subject: [R] Overlay cdf


Hi,
Is it possible to  overlay a cummulative distribution function on a
histogram of a gamma distribuition.

I have a gamma function

Sample = rgamma(1000,2.5,.8)+1.5
hist(Sample)

regards


--
View this message in context: http://www.nabble.com/Overlay-cdf-tp23515551p23515551.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org 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.

______________________________________________
R-help@r-project.org 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: Overlay cdf

Matthieu Dubois-3
In reply to this post by Bill.Venables
You might also use ?curve

# same example as Bill's
par(mar = c(5,4,2,4)+0.1, yaxs = "r")
Sample <- rgamma(1000,2.5,.8)
hist(Sample, main = "", freq = FALSE, ylim = c(0,1))

curve(pgamma(x, 2.5, 0.8), add=T, col='red')
curve(dgamma(x, 2.5, 0.8), add=T, col='darkgreen')

axis(4, col = "red")
mtext(side = 4, text = "Cumulative probability", col = "red", line = 2.5)

x0 <- c(0, sort(Sample))
p0 <- 0:1000/1000
lines(x0, p0, type = "S", col = "blue")
 
Regards,

Matthieu

______________________________________________
[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.