Description Usage Arguments Details Value Author(s) See Also Examples
qqmathFitted
is a modified version of qqmath
that
draws a quantile-quantile plot of sample data against a
fitted reference distribution. The fitting is done during
the panel construction using a user-provided function to
estimate distributional parameters.
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 | qqmathFitted(formula,
data = NULL,
allow.multiple = is.null(groups) || outer,
outer = !is.null(groups),
distribution = qnorm,
f.value = NULL,
auto.key = FALSE,
aspect = "fill",
panel = panel.qqmath.fitted,
prepanel = prepanel.qqmath.fitted,
scales = list(),
strip = TRUE,
groups = NULL,
xlab,
xlim,
ylab,
ylim,
drop.unused.levels = lattice.getOption("drop.unused.levels"),
distribution.fit = function(y) list(mean = 0, sd = 1),
quantile.type = 7,
qqstyle = NULL,
add.qqline = c("none", "lm", "lmRob"),
add.qqline.par = if (!is.null(groups))
trellis.par.get("panel.superpose") else
trellis.par.get("add.line"),
envelope = TRUE,
rdist = rnorm,
rdist.args = NULL,
sig.level = 0.95,
mc.samples = 100,
seed = .Random.seed,
envstyle = NULL,
id.n = 3,
labelargs = FALSE,
verbose = FALSE,
...,
lattice.options = NULL,
default.scales = list(),
subscripts = !is.null(groups),
subset = TRUE)
|
|
Most of these arguments work just like they do for
|
formula |
A lattice formula of the form
|
data |
A data source ( e.g., a data frame ) in
which to find the variables referenced in
|
allow.multiple |
See |
outer |
See |
distribution |
function to compute quantiles from the reference
distribution. Can be a named function (e.g., |
f.value |
Vector of probabilities at which
to compute quantiles. By default, |
auto.key |
See |
aspect |
See |
panel |
A function that will be called once for each
panel of the plot to do the actual plotting. See
|
prepanel |
Prepanel functions set sensible x- and y-limits
for panels; see |
scales |
See |
strip |
See |
groups |
See |
xlab |
See |
xlim |
See |
ylab |
See |
ylim |
See |
drop.unused.levels |
See |
distribution.fit |
function to fit the parameters of the reference
distribution (defined in The function should return a list of parameters to |
quantile.type |
Numeric value, passed to |
qqstyle |
List of graphical parameters to use for plotting the observed and reference quantiles. |
add.qqline |
Controls whether a fitted line should be added
to the plot. The default option, |
add.qqline.par |
Optional list of parameters controlling the appearance of the fitted line. |
envelope |
If TRUE, plot a confidence region for the Q-Q plot via simulation. Envelopes are not supported when groups are used, as the resulting plot would be quite cluttered. |
rdist |
The distribution from which to draw random numbers
for the confidence region simulation. It should correspond to
the distribution assumed in |
rdist.args |
A list containing additional arguments to the
function specified in |
sig.level |
Significance level to use for the confidence region. Default is a 95% condifence interval. |
mc.samples |
Number of random samples to use to construct the confidence region. |
seed |
Seed to use for the random number generator. If specified,
|
envstyle |
List of graphical parameters to use for plotting the confidence region boundaries. |
id.n |
Number of outliers to label in each panel. Default is 3.
Use |
labelargs |
Controls whether the fitted distributional parameters
are added to each panel. Can be a logical value or a character value.
If FALSE, no labels are added. If TRUE, labels are taken from the
names of
|
verbose |
If TRUE, additional debugging information will be printed. |
... |
Further arguments, often graphical parameters,
passed to internal plotting functions and eventually on
to |
lattice.options |
See |
default.scales |
See |
subscripts |
See |
subset |
See |
qqmathFitted
is a modified version of qqmath
from Deepayan Sarkar's lattice
package. It adds the ability to
fit the reference distribution to the data during the plotting procedure,
as well as the ability to simulation envelopes. The latter ability is
based on code appearing in the function lmfmResQQPlot
from the
robust
package maintained by Kjell Konis.
prepanel.qqmath.fitted
does the actual distributional fitting for
qqmathFitted
.
An object of class "trellis"
.
Christopher G. Green christopher.g.green@gmail.com for
qqmathFitted
. qqmathFitted
is a modified
version of qqmath
from the lattice
package, written by Deepayan
Sarkar. The plotting code for simulation envelopes is based on code appearing
in the lmfmResQQPlot
function from the robust
package
written by Kjell Konis et al.
prepanel.qqmath.fitted
, panel.qqmath.fitted
,
qqmath
, panel.qqmath
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | # normal distribution example
n.trials <- 4
n.sample <- 250
# generate sample data
normal.sample.data <- as.data.frame(
list(
ret=rnorm(n.trials*n.sample,
mean=rep(seq(-5,5,length=n.trials),each=n.sample),
sd=rep(seq(0.1,10,length=n.trials),each=n.sample)),
trial=rep(paste("TRIAL",
c(paste("0",1:9,sep=""),
as.character(10:n.trials))),each=n.sample),
case=rep(c("CASE A","CASE B"),
each=n.trials*n.sample %/% 2)
)
)
# normal q-q plot
qqmathFitted( ~ret,
data=normal.sample.data,
subset=1:n.sample,
panel = panel.qqmath.fitted,
main = "Normally-distributed trial data",
ylab = "Quantiles of sample data",
xlab = "Quantiles of fitted normal distribution",
aspect = 1,
as.table=TRUE,
layout=c(1,1),
distribution=qnorm,
distribution.fit=function(y)
list(mean=as.vector(median(y)), sd=mad(y)),
rdist=rnorm,
qqstyle=list(pch="+",col=2),
envstyle=list(pch="o",col=3)
)
# normal q-q plot, one panel per trial
qqmathFitted( ~ret|trial,
data=normal.sample.data,
panel = panel.qqmath.fitted,
main = "Normally-distributed trial data",
ylab = "Quantiles of sample data",
xlab = "Quantiles of fitted normal distribution",
aspect = 1,
as.table=TRUE,
layout=c(2,2),
distribution=qnorm,
distribution.fit=function(y)
list(mean=median(y), sd=mad(y)),
rdist=rnorm,
scales = list(relation="free"),
qqstyle=list(pch="+",col=2),
envstyle=list(pch="o",col=3)
)
# normal q-q plot showing subsetting
qqmathFitted( ~ret,
data=normal.sample.data,
groups = trial,
subset = (trial %in% c("TRIAL 01","TRIAL 05")),
panel = panel.qqmath.fitted,
main = "Normally-distributed trial data",
ylab = "Quantiles of sample data",
xlab = "Quantiles of fitted normal distribution",
aspect = 1,
as.table=TRUE,
layout=c(1,1),
distribution=qnorm,
distribution.fit=function(y)
list(mean=median(y), sd=mad(y)),
envelope=FALSE,
add.qqline="lm",
add.qqline.par=list(lty=c(2,rep(NA,3),3),
col=c("green",rep("",3),"black"))
)
# student t example
# generate sample data
symt.sample.data <- as.data.frame(
list(
ret=rep(seq(-5,5,length=n.trials),each=n.sample) +
1.2*rt(n.trials*n.sample, df=4),
trial=rep(paste("TRIAL",
c(paste("0",1:9,sep=""),
as.character(10:n.trials))),each=n.sample)
)
)
# symmetric t q-q plot
qqmathFitted( ~ret,
data=symt.sample.data,
subset=1:n.sample,
panel = panel.qqmath.fitted,
main = "Symmetric t-distributed trial data",
ylab = "Quantiles of sample data",
xlab = "Quantiles of fitted symmetric t distribution",
aspect = 1,
as.table=TRUE,
layout=c(1,1),
distribution=function(p,df,mu,sigma)
mu + sigma*qt(p,df),
distribution.fit=function(y) fit.mle.t(y),
rdist=function(n,df,mu,sigma)
mu + sigma*rt(n,df),
qqstyle=list(pch="o",col=2),
envstyle=list(pch="+",col=3),
labelargs=c("df"),
verbose = TRUE
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.