Skip to content

Commit

Permalink
Fixed spacing issues; standardized (mostly) the way that printing is …
Browse files Browse the repository at this point in the history
…done
  • Loading branch information
kloppen committed Jun 22, 2020
1 parent 0b115ab commit 668ee9b
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 69 deletions.
25 changes: 23 additions & 2 deletions R/adk.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@
#' Guideline for Characterization of Structural Materials,” SAE International,
#' CMH-17-1G, Mar. 2012.
#'
#' @examples
#' library(dplyr)
#'
#' carbon.fabric %>%
#' filter(test == "WT") %>%
#' filter(condition == "RTD") %>%
#' ad_ksample(strength, batch)
#' ##
#' ## Call:
#' ## ad_ksample(data = ., x = strength, groups = batch)
#' ##
#' ## N = 18 k = 3
#' ## ADK = 0.912 p-value = 0.95989
#' ## Conclusion: Samples come from the same distribution ( alpha = 0.025 )
#'
#' @importFrom rlang enquo eval_tidy
#' @importFrom kSamples ad.test
#' @export
Expand Down Expand Up @@ -177,8 +192,14 @@ glance.adk <- function(x, ...) { # nolint
print.adk <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
cat("N = ", x$n, "\tk = ", x$k, "\n")
cat("ADK = ", x$ad, "\tp-value = ", x$p, "\n")

justify <- c("left", "left")
width <- c(16L, 16L)

print_row_equal(list("N", x$n, "k", x$k),
justify, width, ...)
print_row_equal(list("ADK", x$ad, "p-value", x$p),
justify, width, ...)
if (x$reject_same_dist) {
cat("Conclusion: Samples do not come from the same distribution (alpha =",
x$alpha, ")\n\n")
Expand Down
23 changes: 19 additions & 4 deletions R/adtest.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@
#' Composites Guideline for Characterization of Structural
#' Materials," SAE International, CMH-17-1G, Mar. 2012.
#'
#' @examples
#' library(dplyr)
#'
#' carbon.fabric %>%
#' filter(test == "FC") %>%
#' filter(condition == "RTD") %>%
#' anderson_darling_normal(strength)
#' ## Call:
#' ## anderson_darling_normal(data = ., x = strength)
#' ##
#' ## Distribution: Normal ( n = 18 )
#' ## Test statistic: A = 0.9224776
#' ## Significance: 0.01212193 (assuming unknown parameters)
#' ## Conclusion: Sample is not drawn from a Normal distribution (alpha = 0.05 )
#'
#' @importFrom rlang enquo eval_tidy
#'
#' @name anderson_darling
Expand Down Expand Up @@ -167,9 +182,9 @@ print.anderson_darling <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")

cat("Distribution: ", x$dist, "( n = ", x$n, ")", "\n")
cat("Distribution: ", x$dist, "( n =", x$n, ")", "\n")

cat("Test statistic: A = ", x$A, "\n")
cat("Test statistic: A =", x$A, "\n")
cat(
"Significance: ",
x$osl,
Expand All @@ -178,11 +193,11 @@ print.anderson_darling <- function(x, ...) {
if (x$reject_distribution) {
cat("Conclusion: Sample is not drawn from a",
x$dist,
"distribution (alpha = ", x$alpha, ")")
"distribution (alpha =", x$alpha, ")")
} else {
cat("Conclusion: Sample is drawn from a",
x$dist,
"distribution (alpha = ", x$alpha, ")")
"distribution (alpha =", x$alpha, ")")
}
}

Expand Down
22 changes: 13 additions & 9 deletions R/basis.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ k_factor_normal <- function(n, p = 0.90, conf = 0.95) {
#' value of \code{x} is expected to be a variable within \code{data}. If
#' \code{data} is not specified, \code{x} must be a vector.
#'
#' When \code{modcv=TRUE} is set, which is only applicable to the pooling methods,
#' the data is first modified according to the modified coefficient of variation (CV)
#' rules. This modified data is then used when both calculating the basis values and
#' also when performing the diagnostic tests. The modified CV approach is a way of
#' When \code{modcv=TRUE} is set, which is only applicable to the
#' pooling methods,
#' the data is first modified according to the modified coefficient
#' of variation (CV)
#' rules. This modified data is then used when both calculating the
#' basis values and
#' also when performing the diagnostic tests. The modified CV approach
#' is a way of
#' adding extra variance to datasets with unexpectedly low variance.
#'
#' \code{basis_normal} calculate the basis value by subtracting \eqn{k} times
Expand Down Expand Up @@ -422,9 +426,9 @@ print.basis <- function(x, ...) {

cat("Distribution: ", x$distribution, "\t")

cat("( n = ", x$n)
cat("( n =", x$n)
if (!is.null(x$r) & !all(is.na(x$r))) {
cat(", r = ", x$r)
cat(", r =", x$r)
}
cat(" )\n")

Expand All @@ -438,13 +442,13 @@ print.basis <- function(x, ...) {
x$override)

if (x$conf == 0.95 & x$p == 0.9) {
cat("B-Basis: ", " ( p = ", x$p, ", conf = ", x$conf, ")\n")
cat("B-Basis: ", " ( p =", x$p, ", conf =", x$conf, ")\n")
}
else if (x$conf == 0.95 & x$p == 0.99) {
cat("A-Basis: ", " ( p = ", x$p, ", conf = ", x$conf, ")\n")
cat("A-Basis: ", " ( p =", x$p, ", conf =", x$conf, ")\n")
}
else {
cat("Basis: ", " ( p = ", x$p, ", conf = ", x$conf, ")\n")
cat("Basis: ", " ( p =", x$p, ", conf =", x$conf, ")\n")
}

if (is.numeric(x$basis)) {
Expand Down
70 changes: 35 additions & 35 deletions R/equiv.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@
#' ##
#' ## Call:
#' ## equiv_mean_extremum(mean_qual = 100, sd_qual = 5.5, n_sample = 6,
#' ## alpha = 0.01, modcv = TRUE)
#' ## alpha = 0.01, modcv = TRUE)
#' ##
#' ## Modified CV used: CV* = 0.0675 ( CV = 0.055 )
#' ##
#' ## For alpha = 0.01 and n = 6
#' ## ( k1 = 3.128346 and k2 = 1.044342 )
#' ## Min Individual Sample Mean
#' ## Thresholds: 78.88367 92.95069
#' ## Min Individual Sample Mean
#' ## Thresholds: 78.88367 92.95069
#'
#' @seealso
#' \code{\link{k_equiv}}
Expand Down Expand Up @@ -308,12 +308,8 @@ print.equiv_mean_extremum <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")

printrow <- function(c1, c2, c3) {
cat(format(c1, justify = "right", width = 16L, ...),
format(c2, justify = "right", width = 16L, ...),
format(c3, justify = "right", width = 16L, ...),
"\n")
}
justify <- c("right", "centre", "centre")
col_width <- c(16L, 16L, 16L)

if (x$modcv) {
cat("Modified CV used: CV* =", format(x$cv_star, ...),
Expand All @@ -325,13 +321,19 @@ print.equiv_mean_extremum <- function(x, ...) {
"and n =", format(x$n_sample, ...),
"\n( k1 =", format(x$k1, ...),
"and k2 =", format(x$k2, ...), ")\n")
printrow("", "Min Individual", "Sample Mean")

print_row(list("", "Min Individual", "Sample Mean"),
justify, col_width, ...)

if (!is.null(x$min_sample)) {
printrow("Sample:", x$min_sample, x$mean_sample)
print_row(list("Sample:", x$min_sample, x$mean_sample),
justify, col_width, ...)
}
printrow("Thresholds:", x$threshold_min_indiv, x$threshold_mean)
print_row(list("Thresholds:", x$threshold_min_indiv, x$threshold_mean),
justify, col_width, ...)
if (!is.null(x$result_min_indiv)) {
printrow("Equivalency:", x$result_min_indiv, x$result_mean)
print_row(list("Equivalency:", x$result_min_indiv, x$result_mean),
justify, col_width, ...)
}
}

Expand Down Expand Up @@ -866,32 +868,30 @@ print.equiv_change_mean <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")

printrow <- function(c1, c2, c3) {
cat(format(c1, justify = "right", width = 16L, ...),
format(c2, justify = "centre", width = 16L, ...),
format(c3, justify = "centre", width = 16L, ...),
"\n")
}

printrow2 <- function(c1, c2) {
cat(format(c1, justify = "right", width = 16L, ...),
format(c2, justify = "centre", width = 32L, ...),
"\n")
}

cat("For alpha =", format(x$alpha, ...), "\n")

if (x$modcv) {
cat("Modified CV used\n")
}

printrow("", "Qualification", "Sample")
printrow("Number", format(x$n_qual, ...), format(x$n_sample, ...))
printrow("Mean", format(x$mean_qual, ...), format(x$mean_sample, ...))
printrow("SD", format(x$sd_qual, ...), format(x$sd_sample, ...))
printrow2("Result", x$result)
printrow2("Passing Range", paste0(format(x$threshold[1], ...),
" to ",
format(x$threshold[2], ...))
)
justify3 <- c("right", "centre", "centre")
width3 <- c(16L, 16L, 16L)

justify2 <- c("right", "centre")
width2 <- c(16L, 32L)

print_row(list("", "Qualification", "Sample"),
justify3, width3, ...)
print_row(list("Number", x$n_qual, x$n_sample),
justify3, width3, ...)
print_row(list("Mean", x$mean_qual, x$mean_sample),
justify3, width3, ...)
print_row(list("SD", x$sd_qual, x$sd_sample),
justify3, width3, ...)
print_row(list("Result", x$result),
justify2, width2, ...)
print_row(list("Passing Range", paste0(format(x$threshold[1], ...),
" to ",
format(x$threshold[2], ...))),
justify2, width2, ...)
}
28 changes: 24 additions & 4 deletions R/levene.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@
#' Guideline for Characterization of Structural Materials,” SAE International,
#' CMH-17-1G, Mar. 2012.
#'
#' @examples
#' library(dplyr)
#'
#' carbon.fabric.2 %>%
#' filter(test == "FC") %>%
#' levene_test(strength, condition)
#' ##
#' ## Call:
#' ## levene_test(data = ., x = strength, groups = condition)
#' ##
#' ## n = 91 k = 5
#' ## F = 3.883818 p-value = 0.00600518
#' ## Conclusion: Samples have unequal variance ( alpha = 0.05 )
#'
#' @importFrom rlang enquo eval_tidy
#' @importFrom stats var.test median pf
#'
Expand Down Expand Up @@ -193,18 +207,24 @@ glance.levene <- function(x, ...) { # nolint
print.levene <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
cat("n = ", x$n, "\tk = ", x$k, "\n")

justify <- c("left", "left")
width <- c(16L, 16L)

print_row_equal(list("n", x$n, "k", x$k),
justify, width, ...)

if (x$modcv == TRUE) {
cat("Modified CV Approach Used", "\n")
}

cat("F = ", x$f, "\tp-value = ", x$p, "\n")
print_row_equal(list("F", x$f, "p-value", x$p),
justify, width, ...)
if (x$reject_equal_variance) {
cat("Conclusion: Samples have unequal variance ( alpha=",
cat("Conclusion: Samples have unequal variance ( alpha =",
x$alpha, ")\n\n")
} else {
cat("Conclusion: Samples have equal variances ( alpha=",
cat("Conclusion: Samples have equal variances ( alpha =",
x$alpha, ")\n\n")
}
}
16 changes: 8 additions & 8 deletions R/mnr.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,20 @@ augment.mnr <- function(x, data = x$data, ...) { # nolint
print.mnr <- function(x, ...) {
cat("\nCall:\n",
paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n", sep = "")
cat("MNR = ", x$mnr, " ( critical value = ", x$crit, ")\n\n")
cat("MNR =", x$mnr, " ( critical value =", x$crit, ")\n\n")
if (nrow(x$outliers) == 0) {
cat("No outliers detected\n\n")
} else {
cat("Outliers:\n")

col_width <- max(nchar(as.character(x$outliers[["index"]])), 5) + 2
cat(format("Index", width = col_width, justify = "right"))
cat(" ")
cat("Value\n")
justify <- c("right", "left", "left")
width <- c(8L, 2L, 16L)

print_row(list("Index", " ", "Value"), justify, width, ...)

for (j in seq(along.with = x$outliers$index)) {
cat(format(x$outliers[["index"]][j], width = col_width))
cat(" ")
cat(x$outliers[["value"]][j], "\n")
print_row(list(x$outliers[["index"]][j], " ", x$outliers[["value"]][j]),
justify, width, ...)
}

}
Expand Down
29 changes: 29 additions & 0 deletions R/util.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

print_row <- function(content, justify, width, ...) {
# content must be a list, justify and width must be vectors
for (i in seq_along(content)) {
cat(format(
format(content[[i]], ...),
justify = justify[i],
width = width[i],
...))
}
cat("\n")
}

print_row_equal <- function(content, justify, column_width, ...) {
# content must be a list with the content:
# (var_name1, var1, var_name2, var2, etc)
# the length of content will be twice the length of the other vectors
for (i in seq_along(justify)) {
cat(format(
paste0(content[[2 * i - 1]],
" = ",
format(content[[2 * i]], ...)
),
justify = justify[i],
width = column_width[i],
...))
}
cat("\n")
}
16 changes: 16 additions & 0 deletions man/ad_ksample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions man/anderson_darling.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 668ee9b

Please sign in to comment.