R/qqPlotRmx.R

Defines functions qqPlot.rmx qqPlot

Documented in qqPlot qqPlot.rmx

qqPlot <- function(x, ...){
  UseMethod("qqPlot")
}
qqPlot.rmx <- function(x, param.digits = 3, ggplot.xlab = "Theoretical Quantiles", 
                      ggplot.ylab = "Sample Quantiles", ggplot.ggtitle = NULL,
                      point.col = "#0072B5", point.alpha = 1, ...){
  stopifnot(length(ggplot.xlab) == 1)
  stopifnot(length(ggplot.ylab) == 1)
  
  Dname <- x$rmxIF$model
  if(Dname %in% c("binom", "pois"))
    stop("'qqPlot' is only implemented for continous models.")
  param <- sapply(as.list(x$rmxIF$parameter), signif, digits = param.digits)

  if(is.null(ggplot.ggtitle)){
    Param <- paste(paste(names(param), param, sep = " = "), collapse = ", ")
    ggt <- ggtitle(paste0("qq-Plot for ", Dname, "(", Param, ")"))
  }else{
    stopifnot((length(ggplot.ggtitle) == 1))
    ggt <- ggtitle(ggplot.ggtitle)
  }
  
  DF <- data.frame(x = x$x)
  gg <- ggplot(DF, aes(sample = x)) + 
    stat_qq_band(dparams = param, distribution = Dname, identity = TRUE) + 
    stat_qq_point(dparams = param, distribution = Dname, 
                  color = point.col, alpha = point.alpha) + 
    stat_qq_line(dparams = param, distribution = Dname, identity = TRUE) + 
    xlab(ggplot.xlab) + ylab(ggplot.ylab) + ggt
  gg
}
stamats/rmx documentation built on Sept. 29, 2023, 7:13 p.m.