Learn R Programming

QQreflimits (version 1.0.3)

QQnorm: QQ Plot with Correlation

Description

Creates QQ plot of complete or censored data, with summaries and test.

Usage

QQnorm(X, main="", ylab="", censor=0, winsor=0,
       joinem=FALSE, ylim=c(NA,NA), isBC=FALSE, is2pBC=FALSE,
       doplot=TRUE, showP=TRUE, fitline=TRUE, showsum=FALSE)

Value

A list containing the following components:

correl

the QQ correlation coefficient.

Pval

the P value of the QQ correlation coefficient.

mean

the mean of the data.

sd

the sd of the data.

intercept

the intercept of the QQ regression line, used in place of the mean when there is censoring or winsorization.

slope

the slope of the QQ regression line, used in place of the sd when there is censorin or winsorization.

Arguments

X

the numeric data vector to be plotted. Censored values should be reported as the censoring value.

main

the header text.

ylab

the name of the variable.

censor

optional (default of 0) - the number of data censored on the left.

winsor

optional (default of 0) - the number of data winsored in each tail.

joinem

optional (default of FALSE) - if TRUE the plot is drawn as a segmented line, if FALSE the individual points are plotted as x if winsorized, else *.

ylim

optional - y limits on the plot.

isBC

optional (default of FALSE) - if true, the data set is a Box-Cox transform of the original data.

is2pBC

optional (default of FALSE) - if true, the data set is a shifted Box-Cox tranform.

doplot

optional (default of TRUE) - if true, the QQ plot is drawn.

showP

optional (default of TRUE) - if true, the QQCC P value is shown on the plot.

fitline

optional (default of TRUE) - if true, the QQ regression line is plotted.

showsum

optional (default of FALSE) - if true, the intercept and slope of the QQ regression are shown.

Author

Douglas M. Hawkins, Jessica J. Kraker krakerjj@uwec.edu

Details

Makes QQ plot of complete or censored data, as input by user:

  • fits regression line to complete uncensored portion of data,

  • calculates the QQ correlation coefficient of the fitted line, and

  • reports the P value of the QQ correlation coefficient as calculated by BCR_pval. Parameters isBC and is2pBC are relevant to the P value calculation.

References

Hawkins DM, Esquivel RN (2024). A Quantile-Quantile Toolbox for Reference Intervals. The Journal of Applied Laboratory Medicine, 9:2, 357-370.

Examples

Run this code
# parameters
mu    <- 40
sigma <- 10
n     <- 120
# identifying winsoring
wins  <- trunc(n/40)
# replicable randomization
set.seed(1069)
X     <- mu + sigma*rnorm(n)
# replicable randomization with heavy tails
set.seed(1069)
HT    <- mu + sigma * rt(n, 5)

# retain original visual settings
oldsettings <- par(mfrow=par()$mfrow, oma=par()$oma)
# visual settings
par(mfrow=c(2,2))
par(oma=c(0,0,2,0))
# plot to compare
base <- QQnorm(X, main="Base normal", showsum=TRUE)
title("Illustrating QQnorm with para_limits", outer=TRUE)
basew <- QQnorm(X, main="Winsorized", winsor=wins, showsum=TRUE)
ht   <- QQnorm(HT, main="Heavy tail", showsum=TRUE)
htw  <- QQnorm(HT, main="Winsorized", winsor=wins, showsum=TRUE)
# restore
par(oldsettings)

Run the code above in your browser using DataLab