Type: | Package |
Title: | Graph Probability Distributions with User Supplied Parameters and Statistics |
Version: | 4.5.0 |
Depends: | R (≥ 4.0.0) |
Description: | Graphs the pdf or pmf and highlights what area or probability is present in user defined locations. Visualize is able to provide lower tail, bounded, upper tail, and two tail calculations. Supports strict and equal to inequalities. Also provided on the graph is the mean and variance of the distribution. |
License: | MIT + file LICENSE |
URL: | https://github.com/coatless-rpkg/visualize, https://thecoatlessprofessor.com/projects/visualize/, https://r-pkg.thecoatlessprofessor.com/visualize/ |
BugReports: | https://github.com/coatless-rpkg/visualize/issues |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
NeedsCompilation: | no |
Packaged: | 2023-11-13 09:26:55 UTC; ronin |
Author: | James Balamuta |
Maintainer: | James Balamuta <james.balamuta@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-11-13 09:40:02 UTC |
visualize: Graph Probability Distributions with User Supplied Parameters and Statistics
Description
Graphs the pdf or pmf and highlights what area or probability is present in user defined locations. Visualize is able to provide lower tail, bounded, upper tail, and two tail calculations. Supports strict and equal to inequalities. Also provided on the graph is the mean and variance of the distribution.
Author(s)
Maintainer: James Balamuta james.balamuta@gmail.com (ORCID) [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/coatless-rpkg/visualize/issues
Examples
## visualize.it acts as the general wrapper.
## For guided application of visualize, see the visualize.distr_name list.
# Binomial distribution evaluated at lower tail.
visualize.it(dist = 'binom', stat = 2, params = list(size = 4,prob = .5),
section ="lower", strict = TRUE)
visualize.binom(stat = 2, size = 4, prob =.5, section ="lower", strict = TRUE)
# Set to shade inbetween a bounded region.
visualize.it(dist = 'norm', stat = c(-1, 1), list(mu = 0, sd = 1), section="bounded")
visualize.norm(stat = c(-1, 1), mu = 0, sd = 1, section ="bounded")
# Gamma distribution evaluated at upper tail.
visualize.it(dist = 'gamma', stat = 2, params = list(alpha = 2, theta = 1), section="upper")
visualize.gamma(stat = 2, alpha = 2, theta = 1, section="upper")
Visualize Beta Distribution
Description
Generates a plot of the Beta distribution with user specified parameters.
Usage
visualize.beta(stat = 1, alpha = 3, beta = 2, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
alpha |
|
beta |
|
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.beta(stat = 1, alpha = 2, beta = 3, section = "lower")
# Evaluates bounded region.
visualize.beta(stat = c(.5,1), alpha = 4, beta = 3, section = "bounded")
# Evaluates upper tail.
visualize.beta(stat = 1, alpha = 2, beta = 3, section = "upper")
Visualize Binomial Distribution
Description
Generates a plot of the Binomial distribution with user specified parameters.
Usage
visualize.binom(
stat = 1,
size = 3,
prob = 0.5,
section = "lower",
strict = FALSE
)
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
size |
size of sample. |
prob |
probability of picking object. |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail with equal to inequality.
visualize.binom(stat = 1, size = 3, prob = 0.5, section = "lower", strict = FALSE)
# Evaluates bounded region with lower bound equal to and upper bound strict inequality.
visualize.binom(stat = c(1,2), size = 5, prob = 0.35, section = "bounded", strict = c(0,1))
# Evaluates upper tail with strict inequality.
visualize.binom(stat = 1, size = 3, prob = 0.5, section = "upper", strict = TRUE)
Visualize Cauchy Distribution
Description
Generates a plot of the Cauchy distribution with user specified parameters.
Usage
visualize.cauchy(stat = 1, location = 2, scale = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
location |
location parameter |
scale |
scale parameter |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.cauchy(stat = 1, location = 4, scale = 2, section = "lower")
# Evaluates bounded region.
visualize.cauchy(stat = c(3,5), location = 5, scale = 3, section = "bounded")
# Evaluates upper tail.
visualize.cauchy(stat = 1, location = 4, scale = 2, section = "upper")
Visualize Chi-squared Distribution
Description
Generates a plot of the Chi-squared distribution with user specified parameters.
Usage
visualize.chisq(stat = 1, df = 3, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
df |
degrees of freedom of Chi-squared distribution. |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.chisq(stat = 1, df = 3, section = "lower")
# Evaluates bounded region.
visualize.chisq(stat = c(1,2), df = 6, section = "bounded")
# Evaluates upper tail.
visualize.chisq(stat = 1, df = 3, section = "upper")
Graphing function for Continuous Distributions.
Description
Handles how continuous distributions are graphed. Users should not use this
function. Instead, users should use visualize.it()
.
Usage
visualize.continuous(dist, stat = c(0, 1), params, section = "lower")
Arguments
dist |
contains a supported continuos distribution shortname. |
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as
|
params |
A list that must contain the necessary parameters for each
distribution. For example, |
section |
Select how you want the statistic(s) evaluated via
|
Author(s)
James Balamuta
See Also
visualize.it()
, visualize.beta()
, visualize.chisq()
, visualize.exp()
,
visualize.gamma()
, visualize.norm()
, visualize.unif()
, visualize.cauchy()
,
visualize.f()
, visualize.lnorm()
, visualize.t()
, visualize.wilcox()
,
visualize.logis()
.
Examples
# Function does not have dist look up, must go through visualize.it
visualize.it(dist='norm', stat = c(0,1), params = list(mu = 1, sd = 1), section = "bounded")
Graphing function for Discrete Distributions.
Description
Handles how discrete distributions are graphed. Users should not use this
function. Instead, users should use link{visualize.it}
.
Usage
visualize.discrete(dist, stat = c(0, 1), params, section = "lower", strict)
Arguments
dist |
contains the distribution from
|
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
params |
A list that must contain the necessary parameters for each
distribution. For example, |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
visualize.it()
, visualize.binom()
,
visualize.geom()
, visualize.hyper()
,
visualize.nbinom()
, visualize.pois()
.
Examples
# Function does not have dist look up, must go through visualize.it
visualize.it(dist='geom', stat = c(2,4), params = list(prob = .75), section = "bounded",
strict = c(0,1))
Visualize's Supported Distributions
Description
All of visualize's supported distributions with their density, probability, and quantile functions. In addition, mean and variance functions are present. Other descriptors also exist and are documented below.
Usage
visualize.distributions
Format
Distributions are loaded with the following format:
type: | specify either "continuous" or "discrete" |
to direct the query to the right graph handler. | |
name: | specify the name of the distribution. |
In example, "Poisson Distribution." | |
This is used in the main graph title. | |
variable: | specify the variable in probability statement. |
In example, P(z < 5). | |
This is used in the probability subtitle. | |
varsymbols: | specify the variable symbols for distribution. |
In example, mu = 1 sd = 2. | |
This is used in the distribution subtitle. | |
params: | specify the amount of params required for distribution. |
This is used in the first error handling check to ensure | |
the correct number of params is supplied. | |
init(params, ...): | Function that generates the mean and variance |
of a distribution. | |
density(x, params, ncp = 0, lower.tail = TRUE, log = FALSE, ...): | Function that provides the density value using vectors of the |
quantiles from the distribution. | |
This serves as a wrapper for ddistr_name. | |
probability(x, params, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...) | Function that provides the probability value |
using vectors of quantiles from the distribution. | |
This serves as a wrapper for pdistr_name. | |
quantile(x, params, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...) | Function that provides the quantile value |
using vectors of probabilities from the distribution. | |
This serves as a wrapper for qdistr_name. | |
The distributions currently available to use are:
Distribution | r Name | Distribution | r Name |
Beta | beta | Lognormal* | lnorm |
Binomial | binom | Negative Binomial | nbinom |
Cauchy* | cauchy | Normal | norm |
Chisquare | chisq | Poisson | pois |
Exponential | exp | Student t* | t |
F* | f | Uniform | unif |
Gamma | gamma | Geometric | geom |
Hypergeometric | hyper | Wilcoxon* | wilcox |
Logistic* | logis | ||
denotes the distribution was added in v2.0.
Author(s)
James Balamuta
Examples
visualize.distributions = list(
'beta' = list(
type = "continuous",
name = "Beta Distribution",
variable = "b",
varsymbols = c("\u03B1","\u03B2"),
params = 2,
init = function(params, ...) {
shape1 = params[[1]]; shape2 = params[[2]]
if(shape1 <= 0 || shape2 <= 0) stop("Error: Need alpha, beta > 0")
mean = shape1 / (shape1 + shape2)
var = (shape1 * shape2)/((shape1 + shape2 + 1)*(shape1 + shape2)^2)
c(mean, var)
},
density = function(x,params, ncp = 0, lower.tail = TRUE, log = FALSE, ...){
if(params[[1]] <= 0 || params[[2]] <= 0) stop("Error: Need alpha, beta > 0")
dbeta(x,params[[1]], params[[2]], ncp = ncp, log = log)
},
probability = function(q,params, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...){
if(params[[1]] <= 0 || params[[2]] <= 0) stop("Error: Need alpha, beta > 0")
pbeta(q,params[[1]], params[[2]], ncp = ncp, lower.tail = lower.tail, log.p = log.p)
},
quantile = function(p,params, ncp = 0, lower.tail = TRUE, log.p = FALSE, ...){
if(params[[1]] <= 0 || params[[2]] <= 0) stop("Error: Need alpha, beta > 0")
qbeta(p,params[[1]], params[[2]], ncp = ncp, lower.tail = lower.tail, log.p = log.p)
}
)
)
Visualize Exponential Distribution
Description
Generates a plot of the Exponential distribution with user specified parameters.
Usage
visualize.exp(stat = 1, theta = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
theta |
vector of rates |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.exp(stat = .5, theta = 3, section = "lower")
# Evaluates bounded region.
visualize.exp(stat = c(1,2), theta = 3, section = "bounded")
# Evaluates upper tail.
visualize.exp(stat = .5, theta = 3, section = "upper")
Visualize F distribution
Description
Generates a plot of the F distribution with user specified parameters.
Usage
visualize.f(stat = 1, df1 = 5, df2 = 4, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
df1 |
First Degrees of Freedom |
df2 |
Second Degrees of Freedom |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.f(stat = 1, df1 = 5, df2 = 4, section = "lower")
# Evaluates bounded region.
visualize.f(stat = c(3,5), df1 = 6, df2 = 3, section = "bounded")
# Evaluates upper tail.
visualize.f(stat = 1, df1 = 5, df2 = 4, section = "upper")
Visualize Gamma Distribution
Description
Generates a plot of the Gamma distribution with user specified parameters.
Usage
visualize.gamma(stat = 1, alpha = 1, theta = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
alpha |
|
theta |
|
section |
Select how you want the statistic(s) evaluated via
|
Author(s)
James Balamuta
See Also
Examples
# Evaluate lower tail.
visualize.gamma(stat = 1, alpha = 3, theta = 1, section = "lower")
# Evaluate bounded section.
visualize.gamma(stat = c(0.75,1), alpha = 3, theta = 1, section = "bounded")
# Evaluate upper tail.
visualize.gamma(stat = 1, alpha = 3, theta = 1, section = "upper")
Visualize Geometric Distribution
Description
Generates a plot of the Geometric distribution with user specified parameters.
Usage
visualize.geom(stat = 1, prob = 0.3, section = "lower", strict = FALSE)
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
prob |
probability of picking object. |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.geom(stat = 1, prob = 0.5, section = "lower", strict = FALSE)
# Evaluates bounded region.
visualize.geom(stat = c(1,3), prob = 0.35, section = "bounded", strict = c(0,1))
# Evaluates upper tail.
visualize.geom(stat = 1, prob = 0.5, section = "upper", strict = 1)
Visualize Hypergeometric Distribution
Description
Generates a plot of the Hypergeometric distribution with user specified parameters.
Usage
visualize.hyper(
stat = 1,
m = 5,
n = 4,
k = 2,
section = "lower",
strict = FALSE
)
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
m |
|
n |
|
k |
draw |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.hyper(stat = 1, m=4, n=5, k=3, section = "lower", strict = 0)
# Evaluates bounded region.
visualize.hyper(stat = c(2,4), m=14, n=5, k=2, section = "bounded", strict = c(0,1))
# Evaluates upper tail.
visualize.hyper(stat = 1, m=4, n=5, k=3, section = "upper", strict = 1)
Visualize's Processing Function
Description
Acts as a director of traffic and first line of error handling regarding submitted visualization requests. This function should only be used by advanced users.
Usage
visualize.it(
dist = "norm",
stat = c(0, 1),
params = list(mu = 0, sd = 1),
section = "lower",
strict = c(0, 1)
)
Arguments
dist |
a string that should be contain a supported probability
distributions name in R. Supported continuous distributions: |
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
params |
A list that must contain the necessary parameters for each
distribution. For example, |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
References
http://cran.r-project.org/web/views/Distributions.html
See Also
visualize.beta()
, visualize.chisq()
,
visualize.exp()
, visualize.gamma()
,
visualize.norm()
, visualize.unif()
,
visualize.binom()
, visualize.geom()
,
visualize.hyper()
, visualize.nbinom()
,
visualize.pois()
.
Examples
# Defaults to lower tail evaluation
visualize.it(dist = 'norm', stat = 1, list(mu = 3 , sd = 2), section = "lower")
# Set to evaluate the upper tail.
visualize.it(dist = 'norm', stat = 1, list(mu=3,sd=2),section="upper")
# Set to shade inbetween a bounded region.
visualize.it(dist = 'norm', stat = c(-1,1), list(mu=0,sd=1), section="bounded")
# Gamma distribution evaluated at upper tail.
visualize.it(dist = 'gamma', stat = 2, params = list(alpha=2,beta=1),section="upper")
# Binomial distribution evaluated at lower tail.
visualize.it('binom', stat = 2, params = list(n=4,p=.5))
Visualize Log Normal Distribution
Description
Generates a plot of the Log Normal distribution with user specified parameters.
Usage
visualize.lnorm(stat = 1, meanlog = 3, sdlog = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
meanlog |
Mean of the distribution |
sdlog |
Standard deviation of the distribution |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.lnorm(stat = 1, meanlog = 3, sdlog = 1, section = "lower")
# Evaluates bounded region.
visualize.lnorm(stat = c(3,5), meanlog = 3, sdlog = 3, section = "bounded")
# Evaluates upper tail.
visualize.lnorm(stat = 1, meanlog = 3, sdlog = 1, section = "upper")
Visualize Logistic distribution
Description
Generates a plot of the Logistic distribution with user specified parameters.
Usage
visualize.logis(stat = 1, location = 3, scale = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
location |
Location of the distribution. |
scale |
Scale of the distribution. |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.logis(stat = 1, location = 4, scale = 2, section = "lower")
# Evaluates bounded region.
visualize.logis(stat = c(3,5), location = 4, scale = 2, section = "bounded")
# Evaluates upper tail.
visualize.logis(stat = 1, location = 4, scale = 2, section = "upper")
Visualize Negative Binomial Distribution
Description
Generates a plot of the Negative Binomial distribution with user specified parameters.
Usage
visualize.nbinom(
stat = 1,
size = 6,
prob = 0.5,
section = "lower",
strict = FALSE
)
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
size |
number of objects. |
prob |
probability of picking object. |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.nbinom(stat = 1, size = 5, prob = 0.5, section = "lower", strict = 0)
# Evaluates bounded region.
visualize.nbinom(stat = c(1,3), size = 10, prob = 0.35, section = "bounded",
strict = c(TRUE, FALSE))
# Evaluates upper tail.
visualize.nbinom(stat = 1, size = 5, prob = 0.5, section = "upper", strict = 1)
Visualize Normal Distribution
Description
Generates a plot of the Normal distribution with user specified parameters.
Usage
visualize.norm(stat = 1, mu = 0, sd = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
mu |
mean of the Normal Distribution. |
sd |
standard deviation of the Normal Distribution. |
section |
Select how you want the statistic(s) evaluated via
|
See Also
Examples
# Evaluates lower tail.
visualize.norm(stat = 1, mu = 4, sd = 5, section = "lower")
# Evaluates bounded region.
visualize.norm(stat = c(3,6), mu = 5, sd = 3, section = "bounded")
# Evaluates upper tail.
visualize.norm(stat = 1, mu = 3, sd = 2, section = "upper")
Visualize Poisson Distribution
Description
Generates a plot of the Poisson distribution with user specified parameters.
Usage
visualize.pois(stat = 1, lambda = 3.5, section = "lower", strict = FALSE)
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
lambda |
lambda value of the Poisson Distribution. |
section |
Select how you want the statistic(s) evaluated via
|
strict |
Determines whether the probability will be generated as a
strict (<, >) or equal to (<=, >=) inequality. |
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.pois(stat = 1, lambda = 2, section = "lower", strict = FALSE)
# Evaluates bounded region.
visualize.pois(stat = c(1,3), lambda = 3, section = "bounded", strict = c(0,1))
# Evaluates upper tail.
visualize.pois(stat = 1, lambda = 2, section = "upper", strict = 1)
Visualize Student's t distribution
Description
Generates a plot of the Student's t distribution with user specified parameters.
Usage
visualize.t(stat = 1, df = 3, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
df |
Degrees of freedom |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.t(stat = 1, df = 4, section = "lower")
# Evaluates bounded region.
visualize.t(stat = c(3,5), df = 6, section = "bounded")
# Evaluates upper tail.
visualize.t(stat = 1, df = 4, section = "upper")
Visualize Uniform Distribution
Description
Generates a plot of the Uniform distribution with user specified parameters.
Usage
visualize.unif(stat = 1, a = 0, b = 1, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
a |
starting point. Note: |
b |
end point. Note: |
section |
Select how you want the statistic(s) evaluated via
|
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.unif(stat = 8.75, a = 7, b = 10, section = "lower")
# Evaluates bounded region.
visualize.unif(stat = c(3,6), a = 1, b = 7, section = "bounded")
# Evaluates upper tail.
visualize.unif(stat = 2, a = 1, b = 5, section = "upper")
Visualize Cauchy Distribution
Description
Generates a plot of the Wilcoxon Rank Sum distribution with user specified parameters.
Usage
visualize.wilcox(stat = 1, m = 7, n = 3, section = "lower")
Arguments
stat |
a statistic to obtain the probability from. When using the
"bounded" condition, you must supply the parameter as |
m |
Sample size from group 1. |
n |
Sample size from group 2. |
section |
Select how you want the statistic(s) evaluated via
|
Value
Returns a plot of the distribution according to the conditions supplied.
Author(s)
James Balamuta
See Also
Examples
# Evaluates lower tail.
visualize.wilcox(stat = 1, m = 7, n = 3, section = "lower")
# Evaluates bounded region.
visualize.wilcox(stat = c(2,3), m = 5, n = 4, section = "bounded")
# Evaluates upper tail.
visualize.wilcox(stat = 1, m = 7, n = 3, section = "upper")