quickdist: Create a 'quickdist' Object for Quick Plotting

Description Usage Arguments Details Value Examples

View source: R/Plotting_functions.R

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
quickdist(dist, type = "PDF", prm = NULL, x = NULL, b = NULL)

## S3 method for class 'quickdist'
plot(x, weight = NULL, ...)

## S3 method for class 'quickdist'
lines(object, ch = 1, weight = NULL, ...)

## S3 method for class 'quickdist'
points(object, ch = 1, weight = NULL, ...)

is.quickdist(x)

Arguments

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.

Details

Currently supported distributions include...

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.

Value

An object of class 'quickdist', a list consisting of...

Examples

 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 )

rettopnivek/seqmodels documentation built on May 1, 2020, 2:59 p.m.