diff --git a/NAMESPACE b/NAMESPACE index 5bbb9e4..c1e2680 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,8 +30,6 @@ S3method(print,infer_ts_ind_ttest) S3method(print,infer_ts_paired_ttest) S3method(print,infer_ts_prop_test) S3method(print,infer_ts_var_test) -S3method(print,var_test_shiny) -S3method(var_test_shiny,default) export(binom_calc) export(binom_test) export(chisq_gof) @@ -70,16 +68,13 @@ export(ts_prop_grp) export(ts_prop_test) export(ttest) export(var_test) -export(var_test_shiny) importFrom(Rcpp,sourceCpp) importFrom(dplyr,"%>%") importFrom(dplyr,funs) importFrom(dplyr,group_by) -importFrom(dplyr,group_by_) importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,select) -importFrom(dplyr,select_) importFrom(dplyr,summarise_all) importFrom(magrittr,"%>%") importFrom(magrittr,subtract) @@ -93,6 +88,7 @@ importFrom(rlang,"!!") importFrom(rlang,enquo) importFrom(rlang,quo_is_null) importFrom(rlang,quos) +importFrom(rlang,sym) importFrom(shiny,runApp) importFrom(stats,anova) importFrom(stats,as.formula) @@ -116,4 +112,4 @@ importFrom(stats,var) importFrom(tibble,as_data_frame) importFrom(tibble,tibble) importFrom(tidyr,gather) -useDynLib(inferr, .registration = TRUE) +useDynLib(inferr) diff --git a/R/RcppExports.R b/R/RcppExports.R index 97c2d3a..49b3de1 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -2,10 +2,10 @@ # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 nsignC <- function(x) { - .Call(`_inferr_nsignC`, x) + .Call('_inferr_nsignC', PACKAGE = 'inferr', x) } gvar <- function(ln, ly) { - .Call(`_inferr_gvar`, ln, ly) + .Call('_inferr_gvar', PACKAGE = 'inferr', ln, ly) } diff --git a/R/infer-two-samp-var-test-shiny.R b/R/infer-two-samp-var-test-shiny.R deleted file mode 100644 index f183c78..0000000 --- a/R/infer-two-samp-var-test-shiny.R +++ /dev/null @@ -1,89 +0,0 @@ -#' @importFrom stats complete.cases -#' @importFrom purrr map_dbl -#' @title Two Sample Variance Comparison Test Shiny -#' @description \code{var_test} performs tests on the equality of standard -#' deviations (variances). -#' @param data a dataframe -#' @param variable1 character; name of sample 1 in data frame -#' @param variable2 character; name of sample 2 in data frame -#' @param alternative a character string specifying the alternative hypothesis, -#' must be one of "both" (default), "greater", "less" or "all". You can specify -#' just the initial letter. -#' @return \code{var_test} returns an object of class \code{"var_test"}. -#' An object of class \code{"var_test"} is a list containing the -#' following components: -#' -#' \item{f}{f statistic} -#' \item{lower}{lower one-sided p-value} -#' \item{upper}{upper one-sided p-value} -#' \item{two_tail}{two-sided p-value} -#' \item{vars}{variances for each level of the grouping variable} -#' \item{avgs}{means for each level of the grouping variable} -#' \item{sds}{standard deviations for each level of the grouping variable} -#' \item{ses}{standard errors for each level of the grouping variable} -#' \item{avg}{combined mean} -#' \item{sd}{combined standard deviation} -#' \item{se}{estimated combined standard error} -#' \item{n1}{numerator degrees of freedom} -#' \item{n2}{denominator degrees of freedom} -#' \item{lens}{number of observations for each level of grouping variable} -#' \item{len}{number of observations} -#' \item{lev}{levels of the grouping variable} -#' \item{type}{alternative hypothesis} -#' -#' @references Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric -#' Statistical Procedures, 4th edition. : Chapman & Hall/CRC. -#' @seealso \code{\link[stats]{var.test}} -#' @examples -#' # using two variables -#' # lower tail -#' var_test_shiny(hsb, 'read', 'write', alternative = 'less') -#' -#' # upper tail -#' var_test_shiny(hsb, 'read', 'write', alternative = 'greater') -#' -#' # all tails -#' var_test_shiny(hsb, 'read', 'write', alternative = 'all') -#' -#' @export -#' -var_test_shiny <- function(data, variable1, variable2, - alternative = c("less", "greater", "all")) UseMethod('var_test_shiny') - -#' @export -#' -var_test_shiny.default <- function(data, variable1, variable2, - alternative = c("less", "greater", "all")) { - - variables <- data %>% select_(variable1, variable2) - z <- list(variables[[1]], variables[[2]]) - ln <- z %>% map_int(length) - ly <- seq_len(length(z)) - - if (length(z) < 2) { - stop('Please specify at least two variables.', call. = FALSE) - } - - out <- gvar(ln, ly) - variable <- unlist(z) - group_var <- unlist(out) - - type <- match.arg(alternative) - k <- var_comp(variable, group_var) - lev <- c(variable1, variable2) - - out <- list(f = k$f, lower = k$lower, upper = k$upper, vars = k$vars, - avgs = k$avgs, sds = k$sds, ses = k$ses, avg = k$avg, sd = k$sd, - se = k$se, n1 = k$n1, n2 = k$n2, lens = k$lens, len = k$len, - lev = lev, type = type) - - class(out) <- 'var_test_shiny' - return(out) - -} - -#' @export -#' -print.var_test_shiny <- function(x, ...) { - print_var_test(x) -} diff --git a/R/infer-utils.R b/R/infer-utils.R index 91e5e01..ffad90a 100644 --- a/R/infer-utils.R +++ b/R/infer-utils.R @@ -1,4 +1,4 @@ -#' @importFrom dplyr group_by group_by_ select_ summarise_all funs mutate +#' @importFrom dplyr group_by summarise_all funs mutate #' @importFrom magrittr %>% use_series #' @importFrom stats var sd #' @importFrom tibble tibble as_data_frame @@ -741,10 +741,12 @@ indpool <- function(n1, n2, mean_diff, se_dif) { return(out) } +#' @importFrom rlang sym tibble_stats <- function(data, x, y) { + by_factor <- data %>% - group_by_(y) %>% - select_(y, x) %>% + group_by(!! sym(y)) %>% + select(!! sym(y), !! sym(x)) %>% summarise_all(funs(length, mean, var, sd)) %>% as_data_frame() %>% mutate( @@ -755,7 +757,7 @@ tibble_stats <- function(data, x, y) { tbl_stats <- function(data, y) { avg <- data %>% - select_(y) %>% + select(y) %>% summarise_all(funs(length, mean, sd)) %>% as_data_frame() %>% mutate( @@ -837,8 +839,8 @@ paired_data <- function(x, y) { #' @importFrom dplyr select paired_stats <- function(data, key, value) { d <- data %>% - group_by_(key) %>% - select_(value, key) %>% + group_by(key) %>% + select(value, key) %>% summarise_all(funs(length, mean, sd)) %>% as_data_frame() %>% mutate( diff --git a/man/var_test_shiny.Rd b/man/var_test_shiny.Rd deleted file mode 100644 index c2a9660..0000000 --- a/man/var_test_shiny.Rd +++ /dev/null @@ -1,66 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/infer-two-samp-var-test-shiny.R -\name{var_test_shiny} -\alias{var_test_shiny} -\title{Two Sample Variance Comparison Test Shiny} -\usage{ -var_test_shiny(data, variable1, variable2, alternative = c("less", "greater", - "all")) -} -\arguments{ -\item{data}{a dataframe} - -\item{variable1}{character; name of sample 1 in data frame} - -\item{variable2}{character; name of sample 2 in data frame} - -\item{alternative}{a character string specifying the alternative hypothesis, -must be one of "both" (default), "greater", "less" or "all". You can specify -just the initial letter.} -} -\value{ -\code{var_test} returns an object of class \code{"var_test"}. -An object of class \code{"var_test"} is a list containing the -following components: - -\item{f}{f statistic} -\item{lower}{lower one-sided p-value} -\item{upper}{upper one-sided p-value} -\item{two_tail}{two-sided p-value} -\item{vars}{variances for each level of the grouping variable} -\item{avgs}{means for each level of the grouping variable} -\item{sds}{standard deviations for each level of the grouping variable} -\item{ses}{standard errors for each level of the grouping variable} -\item{avg}{combined mean} -\item{sd}{combined standard deviation} -\item{se}{estimated combined standard error} -\item{n1}{numerator degrees of freedom} -\item{n2}{denominator degrees of freedom} -\item{lens}{number of observations for each level of grouping variable} -\item{len}{number of observations} -\item{lev}{levels of the grouping variable} -\item{type}{alternative hypothesis} -} -\description{ -\code{var_test} performs tests on the equality of standard -deviations (variances). -} -\examples{ -# using two variables -# lower tail -var_test_shiny(hsb, 'read', 'write', alternative = 'less') - -# upper tail -var_test_shiny(hsb, 'read', 'write', alternative = 'greater') - -# all tails -var_test_shiny(hsb, 'read', 'write', alternative = 'all') - -} -\references{ -Sheskin, D. J. 2007. Handbook of Parametric and Nonparametric -Statistical Procedures, 4th edition. : Chapman & Hall/CRC. -} -\seealso{ -\code{\link[stats]{var.test}} -} diff --git a/tests/testthat/test-two-samp-var-test-shiny.R b/tests/testthat/test-two-samp-var-test-shiny.R deleted file mode 100644 index 042f3e5..0000000 --- a/tests/testthat/test-two-samp-var-test-shiny.R +++ /dev/null @@ -1,23 +0,0 @@ -context('var test shiny') - -test_that('output from var_test_shiny matches expected result', { - - k <- var_test_shiny(mtcars, 'mpg', 'qsec', alternative = 'less') - expect_equal(k$f, 11.3756) - expect_equal(k$lower, 1) - expect_equal(k$upper, 0) - expect_equivalent(as.vector(k$vars), c(36.32, 3.19)) - expect_equivalent(as.vector(k$avgs), c(20.09, 17.85)) - expect_equivalent(as.vector(k$sds), c(6.03, 1.79)) - expect_equivalent(as.vector(k$ses), c(1.07, 0.32)) - expect_equal(k$avg, 18.97) - expect_equal(k$sd, 4.55) - expect_equal(k$se, 0.57) - expect_equal(k$len, 64) - expect_equivalent(as.vector(k$lens), c(32, 32)) - expect_equal(unname(k$n1), 31) - expect_equal(unname(k$n2), 31) - expect_equivalent(k$type, 'less') - expect_equivalent(k$lev, c('mpg', 'qsec')) - -})