Skip to content

Commit 5cc7e8d

Browse files
Merge pull request #35 from rsquaredacademy/develop
Patch release for CRAN note
2 parents 9d065a2 + 57d9a23 commit 5cc7e8d

File tree

15 files changed

+389
-405
lines changed

15 files changed

+389
-405
lines changed

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Package: vistributions
22
Type: Package
33
Title: Visualize Probability Distributions
4-
Version: 0.1.1.9000
4+
Version: 0.1.2
55
Authors@R: person("Aravind", "Hebbali", email = "hebbali.aravind@gmail.com", role = c("aut", "cre"))
66
Description: Visualize and compute percentiles/probabilities of normal, t, f, chi square
77
and binomial distributions.
88
Depends:
9-
R(>= 3.1)
9+
R(>= 3.2)
1010
Imports:
1111
ggplot2,
1212
magrittr,
@@ -23,6 +23,5 @@ License: MIT + file LICENSE
2323
URL: https://github.com/rsquaredacademy/vistributions, https://vistributions.rsquaredacademy.com
2424
BugReports: https://github.com/rsquaredacademy/vistributions/issues
2525
Encoding: UTF-8
26-
LazyData: true
2726
RoxygenNote: 7.1.1
2827
VignetteBuilder: knitr

NAMESPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export(vdist_normal_prob)
1616
export(vdist_t_perc)
1717
export(vdist_t_plot)
1818
export(vdist_t_prob)
19-
importFrom(magrittr,"%>%")
20-
importFrom(utils,install.packages)
21-
importFrom(utils,menu)
22-
importFrom(utils,packageVersion)
19+
import(ggplot2)
20+
import(magrittr)
21+
import(stats)
22+
import(utils)

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# vistributions 0.1.2
2+
3+
This is a patch release to fix CRAN note about lazy data.
4+
15
# vistributions 0.1.1
26

37
This is a patch release to fix bugs in the app.

R/vdist-binomial.R

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ vdist_binom_plot <- function(n = 10, p = 0.3, print_plot = TRUE) {
4242
xn <- n / 40
4343
bm <- round(n * p, 2)
4444
bsd <- round(sqrt((1 - p) * bm) , 2)
45-
data <- stats::dbinom(x, n, p)
45+
data <- dbinom(x, n, p)
4646

4747
plot_data <- data.frame(n = seq(0, n), df = data)
4848

4949
pp <-
50-
ggplot2::ggplot(plot_data) +
51-
ggplot2::geom_col(ggplot2::aes(x = n, y = df), fill = "blue") +
52-
ggplot2::ylab("Probability") + ggplot2::xlab("No. of success") +
53-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
50+
ggplot(plot_data) +
51+
geom_col(aes(x = n, y = df), fill = "blue") +
52+
ylab("Probability") + xlab("No. of success") +
53+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
5454
subtitle = paste("Mean =", bm, ", Std. Dev. =", bsd)) +
55-
ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5),
56-
plot.subtitle = ggplot2::element_text(hjust = 0.5)) +
57-
ggplot2::scale_x_continuous(breaks = seq(0, n))
55+
theme(plot.title = element_text(hjust = 0.5),
56+
plot.subtitle = element_text(hjust = 0.5)) +
57+
scale_x_continuous(breaks = seq(0, n))
5858

5959
if (print_plot) {
6060
print(pp)
@@ -95,49 +95,49 @@ vdist_binom_prob <- function(n = 10, p = 0.3, s = 4,
9595
bsd <- round(sqrt((1 - p) * bm), 2)
9696

9797
if (method == "lower") {
98-
k <- round(stats::pbinom(s, n, p), 3)
99-
cols <- ifelse(cumsum(round(stats::dbinom(x, n, p), 3)) <= k, "#0000CD", "#6495ED")
98+
k <- round(pbinom(s, n, p), 3)
99+
cols <- ifelse(cumsum(round(dbinom(x, n, p), 3)) <= k, "#0000CD", "#6495ED")
100100
} else if (method == "upper") {
101-
k <- round(1 - stats::pbinom((s - 1), n, p), 3)
102-
cols <- ifelse(cumsum(round(stats::dbinom(x, n, p), 3)) >= k, "#0000CD", "#6495ED")
101+
k <- round(1 - pbinom((s - 1), n, p), 3)
102+
cols <- ifelse(cumsum(round(dbinom(x, n, p), 3)) >= k, "#0000CD", "#6495ED")
103103
} else if (method == "exact") {
104-
k <- stats::pbinom(s, n, p) - stats::pbinom((s - 1), n, p)
105-
cols <- ifelse(round(stats::dbinom(x, n, p), 5) == round(k, 5), "#0000CD", "#6495ED")
104+
k <- pbinom(s, n, p) - pbinom((s - 1), n, p)
105+
cols <- ifelse(round(dbinom(x, n, p), 5) == round(k, 5), "#0000CD", "#6495ED")
106106
} else {
107-
k1 <- stats::pbinom((s[1] - 1), n, p)
108-
k2 <- stats::pbinom(s[2], n, p)
109-
k <- stats::pbinom(s[2], n, p) - stats::pbinom((s[1] - 1), n, p)
110-
cols <- ifelse((round(cumsum(stats::dbinom(x, n, p)), 6) > round(k1, 6) &
111-
round(cumsum(stats::dbinom(x, n, p)), 6) <= round(k2, 6)), "#0000CD", "#6495ED")
107+
k1 <- pbinom((s[1] - 1), n, p)
108+
k2 <- pbinom(s[2], n, p)
109+
k <- pbinom(s[2], n, p) - pbinom((s[1] - 1), n, p)
110+
cols <- ifelse((round(cumsum(dbinom(x, n, p)), 6) > round(k1, 6) &
111+
round(cumsum(dbinom(x, n, p)), 6) <= round(k2, 6)), "#0000CD", "#6495ED")
112112
}
113113

114-
data <- stats::dbinom(x, n, p)
114+
data <- dbinom(x, n, p)
115115
plot_data <- data.frame(n = seq(0, n), df = data)
116116

117117
pp <-
118-
ggplot2::ggplot(plot_data) +
119-
ggplot2::geom_col(ggplot2::aes(x = n, y = df), fill = cols) +
120-
ggplot2::ylab("Probability") +
121-
ggplot2::xlab(paste("No. of success\n", "Mean =", bm, ", Std. Dev. =", bsd)) +
122-
ggplot2::scale_x_continuous(breaks = seq(0, n)) +
123-
ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5),
124-
plot.subtitle = ggplot2::element_text(hjust = 0.5))
118+
ggplot(plot_data) +
119+
geom_col(aes(x = n, y = df), fill = cols) +
120+
ylab("Probability") +
121+
xlab(paste("No. of success\n", "Mean =", bm, ", Std. Dev. =", bsd)) +
122+
scale_x_continuous(breaks = seq(0, n)) +
123+
theme(plot.title = element_text(hjust = 0.5),
124+
plot.subtitle = element_text(hjust = 0.5))
125125

