File: overlaidQQPlot.R

package info (click to toggle)
r-cran-fit.models 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 364 kB
  • sloc: sh: 13; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' Overlaid Normal QQ Plot
#' 
#' Produces an overlaid normal QQ plot.
#' 
#' 
#' @param x a \code{fit.models} object.
#' @param fun a function to extract the desired quantity from \code{x}.
#' @param \dots additional arguments are passed to
#' \code{\link[lattice]{qqmath}}.
#' @return the \code{trellis} object is invisibly returned.
#' @keywords hplot


#' @importFrom lattice qqmath strip.default


#' @export
overlaidQQPlot <- function(x, fun, ...)
{
  n.models <- length(x)
  mod.names <- names(x)

  y <- lapply(x, fun)
  n.y <- sapply(y, length)
  mod <- factor(rep(mod.names, n.y), levels = mod.names)
  tdf <- data.frame(y = unlist(y), mod = mod)

  p <- qqmath(~ y | "",
              groups = mod,
              data = tdf,
              distribution = qnorm,
              strip = function(...) strip.default(..., style = 1),
              auto.key = list(corner = c(0.05, 0.95)),
              ...)

  print(p)
  invisible(p)
}