Skip to content

Commit bb0b8b6

Browse files
committed
Renamed functions, added examples.
1 parent 5d65e18 commit bb0b8b6

37 files changed

+503
-242
lines changed

NAMESPACE

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(addexp)
4-
export(addlnorm)
5-
export(addnorm)
6-
export(addt)
7-
export(addtnorm)
8-
export(binomnorm)
9-
export(binompower)
10-
export(binomprob)
11-
export(binomtest)
12-
export(boxplot)
13-
export(chisqrprob)
14-
export(dotplot)
15-
export(hypernorm)
16-
export(hyperprob)
17-
export(invbinom)
18-
export(invnorm)
19-
export(invt)
20-
export(normpower)
21-
export(normprob)
22-
export(onesamplet)
23-
export(summary)
24-
export(tprob)
25-
export(twosamplet)
3+
export(iscamaddexp)
4+
export(iscamaddlnorm)
5+
export(iscamaddnorm)
6+
export(iscamaddt)
7+
export(iscamaddtnorm)
8+
export(iscambinomnorm)
9+
export(iscambinompower)
10+
export(iscambinomprob)
11+
export(iscambinomtest)
12+
export(iscamboxplot)
13+
export(iscamchisqrprob)
14+
export(iscamdotplot)
15+
export(iscamhypernorm)
16+
export(iscamhyperprob)
17+
export(iscaminvbinom)
18+
export(iscaminvnorm)
19+
export(iscaminvt)
20+
export(iscamnormpower)
21+
export(iscamnormprob)
22+
export(iscamonesamplet)
23+
export(iscamsummary)
24+
export(iscamtprob)
25+
export(iscamtwosamplet)
2626
importFrom(graphics,abline)
2727
importFrom(graphics,axis)
2828
importFrom(graphics,bxp)