126126
if (method == "lower") {
127127
pp +
128-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
128+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
129129
subtitle = paste("P(X) <=", s, "=", round(k, 3)))
130130
} else if (method == "upper") {
131131
pp +
132-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
132+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
133133
subtitle = paste("P(X) >=", s, "=", round(k, 3)))
134134
} else if (method == "exact") {
135135
pp +
136-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
136+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
137137
subtitle = paste("P(X) =", s, "=", round(k, 3)))
138138
} else {
139139
pp +
140-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
140+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
141141
subtitle = paste0("P(", s[1], " <= X <= ", s[2], ")", " = ", round(k, 3)))
142142
}
143143

@@ -166,33 +166,33 @@ vdist_binom_perc <- function(n = 10, p = 0.5, tp = 0.05, type = c("lower", "uppe
166166
x <- seq(0, n, 1)
167167

168168
if (method == "lower") {
169-
k <- round(stats::qbinom(tp, n, p), 3)
170-
cols <- ifelse(cumsum(stats::dbinom(x, n, p)) <= stats::pbinom(k, n, p), "#0000CD", "#6495ED")
169+
k <- round(qbinom(tp, n, p), 3)
170+
cols <- ifelse(cumsum(dbinom(x, n, p)) <= pbinom(k, n, p), "#0000CD", "#6495ED")
171171
} else {
172-
k <- round(stats::qbinom(tp, n, p, lower.tail = F), 3)
173-
cols <- ifelse(cumsum(stats::dbinom(x, n, p)) > stats::pbinom((k + 1), n, p), "#0000CD", "#6495ED")
172+
k <- round(qbinom(tp, n, p, lower.tail = F), 3)
173+
cols <- ifelse(cumsum(dbinom(x, n, p)) > pbinom((k + 1), n, p), "#0000CD", "#6495ED")
174174
}
175175

176-
data <- stats::dbinom(x, n, p)
176+
data <- dbinom(x, n, p)
177177
plot_data <- data.frame(n = seq(0, n), df = data)
178178

179179
pp <-
180-
ggplot2::ggplot(plot_data) +
181-
ggplot2::geom_col(ggplot2::aes(x = n, y = df), fill = cols) +
182-
ggplot2::ylab("Probability") + ggplot2::xlab("No. of success") +
183-
ggplot2::scale_x_continuous(breaks = seq(0, n)) +
184-
ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5),
185-
plot.subtitle = ggplot2::element_text(hjust = 0.5))
180+
ggplot(plot_data) +
181+
geom_col(aes(x = n, y = df), fill = cols) +
182+
ylab("Probability") + xlab("No. of success") +
183+
scale_x_continuous(breaks = seq(0, n)) +
184+
theme(plot.title = element_text(hjust = 0.5),
185+
plot.subtitle = element_text(hjust = 0.5))
186186

187187

188188
if (method == "lower") {
189189
pp +
190-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
190+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
191191
subtitle = paste0("P(X <= ", k, ") <= ", tp, ", but P(X <= ", (k + 1),
192192
") > ", tp))
193193
} else {
194194
pp +
195-
ggplot2::ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
195+
ggtitle(label = paste("Binomial Distribution: n =", n, ", p =", p),
196196
subtitle = paste0("P(X >= ", (k + 1), ") <= ", tp, ", but P(X >= ", k,
197197
") > ", tp))
198198
}

0 commit comments

Comments
 (0)