[R] Drawing a reference line for a qqplot with reference to Weibull distribution

Richard M. Heiberger rmh at temple.edu
Wed Oct 25 22:37:49 CEST 2006


The reference line needs to know the distribution.   The qqline
function has the normal built in.  You need to write something
similar.  qqline puts a line through the quartiles.  I extended
that to the t-distribution in the qqline.t function appended here.
You need to do something similar to get Weibull or any other distribution
recognized.

## qqline.t is based on qqline with an additional, optional argument.
## When df is not missing, the function draws a line through the
## quartiles of a t distribution.  When df is missing, qqline.t is
## identical to the original qqline and produces the line through the
## quartiles of the normal.

qqline.t <- function(x, df, ...) {
  data.quartiles <- quantile(x, c(0.25, 0.75), na.rm = T)
  norm.quartiles <-
    if (missing(df))
      qnorm(c(0.25, 0.75))
    else
      qt(c(0.25, 0.75), df=df)
  b <- (data.quartiles[2] - data.quartiles[1]) /
    (norm.quartiles[2] - norm.quartiles[1])
  a <- data.quartiles[1] - norm.quartiles[1] * b
  abline(a, b, ...)
  ans <- as.vector(c(a, b))
  names(ans) <- c("intercept", "slope")
  invisible(ans)
}



More information about the R-help mailing list