R/binomial.R

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#' @export
1313
#'
1414
#' @examples
15-
#' binomnorm(10, 20, 0.5, "two.sided")
16-
binomnorm <- function(k, n, prob, direction) {
15+
#' iscambinomnorm(k = 10, n = 20, prob = 0.5, direction = "two.sided")
16+
iscambinomnorm <- function(k, n, prob, direction) {
1717
withr::local_par(mar = c(5, 3, 1, 1))
1818

1919
thisx <- 0:n
@@ -221,7 +221,14 @@ binomnorm <- function(k, n, prob, direction) {
221221
#' @export
222222
#'
223223
#' @examples
224-
binompower <- function(LOS, n, prob1, alternative, prob2 = NULL) {
224+
#' iscambinompower(LOS = 0.05, n = 20, prob1 = 0.5, alternative = "less")
225+
#'
226+
#' iscambinompower(LOS = 0.05, n = 20, prob1 = 0.5, alternative = "greater", prob2 = 0.75)
227+
#'
228+
#' iscambinompower(LOS = 0.10, n = 30, prob1 = 0.4, alternative = "two.sided")
229+
#'
230+
#' iscambinompower(LOS = 0.10, n = 30, prob1 = 0.4, alternative = "two.sided", prob2 = 0.2)
231+
iscambinompower <- function(LOS, n, prob1, alternative, prob2 = NULL) {
225232
thisx <- 0:n
226233
minx <- max(
227234
0,
@@ -423,14 +430,14 @@ binompower <- function(LOS, n, prob1, alternative, prob2 = NULL) {
423430
#' @export
424431
#'
425432
#' @examples
426-
binomprob <- function(k, n, prob, lower.tail) {
427-
Description <- "iscambinomprob(k, n, prob, lower.tail) \n This function calculates tail probabilities from the binomial distribution.\r
428-
k is the number of successes of interest (must be integer), n and prob are the number of trials and success probability \n lower.tail is a Boolean for finding the probability above (FALSE) or below (TRUE) the inputted value (inclusive)"
429-
# TODO Stop if probability is wrong
430-
431-
if (as.character(k) == "?") {
432-
stop(Description)
433+
#' iscambinomprob(k = 5, n = 20, prob = 0.4, lower.tail = TRUE)
434+
#' iscambinomprob(k = 15, n = 30, prob = 0.3, lower.tail = FALSE)
435+
#' iscambinomprob(k = 22, n = 25, prob = 0.9, lower.tail = TRUE)
436+
iscambinomprob <- function(k, n, prob, lower.tail) {
437+
if (prob < 0 || prob > 1) {
438+
stop("Error: `prob` (probability) must be a numeric value between 0 and 1.")
433439
}
440+
434441
withr::local_par(mar = c(4, 3, 2, 2))
435442
thisx <- 0:n
436443
minx <- max(0, n * prob - 4 * sqrt(prob * (1 - prob) * n))
@@ -499,24 +506,43 @@ k is the number of successes of interest (must be integer), n and prob are the n
499506
#' @param alternative "less", "greater", or "two.sided"
500507
#' @param conf.level Confidence level for a two-sided confidence interval.
501508
#'
502-
#' @return P-value along with a plot of the binomial distribution and/or
503-
#' binomial confidence interval.
509+
#' @return a list of the p-value along with lower and upper bound for the calculated confidence interval.
504510
#' @export
505511
#'
506512
#' @examples
507-
binomtest <- function(
513+
#'
514+
#' iscambinomtest(
515+
#' observed = 17,
516+
#' n = 25,
517+
#' hypothesized = 0.5,
518+
#' alternative = "greater"
519+
#' )
520+
#'
521+
#' iscambinomtest(
522+
#' observed = 12,
523+
#' n = 80,
524+
#' hypothesized = 0.10,
525+
#' alternative = "two.sided",
526+
#' conf.level = 0.95
527+
#' )
528+
#'
529+
#' iscambinomtest(
530+
#' observed = 0.14,
531+
#' n = 100,
532+
#' hypothesized = 0.20,
533+
#' alternative = "less"
534+
#' )
535+
#'
536+
#' iscambinomtest(observed = 17, n = 25, conf.level = 0.95)
537+
#'
538+
#' iscambinomtest(observed = 12, n = 80, conf.level = c(0.90, 0.95, 0.99))
539+
iscambinomtest <- function(
508540
observed,
509541
n,
510542
hypothesized = NULL,
511543
alternative,
512544
conf.level = NULL
513545
) {
514-
# TODO Better documentation that takes into account all parts of description
515-
Description <- "iscambinomtest(observed, n, hypothesized=NULL, alternative, conf.level=NULL) \n This function performs an exact binomial test and graphs the binomial distribution and/or binomial confidence interval.\n Input the observed number of successes or sample proportion (assumed if value less than one),\n Input n = the sample size and the hypothesized probability of success \n Optional: Input the hypothesized probability of success and form of alternative (\"less\", \"greater\", or \"two.sided\") \n Optional: Input a confidence level (one or more values) for a two-sided confidence interval.\n "
516-
517-
if (as.character(observed) == "?") {
518-
stop(Description)
519-
}
520546
withr::local_par(mar = c(4, 3, 2, 2))
521547

522548
if (observed < 1) {
@@ -759,12 +785,12 @@ binomtest <- function(
759785
#' @export
760786
#'
761787
#' @examples
762-
invbinom <- function(alpha, n, prob, lower.tail) {
763-
Description <- "iscaminvbinom(alpha, n, prob, lower.tail) \n This function calculates the binomial quantile of a specified probability. \n Input the desired probability and the parameters of the binomial distribution. \n Specify whether you want this is an upper tail (FALSE) or lower tail (TRUE) \n The integer that achieves at most the stated probability will be returned."
764-
765-
if (as.character(alpha) == "?") {
766-
stop(Description)
767-
}
788+
#' iscaminvbinom(alpha = 0.05, n = 30, prob = 0.5, lower.tail = TRUE)
789+
#'
790+
#' iscaminvbinom(alpha = 0.05, n = 30, prob = 0.5, lower.tail = FALSE)
791+
#'
792+
#' iscaminvbinom(alpha = 0.01, n = 60, prob = 0.10, lower.tail = FALSE)
793+
iscaminvbinom <- function(alpha, n, prob, lower.tail) {
768794
withr::local_par(mar = c(4, 3, 2, 2))
769795

770796
thisx <- 0:n

R/chisqrprob.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#' @export
1414
#'
1515
#' @examples
16-
#' chisqrprob(5, 3)
17-
chisqrprob <- function(x_val, df) {
16+
#' iscamchisqrprob(5, 3)
17+
iscamchisqrprob <- function(x_val, df) {
1818
withr::local_par(mar = c(4, 4, 2, 1))
1919

2020
minx <- 0

R/hypergeometric.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#' @export
1414
#'
1515
#' @examples
16-
#' hypernorm(1, 20, 5, 10, TRUE)
17-
hypernorm <- function(k, total, succ, n, lower.tail) {
16+
#' iscamhypernorm(1, 20, 5, 10, TRUE)
17+
iscamhypernorm <- function(k, total, succ, n, lower.tail) {
1818
# TODO rewrite so that it uses hyperprob and overlay normal?
1919
withr::local_par(mar = c(4, 4, 2, 1))
2020

@@ -150,8 +150,8 @@ hypernorm <- function(k, total, succ, n, lower.tail) {
150150
#' @export
151151
#'
152152
#' @examples
153-
#' hyperprob(1, 20, 5, 10, TRUE)
154-
hyperprob <- function(k, total, succ, n, lower.tail) {
153+
#' iscamhyperprob(1, 20, 5, 10, TRUE)
154+
iscamhyperprob <- function(k, total, succ, n, lower.tail) {
155155
withr::local_par(mar = c(4, 4, 2, 1))
156156

157157
if (k < 1 & k > 0) {

R/normal.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
#' @export
2121
#'
2222
#' @examples
23-
normprob <- function(
23+
#' iscamnormprob(1.96, direction = "above")
24+
#' iscamnormprob(-1.5, mean = 1, sd = 2, direction = "below")
25+
#' iscamnormprob(0, xval2 = 1.5, direction = "between")
26+
#' iscamnormprob(-1, xval2 = 1, direction = "outside")
27+
iscamnormprob <- function(
2428
xval,
2529
mean = 0,
2630
sd = 1,
@@ -190,7 +194,11 @@ normprob <- function(
190194
#' @export
191195
#'
192196
#' @examples
193-
invnorm <- function(prob1, mean = 0, sd = 1, direction) {
197+
#' iscaminvnorm(0.05, direction = "below")
198+
#' iscaminvnorm(0.90, mean = 100, sd = 15, direction = "above")
199+
#' iscaminvnorm(0.10, direction = "outside")
200+
#' iscaminvnorm(0.95, direction = "between")
201+
iscaminvnorm <- function(prob1, mean = 0, sd = 1, direction) {
194202
withr::local_par(mar = c(4, 3, 2, 2))
195203
min <- mean - 4 * sd
196204
max <- mean + 4 * sd
@@ -346,7 +354,10 @@ invnorm <- function(prob1, mean = 0, sd = 1, direction) {
346354
#' @export
347355
#'
348356
#' @examples
349-
normpower <- function(LOS, n, prob1, alternative, prob2) {
357+
#' iscamnormpower(0.05, n = 100, prob1 = 0.5, alternative = "greater", prob2 = 0.6)
358+
#' iscamnormpower(0.10, n = 50, prob1 = 0.25, alternative = "less", prob2 = 0.15)
359+
#' iscamnormpower(0.05, n = 200, prob1 = 0.8, alternative = "two.sided", prob2 = 0.7)
360+
iscamnormpower <- function(LOS, n, prob1, alternative, prob2) {
350361
withr::local_par(mar = c(5, 4, 1, 1), mfrow = c(2, 1))
351362

352363
minx <- max(

R/overlayDensities.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ NULL
2222
#' @examples
2323
#' set.seed(0)
2424
#' x <- rexp(100, rate = 0.5)
25-
#' addexp(x)
26-
#' addexp(x, main = "Your Active Title", xlab = "Exponential Data", bins = 20)
27-
addexp <- function(
25+
#' iscamaddexp(x)
26+
#' iscamaddexp(x, main = "Your Active Title", xlab = "Exponential Data", bins = 20)
27+
iscamaddexp <- function(
2828
x,
2929
main = "Histogram with exponential curve",
3030
xlab = deparse(substitute(x)),
@@ -54,9 +54,9 @@ addexp <- function(
5454
#' @examples
5555
#' set.seed(0)
5656
#' x <- rlnorm(100)
57-
#' addlnorm(x)
58-
#' addlnorm(x, main = "Your Active Title", xlab = "Log Normal Data", bins = 20)
59-
addlnorm <- function(
57+
#' iscamaddlnorm(x)
58+
#' iscamaddlnorm(x, main = "Your Active Title", xlab = "Log Normal Data", bins = 20)
59+
iscamaddlnorm <- function(
6060
x,
6161
main = "Histogram with log-normal curve",
6262
xlab = deparse(substitute(x)),
@@ -89,9 +89,9 @@ addlnorm <- function(
8989
#' @examples
9090
#' set.seed(0)
9191
#' x <- rnorm(100)
92-
#' addnorm(x)
93-
#' addnorm(x, main = "Your Active Title", xlab = "Normal Data", bins = 20)
94-
addnorm <- function(
92+
#' iscamaddnorm(x)
93+
#' iscamaddnorm(x, main = "Your Active Title", xlab = "Normal Data", bins = 20)
94+
iscamaddnorm <- function(
9595
x,
9696
main = "Histogram with normal curve",
9797
xlab = deparse(substitute(x)),
@@ -124,9 +124,9 @@ addnorm <- function(
124124
#' @examples
125125
#' set.seed(0)
126126
#' x <- rt(100, 30)
127-
#' addt(x, 30)
128-
#' addt(x, 30, main = "Your Active Title", xlab = "t Data", bins = 20)
129-
addt <- function(
127+
#' iscamaddt(x, 30)
128+
#' iscamaddt(x, 30, main = "Your Active Title", xlab = "t Data", bins = 20)
129+
iscamaddt <- function(
130130
x,
131131
df,
132132
main = "Histogram with t curve",
@@ -160,9 +160,9 @@ addt <- function(
160160
#' @examples
161161
#' set.seed(0)
162162
#' x <- rt(100, 5)
163-
#' addtnorm(x, 5)
164-
#' addtnorm(x, 5, main = "Your Active Title", xlab = "t Data", bins = 20)
165-
addtnorm <- function(
163+
#' iscamaddtnorm(x, 5)
164+
#' iscamaddtnorm(x, 5, main = "Your Active Title", xlab = "t Data", bins = 20)
165+
iscamaddtnorm <- function(
166166
x,
167167
df,
168168
main = "Histogram with t and normal curve",

R/plots.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ NULL
2222
#' @export
2323
#'
2424
#' @examples
25-
#' boxplot(
25+
#' iscamboxplot(
2626
#' mtcars$mpg,
2727
#' main = "mtcars Cylinders Dotplot",
2828
#' xlab = "Number of Cylinders"
2929
#' )
30-
#' boxplot(
30+
#' iscamboxplot(
3131
#' mtcars$mpg,
3232
#' mtcars$am,
3333
#' main = "Automatic Cars Have Better Mileage on Average",
3434
#' xlab = "Mileage (miles per gallon)",
3535
#' ylab = "Automatic (yes coded as 1)"
3636
#' )
37-
boxplot <- function(
37+
iscamboxplot <- function(
3838
response,
3939
explanatory = NULL,
4040
main = "",
@@ -81,19 +81,19 @@ boxplot <- function(
8181
#' @export
8282
#'
8383
#' @examples
84-
#' dotplot(
84+
#' iscamdotplot(
8585
#' mtcars$cyl,
8686
#' main = "mtcars Cylinders Dotplot",
8787
#' xlab = "Number of Cylinders"
8888
#' )
89-
#' dotplot(
89+
#' iscamdotplot(
9090
#' mtcars$mpg,
9191
#' mtcars$am,
9292
#' main = "Automatic Cars Have Better Mileage on Average",
9393
#' xlab = "Mileage (miles per gallon)",
9494
#' ylab = "Automatic (yes coded as 1)"
9595
#' )
96-
dotplot <- function(
96+
iscamdotplot <- function(
9797
response,
9898
explanatory = NULL,
9999
main = "",
@@ -131,3 +131,8 @@ dotplot <- function(
131131
title(main = main, xlab = xlab, ylab = ylab)
132132
invisible()
133133
}
134+
135+
# TODO: look at lattice::histogram
136+
#' @noRd
137+
#' @keywords internal
138+
iscamhistogram <- function() {}

R/iscamsummary.R renamed to R/summary.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#' set.seed(0)
1818
#' fake_data <- rnorm(30) # simulating some data
1919
#' groups <- sample(c("group1","group2"), 30, TRUE)
20-
#' summary(fake_data)
21-
#' summary(fake_data, explanatory = groups, digits = 2) # with groups
22-
summary <- function(x, explanatory = NULL, digits = 3) {
20+
#' iscamsummary(fake_data)
21+
#' iscamsummary(fake_data, explanatory = groups, digits = 2) # with groups
22+
iscamsummary <- function(x, explanatory = NULL, digits = 3) {
2323
if (is.null(explanatory)) {
2424
output <- .getSummaryStats(x)
2525
} else {

0 commit comments

Comments
 (0)