Yvonnick Noel
2013-Jun-21 14:55 UTC
[R] Superpose two QQ-plots (gamma distribution) with lattice function qqmath()
Hello,
I am trying to superpose on a single panel two QQ plots with the lattice
qqmath function.
Here is a reproducible example of the problem I am facing:
# Generate data
shape = 8
rate = c(rep(1/4,100),rep(1/3,100))
x = rgamma(200,shape,rate)
groups = gl(2,100,200,labels=LETTERS[1:2])
# Plot
qqmath(~x,groups=groups,panel = "panel.superpose",
distribution = function(x) qgamma(x,shape,rate),
panel.groups = function(x,subscripts,...) {
panel.qqmath(x,shape=shape,rate=rate[subscripts],...)
panel.qqmathline(x,shape=shape,rate=rate[subscripts],...)
})
Both data series seem to be reproduced twice, somewhat rescaled.
I don't understand what this mean.
What am I doing wrong?
Thanks a lot for your help,
Yvonnick Noel
University of Brittany, Rennes
Dpt. of Psychology
France
David Carlson
2013-Jun-21 15:39 UTC
[R] Superpose two QQ-plots (gamma distribution) with lattice function qqmath()
Your "rate" variable is not a single value, but a vector of 200!. I'm surprised you get anything at all. You have to pick one rate value to use to create the values for the x-axis. For example run> rate <- 1/4And then run the qqmath() function. Or, change the rate variable in the ggamma() function to qgamma(x,shape,1/4). ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Yvonnick Noel Sent: Friday, June 21, 2013 9:55 AM To: r-help at r-project.org Cc: Deepayan.Sarkar at r-project.org Subject: [R] Superpose two QQ-plots (gamma distribution) with lattice function qqmath() Hello, I am trying to superpose on a single panel two QQ plots with the lattice qqmath function. Here is a reproducible example of the problem I am facing: # Generate data shape = 8 rate = c(rep(1/4,100),rep(1/3,100)) x = rgamma(200,shape,rate) groups = gl(2,100,200,labels=LETTERS[1:2]) # Plot qqmath(~x,groups=groups,panel = "panel.superpose", distribution = function(x) qgamma(x,shape,rate), panel.groups = function(x,subscripts,...) { panel.qqmath(x,shape=shape,rate=rate[subscripts],...) panel.qqmathline(x,shape=shape,rate=rate[subscripts],...) }) Both data series seem to be reproduced twice, somewhat rescaled. I don't understand what this mean. What am I doing wrong? Thanks a lot for your help, Yvonnick Noel University of Brittany, Rennes Dpt. of Psychology France ______________________________________________ R-help at 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.
Duncan Mackay
2013-Jun-22 04:23 UTC
[R] Superpose two QQ-plots (gamma distribution) with lattice function qqmath()
Hi
Following on David's rate argument
try (with modifications of pch and grid)
rate <- 1/4
shape = 8
rate = c(rep(1/4,100),rep(1/3,100))
x = rgamma(200,shape,rate)
groups = gl(2,100,200,labels=LETTERS[1:2])
dat = data.frame(x=x, gp=groups)
qqmath(~ x, data = dat,
groups = gp,
pch = 20,
type = c("p","g"),
distribution = function(x) qgamma(x,shape,rate),
panel = function(x,groups,...) {
panel.qqmath(x,groups, ...)
})
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
At 00:55 22/06/2013, you wrote:>Hello,
>
>I am trying to superpose on a single panel two QQ plots with the
>lattice qqmath function.
>
>Here is a reproducible example of the problem I am facing:
>
># Generate data
>shape = 8
>rate = c(rep(1/4,100),rep(1/3,100))
>x = rgamma(200,shape,rate)
>groups = gl(2,100,200,labels=LETTERS[1:2])
>
># Plot
>qqmath(~x,groups=groups,panel = "panel.superpose",
>distribution = function(x) qgamma(x,shape,rate),
>panel.groups = function(x,subscripts,...) {
> panel.qqmath(x,shape=shape,rate=rate[subscripts],...)
> panel.qqmathline(x,shape=shape,rate=rate[subscripts],...)
>})
>
>Both data series seem to be reproduced twice, somewhat rescaled.
>
>I don't understand what this mean.
>
>What am I doing wrong?
>
>Thanks a lot for your help,
>
>Yvonnick Noel
>University of Brittany, Rennes
>Dpt. of Psychology
>France
>
>______________________________________________
>R-help at 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.
>