Description Usage Arguments Details Value Examples
View source: R/Plotting_functions.R
A function to create a quickdist
object with methods for the
plot
, lines
, and points
functions,
allowing for quick plotting of density, distribution, quantile,
and hazard functions over a variety of distributions.
1 2 3 4 5 6 7 8 9 10 11 12 |
dist |
a character string indicating the type of distribution to plot. |
type |
the type of function to compute over the set of plotting values, either the density ('PDF', 'pdf', 'density', 'Density', 'd'), distribution ('CDF', 'cdf', 'Distribution', 'distribution', 'df', 'DF'), quantile ('QF', 'qf', 'QPE', 'qpe', 'quantile', 'quantiles', 'Quantile', 'Quantiles', 'q'), or hazard function ('HF', 'hf', 'h', 'Hazard', 'hazard'). |
prm |
a vector of parameters. If null, default values are used. A named vector can be passed in to control the order in which parameter inputs are extracted. |
x |
an optional vector of response times or probabilities to plot over. |
b |
an optional vector giving the lower and upper limits as well as the number of increments used to generate a sequence of plotting values. |
Currently supported distributions include...
Exponentially modified Gaussian ('emg', 'EMG');
Shifted inverse Gaussian, or Wald ('sig', 'SIG', 'wald', 'Wald', 'ig', 'IG' );
Two-boundary Wiener process, or Wiener diffusion ('wp', 'WP', 'wd', 'WD', 'wiener', 'Wiener');
Gaussian, or Normal ('n', 'N', 'gauss', 'Gauss', 'normal', 'Normal', 'gaussian', 'Gaussian' );
Gamma ('ga', 'gamma', 'Gamma');
Weibull ('wei', 'weibull', 'Weibull');
Log-normal ('ln', 'LN', 'log-normal', 'Log-normal');
Beta ('b', 'B', 'beta', 'Beta');
Exponential ('exp', 'Exp', 'exponential', 'Exponential');
Once a quickdist
object has been created, a blank plot
can be generated via the plot
command. The figure can
then be updated via the lines
or points
functions,
making it easy to add multiple functions to a single figure.
An object of class 'quickdist', a list consisting of...
d_pv
- x and y-axis values for the density
function;
p_pv
- x and y-axis values for the distribution
function;
q_pv
- x and y-axis values for the quantile
function;
h_pv
- x and y-axis values for the hazard
function;
type
- a numeric code indicating the
type of function to plot.
prm
- a named vector with the parameter
values for the specified distribution.
dist
- A character string with the
abbreviated label for the specified distribution.
ch
- A numeric code indicating the
choice for the conditional distribution (for
two-choice models).
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 | # Plot density function for shifted inverse Gaussian
obj <- quickdist( 'SIG' )
plot( obj ); lines( obj )
# Add line for density function with new values
# for kappa, xi, and tau (threshold, drift, and
# shift)
obj_2 <- quickdist( 'SIG', prm = c( .5, 2, .3 ) )
lines( obj_2, col = 'red', lty = 2 )
# Plot distribution function for normal distribution
# over custom range and number of points used to
# approximate line
obj <- quickdist( 'Normal', type = 'CDF', b = c(-4,4,10) )
plot( obj ); lines( obj ); points( obj, pch = 19 )
# Plot predicted versus observed quantile functions
# Simulate data for create observed function
prb <- seq( .1, .9, .1 ) # 10% to 90% in 10% increments
# Simulate data from Beta( 5, 2 )
x <- rbeta( 1000, 5, 2 )
q_obs <- list( x = quantile( x, prob = prb ) )
q_obs$y <- prb
# Examine quantile functions for two different predictions
# Predicted under Beta(1,1)
prd_1 <- quickdist( 'b', type = 'QF', x = prb, prm = c( 1, 1 ) )
# Predicted under Beta(5,2)
prd_2 <- quickdist( 'Beta', type = 'QF', x = prb, prm = c( 5, 2 ) )
plot( prd_1 ); points( prd_1, col = 'blue', pch = 19 )
points( prd_2, col = 'red', pch = 15 )
# Observed
points( q_obs$x, q_obs$y, cex = 1.5 )
# Plot hazard function for exponential distribution
# (demonstrates memoryless property)
obj <- quickdist( 'Exponential', type = 'HF' )
plot( obj ); lines( obj )
# Contrast with gamma distribution
obj <- quickdist( 'Gamma', type = 'HF', prm = c( 1.1, 1) )
lines( obj, lty = 2 )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.