Site icon R-bloggers

vistributions 0.2.2

[This article was first published on Rsquared Academy Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

vistributions 0.2.2

vistributions draws the probability and percentile questions you ask of the normal, t, chi-square, F and binomial distributions, with the answer printed on the plot.

Version 0.2.2 is a correctness release. What the plot shades and what its caption prints now agree with the exact probability, and inputs that cannot describe an event stop with a clear message. If you use the binomial functions to size an event, read the first section.

< section id="install-from-cran" class="level2">

Install from CRAN

< details open="" class="code-fold"> < summary>Code
install.packages("vistributions")

The full list of changes is in the release notes.

< section id="shading-follows-the-event" class="level2">

Shading follows the event

A trial cohort has 40 users, and about 25% of trial users usually upgrade. How likely is it that exactly 10 of them upgrade?

< details open="" class="code-fold"> < summary>Code
vdist_binom_prob(n = 40, p = 0.25, s = 10, type = "exact")

The exact value, from base R:

< details open="" class="code-fold"> < summary>Code
dbinom(10, size = 40, prob = 0.25)
[1] 0.1443643

The caption and the shaded bar match this value. The change matters most for large n, where bars are grouped. A grouped bar that crossed the cutoff was painted whole: for n = 10000, p = 0.01 and s = 100, the shaded area was 19.26% for an event whose exact probability is 4.01% (release notes). Every event cutoff is now a bar edge, so the shaded bar heights add up to dbinom() or pbinom() for the event.

< section id="inputs-that-cannot-be-an-event" class="level2">

Inputs that cannot be an event

A count of successes has to lie between 0 and the number of trials. Asking for a negative count used to be accepted, with the caption P(X) <= -1 = 0. It now gives the same clear error as a count above n:

< details open="" class="code-fold"> < summary>Code
tryCatch(
  vdist_binom_prob(n = 10, p = 0.3, s = -1, type = "lower"),
  error = function(e) conditionMessage(e)
)
[1] "s must be a whole number of successes between 0 and n (n = 10)."

The same release adds checks for the other families, for example whole-number arguments for the binomial and a documented range for percentile probabilities (1e-12 < probs < 1 - 1e-12).

< section id="percentiles-under-a-decimal-comma" class="level2">

Percentiles under a decimal comma

Delivery times are about 48 hours on average, with a standard deviation of 6 hours. By what time have 95% of orders arrived?

With options(OutDec = ","), which is common in European locales, every percentile and probability export used to fail with NAs introduced by coercion. The decimal mark is now fixed to . wherever numbers are printed and parsed back:

< details open="" class="code-fold"> < summary>Code
old <- options(OutDec = ",")
vdist_normal_perc(probs = 0.95, mean = 48, sd = 6, type = "lower")

< details open="" class="code-fold"> < summary>Code
options(old)
< details open="" class="code-fold"> < summary>Code
qnorm(0.95, mean = 48, sd = 6)
[1] 57.86912
< section id="other-improvements" class="level2">

Other improvements

The release notes carry the rest.

< section id="documentation" class="level2">

Documentation

Documentation and examples for every function are at vistributions.rsquaredacademy.com. Report problems at github.com/rsquaredacademy/vistributions/issues.

To leave a comment for the author, please follow the link and comment on their blog: Rsquared Academy Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Exit mobile version