File: sim.qqnorm.R

package info (click to toggle)
r-cran-animation 2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,268 kB
  • sloc: javascript: 873; sh: 15; makefile: 2
file content (27 lines) | stat: -rw-r--r-- 1,088 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
#' Simulation of QQ plots for the Normal distribution
#'
#' This demo shows the possible QQ plots created by random numbers generated
#' from a Normal distribution so that users can get a rough idea about how QQ
#' plots really look like.
#'
#' When the sample size is small, it is hard to get a correct inference about
#' the distribution of data from a QQ plot. Even if the sample size is large,
#' usually there are outliers far away from the straight line. Therefore, don't
#' overinterpret the QQ plots.
#' @param n integer: sample size
#' @param last.plot an expression to be evaluated after the plot is drawn, e.g.
#'   \code{expression(abline(0, 1))} to add the diagonal line
#' @param ... other arguments passed to \code{\link{qqnorm}}
#' @return \code{NULL}
#' @author Yihui Xie
#' @references Examples at \url{https://yihui.org/animation/example/sim-qqnorm/}
#' @seealso \code{\link{qqnorm}}
#' @export
sim.qqnorm = function(n = 20, last.plot = NULL, ...) {
  for(i in 1:ani.options('nmax')) {
    dev.hold()
    qqnorm(rnorm(n), ...)
    eval(last.plot)
    ani.pause()
  }
}