From 95e3bad7fa330b04f2b25dc0616fdc7f18c43726 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Mon, 29 Dec 2014 11:08:04 -0500 Subject: [PATCH 001/219] Change description per CRAN maintainer suggestion --- DESCRIPTION | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bfd763f..42fd1fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,14 @@ Package: tableone Type: Package -Title: Create "Table 1" to describe baseline characteristics +Title: Create "Table 1" to Describe Baseline Characteristics Version: 0.6.3 Date: 2014-12-28 Author: Kazuki Yoshida, Justin Bohn. Maintainer: Kazuki Yoshida -Description: This package creates "Table 1", i.e., description of baseline - patient characteristics, which is essential in every medical research. This - package provides functions to create such summaries for continuous and - categorical variables, optionally with subgroup comparisons. The package +Description: tableone creates "Table 1", i.e., description of baseline + patient characteristics, which is essential in every medical research. + It provides functions to create such summaries for continuous and + categorical variables, optionally with subgroup comparisons. tableone was inspired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. From 956ebe938117ac98d73e849ddcd68fd51bd78e7a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 27 Mar 2015 22:01:34 -0400 Subject: [PATCH 002/219] Add confint.default override --- R/ShowRegTable.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/ShowRegTable.R b/R/ShowRegTable.R index d569bd8..ba16609 100644 --- a/R/ShowRegTable.R +++ b/R/ShowRegTable.R @@ -9,6 +9,7 @@ ##' @param pDigits Number of digits to print for the p-values. ##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. +##' @param simpleCi Whether to calculate confidence interval by the default normal approximation method. The default is FALSE. If TRUE, the default normal approximation method is used. This may be used when the profile likelihood-based calculation takes too much time. ##' @return A matrix containing what you see is returned invisibly. You can capture it by assignment to an object. ##' @author Kazuki Yoshida ##' @examples @@ -33,7 +34,12 @@ ##' ShowRegTable(objCoxph, quote = TRUE) ##' ##' @export -ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle = TRUE, quote = FALSE) { +ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle = TRUE, + quote = FALSE, simpleCi = FALSE) { + + if (simpleCi) { + confint <- confint.default + } ## Create formats fmt1 <- paste0("%.", digits, "f") From 7c18463239d0db380f5230f0e4ed1053650f0869 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 27 Mar 2015 22:05:56 -0400 Subject: [PATCH 003/219] Change to exp(coef) --- R/ShowRegTable.R | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/R/ShowRegTable.R b/R/ShowRegTable.R index ba16609..b083a60 100644 --- a/R/ShowRegTable.R +++ b/R/ShowRegTable.R @@ -1,8 +1,8 @@ ##' Format regression results in medically decent format -##' +##' ##' It shows the regression result in the HR [95\% CI] p-value format, which is usually the form used in medical research papers. -##' -##' +##' +##' ##' @param model Regression model result objects that have the summary and confint methods. ##' @param exp TRUE by default. You need to specify exp = FALSE if your model is has the indentity link function (linear regression, etc). ##' @param digits Number of digits to print for the main part. @@ -13,26 +13,26 @@ ##' @return A matrix containing what you see is returned invisibly. You can capture it by assignment to an object. ##' @author Kazuki Yoshida ##' @examples -##' +##' ##' ## Load ##' library(tableone) -##' +##' ##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data ##' library(survival) ##' data(pbc) ##' ## Check variables ##' head(pbc) -##' +##' ##' ## Fit a Cox regression model ##' objCoxph <- coxph(formula = Surv(time, status == 2) ~ trt + age + albumin + ascites, ##' data = pbc) -##' +##' ##' ## Show the simple table ##' ShowRegTable(objCoxph) -##' +##' ##' ## Show with quote to ease copy and paste ##' ShowRegTable(objCoxph, quote = TRUE) -##' +##' ##' @export ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle = TRUE, quote = FALSE, simpleCi = FALSE) { @@ -65,7 +65,7 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle pointEstimates <- sprintf(fmt = fmt1, resMat[,1]) pointEstimates <- format(pointEstimates, justify = "right") - + resString <- sprintf(fmt = paste0("%s", " [", fmt1, ", ", fmt1 ,"]"), ## resMat[,1], # point estimate pointEstimates, @@ -76,7 +76,7 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle ## Format p-values pString <- sprintf(fmt = fmt2, modelP) - ## Create a string like <0.001 + ## Create a string like <0.001 smallPString <- paste0("<0.", paste0(rep("0", pDigits - 1), collapse = ""), "1") ## Check positions where it is all zero like 0.000 posAllZeros <- grepl("^0\\.0*$", pString) @@ -85,7 +85,7 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle ## Put a preceding " " where it is not all zero like 0.000 pString[!posAllZeros] <- paste0(" ", pString[!posAllZeros]) - + ## Combine with the result column. (Need to be after exponentiation) outMat <- cbind(resString, "p" = pString) @@ -95,15 +95,15 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle ## Change column names depending on the exponentiation status if (exp) { - colnames(outMat)[1] <- "exp(beta) [confint]" + colnames(outMat)[1] <- "exp(coef) [confint]" } else if (!exp) { - colnames(outMat)[1] <- "beta [confint]" + colnames(outMat)[1] <- "coef [confint]" } ## Add quotes if requested if (quote) { rownames(outMat) <- paste0('"', rownames(outMat), '"') - colnames(outMat) <- paste0('"', colnames(outMat), '"') + colnames(outMat) <- paste0('"', colnames(outMat), '"') } From 1c6d848bf1b1b33799b62b470de1619f6bc772d2 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 15:24:11 -0400 Subject: [PATCH 004/219] Start weighted table object creators as copies --- R/CreateCatTableWt.R | 209 +++++++++++++++++++++++++++++++++++ R/CreateContTableWt.R | 246 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 455 insertions(+) create mode 100644 R/CreateCatTableWt.R create mode 100644 R/CreateContTableWt.R diff --git a/R/CreateCatTableWt.R b/R/CreateCatTableWt.R new file mode 100644 index 0000000..fa8b516 --- /dev/null +++ b/R/CreateCatTableWt.R @@ -0,0 +1,209 @@ +##' Create an object summarizing categorical variables +##' +##' Create an object summarizing categorical variables optionally stratifying +##' by one or more startifying variables and performing statistical tests. The +##' object gives a table that is easy to use in medical research papers. See +##' also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +##' +##' @param vars Variable(s) to be summarized given as a character vector. +##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. +##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. +##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. +##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) +##' @seealso +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for categorical variables +##' catVars <- c("status","ascites","hepato","spiders","edema","stage") +##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.CatTable method, +##' ## which will show the sample size, frequencies and percentages. +##' ## For 2-level variables, only the higher level is shown for simplicity +##' ## unless the variables are specified in the cramVars argument. +##' catTableOverall +##' +##' ## If you need to show both levels for some 2-level factors, use cramVars +##' print(catTableOverall, cramVars = "hepato") +##' +##' ## Use the showAllLevels argument to see all levels for all variables. +##' print(catTableOverall, showAllLevels = TRUE) +##' +##' ## You can choose form frequencies ("f") and/or percentages ("p") or both. +##' ## "fp" frequency (percentage) is the default. Row names change accordingly. +##' print(catTableOverall, format = "f") +##' print(catTableOverall, format = "p") +##' +##' ## To further examine the variables, use the summary.CatTable method, +##' ## which will show more details. +##' summary(catTableOverall) +##' +##' ## The table can be stratified by one or more variables +##' catTableBySexTrt <- CreateCatTable(vars = catVars, +##' strata = c("sex","trt"), data = pbc) +##' +##' ## print now includes p-values which are by default calculated by chisq.test. +##' ## It is formatted at the decimal place specified by the pDigits argument +##' ## (3 by default). It does <0.001 for you. +##' catTableBySexTrt +##' +##' ## The exact argument toggles the p-values to the exact test result from +##' ## fisher.test. It will show which ones are from exact tests. +##' print(catTableBySexTrt, exact = "ascites") +##' +##' ## summary now includes both types of p-values +##' summary(catTableBySexTrt) +##' +##' ## If your work flow includes copying to Excel and Word when writing manuscripts, +##' ## you may benefit from the quote argument. This will quote everything so that +##' ## Excel does not mess up the cells. +##' print(catTableBySexTrt, exact = "ascites", quote = TRUE) +##' +##' ## If you want to center-align values in Word, use noSpaces option. +##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +##' +##' @export +CreateCatTable <- + function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + test = TRUE, # whether to put p-values + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5) # arguments passed to testExact + ) { + +### Data check + ## Check if the data given is a dataframe + ModuleStopIfNotDataFrame(data) + + ## Check if variables exist. Drop them if not. + vars <- ModuleReturnVarsExist(vars, data) + + ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) + + ## Extract necessary variables (unused variables are not included in dat) + dat <- data[c(vars)] + + ## Toggle test FALSE if no strata + test <- ModuleReturnFalseIfNoStrata(strata, test) + + ## Convert to a factor if it is not a factor already. (categorical version only) + ## Not done on factors, to avoid dropping zero levels. + ## Probably this cannot handle Surv object?? + logiNotFactor <- sapply(dat, function(VEC) { + ## Return TRUE if classes for a vector does NOT contain class "factor" + ## VEC is a vector of a variable in the dat data frame, use class + !any(class(VEC) %in% c("factor")) + }) + + dat[logiNotFactor] <- lapply(dat[logiNotFactor], factor) + + ## Create strata data frame (data frame with only strata variables) + strata <- ModuleReturnStrata(strata, data) + + +### Actual descriptive statistics are calculated here. + + ## strata--variable-CreateTableForOneVar structure + ## Devide by strata + result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame + + ## Work on each stratum + FUN = function(dfStrataDat) { # dfStrataDat should be a data frame + + ## Loop for variables + sapply(dfStrataDat, + FUN = ModuleCreateTableForOneVar, + simplify = FALSE) + + }, simplify = FALSE) + + + ## Add stratification variable information as an attribute + if (length(result) > 1 ) { + ## strataVarName from dimension headers + strataVarName <- ModuleCreateStrataVarName(result) + ## Add an attribute for the stratifying variable name + attributes(result) <- c(attributes(result), + list(strataVarName = strataVarName)) + } + + +### Perform tests when necessary + ## Initialize + pValues <- NULL + listXtabs <- list() + + ## Only when test is asked for + if (test == TRUE) { + + ## Create a single variable representation of multivariable stratification + strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + + ## Loop over variables in dat, and create a list of xtabs + ## Empty strata are kept in the corss tables. Different behavior than the cont counterpart! + listXtabs <- sapply(X = names(dat), + FUN = function(var) { + ## Create a formula + formula <- paste0("~ ", var, " + ", "strataVar") + formula <- as.formula(formula) + + ## Create a 2-dimensional crosstable + xtabs(formula = formula, data = dat) + }, + simplify = FALSE) + + ## Rename the second dimension of the xtabs with the newly create name. + for (i in seq_along(listXtabs)) { + + names(dimnames(listXtabs[[i]]))[2] <- strataVarName + } + + ## Loop over xtabs, and create p-values + pValues <- sapply(X = listXtabs, + FUN = function(xtabs) { + ## Perform tests and return the result as 1x2 DF + data.frame( + pApprox = ModuleTestSafe(xtabs, testApprox, argsApprox), + pExact = ModuleTestSafe(xtabs, testExact, argsExact) + ) + }, + simplify = FALSE) + + ## Create a single data frame (n x 2 (normal,nonormal)) + pValues <- do.call(rbind, pValues) + } # Conditional for test == TRUE ends here. + + + ## Return object + ## Give an S3 class + class(result) <- c("CatTable", class(result)) + + ## Give additional attributes + attributes(result) <- c(attributes(result), + list(pValues = pValues), + list(xtabs = listXtabs)) + + ## Return + return(result) +} diff --git a/R/CreateContTableWt.R b/R/CreateContTableWt.R new file mode 100644 index 0000000..27f6e1e --- /dev/null +++ b/R/CreateContTableWt.R @@ -0,0 +1,246 @@ +##' Create an object summarizing continous variables +##' +##' Create an object summarizing continous variables optionally stratifying by +##' one or more startifying variables and performing statistical tests. The +##' object gives a table that is easy to use in medical research papers. See +##' also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +##' +##' @param vars Variable(s) to be summarized given as a character vector. +##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. +##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param funcNames The functions to give the group size, number with missing values, proportion with missing values, mean, standard deviations, median, 25th percentile, 75th percentile, minimum, maximum, skewness (same definition as in SAS), kurtosis (same definition as in SAS). All of them can be seen in the summary method output. The print method uses subset of these. You can choose subset of them or reorder them. They are all configure to omit NA values (\code{na.rm = TRUE}). +##' @param funcAdditional Additional functions can be given as a named list. For example, \code{list(sum = sum)}. +##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method. +##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. +##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. +##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. +##' @return An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) +##' @seealso +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for continuous variables +##' contVars <- c("time","age","bili","chol","albumin","copper", +##' "alk.phos","ast","trig","platelet","protime") +##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.ContTable method, +##' ## which will show the sample size, means and standard deviations. +##' contTableOverall +##' +##' ## To further examine the variables, use the summary.ContTable method, +##' ## which will show more details. +##' summary(contTableOverall) +##' +##' ## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. +##' ## Specify them in the nonnormal argument, and the display changes to the median, +##' ## and the [25th, 75th] percentile. +##' nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") +##' print(contTableOverall, nonnormal = nonNormalVars) +##' +##' ## To show median [min,max] for nonnormal variables, use minMax = TRUE +##' print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) +##' +##' ## The table can be stratified by one or more variables +##' contTableBySexTrt <- CreateContTable(vars = contVars, +##' strata = c("sex","trt"), data = pbc) +##' +##' ## print now includes p-values which are by default calculated by oneway.test (t-test +##' ## equivalent in the two group case). It is formatted at the decimal place specified +##' ## by the pDigits argument (3 by default). It does <0.001 for you. +##' contTableBySexTrt +##' +##' ## The nonnormal argument toggles the p-values to the nonparametric result from +##' ## kruskal.test (wilcox.test equivalent for the two group case). +##' print(contTableBySexTrt, nonnormal = nonNormalVars) +##' +##' ## summary now includes both types of p-values +##' summary(contTableBySexTrt) +##' +##' ## If your work flow includes copying to Excel and Word when writing manuscripts, +##' ## you may benefit from the quote argument. This will quote everything so that +##' ## Excel does not mess up the cells. +##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) +##' +##' ## If you want to center-align values in Word, use noSpaces option. +##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +##' +##' @export +CreateContTable <- + function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + funcNames = c( # can pick a subset of them + "n","miss","p.miss", + "mean","sd", + "median","p25","p75","min","max", + "skew","kurt" + ), + funcAdditional, # named list of additional functions + test = TRUE, # Whether to put p-values + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { + + ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) + ## require(e1071) # for skewness and kurtosis + +### Data check + ## Check if the data given is a dataframe + ModuleStopIfNotDataFrame(data) + + ## Check if variables exist. Drop them if not. + vars <- ModuleReturnVarsExist(vars, data) + + ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) + + ## Extract necessary variables + dat <- data[c(vars)] + + ## Toggle test FALSE if no strata + test <- ModuleReturnFalseIfNoStrata(strata, test) + + ## Create strata data frame (data frame with only strata variables) + strata <- ModuleReturnStrata(strata, data) + + + ## Handle non-numeric elements (intergers give TRUE, and pass) + if(any(!sapply(dat, is.numeric))){ + ## If there is any non-numeric variables + dat <- dat[sapply(dat, is.numeric)] + warning("Non-numeric variables dropped") + } + + ## Check if all the variables are continuous, and stop if not + if(!all(sapply(dat, is.numeric))) {stop("Can only be run on numeric variables")} + + + ## Create indexes for default functions by partial string matching with the funcNames argument + funcIndexes <- pmatch(funcNames, c("n","miss","p.miss", + "mean","sd", + "median","p25","p75","min","max", + "skew","kurt")) + ## Remove NA + funcIndexes <- funcIndexes[!is.na(funcIndexes)] + + ## Create a list of default functions + functions <- c("n" = function(x) {length(x)}, + "miss" = function(x) {sum(is.na(x))}, + "p.miss" = function(x) {(sum(is.na(x)) / length(x)) * 100}, + "mean" = function(x) {mean(x, na.rm = TRUE)}, + "sd" = function(x) {sd(x, na.rm = TRUE)}, + "median" = function(x) {median(x, na.rm = TRUE)}, + "p25" = function(x) {quantile(x, probs = 0.25, na.rm = TRUE)}, + "p75" = function(x) {quantile(x, probs = 0.75, na.rm = TRUE)}, + "min" = function(x) {min(x, na.rm = TRUE)}, + "max" = function(x) {max(x, na.rm = TRUE)}, + "skew" = function(x) {ModuleSasSkewness(x)}, + "kurt" = function(x) {ModuleSasKurtosis(x)} + ) + + ## Keep only functions in use + functions <- functions[funcIndexes] + + ## Check for additional functions + if(!missing(funcAdditional)) { + + ## When additional functions are given + if(!is.list(funcAdditional) || is.null(names(funcAdditional))) { + ## Stop if not a named list + stop("funcAdditional must be a named list of functions") + } + + ## If a named list is given, add to the vector of functions and their names + functions <- c(functions, unlist(funcAdditional)) + funcNames <- c(funcNames, names(funcAdditional)) + } + + +### Actual descriptive statistics are calculated here. + ## strata-functions-variable structure alternative 2014-01-22 + ## Devide by strata + result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame + + ## Work on each stratum + FUN = function(strataDat) { # Work on each stratum through by() + + ## Loop for functions + out <- sapply(X = functions, + FUN = function(fun) { + + ## Loop for variables + sapply(X = strataDat, FUN = fun, simplify = TRUE) + + }, simplify = FALSE) + + ## The 2nd-level loop does not simplify to avoid oversimplification + ## when there is only one variable. + do.call(cbind, out) + }) + + ## Add stratification variable information as an attribute + if (length(result) > 1 ) { + ## strataVarName from dimension headers + strataVarName <- ModuleCreateStrataVarName(result) + ## Add an attribute for the stratifying variable name + attributes(result) <- c(attributes(result), + list(strataVarName = strataVarName)) + } + + +### Perform tests when necessary + ## Initialize to avoid error when it does not exist at the attribute assignment + pValues <- NULL + + + ## Only when test is asked for + if (test == TRUE) { + + ## Create a single variable representation of multivariable stratification + strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + + ## Loop over variables in dat, and obtain p values for two tests + ## DF = 6 when there are 8 levels (one empty), i.e., empty strata dropped by oneway.test/kruskal.test + pValues <- + sapply(X = dat, + FUN = function(var) { + ## Perform tests and return the result as 1x2 DF + data.frame( + pNormal = ModuleTestSafe(var ~ strataVar, testNormal, argsNormal), + pNonNormal = ModuleTestSafe(var ~ strataVar, testNonNormal, argsNonNormal) + ) + }, + simplify = FALSE) + + ## Create a single data frame (n x 2 (normal,nonormal)) + pValues <- do.call(rbind, pValues) + } # Conditional for test == TRUE ends here. + + + ## Return object + ## Give an S3 class + class(result) <- c("ContTable", class(result)) + + ## Give additional attributes + attributes(result) <- c(attributes(result), + list(pValues = pValues)) + + ## Return + return(result) +} From 576906543979a72f3291a2fa9d8e58047b31d153 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:27:06 -0400 Subject: [PATCH 005/219] Add module file for survey support --- R/svyModules.R | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 R/svyModules.R diff --git a/R/svyModules.R b/R/svyModules.R new file mode 100644 index 0000000..2c3b2cc --- /dev/null +++ b/R/svyModules.R @@ -0,0 +1,6 @@ +################################################################################ +### Modules for survey data support +## +## Created on: 2015-07-23 +## Author: Kazuki Yoshida +################################################################################ From 76ce8daaf98169fb3e1bbda439e43587603cbaa6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:33:32 -0400 Subject: [PATCH 006/219] Add helper functions for continuous variable summary --- R/svyModules.R | 116 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/R/svyModules.R b/R/svyModules.R index 2c3b2cc..68a8b94 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -1,6 +1,120 @@ ################################################################################ ### Modules for survey data support -## +## ## Created on: 2015-07-23 ## Author: Kazuki Yoshida ################################################################################ + + +### +### Generic helpers +################################################################################ + +## Function to return 1 as many as x elements +## Used for counting weighted sample size +one <- function(x) { + rep(1, length(x)) +} + + +## 0,1 indicator variable for missingness +miss <- function(x) { + as.numeric(is.na(x)) +} + + +## Return formula string having vars on RHS +FormulaString <- function(vars) { + paste0(" ~ ", vars, collapse = " + ") +} + + +### +### Helpers for continuous variable summary +################################################################################ + +svyN <- function(vars, design) { + ## Same for all variables, just use first + form <- sprintf(" ~ one(%s)", vars[1]) + ## No missing handling as all values are 1 + res <- svytotal(x = as.formula(form), design = design) + ## Repeat for all variables + out <- rep(res[1], length(vars)) + names(out) <- vars + out +} + + +svyMiss <- function(vars, design) { + + ## Rewrite variables locally to missing 0,1 indicators + design$variables[vars] <- lapply(design$variables[vars], miss) + + ## Same for all variables, just use first + form <- paste0(" ~ ", vars, collapse = " + ") + + res <- svytotal(x = as.formula(form), design = design) + out <- as.vector(res) + names(out) <- vars + out +} + + +svyPMiss <- function(vars, design) { + svyMiss(vars, design) / svyN(vars, design) +} + + +svyMean <- function(vars, design) { + ## Same for all variables, just use first + form <- paste0(" ~ ", vars, collapse = " + ") + ## Remove missingness and mean + ## Bad behavior, but consistent with the unweighted version + res <- svymean(x = as.formula(form), design = design, na.rm = TRUE) + out <- as.vector(res) + names(out) <- vars + out +} + + +svySd <- function(vars, design) { + ## Same for all variables, just use first + form <- paste0(" ~ ", vars, collapse = " + ") + ## Remove missingness and var + ## Bad behavior, but consistent with the unweighted version + res <- svyvar(x = as.formula(form), design = design, na.rm = TRUE) + ## Diagnonal elements are variances + out <- sqrt(diag(res)) + names(out) <- vars + sqrt(out) +} + +svyQuant <- function(vars, design, q = 0.5) { + ## Same for all variables, just use first + form <- paste0(" ~ ", vars, collapse = " + ") + ## Remove missingness and mean + ## Bad behavior, but consistent with the unweighted version + res <- svyquantile(x = as.formula(form), quantiles = q, design = design, na.rm = TRUE) + out <- as.vector(res) + names(out) <- vars + out +} + + +svyContSummary <- function(vars, design) { + + ## Save for reuse + nVec <- svyN(vars, design) + missVec <- svyMiss(vars, design) + + cbind(n = nVec, + miss = missVec, + p.miss = missVec / nVec * 100, + mean = svyMean(vars, design), + sd = svySd(vars, design), + median = svyQuant(vars, design, q = 0.5), + p25 = svyQuant(vars, design, q = 0.25), + p75 = svyQuant(vars, design, q = 0.75), + min = svyQuant(vars, design, q = 0), + max = svyQuant(vars, design, q = 1)) +} From 8877a193268f62ae9a6e7d886b7866582c445f13 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:36:03 -0400 Subject: [PATCH 007/219] Factor out formula string creation --- R/svyModules.R | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index 68a8b94..aa85e06 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -51,7 +51,7 @@ svyMiss <- function(vars, design) { design$variables[vars] <- lapply(design$variables[vars], miss) ## Same for all variables, just use first - form <- paste0(" ~ ", vars, collapse = " + ") + form <- FormulaString(vars) res <- svytotal(x = as.formula(form), design = design) out <- as.vector(res) @@ -67,7 +67,7 @@ svyPMiss <- function(vars, design) { svyMean <- function(vars, design) { ## Same for all variables, just use first - form <- paste0(" ~ ", vars, collapse = " + ") + form <- FormulaString(vars) ## Remove missingness and mean ## Bad behavior, but consistent with the unweighted version res <- svymean(x = as.formula(form), design = design, na.rm = TRUE) @@ -79,7 +79,7 @@ svyMean <- function(vars, design) { svySd <- function(vars, design) { ## Same for all variables, just use first - form <- paste0(" ~ ", vars, collapse = " + ") + form <- FormulaString(vars) ## Remove missingness and var ## Bad behavior, but consistent with the unweighted version res <- svyvar(x = as.formula(form), design = design, na.rm = TRUE) @@ -89,9 +89,10 @@ svySd <- function(vars, design) { sqrt(out) } + svyQuant <- function(vars, design, q = 0.5) { ## Same for all variables, just use first - form <- paste0(" ~ ", vars, collapse = " + ") + form <- FormulaString(vars) ## Remove missingness and mean ## Bad behavior, but consistent with the unweighted version res <- svyquantile(x = as.formula(form), quantiles = q, design = design, na.rm = TRUE) @@ -107,14 +108,14 @@ svyContSummary <- function(vars, design) { nVec <- svyN(vars, design) missVec <- svyMiss(vars, design) - cbind(n = nVec, - miss = missVec, + cbind(n = nVec, + miss = missVec, p.miss = missVec / nVec * 100, - mean = svyMean(vars, design), - sd = svySd(vars, design), + mean = svyMean(vars, design), + sd = svySd(vars, design), median = svyQuant(vars, design, q = 0.5), - p25 = svyQuant(vars, design, q = 0.25), - p75 = svyQuant(vars, design, q = 0.75), - min = svyQuant(vars, design, q = 0), - max = svyQuant(vars, design, q = 1)) + p25 = svyQuant(vars, design, q = 0.25), + p75 = svyQuant(vars, design, q = 0.75), + min = svyQuant(vars, design, q = 0), + max = svyQuant(vars, design, q = 1)) } From 2db58bebb0b80be5a874c9df5022ef23464fd054 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:38:43 -0400 Subject: [PATCH 008/219] Change name to svyX --- R/{CreateCatTableWt.R => svyCreateCatTable.R} | 4 ++-- ...eateContTableWt.R => svyCreateContTable.R} | 21 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) rename R/{CreateCatTableWt.R => svyCreateCatTable.R} (99%) rename R/{CreateContTableWt.R => svyCreateContTable.R} (91%) diff --git a/R/CreateCatTableWt.R b/R/svyCreateCatTable.R similarity index 99% rename from R/CreateCatTableWt.R rename to R/svyCreateCatTable.R index fa8b516..e7f61ba 100644 --- a/R/CreateCatTableWt.R +++ b/R/svyCreateCatTable.R @@ -1,4 +1,4 @@ -##' Create an object summarizing categorical variables +##' Create an object summarizing categorical variables for weighted data ##' ##' Create an object summarizing categorical variables optionally stratifying ##' by one or more startifying variables and performing statistical tests. The @@ -80,7 +80,7 @@ ##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) ##' ##' @export -CreateCatTable <- +CreateCatTableWt <- function(vars, # character vector of variable names strata, # character vector of variable names data, # data frame diff --git a/R/CreateContTableWt.R b/R/svyCreateContTable.R similarity index 91% rename from R/CreateContTableWt.R rename to R/svyCreateContTable.R index 27f6e1e..4896db3 100644 --- a/R/CreateContTableWt.R +++ b/R/svyCreateContTable.R @@ -1,4 +1,4 @@ -##' Create an object summarizing continous variables +##' Create an object summarizing continous variables for weighted dataset ##' ##' Create an object summarizing continous variables optionally stratifying by ##' one or more startifying variables and performing statistical tests. The @@ -8,8 +8,8 @@ ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. -##' @param funcNames The functions to give the group size, number with missing values, proportion with missing values, mean, standard deviations, median, 25th percentile, 75th percentile, minimum, maximum, skewness (same definition as in SAS), kurtosis (same definition as in SAS). All of them can be seen in the summary method output. The print method uses subset of these. You can choose subset of them or reorder them. They are all configure to omit NA values (\code{na.rm = TRUE}). -##' @param funcAdditional Additional functions can be given as a named list. For example, \code{list(sum = sum)}. +##' @param funcNames Not available for weighted dataset +##' @param funcAdditional Not available for weighted dataset ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method. ##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. @@ -79,17 +79,12 @@ ##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) ##' ##' @export -CreateContTable <- +CreateContTableWt <- function(vars, # character vector of variable names strata, # character vector of variable names data, # data frame - funcNames = c( # can pick a subset of them - "n","miss","p.miss", - "mean","sd", - "median","p25","p75","min","max", - "skew","kurt" - ), - funcAdditional, # named list of additional functions + funcNames = NULL, # Ignored + funcAdditional = NULL, # Ignored test = TRUE, # Whether to put p-values testNormal = oneway.test, # test for normally distributed variables argsNormal = list(var.equal = TRUE), # arguments passed to testNormal @@ -101,8 +96,8 @@ CreateContTable <- ## require(e1071) # for skewness and kurtosis ### Data check - ## Check if the data given is a dataframe - ModuleStopIfNotDataFrame(data) + ## Check if the data given is a survey design object + ModuleStopIfNotSurveyDesign(data) ## Check if variables exist. Drop them if not. vars <- ModuleReturnVarsExist(vars, data) From ecaf6e9c8160e4c6a0c72ef08f655592d6544dd5 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:44:59 -0400 Subject: [PATCH 009/219] Drop flexible function choice from svyCreateContTable --- R/svyCreateContTable.R | 44 +++--------------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 4896db3..1bc11f6 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -126,50 +126,12 @@ CreateContTableWt <- if(!all(sapply(dat, is.numeric))) {stop("Can only be run on numeric variables")} - ## Create indexes for default functions by partial string matching with the funcNames argument - funcIndexes <- pmatch(funcNames, c("n","miss","p.miss", - "mean","sd", - "median","p25","p75","min","max", - "skew","kurt")) - ## Remove NA - funcIndexes <- funcIndexes[!is.na(funcIndexes)] - - ## Create a list of default functions - functions <- c("n" = function(x) {length(x)}, - "miss" = function(x) {sum(is.na(x))}, - "p.miss" = function(x) {(sum(is.na(x)) / length(x)) * 100}, - "mean" = function(x) {mean(x, na.rm = TRUE)}, - "sd" = function(x) {sd(x, na.rm = TRUE)}, - "median" = function(x) {median(x, na.rm = TRUE)}, - "p25" = function(x) {quantile(x, probs = 0.25, na.rm = TRUE)}, - "p75" = function(x) {quantile(x, probs = 0.75, na.rm = TRUE)}, - "min" = function(x) {min(x, na.rm = TRUE)}, - "max" = function(x) {max(x, na.rm = TRUE)}, - "skew" = function(x) {ModuleSasSkewness(x)}, - "kurt" = function(x) {ModuleSasKurtosis(x)} - ) - - ## Keep only functions in use - functions <- functions[funcIndexes] - - ## Check for additional functions - if(!missing(funcAdditional)) { - - ## When additional functions are given - if(!is.list(funcAdditional) || is.null(names(funcAdditional))) { - ## Stop if not a named list - stop("funcAdditional must be a named list of functions") - } - - ## If a named list is given, add to the vector of functions and their names - functions <- c(functions, unlist(funcAdditional)) - funcNames <- c(funcNames, names(funcAdditional)) - } - - ### Actual descriptive statistics are calculated here. ## strata-functions-variable structure alternative 2014-01-22 ## Devide by strata + + + result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame ## Work on each stratum From 53a33b7fd3dcbb0afeb58cb0f05462e647f636dd Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:45:48 -0400 Subject: [PATCH 010/219] Add survey data checker --- R/svyCreateContTable.R | 2 +- R/svyModules.R | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 1bc11f6..f4e8627 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -97,7 +97,7 @@ CreateContTableWt <- ### Data check ## Check if the data given is a survey design object - ModuleStopIfNotSurveyDesign(data) + StopIfNotSurveyDesign(data) ## Check if variables exist. Drop them if not. vars <- ModuleReturnVarsExist(vars, data) diff --git a/R/svyModules.R b/R/svyModules.R index aa85e06..39fe01c 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -29,6 +29,20 @@ FormulaString <- function(vars) { } +### +### Helpers for both types of data +################################################################################ + +## Check for survey data; fail if not +StopIfNotSurveyDesign <- function(data) { + + if (c("survey.design2") %in% class(data)) { + stop("The data argument needs to be a survey design object.") + } + +} + + ### ### Helpers for continuous variable summary ################################################################################ From 755aa3badb1213df381c87bee193352d6c309d3a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 23 Jul 2015 22:53:16 -0400 Subject: [PATCH 011/219] Drop unused argument from svyCreateContTable --- R/svyCreateContTable.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index f4e8627..b4f41f6 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -79,12 +79,10 @@ ##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) ##' ##' @export -CreateContTableWt <- +svyCreateContTable <- function(vars, # character vector of variable names strata, # character vector of variable names - data, # data frame - funcNames = NULL, # Ignored - funcAdditional = NULL, # Ignored + data, # survey design data test = TRUE, # Whether to put p-values testNormal = oneway.test, # test for normally distributed variables argsNormal = list(var.equal = TRUE), # arguments passed to testNormal From 3e02ac077b258e41e253eee01954f303fa7c9f91 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 09:52:20 -0400 Subject: [PATCH 012/219] Change continuous data check to support svydesign --- R/svyCreateContTable.R | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index b4f41f6..9ca71d6 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -93,18 +93,19 @@ svyCreateContTable <- ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) ## require(e1071) # for skewness and kurtosis -### Data check +## Data check ## Check if the data given is a survey design object StopIfNotSurveyDesign(data) ## Check if variables exist. Drop them if not. - vars <- ModuleReturnVarsExist(vars, data) + ## survey.design$variables holds original data frame + vars <- ModuleReturnVarsExist(vars, data$variables) ## Abort if no variables exist at this point ModuleStopIfNoVarsLeft(vars) ## Extract necessary variables - dat <- data[c(vars)] + dat <- data[vars] ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) @@ -114,22 +115,25 @@ svyCreateContTable <- ## Handle non-numeric elements (intergers give TRUE, and pass) - if(any(!sapply(dat, is.numeric))){ + if(any(!sapply(data$variables[vars], is.numeric))){ + ## If there is any non-numeric variables - dat <- dat[sapply(dat, is.numeric)] + vars <- vars[sapply(data$variables[vars], is.numeric)] warning("Non-numeric variables dropped") } ## Check if all the variables are continuous, and stop if not - if(!all(sapply(dat, is.numeric))) {stop("Can only be run on numeric variables")} + if(!all(sapply(data$variables[vars], is.numeric))) { + stop("Can only be run on numeric variables") + } ### Actual descriptive statistics are calculated here. ## strata-functions-variable structure alternative 2014-01-22 ## Devide by strata - - + + result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame ## Work on each stratum From 7ed109719e448893fa948d91031dfb2cd4f65812 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 09:59:45 -0400 Subject: [PATCH 013/219] Add todo for strata handling --- R/svyCreateContTable.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 9ca71d6..2ce81f1 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -111,7 +111,11 @@ svyCreateContTable <- test <- ModuleReturnFalseIfNoStrata(strata, test) ## Create strata data frame (data frame with only strata variables) - strata <- ModuleReturnStrata(strata, data) + ## FIXME: This changes type of strata + strata <- ModuleReturnStrata(strata, data$variables) + + ## Create a single stratification variable + strataVar <- do.call(interaction, strata) ## Handle non-numeric elements (intergers give TRUE, and pass) @@ -129,11 +133,15 @@ svyCreateContTable <- ### Actual descriptive statistics are calculated here. - ## strata-functions-variable structure alternative 2014-01-22 - ## Devide by strata + ## To implement + ## Create a single grouping variable from strata variables + ## Create a list of subgroup data by the grouping variable + ## Loop over each stratum with matrix forming function + ## strata-functions-variable structure alternative 2014-01-22 + ## Devide by strata result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame ## Work on each stratum From cab41a4f4489c22967bdc240cc920474e0200c5e Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 12:50:03 -0400 Subject: [PATCH 014/219] Add stratification functionality to CreateContTable --- R/svyCreateContTable.R | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 2ce81f1..f1f486e 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -111,12 +111,13 @@ svyCreateContTable <- test <- ModuleReturnFalseIfNoStrata(strata, test) ## Create strata data frame (data frame with only strata variables) - ## FIXME: This changes type of strata + ## FIXME: This changes type of strata; not a good practice strata <- ModuleReturnStrata(strata, data$variables) ## Create a single stratification variable - strataVar <- do.call(interaction, strata) - + ## Keeps non-existing levels + strataVar <- interaction(strata, sep = ":") + strataVarLevels <- levels(strataVar) ## Handle non-numeric elements (intergers give TRUE, and pass) if(any(!sapply(data$variables[vars], is.numeric))){ @@ -139,32 +140,19 @@ svyCreateContTable <- ## Create a list of subgroup data by the grouping variable ## Loop over each stratum with matrix forming function + result <- lapply(strataVarLevels, function(level) { - ## strata-functions-variable structure alternative 2014-01-22 - ## Devide by strata - result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame - - ## Work on each stratum - FUN = function(strataDat) { # Work on each stratum through by() - - ## Loop for functions - out <- sapply(X = functions, - FUN = function(fun) { - - ## Loop for variables - sapply(X = strataDat, FUN = fun, simplify = TRUE) - - }, simplify = FALSE) + ## Create a matrix including vars X c(n,miss,...) matrix + svyContSummary(vars, subset(data, strataVar == level)) + }) + ## Make it a by object + class(result) <- "by" - ## The 2nd-level loop does not simplify to avoid oversimplification - ## when there is only one variable. - do.call(cbind, out) - }) ## Add stratification variable information as an attribute if (length(result) > 1 ) { ## strataVarName from dimension headers - strataVarName <- ModuleCreateStrataVarName(result) + strataVarName <- paste0(names(strata), collapse = ":") ## Add an attribute for the stratifying variable name attributes(result) <- c(attributes(result), list(strataVarName = strataVarName)) From f278c6ac0358a9cc17e05e80b9aee96639bb6d8d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 13:21:03 -0400 Subject: [PATCH 015/219] Keep strata names --- R/svyCreateContTable.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index f1f486e..fd9cf32 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -93,7 +93,7 @@ svyCreateContTable <- ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) ## require(e1071) # for skewness and kurtosis -## Data check +### Data check ## Check if the data given is a survey design object StopIfNotSurveyDesign(data) @@ -104,9 +104,6 @@ svyCreateContTable <- ## Abort if no variables exist at this point ModuleStopIfNoVarsLeft(vars) - ## Extract necessary variables - dat <- data[vars] - ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) @@ -140,17 +137,19 @@ svyCreateContTable <- ## Create a list of subgroup data by the grouping variable ## Loop over each stratum with matrix forming function - result <- lapply(strataVarLevels, function(level) { + result <- sapply(strataVarLevels, function(level) { ## Create a matrix including vars X c(n,miss,...) matrix svyContSummary(vars, subset(data, strataVar == level)) - }) + + }, simplify = FALSE) + ## Make it a by object class(result) <- "by" ## Add stratification variable information as an attribute - if (length(result) > 1 ) { + if (length(result) > 1) { ## strataVarName from dimension headers strataVarName <- paste0(names(strata), collapse = ":") ## Add an attribute for the stratifying variable name @@ -164,8 +163,9 @@ svyCreateContTable <- pValues <- NULL - ## Only when test is asked for - if (test == TRUE) { + ## Only when test is asked FOR + ## TEMPORALILY TURNED OFF + if (test & FALSE) { ## Create a single variable representation of multivariable stratification strataVar <- ModuleCreateStrataVarAsFactor(result, strata) @@ -190,7 +190,7 @@ svyCreateContTable <- ## Return object ## Give an S3 class - class(result) <- c("ContTable", class(result)) + class(result) <- c("svyContTable", "ContTable", class(result)) ## Give additional attributes attributes(result) <- c(attributes(result), From d5699e7f9b72830a69e4f399e727238d476989d3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 13:26:44 -0400 Subject: [PATCH 016/219] Fix broken survey.design object checker --- R/svyModules.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/svyModules.R b/R/svyModules.R index 39fe01c..5fec783 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -36,7 +36,7 @@ FormulaString <- function(vars) { ## Check for survey data; fail if not StopIfNotSurveyDesign <- function(data) { - if (c("survey.design2") %in% class(data)) { + if (!("survey.design2" %in% class(data))) { stop("The data argument needs to be a survey design object.") } From 211d6683be35bd2c3587031bdadfe04100e301c9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 13:27:00 -0400 Subject: [PATCH 017/219] Add data checker for svyCreateCatTable --- R/svyCreateCatTable.R | 69 +++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index e7f61ba..9409af7 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -93,56 +93,75 @@ CreateCatTableWt <- ### Data check ## Check if the data given is a dataframe - ModuleStopIfNotDataFrame(data) + StopIfNotSurveyDesign(data) ## Check if variables exist. Drop them if not. - vars <- ModuleReturnVarsExist(vars, data) + vars <- ModuleReturnVarsExist(vars, data$variables) ## Abort if no variables exist at this point ModuleStopIfNoVarsLeft(vars) - ## Extract necessary variables (unused variables are not included in dat) - dat <- data[c(vars)] - ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + ## Create strata data frame (data frame with only strata variables) + ## FIXME: This changes type of strata; not a good practice + strata <- ModuleReturnStrata(strata, data$variables) + + ## Create a single stratification variable + ## Keeps non-existing levels + strataVar <- interaction(strata, sep = ":") + strataVarLevels <- levels(strataVar) + ## Convert to a factor if it is not a factor already. (categorical version only) ## Not done on factors, to avoid dropping zero levels. - ## Probably this cannot handle Surv object?? - logiNotFactor <- sapply(dat, function(VEC) { + logiNotFactor <- sapply(data$variables, function(v) { ## Return TRUE if classes for a vector does NOT contain class "factor" - ## VEC is a vector of a variable in the dat data frame, use class - !any(class(VEC) %in% c("factor")) + ## v is a vector of a variable in the data$variables data frame, use class + ## Ordered factor has c("ordered", "factor"), thus, %in% is necessary + !("factor" %in% class(v)) }) - dat[logiNotFactor] <- lapply(dat[logiNotFactor], factor) - - ## Create strata data frame (data frame with only strata variables) - strata <- ModuleReturnStrata(strata, data) + data$variables[logiNotFactor] <- lapply(data$variables[logiNotFactor], factor) ### Actual descriptive statistics are calculated here. - ## strata--variable-CreateTableForOneVar structure - ## Devide by strata - result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame + ## To implement + ## Create a single grouping variable from strata variables + ## Create a list of subgroup data by the grouping variable + ## Loop over each stratum with matrix forming function - ## Work on each stratum - FUN = function(dfStrataDat) { # dfStrataDat should be a data frame + result <- sapply(strataVarLevels, function(level) { - ## Loop for variables - sapply(dfStrataDat, - FUN = ModuleCreateTableForOneVar, - simplify = FALSE) + ## Create a matrix including vars X c(n,miss,...) matrix + svyCatSummary(vars, subset(data, strataVar == level)) + + }, simplify = FALSE) + + ## Make it a by object + class(result) <- "by" - }, simplify = FALSE) + if (FALSE) { + ## strata--variable-CreateTableForOneVar structure + ## Devide by strata + result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame + ## Work on each stratum + FUN = function(dfStrataDat) { # dfStrataDat should be a data frame + + ## Loop for variables + sapply(dfStrataDat, + FUN = ModuleCreateTableForOneVar, + simplify = FALSE) + + }, simplify = FALSE) + } ## Add stratification variable information as an attribute - if (length(result) > 1 ) { + if (length(result) > 1) { ## strataVarName from dimension headers - strataVarName <- ModuleCreateStrataVarName(result) + strataVarName <- paste0(names(strata), collapse = ":") ## Add an attribute for the stratifying variable name attributes(result) <- c(attributes(result), list(strataVarName = strataVarName)) From 4b5ae8caf37ca5d91d33272abba5580465c95886 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 13:48:20 -0400 Subject: [PATCH 018/219] Add helpers for categorical variable summary --- R/svyModules.R | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/R/svyModules.R b/R/svyModules.R index 5fec783..d73efd9 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -133,3 +133,44 @@ svyContSummary <- function(vars, design) { min = svyQuant(vars, design, q = 0), max = svyQuant(vars, design, q = 1)) } + + +### +### Helpers for categorical variable summary +################################################################################ + +svyTable <- function(vars, design) { + form <- FormulaString(vars) + ## Remove missingness and mean + ## Bad behavior, but consistent with the unweighted version + res <- svytable(formula = as.formula(form), design = design) + out +} + + +svyLevel <- function(vars, design) { + names(svyTable(vars, design)) +} + + +svyPropTable <- function(vars, design) { + prop.table(svyTable(vars, design)) +} + + +svyCatSummary <- function(vars, design) { + + ## Save for reuse + freqTab <- svyTable(vars, design) + propTab <- prop.table(freqTab), + nVec <- svyN(vars, design) + missVec <- svyMiss(vars, design) + + data.frame(n = nVec, + miss = missVec, + p.miss = missVec / nVec * 100, + level = names(freqTab), + freq = freqTab, # This remains as a table + percent = propTab, + cum.percent = cumsum(propTab)) +} From 6774fd6597bb0535141cd52a16481a7c0a3b9142 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 14:17:53 -0400 Subject: [PATCH 019/219] Add functionality to include as a level --- R/svyModules.R | 74 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index d73efd9..e5951f4 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -138,39 +138,67 @@ svyContSummary <- function(vars, design) { ### ### Helpers for categorical variable summary ################################################################################ +## These work on one variable at a time -svyTable <- function(vars, design) { - form <- FormulaString(vars) - ## Remove missingness and mean - ## Bad behavior, but consistent with the unweighted version - res <- svytable(formula = as.formula(form), design = design) +svyTable <- function(var, design, includeNA = FALSE) { + form <- FormulaString(var) + + ## If including NA, redefine variable + if (includeNA) { + design$variables[, var] <- factor(design$variables[, var], exclude = NULL) + } + + out <- svytable(formula = as.formula(form), design = design) out } -svyLevel <- function(vars, design) { - names(svyTable(vars, design)) +svyLevel <- function(var, design) { + names(svyTable(var, design)) +} + + +svyPropTable <- function(var, design) { + prop.table(svyTable(var, design)) } -svyPropTable <- function(vars, design) { - prop.table(svyTable(vars, design)) +svyCatSummary <- function(var, design, includeNA = FALSE) { + + ## Tables + freqTab <- svyTable(var, design, includeNA) + propTab <- prop.table(freqTab) + nLevels <- length(freqTab) + ## Repeat as many as the levels + nVec <- rep(svyN(var, design), nLevels) + missVec <- rep(svyMiss(var, design), nLevels) + + data.frame(n = nVec, + miss = missVec, + p.miss = missVec / nVec * 100, + level = names(freqTab), + freq = as.vector(freqTab), + percent = as.vector(propTab), + cum.percent = cumsum(propTab), + ## To protect against, level having + row.names = NULL) } -svyCatSummary <- function(vars, design) { - ## Save for reuse - freqTab <- svyTable(vars, design) - propTab <- prop.table(freqTab), - nVec <- svyN(vars, design) - missVec <- svyMiss(vars, design) - data.frame(n = nVec, - miss = missVec, - p.miss = missVec / nVec * 100, - level = names(freqTab), - freq = freqTab, # This remains as a table - percent = propTab, - cum.percent = cumsum(propTab)) -} + + + + + + + + + + + + + + + From 7eab482432872ae43ee1f87e9a5c38f717449dc3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 14:23:36 -0400 Subject: [PATCH 020/219] Fix percent; add function that can take multiple categorical vars --- R/svyModules.R | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index e5951f4..ebbf1ce 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -163,7 +163,8 @@ svyPropTable <- function(var, design) { } -svyCatSummary <- function(var, design, includeNA = FALSE) { +## This one works at a single variable level within a stratum +svyCatSummaryForOneVar <- function(var, design, includeNA = FALSE) { ## Tables freqTab <- svyTable(var, design, includeNA) @@ -178,27 +179,19 @@ svyCatSummary <- function(var, design, includeNA = FALSE) { p.miss = missVec / nVec * 100, level = names(freqTab), freq = as.vector(freqTab), - percent = as.vector(propTab), - cum.percent = cumsum(propTab), + percent = as.vector(propTab) * 100, + cum.percent = cumsum(propTab) * 100, ## To protect against, level having row.names = NULL) } +## This one can take multiple variables and return a list +svyCatSummary <- function(vars, design, includeNA = FALSE) { + sapply(vars, function(var) { + svyCatSummaryForOneVar(var, design, includeNA) - - - - - - - - - - - - - - + }, simplify = FALSE) +} From adebe5aa0f1cf5f1735cec8c7121e407190cbde5 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 14:25:39 -0400 Subject: [PATCH 021/219] Finish svyCreateCatTable with new function --- R/svyCreateCatTable.R | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 9409af7..6debcee 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -80,16 +80,16 @@ ##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) ##' ##' @export -CreateCatTableWt <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - test = TRUE, # whether to put p-values - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5) # arguments passed to testExact - ) { +svyCreateCatTable <- +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + test = TRUE, # whether to put p-values + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5) # arguments passed to testExact + ) { ### Data check ## Check if the data given is a dataframe @@ -142,22 +142,6 @@ CreateCatTableWt <- ## Make it a by object class(result) <- "by" - if (FALSE) { - ## strata--variable-CreateTableForOneVar structure - ## Devide by strata - result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame - - ## Work on each stratum - FUN = function(dfStrataDat) { # dfStrataDat should be a data frame - - ## Loop for variables - sapply(dfStrataDat, - FUN = ModuleCreateTableForOneVar, - simplify = FALSE) - - }, simplify = FALSE) - } - ## Add stratification variable information as an attribute if (length(result) > 1) { ## strataVarName from dimension headers @@ -174,7 +158,8 @@ CreateCatTableWt <- listXtabs <- list() ## Only when test is asked for - if (test == TRUE) { + ## TURN OFF FOR THE TIME BEING + if (test & FALSE) { ## Create a single variable representation of multivariable stratification strataVar <- ModuleCreateStrataVarAsFactor(result, strata) @@ -216,7 +201,7 @@ CreateCatTableWt <- ## Return object ## Give an S3 class - class(result) <- c("CatTable", class(result)) + class(result) <- c("svyCatTable", "CatTable", class(result)) ## Give additional attributes attributes(result) <- c(attributes(result), From fc204bf2d6f9af8e5f2fecf2461f85e8be3b6a47 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 14:51:46 -0400 Subject: [PATCH 022/219] Manipulate local survey design file itself for including NA --- R/svyCreateCatTable.R | 19 ++++++++++++++++++- R/svyModules.R | 16 +++++----------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 6debcee..11cdc5e 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -84,9 +84,10 @@ svyCreateCatTable <- function(vars, # character vector of variable names strata, # character vector of variable names data, # data frame + includeNA = FALSE, # include NA as a category test = TRUE, # whether to put p-values testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox + argsApprox = list(correct = TRUE), # arguments passed to testApprox testExact = fisher.test, # function for exact test argsExact = list(workspace = 2*10^5) # arguments passed to testExact ) { @@ -124,6 +125,22 @@ function(vars, # character vector of variable na data$variables[logiNotFactor] <- lapply(data$variables[logiNotFactor], factor) + ## If including NA as a level, include NA as a factor level before subsetting + if (includeNA) { + ## Logical vector for variables that have any NA + logiAnyNA <- (colSums(is.na(data$variables)) > 0) + + ## Add NA as a new level unless already present + data$variables[logiAnyNA] <- + lapply(data$variables[logiAnyNA], + function(var) { + if (all(!is.na(levels(var)))) { + var <- factor(var, c(levels(var), NA), + exclude = NULL) + } + var + }) + } ### Actual descriptive statistics are calculated here. diff --git a/R/svyModules.R b/R/svyModules.R index ebbf1ce..9e72876 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -140,14 +140,8 @@ svyContSummary <- function(vars, design) { ################################################################################ ## These work on one variable at a time -svyTable <- function(var, design, includeNA = FALSE) { +svyTable <- function(var, design) { form <- FormulaString(var) - - ## If including NA, redefine variable - if (includeNA) { - design$variables[, var] <- factor(design$variables[, var], exclude = NULL) - } - out <- svytable(formula = as.formula(form), design = design) out } @@ -164,10 +158,10 @@ svyPropTable <- function(var, design) { ## This one works at a single variable level within a stratum -svyCatSummaryForOneVar <- function(var, design, includeNA = FALSE) { +svyCatSummaryForOneVar <- function(var, design) { ## Tables - freqTab <- svyTable(var, design, includeNA) + freqTab <- svyTable(var, design) propTab <- prop.table(freqTab) nLevels <- length(freqTab) ## Repeat as many as the levels @@ -187,11 +181,11 @@ svyCatSummaryForOneVar <- function(var, design, includeNA = FALSE) { ## This one can take multiple variables and return a list -svyCatSummary <- function(vars, design, includeNA = FALSE) { +svyCatSummary <- function(vars, design) { sapply(vars, function(var) { - svyCatSummaryForOneVar(var, design, includeNA) + svyCatSummaryForOneVar(var, design) }, simplify = FALSE) } From 6984860a44aed2221cd38e52cbde3b3c701eb496 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 15:02:35 -0400 Subject: [PATCH 023/219] Add unified interface for weighted data as a copy --- R/svyCreateTableOne.R | 250 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 R/svyCreateTableOne.R diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R new file mode 100644 index 0000000..39c5bc8 --- /dev/null +++ b/R/svyCreateTableOne.R @@ -0,0 +1,250 @@ +##' Create an object summarizing both categorical and continuous variables +##' +##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +##' +##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used. +##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. +##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. +##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. +##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. +##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. +##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. +##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. +##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @return An object of class \code{TableOne}, which really is a list of three objects. +##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} +##' @return \item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} +##' @return \item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} +##' @return The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +##' +##' @author Justin Bohn, Kazuki Yoshida +##' @seealso +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Make categorical variables factors +##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) +##' +##' ## Create a variable list +##' dput(names(pbc)) +##' vars <- c("time","status","age","sex","ascites","hepato", +##' "spiders","edema","bili","chol","albumin", +##' "copper","alk.phos","ast","trig","platelet", +##' "protime","stage") +##' +##' ## Create Table 1 stratified by trt +##' tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) +##' +##' ## Just typing the object name will invoke the print.TableOne method +##' tableOne +##' +##' ## Specifying nonnormal variables will show the variables appropriately, +##' ## and show nonparametric test p-values. Specify variables in the exact +##' ## argument to obtain the exact test p-values. +##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), +##' exact = c("status","stage")) +##' +##' ## Use the summary.TableOne method for detailed summary +##' summary(tableOne) +##' +##' ## See the categorical part only using $ operator +##' tableOne$CatTable +##' summary(tableOne$CatTable) +##' +##' ## See the continuous part only using $ operator +##' tableOne$ContTable +##' summary(tableOne$ContTable) +##' +##' ## If your work flow includes copying to Excel and Word when writing manuscripts, +##' ## you may benefit from the quote argument. This will quote everything so that +##' ## Excel does not mess up the cells. +##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), +##' exact = c("status","stage"), quote = TRUE) +##' +##' ## If you want to center-align values in Word, use noSpaces option. +##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), +##' exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) +##' +##' @export +CreateTableOne <- + function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + test = TRUE, # whether to put p-values + ## Test configuration for categorical data + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5), # arguments passed to testExact + ## Test configuration for continuous data + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { + +### Data check + ## Check if the data given is a dataframe + ModuleStopIfNotDataFrame(data) + + ## Check if vars argument is missing. If so, add all names in data. + if (missing(vars)) { + vars <- names(data) + } + + ## Check if variables exist. Drop them if not. + vars <- ModuleReturnVarsExist(vars, data) + + ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) + + ## Factor conversions if the factorVars argument exist + if (!missing(factorVars)) { + ## Check if variables exist. Drop them if not. + factorVars <- ModuleReturnVarsExist(factorVars, data) + ## Convert to factor + data[factorVars] <- lapply(data[factorVars], factor) + } + + ## Toggle test FALSE if no strata is given + test <- ModuleReturnFalseIfNoStrata(strata, test) + + ## Get the classes of the variables + varClasses <- lapply(data[vars], class) + + ## Classify as varFactors if any one of these classes are contained + varFactors <-sapply(varClasses, function(VEC) { + any(VEC %in% c("factor", "ordered", "logical", "character")) + }) + varFactors <- names(varFactors)[varFactors] + + ## Classify as varNumerics if any one of these classes are contained + varNumerics <-sapply(varClasses, function(VEC) { + any(VEC %in% c("numeric", "integer")) + }) + varNumerics <- names(varNumerics)[varNumerics] + + ## Drop variables that do not meet either because it is unsupported + varDrop <- setdiff(vars, c(varFactors, varNumerics)) + if (length(varDrop) > 0) { + warning("Dropping variable(s) ", paste0(varDrop, sep = " "), + " due to unsupported class.\n") + vars <- setdiff(vars, varDrop) + } + + ## Create a logical vector indicator for factors (vars in varFactors = TRUE) + logiFactors <- vars %in% varFactors + + ## Create lists of arguments + argsCreateContTable <- list(data = data, + test = test, + testNormal = testNormal, + argsNormal = argsNormal, + testNonNormal = testNonNormal, + argsNonNormal = argsNonNormal + ) + argsCreateCatTable <- list(data = data, + test = test, + testApprox = testApprox, + argsApprox = argsApprox, + testExact = testExact, + argsExact = argsExact + ) + ## Add strata = strata for argument only if strata is given + if (!missing(strata)) { + + ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. + ## Must not be place outside if (!missing(strata)) { }. + dfStrata <- ModuleReturnStrata(strata, data) + ## Return variable names. Code inefficient in exchange for code simplicity. + strata <- names(dfStrata) + + ## Create lists of arguments including strata + argsCreateContTable <- c(list(strata = strata), argsCreateContTable) + argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) + } + + + ## Condition on the absence of factor/numeric + if (length(varNumerics) == 0) { + ## No numerics + cat('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) + return(CatTable) + + } else if (length(varFactors) == 0) { + ## No factors + cat('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') + ContTable <- do.call(CreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + return(ContTable) + +### Proceed if both types of variables are present (both factors and numerics) + } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { + + ## Create a list of constructors + listOfConstructors <- list(CreateContTable = CreateContTable, + CreateCatTable = CreateCatTable) + ## CreateCatTable for categorical. CreateContTable for continuous. + listOfConstructors <- listOfConstructors[logiFactors + 1] + ## Create a list of arguments + listOfArgs <- list(argsCreateContTable = argsCreateContTable, + argsCreateCatTable = argsCreateCatTable) + ## argsCreateCatTable for categorical. argsCreateContTable for continuous. + listOfArgs <- listOfArgs[logiFactors + 1] + + ## Create a list of tables by looping over variables/constructors/arguments + TableOne <- sapply(seq_along(listOfConstructors), + FUN = function(i) { + + args <- c(list(vars = vars[i]), # vector element + listOfArgs[[i]]) # list element + + do.call(listOfConstructors[[i]], # list element + args = args) + }, + simplify = FALSE) + + ## Give variable names to the result object + names(TableOne) <- vars + + + ## Create ContTable and CatTable objects (this is redundant, but easy) + ## Aggregated ContTable + ContTable <- do.call(CreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + ## Aggregated CatTable + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) + + ## Create a list for output + TableOneObject <- list(TableOne = TableOne, + ContTable = ContTable, + CatTable = CatTable + ) + + ## Give a class + class(TableOneObject) <- "TableOne" + + ## Return the object + return(TableOneObject) + } + } From 4d60ef44ef8bfa511839db149899fe35b1668593 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 15:03:50 -0400 Subject: [PATCH 024/219] Fix indentation; change cat() to message() --- R/modules.R | 2 +- R/svyCreateTableOne.R | 38 +++++++++++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/R/modules.R b/R/modules.R index 0d4bce6..40b61f8 100644 --- a/R/modules.R +++ b/R/modules.R @@ -369,7 +369,7 @@ ModulePickAndFormatPValues <- function(TableObject, switchVec, pDigits) { ModuleReturnDimHeaders <- function(TableObject) { ## Add stratification information to the column header - if (length(TableObject) > 1 ) { + if (length(TableObject) > 1) { ## Create strata string strataString <- paste0("Stratified by ", paste0(names(attr(TableObject, "dimnames")), collapse = ":")) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 39c5bc8..a013408 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -1,4 +1,4 @@ -##' Create an object summarizing both categorical and continuous variables +##' Create an object summarizing any variables for weighted data ##' ##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. ##' @@ -83,22 +83,22 @@ ##' ##' @export CreateTableOne <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - factorVars, # variables to be transformed to factors - test = TRUE, # whether to put p-values - ## Test configuration for categorical data - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5), # arguments passed to testExact - ## Test configuration for continuous data - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + test = TRUE, # whether to put p-values + ## Test configuration for categorical data + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5), # arguments passed to testExact + ## Test configuration for continuous data + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ### Data check ## Check if the data given is a dataframe @@ -185,14 +185,14 @@ CreateTableOne <- ## Condition on the absence of factor/numeric if (length(varNumerics) == 0) { ## No numerics - cat('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') + message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') CatTable <- do.call(CreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) return(CatTable) } else if (length(varFactors) == 0) { ## No factors - cat('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') + message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') ContTable <- do.call(CreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) return(ContTable) From 1b4884c270d9b2eb2dcef8df1b9e73004d214df0 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 15:30:48 -0400 Subject: [PATCH 025/219] Create svyCatTable/svyContTable specific print methods as copies --- R/print.svyCatTable.R | 448 +++++++++++++++++++++++++++++++++++++++++ R/print.svyContTable.R | 318 +++++++++++++++++++++++++++++ 2 files changed, 766 insertions(+) create mode 100644 R/print.svyCatTable.R create mode 100644 R/print.svyContTable.R diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R new file mode 100644 index 0000000..4dba915 --- /dev/null +++ b/R/print.svyCatTable.R @@ -0,0 +1,448 @@ +##' Format and print the \code{CatTable} class objects +##' +##' This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +##' +##' @param x The result of a call to the \code{\link{CreateCatTable}} function. +##' @param digits Number of digits to print in the table. +##' @param pDigits Number of digits to print for p-values. +##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. +##' @param missing Whether to show missing data information (not implemented yet, placeholder) +##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown. +##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. +##' @param noSpaces Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. +##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency). +##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. +##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. +##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test). +##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. +##' @param ... For compatibility with generic. Ignored. +##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @author Kazuki Yoshida +##' @seealso +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for categorical variables +##' catVars <- c("status","ascites","hepato","spiders","edema","stage") +##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.CatTable method, +##' ## which will show the sample size, frequencies and percentages. +##' ## For 2-level variables, only the higher level is shown for simplicity. +##' catTableOverall +##' +##' ## If you need to show both levels for some 2-level factors, use cramVars +##' print(catTableOverall, cramVars = "hepato") +##' +##' ## Use the showAllLevels argument to see all levels for all variables. +##' print(catTableOverall, showAllLevels = TRUE) +##' +##' ## You can choose form frequencies ("f") and/or percentages ("p") or both. +##' ## "fp" frequency (percentage) is the default. Row names change accordingly. +##' print(catTableOverall, format = "f") +##' print(catTableOverall, format = "p") +##' +##' ## To further examine the variables, use the summary.CatTable method, +##' ## which will show more details. +##' summary(catTableOverall) +##' +##' ## The table can be stratified by one or more variables +##' catTableBySexTrt <- CreateCatTable(vars = catVars, +##' strata = c("sex","trt"), data = pbc) +##' +##' ## print now includes p-values which are by default calculated by chisq.test. +##' ## It is formatted at the decimal place specified by the pDigits argument +##' ## (3 by default). It does <0.001 for you. +##' catTableBySexTrt +##' +##' ## The exact argument toggles the p-values to the exact test result from +##' ## fisher.test. It will show which ones are from exact tests. +##' print(catTableBySexTrt, exact = "ascites") +##' +##' ## summary now includes both types of p-values +##' summary(catTableBySexTrt) +##' +##' ## If your work flow includes copying to Excel and Word when writing manuscripts, +##' ## you may benefit from the quote argument. This will quote everything so that +##' ## Excel does not mess up the cells. +##' print(catTableBySexTrt, exact = "ascites", quote = TRUE) +##' +##' ## If you want to center-align values in Word, use noSpaces option. +##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +##' +##' @export +print.svyCatTable <- function(x, # CatTable object + digits = 1, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes + + missing = FALSE, # Show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments + + format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent + showAllLevels = FALSE, + cramVars = NULL, # variables to be crammed into one row + + test = TRUE, # Whether to add p-values + exact = NULL, # Which variables should be tested with exact tests + + CrossTable = FALSE, # Whether to show gmodels::CrossTable + + ...) { + + ## x and ... required to be consistent with generic print(x, ...) + CatTable <- x + +### Check the data structure first + + ## CatTable has a strata(list)-variable(list)-table(dataframe) structure + ## Get the position of the non-null element + logiNonNullElement <- !sapply(CatTable, is.null) + ## Stop if all elements are null. + if (sum(logiNonNullElement) == 0) {stop("All strata are null strata. Check data.")} + ## Get the first non-null position + posFirstNonNullElement <- which(logiNonNullElement)[1] + ## Save variable names using the first non-null element + varNames <- names(CatTable[[posFirstNonNullElement]]) + ## Check the number of variables (list length) + nVars <- length(varNames) + + + ## Returns a numeric vector: 1 for approx test variable; 2 for exact test variable + exact <- ModuleHandleDefaultOrAlternative(switchVec = exact, + nameOfSwitchVec = "exact", + varNames = varNames) + + + ## Check format argument. If it is broken, choose "fp" for frequency (percent) + if (!length(format) == 1 | !format %in% c("fp","f","p","pf")) { + warning("format only accepts one of fp, f, p, or pf. Choosing fp.") + format <- "fp" + } + + ## Obtain the strata sizes in a character vector. This has to be obtained from the original data + ## Added as the top row later + strataN <- sapply(CatTable, + FUN = function(stratum) { # loop over strata + ## each stratum is a list of one data frame for each variable + ## Obtain n from all variables and all levels (list of data frames) + n <- unlist(sapply(stratum, getElement, "n")) + ## Pick the first non-null element + n[!is.null(n)][1] + ## Convert NULL to 0 + ifelse(is.null(n), "0", as.character(n)) + }, + simplify = TRUE) # vector with as many elements as strata + + ## Provide indicators to show what columns were added. + wasLevelColumnAdded <- FALSE + wasPValueColumnAdded <- FALSE + wasExactColumnAdded <- FALSE + + +### Formatting for printing + + ## Create format for percent used in the loop + fmt1 <- paste0("%.", digits, "f") + + ## Obtain collpased result + CatTableCollapsed <- + sapply(X = CatTable, # Loop over strata + FUN = function(LIST) { + + ## Do the following formatting only if the stratum is non-null. Do nothing if null. + if (!is.null(LIST)) { + + ## Returns an empty list if the stratum is null (empty). + LIST <- + sapply(X = seq_along(LIST), # Loop over variables (list element is DF) + FUN = function(i) { + + ## Extract the data frame (list element) + DF <- LIST[[i]] + + ## Extract the variable name + varName <- names(LIST)[i] + + ## Check number of rows (levels) + nRow <- nrow(DF) + + ## Add a variable name to the left as a character vector + DF <- cbind(var = rep(varName, nRow), + DF) + + ## Format percent and cum.percent as strings + DF[c("p.miss","percent","cum.percent")] <- + lapply(X = DF[c("p.miss","percent","cum.percent")], + FUN = sprintf, + fmt = fmt1) + + + ## Make all variables strings (freq is an integer, so direct convert ok) + DF[] <- lapply(X = DF, FUN = as.character) + + ## Add first row indicator column + DF$firstRowInd <- "" + ## Add crammed row indicator column + DF$crammedRowInd <- "" + + ## Format based on the number of levels + if (!showAllLevels & nRow == 1) { + ## If showAllLevels is FALSE AND there are only ONE levels, + ## change variable name to "var = level" + DF$var <- with(DF, paste0(var, " = ", level)) + + } else if (!showAllLevels & nRow == 2) { + ## If showAllLevels is FALSE AND there are only TWO levels, + ## cram two levels in one row if requested + if (unique(DF$var) %in% cramVars) { + ## If cramVars includes var, cram into one line + ## Cram two freq and count with / in between + DF$freq <- paste0(DF$freq, collapse = "/") + DF$percent <- paste0(DF$percent, collapse = "/") + ## change variable name, and delete the first level. + DF$var <- paste0(DF$var, " = ", + paste0(DF$level, collapse = "/")) + ## Delete the first row + DF <- DF[-1, , drop = FALSE] + ## Add crammed row indicator (used for formatting) + DF[1,"crammedRowInd"] <- "crammed" + } else { + ## Otherwise, keep the second level only + ## change variable name, and delete the first level. + DF$var <- with(DF, paste0(var, " = ", level)) + DF <- DF[-1, , drop = FALSE] + } + + } else if (!showAllLevels & nRow > 2) { + ## If showAllLevels is FALSE AND there are MORE THAN two levels, + ## add an empty row and put the var name, then levels below. + DF <- rbind(rep("", ncol(DF)), + DF) + ## Add variable name in the first row + DF[1,"var"] <- DF[2,"var"] + + ## 2nd to last have level names. (nrow has changed by +1) + secondToLastRows <- seq(from = 2,to = nrow(DF), by = 1) + DF[secondToLastRows, "var"] <- + paste0(" ", DF[secondToLastRows, "level"]) # preceding spaces + + } else if (showAllLevels) { + ## If showAllLevels is TRUE, clear these except in 1st row + DF[-1, c("var","n","miss","p.miss")] <- "" + } + + ## Add first row indicator (used to add (%)) + DF[1,"firstRowInd"] <- "first" + + ## Return a data frame + DF + }, + simplify = FALSE) # Looped over variables (list element is DF) + + + ## Collapse DFs within each stratum + DF <- do.call(rbind, LIST) + + ## Justification should happen here after combining variable DFs into a stratum DF. + ## Check non-empty rows + posNonEmptyRows <- DF$freq != "" + + + ## Create freq to be added on to the right side within () + DF$freqAddOn <- DF$freq + ## Right justify frequency (crammed and non-crammed at once) + DF$freq <- format(DF$freq, justify = "right") + ## Right justify frequency (non-crammed only) + DF[DF$crammedRowInd == "","freqAddOn"] <- + format(DF[DF$crammedRowInd == "","freqAddOn"], justify = "right") + ## Obtain the max width of characters + nCharFreq <- max(nchar(DF$freq)) + + + ## Create percent to be added on to the right side within () + DF$percentAddOn <- DF$percent + ## Right justify percent (crammed and non-crammed at once) + DF$percent <- format(DF$percent, justify = "right") + ## Right justify percent (non-crammed only) + DF[DF$crammedRowInd == "","percentAddOn"] <- + format(DF[DF$crammedRowInd == "","percentAddOn"], justify = "right") + ## Obtain the max width of characters + nCharPercent <- max(nchar(DF$percent)) + + + ## Add freq (percent) column (only in non-empty rows) + DF$freqPer <- "" + DF[posNonEmptyRows,]$freqPer <- sprintf(fmt = "%s (%s) ", + DF[posNonEmptyRows,]$freq, + DF[posNonEmptyRows,]$percentAddOn) + + ## Add percent (freq) column (only in non-empty rows) + DF$perFreq <- "" + DF[posNonEmptyRows,]$perFreq <- sprintf(fmt = "%s (%s) ", + DF[posNonEmptyRows,]$percent, + DF[posNonEmptyRows,]$freqAddOn) + + ## Add aditional attributes + attributes(DF) <- c(attributes(DF), + list(nCharFreq = nCharFreq, + nCharPercent = nCharPercent) + ) + + ## Return a data frame (2014-02-12 sapply breaks attributes?) + DF + } # end of non-null condition (Null strata skip all this. No action.) + + }, simplify = FALSE) + + +### Obtain the original column width in characters for alignment in print.TableOne + ## Name of the column to keep + widthCol <- c("nCharFreq","nCharFreq","nCharPercent","nCharPercent")[format == c("fp","f","p","pf")] + vecColWidths <- sapply(CatTableCollapsed, + FUN = function(LIST) { + + ## Get the width of the column (freq or percent, whichever comes left) + out <- attributes(LIST)[widthCol] + ## Return NA if null + if (is.null(out)) { + return(NA) + } else { + return(as.numeric(out)) + } + }, + simplify = TRUE) + + + ## Fill the null element using the first non-null element's dimension (Make sure to erase data) + CatTableCollapsed[!logiNonNullElement] <- CatTableCollapsed[posFirstNonNullElement] + ## Access the filled-in data frames, and erase them with place holders. + for (i in which(!logiNonNullElement)) { + ## Replace all elements with a place holder variable by variable + CatTableCollapsed[[i]][] <- lapply(CatTableCollapsed[[i]][], + function(var) { + + var <- rep("-", length(var)) + }) + } + + ## Choose the column name for the right format + nameResCol <- c("freqPer","freq","percent","perFreq")[format == c("fp","f","p","pf")] + + + ## Create output matrix without variable names with the right format + out <- do.call(cbind, lapply(CatTableCollapsed, getElement, nameResCol)) + out <- as.matrix(out) + + ## Add column names if multivariable stratification is used. (No column names added automatically) + if (length(attr(CatTable, "dimnames")) > 1) { + + colnames(out) <- ModuleCreateStrataNames(CatTable) + } + + + ## Set the variables names + rownames(out) <- CatTableCollapsed[[posFirstNonNullElement]][,"var"] + ## Get positions of rows with variable names + logiNonEmptyRowNames <- CatTableCollapsed[[posFirstNonNullElement]][, "firstRowInd"] != "" + + + + ## Add level names if showAllLevels is TRUE. This adds the level column. Need come after column naming. + if (showAllLevels) { + out <- cbind(level = CatTableCollapsed[[posFirstNonNullElement]][,"level"], # Cannot be DF + out) + ## Changed the indicator + wasLevelColumnAdded <- TRUE + } + + + ## Add p-values when requested and available + if (test == TRUE & !is.null(attr(CatTable, "pValues"))) { + + ## Pick test types used (used for annonation) + testTypes <- c("","exact")[exact] + + ## Pick the p-values requested, and format like <0.001 + pVec <- ModulePickAndFormatPValues(TableObject = CatTable, + switchVec = exact, + pDigits = pDigits) + + ## Create an empty p-value column and test column + out <- cbind(out, + p = rep("", nrow(out))) # Column for p-values + ## Put the values at the non-empty positions + out[logiNonEmptyRowNames,"p"] <- pVec + + ## Change the indicator + wasPValueColumnAdded <- TRUE + + + ## Create an empty test type column, and add test types + out <- cbind(out, + test = rep("", nrow(out))) # Column for test types + ## Put the test types at the non-empty positions (all rows in continuous!) + out[logiNonEmptyRowNames,"test"] <- testTypes + + ## Change the indicator + wasExactColumnAdded <- TRUE + } + + + ## Add freq () explanation if requested + if (explain) { + ## Choose the format of the explanation string + explainString <- c(" (%)", "", " (%)", " % (freq)")[format == c("fp","f","p","pf")] + ## Only for rows with row names + rownames(out)[logiNonEmptyRowNames] <- paste0(rownames(out)[logiNonEmptyRowNames], + explainString) + } + + ## Keep column names (strataN does not have correct names if stratification is by multiple variables) + outColNames <- colnames(out) + ## Add n at the correct location depending on the number of columns added (level and/or p) + out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added + strataN, + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasExactColumnAdded) # Add "" padding if exact test used + ), + out) + ## Put back the column names (overkill for non-multivariable cases) + colnames(out) <- outColNames + + ## Add stratification information to the column header depending on the dimension + names(dimnames(out)) <- ModuleReturnDimHeaders(CatTable) + + ## Remove spaces if asked. + out <- ModuleRemoveSpaces(mat = out, noSpaces = noSpaces) + + ## Modular version of quote/print toggle. + out <- ModuleQuoteAndPrintMat(matObj = out, + quote = quote, printToggle = printToggle) + + ## Print CrossTable() if requested + if (CrossTable) { + + junk <- lapply(attributes(CatTable)$xtabs, gmodels::CrossTable) + } + + ## Add attributes for column widths in characters + attributes(out) <- c(attributes(out), + list(vecColWidths = vecColWidths)) + + ## return a matrix invisibly + return(invisible(out)) +} diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R new file mode 100644 index 0000000..7ba5358 --- /dev/null +++ b/R/print.svyContTable.R @@ -0,0 +1,318 @@ +##' Format and print the \code{ContTable} class objects +##' +##' This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +##' +##' @param x The result of a call to the \code{\link{CreateContTable}} function. +##' @param digits Number of digits to print in the table. +##' @param pDigits Number of digits to print for p-values. +##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. +##' @param missing Whether to show missing data information (not implemented yet, placeholder) +##' @param explain Whether to add explanation to the variable names, i.e., (mean (sd) or median [IQR]) is added to the variable names. +##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. +##' @param noSpaces Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. +##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test). +##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. +##' @param insertLevel Whether to add an empty level column to the left of strata. +##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param ... For compatibility with generic. Ignored. +##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @author Kazuki Yoshida +##' @seealso +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for continuous variables +##' contVars <- c("time","age","bili","chol","albumin","copper", +##' "alk.phos","ast","trig","platelet","protime") +##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.ContTable method, +##' ## which will show the sample size, means and standard deviations. +##' contTableOverall +##' +##' ## To further examine the variables, use the summary.ContTable method, +##' ## which will show more details. +##' summary(contTableOverall) +##' +##' ## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. +##' ## Specify them in the nonnormal argument, and the display changes to the median, +##' ## and the [25th, 75th] percentile. +##' nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") +##' print(contTableOverall, nonnormal = nonNormalVars) +##' +##' ## To show median [min,max] for nonnormal variables, use minMax = TRUE +##' print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) +##' +##' ## The table can be stratified by one or more variables +##' contTableBySexTrt <- CreateContTable(vars = contVars, +##' strata = c("sex","trt"), data = pbc) +##' +##' ## print now includes p-values which are by default calculated by oneway.test (t-test +##' ## equivalent in the two group case). It is formatted at the decimal place specified +##' ## by the pDigits argument (3 by default). It does <0.001 for you. +##' contTableBySexTrt +##' +##' ## The nonnormal argument toggles the p-values to the nonparametric result from +##' ## kruskal.test (wilcox.test equivalent for the two group case). +##' print(contTableBySexTrt, nonnormal = nonNormalVars) +##' +##' ## The minMax argument toggles whether to show median [range] +##' print(contTableBySexTrt, nonnormal = nonNormalVars, minMax = TRUE) +##' +##' ## summary now includes both types of p-values +##' summary(contTableBySexTrt) +##' +##' ## If your work flow includes copying to Excel and Word when writing manuscripts, +##' ## you may benefit from the quote argument. This will quote everything so that +##' ## Excel does not mess up the cells. +##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) +##' +##' ## If you want to center-align values in Word, use noSpaces option. +##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +##' +##' @export +print.svyContTable <- function(x, # ContTable object + digits = 2, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes + + missing = FALSE, # show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments + + nonnormal = NULL, # Which variables should be treated as nonnormal + minMax = FALSE, # median [range] instead of median [IQR] + insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable + + test = TRUE, # Whether to add p-values + + ...) { + + ## x and ... required to be consistent with generic print(x, ...) + ContTable <- x + +### Check data structure first + + ## ContTable is by() object + ## Get the position of the first non-null element + posFirstNonNullElement <- which(!sapply(ContTable, is.null))[1] + ## Save variable names using the first non-null element + varNames <- rownames(ContTable[[posFirstNonNullElement]]) + ## Check the number of variables + nVars <- length(varNames) + + + ## Returns a numeric vector: 1 for normal variable; 2 for nonnormal variable + nonnormal <- ModuleHandleDefaultOrAlternative(switchVec = nonnormal, + nameOfSwitchVec = "nonnormal", + varNames = varNames) + + + ## Check the statistics. If necessary statistics are lacking abort + statNames <- colnames(ContTable[[posFirstNonNullElement]]) + funcDefault <- c("n","miss","mean","sd","median","p25","p75") + if (any(!funcDefault %in% statNames)) { + + ## summary(ContTable) + stop("The object does not contain all necessary statistics. Use summary() method.") + } + + + ## Obtain the strata sizes in a character vector. This has to be obtained from the original data + ## Added as the top row later + strataN <- sapply(ContTable, + FUN = function(stratum) { # loop over strata + ## each strutum is a data frame with one row for each variable + ## Obtain n from all variables (matrix) + n <- stratum[,"n"] + ## Pick the first non-null element + n[!is.null(n)][1] + ## Convert NULL to 0 + ifelse(is.null(n), "0", as.character(n)) + }, + simplify = TRUE) # vector with as many elements as strata + + ## Provide indicators to show what columns were added. + wasPValueColumnAdded <- FALSE + wasNonNormalColumnAdded <- FALSE + + +### Conversion of data for printing + + ## Define the nonnormal formatter depending on the minMax status + ConvertNormal <- function(rowMat) { + ## Take minMax value from outside (NOT A STANDALONE FUNCTION!!) + ModuleConvertNormal(rowMat, digits) + } + ## Define the nonnormal formatter depending on the minMax status + ConvertNonNormal <- function(rowMat) { + ## Take minMax value from outside (NOT A STANDALONE FUNCTION!!) + ModuleConvertNonNormal(rowMat, digits, minMax = minMax) + } + + ## Create a list of these two functions + listOfFunctions <- list(normal = ConvertNormal, nonnormal = ConvertNonNormal) + + ## Take functions from the 2-element list, and convert to an nVars-length list + listOfFunctions <- listOfFunctions[nonnormal] + + ## Loop over strata (There may be just one) + out <- sapply(ContTable, + FUN = function(stratum) { + + ## In an empty stratum, return empty + if (is.null(stratum)) { + out <- rep("-", nVars) + ## Give NA to the width of the mean/median column in characters + nCharMeanOrMedian <- NA + } else { + + ## Apply row by row within each non-empty stratum + ## This row-by-row operation is necessary to handle mean (sd) and median [IQR] + out <- sapply(seq_len(nVars), + FUN = function(i) { + + ## Choose between normal or nonnormal function + fun <- listOfFunctions[[i]] + ## Convert a row matrix to 1x2 df (numeric, character) + fun(stratum[i, , drop = FALSE]) + + ## Create a 1-row DF (numeric, character) + }, + simplify = FALSE) + + ## nx2 data frame by row binding multiple 1-row data frames + out <- do.call(rbind, out) + + ## Format for decimals + out$col1 <- sprintf(fmt = paste0("%.", digits, "f"), out$col1) + + ## right justify by adding spaces (to align at the decimal point of mean/median) + out$col1 <- format(out$col1, justify = "right") + + ## Obtain the width of the mean/median column in characters + nCharMeanOrMedian <- nchar(out$col1[1]) + + ## Create mean (SD) or median [p25, p75] as a character vector + out <- do.call(paste0, out) + } + + ## Add attributes + attributes(out) <- c(attributes(out), + list(nCharMeanOrMedian = nCharMeanOrMedian)) + + ## Return + out + }, + simplify = FALSE) + +### Obtain the original column width in characters for alignment in print.TableOne + vecColWidths <- sapply(out, + FUN = function(LIST) { + + ## Get the width of the column + attributes(LIST)$nCharMeanOrMedian + }, + simplify = TRUE) + + + ## The outer sapply should not simplify to avoid a vector + ## Column-bind to create variables x strata matrix + out <- do.call(cbind, out) + + ## Put the variables names back (looping over rows can solve this) + rownames(out) <- varNames + + ## Add column names if multivariable stratification is used. + if (length(attr(ContTable, "dimnames")) > 1) { + + colnames(out) <- ModuleCreateStrataNames(ContTable) + } + + + ## Add p-values when requested and available + if (test == TRUE & !is.null(attr(ContTable, "pValues"))) { + + ## Pick test types used (used for annonation) + testTypes <- c("","nonnorm")[nonnormal] + + ## Pick the p-values requested, and format like <0.001 + pVec <- ModulePickAndFormatPValues(TableObject = ContTable, + switchVec = nonnormal, + pDigits = pDigits) + + ## Column combine with the output + out <- cbind(out, p = pVec) + + ## Change the indicator + wasPValueColumnAdded <- TRUE + + + ## Create an empty test type column, and add test types + out <- cbind(out, + test = rep("", nrow(out))) # Column for test types + ## Put the test types at the non-empty positions (all rows in continuous!) + out[ ,"test"] <- testTypes + + ## Change the indicator + wasNonNormalColumnAdded <- TRUE + } + + + ## Add mean (sd) or median [IQR]/median [range] explanation if requested + if (explain) { + ## Create a vector of explanations to be pasted + if (minMax == FALSE) { + what <- c(" (mean (sd))"," (median [IQR])")[nonnormal] + } else if (minMax == TRUE) { + what <- c(" (mean (sd))"," (median [range])")[nonnormal] + } + ## Paste to the rownames + rownames(out) <- paste0(rownames(out), what) + } + + ## Keep column names (strataN does not have correct names if stratification is by multiple variables) + outColNames <- colnames(out) + ## Add n at the correct location depending on the number of columns added (level and/or p) + out <- rbind(n = c(strataN, + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used + ), + out) + ## Put back the column names (overkill for non-multivariable cases) + colnames(out) <- outColNames + + ## Add the level column if requested + if (insertLevel) { + out <- cbind(level = rep("", nrow(out)), + out) + } + + ## Add stratification information to the column header depending on the dimension + names(dimnames(out)) <- ModuleReturnDimHeaders(ContTable) + + ## Remove spaces if asked. + out <- ModuleRemoveSpaces(mat = out, noSpaces = noSpaces) + + ## (module) Takes an matrix object format, print if requested + out <- ModuleQuoteAndPrintMat(matObj = out, + quote = quote, printToggle = printToggle) + + ## Add attributes for column widths in characters + attributes(out) <- c(attributes(out), + list(vecColWidths = vecColWidths)) + + ## return a matrix invisibly + return(invisible(out)) +} From 8f76b34ac5eca3139b18962bbfb97b856d2676cd Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 15:40:59 -0400 Subject: [PATCH 026/219] Add decimal formatting for sample size in for printing ContTable --- R/print.svyContTable.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 7ba5358..1d6f99c 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -139,7 +139,9 @@ print.svyContTable <- function(x, # ContTable object ## Pick the first non-null element n[!is.null(n)][1] ## Convert NULL to 0 - ifelse(is.null(n), "0", as.character(n)) + ifelse(is.null(n), + "0", + sprintf(fmt = paste0("%.", digits, "f"), n)) }, simplify = TRUE) # vector with as many elements as strata From 6ccea7bb4a55c5182b375c1e9f39d6e36fb88de6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:15:41 -0400 Subject: [PATCH 027/219] Add correct strataVarName handling to svy print methods --- R/print.svyCatTable.R | 3 ++- R/print.svyContTable.R | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 4dba915..d828a81 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -424,7 +424,8 @@ print.svyCatTable <- function(x, # CatTable object colnames(out) <- outColNames ## Add stratification information to the column header depending on the dimension - names(dimnames(out)) <- ModuleReturnDimHeaders(CatTable) + names(dimnames(out)) <- c("", paste0("Stratified by ", + attr(CatTable, "strataVarName"))) ## Remove spaces if asked. out <- ModuleRemoveSpaces(mat = out, noSpaces = noSpaces) diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 1d6f99c..97bc985 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -302,7 +302,8 @@ print.svyContTable <- function(x, # ContTable object } ## Add stratification information to the column header depending on the dimension - names(dimnames(out)) <- ModuleReturnDimHeaders(ContTable) + names(dimnames(out)) <- c("", paste0("Stratified by ", + attr(ContTable, "strataVarName"))) ## Remove spaces if asked. out <- ModuleRemoveSpaces(mat = out, noSpaces = noSpaces) From 37d86347dcfb00869e0804e4b8a33ea3096f1a15 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:15:54 -0400 Subject: [PATCH 028/219] Start svy summary methods as copies --- R/summary.svyCatTable.R | 109 +++++++++++++++++++++++++++++++++++++++ R/summary.svyContTable.R | 49 ++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 R/summary.svyCatTable.R create mode 100644 R/summary.svyContTable.R diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R new file mode 100644 index 0000000..85f91a3 --- /dev/null +++ b/R/summary.svyCatTable.R @@ -0,0 +1,109 @@ +##' Shows all results in a \code{CatTable} class object +##' +##' This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +##' +##' @param object An object that has the \code{CatTable} class to be shown. +##' @param digits Number of digits to print. +##' @param ... For compatibility with generic. Ignored. +##' @return It will print the results. +##' @author Kazuki Yoshida +##' @seealso +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for categorical variables +##' catVars <- c("status","ascites","hepato","spiders","edema","stage") +##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.CatTable method, +##' ## which will show the sample size, frequencies and percentages. +##' ## For 2-level variables, only the higher level is shown for simplicity. +##' catTableOverall +##' +##' ## To further examine the variables, use the summary.CatTable method, +##' ## which will show more details. +##' summary(catTableOverall) +##' +##' @export +summary.svyCatTable <- function(object, digits = 1, ...) { + + ## object and ... required to be consistent with generic summary(object, ...) + CatTable <- object + + ## Create format + fmt <- paste0("%.", digits, "f") + + ## Obtain collpased result within each stratum + CatTableCollapsed <- + sapply(X = CatTable, # Loop over strata + FUN = function(LIST) { + + LIST <- sapply(X = seq_along(LIST), # Loop over variables + FUN = function(i) { + + ## Extract the data frame + DF <- LIST[[i]] + + ## Extract the variable name + varName <- names(LIST)[i] + + ## Check number of rows (levels) + nRow <- nrow(DF) + + ## Add a variable name to the left as a character vector + DF <- cbind(var = rep(varName, nRow), + DF) + + ## Format percent and cum.percent + DF[c("p.miss","percent","cum.percent")] <- + lapply(X = DF[c("p.miss","percent","cum.percent")], + FUN = sprintf, + fmt = fmt) + + ## Make var and level a string + DF[c("var","level")] <- + lapply(X = DF[c("var","level")], + FUN = as.character) + + ## Delete n and miss except in the first row + DF[-1, c("var","n","miss","p.miss")] <- "" + + ## row bind an empty row + DF <- rbind(DF, + rep("", ncol(DF))) + + ## Return a data frame + DF + }, + simplify = FALSE) + + ## Collapse DFs within each stratum + DF <- do.call(rbind, LIST) + + ## Return a data frame + DF + }, simplify = FALSE) + + ## Restore the dimnames through attributes() + attributes(CatTableCollapsed) <- c(attributes(CatTableCollapsed), attributes(CatTable)) + + ## Print forcing the print.by method. Do not show row names. + print.by(CatTableCollapsed, digits = digits, row.names = FALSE) + + ## Print p-values if it exist + if (!is.null(attributes(CatTable)$pValues)) { + cat("\np-values\n") + print(attributes(CatTable)$pValues) + } +} diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R new file mode 100644 index 0000000..6a5644e --- /dev/null +++ b/R/summary.svyContTable.R @@ -0,0 +1,49 @@ +##' Shows all results in a \code{ContTable} class object +##' +##' This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +##' +##' @param object An object that has the \code{ContTable} class to be shown. +##' @param digits Number of digits to print. +##' @param ... For compatibility with generic. Ignored. +##' @return It will print the results. +##' @author Kazuki Yoshida +##' @seealso +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' @examples +##' +##' ## Load +##' library(tableone) +##' +##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data +##' library(survival) +##' data(pbc) +##' ## Check variables +##' head(pbc) +##' +##' ## Create an overall table for continuous variables +##' contVars <- c("time","age","bili","chol","albumin","copper", +##' "alk.phos","ast","trig","platelet","protime") +##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) +##' +##' ## Simply typing the object name will invoke the print.ContTable method, +##' ## which will show the sample size, means and standard deviations. +##' contTableOverall +##' +##' ## To further examine the variables, use the summary.ContTable method, +##' ## which will show more details. +##' summary(contTableOverall) +##' +##' @export +summary.svyContTable <- function(object, digits = 2, ...) { + + ## Just call print.by + print.by(object, digits = digits) + + ## Print p-values if it exist + if (!is.null(attributes(object)$pValues)) { + cat("\np-values\n") + print(attributes(object)$pValues) + } +} From daa4aabc3c8a413e1dc242a31bc9d15669c5f8fa Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:15:59 -0400 Subject: [PATCH 029/219] Make summary method for ContTable just print as list --- R/summary.svyContTable.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 6a5644e..1e4927b 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -38,8 +38,11 @@ ##' @export summary.svyContTable <- function(object, digits = 2, ...) { - ## Just call print.by - print.by(object, digits = digits) + ## Force class list + class(object) <- "list" + + ## Just print as a list + print(object, digits = digits) ## Print p-values if it exist if (!is.null(attributes(object)$pValues)) { From 1592f3042621b1525e20ce5164d1fc815b62fb27 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:24:01 -0400 Subject: [PATCH 030/219] Format numbers reasonably for survey categorical methods --- R/print.svyCatTable.R | 12 +++++++----- R/summary.svyCatTable.R | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index d828a81..dc929eb 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -143,7 +143,9 @@ print.svyCatTable <- function(x, # CatTable object ## Pick the first non-null element n[!is.null(n)][1] ## Convert NULL to 0 - ifelse(is.null(n), "0", as.character(n)) + ifelse(is.null(n), + "0", + sprintf(fmt = paste0("%.", digits, "f"), n)) }, simplify = TRUE) # vector with as many elements as strata @@ -157,6 +159,7 @@ print.svyCatTable <- function(x, # CatTable object ## Create format for percent used in the loop fmt1 <- paste0("%.", digits, "f") + varsNumeric <- c("n","miss","p.miss","freq","percent","cum.percent") ## Obtain collpased result CatTableCollapsed <- @@ -185,10 +188,9 @@ print.svyCatTable <- function(x, # CatTable object DF) ## Format percent and cum.percent as strings - DF[c("p.miss","percent","cum.percent")] <- - lapply(X = DF[c("p.miss","percent","cum.percent")], - FUN = sprintf, - fmt = fmt1) + DF[varsNumeric] <- lapply(X = DF[varsNumeric], + FUN = sprintf, + fmt = fmt1) ## Make all variables strings (freq is an integer, so direct convert ok) diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index 85f91a3..a007a05 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -43,6 +43,7 @@ summary.svyCatTable <- function(object, digits = 1, ...) { ## Create format fmt <- paste0("%.", digits, "f") + varsNumeric <- c("n","miss","p.miss","freq","percent","cum.percent") ## Obtain collpased result within each stratum CatTableCollapsed <- @@ -66,10 +67,9 @@ summary.svyCatTable <- function(object, digits = 1, ...) { DF) ## Format percent and cum.percent - DF[c("p.miss","percent","cum.percent")] <- - lapply(X = DF[c("p.miss","percent","cum.percent")], - FUN = sprintf, - fmt = fmt) + DF[varsNumeric] <- lapply(X = DF[varsNumeric], + FUN = sprintf, + fmt = fmt) ## Make var and level a string DF[c("var","level")] <- From bcaa5b28e8acab60e496e071f7e33bfde24e5bf3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:45:04 -0400 Subject: [PATCH 031/219] Make survey summary force object array structure and use print.by() --- R/summary.svyCatTable.R | 6 ++++-- R/summary.svyContTable.R | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index a007a05..aa700c6 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -95,8 +95,10 @@ summary.svyCatTable <- function(object, digits = 1, ...) { DF }, simplify = FALSE) - ## Restore the dimnames through attributes() - attributes(CatTableCollapsed) <- c(attributes(CatTableCollapsed), attributes(CatTable)) + ## Change to an array to use print.by() + CatTableCollapsed <- as.array(CatTableCollapsed) + ## Force dimname label as the strataVarName + names(dimnames(CatTableCollapsed)) <- attr(CatTable, "strataVarName") ## Print forcing the print.by method. Do not show row names. print.by(CatTableCollapsed, digits = digits, row.names = FALSE) diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 1e4927b..9067d64 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -38,11 +38,15 @@ ##' @export summary.svyContTable <- function(object, digits = 2, ...) { - ## Force class list - class(object) <- "list" + ## Save the initial object + ContTable <- object + + ## Force an 1-dimensional array + object <- as.array(object) + names(dimnames(object)) <- attr(ContTable, "strataVarName") ## Just print as a list - print(object, digits = digits) + print.by(object, digits = digits) ## Print p-values if it exist if (!is.null(attributes(object)$pValues)) { From 3c30153663f6606c4191fae7382ead183dc7c415 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 16:46:53 -0400 Subject: [PATCH 032/219] Bump version; import survey --- DESCRIPTION | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 42fd1fa..b59984b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: tableone Type: Package Title: Create "Table 1" to Describe Baseline Characteristics -Version: 0.6.3 -Date: 2014-12-28 +Version: 0.7.0 +Date: 2015-07-24 Author: Kazuki Yoshida, Justin Bohn. Maintainer: Kazuki Yoshida Description: tableone creates "Table 1", i.e., description of baseline @@ -14,6 +14,7 @@ Description: tableone creates "Table 1", i.e., description of baseline or Java, and intended for command-line users. License: GPL-2 Imports: + survey, e1071, gmodels Suggests: From 36a6f330f0f5417fb43136066452e479cd45700c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 17:11:56 -0400 Subject: [PATCH 033/219] Fix erroneous double sqrt for svySd; also handle variable number correct svyvar: returns a vcov if given 2+ variables -> take diagnonal, and sqrt returns a single value if given 1 variable -> as.vector, and sqrt --- R/svyModules.R | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index 9e72876..f4f78fd 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -97,10 +97,21 @@ svySd <- function(vars, design) { ## Remove missingness and var ## Bad behavior, but consistent with the unweighted version res <- svyvar(x = as.formula(form), design = design, na.rm = TRUE) - ## Diagnonal elements are variances - out <- sqrt(diag(res)) + + + ## Diagnonal elements are variances given 2+ variables + if (length(vars) == 1) { + + out <- as.vector(sqrt(res)) + + } else if (length(vars) > 1) { + + ## Matrix if vars is of length 2+ + out <- sqrt(diag(res)) + } + names(out) <- vars - sqrt(out) + out } From 3184f46d7e53cadded0ee9dd8dede3f8a9f291b1 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 18:45:39 -0400 Subject: [PATCH 034/219] Add unit testing file for svyModules --- tests/testthat/test-svyModules.R | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/testthat/test-svyModules.R diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R new file mode 100644 index 0000000..029a3e3 --- /dev/null +++ b/tests/testthat/test-svyModules.R @@ -0,0 +1,57 @@ +################################################################################ +### Unit tests for the modules +## Reference: http://adv-r.had.co.nz/Testing.html +## Created on: 2015-07-24 +## Author: Kazuki Yoshida +################################################################################ + +### Structure +## expectations within tests within context + +### Prepare environment +################################################################################ +library(testthat) +library(tableone) + + +### Context (1 for each file) +################################################################################ +context("Unit tests for the survey-related modules") + + + +### Provide data +################################################################################ + + + +### Tests +################################################################################ +## A test should group together expectations for one functionality. + + +test_that("indicator functions work correctly", { + + ## one for counting + expect_equal(one(c(NA,NA,NA)), c(1,1,1)) + expect_equal(one(c(1,2,3)), c(1,1,1)) + + ## missing value indicator + expect_equal(miss(c(NA,NA,NA)), c(1,1,1)) + expect_equal(miss(c(1,2,3)), c(0,0,0)) + expect_equal(miss(c(1,NA,3)), c(0,1,0)) +}) + + +test_that("variable names are transformed to correct formula", { + + ## Expectations + expect_equal(FormulaString(c("a","b","c")), " ~ a + b + c") + expect_equal(FormulaString("a"), " ~ a") +}) + +test_that("survey functions for counting", { + + ## Expectations + expect_equal(NA, NA) +}) From 0dc1865ec88558a4bf2cbdd3172a8baf1ad23eac Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 19:06:11 -0400 Subject: [PATCH 035/219] Add data generation to module testing --- tests/testthat/test-svyModules.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R index 029a3e3..7313b36 100644 --- a/tests/testthat/test-svyModules.R +++ b/tests/testthat/test-svyModules.R @@ -23,6 +23,22 @@ context("Unit tests for the survey-related modules") ### Provide data ################################################################################ +## Three-group dataset with matching weight (Li & Greene 2013) +datMw <- structure(list(E = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, +2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), C = c(1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L), Y = c(0, 1, 0, 1, 0, 1, 0, 1, 0, +1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), C1 = c(0, 0, 0, +0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 +), C2 = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, +0, 1, 1, 0, 0, 1, 1), n = c(252L, 28L, 105L, 45L, 12L, 28L, 1L, +9L, 72L, 8L, 63L, 27L, 24L, 56L, 1L, 9L, 36L, 4L, 42L, 18L, 24L, +56L, 8L, 72L), Mw = c(0.1429, 0.1429, 0.4, 0.4, 1, 1, 1, 1, 0.5, +0.5, 0.6667, 0.6667, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.125, +0.125)), class = "data.frame", .Names = c("E", "C", "Y", "C1", +"C2", "n", "Mw"), row.names = c(NA, -24L)) + +datMw <- datMw[rep(seq_along(datMw$n), datMw$n),] ### Tests From 28174cb824d8810dc608cae6be45c877b30914da Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:02:45 -0400 Subject: [PATCH 036/219] Add tests for helper functions for survey data summary --- tests/testthat/test-svyModules.R | 209 ++++++++++++++++++++++++++++--- 1 file changed, 194 insertions(+), 15 deletions(-) diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R index 7313b36..ca27d67 100644 --- a/tests/testthat/test-svyModules.R +++ b/tests/testthat/test-svyModules.R @@ -12,6 +12,7 @@ ################################################################################ library(testthat) library(tableone) +library(survey) ### Context (1 for each file) @@ -24,21 +25,26 @@ context("Unit tests for the survey-related modules") ################################################################################ ## Three-group dataset with matching weight (Li & Greene 2013) -datMw <- structure(list(E = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, -2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), C = c(1L, -1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, -1L, 2L, 2L, 3L, 3L, 4L, 4L), Y = c(0, 1, 0, 1, 0, 1, 0, 1, 0, -1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), C1 = c(0, 0, 0, +datMw <- structure(list(E = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, +2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), C = c(1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L), Y = c(0, 1, 0, 1, 0, 1, 0, 1, 0, +1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), C1 = c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 -), C2 = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, -0, 1, 1, 0, 0, 1, 1), n = c(252L, 28L, 105L, 45L, 12L, 28L, 1L, -9L, 72L, 8L, 63L, 27L, 24L, 56L, 1L, 9L, 36L, 4L, 42L, 18L, 24L, -56L, 8L, 72L), Mw = c(0.1429, 0.1429, 0.4, 0.4, 1, 1, 1, 1, 0.5, -0.5, 0.6667, 0.6667, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.125, -0.125)), class = "data.frame", .Names = c("E", "C", "Y", "C1", +), C2 = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, +0, 1, 1, 0, 0, 1, 1), n = c(252L, 28L, 105L, 45L, 12L, 28L, 1L, +9L, 72L, 8L, 63L, 27L, 24L, 56L, 1L, 9L, 36L, 4L, 42L, 18L, 24L, +56L, 8L, 72L), Mw = c(0.1429, 0.1429, 0.4, 0.4, 1, 1, 1, 1, 0.5, +0.5, 0.6667, 0.6667, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.125, +0.125)), class = "data.frame", .Names = c("E", "C", "Y", "C1", "C2", "n", "Mw"), row.names = c(NA, -24L)) +## Create individual level data datMw <- datMw[rep(seq_along(datMw$n), datMw$n),] +## Introduce missingness +datMw[c(1,150), "Y"] <- NA +## Create a survey design object +datSvy <- svydesign(ids = ~ 1, data = datMw, weights = ~ Mw) ### Tests @@ -60,14 +66,187 @@ test_that("indicator functions work correctly", { test_that("variable names are transformed to correct formula", { - + ## Expectations expect_equal(FormulaString(c("a","b","c")), " ~ a + b + c") - expect_equal(FormulaString("a"), " ~ a") + expect_equal(FormulaString("a"), " ~ a") +}) + + +test_that("post-weighting dataset has 150 x 3 weighted subjects", { + + ## Expectations + expect_equal(as.integer(round(svyN(vars = "E", datSvy))), 450) + expect_equal(as.numeric(svyN(vars = "E", datSvy)), + as.numeric(svytotal( ~ one(E), datSvy))) + + expect_equal(as.integer(round(svyN(vars = "Y", datSvy))), 450) + expect_equal(as.numeric(svyN(vars = "Y", datSvy)), + as.numeric(svytotal( ~ one(Y), datSvy))) + + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 1)))), 150) + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 2)))), 150) + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 3)))), 150) + + expect_equal(as.numeric(svyN(vars = "E", subset(datSvy, E == 1))), + as.numeric(svytotal( ~ one(E), subset(datSvy, E == 1)))) + expect_equal(as.numeric(svyN(vars = "E", subset(datSvy, E == 2))), + as.numeric(svytotal( ~ one(E), subset(datSvy, E == 2)))) + expect_equal(as.numeric(svyN(vars = "E", subset(datSvy, E == 3))), + as.numeric(svytotal( ~ one(E), subset(datSvy, E == 3)))) + + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 1)))), 150) + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 2)))), 150) + expect_equal(as.integer(round(svyN(vars = "E", subset(datSvy, E == 3)))), 150) + + expect_equal(as.integer(round(svyN(vars = c("E","Y"), subset(datSvy, E == 3)))), c(150,150)) +}) + + +test_that("NA counting works", { + + ## Expectations + expect_true(svyMiss(vars = "E", datSvy) == 0) + ## Two observations with a weight of 0.1429 each + expect_true(svyMiss(vars = "Y", datSvy) == 0.2858) + ## Can work on multiple variables at a time + expect_true(all(svyMiss(vars = c("E","C1"), datSvy) == c(0, 0))) + expect_true(all(svyMiss(vars = c("E","C1","Y"), datSvy) == c(0, 0, 0.2858))) +}) + + +test_that("Means are correct", { + + ## Expectations + expect_equal(as.numeric(svyMean(vars = "E", datSvy)), + as.numeric(svymean( ~ E, datSvy))) + + ## NA's are always removed + expect_equal(as.numeric(svyMean(vars = "Y", datSvy)), + as.numeric(svymean( ~ Y, datSvy, na.rm = TRUE))) + + expect_equal(as.numeric(svyMean(vars = "Y", subset(datSvy, E == 1))), + as.numeric(svymean( ~ Y, subset(datSvy, E == 1), na.rm = TRUE))) +}) + + +test_that("SDs are correct", { + + ## Expectations + expect_equal(as.numeric(svySd(vars = "E", datSvy)), + as.numeric(sqrt(svyvar( ~ E, datSvy)))) + + ## NA's are always removed + expect_equal(as.numeric(svySd(vars = "Y", datSvy)), + as.numeric(sqrt(svyvar( ~ Y, datSvy, na.rm = TRUE)))) + + ## Take diagnoal of matrix for multiple variables + expect_equal(as.numeric(svySd(vars = c("C1","C2"), datSvy)), + as.numeric(sqrt(diag(svyvar( ~ C1 + C2, datSvy, na.rm = TRUE))))) +}) + + +test_that("Quantiles are correct", { + + ## Expectations + expect_equal(as.numeric(svyQuant(vars = "E", datSvy, q = 0.5)), + as.numeric(svyquantile( ~ E, datSvy, quantiles = 0.5))) + + expect_equal(as.numeric(svyQuant(vars = "E", datSvy, q = 1)), + as.numeric(svyquantile( ~ E, datSvy, quantiles = 1))) + + expect_equal(as.numeric(svyQuant(vars = "Y", datSvy, q = 0)), + as.numeric(svyquantile( ~ Y, datSvy, quantiles = 0, na.rm = TRUE))) + + ## Only first of q is used + expect_equal(as.numeric(svyQuant(vars = "E", datSvy, q = c(0.5, 0, 1))), + as.numeric(svyquantile( ~ E, datSvy, quantiles = 0.5))) +}) + + +test_that("Regression test for svyContSummary", { + + res1 <- structure(c(450.015, 450.015, 0, 0.2858, 0, 0.0635089941446396, + 2.00060881081326, 0.39357484459537, 0.816777838825025, 0.488786864487986, + 2, 0, 1, 0, 3, 1, 1, 0, 3, 1), .Dim = c(2L, 10L), .Dimnames = list( + c("E", "Y"), c("n", "miss", "p.miss", "mean", "sd", "median", + "p25", "p75", "min", "max"))) + expect_equal(svyContSummary(vars = c("E","Y"), datSvy), res1) +}) + + +test_that("table works", { + + ## Expectations + expect_true(all(svyTable("E", datSvy) == svytable( ~ E, datSvy))) + expect_true(all(svyTable("Y", datSvy) == svytable( ~ Y, datSvy))) +}) + + +test_that("Levels are obtained", { + + ## Expectations + expect_equal(svyLevel("E", datSvy), c("1","2","3")) + expect_equal(svyLevel("Y", datSvy), c("0","1")) }) -test_that("survey functions for counting", { + +test_that("Prop table works", { ## Expectations - expect_equal(NA, NA) + expect_equal(as.numeric(round(svyPropTable("E", datSvy), 3)), + round(c(1/3,1/3,1/3), 3)) + expect_equal(as.numeric(svyPropTable("Y", datSvy)), + as.numeric(prop.table(svytable( ~ Y, datSvy)))) +}) + + +test_that("Regression test for one variable categorical summary", { + + ## Expectations + res1 <- structure(list(n = c(450.015, 450.015), miss = c(0.2858, 0.2858 +), p.miss = c(0.0635089941446396, 0.0635089941446396), level = structure(1:2, .Label = c("0", +"1"), class = "factor"), freq = c(272.7271, 177.0021), percent = c(60.642515540463, +39.357484459537), cum.percent = c(60.642515540463, 100)), .Names = c("n", +"miss", "p.miss", "level", "freq", "percent", "cum.percent"), row.names = c(NA, +-2L), class = "data.frame") + expect_equal(svyCatSummaryForOneVar("Y", datSvy), res1) + + res2 <- structure(list(n = c(450.015, 450.015, 450.015), miss = c(0, +0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", +"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), + percent = c(33.3348888370388, 33.3328889037032, 33.332222259258 + ), cum.percent = c(33.3348888370388, 66.667777740742, 100 + )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", +"cum.percent"), row.names = c(NA, -3L), class = "data.frame") + expect_equal(svyCatSummaryForOneVar("E", datSvy), res2) +}) + + +test_that("Regression test for multiple variable categorical sumamry", { + + ## Expectations + + res1 <- structure(list(E = structure(list(n = c(450.015, 450.015, 450.015 +), miss = c(0, 0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", +"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), + percent = c(33.3348888370388, 33.3328889037032, 33.332222259258 + ), cum.percent = c(33.3348888370388, 66.667777740742, 100 + )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", +"cum.percent"), row.names = c(NA, -3L), class = "data.frame"), + Y = structure(list(n = c(450.015, 450.015), miss = c(0.2858, + 0.2858), p.miss = c(0.0635089941446396, 0.0635089941446396 + ), level = structure(1:2, .Label = c("0", "1"), class = "factor"), + freq = c(272.7271, 177.0021), percent = c(60.642515540463, + 39.357484459537), cum.percent = c(60.642515540463, 100 + )), .Names = c("n", "miss", "p.miss", "level", "freq", + "percent", "cum.percent"), row.names = c(NA, -2L), class = "data.frame"), + C1 = structure(list(n = c(450.015, 450.015), miss = c(0, + 0), p.miss = c(0, 0), level = structure(1:2, .Label = c("0", + "1"), class = "factor"), freq = c(300.015, 150), percent = c(66.667777740742, + 33.332222259258), cum.percent = c(66.667777740742, 100)), .Names = c("n", + "miss", "p.miss", "level", "freq", "percent", "cum.percent" + ), row.names = c(NA, -2L), class = "data.frame")), .Names = c("E", + "Y", "C1")) + expect_equal(svyCatSummary(c("E","Y","C1"), datSvy), res1) }) From b7368d1b2c19feb6303df266ead475c1e6ef7198 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:09:08 -0400 Subject: [PATCH 037/219] Drop library(tableone) from test (test repo file not installed one) --- tests/testthat/test-CreateTableOne.R | 1 - tests/testthat/test-modules.R | 1 - tests/testthat/test-svyModules.R | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index b09fd2f..e38cf15 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -11,7 +11,6 @@ ### Prepare environment ################################################################################ library(testthat) -library(tableone) ### Context (1 for each file) context("Unit tests for the CreateTableOne function") diff --git a/tests/testthat/test-modules.R b/tests/testthat/test-modules.R index 4115ae1..ba1bfef 100644 --- a/tests/testthat/test-modules.R +++ b/tests/testthat/test-modules.R @@ -11,7 +11,6 @@ ### Prepare environment ################################################################################ library(testthat) -library(tableone) ### Context (1 for each file) context("Unit tests for the modules") diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R index ca27d67..c503eb5 100644 --- a/tests/testthat/test-svyModules.R +++ b/tests/testthat/test-svyModules.R @@ -11,7 +11,6 @@ ### Prepare environment ################################################################################ library(testthat) -library(tableone) library(survey) From a31f6a68601c7f022e98dfd9ba70c74884a10ec4 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:09:41 -0400 Subject: [PATCH 038/219] Fix formula formation for survey; protect against multiple quantiles --- R/svyModules.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index f4f78fd..83d8254 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -25,7 +25,7 @@ miss <- function(x) { ## Return formula string having vars on RHS FormulaString <- function(vars) { - paste0(" ~ ", vars, collapse = " + ") + paste0(" ~ ", paste0(vars, collapse = " + ")) } @@ -120,7 +120,8 @@ svyQuant <- function(vars, design, q = 0.5) { form <- FormulaString(vars) ## Remove missingness and mean ## Bad behavior, but consistent with the unweighted version - res <- svyquantile(x = as.formula(form), quantiles = q, design = design, na.rm = TRUE) + ## Use only one quantile + res <- svyquantile(x = as.formula(form), quantiles = q[1], design = design, na.rm = TRUE) out <- as.vector(res) names(out) <- vars out From 95a473090297ed2dcb22c20510a31c5decd898d3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:10:23 -0400 Subject: [PATCH 039/219] Add automatically generated manual files and NAMESPACE --- NAMESPACE | 8 ++- man/CreateCatTable.Rd | 2 +- man/CreateContTable.Rd | 2 +- man/CreateTableOne.Rd | 106 ++++++++++++++++++++++++++++++++- man/ShowRegTable.Rd | 6 +- man/print.CatTable.Rd | 2 +- man/print.ContTable.Rd | 2 +- man/print.TableOne.Rd | 2 +- man/print.svyCatTable.Rd | 115 ++++++++++++++++++++++++++++++++++++ man/print.svyContTable.Rd | 112 +++++++++++++++++++++++++++++++++++ man/summary.CatTable.Rd | 2 +- man/summary.ContTable.Rd | 2 +- man/summary.TableOne.Rd | 2 +- man/summary.svyCatTable.Rd | 53 +++++++++++++++++ man/summary.svyContTable.Rd | 53 +++++++++++++++++ man/svyCreateCatTable.Rd | 104 ++++++++++++++++++++++++++++++++ man/svyCreateContTable.Rd | 105 ++++++++++++++++++++++++++++++++ man/tableone-package.Rd | 2 +- 18 files changed, 666 insertions(+), 14 deletions(-) create mode 100644 man/print.svyCatTable.Rd create mode 100644 man/print.svyContTable.Rd create mode 100644 man/summary.svyCatTable.Rd create mode 100644 man/summary.svyContTable.Rd create mode 100644 man/svyCreateCatTable.Rd create mode 100644 man/svyCreateContTable.Rd diff --git a/NAMESPACE b/NAMESPACE index 025f031..0a1c2d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,14 +1,20 @@ -# Generated by roxygen2 (4.1.0): do not edit by hand +# Generated by roxygen2 (4.1.1): do not edit by hand S3method(print,CatTable) S3method(print,ContTable) S3method(print,TableOne) +S3method(print,svyCatTable) +S3method(print,svyContTable) S3method(summary,CatTable) S3method(summary,ContTable) S3method(summary,TableOne) +S3method(summary,svyCatTable) +S3method(summary,svyContTable) export(CreateCatTable) export(CreateContTable) export(CreateTableOne) export(ShowRegTable) +export(svyCreateCatTable) +export(svyCreateContTable) import(e1071) import(gmodels) diff --git a/man/CreateCatTable.Rd b/man/CreateCatTable.Rd index 54b1faf..81dd3d2 100644 --- a/man/CreateCatTable.Rd +++ b/man/CreateCatTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/CreateCatTable.R \name{CreateCatTable} \alias{CreateCatTable} diff --git a/man/CreateContTable.Rd b/man/CreateContTable.Rd index 494feb1..9135f9d 100644 --- a/man/CreateContTable.Rd +++ b/man/CreateContTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/CreateContTable.R \name{CreateContTable} \alias{CreateContTable} diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 373ad68..dbedf2f 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -1,9 +1,15 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand -% Please edit documentation in R/CreateTableOne.R +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/CreateTableOne.R, R/svyCreateTableOne.R \name{CreateTableOne} \alias{CreateTableOne} \title{Create an object summarizing both categorical and continuous variables} \usage{ +CreateTableOne(vars, strata, data, factorVars, test = TRUE, + testApprox = chisq.test, argsApprox = list(correct = TRUE), + testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), + testNormal = oneway.test, argsNormal = list(var.equal = TRUE), + testNonNormal = kruskal.test, argsNonNormal = list(NULL)) + CreateTableOne(vars, strata, data, factorVars, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), @@ -36,6 +42,32 @@ CreateTableOne(vars, strata, data, factorVars, test = TRUE, \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} + +\item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.} + +\item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} + +\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} + +\item{factorVars}{Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument.} + +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} + +\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} + +\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} + +\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} + +\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} + +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} + +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} + +\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} + +\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} } \value{ An object of class \code{TableOne}, which really is a list of three objects. @@ -46,9 +78,21 @@ An object of class \code{TableOne}, which really is a list of three objects. \item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} +The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. + +An object of class \code{TableOne}, which really is a list of three objects. + +\item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} + +\item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} + +\item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} + The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. } \description{ +Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. + Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. } \examples{ @@ -95,6 +139,58 @@ summary(tableOne$CatTable) tableOne$ContTable summary(tableOne$ContTable) +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Make categorical variables factors +varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + +## Create a variable list +dput(names(pbc)) +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + +## Create Table 1 stratified by trt +tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) + +## Just typing the object name will invoke the print.TableOne method +tableOne + +## Specifying nonnormal variables will show the variables appropriately, +## and show nonparametric test p-values. Specify variables in the exact +## argument to obtain the exact test p-values. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage")) + +## Use the summary.TableOne method for detailed summary +summary(tableOne) + +## See the categorical part only using $ operator +tableOne$CatTable +summary(tableOne$CatTable) + +## See the continuous part only using $ operator +tableOne$ContTable +summary(tableOne$ContTable) + ## If your work flow includes copying to Excel and Word when writing manuscripts, ## you may benefit from the quote argument. This will quote everything so that ## Excel does not mess up the cells. @@ -106,9 +202,15 @@ print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) } \author{ +Justin Bohn, Kazuki Yoshida + Justin Bohn, Kazuki Yoshida } \seealso{ +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} + \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} diff --git a/man/ShowRegTable.Rd b/man/ShowRegTable.Rd index ddca8f8..a34720a 100644 --- a/man/ShowRegTable.Rd +++ b/man/ShowRegTable.Rd @@ -1,11 +1,11 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/ShowRegTable.R \name{ShowRegTable} \alias{ShowRegTable} \title{Format regression results in medically decent format} \usage{ ShowRegTable(model, exp = TRUE, digits = 2, pDigits = 3, - printToggle = TRUE, quote = FALSE) + printToggle = TRUE, quote = FALSE, simpleCi = FALSE) } \arguments{ \item{model}{Regression model result objects that have the summary and confint methods.} @@ -19,6 +19,8 @@ ShowRegTable(model, exp = TRUE, digits = 2, pDigits = 3, \item{printToggle}{Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} + +\item{simpleCi}{Whether to calculate confidence interval by the default normal approximation method. The default is FALSE. If TRUE, the default normal approximation method is used. This may be used when the profile likelihood-based calculation takes too much time.} } \value{ A matrix containing what you see is returned invisibly. You can capture it by assignment to an object. diff --git a/man/print.CatTable.Rd b/man/print.CatTable.Rd index 5a0c957..0e893f6 100644 --- a/man/print.CatTable.Rd +++ b/man/print.CatTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/print.CatTable.R \name{print.CatTable} \alias{print.CatTable} diff --git a/man/print.ContTable.Rd b/man/print.ContTable.Rd index 51a7c78..0bcf1c2 100644 --- a/man/print.ContTable.Rd +++ b/man/print.ContTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/print.ContTable.R \name{print.ContTable} \alias{print.ContTable} diff --git a/man/print.TableOne.Rd b/man/print.TableOne.Rd index 2aa6913..641d27f 100644 --- a/man/print.TableOne.Rd +++ b/man/print.TableOne.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/print.TableOne.R \name{print.TableOne} \alias{print.TableOne} diff --git a/man/print.svyCatTable.Rd b/man/print.svyCatTable.Rd new file mode 100644 index 0000000..afd17ab --- /dev/null +++ b/man/print.svyCatTable.Rd @@ -0,0 +1,115 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/print.svyCatTable.R +\name{print.svyCatTable} +\alias{print.svyCatTable} +\title{Format and print the \code{CatTable} class objects} +\usage{ +\method{print}{svyCatTable}(x, digits = 1, pDigits = 3, quote = FALSE, + missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, + format = c("fp", "f", "p", "pf")[1], showAllLevels = FALSE, + cramVars = NULL, test = TRUE, exact = NULL, CrossTable = FALSE, ...) +} +\arguments{ +\item{x}{The result of a call to the \code{\link{CreateCatTable}} function.} + +\item{digits}{Number of digits to print in the table.} + +\item{pDigits}{Number of digits to print for p-values.} + +\item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} + +\item{missing}{Whether to show missing data information (not implemented yet, placeholder)} + +\item{explain}{Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown.} + +\item{printToggle}{Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.} + +\item{noSpaces}{Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software.} + +\item{format}{The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency).} + +\item{showAllLevels}{Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information.} + +\item{cramVars}{A character vector to specify the two-level categorical variables, for which both levels should be shown in one row.} + +\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} + +\item{exact}{A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).} + +\item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} + +\item{...}{For compatibility with generic. Ignored.} +} +\value{ +It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +} +\description{ +This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for categorical variables +catVars <- c("status","ascites","hepato","spiders","edema","stage") +catTableOverall <- CreateCatTable(vars = catVars, data = pbc) + +## Simply typing the object name will invoke the print.CatTable method, +## which will show the sample size, frequencies and percentages. +## For 2-level variables, only the higher level is shown for simplicity. +catTableOverall + +## If you need to show both levels for some 2-level factors, use cramVars +print(catTableOverall, cramVars = "hepato") + +## Use the showAllLevels argument to see all levels for all variables. +print(catTableOverall, showAllLevels = TRUE) + +## You can choose form frequencies ("f") and/or percentages ("p") or both. +## "fp" frequency (percentage) is the default. Row names change accordingly. +print(catTableOverall, format = "f") +print(catTableOverall, format = "p") + +## To further examine the variables, use the summary.CatTable method, +## which will show more details. +summary(catTableOverall) + +## The table can be stratified by one or more variables +catTableBySexTrt <- CreateCatTable(vars = catVars, + strata = c("sex","trt"), data = pbc) + +## print now includes p-values which are by default calculated by chisq.test. +## It is formatted at the decimal place specified by the pDigits argument +## (3 by default). It does <0.001 for you. +catTableBySexTrt + +## The exact argument toggles the p-values to the exact test result from +## fisher.test. It will show which ones are from exact tests. +print(catTableBySexTrt, exact = "ascites") + +## summary now includes both types of p-values +summary(catTableBySexTrt) + +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(catTableBySexTrt, exact = "ascites", quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +} +\author{ +Kazuki Yoshida +} +\seealso{ +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/print.svyContTable.Rd b/man/print.svyContTable.Rd new file mode 100644 index 0000000..74d4bd1 --- /dev/null +++ b/man/print.svyContTable.Rd @@ -0,0 +1,112 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/print.svyContTable.R +\name{print.svyContTable} +\alias{print.svyContTable} +\title{Format and print the \code{ContTable} class objects} +\usage{ +\method{print}{svyContTable}(x, digits = 2, pDigits = 3, quote = FALSE, + missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, + nonnormal = NULL, minMax = FALSE, insertLevel = FALSE, test = TRUE, + ...) +} +\arguments{ +\item{x}{The result of a call to the \code{\link{CreateContTable}} function.} + +\item{digits}{Number of digits to print in the table.} + +\item{pDigits}{Number of digits to print for p-values.} + +\item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} + +\item{missing}{Whether to show missing data information (not implemented yet, placeholder)} + +\item{explain}{Whether to add explanation to the variable names, i.e., (mean (sd) or median [IQR]) is added to the variable names.} + +\item{printToggle}{Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.} + +\item{noSpaces}{Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software.} + +\item{nonnormal}{A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test).} + +\item{minMax}{Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE.} + +\item{insertLevel}{Whether to add an empty level column to the left of strata.} + +\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} + +\item{...}{For compatibility with generic. Ignored.} +} +\value{ +It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +} +\description{ +This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for continuous variables +contVars <- c("time","age","bili","chol","albumin","copper", + "alk.phos","ast","trig","platelet","protime") +contTableOverall <- CreateContTable(vars = contVars, data = pbc) + +## Simply typing the object name will invoke the print.ContTable method, +## which will show the sample size, means and standard deviations. +contTableOverall + +## To further examine the variables, use the summary.ContTable method, +## which will show more details. +summary(contTableOverall) + +## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. +## Specify them in the nonnormal argument, and the display changes to the median, +## and the [25th, 75th] percentile. +nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") +print(contTableOverall, nonnormal = nonNormalVars) + +## To show median [min,max] for nonnormal variables, use minMax = TRUE +print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) + +## The table can be stratified by one or more variables +contTableBySexTrt <- CreateContTable(vars = contVars, + strata = c("sex","trt"), data = pbc) + +## print now includes p-values which are by default calculated by oneway.test (t-test +## equivalent in the two group case). It is formatted at the decimal place specified +## by the pDigits argument (3 by default). It does <0.001 for you. +contTableBySexTrt + +## The nonnormal argument toggles the p-values to the nonparametric result from +## kruskal.test (wilcox.test equivalent for the two group case). +print(contTableBySexTrt, nonnormal = nonNormalVars) + +## The minMax argument toggles whether to show median [range] +print(contTableBySexTrt, nonnormal = nonNormalVars, minMax = TRUE) + +## summary now includes both types of p-values +summary(contTableBySexTrt) + +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +} +\author{ +Kazuki Yoshida +} +\seealso{ +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/summary.CatTable.Rd b/man/summary.CatTable.Rd index 047f985..a07f7b0 100644 --- a/man/summary.CatTable.Rd +++ b/man/summary.CatTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/summary.CatTable.R \name{summary.CatTable} \alias{summary.CatTable} diff --git a/man/summary.ContTable.Rd b/man/summary.ContTable.Rd index 4589dbe..2dde221 100644 --- a/man/summary.ContTable.Rd +++ b/man/summary.ContTable.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/summary.ContTable.R \name{summary.ContTable} \alias{summary.ContTable} diff --git a/man/summary.TableOne.Rd b/man/summary.TableOne.Rd index aff87be..367620d 100644 --- a/man/summary.TableOne.Rd +++ b/man/summary.TableOne.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/summary.TableOne.R \name{summary.TableOne} \alias{summary.TableOne} diff --git a/man/summary.svyCatTable.Rd b/man/summary.svyCatTable.Rd new file mode 100644 index 0000000..846d79d --- /dev/null +++ b/man/summary.svyCatTable.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/summary.svyCatTable.R +\name{summary.svyCatTable} +\alias{summary.svyCatTable} +\title{Shows all results in a \code{CatTable} class object} +\usage{ +\method{summary}{svyCatTable}(object, digits = 1, ...) +} +\arguments{ +\item{object}{An object that has the \code{CatTable} class to be shown.} + +\item{digits}{Number of digits to print.} + +\item{...}{For compatibility with generic. Ignored.} +} +\value{ +It will print the results. +} +\description{ +This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for categorical variables +catVars <- c("status","ascites","hepato","spiders","edema","stage") +catTableOverall <- CreateCatTable(vars = catVars, data = pbc) + +## Simply typing the object name will invoke the print.CatTable method, +## which will show the sample size, frequencies and percentages. +## For 2-level variables, only the higher level is shown for simplicity. +catTableOverall + +## To further examine the variables, use the summary.CatTable method, +## which will show more details. +summary(catTableOverall) +} +\author{ +Kazuki Yoshida +} +\seealso{ +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/summary.svyContTable.Rd b/man/summary.svyContTable.Rd new file mode 100644 index 0000000..87ea637 --- /dev/null +++ b/man/summary.svyContTable.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/summary.svyContTable.R +\name{summary.svyContTable} +\alias{summary.svyContTable} +\title{Shows all results in a \code{ContTable} class object} +\usage{ +\method{summary}{svyContTable}(object, digits = 2, ...) +} +\arguments{ +\item{object}{An object that has the \code{ContTable} class to be shown.} + +\item{digits}{Number of digits to print.} + +\item{...}{For compatibility with generic. Ignored.} +} +\value{ +It will print the results. +} +\description{ +This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for continuous variables +contVars <- c("time","age","bili","chol","albumin","copper", + "alk.phos","ast","trig","platelet","protime") +contTableOverall <- CreateContTable(vars = contVars, data = pbc) + +## Simply typing the object name will invoke the print.ContTable method, +## which will show the sample size, means and standard deviations. +contTableOverall + +## To further examine the variables, use the summary.ContTable method, +## which will show more details. +summary(contTableOverall) +} +\author{ +Kazuki Yoshida +} +\seealso{ +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/svyCreateCatTable.Rd b/man/svyCreateCatTable.Rd new file mode 100644 index 0000000..fce73eb --- /dev/null +++ b/man/svyCreateCatTable.Rd @@ -0,0 +1,104 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/svyCreateCatTable.R +\name{svyCreateCatTable} +\alias{svyCreateCatTable} +\title{Create an object summarizing categorical variables for weighted data} +\usage{ +svyCreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, + testApprox = chisq.test, argsApprox = list(correct = TRUE), + testExact = fisher.test, argsExact = list(workspace = 2 * 10^5)) +} +\arguments{ +\item{vars}{Variable(s) to be summarized given as a character vector.} + +\item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} + +\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} + +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method.} + +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} + +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} + +\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} + +\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} +} +\value{ +An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +} +\description{ +Create an object summarizing categorical variables optionally stratifying +by one or more startifying variables and performing statistical tests. The +object gives a table that is easy to use in medical research papers. See +also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for categorical variables +catVars <- c("status","ascites","hepato","spiders","edema","stage") +catTableOverall <- CreateCatTable(vars = catVars, data = pbc) + +## Simply typing the object name will invoke the print.CatTable method, +## which will show the sample size, frequencies and percentages. +## For 2-level variables, only the higher level is shown for simplicity +## unless the variables are specified in the cramVars argument. +catTableOverall + +## If you need to show both levels for some 2-level factors, use cramVars +print(catTableOverall, cramVars = "hepato") + +## Use the showAllLevels argument to see all levels for all variables. +print(catTableOverall, showAllLevels = TRUE) + +## You can choose form frequencies ("f") and/or percentages ("p") or both. +## "fp" frequency (percentage) is the default. Row names change accordingly. +print(catTableOverall, format = "f") +print(catTableOverall, format = "p") + +## To further examine the variables, use the summary.CatTable method, +## which will show more details. +summary(catTableOverall) + +## The table can be stratified by one or more variables +catTableBySexTrt <- CreateCatTable(vars = catVars, + strata = c("sex","trt"), data = pbc) + +## print now includes p-values which are by default calculated by chisq.test. +## It is formatted at the decimal place specified by the pDigits argument +## (3 by default). It does <0.001 for you. +catTableBySexTrt + +## The exact argument toggles the p-values to the exact test result from +## fisher.test. It will show which ones are from exact tests. +print(catTableBySexTrt, exact = "ascites") + +## summary now includes both types of p-values +summary(catTableBySexTrt) + +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(catTableBySexTrt, exact = "ascites", quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +} +\author{ +Kazuki Yoshida (based on \code{Deducer::frequencies()}) +} +\seealso{ +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/svyCreateContTable.Rd b/man/svyCreateContTable.Rd new file mode 100644 index 0000000..4df2dea --- /dev/null +++ b/man/svyCreateContTable.Rd @@ -0,0 +1,105 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/svyCreateContTable.R +\name{svyCreateContTable} +\alias{svyCreateContTable} +\title{Create an object summarizing continous variables for weighted dataset} +\usage{ +svyCreateContTable(vars, strata, data, test = TRUE, + testNormal = oneway.test, argsNormal = list(var.equal = TRUE), + testNonNormal = kruskal.test, argsNonNormal = list(NULL)) +} +\arguments{ +\item{vars}{Variable(s) to be summarized given as a character vector.} + +\item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} + +\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} + +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method.} + +\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} + +\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} + +\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} + +\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} + +\item{funcNames}{Not available for weighted dataset} + +\item{funcAdditional}{Not available for weighted dataset} +} +\value{ +An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +} +\description{ +Create an object summarizing continous variables optionally stratifying by +one or more startifying variables and performing statistical tests. The +object gives a table that is easy to use in medical research papers. See +also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Create an overall table for continuous variables +contVars <- c("time","age","bili","chol","albumin","copper", + "alk.phos","ast","trig","platelet","protime") +contTableOverall <- CreateContTable(vars = contVars, data = pbc) + +## Simply typing the object name will invoke the print.ContTable method, +## which will show the sample size, means and standard deviations. +contTableOverall + +## To further examine the variables, use the summary.ContTable method, +## which will show more details. +summary(contTableOverall) + +## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. +## Specify them in the nonnormal argument, and the display changes to the median, +## and the [25th, 75th] percentile. +nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") +print(contTableOverall, nonnormal = nonNormalVars) + +## To show median [min,max] for nonnormal variables, use minMax = TRUE +print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) + +## The table can be stratified by one or more variables +contTableBySexTrt <- CreateContTable(vars = contVars, + strata = c("sex","trt"), data = pbc) + +## print now includes p-values which are by default calculated by oneway.test (t-test +## equivalent in the two group case). It is formatted at the decimal place specified +## by the pDigits argument (3 by default). It does <0.001 for you. +contTableBySexTrt + +## The nonnormal argument toggles the p-values to the nonparametric result from +## kruskal.test (wilcox.test equivalent for the two group case). +print(contTableBySexTrt, nonnormal = nonNormalVars) + +## summary now includes both types of p-values +summary(contTableBySexTrt) + +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +} +\author{ +Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) +} +\seealso{ +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +} + diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index 50addc7..217b4b9 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.0): do not edit by hand +% Generated by roxygen2 (4.1.1): do not edit by hand % Please edit documentation in R/tableone-package.R \docType{package} \name{tableone-package} From ea4141fa2cc29539e5c50436d40f78a8ea30d5d4 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:19:16 -0400 Subject: [PATCH 040/219] Modify svyCreateTableOne for correctness; modify print.TableOne print.TableOne() was modified to accommodate svyTableOne object relies on alphabetical ordering of Cat and Cont --- R/print.TableOne.R | 3 +- R/svyCreateTableOne.R | 70 +++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index c400aa5..7e16865 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -107,7 +107,8 @@ print.TableOne <- function(x, # TableOne object ## Get the Cont/Cat status (1st of classes) classOfTables <- sapply(TableOne, class)[1,] - digits <- c(CatTable = catDigits, ContTable = contDigits)[classOfTables] + ## This relies on Cat/Cont alphabetical order (svyCat/svyCont work similarly) + digits <- c(CatTable = catDigits, ContTable = contDigits)[as.numeric(factor(classOfTables))] ## Get the formatted tables diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index a013408..1dcbb8d 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -82,61 +82,62 @@ ##' exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) ##' ##' @export -CreateTableOne <- -function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - factorVars, # variables to be transformed to factors - test = TRUE, # whether to put p-values - ## Test configuration for categorical data - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5), # arguments passed to testExact - ## Test configuration for continuous data - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { +svyCreateTableOne <- + function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + test = TRUE, # whether to put p-values + ## Test configuration for categorical data + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5), # arguments passed to testExact + ## Test configuration for continuous data + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ### Data check ## Check if the data given is a dataframe - ModuleStopIfNotDataFrame(data) + StopIfNotSurveyDesign(data) ## Check if vars argument is missing. If so, add all names in data. if (missing(vars)) { - vars <- names(data) + vars <- names(data$variables) } ## Check if variables exist. Drop them if not. - vars <- ModuleReturnVarsExist(vars, data) + vars <- ModuleReturnVarsExist(vars, data$variables) ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) ## Factor conversions if the factorVars argument exist if (!missing(factorVars)) { ## Check if variables exist. Drop them if not. - factorVars <- ModuleReturnVarsExist(factorVars, data) + factorVars <- ModuleReturnVarsExist(factorVars, data$variables) ## Convert to factor - data[factorVars] <- lapply(data[factorVars], factor) + data$variables[factorVars] <- lapply(data$variables[factorVars], factor) } ## Toggle test FALSE if no strata is given test <- ModuleReturnFalseIfNoStrata(strata, test) ## Get the classes of the variables - varClasses <- lapply(data[vars], class) + varClasses <- lapply(data$variables[vars], class) ## Classify as varFactors if any one of these classes are contained - varFactors <-sapply(varClasses, function(VEC) { + varFactors <- sapply(varClasses, function(VEC) { any(VEC %in% c("factor", "ordered", "logical", "character")) }) varFactors <- names(varFactors)[varFactors] ## Classify as varNumerics if any one of these classes are contained - varNumerics <-sapply(varClasses, function(VEC) { + varNumerics <- sapply(varClasses, function(VEC) { any(VEC %in% c("numeric", "integer")) }) varNumerics <- names(varNumerics)[varNumerics] @@ -172,7 +173,7 @@ function(vars, # character vector of variab ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. ## Must not be place outside if (!missing(strata)) { }. - dfStrata <- ModuleReturnStrata(strata, data) + dfStrata <- ModuleReturnStrata(strata, data$variable) ## Return variable names. Code inefficient in exchange for code simplicity. strata <- names(dfStrata) @@ -186,14 +187,14 @@ function(vars, # character vector of variab if (length(varNumerics) == 0) { ## No numerics message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') - CatTable <- do.call(CreateCatTable, + CatTable <- do.call(svyCreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) return(CatTable) } else if (length(varFactors) == 0) { ## No factors message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') - ContTable <- do.call(CreateContTable, + ContTable <- do.call(svyCreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) return(ContTable) @@ -201,8 +202,8 @@ function(vars, # character vector of variab } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { ## Create a list of constructors - listOfConstructors <- list(CreateContTable = CreateContTable, - CreateCatTable = CreateCatTable) + listOfConstructors <- list(CreateContTable = svyCreateContTable, + CreateCatTable = svyCreateCatTable) ## CreateCatTable for categorical. CreateContTable for continuous. listOfConstructors <- listOfConstructors[logiFactors + 1] ## Create a list of arguments @@ -229,20 +230,19 @@ function(vars, # character vector of variab ## Create ContTable and CatTable objects (this is redundant, but easy) ## Aggregated ContTable - ContTable <- do.call(CreateContTable, + ContTable <- do.call(svyCreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) ## Aggregated CatTable - CatTable <- do.call(CreateCatTable, + CatTable <- do.call(svyCreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) ## Create a list for output TableOneObject <- list(TableOne = TableOne, ContTable = ContTable, - CatTable = CatTable - ) + CatTable = CatTable) ## Give a class - class(TableOneObject) <- "TableOne" + class(TableOneObject) <- c("svyTableOne", "TableOne") ## Return the object return(TableOneObject) From 79cd4b744da225d04c5a1578c002c53edadf871b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 21:58:01 -0400 Subject: [PATCH 041/219] Change cat() in CreateTableOne() to message() --- R/CreateTableOne.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 39c5bc8..0b6ec15 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -185,14 +185,14 @@ CreateTableOne <- ## Condition on the absence of factor/numeric if (length(varNumerics) == 0) { ## No numerics - cat('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') + message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') CatTable <- do.call(CreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) return(CatTable) } else if (length(varFactors) == 0) { ## No factors - cat('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') + message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') ContTable <- do.call(CreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) return(ContTable) From aa9dda745ed071b04d7e30e591d87a8e4aa55ecd Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 22:54:16 -0400 Subject: [PATCH 042/219] Add simple regression tests for CreateTableOne --- tests/testthat/test-CreateTableOne.R | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index e38cf15..7e27f30 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -77,3 +77,99 @@ test_that("P-values should be NA for 1xM xtabs", { }) + +### Regression tests +################################################################################ + +library(survival) +data(pbc) + +## Make categorical variables factors +varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + +## Create a variable list +dput(names(pbc)) +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + + +tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) + + +## Specifying nonnormal variables will show the variables appropriately, +## and show nonparametric test p-values. Specify variables in the exact +## argument to obtain the exact test p-values. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage")) + +test_that("Regression test", { + + + ## Expectations + res1 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", +" 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", +" 14 (8.9) ", " 73 (46.2) ", " 45 (28.5) ", " ", +" 132 (83.5) ", " 16 (10.1) ", " 10 ( 6.3) ", " 2.87 (3.63)", +" 365.01 (209.54)", " 3.52 (0.44)", " 97.64 (90.59)", "2021.30 (2183.44)", +" 120.21 (54.52)", " 124.14 (71.54)", " 258.75 (100.32)", " 10.65 (0.85)", +" ", " 12 ( 7.6) ", " 35 (22.2) ", " 56 (35.4) ", +" 55 (34.8) ", "154", "1996.86 (1155.93)", " ", " 85 (55.2) ", +" 9 ( 5.8) ", " 60 (39.0) ", " 48.58 (9.96)", " 139 (90.3) ", +" 10 (6.5) ", " 87 (56.5) ", " 45 (29.2) ", " ", +" 131 (85.1) ", " 13 ( 8.4) ", " 10 ( 6.5) ", " 3.65 (5.28)", +" 373.88 (252.48)", " 3.52 (0.40)", " 97.65 (80.49)", "1943.01 (2101.69)", +" 124.97 (58.93)", " 125.25 (58.52)", " 265.20 (90.73)", " 10.80 (1.14)", +" ", " 4 ( 2.6) ", " 32 (20.8) ", " 64 (41.6) ", +" 54 (35.1) ", "", " 0.883", " 0.894", "", "", "", " 0.018", +" 0.421", " 0.567", " 0.088", " 0.985", " 0.877", "", "", "", +" 0.131", " 0.748", " 0.874", " 0.999", " 0.747", " 0.460", " 0.886", +" 0.555", " 0.197", " 0.201", "", "", "", "", "", "", "", "", +"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", +"", "", "", "", "", "", "", "", ""), .Dim = c(29L, 4L), .Dimnames = structure(list( + c("n", "time (mean (sd))", "status (%)", " 0", " 1", + " 2", "age (mean (sd))", "sex = f (%)", "ascites = 1 (%)", + "hepato = 1 (%)", "spiders = 1 (%)", "edema (%)", " 0", + " 0.5", " 1", "bili (mean (sd))", "chol (mean (sd))", + "albumin (mean (sd))", "copper (mean (sd))", "alk.phos (mean (sd))", + "ast (mean (sd))", "trig (mean (sd))", "platelet (mean (sd))", + "protime (mean (sd))", "stage (%)", " 1", " 2", " 3", + " 4"), `Stratified by trt` = c("1", "2", "p", "test")), .Names = c("", +"Stratified by trt"))) + expect_equal(print(tableOne, printToggle = FALSE), res1) + + res2 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", +" 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", +" 14 (8.9) ", " 73 (46.2) ", " 45 (28.5) ", " ", +" 132 (83.5) ", " 16 (10.1) ", " 10 ( 6.3) ", " 1.40 [0.80, 3.20]", +" 315.50 [247.75, 417.00]", " 3.52 (0.44)", " 73.00 [40.00, 121.00]", +"1214.50 [840.75, 2028.00]", " 120.21 (54.52)", " 106.00 [84.50, 146.00]", +" 258.75 (100.32)", " 10.65 (0.85)", " ", " 12 ( 7.6) ", +" 35 (22.2) ", " 56 (35.4) ", " 55 (34.8) ", "154", +"1996.86 (1155.93)", " ", " 85 (55.2) ", " 9 ( 5.8) ", +" 60 (39.0) ", " 48.58 (9.96)", " 139 (90.3) ", " 10 (6.5) ", +" 87 (56.5) ", " 45 (29.2) ", " ", " 131 (85.1) ", +" 13 ( 8.4) ", " 10 ( 6.5) ", " 1.30 [0.72, 3.60]", +" 303.50 [254.25, 377.00]", " 3.52 (0.40)", " 73.00 [43.00, 139.00]", +"1283.00 [922.50, 1949.75]", " 124.97 (58.93)", " 113.00 [84.50, 155.00]", +" 265.20 (90.73)", " 10.80 (1.14)", " ", " 4 ( 2.6) ", +" 32 (20.8) ", " 64 (41.6) ", " 54 (35.1) ", "", +" 0.883", " 0.884", "", "", "", " 0.018", " 0.421", " 0.567", +" 0.088", " 0.985", " 0.877", "", "", "", " 0.842", " 0.544", +" 0.874", " 0.717", " 0.812", " 0.460", " 0.370", " 0.555", " 0.197", +" 0.205", "", "", "", "", "", "", "exact", "", "", "", "", "", +"", "", "", "", "", "", "", "nonnorm", "nonnorm", "", "nonnorm", +"nonnorm", "", "nonnorm", "", "", "exact", "", "", "", ""), .Dim = c(29L, +4L), .Dimnames = structure(list(c("n", "time (mean (sd))", "status (%)", +" 0", " 1", " 2", "age (mean (sd))", "sex = f (%)", "ascites = 1 (%)", +"hepato = 1 (%)", "spiders = 1 (%)", "edema (%)", " 0", " 0.5", +" 1", "bili (median [IQR])", "chol (median [IQR])", "albumin (mean (sd))", +"copper (median [IQR])", "alk.phos (median [IQR])", "ast (mean (sd))", +"trig (median [IQR])", "platelet (mean (sd))", "protime (mean (sd))", +"stage (%)", " 1", " 2", " 3", " 4"), `Stratified by trt` = c("1", +"2", "p", "test")), .Names = c("", "Stratified by trt"))) + expect_equal(print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), printToggle = FALSE), res2) +}) From 0543e8eb897662571420f752dd184b0783cf3796 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 23:10:27 -0400 Subject: [PATCH 043/219] Add regression test for showAllLevels and noSpaces (failing) --- tests/testthat/test-CreateTableOne.R | 73 +++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 7e27f30..f0f5db4 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -89,25 +89,17 @@ varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) ## Create a variable list -dput(names(pbc)) vars <- c("time","status","age","sex","ascites","hepato", "spiders","edema","bili","chol","albumin", "copper","alk.phos","ast","trig","platelet", "protime","stage") +## Create a table to test +pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) -tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) - - -## Specifying nonnormal variables will show the variables appropriately, -## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage")) test_that("Regression test", { - ## Expectations res1 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", " 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", @@ -138,7 +130,8 @@ test_that("Regression test", { "protime (mean (sd))", "stage (%)", " 1", " 2", " 3", " 4"), `Stratified by trt` = c("1", "2", "p", "test")), .Names = c("", "Stratified by trt"))) - expect_equal(print(tableOne, printToggle = FALSE), res1) + expect_equal(print(pbcByTrt, printToggle = FALSE), res1) + res2 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", " 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", @@ -170,6 +163,62 @@ test_that("Regression test", { "trig (median [IQR])", "platelet (mean (sd))", "protime (mean (sd))", "stage (%)", " 1", " 2", " 3", " 4"), `Stratified by trt` = c("1", "2", "p", "test")), .Names = c("", "Stratified by trt"))) - expect_equal(print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + expect_equal(print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), printToggle = FALSE), res2) + + + res3 <- structure(c("158", "2015.62 (1094.12)", "0.89 (0.96)", "51.42 (11.01)", +"137 (86.7)", "0.09 (0.29)", "0.46 (0.50)", "0.28 (0.45)", "0.11 (0.28)", +"1.40 [0.80, 3.20]", "315.50 [247.75, 417.00]", "3.52 (0.44)", +"73.00 [40.00, 121.00]", "1214.50 [840.75, 2028.00]", "120.21 (54.52)", +"106.00 [84.50, 146.00]", "258.75 (100.32)", "10.65 (0.85)", +"2.97 (0.94)", "154", "1996.86 (1155.93)", "0.84 (0.96)", "48.58 (9.96)", +"139 (90.3)", "0.06 (0.25)", "0.56 (0.50)", "0.29 (0.46)", "0.11 (0.27)", +"1.30 [0.72, 3.60]", "303.50 [254.25, 377.00]", "3.52 (0.40)", +"73.00 [43.00, 139.00]", "1283.00 [922.50, 1949.75]", "124.97 (58.93)", +"113.00 [84.50, 155.00]", "265.20 (90.73)", "10.80 (1.14)", "3.09 (0.81)", +"", "0.883", "0.657", "0.018", "0.421", "0.434", "0.069", "0.886", +"0.828", "0.842", "0.544", "0.874", "0.717", "0.812", "0.460", +"0.370", "0.555", "0.197", "0.243", "", "", "", "", "", "", "", +"", "", "nonnorm", "nonnorm", "", "nonnorm", "nonnorm", "", "nonnorm", +"", "", ""), .Dim = c(19L, 4L), .Dimnames = structure(list(c("n", +"time (mean (sd))", "status (mean (sd))", "age (mean (sd))", +"sex = f (%)", "ascites (mean (sd))", "hepato (mean (sd))", "spiders (mean (sd))", +"edema (mean (sd))", "bili (median [IQR])", "chol (median [IQR])", +"albumin (mean (sd))", "copper (median [IQR])", "alk.phos (median [IQR])", +"ast (mean (sd))", "trig (median [IQR])", "platelet (mean (sd))", +"protime (mean (sd))", "stage (mean (sd))"), `Stratified by trt` = c("1", +"2", "p", "test")), .Names = c("", "Stratified by trt"))) + out3 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), noSpaces = TRUE, printToggle = FALSE) + expect_equal(out3, res3) + + + res4 <- structure(c("", "", "", "", "m", "f", "", "", "", "", "", "", +"", "", "", "", "", "", "", "", "158", "2015.62 (1094.12)", " 0.89 (0.96)", +" 51.42 (11.01)", " 21 (13.3) ", " 137 (86.7) ", " 0.09 (0.29)", +" 0.46 (0.50)", " 0.28 (0.45)", " 0.11 (0.28)", " 1.40 [0.80, 3.20]", +" 315.50 [247.75, 417.00]", " 3.52 (0.44)", " 73.00 [40.00, 121.00]", +"1214.50 [840.75, 2028.00]", " 120.21 (54.52)", " 106.00 [84.50, 146.00]", +" 258.75 (100.32)", " 10.65 (0.85)", " 2.97 (0.94)", "154", +"1996.86 (1155.93)", " 0.84 (0.96)", " 48.58 (9.96)", " 15 ( 9.7) ", +" 139 (90.3) ", " 0.06 (0.25)", " 0.56 (0.50)", " 0.29 (0.46)", +" 0.11 (0.27)", " 1.30 [0.72, 3.60]", " 303.50 [254.25, 377.00]", +" 3.52 (0.40)", " 73.00 [43.00, 139.00]", "1283.00 [922.50, 1949.75]", +" 124.97 (58.93)", " 113.00 [84.50, 155.00]", " 265.20 (90.73)", +" 10.80 (1.14)", " 3.09 (0.81)", "", " 0.883", " 0.657", " 0.018", +" 0.421", "", " 0.434", " 0.069", " 0.886", " 0.828", " 0.842", +" 0.544", " 0.874", " 0.717", " 0.812", " 0.460", " 0.370", " 0.555", +" 0.197", " 0.243", "", "", "", "", "", "", "", "", "", "", "nonnorm", +"nonnorm", "", "nonnorm", "nonnorm", "", "nonnorm", "", "", "" +), .Dim = c(20L, 5L), .Dimnames = structure(list(c("n", "time (mean (sd))", +"status (mean (sd))", "age (mean (sd))", "sex (%)", "", "ascites (mean (sd))", +"hepato (mean (sd))", "spiders (mean (sd))", "edema (mean (sd))", +"bili (median [IQR])", "chol (median [IQR])", "albumin (mean (sd))", +"copper (median [IQR])", "alk.phos (median [IQR])", "ast (mean (sd))", +"trig (median [IQR])", "platelet (mean (sd))", "protime (mean (sd))", +"stage (mean (sd))"), `Stratified by trt` = c("level", "1", "2", +"p", "test")), .Names = c("", "Stratified by trt"))) + expect_equal(print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), showAllLevels = TRUE, printToggle = FALSE), res4) }) From aeed6bce1e8ecae045ad38aea9d9e15b16888603 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 24 Jul 2015 23:15:21 -0400 Subject: [PATCH 044/219] Add test file for svyCreateTableOne --- tests/testthat/test-svyCreateTableOne.R | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/testthat/test-svyCreateTableOne.R diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R new file mode 100644 index 0000000..5ae06e4 --- /dev/null +++ b/tests/testthat/test-svyCreateTableOne.R @@ -0,0 +1,65 @@ +################################################################################ +### Unit tests for the svyCreateTableOne +## Reference: http://adv-r.had.co.nz/Testing.html +## Created on: 2015-07-24 +## Author: Kazuki Yoshida +################################################################################ + +### Structure +## expectations within tests within context + +### Prepare environment +################################################################################ +library(testthat) +library(survey) + + +### Context (1 for each file) +################################################################################ +context("Unit tests for the survey-related modules") + + + +### Provide data +################################################################################ + +## Three-group dataset with matching weight (Li & Greene 2013) +datMw <- structure(list(E = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, +2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), C = c(1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 1L, +1L, 2L, 2L, 3L, 3L, 4L, 4L), Y = c(0, 1, 0, 1, 0, 1, 0, 1, 0, +1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1), C1 = c(0, 0, 0, +0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 +), C2 = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, +0, 1, 1, 0, 0, 1, 1), n = c(252L, 28L, 105L, 45L, 12L, 28L, 1L, +9L, 72L, 8L, 63L, 27L, 24L, 56L, 1L, 9L, 36L, 4L, 42L, 18L, 24L, +56L, 8L, 72L), Mw = c(0.1429, 0.1429, 0.4, 0.4, 1, 1, 1, 1, 0.5, +0.5, 0.6667, 0.6667, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.125, +0.125)), class = "data.frame", .Names = c("E", "C", "Y", "C1", +"C2", "n", "Mw"), row.names = c(NA, -24L)) + +## Create individual level data +datMw <- datMw[rep(seq_along(datMw$n), datMw$n),] +## Introduce missingness +datMw[c(1,150), "Y"] <- NA +## Create a survey design object +datSvy <- svydesign(ids = ~ 1, data = datMw, weights = ~ Mw) + + +### Tests +################################################################################ +## A test should group together expectations for one functionality. + + + +test_that("Data check assessment", { + + ## Should give + ## Error in ModuleStopIfNoVarsLeft(vars) (from modules.R#52) : No valid variables. + ## In addition: Warning message: + ## In ModuleReturnVarsExist(vars, data$variables) : + ## The data frame does not have: none Dropped + expect_warning(expect_error(svyCreateTableOne(vars = "none", data = datSvy))) + + +}) From b4a352af629c45413f02977dd7cd6a742d1a0883 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 07:18:25 -0400 Subject: [PATCH 045/219] Simplify regression tests using expect_equal_to_reference --- tests/testthat/test-CreateTableOne.R | 134 +++------------------------ 1 file changed, 14 insertions(+), 120 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index f0f5db4..f842998 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -98,127 +98,21 @@ vars <- c("time","status","age","sex","ascites","hepato", pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) -test_that("Regression test", { +test_that("printing of a TableOne object does not regress", { ## Expectations - res1 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", -" 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", -" 14 (8.9) ", " 73 (46.2) ", " 45 (28.5) ", " ", -" 132 (83.5) ", " 16 (10.1) ", " 10 ( 6.3) ", " 2.87 (3.63)", -" 365.01 (209.54)", " 3.52 (0.44)", " 97.64 (90.59)", "2021.30 (2183.44)", -" 120.21 (54.52)", " 124.14 (71.54)", " 258.75 (100.32)", " 10.65 (0.85)", -" ", " 12 ( 7.6) ", " 35 (22.2) ", " 56 (35.4) ", -" 55 (34.8) ", "154", "1996.86 (1155.93)", " ", " 85 (55.2) ", -" 9 ( 5.8) ", " 60 (39.0) ", " 48.58 (9.96)", " 139 (90.3) ", -" 10 (6.5) ", " 87 (56.5) ", " 45 (29.2) ", " ", -" 131 (85.1) ", " 13 ( 8.4) ", " 10 ( 6.5) ", " 3.65 (5.28)", -" 373.88 (252.48)", " 3.52 (0.40)", " 97.65 (80.49)", "1943.01 (2101.69)", -" 124.97 (58.93)", " 125.25 (58.52)", " 265.20 (90.73)", " 10.80 (1.14)", -" ", " 4 ( 2.6) ", " 32 (20.8) ", " 64 (41.6) ", -" 54 (35.1) ", "", " 0.883", " 0.894", "", "", "", " 0.018", -" 0.421", " 0.567", " 0.088", " 0.985", " 0.877", "", "", "", -" 0.131", " 0.748", " 0.874", " 0.999", " 0.747", " 0.460", " 0.886", -" 0.555", " 0.197", " 0.201", "", "", "", "", "", "", "", "", -"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -"", "", "", "", "", "", "", "", ""), .Dim = c(29L, 4L), .Dimnames = structure(list( - c("n", "time (mean (sd))", "status (%)", " 0", " 1", - " 2", "age (mean (sd))", "sex = f (%)", "ascites = 1 (%)", - "hepato = 1 (%)", "spiders = 1 (%)", "edema (%)", " 0", - " 0.5", " 1", "bili (mean (sd))", "chol (mean (sd))", - "albumin (mean (sd))", "copper (mean (sd))", "alk.phos (mean (sd))", - "ast (mean (sd))", "trig (mean (sd))", "platelet (mean (sd))", - "protime (mean (sd))", "stage (%)", " 1", " 2", " 3", - " 4"), `Stratified by trt` = c("1", "2", "p", "test")), .Names = c("", -"Stratified by trt"))) - expect_equal(print(pbcByTrt, printToggle = FALSE), res1) - - - res2 <- structure(c("158", "2015.62 (1094.12)", " ", " 83 (52.5) ", -" 10 ( 6.3) ", " 65 (41.1) ", " 51.42 (11.01)", " 137 (86.7) ", -" 14 (8.9) ", " 73 (46.2) ", " 45 (28.5) ", " ", -" 132 (83.5) ", " 16 (10.1) ", " 10 ( 6.3) ", " 1.40 [0.80, 3.20]", -" 315.50 [247.75, 417.00]", " 3.52 (0.44)", " 73.00 [40.00, 121.00]", -"1214.50 [840.75, 2028.00]", " 120.21 (54.52)", " 106.00 [84.50, 146.00]", -" 258.75 (100.32)", " 10.65 (0.85)", " ", " 12 ( 7.6) ", -" 35 (22.2) ", " 56 (35.4) ", " 55 (34.8) ", "154", -"1996.86 (1155.93)", " ", " 85 (55.2) ", " 9 ( 5.8) ", -" 60 (39.0) ", " 48.58 (9.96)", " 139 (90.3) ", " 10 (6.5) ", -" 87 (56.5) ", " 45 (29.2) ", " ", " 131 (85.1) ", -" 13 ( 8.4) ", " 10 ( 6.5) ", " 1.30 [0.72, 3.60]", -" 303.50 [254.25, 377.00]", " 3.52 (0.40)", " 73.00 [43.00, 139.00]", -"1283.00 [922.50, 1949.75]", " 124.97 (58.93)", " 113.00 [84.50, 155.00]", -" 265.20 (90.73)", " 10.80 (1.14)", " ", " 4 ( 2.6) ", -" 32 (20.8) ", " 64 (41.6) ", " 54 (35.1) ", "", -" 0.883", " 0.884", "", "", "", " 0.018", " 0.421", " 0.567", -" 0.088", " 0.985", " 0.877", "", "", "", " 0.842", " 0.544", -" 0.874", " 0.717", " 0.812", " 0.460", " 0.370", " 0.555", " 0.197", -" 0.205", "", "", "", "", "", "", "exact", "", "", "", "", "", -"", "", "", "", "", "", "", "nonnorm", "nonnorm", "", "nonnorm", -"nonnorm", "", "nonnorm", "", "", "exact", "", "", "", ""), .Dim = c(29L, -4L), .Dimnames = structure(list(c("n", "time (mean (sd))", "status (%)", -" 0", " 1", " 2", "age (mean (sd))", "sex = f (%)", "ascites = 1 (%)", -"hepato = 1 (%)", "spiders = 1 (%)", "edema (%)", " 0", " 0.5", -" 1", "bili (median [IQR])", "chol (median [IQR])", "albumin (mean (sd))", -"copper (median [IQR])", "alk.phos (median [IQR])", "ast (mean (sd))", -"trig (median [IQR])", "platelet (mean (sd))", "protime (mean (sd))", -"stage (%)", " 1", " 2", " 3", " 4"), `Stratified by trt` = c("1", -"2", "p", "test")), .Names = c("", "Stratified by trt"))) - expect_equal(print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), printToggle = FALSE), res2) - - - res3 <- structure(c("158", "2015.62 (1094.12)", "0.89 (0.96)", "51.42 (11.01)", -"137 (86.7)", "0.09 (0.29)", "0.46 (0.50)", "0.28 (0.45)", "0.11 (0.28)", -"1.40 [0.80, 3.20]", "315.50 [247.75, 417.00]", "3.52 (0.44)", -"73.00 [40.00, 121.00]", "1214.50 [840.75, 2028.00]", "120.21 (54.52)", -"106.00 [84.50, 146.00]", "258.75 (100.32)", "10.65 (0.85)", -"2.97 (0.94)", "154", "1996.86 (1155.93)", "0.84 (0.96)", "48.58 (9.96)", -"139 (90.3)", "0.06 (0.25)", "0.56 (0.50)", "0.29 (0.46)", "0.11 (0.27)", -"1.30 [0.72, 3.60]", "303.50 [254.25, 377.00]", "3.52 (0.40)", -"73.00 [43.00, 139.00]", "1283.00 [922.50, 1949.75]", "124.97 (58.93)", -"113.00 [84.50, 155.00]", "265.20 (90.73)", "10.80 (1.14)", "3.09 (0.81)", -"", "0.883", "0.657", "0.018", "0.421", "0.434", "0.069", "0.886", -"0.828", "0.842", "0.544", "0.874", "0.717", "0.812", "0.460", -"0.370", "0.555", "0.197", "0.243", "", "", "", "", "", "", "", -"", "", "nonnorm", "nonnorm", "", "nonnorm", "nonnorm", "", "nonnorm", -"", "", ""), .Dim = c(19L, 4L), .Dimnames = structure(list(c("n", -"time (mean (sd))", "status (mean (sd))", "age (mean (sd))", -"sex = f (%)", "ascites (mean (sd))", "hepato (mean (sd))", "spiders (mean (sd))", -"edema (mean (sd))", "bili (median [IQR])", "chol (median [IQR])", -"albumin (mean (sd))", "copper (median [IQR])", "alk.phos (median [IQR])", -"ast (mean (sd))", "trig (median [IQR])", "platelet (mean (sd))", -"protime (mean (sd))", "stage (mean (sd))"), `Stratified by trt` = c("1", -"2", "p", "test")), .Names = c("", "Stratified by trt"))) + out1 <- print(pbcByTrt, printToggle = FALSE) + expect_equal_to_reference(out1, "ref-CreateTableOne_defaultPrint") + + out2 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), printToggle = FALSE) + expect_equal_to_reference(out2, "ref-CreateTableOne_nonnormal_exact") + out3 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), noSpaces = TRUE, printToggle = FALSE) - expect_equal(out3, res3) - - - res4 <- structure(c("", "", "", "", "m", "f", "", "", "", "", "", "", -"", "", "", "", "", "", "", "", "158", "2015.62 (1094.12)", " 0.89 (0.96)", -" 51.42 (11.01)", " 21 (13.3) ", " 137 (86.7) ", " 0.09 (0.29)", -" 0.46 (0.50)", " 0.28 (0.45)", " 0.11 (0.28)", " 1.40 [0.80, 3.20]", -" 315.50 [247.75, 417.00]", " 3.52 (0.44)", " 73.00 [40.00, 121.00]", -"1214.50 [840.75, 2028.00]", " 120.21 (54.52)", " 106.00 [84.50, 146.00]", -" 258.75 (100.32)", " 10.65 (0.85)", " 2.97 (0.94)", "154", -"1996.86 (1155.93)", " 0.84 (0.96)", " 48.58 (9.96)", " 15 ( 9.7) ", -" 139 (90.3) ", " 0.06 (0.25)", " 0.56 (0.50)", " 0.29 (0.46)", -" 0.11 (0.27)", " 1.30 [0.72, 3.60]", " 303.50 [254.25, 377.00]", -" 3.52 (0.40)", " 73.00 [43.00, 139.00]", "1283.00 [922.50, 1949.75]", -" 124.97 (58.93)", " 113.00 [84.50, 155.00]", " 265.20 (90.73)", -" 10.80 (1.14)", " 3.09 (0.81)", "", " 0.883", " 0.657", " 0.018", -" 0.421", "", " 0.434", " 0.069", " 0.886", " 0.828", " 0.842", -" 0.544", " 0.874", " 0.717", " 0.812", " 0.460", " 0.370", " 0.555", -" 0.197", " 0.243", "", "", "", "", "", "", "", "", "", "", "nonnorm", -"nonnorm", "", "nonnorm", "nonnorm", "", "nonnorm", "", "", "" -), .Dim = c(20L, 5L), .Dimnames = structure(list(c("n", "time (mean (sd))", -"status (mean (sd))", "age (mean (sd))", "sex (%)", "", "ascites (mean (sd))", -"hepato (mean (sd))", "spiders (mean (sd))", "edema (mean (sd))", -"bili (median [IQR])", "chol (median [IQR])", "albumin (mean (sd))", -"copper (median [IQR])", "alk.phos (median [IQR])", "ast (mean (sd))", -"trig (median [IQR])", "platelet (mean (sd))", "protime (mean (sd))", -"stage (mean (sd))"), `Stratified by trt` = c("level", "1", "2", -"p", "test")), .Names = c("", "Stratified by trt"))) - expect_equal(print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), showAllLevels = TRUE, printToggle = FALSE), res4) + exact = c("status","stage"), noSpaces = TRUE, printToggle = FALSE) + expect_equal_to_reference(out3, file = "ref-CreateTableOne_noSpaces") + + out4 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), showAllLevels = TRUE, printToggle = FALSE) + expect_equal_to_reference(out4, "ref-CreateTableOne_showAllLevels") }) From 8fd11f2b747c26e1060d8e7c006e683ca596ce4c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 08:07:30 -0400 Subject: [PATCH 046/219] Add tests for printing TableOne/CatTable/ContTable --- tests/testthat/test-CreateTableOne.R | 124 ++++++++++++++++++++++++--- 1 file changed, 112 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index f842998..6bf4b8b 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -95,24 +95,124 @@ vars <- c("time","status","age","sex","ascites","hepato", "protime","stage") ## Create a table to test -pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) +pbcOverall <- CreateTableOne(vars = vars, data = pbc) +pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) +pbcByTrtSex <- CreateTableOne(vars = vars, strata = c("trt","sex"), data = pbc) test_that("printing of a TableOne object does not regress", { + nonnormalVars <- c("bili","chol","copper","alk.phos","trig") + exactVars <- c("status","stage") + + ## Expectations + expect_equal_to_reference(print(pbcByTrt, printToggle = FALSE), + "ref-TableOne_defaultPrint") + + expect_equal_to_reference(print(pbcOverall, printToggle = FALSE), + "ref-TableOne_overallPrint") + + expect_equal_to_reference(print(pbcByTrtSex, printToggle = FALSE), + "ref-TableOne_2StrataVars") + + ## 2015-07-25 pDigits is not functional now + expect_equal_to_reference(print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), + "ref-TableOne_digits") + + expect_equal_to_reference(print(pbcByTrt, test = FALSE, printToggle = FALSE), + "ref-TableOne_noTests") + + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + "ref-TableOne_nonnormal_exact") + + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + "ref-TableOne_nonnormal_minMax") + + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, printToggle = FALSE), + "ref-TableOne_noSpaces") + + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = FALSE), + "ref-TableOne_showAllLevels") + + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = FALSE), + "ref-TableOne_noSpaces_showAllLevels_quote") +}) + + +test_that("printing of a TableOne$CatTable object do not regress", { + + ## Expectations + expect_equal_to_reference(print(pbcByTrt$CatTable, printToggle = FALSE), + "ref-CatTable_defaultPrint") + + expect_equal_to_reference(print(pbcOverall$CatTable, printToggle = FALSE), + "ref-CatTable_overallPrint") + + expect_equal_to_reference(print(pbcByTrtSex$CatTable, printToggle = FALSE), + "ref-CatTable_2StrataVars") + + expect_equal_to_reference(print(pbcByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = FALSE), + "ref-CatTable_digits") + + expect_equal_to_reference(print(pbcByTrtSex$CatTable, test = FALSE, printToggle = FALSE), + "ref-CatTable_noTests") + + expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, printToggle = FALSE), + "ref-CatTable_noSpaces") + + expect_equal_to_reference(print(pbcByTrt$CatTable, showAllLevels = TRUE, printToggle = FALSE), + "ref-CatTable_showAllLevels") + + expect_equal_to_reference(print(pbcByTrt$CatTable, explain = FALSE, printToggle = FALSE), + "ref-CatTable_explain") + + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "f", printToggle = FALSE), + "ref-CatTable_format_f") + + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "p", printToggle = FALSE), + "ref-CatTable_format_p") + + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "pf", printToggle = FALSE), + "ref-CatTable_format_pf") + + expect_equal_to_reference(print(pbcByTrt$CatTable, cramVars = "sex", printToggle = FALSE), + "ref-CatTable_cramVars") + + expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + "ref-CatTable_noSpaces_showAllLevels_quote") +}) + + +test_that("printing of a TableOne$ContTable object do not regress", { + ## Expectations - out1 <- print(pbcByTrt, printToggle = FALSE) - expect_equal_to_reference(out1, "ref-CreateTableOne_defaultPrint") + expect_equal_to_reference(print(pbcByTrt$ContTable, printToggle = FALSE), + "ref-ContTable_defaultPrint") + + expect_equal_to_reference(print(pbcOverall$ContTable, printToggle = FALSE), + "ref-ContTable_overallPrint") + + expect_equal_to_reference(print(pbcByTrtSex$ContTable, printToggle = FALSE), + "ref-ContTable_2StrataVars") + + expect_equal_to_reference(print(pbcByTrt$ContTable, digits = 3, pDigits = 5, printToggle = FALSE), + "ref-ContTable_digits") + + expect_equal_to_reference(print(pbcByTrt$ContTable, test = FALSE, printToggle = FALSE), + "ref-ContTable_noTests") + + expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + "ref-ContTable_nonnormal_exact") - out2 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), printToggle = FALSE) - expect_equal_to_reference(out2, "ref-CreateTableOne_nonnormal_exact") + expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + "ref-ContTable_nonnormal_minMax") + + expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), + "ref-ContTable_noSpaces") - out3 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), noSpaces = TRUE, printToggle = FALSE) - expect_equal_to_reference(out3, file = "ref-CreateTableOne_noSpaces") + expect_equal_to_reference(print(pbcByTrt$ContTable, explain = FALSE, printToggle = FALSE), + "ref-ContTable_explain") - out4 <- print(pbcByTrt, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), showAllLevels = TRUE, printToggle = FALSE) - expect_equal_to_reference(out4, "ref-CreateTableOne_showAllLevels") + expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + "ref-ContTable_noSpaces_showAllLevels_quote") }) From 7ad273845a887631d42a2f11a5235bd0540d3d26 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 08:08:56 -0400 Subject: [PATCH 047/219] Add reference standards for testing TableOne/CatTable/ContTable pDigits for TableOne is not functional, thus not added --- tests/testthat/ref-CatTable_2StrataVars | Bin 0 -> 612 bytes tests/testthat/ref-CatTable_cramVars | Bin 0 -> 516 bytes tests/testthat/ref-CatTable_defaultPrint | Bin 0 -> 492 bytes tests/testthat/ref-CatTable_digits | Bin 0 -> 670 bytes tests/testthat/ref-CatTable_explain | Bin 0 -> 484 bytes tests/testthat/ref-CatTable_format_f | Bin 0 -> 384 bytes tests/testthat/ref-CatTable_format_p | Bin 0 -> 423 bytes tests/testthat/ref-CatTable_format_pf | Bin 0 -> 503 bytes tests/testthat/ref-CatTable_noSpaces | Bin 0 -> 482 bytes .../ref-CatTable_noSpaces_showAllLevels_quote | Bin 0 -> 550 bytes tests/testthat/ref-CatTable_noTests | Bin 0 -> 565 bytes tests/testthat/ref-CatTable_overallPrint | Bin 0 -> 347 bytes tests/testthat/ref-CatTable_showAllLevels | Bin 0 -> 530 bytes tests/testthat/ref-ContTable_2StrataVars | Bin 0 -> 716 bytes tests/testthat/ref-ContTable_defaultPrint | Bin 0 -> 521 bytes tests/testthat/ref-ContTable_digits | Bin 0 -> 566 bytes tests/testthat/ref-ContTable_explain | Bin 0 -> 503 bytes tests/testthat/ref-ContTable_noSpaces | Bin 0 -> 517 bytes .../ref-ContTable_noSpaces_showAllLevels_quote | Bin 0 -> 533 bytes tests/testthat/ref-ContTable_noTests | Bin 0 -> 464 bytes tests/testthat/ref-ContTable_nonnormal_exact | Bin 0 -> 587 bytes tests/testthat/ref-ContTable_nonnormal_minMax | Bin 0 -> 583 bytes tests/testthat/ref-ContTable_overallPrint | Bin 0 -> 361 bytes tests/testthat/ref-TableOne_2StrataVars | Bin 0 -> 1128 bytes tests/testthat/ref-TableOne_defaultPrint | Bin 0 -> 790 bytes tests/testthat/ref-TableOne_noSpaces | Bin 0 -> 842 bytes .../ref-TableOne_noSpaces_showAllLevels_quote | Bin 0 -> 861 bytes tests/testthat/ref-TableOne_noTests | Bin 0 -> 705 bytes tests/testthat/ref-TableOne_nonnormal_exact | Bin 0 -> 872 bytes tests/testthat/ref-TableOne_nonnormal_minMax | Bin 0 -> 856 bytes tests/testthat/ref-TableOne_overallPrint | Bin 0 -> 517 bytes tests/testthat/ref-TableOne_showAllLevels | Bin 0 -> 917 bytes 32 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/ref-CatTable_2StrataVars create mode 100644 tests/testthat/ref-CatTable_cramVars create mode 100644 tests/testthat/ref-CatTable_defaultPrint create mode 100644 tests/testthat/ref-CatTable_digits create mode 100644 tests/testthat/ref-CatTable_explain create mode 100644 tests/testthat/ref-CatTable_format_f create mode 100644 tests/testthat/ref-CatTable_format_p create mode 100644 tests/testthat/ref-CatTable_format_pf create mode 100644 tests/testthat/ref-CatTable_noSpaces create mode 100644 tests/testthat/ref-CatTable_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-CatTable_noTests create mode 100644 tests/testthat/ref-CatTable_overallPrint create mode 100644 tests/testthat/ref-CatTable_showAllLevels create mode 100644 tests/testthat/ref-ContTable_2StrataVars create mode 100644 tests/testthat/ref-ContTable_defaultPrint create mode 100644 tests/testthat/ref-ContTable_digits create mode 100644 tests/testthat/ref-ContTable_explain create mode 100644 tests/testthat/ref-ContTable_noSpaces create mode 100644 tests/testthat/ref-ContTable_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-ContTable_noTests create mode 100644 tests/testthat/ref-ContTable_nonnormal_exact create mode 100644 tests/testthat/ref-ContTable_nonnormal_minMax create mode 100644 tests/testthat/ref-ContTable_overallPrint create mode 100644 tests/testthat/ref-TableOne_2StrataVars create mode 100644 tests/testthat/ref-TableOne_defaultPrint create mode 100644 tests/testthat/ref-TableOne_noSpaces create mode 100644 tests/testthat/ref-TableOne_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-TableOne_noTests create mode 100644 tests/testthat/ref-TableOne_nonnormal_exact create mode 100644 tests/testthat/ref-TableOne_nonnormal_minMax create mode 100644 tests/testthat/ref-TableOne_overallPrint create mode 100644 tests/testthat/ref-TableOne_showAllLevels diff --git a/tests/testthat/ref-CatTable_2StrataVars b/tests/testthat/ref-CatTable_2StrataVars new file mode 100644 index 0000000000000000000000000000000000000000..d04710d6bfdf4dde15f16b0f2e21619bb705e06d GIT binary patch literal 612 zcmV-q0-OCGiwFP!000001I<-UZ`wc*T?|Emx=GZi_qkLe7t8D2^#^LDNc{;tv{yHn z#!^TScB}T!N1Xv1k9S>AZ@sYN$D21ZZ`Sa2E`;#J*c%CNOyMX^Q=%fSw1pOc}du7kXm;7+Eexo!pV58OEz z#~pj}u~dmA?L&f704}+s`9PTfh8gRFp&nEcL>-25*hR?4@TT}sx) zJ)7E=c$+3VSf{ylnQI+gL$aN>GE_rr(v!p1QT^2PMx@J!;yui*)y)Nat0TT@+!R?S zdm4sn>4?wOSf>Vbr}RE4Wuf*t{eY}cvK%90_7sIF*Gn_@l!fs*b!5f*9P9r(#l*vp zQF|FzlnbOh<(r~H%1y(&-g6J%kDl6JiK@=)9~CU#-!{ku074c^ z7Dr9|x+;FbM_9A8tGv1|>!LzfGWhbL*yi=KgcZUlhj^{=HB%MF8hlfl;2mk;jfG;-y literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_cramVars b/tests/testthat/ref-CatTable_cramVars new file mode 100644 index 0000000000000000000000000000000000000000..86b92b36656b6deeabdd0aea36f18e15f082355d GIT binary patch literal 516 zcmV+f0{i_RiwFP!000001I<)DZ`&{srDQjVgT_glrQ8eId zBcM(Ui!ItepY|wI21PkY$9T}4PVXMyy(9efgb> z0{*msOmV6%A*`|-GAO7RR|^H1WR&fz7o4q_C?R8lij^*C8PQ0j(X<*@OFU8*l#iVxmAn368(ZCFuprpmPN4V2@tVtoiP*g@$#0p9EzKY(;gWe)g zshAWh6rh6kowq1jR5agL-!p~YBDSLCs>w#m)F+v{dwdoLY;c@3ZcK1Db@X1MMYx}c< z?Bk`c%yEf%kh37?K0ocuZ@7Z>>Mm$JtGnCQnhrm(puD^{o7z4`)w6EXHf9@x7p5`m z`WZDxE~n~%wgpb{-9&ANgu7e>x%9rw2VaJ!WavmX0~|-Qk~C~XD7I%NPyYbKxx9cu G1^@tj+5o=* literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_defaultPrint b/tests/testthat/ref-CatTable_defaultPrint new file mode 100644 index 0000000000000000000000000000000000000000..aea4951e72688d41c9bb11e8704290ed5185b0d4 GIT binary patch literal 492 zcmVH38 zDkzNP<^modQ9=O~R|KjI6k2exhlHx3uobUqp~gbX8v@lRuPZJIq)|&+(vj^oC2Fd8 zm&@5yb6KO$%9Stc&vv5Au z@RFK^tfq`CowlI6TC~)}&}ddeIuf%4nq^{V)OY~>r#Aa-Ae>9aW}$zwjJMI_=_$+T z(LZsZc?4M7q`svwu(TB9%~UmcE3GAOjWtxguKz(@mf|n0|1Yv-j*o2q`*r;q!*dos zXU1NR#F%o7l$&<#2Bf^2c;_Q`_j`6TB`1S#{kH*%*B2AA1b~v{g5+{O^Wc8K8@M86 zXYFv=dp95~2z+|&Hm$!+(6eFFcW#@KSFUsG_BXQ}g`As5CR^bSUtCi5*w`UgB-fKG z%h{E=D4Q#?%}mGDd}8vG$>C8WPmcEDgWtBkzv^8FpMQeiVl}%<6rO!|m+x-Be(XDc i9Zq!`gx((SZa&9d&Eh_3M28)f+1)RH4M5T21pol*3h@E} literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_digits b/tests/testthat/ref-CatTable_digits new file mode 100644 index 0000000000000000000000000000000000000000..1804d64cae0ab2af4eae58e54ec5612bee41d121 GIT binary patch literal 670 zcmV;P0%83hiwFP!000001I<-UZ__{!-K3>TOK~d@_qiaYm(_lIw*m=?pTGgGp>b)X zrmbp&;Ljsw5+|P6O9M9!@s6Ko-@JJ{c0Qj7A;#ihJQCvr3eWL!D-Ojm-5A|QqFqnH z!Bi)yT)coSW)XAJ#L!_H^Fojzlq^rd6qHm-F-#-oWEl+GYhdb2shxeY##WOqVH%Z8 z-aM@-Q>*I>YeJIVIF_I56>C{5t>xMxVo|E(x7b+wK?U6D{>Bkx^Zg3BJXEavc?n(5 zIlNm}aHr$`{9G;ZkNKzIGtLb?IncK3l_;RZz5quegzk6>pxppoYLyu3Nsle1G2PJ@ zNQ#QoZmR`oOAJZ6$Qi!ejXwx*%2k!%eT)o0|nlB3?NZFO34TT{+f8euw^ z(sPD~>ZMFDE6_atHv5 z#hS&Yji1-m4|oUHY}?tazFIU@jj(2LaZ^3an)@DlRzED})nh;TxSChX*&nnVQ7nB% z*)jI;wd!rl$)?z{*tM=4ZNCSX%S~vyP+wkm=q4OJY>2Swrf2`N*83IvxObedKQ@oE zW^ui!=J4ewG>^?C+KCT-^;k~7S63hIZ$B;O%?*(iMDcz-5MsMdc30y04bwZyt-uHX E0J0%QCIA2c literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_explain b/tests/testthat/ref-CatTable_explain new file mode 100644 index 0000000000000000000000000000000000000000..242cee9ad626af2d2a4137a1e20886cf59a231f1 GIT binary patch literal 484 zcmVia?ctLJKbTkWe)gw&FD{)L3YFL!cVvb;TutG-^ppI7Wya4bQ?XMp0bP{ z{Syb8M}W1>+_!lQEG-3jnW`qQ(pvIrtfA_4{SWH06wk2!zsQz3eq{0I*Y#@*uUYsz zGxl~Qrj%o(+_q~sAm!b}I~%#X@3Y(J$lzQ5W0+n`04PZ=NG_-R#o&Iy2e^(GZ-=Yi zy8)rdKDlw5*5482blCKr+fvfXb#C20()TFj+&nVH3TOT1o*6IXisX9Qd>J>7MOm!K zHj$2N_?eNb$;DA4pB?7>(r;VeU-zzqufM@>v6|h_6kh#wS0C@bf9^Yf6VCA_2wfcS a?i%B+X7Oj%hz>g{v-`hqjt{=Z1pojR0P3Uw literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_format_f b/tests/testthat/ref-CatTable_format_f new file mode 100644 index 0000000000000000000000000000000000000000..9c233d69902dea1be71a6adb0209dabbca05a72d GIT binary patch literal 384 zcmV-`0e}7~I5cnSWfrL|WJU|HNA_kb`3L=Cw%wr94q+v?5 zEY1ue(J(WzggENrcy45=>j}#PHr&`0BSuDy9g;Y^usjr|i^$k1Tpsf5R2SIDoP)AF zAmhwxJ~g-6I&^V}qFG+_Z~IZQk~y|Al4e#G<++s=dK69dEc-+Cd4x}}{$GU97l)^Y zTh$v8EWSea&!|?~6qy8=U1ONcdA-ebg literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_format_p b/tests/testthat/ref-CatTable_format_p new file mode 100644 index 0000000000000000000000000000000000000000..ce04295fccb5c54ffafb686d7dceb5047ce7f014 GIT binary patch literal 423 zcmV;Y0a*SYiwFP!000001I<%CPs1<}bv~$Qfi}P&@PY)3l{j(Y3`j^U>VJ6F{i+y)pimoF?gsv2!Ah0_l)y$t1&zO5g@ RW?N;n{Q;lniQhH_005(S#W4T? literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_format_pf b/tests/testthat/ref-CatTable_format_pf new file mode 100644 index 0000000000000000000000000000000000000000..e2b69a285df934b89ba4bdc607590a24b0fe7cbe GIT binary patch literal 503 zcmVA|Ic~NBiqLLP$y`X+qM8cjxZ-M5g4evlFIt=aSC8 zSDY$XfEE|fhajiIg;+L(B%{oQay5i>P77EtQJ_LiOJ68aVNSUV6^Nee@S+^JUYgOu zrq1fKLJDyTNwp6RC?}SDC6)?Y8gYRNg-{}{ zl4f2kq+gl&mYFDbrcjZ}Y8%o>QeK7^N5xWJ87A1y0{mc1?0aSqiwCg)t&3-28oU6v zdXLKGj(&b8O1|Pe07p>9y2aL`BxmTR@&es5t^Su#!Ck@TNm z-K?DXK>Y7a$Y}uXLJl3|zFL{qLC!kdJYcu^1P~qdmOomJm47Xs;)q?WVHLvN1J$djh+0)#N#1 tIQnI7t{?8cG_}3;+njl#tNHe`=cG-%ts1XhnCbA|o9P?4+CT`!XcR{%9(Cy+JkHS=B@jncsv$)~OcckdWJDeh zg(=N&niFo%NiK0JD518nL3x2wm6O6z1QbZQq77;x0UAuXCdg?qpmO&np*c=z z=Gukxpj9211<6-L-t}N!Qwd6365$Gf;DV@QXNUM^2VkUhDw7hp#+jE>FK0u(+3Ht(f^R+AZq?p2Mz>I= zUU}zU&nxp3RCn8XQ|mb##?}=}iYz0V zTR2?J1SYQy4)+>yu(bUPv#3mS+vpl!zhScgHhK>fwqEqj+0(;iQ=9v4RXd%~>2$es Y8<(8XN6^S0wpT{)pFO30@?i^iwFP!000001I<;-Zrd;rq~*A=5~m2@9}ox>P%eb{6m=`mPw1h&6>7vZ z0_?=F)S&(Ov`bkO87V^0TYV5$!=2gPA#H!XKnO)>87)w>wBa>8zM(S|Bl|h6i_8Vo z1mBVXS$QN=D>O53FgHq>6C&9xIuof)Y9aj3z1N zKI4M&JV~`8xkrRZ(jp+ODFB)jgNO!I$%!6-9QqK7Ft0%Y$*J!w7QkWJ15lWODi2bq zg5I*Q?#pS`6c{;C1A$vj=F7$s6u2b91CYUm?-a}vFQ$;5eO|zOFqDGoydaq`4}>B# ziUXs_LNhz-_~bzRj0)Tq;m{fYsX|{eP|dTTk^Y8g7k?Foswvggni3ylLK zSy)1e?w5@*3LCbSwqT0xi<}@Z2P?HF1MG!54aCExM|DwXOpBKZX6cjX%yqe z{CYj<3YX1o-I^JV4Zb&rvVEK*H;1}1#~Jb^HkH|zZ*_NRr}$ysO0&_)iIuzQcxRr> z4iCmqA2J^vT=)*doGl*tz3R>Gq$9^lhPqq)xjmL`eOH?*`Tjd;k5&Rbk7PDa=JwO$ o?n_;@_x9-CTeXkt(;aZ@iL?AOsuungbjs-YFHQfur^5yS0QGMMcmMzZ literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_noTests b/tests/testthat/ref-CatTable_noTests new file mode 100644 index 0000000000000000000000000000000000000000..73ab1b715cb4adeb921377dcc0e4d62c84a133ab GIT binary patch literal 565 zcmV-50?Pd#iwFP!000001C><4Zqq;z-8ca?!L${K`&^LRi{CUM=JYB^v@M& zh-48bH*i7}B05$BB9XIR#~I@!5JBQ(Nknv; z)3GJqrb!RhX>MKNTSsR|w)0k|YG_S*a@snopBraHIzAM4Fu&F?7j#yqeAT!qvQ9c0 zhHB}Q&(&L}I$f~{5Stw>tm+*;UUq+OLcHnyY9G$_p|%sZ8vS% z{%9b2d($He07zIYS)BIqi^l$fcd%t?S7mcsx3)o8GWhb&K9=pn2)$|^>&ouO;);kSg{>9=>Z9e58w#bs4+BB zU#dgJ*B922({7_Shj=ue-JKnO4j5wr3xf^|LI)r4_sF`ek7t;O%tPkSTd5>OT5~;y zh61S}f(eh0l$Z#JR7O=QO(4pqr-evC%2QexV|&3BQB9GO8P5*X!Hm+bXF?l5f|Q6) z$6y0U&NTpuK0$Lq$KirfQU^lgf-2<`Lb)+Y*E_RrfK;amttgjx+}F9fEZx9rQ%-+_EkFu!d?gfVK?zQLDwKn{_INP;j`+qz7?uR!6002Zsq16BY literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-CatTable_showAllLevels b/tests/testthat/ref-CatTable_showAllLevels new file mode 100644 index 0000000000000000000000000000000000000000..4defa1da7e9c19761f51c1e00442f78172dd1c3c GIT binary patch literal 530 zcmV+t0`2`DiwFP!000001I<)TkJB&^b<-BMT|kTW56lHAd$If-=Z3^j-~cxiHeNPT zyIVD31%G~FlEz@CZY6G1YCL^@Z{~R>_2)GqBqQ@|MzVPyUg6^lS&$X!KZkY3e87Dm ze6aPw-D&c_Aah3b(dKbk=>z3;T-!0c1S=ueg6bRi191j97%BtEXvh_(Jb(m;oXe2K zWdXT0v9$^}v$s;z60ay{~{2JU#@JdDA*?W*p33;Da76V+d~?nh$#vTARe z&ZU&=d$+5)$CRkuHMQHPL@QUjZFR=S3Y~s)X9#3G<8u7H+_)#VIequ;#$bV`=qCMJ zj?EhqW|Km1KX&`7Ywj9X!`GkC?NLphCmCKnx!Vtqn@>&M-S<;?(mSxlIY&yxNXK6X7$LDO8y-XV=yVa%iQG*F$ zA(b)U@w#)o6~bDuJ~_b2gZYgRLP4Z>1+ur!g+a=q$%+P|<Q)MIr=~YKeW0skHs+ zlG13ZRT?_YI!?j^##An#KPKT-B4OOnn??zkdXtj1uqR=$B@uaJ77STK1lgBLqG$t# zI#9+3b|%G>8kXpjRzqvaY#Cq#o zqnSYPp(Ww$F^TqgQiGAO0Tl686g?0+BEhs2BzclJC{TVN5$Qy1lUU+udCLJ}(mny? zK&j%;wrp4}$`Q9#LIkUiXTqseOE3&Y9M1Q#oh1VA!E!x~2S+^t8&bK_qeG>>{oep`(stEM_ljjHrs8n8}Yo)tM9OV+|;9W)y>%X&8~bHOSP@? zrl^XsZ?3kx&0pQ`F`f69?`Cyas$nT_?g#5(IoWoLSyR-_i5|~7G1~0Y6Ma8?X?A&2 y-j~Hv-2N8LuDPj;U*vc?$#U_txcjuJzLv}8vF;{dM!)ALzo$Rmsze)b2LJ$b24gk= literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_defaultPrint b/tests/testthat/ref-ContTable_defaultPrint new file mode 100644 index 0000000000000000000000000000000000000000..9f884d7ccb66293e4c4d2479778ceff02cf0dd3b GIT binary patch literal 521 zcmV+k0`~nMiwFP!000001FciblAACPlplH4CSlk403GpVO0N;pIiHY2a>X`TQvpNS zBvtwOO$H2WK{)QgNYm5mnQ6)2-!sORY_(jl<*MCA^bu^$-qE^}==$xw5)#2G9!ud3 zNVV+~pEySercFo?a)3W_&K0e`#Nx3M9?*nr4M-vaj0vQD0@m=@3qZfU zwW1_wK_b%W5nn0+iqz4NSO`#_7l+%M6=tX}y|>_O zJ24`79h@`{&{4nO?Rd6U4?(%Wi9~}Vu0jRI%{n0_PLPHp_~wN4MqlleLW1?I4D0!1(&5XmY`vt^;b(3A1iR-U=%R7zb zR|%Xi5#8|CwuxAf(}m5&_VdI70(U%M$^{#4UmY zYp7BXfI+P9w3GxD9F>w@gVFY$Bb5MZz!NlpO2z;Upee^mKppW?=)qw#qX4Zi;w1%G z)HN@Uw^AgK>6pk6EO={b6%ZlZ=cR1p0e#IL0{Z^6*3=9^c@^p7G*{!=Bd`@4-+{;Z~M?qr5KF zSpVvrzmAnEi?qs$Y%FJ0o=^Wxf0b$8$<(cSqPk1jUglMHsRpWlXeDoIOb1(h`dXdS zD*usZJHGkDt21S@w?T!+-`V!%RD8>K)xO?cx8ue2sbgn<2MuD9O-1(h4;&ljw4Vh4 E0NQjDxc~qF literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_explain b/tests/testthat/ref-ContTable_explain new file mode 100644 index 0000000000000000000000000000000000000000..34ffc9ecdf2d1a7d795a9f5cf669c62f12f1cea8 GIT binary patch literal 503 zcmV8AxG0|i)nz`l*9c0*VBtWZ3ixgn7*Wz${v%-Y=(t8We z_8TLD*U?Sm03GQCZ>PKUdB^qm zrxkAk`!b2Zp&T2e=&dL*_?+pf5su1|+zVAUo_CyjPDh!LF3O~qQI?sw=Q0yz-unqM zi!x)yWS)&OM2zS8Y^L!4pDa!2u?U~Up*+#?argr<_Amgakb8o>=BMIJkf#y19P(7gHq&9OdT`Oe*SOk2JL zSX1R)Q5B)LYT9~Gagmq?iQzRaR0x_YTS3gzjo*#y4jjqM!N)IMn|I~+vN-VFZ{D?Z to4w5#9)1=3=eqh@9=c=iTkv;v`SsZ4pV@#|_zwU8 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_noSpaces b/tests/testthat/ref-ContTable_noSpaces new file mode 100644 index 0000000000000000000000000000000000000000..fbaa391182861e4a047db289c9d471cc5a42f5ab GIT binary patch literal 517 zcmV+g0{Z>OzAa3I_DE|NUqo>Ybsz< zHc3@}ev<(MlD!=F0MhidW~N*4<0E5i%4X9Eo6ef;l3tw6*#}x@0&TZ_lw2Sf8O4G- z4MMKF#61eo4J?3*9{eQ1CQ+=ws2+My28j{Hk~=^>Fcl!3=AZ}Y-X&mk6gv*+*1o?K zpg5fuRt4CATI<5gUt{Y*Iv5rTMOq5Skq`k z1UE=pXbWg*P;e&D)09Gx)+S*)=I;7Ces_5q?(E-9gK)^UB76A{jEYJO HG6ettr40AM literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_noSpaces_showAllLevels_quote b/tests/testthat/ref-ContTable_noSpaces_showAllLevels_quote new file mode 100644 index 0000000000000000000000000000000000000000..d2786b63b3dc7c30728252b0e149eccce5097c13 GIT binary patch literal 533 zcmV+w0_y!AiwFP!000001FciZlAACPm6yrt$!wXNDV^}8OFPmzpO8ax#WopJ0h_W( zs`B%bG#DZ5A-5bry}W+iuLa-U5kjV9Hl2{^tTAu##mJnz#dF5B?aVvDxCSGlm@}t< zi)EL%)*Mt5=D@fQz87GVD3)NP58X(k5fR0LInb&{O3+x%K=q+(mw-`G>=CP)mSs5J0ZE(2c!AaC0V-pn|=iCsM1V|=tXwI1|w$;DXz|0MG%z9#M(gW4TXQ z_yel#{`ij>kM;N@^&x*6C#;IJ&Wdcb?vYl9{mYG<);I6h$7yehU{>CIMeFQX(~DcV z>aL{an)<4U`l<)|r9Px}{yon&(du_p9~uhsd_lALm90PTi?8{n-ZmHPKZMt(r@_wt XTy&ZEpJ5_SjO6(*0E~iYR|Nn7+rShO literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_noTests b/tests/testthat/ref-ContTable_noTests new file mode 100644 index 0000000000000000000000000000000000000000..447c758d29ca944a32f7e3f0799455700cabfdd8 GIT binary patch literal 464 zcmV;>0Wba^iwFP!000001AS6WkJB&|bkjvFXn{aEaP%>`Joz)R&-{cvz%^~d)*@-5 z)FAQa7oMAjCdJ~A_-WpFJa6o;uL&UuStl!!tV5aN?-RKruW(&+Z7$_|!MKJ((2O&y zfQ$Unct@$`phANK;}iUrQYyfdG?P%s2~DXiG_q(Wm<6roYzZ1g7$`N9wj~sbW|o1r z`PGWxAQ_5qBNu!w7zk9?3dQCyI!2k2&(2J#&<08!CSoAP%nN5w=-|cZ{2GOt&ga$^ zV2UuY)?npqr!t@o`UP7oXA627gqbB#N-)S3T7WXqB-l+7s9_MkCc&+eW1O6EDC}}% zi|ONtSAzjY6Z#C#0}^;Ef}L|Ns6n literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_nonnormal_exact b/tests/testthat/ref-ContTable_nonnormal_exact new file mode 100644 index 0000000000000000000000000000000000000000..645563f1f397d9f54ab660315a480e9115a7d23f GIT binary patch literal 587 zcmV-R0<`@fiwFP!000001Eo_-kJB&^b|0{S7TVP=TDbYxN|ohjY@heU5jcQU?ICT$ zHX<*j0f|4q>^P6s4cQZi#2$b1eVO^j`ThnWG)9y02#qIhJBJrVQ}i0v2~(!sUUAA4 z2{>LbY9(QO*#a|+6(iCCj8N7c-(Za4nBp}hhOV$6oZh$C2P{BK0mh{!TCK2Tn$RQu z4!D9SkfcP)PVp9FEg%c8C52^$8D}2pBZRURHGn%&PPy?CWiZ>$)!>)$$_KxgIP(j- z^IhhFf>}d%(1^M@?t}iiQMtBir#>XW0A|<7dX+P3T`xx_iGN4{0v>z#@ zyog!dtFXUbWOW0Orry&T(^1i zI=8_`S$C_eIF0Zkjlv8s4!h;?XAU2Rj;}Xy61($V49NP^=P&n1XuHpoXP_|I{7U0& zK=A!GFN&xf=G}(LPg3mj!!SGx57khORT)1FGj56`tfC|uq!nfUj~R_?)6O;4ZMxeu zD%#DoiVjt82rt?R)EeX7P_MpLWmv^O;%J9Ae{fX-8$I?EE`LYcyFB?8@2b5UWjFGR Z=5e``zr7FmMb?Vw@d>fhohsV}0075$8Ych% literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_nonnormal_minMax b/tests/testthat/ref-ContTable_nonnormal_minMax new file mode 100644 index 0000000000000000000000000000000000000000..d1b626830262223539ebe95a8625c2dd6dfeb397 GIT binary patch literal 583 zcmV-N0=WGjiwFP!000001Eo{RZrd;rrI$8ok=72}G)PZ8+CV^XxQNs_pU^`K7&*wc zY75l{SuN0?PdnOdTCq<(NaW0W^E7-zeSc2~8IsX(K!&4gJH;0#WAYBy5op_PZv_X< zJVEEceZ@d5T3|w{2Bs6!>M=8ZLr%TQxf24vl&YxTGfl3t92!b$}f23eQIE0T_ zEty79&XnpjKT~QXvgp#Ui?p>)%@+`$YEkJmIDpo!>VyKeA%M;`5)UW1r@*~hR?0@# zcXg*!Xv>VQPL5|elwps+nWw8BtzH~0Q=Mht`yR7i<&4(MmrkX!Oj|nlneUxCCXbHU zQ^&Y$9pkNIMqhG_zjjPDC(}L0Y=a8hIwq|ru-vBBn(nI-)|O&A3E5cOW&=cII8lS2$5wGq}%ZM0Iqjgd* literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-ContTable_overallPrint b/tests/testthat/ref-ContTable_overallPrint new file mode 100644 index 0000000000000000000000000000000000000000..7dccf71fd3e566baea85b8e2315a39423821b3eb GIT binary patch literal 361 zcmV-v0hazBiwFP!0000019ef$Qo=A44J{7pfTH*TS%%G>Ce5Q=`vER>TOb1+)5o-x z&qq^ep=jLXCg+@-+Z?~Rb>x7)d0rf7`rZ1p*fy6qE(`mK~PLsNFnCeY7t;!J=nlHRv-l?kpOu%v8_Z5 zq_ifK2N1>=J!K4pC4>YO3}J51m`DLsTwo>?1h&ICf-oGkVh2&7oyU?(gvOplM|~oj zG_z%P46O~SrLHBnR+1-~uB~Lz>4u?>@;;0v%`_&NPI64@&GOt>vUS1pRccZfzTOqa zfiDuX`pVMWK|QaFvecD>c}dJCl)IvK_Ek5o_nRu+x~xi*G}>s_okdv{f2Kdh)W&I< HAp-yaG1sZ^ literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_2StrataVars b/tests/testthat/ref-TableOne_2StrataVars new file mode 100644 index 0000000000000000000000000000000000000000..a54f80ca7a97ca68ba70bdf91ae00832c44d1b05 GIT binary patch literal 1128 zcmV-u1eg0CiwFP!000001Lc>^ZW}ic$JerB)F~P(b$TqoO9A;p@cYAPo}!mt*VZ~- zRI&tV1GF#IM+`bct+XR9CFfoP_L8&IaOOWh4&^`JS5-BsE+-e&87E#XE*S{p2=Hn1NN1i~G#1!ECtB%o0{R$2~P$%dN+)xRd*h zKJ1(bHWS2kZw#Um5>96p|B6KRmd#geutb_ zh@5c)L|OpG2$7V8l^t?6Wo9BJ$Z`YL5V<@s0cT$uZU7Z!d?5P3dN`sM)P$BWFob3} z4M3;{K8SZ^1eZ`yuX)szILTF_Kl-yp{!S@+vn>;slX5AwKOiSembhnXGq91Edq&(#reg8Pt&b9Sf~rm0f|V~S9_@riRX>7Sbo$f5-a@G8$iN{}c( zE%Lsp%O^V~`CW!wsx$N#f}9OpK^stz+JNE_a-=&kXkys3g5t^#$VHGxBqtWYwUn*E zBX%<+m68hu3yCd5Vo?qNjXOE5KJIc(VJyL%sj|cd;ztl^*k36kMK3vQr0wV)GT8g* ztpUizAyFSw8-}CgxmD+o3#o^X?z3H8@^V>~kTbMg#&hQqLnb3GmWfN9a+J`CKn#>i z%k#v+K2YymIP85ajLf(@v)R3>xwjaU6@)mrt3BSUP;HeHmpY3kZHPs~9mER4D@%xT z;1v6(fUhHx5~tuE5~;5%pP9qXOs`ev;cf?!6=@(l;4pAWT$jE(;n`EijRLI#Pr^tb zB-bj+3PET=W6 z3-)9jUeGvfq;Y6ZbJmXf9NIt5oOvt8|If3!n!ulnebbt^OL+WL;lB%2^(zXNE%^bK zyw=NR3rp_$b?6G2IemIrEeiI#dhz&m*}fKD{rt3AubWNb&8K?t7hk`uwuN_)dso`O+q7Rw zuGWjXYZguEGk5FF>O=)^pn_P9BXvqe!?7k~)3b7YxFa8y`=J_!^5J=~?uQray(6e? umqGciCo*}TWRU;zN4KfF_PK55?C~GgZMp}b23~x_-~Rxmq6sM+4*&q>MNZYU_;ib_cHtCDjRdnAngwSmv!EigH7wNv1T`B0I)oCy#fqYZ%2?_w zWY6f!qi>C7@R92biD(NlGHZ+|9pSf#QxFQHJ2g(hhWv+Ir!otqBsk=%z^XojB~#X5 zMi`xYFnUGM7z;yk(3<4yGq9ML=V1Kmr4dqq!iZ8JLy8xYgGBE}qcdv8exaL8keEv* zjf2dDd^jjcxL|^zCmfu4qsap4GUOMPLWSDOQOOM!P8ra#8PQ6Edp4uubf2j3-hvAi z7sh~BZz&G_ASRB=JaRO|eWy4qp7OwHyEN*-VX48}NN~PwfQki&KI}*zq2p$3ZUyHF zy$Qi#-<%mM3l+@VsBWF$%z%_?+lEzeL~xk`hj~f7kJ?QNjz@w+9}dkgf)ie=qiO{g zVEs^8KBVkOdx9BBnAS{nC{g^9x7EzlP;U;+_yp)TTFg+vc&A2sli@avTddnhB}Nv!#p;WhFd4hwuMiIQ~ClvY6w~tbeoC;>$|ckYBURCzI-gIyxB+AtGX)J#UTct7wcl1ze4dW%)v|$Uf!0Qa)RaZ?s31F zu;1jH+ox^0o7nnzx38+=FtPI~-~52;abHjDVeZXT{N_+TOu4Eyc~fkPsWUg#VgE`8 z&#{A{8-wahH7(2)nd?p~i(V`Jp;>=oR`qb~U=vC2w9{SdV;)KQ`df3zoASOa*6j8d UYYuoi`5nH001}z8s~8FZ0P@C(+5i9m literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_noSpaces b/tests/testthat/ref-TableOne_noSpaces new file mode 100644 index 0000000000000000000000000000000000000000..2114b094592ced649b5be0c7612bc7c696a9f06f GIT binary patch literal 842 zcmV-Q1GW4giwFP!000001Ep0f4S^HpaZKNiOkDm{?hnfd11d3*^!4}u^V20Oz+Fx+w16Zj~CQ4qqpL#3&% zr;JdE6+;mvR$$65t3Xhlq2VZ!49hyOPYH??=CvIvi6TKUtsO^_V&MoWCXMrea*ZOR zux@z-IIwMaG(02}ZYl@`5Hr)h9JE|OZ+IICsd5dpHFS$Sg^~!mCfJZG#4#f`Rp5d{ z`w~J-XsqQG5>#W-gb(2nc#B{mYN|8M0f4Rrf#V8MMm_vTFh$8{Any1Wffic8F=YfZ z3L^zr)9N`Tsw6co8Ayfla>h&=;Bp-j%$ub5(6F05G_^6JeF{};teOFFH%sOXSHi@& z#G-Wof(vXeTak!nde$mz+>EJ|*z!%0Kr%!c`aKJF%M~hE2e+6swF}s*L6OB)c@lvv zOWLhfTWr^CKts}ZloGLcL$$yKGd9v!1b1>1+qgj?yi|y0P9e%u2;pmmz{(hGl|^^q$mYLyG*-~Ww>vM4x)Pkh)~lSg3;EHN_#Nl!K{(q zD_Xz)iV@5s7Q#>W3{AZ!4fS$_BCWx-XGrN4L#;=^h-b<%T~3O0 zo}g%+#0wPV)63=;CokgSDM!)g+A~535${gDd##Ic{Ln{sm?zKZ3%d8%#&Ld^7D*0n z>bZ{}lPoTl9q%~L(rL2lg2QB*%;PO3zH@ghdkUW1rnA&lIZdI?>#yIw-_!(?yT|2h zODLY*KF!lbPkU!~%PdP){dpJh>=(`+mwA5}=1}xdPKs6f(4X-ko5e*kOM26?)pE;1 zLs+O=&WmC7?aR literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_noSpaces_showAllLevels_quote b/tests/testthat/ref-TableOne_noSpaces_showAllLevels_quote new file mode 100644 index 0000000000000000000000000000000000000000..f72e7824e47e1fa988e0498e932d91578ade58f3 GIT binary patch literal 861 zcmV-j1ETyNiwFP!000001Ep0N%rPNvdr!kjlu*`M{M1F54j`qDeY}hVAU3sf`g07*rjTs2Py3v*g}z z6--PhBAo*eLJ~c8B9YDXjERW0GiFK=BQ`|>$q;Gi_YK&NYZ$>ggdw!4UBX^93Jo!l zClSap)NQTWqFb{D4JqGIO2m*2)dCmHSSw!Y+xVdvW+ybUQZ#C7~81!CVkGBSW^g0+fx;fVEDA0UMzfp zXmG;2Dcb|uhnJ80`hXrlncl`^`BpoGlBHl+n`sZSwD1ktLbOi+QKp?CIdg`JVh^T0 zn9<6+C5~UeMN94xOX;V3M$Eh`HS=<0M4cgG&rr%Mh8d55Q}s$^ofW6g$zAcrs-=MN&NFDE!>`-eH6gU9;Gl#cOMXlZUOe$2d=)(HC^@ z^8z}*%ZfCI0P_PU_%U53#iH#W;e44*($z-7Ax#yIw-;7=G?r|~g3?|dtr&%`N*7OCwTP&C9sw4Lja(|KK<09_>*!dLOh|h4b${sqh z&hc`Z6zMeWNL{WLUCTeT%eM<`jj?0fr6txZi7V0VHlk~i` nSFg@OxXwDoKZ;dSWcOJ*LASqAv9c7wAN%Z>LmQ72 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_noTests b/tests/testthat/ref-TableOne_noTests new file mode 100644 index 0000000000000000000000000000000000000000..f009b5b574711ceb78f0dc283e901fefb6c0e775 GIT binary patch literal 705 zcmV;y0zUm8iwFP!000001ASCYZ=5g?Wj9IHq-wJ5_FBo8N^lwZ8@p0}MK8UQtdpSb z2U>{K{`sn777}Beti)oThnY9?p80i^W!W-2TQ0KYnP0B(?|XKhUE=+WDKjiTamo~E zPI5-A1jdVDp83NouI6xWI2+JQ z7!GwaYVIs_Ffp^a4Te(_Qlgg)r(goZl>!X*#qm5!lQbNS42L-k!Y_tnR*I8r8D*gD z)LGWIYyx>aj3iVKhd$(Jeop&omSXBRgD`#q>E5|51sfmF#Wk zr<|QH5nhbG+tfR}ee6GmS@!jGpM<=}kbSjtEpDxcxK$r}+F$I)sdx3xk$mT>J;~cm zF*bG8c2)P(lKfi{*nkFW7OeS5yn09_`_Q^SK)KcrGM+p2S0mwIR291pK3c!>&nH73(ZiRRZLSj)jH%h4<2OA8*k n>|(IkBs?3B;?M3_b@hGiHstm%>5d(O|NQkITYtF@#|Hoaqdrhw literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_nonnormal_exact b/tests/testthat/ref-TableOne_nonnormal_exact new file mode 100644 index 0000000000000000000000000000000000000000..815828fb5b44b326691d19207c4e4fc6da86c6a8 GIT binary patch literal 872 zcmV-u1DE_CiwFP!000001ErPUZ__Xk$J4F@HblFrLxTq-zaXX3Wcg=eKkx_e2)rOo zd&t^si|8*knKb@+#5qm6i<1r*lUCd3@15^_pSs_VgCOV!2mM~qKXB6%_$Y!wa0KH4 z*QT1D3dS{!1PM8_igGcjHV%pVs}`ejVI&E)pnB3Yb4EfEQR$f@O+v*f$7ao`az}B> z_ynuDj7exB8t>G@ZEOW*YQ4}gB%&fJJhOrmg+ciZ{1Ui?(~WGG5V`uBxpq}{=8RM^ za>=M+7erFQuByFvM8ZvK*b^$IvA!UR$CT~%T|sa%B*3Urb@k`28c>l-#bCG~TyW&{ z9+s*MYGB_56%0yz6pX-uQNf`zpc9W_Ig84$#<@dS6(O$^BD8^Uu4+c*&TZ&wrmk~P zpMC-b4rP#-M&5-<*8$OLjE3u#nkwH6YN@E%nSo1HbIGlZsBwMaT2m{Z;u7M3#y^!< z$Wf#46_?OdX(_{`DWJxX&{7+DSV9cT5COv-7*UHN0}Si7xx~_<^g6JF{u$lo4>%{L zb#E1x+QU+oSjNI(8DT7$++qoY2p~wtd$D94SjsJy?#eKhX1i^n-6daESpW)Ssi<`q zVo>t{OD-E&LfF7iSqIaCD^_5%4PJ_+-PepNbe- z$r!J+##wQTqX?$|kmJ7bFnvg-#WS7%b$q#8Etjj!qI>yYs%O>}4EpfVtDnJHwt(SH z;C{h_;6o{FN?w6vnJm&AB;!hVQfjyRy=DE<7ug~u;UZ0zB+O@%`rC7y7fErSlkj70 zajz0XbB^XU9HZp6E7w3R zpzFI;-n|X?P;`VG7n|(1+v99KPl|M&cDk)Mt33@pf`+>0G%l;Fhi)#>Tvg}{YIJI+ yUhUCa*K%lR;gNV)VOYlKdt{$}D>g}y-DK&ET>m7+2E2n`?*BLLo#}3%3IG6XtEzzj literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_nonnormal_minMax b/tests/testthat/ref-TableOne_nonnormal_minMax new file mode 100644 index 0000000000000000000000000000000000000000..919962eb87611babb1864f946e3793367c398847 GIT binary patch literal 856 zcmV-e1E>5SiwFP!000001I3l!Yuhjo$DK6o){Z4DT~<06=w;wQ5&CWEVSmM52Bi;f zMkqI^9Gf?ymRj7P!vz)nx$qY5U$F^mUP z>SlVz2$fhd6jEXYrfkt{93uPIEN1mWa}-L3<)Uk*1cgXp?wOTDp`e($W=XNIM^Q}Z z!c|iqp-?Lv?bOq4YyoC$ywDLOA{1txS-^=*JNZrg5-5k$HSd?8Z2jF_hbo&}BNhZ* z6U@mKVgwU%(`;TM4p%8*ld=fxSBOTGIRaY}oDC@uEJR!Xds`2v(6yI_jxgHh-W2zULvfb3Nrmh){~4C|g!PH$a32(q84VaPK2PWx*DYgJf4@|w?Wx4^AYsJ9d1yf*SuS7fT12Ab5b{kjl zF3wCrCrN$l5$|%T!3b(kdyzOda#|G0Ed<<5_2Ao-UKZ7au3fWF7BG@yO1x97uS6o32uu7k8UHPl|n>m+|Tw&L21BJ^|cEH4t`Q73sr1 zpLh8xu98(UPhSu6Pb*^own|98fxo9Aov=FsUqt;`Tw{mE0o#dhM05*;uG# z36fIu>x(WO$)Ob5fX&71csR4%pLc|iC0Q*OWVv$X4u8IqHQC^~k}Mm_Pb_CCq#2DE zOC;zt9vW+kpP}BmnhQ=Nr9j0Km~urUsv()eOfwpZY|2&%q!MpRK&seh3kPSp$G(5o zMi|}Ar4uy5K+KHf2=ffGEBq>gQ0^Kz7o_sp)T?ADNTny}ObOsP2MLmm33gOyw2pbX zV35mr!d57PdAXN2PeJ3*G6ni7g71)V&>BUUOhDu>e8xE_Y$y$B;=>pO#kB(FO_Qq> z5_FhnAcSWH^Q8h~V)Nz`Q;s1h>dhyMdT3%caHcSXz$`P^O;f1LLXh7)620C9%`5T&3-35A>y${{rx5Z;fswquxOB?#n zzG>?lFSx-Mbgwa)PUz8GExcL|yE5+5yB~jSYszxAVsD21x^R~RNUkR#|J?UK0xOWc HKm`B*E&TU2 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_showAllLevels b/tests/testthat/ref-TableOne_showAllLevels new file mode 100644 index 0000000000000000000000000000000000000000..192c819055adca6124a9ab7b071cf7c591c9e4d7 GIT binary patch literal 917 zcmV;G18V#qiwFP!000001Fe=@Z__XofYWYcY>0JJhXyamFG#60S-!{q2|NNXNYfs& zHrpb4QWC>pDN>kwVkJ>3D5kDhQY@@@iV5xdW)#HScS3oFQmt_2iG@I^@q9OO zh(u%Ki8VwbIo6&ygLH(#%=1k_oY5dl0Zy3q#gs!jnuj$}wuWJVeyL8a5DS7X2-f5r zam>i&X74rP&t=iu|)y$liik6 zh#X~Dc{Sp;(9CZOl2B1DvGB#9&4trjz_}&+gc_r;wymI2V#7xv7BaXIG7y#wXi?BQ zZZLTeLuvwe&_E(K%1aGgBNJfD!L=a))#bZHjY*xG0ZfHQl{J2V3b?ipYTz#vVxGTwz*gBTt?qT6v~A3ZFD8S-Ia`ITs% zjlQ-N4dajHZ=d7O5ctr%vl5<;t4pYMR)YEO6)Tl0i&<(Nks2*y5oNxI&aPnY-Gt~^ zx~q(4?jCjRgd)z0XYNW$>8z-6y)fcO{JU|lxX;J+e|`b~>9{{%%;$^MEWZ3FttaN0 z?DpZW*FH@rIj;PC7fznx#&rw=U zM(qJQtm?eJt5EuGv?Z!ReiJj?uZsJK)r-6umvs?ycz9bZ^Li08s+Q%XSjCJEib*lc ze-YmBs+^WKzDWrYUcCSC@v>DNj&B#!EnE5Y>TXufBZ<8lFP6(<6}LOfr(f{$c2UK* z2YFRTTn_71c@wudT~715m=;m9bBK$I4ZYI0X ryV`?nZ$nt)u+-rRCg|!Ls#jp0{II{DFHP4){R;p9#c9D- literal 0 HcmV?d00001 From 2d4999c7e5dbd3e7614a77246d55ccf8c552290c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 08:56:58 -0400 Subject: [PATCH 048/219] Add regression tests for svyCreateTable --- tests/testthat/test-svyCreateTableOne.R | 158 +++++++++++++++++++++++- 1 file changed, 156 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 5ae06e4..f1cf27e 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -51,15 +51,169 @@ datSvy <- svydesign(ids = ~ 1, data = datMw, weights = ~ Mw) ## A test should group together expectations for one functionality. +### Error handling -test_that("Data check assessment", { +test_that("data assessment detects anomalies", { ## Should give ## Error in ModuleStopIfNoVarsLeft(vars) (from modules.R#52) : No valid variables. ## In addition: Warning message: ## In ModuleReturnVarsExist(vars, data$variables) : ## The data frame does not have: none Dropped - expect_warning(expect_error(svyCreateTableOne(vars = "none", data = datSvy))) + expect_warning(expect_error(svyCreateTableOne(vars = "non-existent", data = datSvy), + "No valid variables."), + "The data frame does not have: non-existent Dropped") + + ## Should give + ## Error in ModuleReturnStrata(strata, data$variable) (from modules.R#84) : + ## None of the stratifying variables are present in the data frame. + ## In addition: Warning message: + ## In ModuleReturnVarsExist(strata, data) : + ## The data frame does not have: non-existent Dropped + expect_warning(expect_error(svyCreateTableOne(vars = vars, strata = c("non-existent"), data = datSvy, factorVars = factorVars), + "None of the stratifying variables are present in the data frame."), + "The data frame does not have: non-existent Dropped") + +}) + + +### User-level functionalities + +## Make categorical variables factors + +## Create a variable list +vars <- c("E", "C", "Y", "C1", "C2") +factorVars <- c("Y","C1") + +## Create a table to test +mwOverall <- svyCreateTableOne(vars = vars, data = datSvy, factorVars = factorVars) +mwByTrt <- svyCreateTableOne(vars = vars, strata = c("E"), data = datSvy, factorVars = factorVars) +mwByTrtSex <- svyCreateTableOne(vars = vars, strata = c("E","C1"), data = datSvy, factorVars = factorVars) + +## Specify variables for special handling +nonnormalVars <- c("C") +exactVars <- c("Y") + + +test_that("printing of a svyTableOne object does not regress", { + + ## Expectations + expect_equal_to_reference(print(mwByTrt, printToggle = FALSE), + "ref-svyTableOne_defaultPrint") + + expect_equal_to_reference(print(mwOverall, printToggle = FALSE), + "ref-svyTableOne_overallPrint") + + expect_equal_to_reference(print(mwByTrtSex, printToggle = FALSE), + "ref-svyTableOne_2StrataVars") + + ## 2015-07-25 pDigits is not implemented yet + expect_equal_to_reference(print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), + "ref-svyTableOne_digits") + + ## 2015-07-25 Not implemented yet (thus correct) + expect_equal_to_reference(print(mwByTrt, test = FALSE, printToggle = FALSE), + "ref-svyTableOne_noTests") + + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + "ref-svyTableOne_nonnormal_exact") + + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + "ref-svyTableOne_nonnormal_minMax") + + expect_equal_to_reference(print(mwByTrt, catDigits = 3, noSpaces = TRUE, printToggle = FALSE), + "ref-svyTableOne_noSpaces") + + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = FALSE), + "ref-svyTableOne_showAllLevels") + + expect_equal_to_reference(print(mwByTrt, catDigits = 3, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = FALSE), + "ref-svyTableOne_noSpaces_showAllLevels_quote") +}) + + +## These will fail when p-values are implemented +test_that("printing of a TableOne$CatTable object do not regress", { + + ## Expectations + expect_equal_to_reference(print(mwByTrt$CatTable, printToggle = FALSE), + "ref-svyCatTable_defaultPrint") + + expect_equal_to_reference(print(mwOverall$CatTable, printToggle = FALSE), + "ref-svyCatTable_overallPrint") + + expect_equal_to_reference(print(mwByTrtSex$CatTable, printToggle = FALSE), + "ref-svyCatTable_2StrataVars") + + ## 2015-07-25 p values not implemented yet + expect_equal_to_reference(print(mwByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = FALSE), + "ref-svyCatTable_digits") + + ## 2015-07-25 p not implemented, but will be correct without it + expect_equal_to_reference(print(mwByTrtSex$CatTable, test = FALSE, printToggle = FALSE), + "ref-svyCatTable_noTests") + + ## In this case, noSpaces does not make any difference anyway + expect_equal_to_reference(print(mwByTrt$CatTable, digits = 3, noSpaces = TRUE, printToggle = FALSE), + "ref-svyCatTable_noSpaces") + + expect_equal_to_reference(print(mwByTrt$CatTable, showAllLevels = TRUE, printToggle = FALSE), + "ref-svyCatTable_showAllLevels") + + expect_equal_to_reference(print(mwByTrt$CatTable, explain = FALSE, printToggle = FALSE), + "ref-svyCatTable_explain") + + expect_equal_to_reference(print(mwByTrt$CatTable, format = "f", printToggle = FALSE), + "ref-svyCatTable_format_f") + + expect_equal_to_reference(print(mwByTrt$CatTable, format = "p", printToggle = FALSE), + "ref-svyCatTable_format_p") + + expect_equal_to_reference(print(mwByTrt$CatTable, format = "pf", printToggle = FALSE), + "ref-svyCatTable_format_pf") + + expect_equal_to_reference(print(mwByTrt$CatTable, cramVars = "Y", printToggle = FALSE), + "ref-svyCatTable_cramVars") + + expect_equal_to_reference(print(mwByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + "ref-svyCatTable_noSpaces_showAllLevels_quote") +}) + + +test_that("printing of a TableOne$ContTable object do not regress", { + + ## Expectations + expect_equal_to_reference(print(mwByTrt$ContTable, printToggle = FALSE), + "ref-svyContTable_defaultPrint") + + expect_equal_to_reference(print(mwOverall$ContTable, printToggle = FALSE), + "ref-svyContTable_overallPrint") + + expect_equal_to_reference(print(mwByTrtSex$ContTable, printToggle = FALSE), + "ref-svyContTable_2StrataVars") + + ## 2015-07-25 p values are not implemented yet + expect_equal_to_reference(print(mwByTrt$ContTable, digits = 3, pDigits = 5, printToggle = FALSE), + "ref-svyContTable_digits") + + ## 2015-07-25 p values are not implemented yet, thus correct + expect_equal_to_reference(print(mwByTrt$ContTable, test = FALSE, printToggle = FALSE), + "ref-svyContTable_noTests") + + expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + "ref-svyContTable_nonnormal_exact") + + expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + "ref-svyContTable_nonnormal_minMax") + + ## This does not make a difference here + expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), + "ref-svyContTable_noSpaces") + expect_equal_to_reference(print(mwByTrt$ContTable, explain = FALSE, printToggle = FALSE), + "ref-svyContTable_explain") + + expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + "ref-svyContTable_noSpaces_showAllLevels_quote") }) From 4e9801b2090740303ad91c2daa3399729fe14af0 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 08:57:15 -0400 Subject: [PATCH 049/219] Fix placement of special variable definitions outside test_that for CreateTableOne --- tests/testthat/test-CreateTableOne.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 6bf4b8b..177426a 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -99,11 +99,12 @@ pbcOverall <- CreateTableOne(vars = vars, data = pbc) pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) pbcByTrtSex <- CreateTableOne(vars = vars, strata = c("trt","sex"), data = pbc) +## Specify variables for special handling +nonnormalVars <- c("bili","chol","copper","alk.phos","trig") +exactVars <- c("status","stage") -test_that("printing of a TableOne object does not regress", { - nonnormalVars <- c("bili","chol","copper","alk.phos","trig") - exactVars <- c("status","stage") +test_that("printing of a TableOne object does not regress", { ## Expectations expect_equal_to_reference(print(pbcByTrt, printToggle = FALSE), From 7e800a7450305d0fd95b3964bdc382a2865c2c9d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 08:57:56 -0400 Subject: [PATCH 050/219] Add dummy reference data for intentionally failing tests --- tests/testthat/ref-TableOne_digits | Bin 0 -> 87 bytes tests/testthat/ref-dummy-failing | Bin 0 -> 87 bytes tests/testthat/ref-svyCatTable_digits | Bin 0 -> 87 bytes tests/testthat/ref-svyContTable_digits | Bin 0 -> 87 bytes tests/testthat/ref-svyTableOne_digits | Bin 0 -> 87 bytes tests/testthat/ref-svyTableOne_nonnormal_exact | Bin 0 -> 87 bytes 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/ref-TableOne_digits create mode 100644 tests/testthat/ref-dummy-failing create mode 100644 tests/testthat/ref-svyCatTable_digits create mode 100644 tests/testthat/ref-svyContTable_digits create mode 100644 tests/testthat/ref-svyTableOne_digits create mode 100644 tests/testthat/ref-svyTableOne_nonnormal_exact diff --git a/tests/testthat/ref-TableOne_digits b/tests/testthat/ref-TableOne_digits new file mode 100644 index 0000000000000000000000000000000000000000..a2485fec14c443155a41824efad690022216783c GIT binary patch literal 87 zcmb2|=3oE==I#ec2?+^F328|w2}x{5k}M4~CN{P<3VUR?r=*B!GXySj^2*H1Tj~^; m6_pj36<4&%$ Date: Sat, 25 Jul 2015 09:01:10 -0400 Subject: [PATCH 051/219] Update NAMESPACE and manual entry for svyCreateTableOne --- NAMESPACE | 1 + man/CreateTableOne.Rd | 104 +---------------------------------- man/svyCreateTableOne.Rd | 116 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 103 deletions(-) create mode 100644 man/svyCreateTableOne.Rd diff --git a/NAMESPACE b/NAMESPACE index 0a1c2d7..02f4633 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,5 +16,6 @@ export(CreateTableOne) export(ShowRegTable) export(svyCreateCatTable) export(svyCreateContTable) +export(svyCreateTableOne) import(e1071) import(gmodels) diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index dbedf2f..a7fc58f 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -1,15 +1,9 @@ % Generated by roxygen2 (4.1.1): do not edit by hand -% Please edit documentation in R/CreateTableOne.R, R/svyCreateTableOne.R +% Please edit documentation in R/CreateTableOne.R \name{CreateTableOne} \alias{CreateTableOne} \title{Create an object summarizing both categorical and continuous variables} \usage{ -CreateTableOne(vars, strata, data, factorVars, test = TRUE, - testApprox = chisq.test, argsApprox = list(correct = TRUE), - testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), - testNormal = oneway.test, argsNormal = list(var.equal = TRUE), - testNonNormal = kruskal.test, argsNonNormal = list(NULL)) - CreateTableOne(vars, strata, data, factorVars, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), @@ -42,32 +36,6 @@ CreateTableOne(vars, strata, data, factorVars, test = TRUE, \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} - -\item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.} - -\item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} - -\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} - -\item{factorVars}{Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument.} - -\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} - -\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} - -\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} - -\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} - -\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} - -\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} - -\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} - -\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} - -\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} } \value{ An object of class \code{TableOne}, which really is a list of three objects. @@ -78,21 +46,9 @@ An object of class \code{TableOne}, which really is a list of three objects. \item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} -The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. - -An object of class \code{TableOne}, which really is a list of three objects. - -\item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} - -\item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} - -\item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} - The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. } \description{ -Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. - Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. } \examples{ @@ -139,58 +95,6 @@ summary(tableOne$CatTable) tableOne$ContTable summary(tableOne$ContTable) -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Make categorical variables factors -varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - -## Create a variable list -dput(names(pbc)) -vars <- c("time","status","age","sex","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage") - -## Create Table 1 stratified by trt -tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) - -## Just typing the object name will invoke the print.TableOne method -tableOne - -## Specifying nonnormal variables will show the variables appropriately, -## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage")) - -## Use the summary.TableOne method for detailed summary -summary(tableOne) - -## See the categorical part only using $ operator -tableOne$CatTable -summary(tableOne$CatTable) - -## See the continuous part only using $ operator -tableOne$ContTable -summary(tableOne$ContTable) - ## If your work flow includes copying to Excel and Word when writing manuscripts, ## you may benefit from the quote argument. This will quote everything so that ## Excel does not mess up the cells. @@ -202,15 +106,9 @@ print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) } \author{ -Justin Bohn, Kazuki Yoshida - Justin Bohn, Kazuki Yoshida } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} - \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} diff --git a/man/svyCreateTableOne.Rd b/man/svyCreateTableOne.Rd new file mode 100644 index 0000000..ee84153 --- /dev/null +++ b/man/svyCreateTableOne.Rd @@ -0,0 +1,116 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/svyCreateTableOne.R +\name{svyCreateTableOne} +\alias{svyCreateTableOne} +\title{Create an object summarizing any variables for weighted data} +\usage{ +svyCreateTableOne(vars, strata, data, factorVars, test = TRUE, + testApprox = chisq.test, argsApprox = list(correct = TRUE), + testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), + testNormal = oneway.test, argsNormal = list(var.equal = TRUE), + testNonNormal = kruskal.test, argsNonNormal = list(NULL)) +} +\arguments{ +\item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.} + +\item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} + +\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} + +\item{factorVars}{Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument.} + +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} + +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} + +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} + +\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} + +\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} + +\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} + +\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} + +\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} + +\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} +} +\value{ +An object of class \code{TableOne}, which really is a list of three objects. + +\item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} + +\item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} + +\item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} + +The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +} +\description{ +Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +} +\examples{ +## Load +library(tableone) + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +library(survival) +data(pbc) +## Check variables +head(pbc) + +## Make categorical variables factors +varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + +## Create a variable list +dput(names(pbc)) +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + +## Create Table 1 stratified by trt +tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) + +## Just typing the object name will invoke the print.TableOne method +tableOne + +## Specifying nonnormal variables will show the variables appropriately, +## and show nonparametric test p-values. Specify variables in the exact +## argument to obtain the exact test p-values. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage")) + +## Use the summary.TableOne method for detailed summary +summary(tableOne) + +## See the categorical part only using $ operator +tableOne$CatTable +summary(tableOne$CatTable) + +## See the continuous part only using $ operator +tableOne$ContTable +summary(tableOne$ContTable) + +## If your work flow includes copying to Excel and Word when writing manuscripts, +## you may benefit from the quote argument. This will quote everything so that +## Excel does not mess up the cells. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), quote = TRUE) + +## If you want to center-align values in Word, use noSpaces option. +print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) +} +\author{ +Justin Bohn, Kazuki Yoshida +} +\seealso{ +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +} + From 08fe53af7d224926c5c4b333977e07118f64e864 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 09:07:14 -0400 Subject: [PATCH 052/219] Add temporary refs for svyCreateTableOne testing These are temporary. After implementing p-values many will fail. --- tests/testthat/ref-svyCatTable_2StrataVars | Bin 0 -> 259 bytes tests/testthat/ref-svyCatTable_cramVars | Bin 0 -> 246 bytes tests/testthat/ref-svyCatTable_defaultPrint | Bin 0 -> 218 bytes tests/testthat/ref-svyCatTable_explain | Bin 0 -> 213 bytes tests/testthat/ref-svyCatTable_format_f | Bin 0 -> 194 bytes tests/testthat/ref-svyCatTable_format_p | Bin 0 -> 204 bytes tests/testthat/ref-svyCatTable_format_pf | Bin 0 -> 223 bytes tests/testthat/ref-svyCatTable_noSpaces | Bin 0 -> 239 bytes .../ref-svyCatTable_noSpaces_showAllLevels_quote | Bin 0 -> 279 bytes tests/testthat/ref-svyCatTable_noTests | Bin 0 -> 259 bytes tests/testthat/ref-svyCatTable_overallPrint | Bin 0 -> 212 bytes tests/testthat/ref-svyCatTable_showAllLevels | Bin 0 -> 262 bytes tests/testthat/ref-svyContTable_2StrataVars | Bin 0 -> 280 bytes tests/testthat/ref-svyContTable_defaultPrint | Bin 0 -> 240 bytes tests/testthat/ref-svyContTable_explain | Bin 0 -> 226 bytes tests/testthat/ref-svyContTable_noSpaces | Bin 0 -> 240 bytes .../ref-svyContTable_noSpaces_showAllLevels_quote | Bin 0 -> 253 bytes tests/testthat/ref-svyContTable_noTests | Bin 0 -> 240 bytes tests/testthat/ref-svyContTable_nonnormal_exact | Bin 0 -> 259 bytes tests/testthat/ref-svyContTable_nonnormal_minMax | Bin 0 -> 260 bytes tests/testthat/ref-svyContTable_overallPrint | Bin 0 -> 221 bytes tests/testthat/ref-svyTableOne_2StrataVars | Bin 0 -> 294 bytes tests/testthat/ref-svyTableOne_defaultPrint | Bin 0 -> 250 bytes tests/testthat/ref-svyTableOne_noSpaces | Bin 0 -> 260 bytes .../ref-svyTableOne_noSpaces_showAllLevels_quote | Bin 0 -> 287 bytes tests/testthat/ref-svyTableOne_noTests | Bin 0 -> 250 bytes tests/testthat/ref-svyTableOne_nonnormal_minMax | Bin 0 -> 266 bytes tests/testthat/ref-svyTableOne_overallPrint | Bin 0 -> 213 bytes tests/testthat/ref-svyTableOne_showAllLevels | Bin 0 -> 306 bytes 29 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/ref-svyCatTable_2StrataVars create mode 100644 tests/testthat/ref-svyCatTable_cramVars create mode 100644 tests/testthat/ref-svyCatTable_defaultPrint create mode 100644 tests/testthat/ref-svyCatTable_explain create mode 100644 tests/testthat/ref-svyCatTable_format_f create mode 100644 tests/testthat/ref-svyCatTable_format_p create mode 100644 tests/testthat/ref-svyCatTable_format_pf create mode 100644 tests/testthat/ref-svyCatTable_noSpaces create mode 100644 tests/testthat/ref-svyCatTable_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-svyCatTable_noTests create mode 100644 tests/testthat/ref-svyCatTable_overallPrint create mode 100644 tests/testthat/ref-svyCatTable_showAllLevels create mode 100644 tests/testthat/ref-svyContTable_2StrataVars create mode 100644 tests/testthat/ref-svyContTable_defaultPrint create mode 100644 tests/testthat/ref-svyContTable_explain create mode 100644 tests/testthat/ref-svyContTable_noSpaces create mode 100644 tests/testthat/ref-svyContTable_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-svyContTable_noTests create mode 100644 tests/testthat/ref-svyContTable_nonnormal_exact create mode 100644 tests/testthat/ref-svyContTable_nonnormal_minMax create mode 100644 tests/testthat/ref-svyContTable_overallPrint create mode 100644 tests/testthat/ref-svyTableOne_2StrataVars create mode 100644 tests/testthat/ref-svyTableOne_defaultPrint create mode 100644 tests/testthat/ref-svyTableOne_noSpaces create mode 100644 tests/testthat/ref-svyTableOne_noSpaces_showAllLevels_quote create mode 100644 tests/testthat/ref-svyTableOne_noTests create mode 100644 tests/testthat/ref-svyTableOne_nonnormal_minMax create mode 100644 tests/testthat/ref-svyTableOne_overallPrint create mode 100644 tests/testthat/ref-svyTableOne_showAllLevels diff --git a/tests/testthat/ref-svyCatTable_2StrataVars b/tests/testthat/ref-svyCatTable_2StrataVars new file mode 100644 index 0000000000000000000000000000000000000000..87257bb87c1ddd131217967e0afaa1e77594fcb6 GIT binary patch literal 259 zcmV+e0sQ_SiwFP!000001B>8dU|?WkU}j=uU}6R_1%QMQ0}BHukY+VBFwirAa(Il4 z^b8atbMG0tzxh zC7Dw)b3tmrVGZO0F&ml^4xo~}#N572t9< zgo{A*u)(Y~w1T;r*$BZjMlcPn3=s+p5ef{^T*nG^8rXOys2~HB778vYN-W7t%S=sC zNUBtDwQ>e(XZVL^1W#FNvU7e;cxFmT2FR0qAcr~#fX!hbmWG(g{GXa01-X>r9{^E- JUWEw*005G&V0{1p literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_cramVars b/tests/testthat/ref-svyCatTable_cramVars new file mode 100644 index 0000000000000000000000000000000000000000..9479c6a6a94c047bc4892052033e8bb411432e4e GIT binary patch literal 246 zcmV8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IbxOu zdgl73mU;#X8fFH1X8OjKdM26*P+36*5CADx&@eXEGlol`nPI4BfH1=xWQH-V&0t_* z0!lDK6)>k{<^m~Ru(yF+2u4xD0aTKgn44M*R3Z#jCjeFlk!Q?+m=$U(SRWHqkO4~b2bUBjmSm=7rlu$)RVugwh5n)G w=P64~cFxZU&rB)F06CryWW9qD*boME8lso^KT*yES;g=V0Ab-i8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXtG8 zdIky_#+G^}nhJ0+1F)E}o-teuhbCicYGPnv0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ|a8Jv*{whD#{8mgL50WN1lxCojaLm0yd#xO>+mKACzSRWHq zkO4~b2bUBjmSm=7rlu$)RVugwh5n)G=P64~cFxZU&rB)F06CoxWW9p`*boME8lso^ UKT*yES;g=V00Y|7o&Es;0KZ~RAOHXW literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_explain b/tests/testthat/ref-svyCatTable_explain new file mode 100644 index 0000000000000000000000000000000000000000..796d89dd7a060dae5e9f86651796df614a4d2cbc GIT binary patch literal 213 zcmV;`04o08dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXtG8 zdIky_#+G^}nhJ0+1F)E}o-teuhbCicYGPnv0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ}_91^Kut6&J_usIuod1z{3(u_thhB2CTtWdka`k0`C3{aXs zxTGktBr`2DHANw*Qo$7{^bbuxPg!cRbAC>EW=cs0$jN*l>m3BZhA^Ph5WUR*iE<{$ PDu#amZs%Mz_5lC@k=sxT literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_format_f b/tests/testthat/ref-svyCatTable_format_f new file mode 100644 index 0000000000000000000000000000000000000000..f25712e9bbcbd426be0c5c074af01fb9e79930b4 GIT binary patch literal 194 zcmV;z06qU7iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IV`4@ zNNj{SH54(hFag<&P%-9|%v>PF3w9Zh3&AK#IDks>5_40Ffl7p->IA^*Ao7fPFpDD< zY!wWl95!b|Fb_>FOq$UM#xO>+jumPbSRWHqkO4~b2bUBjmSm=7rlu$)RVugwh5n)G w=P64~cFxZU&rB)F06CctWW9p`*boME8lso^KT*yES;g=V0Gt$y(#8P*03u6A761SM literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_format_p b/tests/testthat/ref-svyCatTable_format_p new file mode 100644 index 0000000000000000000000000000000000000000..82cb63c47ea9c1fe5ac84859b69c04469d4b2205 GIT binary patch literal 204 zcmV;-05ks|iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IV{GO zdM0qTv7Rw5MaHBnVqjqcvKgUb%qf|m$M;U1Wk`2j9~<0pu3C}YA0A96I74^O7jPo6eX5qre&t4 zC?r)XxB`X#q3P!-OHFpp&k4^=DaimioeyNag88dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXuRe zdL{}Qrj~jJnhJ0+V?AS_m;sU)h9+a`Yhqww0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ|a8GMlnwhD#{stOuuMX80FP*HwoLsVfj-G(rR5sYDs<^Wcx z?O=UOP(cQm@xdiUi6xn7nW-rXNtFt&K%swV`gzJylb!Q(!ZTA!GC-c-16l7N05*gH ZordUT{!f%MK~^#R0|3T#+wuqk0038yQ#Akp literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_noSpaces b/tests/testthat/ref-svyCatTable_noSpaces new file mode 100644 index 0000000000000000000000000000000000000000..5880e835cc818df019bd7aaf28a39d13bdf83734 GIT binary patch literal 239 zcmVnNBbxYi>TOycL=^b#=FjJ02XwV6c0^9_Pgn|c-k0021ua#jEU literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyCatTable_noSpaces_showAllLevels_quote new file mode 100644 index 0000000000000000000000000000000000000000..b60209e682ba9288997cc3e42f475abb6d469155 GIT binary patch literal 279 zcmV+y0qFi8iwFP!000001I<#=O2aS|y-PZr+mwm>fDjPcmyj&3qi@347x#EokCTGtdY~_NF9h33FyewbKha#`G?wXg*<8JC- d7<6mhOFu&<{q^)_2y`6<$1miTrh&x*007I6h1mcA literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_noTests b/tests/testthat/ref-svyCatTable_noTests new file mode 100644 index 0000000000000000000000000000000000000000..87257bb87c1ddd131217967e0afaa1e77594fcb6 GIT binary patch literal 259 zcmV+e0sQ_SiwFP!000001B>8dU|?WkU}j=uU}6R_1%QMQ0}BHukY+VBFwirAa(Il4 z^b8atbMG0tzxh zC7Dw)b3tmrVGZO0F&ml^4xo~}#N572t9< zgo{A*u)(Y~w1T;r*$BZjMlcPn3=s+p5ef{^T*nG^8rXOys2~HB778vYN-W7t%S=sC zNUBtDwQ>e(XZVL^1W#FNvU7e;cxFmT2FR0qAcr~#fX!hbmWG(g{GXa01-X>r9{^E- JUWEw*005G&V0{1p literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyCatTable_overallPrint b/tests/testthat/ref-svyCatTable_overallPrint new file mode 100644 index 0000000000000000000000000000000000000000..ef598b24f7defeefadd549b246417eaa34b3f491 GIT binary patch literal 212 zcmV;_04x6=iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!I0}BHukY+V8HPADFa(E5R z&GifvG>k3vOf(hXf*=(@L1R5*pdbSa6Ht&5D#@IZnF~?_wgF@+ND5U62T(~~Vs2_N zP>C>99kL4;^PmjQNCjI3Lj?_0O{f5uvmsmrq6cOsyMI|~QDROGnpLb&d%$X$pn?og znlHGdD6u3nEi*MmA*mAR5r%(g+Ih-Slb!Q(!ZTA!GC;271IamvFhBuFE%SezE&&tdwDM}n@0dZfKdk!*5gPmV+h~@^jGg4<_3Nh>GBz)4t*vu zqjM5Qj7AgEfU}q~5{j6<{ezq_4Mq{2pEC_81QiYF8*n3IZJ9F=_hkS9(p}k~IL!*p zG0iJq({r2BSCld-E literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_defaultPrint b/tests/testthat/ref-svyContTable_defaultPrint new file mode 100644 index 0000000000000000000000000000000000000000..e38e84bf0ac4aca01d13eb750b6dda9792fb38a3 GIT binary patch literal 240 zcmVaVs12pQH_yivGih_|uFcD(n z%d6ekG!hS*co;3ee*M;N(*pnklo&v$NJsdwz=STwwm;<__tjtD_c&(`67Fggcz!6* zeDOrwo6H27K2^01fA##uCj8k3OoGTzC7NV823zirHGvwE4oZqRPfL`Hm2M=pb=@db zVlSDKr*XlYGI90YcJu)bqTr3zhEyBsw>AQugpHY6Y9QH16a*EAtLhwA**;4Xw!N|? qqFbZix}>}4bX;dibr5^m_1 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_explain b/tests/testthat/ref-svyContTable_explain new file mode 100644 index 0000000000000000000000000000000000000000..df6384a50a0a7bdbd1acd087b1bd859fc604274d GIT binary patch literal 226 zcmV<803H7yiwFP!000001B>8dU|?WkU}j=uU}6R_1%Lz(0}BHukY+P9HPACKgz~rz z^$ZLYG=L%onlK?FJws!VkcA~&$Ux7;93*54R|PS~0HKE}#u$@q32yK#hj9v z3#53#{s+o|gwT|50F~q==B5?{l?X%C34ql?1q+9}`rN0ZQ`+mlP$IWTs`NrYIy;D!2lL{-NpTDN9Xu&d&+YOex6#xtSN@ cC$Qh37^I&0KT%Et8PD(!0I!@=Q6T~V0PJB^j{pDw literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_noSpaces b/tests/testthat/ref-svyContTable_noSpaces new file mode 100644 index 0000000000000000000000000000000000000000..e38e84bf0ac4aca01d13eb750b6dda9792fb38a3 GIT binary patch literal 240 zcmVaVs12pQH_yivGih_|uFcD(n z%d6ekG!hS*co;3ee*M;N(*pnklo&v$NJsdwz=STwwm;<__tjtD_c&(`67Fggcz!6* zeDOrwo6H27K2^01fA##uCj8k3OoGTzC7NV823zirHGvwE4oZqRPfL`Hm2M=pb=@db zVlSDKr*XlYGI90YcJu)bqTr3zhEyBsw>AQugpHY6Y9QH16a*EAtLhwA**;4Xw!N|? qqFbZix}>}4bX;dibr5^m_1 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyContTable_noSpaces_showAllLevels_quote new file mode 100644 index 0000000000000000000000000000000000000000..24bca0dd7e738712ffae3277c03f22249a9f13ff GIT binary patch literal 253 zcmV_GVxyJ+MGOqqc++~c|f-pxT&*i>E z%TU@qdni4id;vOE^w5F`4E0#hOGdOJ7*>C`)d_GE+XQ^r{G& zQza*KP3$a*a$?_N$7yi*4O=wyK6w?4>tIf6={3@)tq!}Yy|NlVUfD6d2f>Bp~Dmxg{BhNp#J#l!Ora!hllSONe5 DG{|#c literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_noTests b/tests/testthat/ref-svyContTable_noTests new file mode 100644 index 0000000000000000000000000000000000000000..e38e84bf0ac4aca01d13eb750b6dda9792fb38a3 GIT binary patch literal 240 zcmVaVs12pQH_yivGih_|uFcD(n z%d6ekG!hS*co;3ee*M;N(*pnklo&v$NJsdwz=STwwm;<__tjtD_c&(`67Fggcz!6* zeDOrwo6H27K2^01fA##uCj8k3OoGTzC7NV823zirHGvwE4oZqRPfL`Hm2M=pb=@db zVlSDKr*XlYGI90YcJu)bqTr3zhEyBsw>AQugpHY6Y9QH16a*EAtLhwA**;4Xw!N|? qqFbZix}>}4bX;dibr5^m_1 literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyContTable_nonnormal_exact b/tests/testthat/ref-svyContTable_nonnormal_exact new file mode 100644 index 0000000000000000000000000000000000000000..f4296e619fe6cf475807464224ed807433d0f8e0 GIT binary patch literal 259 zcmV+e0sQ_SiwFP!000001B>8dU|?WkU}j=uU}6R_1%Lz(0}BHukY+P9HPACKgz~rz z^$ZLYG=L%onouD@Bal!uNJ2-!7)Zv#)EelSn1j@s!qq|yGk_^DqNZWSWE#f6!UPmz zgi0}|Waa`XUT}y2DcN;rT@@)C1Xi-Agnq3Q&{Y9aEBc~AzgtAa*uYGR&(MsbQJ z%uxc)Ai$xXOcQDO5^MHe&kLp^3B8i(@koR=?l@16TB{lzz_(x>`g5Tw3YvWOlSEOjLlkfc$Ik4GvQH6%$!;6Y$N;u zm!aFCO~ZEJcwh1?isPP-p)yfxv4W`Wcqp={5Ldw&IX?)Hs`q_S@=JJ+kAf99xr))O XDp!^|{rT60Y=x>9&coZamH_|&jFe>Y literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyTableOne_2StrataVars b/tests/testthat/ref-svyTableOne_2StrataVars new file mode 100644 index 0000000000000000000000000000000000000000..68cc351a8b3ad970e1becd32311c332445847c12 GIT binary patch literal 294 zcmV+>0onc^iwFP!000001GSR9PQx%1g>UQ@wWUQByuckmN*2r4X{j2CDe4n+fiWmS z%8(4S3onmw92+Mg3xW>*$>(!?>>EEX0Du8!0WjW7*Sfoh3C#6)MN$e$_UoF2lo)Cv zBaa>p+Uy-#DkU`1Jw@nbC`Ie^Nd9oPY0?SQ@6zPo(&EdeO}E{!kwV5owU%$RjCak( zyG>{3)z*ZWqj%$m-hSLjB`+B_Qp*2|g9+0puuD8ItHx$tu>PZM>q%x>QfF0h(vmx? zTN_=w9@H-TfMHc+HHN1=a)(@{BXItLPe>R(IIu`*KyFgiGxjq%C9YOn`DyH@l#myY s7tr8#Q+qYDJ+lz(czZm*XXo;*EOLDPz(bO1JA5|n3)b}Jg7pIc0HOhkB>(^b literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyTableOne_defaultPrint b/tests/testthat/ref-svyTableOne_defaultPrint new file mode 100644 index 0000000000000000000000000000000000000000..6c744ae1a15909c06f43519a9401e612d73e5589 GIT binary patch literal 250 zcmV+kXfrTHJOK-gK?zcZ zWB?Xk9`&5qphgVP!S?y*@9sO<-i-i2fG<1{z6mEhO`!)vUO#k<3boyhwL+936I?hH zDNP3bBo2MW2@A9gDN##YJ+R5+bRtEh?*&jTzfFPoUb8jDhr^quMD*O0UN@!JP4Pdb z&=ZV2d*tV3#Y@n<1ovW4M>1eZomIt|B{Qp=G}`vut8EZ$WLOnhEyHuZaNa@s1P=Fd zE&0mk4vbRWA)jgVC$aVPou~U4UgQGmwB5HoH+jNBa2K_`oU%)KEQ?$ou5!cZX2vfn KLT#Co0ssInT5~Y~ literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyTableOne_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyTableOne_noSpaces_showAllLevels_quote new file mode 100644 index 0000000000000000000000000000000000000000..fc0ccb5cb4ba3b9810489ffbfcd071a19181e2cf GIT binary patch literal 287 zcmV+)0pR{0iwFP!000001D%nvPQx$|hTWu~LO`VD1x_a+B@(jiTvODcQ`CVGSU^>W zpadyHGSDu(JmQ?%MnnwIA@=#Z|L#9K&*wsjK!m|a1fdCIUS?t}&Uio7xspoTQ>3L* zkT6lHMbpfnjY-@B@w&B%t9;2P4GAsfTrE74t{2W#a7*>ToH z^t(0v-J1Sut&Xu4A40BWUzt_8k%q?s8%; l(pLvg2k1(s__Tj7_sv^VSMd4)Yvc53zAx=LDU`ng006`SiX`&`JXg>fw>eE%ChS!A%~vCC&;BGC2bQ>Z}ltEj_q1{=RSL8_>5I00{7f2g0}QhK?KZ*wh`!hnbh z89hc89j)+!F`XwC7Rg?c*X(5+V$W2|j5Ix)D;e+X%%q>$g(_!=eiLf`7;64G6h?xO z$C6)EHI-%iC1@9m29^m~n!GMAWO-uWruBBZ*Ko7UFsRGC!QfJaZuxC$VNnr2p7Z9b zJUM0hj<2XOcy?fx>H%4$(cQ={*muG1@9-kmn8EI2Uc9|07y{Sz;d;)m)n`=}`0hv+qIOD=RBTN|Q7;|#@gq)?h?#?&`@Q7lLskzm&)qR7XcG9JJWTPTo+19;^987NN z?{wqvE5>bIb{O{+wVK5r7(DQT0^{Qd!a^*_u1IE$znP z0!%oIyAe-Tve`o$7bAJo~3_Lag=IJm{2Z9erpr8HU3AsT0NSyW% zMM9h$o}=JI7%D`OW#<@cw$hm^l+qL7<2MjNx(GngMVh=qn z;z8k$_P#5$sbA{Nw?&U#AV=d&?JTAU8?`#S+dY@N=BcSGe0;^FLT~zg2fKlBEPn$4 E0H)24m;e9( literal 0 HcmV?d00001 From db3aaf4aa31a77c8bc39cd5748fd1c1ffea8a895 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 09:34:57 -0400 Subject: [PATCH 053/219] Correctly pass pDigits to print method for Cat/ContTable --- R/print.TableOne.R | 2 +- tests/testthat/ref-TableOne_digits | Bin 87 -> 912 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 7e16865..19ec1b4 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -117,7 +117,7 @@ print.TableOne <- function(x, # TableOne object ## print.CatTable or print.ContTable called depending on the class print(TableOne[[i]], printToggle = FALSE, test = test, explain = explain, - digits = digits[i], + digits = digits[i], pDigits = pDigits, ## print.CatTable arguments format = format, exact = exact, diff --git a/tests/testthat/ref-TableOne_digits b/tests/testthat/ref-TableOne_digits index a2485fec14c443155a41824efad690022216783c..f2447000ad311ed68528e37f010cc3281a325bcd 100644 GIT binary patch literal 912 zcmV;B18@8viwFP!000001LamtZyPrdUCC|}r)aFi>9GJW1*8kXAvydw)P7H zi%OOtZGiO87kymsMqKR*&OHV!e!St#c-#ISI%pTgjSi4x#eK0rG^xMmllS9HeKZ(w!AgoUrDWif!wbS87zz){JW8BNl(i%tYl@L>!zl-22&asdfz)>h+O~ZL2}S=7-eK1M$(RL0kuDX9bH()LCM?0^&A3LC6DleRV? z$;QN7qOG(!6)ZsY0Sr&IvCjO_{YJ;22(?B-0|?ZZd<#MKbb>V650Aui z9lVZqsO+Fx)uS(8cIRWVQ{h-a&(`dahTJ{`P1!o4jxLYuUC=)emkhpJvbDE9#(^IbLLMhZ zazlHauPrjI2KjI*_s?uO=S|U5j^kU;s26zuJY#V^$H%OHLD%&b!|z4<0Z|lxwuVEK z*D!f1x786Qcb(m$wSC5CPu*nE)Z0odw^jKhmdEv~Z=*NIrfj|*#qzIy=Nh6{*_^U@ zudv(l%apU)&jX##rxu-ose!vyl7-25Z=kGtaphPyXY@tZ^a zWy;llQ#RG6nmTj0KkP14@CFr3)fi-Fs%U9$vbpWFa@}jCKQ!x4%=W!GD%hM!@0U(@ mt&jPcl;3@74rNn+uB)}U|5r2zoG$)L|NjGU!Qo#J3jhFzD#LvM literal 87 zcmb2|=3oE==I#ec2?+^F328|w2}x{5k}M4~CN{P<3VUR?r=*B!GXySj^2*H1Tj~^; m6_pj36<4&%$ Date: Sat, 25 Jul 2015 09:38:47 -0400 Subject: [PATCH 054/219] Add devtools::test() to Makefile (no dependency) --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4030734..4f74514 100644 --- a/Makefile +++ b/Makefile @@ -22,11 +22,15 @@ PKG_FILES := DESCRIPTION NAMESPACE NEWS $(R_FILES) $(SRC_FILES) $(VIG_FILES) ## .PHONY to allow non-file targets (file targets should not be here) ## https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html -.PHONY: build check install clean +.PHONY: test build check install clean ### Define targets +## test just runs testthat scripts. No dependencies. +test: + Rscript -e "devtools::test()" + ## build depends on the *.tar.gz file, i.e., its own product. ## *.tar.gz file is defined seprately to prevent build execution on every invocation. build: $(PKG_NAME)_$(PKG_VERSION).tar.gz From dbbc5677137ca32f3c9a61e4abb59bffe6c22435 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 11:32:51 -0400 Subject: [PATCH 055/219] Add abnormal data check tests for (svy)CreateTableOne --- tests/testthat/test-CreateTableOne.R | 72 ++++++++++++++++++------- tests/testthat/test-svyCreateTableOne.R | 30 +++++++---- 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 177426a..5bb769e 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -16,8 +16,55 @@ library(testthat) context("Unit tests for the CreateTableOne function") -### Tests for -## Tests for ModuleTestSafe, a wrapper for test functions such as oneway.test and chisq.test +### Load data + +library(survival) +data(pbc) + +## Make categorical variables factors +varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") +pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + +## Create a variable list +vars <- c("time","status","age","sex","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage") + + +### Tests for data checkers + +test_that("abnormal data are correctly detected", { + + ## Expectations + ## Use regular expressions + + ## Error in ModuleStopIfNoVarsLeft(vars) : No valid variables. + ## In addition: Warning message: + ## In ModuleReturnVarsExist(vars, data) : + ## The data frame does not have: non-existent Dropped + expect_error(expect_warning(CreateTableOne(vars = "non-existent", data = pbc), + "The data frame does not have: non-existent Dropped"), + "No valid variables.") + + ## Error in ModuleStopIfNotDataFrame(data) : + ## The data argument needs to be a data frame (no quote). + expect_error(CreateTableOne(data = "not a data frame"), + "The data argument needs to be a data frame") + + ## Error in ModuleReturnStrata(strata, data) : + ## None of the stratifying variables are present in the data frame. + ## In addition: Warning message: + ## In ModuleReturnVarsExist(strata, data) : + ## The data frame does not have: non-existent Dropped + expect_error(expect_warning(CreateTableOne(vars = vars, strata = c("non-existent"), data = pbc), + "The data frame does not have: non-existent Dropped"), + "None of the stratifying variables are present in the data frame") + +}) + + +### Tests for ModuleTestSafe, a wrapper for test functions such as oneway.test and chisq.test ## Create a dataset for a table dat <- read.table(header = TRUE, text = " @@ -81,19 +128,6 @@ test_that("P-values should be NA for 1xM xtabs", { ### Regression tests ################################################################################ -library(survival) -data(pbc) - -## Make categorical variables factors -varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - -## Create a variable list -vars <- c("time","status","age","sex","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage") - ## Create a table to test pbcOverall <- CreateTableOne(vars = vars, data = pbc) pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) @@ -115,7 +149,7 @@ test_that("printing of a TableOne object does not regress", { expect_equal_to_reference(print(pbcByTrtSex, printToggle = FALSE), "ref-TableOne_2StrataVars") - + ## 2015-07-25 pDigits is not functional now expect_equal_to_reference(print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), "ref-TableOne_digits") @@ -157,7 +191,7 @@ test_that("printing of a TableOne$CatTable object do not regress", { expect_equal_to_reference(print(pbcByTrtSex$CatTable, test = FALSE, printToggle = FALSE), "ref-CatTable_noTests") - + expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, printToggle = FALSE), "ref-CatTable_noSpaces") @@ -201,13 +235,13 @@ test_that("printing of a TableOne$ContTable object do not regress", { expect_equal_to_reference(print(pbcByTrt$ContTable, test = FALSE, printToggle = FALSE), "ref-ContTable_noTests") - + expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), "ref-ContTable_nonnormal_exact") expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), "ref-ContTable_nonnormal_minMax") - + expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), "ref-ContTable_noSpaces") diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index f1cf27e..e4cfd12 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -16,7 +16,7 @@ library(survey) ### Context (1 for each file) ################################################################################ -context("Unit tests for the survey-related modules") +context("Unit tests for svy* user functions") @@ -45,6 +45,10 @@ datMw[c(1,150), "Y"] <- NA ## Create a survey design object datSvy <- svydesign(ids = ~ 1, data = datMw, weights = ~ Mw) +## Create a variable list +vars <- c("E", "C", "Y", "C1", "C2") +factorVars <- c("Y","C1") + ### Tests ################################################################################ @@ -55,23 +59,31 @@ datSvy <- svydesign(ids = ~ 1, data = datMw, weights = ~ Mw) test_that("data assessment detects anomalies", { - ## Should give ## Error in ModuleStopIfNoVarsLeft(vars) (from modules.R#52) : No valid variables. ## In addition: Warning message: ## In ModuleReturnVarsExist(vars, data$variables) : ## The data frame does not have: none Dropped expect_warning(expect_error(svyCreateTableOne(vars = "non-existent", data = datSvy), - "No valid variables."), + "No valid variables"), "The data frame does not have: non-existent Dropped") - ## Should give + + ## Error in StopIfNotSurveyDesign(data) : + ## The data argument needs to be a survey design object. + expect_error(svyCreateTableOne(vars = c("E"), data = "not a svy object"), + "The data argument needs to be a survey design object") + + ## Data frame is not allowed + expect_error(svyCreateTableOne(vars = c("E"), data = data.frame(E = c(1,2,3))), + "The data argument needs to be a survey design object") + ## Error in ModuleReturnStrata(strata, data$variable) (from modules.R#84) : ## None of the stratifying variables are present in the data frame. ## In addition: Warning message: ## In ModuleReturnVarsExist(strata, data) : ## The data frame does not have: non-existent Dropped - expect_warning(expect_error(svyCreateTableOne(vars = vars, strata = c("non-existent"), data = datSvy, factorVars = factorVars), - "None of the stratifying variables are present in the data frame."), + expect_warning(expect_error(svyCreateTableOne(vars = vars, strata = c("non-existent"), data = datSvy), + "None of the stratifying variables are present in the data frame"), "The data frame does not have: non-existent Dropped") }) @@ -81,10 +93,6 @@ test_that("data assessment detects anomalies", { ## Make categorical variables factors -## Create a variable list -vars <- c("E", "C", "Y", "C1", "C2") -factorVars <- c("Y","C1") - ## Create a table to test mwOverall <- svyCreateTableOne(vars = vars, data = datSvy, factorVars = factorVars) mwByTrt <- svyCreateTableOne(vars = vars, strata = c("E"), data = datSvy, factorVars = factorVars) @@ -210,7 +218,7 @@ test_that("printing of a TableOne$ContTable object do not regress", { expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), "ref-svyContTable_noSpaces") - + expect_equal_to_reference(print(mwByTrt$ContTable, explain = FALSE, printToggle = FALSE), "ref-svyContTable_explain") From 0057cfcbe073129b6b25152a460e8a189ae683a6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 18:39:23 -0400 Subject: [PATCH 056/219] Make strataVar outside svydata to be svydata$variables$..strataVar.. Safer within the svydesign object that as a separate vector --- R/svyCreateContTable.R | 6 +++--- R/svyModules.R | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index fd9cf32..fcdff02 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -113,8 +113,8 @@ svyCreateContTable <- ## Create a single stratification variable ## Keeps non-existing levels - strataVar <- interaction(strata, sep = ":") - strataVarLevels <- levels(strataVar) + data$variables$..strataVar.. <- interaction(strata, sep = ":") + strataVarLevels <- levels(data$variables$..strataVar..) ## Handle non-numeric elements (intergers give TRUE, and pass) if(any(!sapply(data$variables[vars], is.numeric))){ @@ -140,7 +140,7 @@ svyCreateContTable <- result <- sapply(strataVarLevels, function(level) { ## Create a matrix including vars X c(n,miss,...) matrix - svyContSummary(vars, subset(data, strataVar == level)) + svyContSummary(vars, subset(data, ..strataVar.. %in% level)) }, simplify = FALSE) diff --git a/R/svyModules.R b/R/svyModules.R index 83d8254..f7c9584 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -201,3 +201,29 @@ svyCatSummary <- function(vars, design) { }, simplify = FALSE) } + + +### +### Helpers for testing for p values +################################################################################ + +## Function to do Wald test on a multi-degree variable after linear regression +svyGlmTermTest <- function(formula, design, test.terms, method = "Wald") { + + ## Perform linear regression and perform + regTermTest(svyglm(formula, design), test.terms = test.terms, method = method) +} + + +## Given a formula string as its first argument, calls svyGlmTermTest correctly +svyTestNormal <- function(formulaString, design, test.terms, method) { + + svyGlmTermTest(formula = as.formula(formulaString), design = design, + test.terms = test.terms, method = method) +} + +svyTestNonNormal <- function(formulaString, design) { + + ## Kruskal.test-like + svyranktest(formula = as.formula(formulaString), design = design) +} From ea655c5bd3714d5dc7d10d757d925b8fec396216 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 18:40:33 -0400 Subject: [PATCH 057/219] Add p value test functions for svyCatTable --- R/svyCreateContTable.R | 47 +++++++++++++++++++++++------------------- R/svyCreateTableOne.R | 1 - 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index fcdff02..ff38993 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -80,15 +80,15 @@ ##' ##' @export svyCreateContTable <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # survey design data - test = TRUE, # Whether to put p-values - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # survey design data + test = TRUE, # Whether to put p-values + testNormal = svyTestNormal, # test for normally distributed variables + argsNormal = list(method = "Wald"), # arguments passed to testNormal + testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) ## require(e1071) # for skewness and kurtosis @@ -164,24 +164,29 @@ svyCreateContTable <- ## Only when test is asked FOR - ## TEMPORALILY TURNED OFF - if (test & FALSE) { + if (test) { + ## This is not necessary as it has already been created as ..strataVar... ## Create a single variable representation of multivariable stratification - strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + ## strataVar <- ModuleCreateStrataVarAsFactor(result, strata) ## Loop over variables in dat, and obtain p values for two tests ## DF = 6 when there are 8 levels (one empty), i.e., empty strata dropped by oneway.test/kruskal.test pValues <- - sapply(X = dat, - FUN = function(var) { - ## Perform tests and return the result as 1x2 DF - data.frame( - pNormal = ModuleTestSafe(var ~ strataVar, testNormal, argsNormal), - pNonNormal = ModuleTestSafe(var ~ strataVar, testNonNormal, argsNonNormal) - ) - }, - simplify = FALSE) + sapply(X = vars, + FUN = function(var) { + + ## Create a formula as a string + formulaString <- paste0(var, " ~ ..strataVar..") + + ## Perform tests and return the result as 1x2 DF + ## The test functions should take a formula string as their first argument. + data.frame(pNormal = ModuleTestSafe(formulaString, testNormal, + c(list(design = data, test.terms = var), argsNormal)), + pNonNormal = ModuleTestSafe(formulaString, testNonNormal, + c(list(design = data), argsNonNormal))) + }, + simplify = FALSE) ## Create a single data frame (n x 2 (normal,nonormal)) pValues <- do.call(rbind, pValues) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 1dcbb8d..7879714 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -113,7 +113,6 @@ svyCreateTableOne <- vars <- ModuleReturnVarsExist(vars, data$variables) ## Abort if no variables exist at this point - ModuleStopIfNoVarsLeft(vars) ## Factor conversions if the factorVars argument exist From ac476f12646ec6b5cf5d3f042d777a7627514d2d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 18:58:15 -0400 Subject: [PATCH 058/219] Fix handling of p values for normality based test --- R/svyCreateContTable.R | 2 +- R/svyModules.R | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index ff38993..649bf7f 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -182,7 +182,7 @@ function(vars, # character vector of variable n ## Perform tests and return the result as 1x2 DF ## The test functions should take a formula string as their first argument. data.frame(pNormal = ModuleTestSafe(formulaString, testNormal, - c(list(design = data, test.terms = var), argsNormal)), + c(list(design = data, test.terms = "..strataVar.."), argsNormal)), pNonNormal = ModuleTestSafe(formulaString, testNonNormal, c(list(design = data), argsNonNormal))) }, diff --git a/R/svyModules.R b/R/svyModules.R index f7c9584..a8f1ea3 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -218,12 +218,16 @@ svyGlmTermTest <- function(formula, design, test.terms, method = "Wald") { ## Given a formula string as its first argument, calls svyGlmTermTest correctly svyTestNormal <- function(formulaString, design, test.terms, method) { - svyGlmTermTest(formula = as.formula(formulaString), design = design, - test.terms = test.terms, method = method) + out <- svyGlmTermTest(formula = as.formula(formulaString), design = design, + test.terms = test.terms, method = method) + ## Give an appropriate name for consistent extraction + list(p.value = out$p[1,1]) } svyTestNonNormal <- function(formulaString, design) { ## Kruskal.test-like - svyranktest(formula = as.formula(formulaString), design = design) + out <- svyranktest(formula = as.formula(formulaString), design = design) + + list(p.value = out$p.value[1,1]) } From de188194e8c08dcca5c14710cd27753dd9be7f90 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 19:42:36 -0400 Subject: [PATCH 059/219] Add ANOVA/KW-like functions and corresponding unit tests --- R/svyModules.R | 7 ++- tests/testthat/test-svyModules.R | 80 +++++++++++++++++++------------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index a8f1ea3..286c01a 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -226,8 +226,7 @@ svyTestNormal <- function(formulaString, design, test.terms, method) { svyTestNonNormal <- function(formulaString, design) { - ## Kruskal.test-like - out <- svyranktest(formula = as.formula(formulaString), design = design) - - list(p.value = out$p.value[1,1]) + ## Kruskal.test-like test + ## This returns an htest object that has a scalar $p.value element + svyranktest(formula = as.formula(formulaString), design = design) } diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R index c503eb5..5e52ff8 100644 --- a/tests/testthat/test-svyModules.R +++ b/tests/testthat/test-svyModules.R @@ -146,7 +146,7 @@ test_that("SDs are correct", { test_that("Quantiles are correct", { - + ## Expectations expect_equal(as.numeric(svyQuant(vars = "E", datSvy, q = 0.5)), as.numeric(svyquantile( ~ E, datSvy, quantiles = 0.5))) @@ -165,25 +165,25 @@ test_that("Quantiles are correct", { test_that("Regression test for svyContSummary", { - res1 <- structure(c(450.015, 450.015, 0, 0.2858, 0, 0.0635089941446396, - 2.00060881081326, 0.39357484459537, 0.816777838825025, 0.488786864487986, + res1 <- structure(c(450.015, 450.015, 0, 0.2858, 0, 0.0635089941446396, + 2.00060881081326, 0.39357484459537, 0.816777838825025, 0.488786864487986, 2, 0, 1, 0, 3, 1, 1, 0, 3, 1), .Dim = c(2L, 10L), .Dimnames = list( - c("E", "Y"), c("n", "miss", "p.miss", "mean", "sd", "median", + c("E", "Y"), c("n", "miss", "p.miss", "mean", "sd", "median", "p25", "p75", "min", "max"))) expect_equal(svyContSummary(vars = c("E","Y"), datSvy), res1) }) test_that("table works", { - + ## Expectations expect_true(all(svyTable("E", datSvy) == svytable( ~ E, datSvy))) - expect_true(all(svyTable("Y", datSvy) == svytable( ~ Y, datSvy))) + expect_true(all(svyTable("Y", datSvy) == svytable( ~ Y, datSvy))) }) test_that("Levels are obtained", { - + ## Expectations expect_equal(svyLevel("E", datSvy), c("1","2","3")) expect_equal(svyLevel("Y", datSvy), c("0","1")) @@ -191,7 +191,7 @@ test_that("Levels are obtained", { test_that("Prop table works", { - + ## Expectations expect_equal(as.numeric(round(svyPropTable("E", datSvy), 3)), round(c(1/3,1/3,1/3), 3)) @@ -201,51 +201,65 @@ test_that("Prop table works", { test_that("Regression test for one variable categorical summary", { - + ## Expectations res1 <- structure(list(n = c(450.015, 450.015), miss = c(0.2858, 0.2858 -), p.miss = c(0.0635089941446396, 0.0635089941446396), level = structure(1:2, .Label = c("0", -"1"), class = "factor"), freq = c(272.7271, 177.0021), percent = c(60.642515540463, -39.357484459537), cum.percent = c(60.642515540463, 100)), .Names = c("n", -"miss", "p.miss", "level", "freq", "percent", "cum.percent"), row.names = c(NA, +), p.miss = c(0.0635089941446396, 0.0635089941446396), level = structure(1:2, .Label = c("0", +"1"), class = "factor"), freq = c(272.7271, 177.0021), percent = c(60.642515540463, +39.357484459537), cum.percent = c(60.642515540463, 100)), .Names = c("n", +"miss", "p.miss", "level", "freq", "percent", "cum.percent"), row.names = c(NA, -2L), class = "data.frame") expect_equal(svyCatSummaryForOneVar("Y", datSvy), res1) - res2 <- structure(list(n = c(450.015, 450.015, 450.015), miss = c(0, -0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", -"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), + res2 <- structure(list(n = c(450.015, 450.015, 450.015), miss = c(0, +0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", +"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), percent = c(33.3348888370388, 33.3328889037032, 33.332222259258 ), cum.percent = c(33.3348888370388, 66.667777740742, 100 - )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", + )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", "cum.percent"), row.names = c(NA, -3L), class = "data.frame") expect_equal(svyCatSummaryForOneVar("E", datSvy), res2) }) -test_that("Regression test for multiple variable categorical sumamry", { - +test_that("Regression test for multiple variable categorical summary", { + ## Expectations res1 <- structure(list(E = structure(list(n = c(450.015, 450.015, 450.015 -), miss = c(0, 0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", -"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), +), miss = c(0, 0, 0), p.miss = c(0, 0, 0), level = structure(1:3, .Label = c("1", +"2", "3"), class = "factor"), freq = c(150.012, 150.003, 150), percent = c(33.3348888370388, 33.3328889037032, 33.332222259258 ), cum.percent = c(33.3348888370388, 66.667777740742, 100 - )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", -"cum.percent"), row.names = c(NA, -3L), class = "data.frame"), - Y = structure(list(n = c(450.015, 450.015), miss = c(0.2858, + )), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", +"cum.percent"), row.names = c(NA, -3L), class = "data.frame"), + Y = structure(list(n = c(450.015, 450.015), miss = c(0.2858, 0.2858), p.miss = c(0.0635089941446396, 0.0635089941446396 - ), level = structure(1:2, .Label = c("0", "1"), class = "factor"), - freq = c(272.7271, 177.0021), percent = c(60.642515540463, + ), level = structure(1:2, .Label = c("0", "1"), class = "factor"), + freq = c(272.7271, 177.0021), percent = c(60.642515540463, 39.357484459537), cum.percent = c(60.642515540463, 100 - )), .Names = c("n", "miss", "p.miss", "level", "freq", - "percent", "cum.percent"), row.names = c(NA, -2L), class = "data.frame"), - C1 = structure(list(n = c(450.015, 450.015), miss = c(0, - 0), p.miss = c(0, 0), level = structure(1:2, .Label = c("0", - "1"), class = "factor"), freq = c(300.015, 150), percent = c(66.667777740742, - 33.332222259258), cum.percent = c(66.667777740742, 100)), .Names = c("n", + )), .Names = c("n", "miss", "p.miss", "level", "freq", + "percent", "cum.percent"), row.names = c(NA, -2L), class = "data.frame"), + C1 = structure(list(n = c(450.015, 450.015), miss = c(0, + 0), p.miss = c(0, 0), level = structure(1:2, .Label = c("0", + "1"), class = "factor"), freq = c(300.015, 150), percent = c(66.667777740742, + 33.332222259258), cum.percent = c(66.667777740742, 100)), .Names = c("n", "miss", "p.miss", "level", "freq", "percent", "cum.percent" - ), row.names = c(NA, -2L), class = "data.frame")), .Names = c("E", + ), row.names = c(NA, -2L), class = "data.frame")), .Names = c("E", "Y", "C1")) expect_equal(svyCatSummary(c("E","Y","C1"), datSvy), res1) }) + + +### Statistical test functions + +test_that("Statistical test wrappers work", { + + ## Expectations + ## ANOVA equivalent + expect_true(regTermTest(svyglm(Y ~ E, datSvy), test.terms = "E")$p[1,1] == svyTestNormal("Y ~ E", design = datSvy, test.terms = "E", method = "Wald")) + + ## Kruskal-Wallis test equivalent + expect_equal(svyranktest(Y ~ E, datSvy), svyTestNonNormal("Y ~ E", design = datSvy)) + +}) From 42fbd73b00c19e0963d52ed56c6454f1e4351cee Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 19:57:51 -0400 Subject: [PATCH 060/219] Add svyTestChisq for formula string evaluation --- R/svyModules.R | 10 +++++++++- tests/testthat/test-svyModules.R | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/R/svyModules.R b/R/svyModules.R index 286c01a..581ac15 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -224,9 +224,17 @@ svyTestNormal <- function(formulaString, design, test.terms, method) { list(p.value = out$p[1,1]) } + +## Kruskal-Wallis test svyTestNonNormal <- function(formulaString, design) { - ## Kruskal.test-like test ## This returns an htest object that has a scalar $p.value element svyranktest(formula = as.formula(formulaString), design = design) } + + +svyTestChisq <- function(formulaString, design) { + + ## This returns an htest object that has a scalar $p.value element + svychisq(formula = as.formula(formulaString), design = design) +} diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-svyModules.R index 5e52ff8..f7dcbe3 100644 --- a/tests/testthat/test-svyModules.R +++ b/tests/testthat/test-svyModules.R @@ -259,7 +259,10 @@ test_that("Statistical test wrappers work", { ## ANOVA equivalent expect_true(regTermTest(svyglm(Y ~ E, datSvy), test.terms = "E")$p[1,1] == svyTestNormal("Y ~ E", design = datSvy, test.terms = "E", method = "Wald")) - ## Kruskal-Wallis test equivalent + ## Kruskal-Wallis test equivalent (the whole htest object match) expect_equal(svyranktest(Y ~ E, datSvy), svyTestNonNormal("Y ~ E", design = datSvy)) + ## Chi-squared test equivalent (the whole thing had partial mismatch) + expect_equal(svychisq(~ C1 + E, datSvy)$p.value, svyTestChisq("~ C1 + E", design = datSvy)$p.value) + }) From dce6eb0634a1c6e98ef2b42cfd5e32f67dcc4f62 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 20:15:05 -0400 Subject: [PATCH 061/219] Add svychisq functionality for svyCatTable --- R/svyCreateCatTable.R | 58 ++++++++++++++++++++---------------------- R/svyCreateContTable.R | 7 ++--- R/svyCreateTableOne.R | 34 +++++++++++-------------- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 11cdc5e..b51ab6d 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -81,15 +81,13 @@ ##' ##' @export svyCreateCatTable <- -function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - includeNA = FALSE, # include NA as a category - test = TRUE, # whether to put p-values - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5) # arguments passed to testExact +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + includeNA = FALSE, # include NA as a category + test = TRUE, # whether to put p-values + testApprox = svyTestChisq, # function for approximation test (only choice) + argsApprox = list(NULL) # arguments passed to testApprox ) { ### Data check @@ -111,8 +109,8 @@ function(vars, # character vector of variable na ## Create a single stratification variable ## Keeps non-existing levels - strataVar <- interaction(strata, sep = ":") - strataVarLevels <- levels(strataVar) + data$variables$..strataVar.. <- interaction(strata, sep = ":") + strataVarLevels <- levels(data$variables$..strataVar..) ## Convert to a factor if it is not a factor already. (categorical version only) ## Not done on factors, to avoid dropping zero levels. @@ -152,7 +150,7 @@ function(vars, # character vector of variable na result <- sapply(strataVarLevels, function(level) { ## Create a matrix including vars X c(n,miss,...) matrix - svyCatSummary(vars, subset(data, strataVar == level)) + svyCatSummary(vars, subset(data, ..strataVar.. %in% level)) }, simplify = FALSE) @@ -175,22 +173,15 @@ function(vars, # character vector of variable na listXtabs <- list() ## Only when test is asked for - ## TURN OFF FOR THE TIME BEING - if (test & FALSE) { + if (test) { - ## Create a single variable representation of multivariable stratification - strataVar <- ModuleCreateStrataVarAsFactor(result, strata) - - ## Loop over variables in dat, and create a list of xtabs - ## Empty strata are kept in the corss tables. Different behavior than the cont counterpart! - listXtabs <- sapply(X = names(dat), + listXtabs <- sapply(X = vars, FUN = function(var) { ## Create a formula - formula <- paste0("~ ", var, " + ", "strataVar") - formula <- as.formula(formula) + formula <- as.formula(paste0("~ ", var, " + ", "..strataVar..")) ## Create a 2-dimensional crosstable - xtabs(formula = formula, data = dat) + svytable(formula = formula, design = data) }, simplify = FALSE) @@ -200,14 +191,19 @@ function(vars, # character vector of variable na names(dimnames(listXtabs[[i]]))[2] <- strataVarName } - ## Loop over xtabs, and create p-values - pValues <- sapply(X = listXtabs, - FUN = function(xtabs) { - ## Perform tests and return the result as 1x2 DF - data.frame( - pApprox = ModuleTestSafe(xtabs, testApprox, argsApprox), - pExact = ModuleTestSafe(xtabs, testExact, argsExact) - ) + + ## Loop over variables, and create p-values + pValues <- + sapply(X = vars, + FUN = function(var) { + + formulaString <- paste0(" ~ ", var, " + ..strataVar..") + + ## Perform tests and return the result as 1x2 DF + data.frame(pApprox = ModuleTestSafe(formulaString, testApprox, + c(list(design = data), argsApprox)), + ## Not available for survey data. Just fill in with NA + pExact = NA) }, simplify = FALSE) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 649bf7f..b4de142 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -166,10 +166,6 @@ function(vars, # character vector of variable n ## Only when test is asked FOR if (test) { - ## This is not necessary as it has already been created as ..strataVar... - ## Create a single variable representation of multivariable stratification - ## strataVar <- ModuleCreateStrataVarAsFactor(result, strata) - ## Loop over variables in dat, and obtain p values for two tests ## DF = 6 when there are 8 levels (one empty), i.e., empty strata dropped by oneway.test/kruskal.test pValues <- @@ -182,7 +178,8 @@ function(vars, # character vector of variable n ## Perform tests and return the result as 1x2 DF ## The test functions should take a formula string as their first argument. data.frame(pNormal = ModuleTestSafe(formulaString, testNormal, - c(list(design = data, test.terms = "..strataVar.."), argsNormal)), + c(list(design = data, test.terms = "..strataVar.."), + argsNormal)), pNonNormal = ModuleTestSafe(formulaString, testNonNormal, c(list(design = data), argsNonNormal))) }, diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 7879714..133b576 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -83,22 +83,20 @@ ##' ##' @export svyCreateTableOne <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - factorVars, # variables to be transformed to factors - test = TRUE, # whether to put p-values - ## Test configuration for categorical data - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5), # arguments passed to testExact - ## Test configuration for continuous data - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + test = TRUE, # whether to put p-values + ## Test configuration for categorical data + testApprox = svyTestChisq, # function for approximation test (only choice) + argsApprox = list(NULL), # arguments passed to testApprox + ## Test configuration for continuous data + testNormal = svyTestNormal, # test for normally distributed variables + argsNormal = list(method = "Wald"), # arguments passed to testNormal + testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ### Data check ## Check if the data given is a dataframe @@ -163,9 +161,7 @@ svyCreateTableOne <- argsCreateCatTable <- list(data = data, test = test, testApprox = testApprox, - argsApprox = argsApprox, - testExact = testExact, - argsExact = argsExact + argsApprox = argsApprox ) ## Add strata = strata for argument only if strata is given if (!missing(strata)) { From 7407949f065541f8eaca2688c7652e7833f042ec Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 20:50:13 -0400 Subject: [PATCH 062/219] Add p value checks as TDD --- tests/testthat/test-svyCreateTableOne.R | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index e4cfd12..45244c4 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -225,3 +225,29 @@ test_that("printing of a TableOne$ContTable object do not regress", { expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), "ref-svyContTable_noSpaces_showAllLevels_quote") }) + + + +### p value calculations + +test_that("p values are correctly calculated", { + + ## svychisq + expect_equal(attr(mwByTrt$CatTable, "pValues")[, "pApprox"], + c(svychisq( ~ Y + E, datSvy)$p.value, svychisq( ~ C1 + E, datSvy)$p.value)) + + ## svyglm to do ANOVA equivalent + pValuesTestNormal <- + c(svyTestNormal("E ~ factor(E)", datSvy, test.terms = "factor(E)", method = "Wald")$p.value, + svyTestNormal("C ~ factor(E)", datSvy, test.terms = "factor(E)", method = "Wald")$p.value, + svyTestNormal("C2 ~ factor(E)", datSvy, test.terms = "factor(E)", method = "Wald")$p.value) + expect_equal(attr(mwByTrt$ContTable, "pValues")[, "pNormal"], pValuesTestNormal) + + ## svyranktest + pValuesTestNonNormal <- + c(svyTestNonNormal("E ~ factor(E)", datSvy)$p.value, + svyTestNonNormal("C ~ factor(E)", datSvy)$p.value, + svyTestNonNormal("C2 ~ factor(E)", datSvy)$p.value) + expect_equal(attr(mwByTrt$ContTable, "pValues")[, "pNonNormal"], pValuesTestNonNormal) + +}) From f840d0b92451a1ecf9b41da573cd0fc2b89c7ed7 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:13:44 -0400 Subject: [PATCH 063/219] Avoid args = list(NULL) as it breaks function by unused arg It this placeholder argument is fed to a function with all other arguments filled, the function will not run, and gives an error. Test functions gave NA as errors were suppressed. --- R/svyCreateCatTable.R | 2 +- R/svyCreateContTable.R | 2 +- R/svyCreateTableOne.R | 22 +++++++++++----------- R/svyModules.R | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index b51ab6d..e71fc1b 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -87,7 +87,7 @@ function(vars, # character vector of variable names includeNA = FALSE, # include NA as a category test = TRUE, # whether to put p-values testApprox = svyTestChisq, # function for approximation test (only choice) - argsApprox = list(NULL) # arguments passed to testApprox + argsApprox = NULL # arguments passed to testApprox ) { ### Data check diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index b4de142..6ab6b26 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -87,7 +87,7 @@ function(vars, # character vector of variable n testNormal = svyTestNormal, # test for normally distributed variables argsNormal = list(method = "Wald"), # arguments passed to testNormal testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal + argsNonNormal = NULL # arguments passed to testNonNormal ) { ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 133b576..87025e1 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -83,19 +83,19 @@ ##' ##' @export svyCreateTableOne <- -function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - factorVars, # variables to be transformed to factors - test = TRUE, # whether to put p-values +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + test = TRUE, # whether to put p-values ## Test configuration for categorical data - testApprox = svyTestChisq, # function for approximation test (only choice) - argsApprox = list(NULL), # arguments passed to testApprox + testApprox = svyTestChisq, # function for approximation test (only choice) + argsApprox = NULL, # arguments passed to testApprox ## Test configuration for continuous data - testNormal = svyTestNormal, # test for normally distributed variables - argsNormal = list(method = "Wald"), # arguments passed to testNormal - testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal + testNormal = svyTestNormal, # test for normally distributed variables + argsNormal = list(method = "Wald"), # arguments passed to testNormal + testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables + argsNonNormal = NULL # arguments passed to testNonNormal ) { ### Data check diff --git a/R/svyModules.R b/R/svyModules.R index 581ac15..fd470cb 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -216,7 +216,7 @@ svyGlmTermTest <- function(formula, design, test.terms, method = "Wald") { ## Given a formula string as its first argument, calls svyGlmTermTest correctly -svyTestNormal <- function(formulaString, design, test.terms, method) { +svyTestNormal <- function(formulaString, design, test.terms, method = "Wald") { out <- svyGlmTermTest(formula = as.formula(formulaString), design = design, test.terms = test.terms, method = method) From d50af14f41bb29f7acab0a6a2a21537825810383 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:27:05 -0400 Subject: [PATCH 064/219] Fix unit testing for pApprox (svychisq) --- tests/testthat/test-svyCreateTableOne.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 45244c4..1ac4791 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -141,7 +141,7 @@ test_that("printing of a svyTableOne object does not regress", { ## These will fail when p-values are implemented -test_that("printing of a TableOne$CatTable object do not regress", { +test_that("printing of a svyTableOne$CatTable object do not regress", { ## Expectations expect_equal_to_reference(print(mwByTrt$CatTable, printToggle = FALSE), @@ -188,7 +188,7 @@ test_that("printing of a TableOne$CatTable object do not regress", { }) -test_that("printing of a TableOne$ContTable object do not regress", { +test_that("printing of a svyTableOne$ContTable object do not regress", { ## Expectations expect_equal_to_reference(print(mwByTrt$ContTable, printToggle = FALSE), @@ -233,8 +233,10 @@ test_that("printing of a TableOne$ContTable object do not regress", { test_that("p values are correctly calculated", { ## svychisq - expect_equal(attr(mwByTrt$CatTable, "pValues")[, "pApprox"], - c(svychisq( ~ Y + E, datSvy)$p.value, svychisq( ~ C1 + E, datSvy)$p.value)) + pValuesTestChisq <- c(svychisq( ~ Y + E, datSvy)$p.value, svychisq( ~ C1 + E, datSvy)$p.value) + ## Drop names X-squared X-squared + names(pValuesTestChisq) <- NULL + expect_equal(attr(mwByTrt$CatTable, "pValues")[, "pApprox"], pValuesTestChisq) ## svyglm to do ANOVA equivalent pValuesTestNormal <- From 52beb28428fa9920009f65e5d302a200562a7351 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:34:11 -0400 Subject: [PATCH 065/219] Add check for pExact = NA (not available so filled with NA) --- tests/testthat/test-svyCreateTableOne.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 1ac4791..dd9b970 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -115,11 +115,9 @@ test_that("printing of a svyTableOne object does not regress", { expect_equal_to_reference(print(mwByTrtSex, printToggle = FALSE), "ref-svyTableOne_2StrataVars") - ## 2015-07-25 pDigits is not implemented yet expect_equal_to_reference(print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), "ref-svyTableOne_digits") - ## 2015-07-25 Not implemented yet (thus correct) expect_equal_to_reference(print(mwByTrt, test = FALSE, printToggle = FALSE), "ref-svyTableOne_noTests") @@ -238,6 +236,9 @@ test_that("p values are correctly calculated", { names(pValuesTestChisq) <- NULL expect_equal(attr(mwByTrt$CatTable, "pValues")[, "pApprox"], pValuesTestChisq) + ## no exact tests + expect_equal(attr(mwByTrt$CatTable, "pValues")[, "pExact"], c(NA, NA)) + ## svyglm to do ANOVA equivalent pValuesTestNormal <- c(svyTestNormal("E ~ factor(E)", datSvy, test.terms = "factor(E)", method = "Wald")$p.value, From b2e26caa76e46de5fc5c4492082836581c9491b8 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:42:59 -0400 Subject: [PATCH 066/219] Make user function testing print results (more informative) --- tests/testthat/test-svyCreateTableOne.R | 66 ++++++++++++------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index dd9b970..a48c16e 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -106,34 +106,34 @@ exactVars <- c("Y") test_that("printing of a svyTableOne object does not regress", { ## Expectations - expect_equal_to_reference(print(mwByTrt, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, printToggle = TRUE), "ref-svyTableOne_defaultPrint") - expect_equal_to_reference(print(mwOverall, printToggle = FALSE), + expect_equal_to_reference(print(mwOverall, printToggle = TRUE), "ref-svyTableOne_overallPrint") - expect_equal_to_reference(print(mwByTrtSex, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrtSex, printToggle = TRUE), "ref-svyTableOne_2StrataVars") - expect_equal_to_reference(print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE), "ref-svyTableOne_digits") - expect_equal_to_reference(print(mwByTrt, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, test = FALSE, printToggle = TRUE), "ref-svyTableOne_noTests") - expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE), "ref-svyTableOne_nonnormal_exact") - expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE), "ref-svyTableOne_nonnormal_minMax") - expect_equal_to_reference(print(mwByTrt, catDigits = 3, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, catDigits = 3, noSpaces = TRUE, printToggle = TRUE), "ref-svyTableOne_noSpaces") - expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE), "ref-svyTableOne_showAllLevels") - expect_equal_to_reference(print(mwByTrt, catDigits = 3, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt, catDigits = 3, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = TRUE), "ref-svyTableOne_noSpaces_showAllLevels_quote") }) @@ -142,46 +142,46 @@ test_that("printing of a svyTableOne object does not regress", { test_that("printing of a svyTableOne$CatTable object do not regress", { ## Expectations - expect_equal_to_reference(print(mwByTrt$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, printToggle = TRUE), "ref-svyCatTable_defaultPrint") - expect_equal_to_reference(print(mwOverall$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(mwOverall$CatTable, printToggle = TRUE), "ref-svyCatTable_overallPrint") - expect_equal_to_reference(print(mwByTrtSex$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrtSex$CatTable, printToggle = TRUE), "ref-svyCatTable_2StrataVars") ## 2015-07-25 p values not implemented yet - expect_equal_to_reference(print(mwByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-svyCatTable_digits") ## 2015-07-25 p not implemented, but will be correct without it - expect_equal_to_reference(print(mwByTrtSex$CatTable, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrtSex$CatTable, test = FALSE, printToggle = TRUE), "ref-svyCatTable_noTests") ## In this case, noSpaces does not make any difference anyway - expect_equal_to_reference(print(mwByTrt$CatTable, digits = 3, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, digits = 3, noSpaces = TRUE, printToggle = TRUE), "ref-svyCatTable_noSpaces") - expect_equal_to_reference(print(mwByTrt$CatTable, showAllLevels = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, showAllLevels = TRUE, printToggle = TRUE), "ref-svyCatTable_showAllLevels") - expect_equal_to_reference(print(mwByTrt$CatTable, explain = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, explain = FALSE, printToggle = TRUE), "ref-svyCatTable_explain") - expect_equal_to_reference(print(mwByTrt$CatTable, format = "f", printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, format = "f", printToggle = TRUE), "ref-svyCatTable_format_f") - expect_equal_to_reference(print(mwByTrt$CatTable, format = "p", printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, format = "p", printToggle = TRUE), "ref-svyCatTable_format_p") - expect_equal_to_reference(print(mwByTrt$CatTable, format = "pf", printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, format = "pf", printToggle = TRUE), "ref-svyCatTable_format_pf") - expect_equal_to_reference(print(mwByTrt$CatTable, cramVars = "Y", printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, cramVars = "Y", printToggle = TRUE), "ref-svyCatTable_cramVars") - expect_equal_to_reference(print(mwByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-svyCatTable_noSpaces_showAllLevels_quote") }) @@ -189,38 +189,38 @@ test_that("printing of a svyTableOne$CatTable object do not regress", { test_that("printing of a svyTableOne$ContTable object do not regress", { ## Expectations - expect_equal_to_reference(print(mwByTrt$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, printToggle = TRUE), "ref-svyContTable_defaultPrint") - expect_equal_to_reference(print(mwOverall$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(mwOverall$ContTable, printToggle = TRUE), "ref-svyContTable_overallPrint") - expect_equal_to_reference(print(mwByTrtSex$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrtSex$ContTable, printToggle = TRUE), "ref-svyContTable_2StrataVars") ## 2015-07-25 p values are not implemented yet - expect_equal_to_reference(print(mwByTrt$ContTable, digits = 3, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-svyContTable_digits") ## 2015-07-25 p values are not implemented yet, thus correct - expect_equal_to_reference(print(mwByTrt$ContTable, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, test = FALSE, printToggle = TRUE), "ref-svyContTable_noTests") - expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE), "ref-svyContTable_nonnormal_exact") - expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE), "ref-svyContTable_nonnormal_minMax") ## This does not make a difference here - expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, printToggle = TRUE), "ref-svyContTable_noSpaces") - expect_equal_to_reference(print(mwByTrt$ContTable, explain = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, explain = FALSE, printToggle = TRUE), "ref-svyContTable_explain") - expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(mwByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-svyContTable_noSpaces_showAllLevels_quote") }) From 5bf3ac645e1d12aaff85d4a7056da5c044c949d9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:51:34 -0400 Subject: [PATCH 067/219] Drop obsolete comments from unit tests for svy* user functions --- tests/testthat/test-svyCreateTableOne.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index a48c16e..6fbe386 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -151,15 +151,12 @@ test_that("printing of a svyTableOne$CatTable object do not regress", { expect_equal_to_reference(print(mwByTrtSex$CatTable, printToggle = TRUE), "ref-svyCatTable_2StrataVars") - ## 2015-07-25 p values not implemented yet expect_equal_to_reference(print(mwByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-svyCatTable_digits") - ## 2015-07-25 p not implemented, but will be correct without it expect_equal_to_reference(print(mwByTrtSex$CatTable, test = FALSE, printToggle = TRUE), "ref-svyCatTable_noTests") - ## In this case, noSpaces does not make any difference anyway expect_equal_to_reference(print(mwByTrt$CatTable, digits = 3, noSpaces = TRUE, printToggle = TRUE), "ref-svyCatTable_noSpaces") @@ -198,16 +195,14 @@ test_that("printing of a svyTableOne$ContTable object do not regress", { expect_equal_to_reference(print(mwByTrtSex$ContTable, printToggle = TRUE), "ref-svyContTable_2StrataVars") - ## 2015-07-25 p values are not implemented yet expect_equal_to_reference(print(mwByTrt$ContTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-svyContTable_digits") - ## 2015-07-25 p values are not implemented yet, thus correct expect_equal_to_reference(print(mwByTrt$ContTable, test = FALSE, printToggle = TRUE), "ref-svyContTable_noTests") - expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE), - "ref-svyContTable_nonnormal_exact") + expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, printToggle = TRUE), + "ref-svyContTable_nonnormal") expect_equal_to_reference(print(mwByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE), "ref-svyContTable_nonnormal_minMax") From 61144fd414cec65cda4aea6795eb8e41e9cbc92e Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 21:55:47 -0400 Subject: [PATCH 068/219] Update regression test references after including p values --- tests/testthat/ref-dummy-failing | Bin 87 -> 0 bytes tests/testthat/ref-svyCatTable_2StrataVars | Bin 259 -> 282 bytes tests/testthat/ref-svyCatTable_cramVars | Bin 246 -> 270 bytes tests/testthat/ref-svyCatTable_defaultPrint | Bin 218 -> 243 bytes tests/testthat/ref-svyCatTable_digits | Bin 87 -> 298 bytes tests/testthat/ref-svyCatTable_explain | Bin 213 -> 237 bytes tests/testthat/ref-svyCatTable_format_f | Bin 194 -> 220 bytes tests/testthat/ref-svyCatTable_format_p | Bin 204 -> 232 bytes tests/testthat/ref-svyCatTable_format_pf | Bin 223 -> 249 bytes tests/testthat/ref-svyCatTable_noSpaces | Bin 239 -> 265 bytes ...ref-svyCatTable_noSpaces_showAllLevels_quote | Bin 279 -> 297 bytes tests/testthat/ref-svyCatTable_showAllLevels | Bin 262 -> 282 bytes tests/testthat/ref-svyContTable_2StrataVars | Bin 280 -> 299 bytes tests/testthat/ref-svyContTable_defaultPrint | Bin 240 -> 270 bytes tests/testthat/ref-svyContTable_digits | Bin 87 -> 285 bytes tests/testthat/ref-svyContTable_explain | Bin 226 -> 249 bytes tests/testthat/ref-svyContTable_noSpaces | Bin 240 -> 269 bytes ...ef-svyContTable_noSpaces_showAllLevels_quote | Bin 253 -> 281 bytes tests/testthat/ref-svyContTable_nonnormal | Bin 0 -> 291 bytes tests/testthat/ref-svyContTable_nonnormal_exact | Bin 259 -> 0 bytes .../testthat/ref-svyContTable_nonnormal_minMax | Bin 260 -> 292 bytes tests/testthat/ref-svyTableOne_2StrataVars | Bin 294 -> 314 bytes tests/testthat/ref-svyTableOne_defaultPrint | Bin 250 -> 274 bytes tests/testthat/ref-svyTableOne_digits | Bin 87 -> 319 bytes tests/testthat/ref-svyTableOne_noSpaces | Bin 260 -> 283 bytes ...ref-svyTableOne_noSpaces_showAllLevels_quote | Bin 287 -> 335 bytes tests/testthat/ref-svyTableOne_nonnormal_exact | Bin 87 -> 312 bytes tests/testthat/ref-svyTableOne_nonnormal_minMax | Bin 266 -> 299 bytes tests/testthat/ref-svyTableOne_showAllLevels | Bin 306 -> 356 bytes 29 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/testthat/ref-dummy-failing create mode 100644 tests/testthat/ref-svyContTable_nonnormal delete mode 100644 tests/testthat/ref-svyContTable_nonnormal_exact diff --git a/tests/testthat/ref-dummy-failing b/tests/testthat/ref-dummy-failing deleted file mode 100644 index a2485fec14c443155a41824efad690022216783c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 87 zcmb2|=3oE==I#ec2?+^F328|w2}x{5k}M4~CN{P<3VUR?r=*B!GXySj^2*H1Tj~^; m6_pj36<4&%$05AW80-6Gl903H89XfyP0nx<(rP*wNq6UUoc?=jd0}B(7V1)9SQ!;Zw=7Zx2 z$OU2!G$kBBC3%Utsl`Ag!ccVrV6_l=#ylv4Gg84;!B9a%RTC<}>mUFLLSku%nauy8E@7jB@4+r*_y+)E Koe8m80{{SD)K#Yd delta 185 zcmV;q07n0s0)qmO903rK9Xfw(I_qL!VFC&=LM53~GIK#{z+nyK0x=t!5)Pn}yu{qp zVxSUXs5$|#T8KPj9+bfusbH&MsGy;$2^HXSHiU~n^svFKHMD}cnb`=zG)6EDtqc(g z3=s+p(Okz0bsE@sCa53-lokpuDM~EKOv_A7QAny(aJ6yFLmdNYp&u{X{%B#xM_iI!Mg{E zskSDVCiSBLiH~1+$E97MKmDwp=5Mddx->6#qjS5-?8<#j7@ao$ U4mUnDd-D|R_JoyNxPAfv0C9kS=>Px# literal 246 zcmV8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IbxOu zdgl73mU;#X8fFH1X8OjKdM26*P+36*5CADx&@eXEGlol`nPI4BfH1=xWQH-V&0t_* z0!lDK6)>k{<^m~Ru(yF+2u4xD0aTKgn44M*R3Z#jCjeFlk!Q?+m=$U(SRWHqkO4~b2bUBjmSm=7rlu$)RVugwh5n)G w=P64~cFxZU&rB)F06CryWW9qD*boME8lso^KT*yES;g=V0Ab-ihiwFP!000001FcZ83c@fHd`(+XQCsi_vIx3_#Mq&OAc$Y!ppMm6ENB%Q z1b@DorfG+$n@jHAP&4iC0o8 tjC}8r9G2JfCXL0ZoM%wZvGA+Km{?`)mpSjZ-qlx7ya5+~kfTom000*Tb%Fo@ literal 218 zcmV<0044t)iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXtG8 zdIky_#+G^}nhJ0+1F)E}o-teuhbCicYGPnv0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ|a8Jv*{whD#{8mgL50WN1lxCojaLm0yd#xO>+mKACzSRWHq zkO4~b2bUBjmSm=7rlu$)RVugwh5n)G=P64~cFxZU&rB)F06CoxWW9p`*boME8lso^ UKT*yES;g=V00Y|7o&Es;0KZ~RAOHXW diff --git a/tests/testthat/ref-svyCatTable_digits b/tests/testthat/ref-svyCatTable_digits index a2485fec14c443155a41824efad690022216783c..5373eb37e152f98728213f7a3ba10d024d782683 100644 GIT binary patch literal 298 zcmV+_0oDE=iwFP!000001I>`)1z0Hy^vV9ROg!SpbaNFg8aYLTDS@mxv>jiqcrA5uy|W zi)U&mDqa{Bq8NBw@!pQfPxdw0FLvCp*4 z7sCAD$&iRnCRdF2 zL{(dvR=aamhe;jERMrAn3#u@9r6APBLN`XqNm_rfy_*!4Uzao5QJMn)09)6Q@c;k- literal 87 zcmb2|=3oE==I#ec2?+^F328|w2}x{5k}M4~CN{P<3VUR?r=*B!GXySj^2*H1Tj~^; m6_pj36<4&%$> ze_l<~#3AbDa_`>VyX4(%+5mvT!w9ffrI89f@S&wJh$oCPL&C|FGBV&(Iv$dDjp-Vv z{9XGo#Q#481{)-%jIpl_J`jAY0y5l7MXsQuub^n<#gR0Xq)76tRFb~YMOs_;QDK+Z zk{OAujYX_ktqrW!w$aEY+$I;3_%bV{;~_8x^kdlBskf5XM2dsRQnI^~r7As~`S6zQ n7w6Mjr1Dtp(XIT?qxv8&*0bKz-SeAw{S`c3Lij7@M*;u8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXtG8 zdIky_#+G^}nhJ0+1F)E}o-teuhbCicYGPnv0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ}_91^Kut6&J_usIuod1z{3(u_thhB2CTtWdka`k0`C3{aXs zxTGktBr`2DHANw*Qo$7{^bbuxPg!cRbAC>EW=cs0$jN*l>m3BZhA^Ph5WUR*iE<{$ PDu#amZs%Mz_5lC@k=sxT diff --git a/tests/testthat/ref-svyCatTable_format_f b/tests/testthat/ref-svyCatTable_format_f index f25712e9bbcbd426be0c5c074af01fb9e79930b4..b900dd68e66bb560a6b5a256d7be12dc908bd6f2 100644 GIT binary patch delta 200 zcmV;(05|`_0o(zQ9DhFp3j-&RW;HZ5&@+H?SWGRE*a&gzDPn-qYzl^Y1_lOLc?=jd z0}B(7V1)9SQ!;ab6ff9UKrYB`G$kBBC3%Utsl`Ag!ccVrV6_l=#yps#BNc2F3}Mc2 zHU#q^YFS}wVbY97ForRVQ2_H|NosKknj2W54ged*gytvy;6ak2#FEUk%+wTxq)G)> zpwK@w{XAu<$Oog delta 174 zcmV;f08#(k0m1>09DgSR3lK9fuo{{g=ovscET)!7Y=k&96fv+c0ojaDG3J!aTp+~@ zb{UWh!6-^NfJ*Wbb5o0fN`#^61i1k)9}`rN0ZQ`+mlP$IWTs`NrYIy;D!2lL{-NpTDN9Xu&L__a&rB)F06CctWW9p` c*boME8lso^KT*yES;g=V0Gt$y(#8P*07dsg_5c6? diff --git a/tests/testthat/ref-svyCatTable_format_p b/tests/testthat/ref-svyCatTable_format_p index 82cb63c47ea9c1fe5ac84859b69c04469d4b2205..d9e84afaec72e1d0fa156ac1f866b57893f8daad 100644 GIT binary patch delta 212 zcmV;_04x8@0q6mc9DhFp3j-&RW;HZ5&@+H?Sd1<8OyF!|J!4#ojLB8R0HxU!4D}2Q z46yPTFlYuACLqBG5_40Ffl7p->IA@QA@YoQPzGnD zf~|s~f`+OlRDjFb5H14I!wS=52xAz*7%*Qk7Qnn(l3HAX=1mq>s6)VpF`@a5Ke(hQ zu_QAsGc`pasZzleDD)3aKTla|vU7e;cxFmT2FO2rAb&UrKmrDxhUjJfkM3V=ZUAl9^dF0f2$eJYarKV>%)Tpg|bQq2R(6Ej8i;><&j<^zfl6 zu1FJ4+Dl0NR|qWDP;w!}+X`L~0!D{tYd_6)1Ruo~sLXqDEOoN%lbybhrDJ_@;VtjI zy(R5$9HYcf?5@xH)U#?dm4D?j9ad>sk$y!~MUIvPMqiB6RcKo(9%Igw(cGL9ldUtI z;_?S)B;A~R>#A4N!}cpn%_g6$oli80%N4m;X8m7x@^`%#U%~ATP+tX^Spon6Jxg>! literal 223 zcmV<503iP#iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!60}Bu{Ft8e$8t557IXuRe zdL{}Qrj~jJnhJ0+V?AS_m;sU)h9+a`Yhqww0*Wz0<(N}4bAc2u*e5_P1fwY704m8# z%uOu@DiMaN69B7&$TQ|a8GMlnwhD#{stOuuMX80FP*HwoLsVfj-G(rR5sYDs<^Wcx z?O=UOP(cQm@xdiUi6xn7nW-rXNtFt&K%swV`gzJylb!Q(!ZTA!GC-c-16l7N05*gH ZordUT{!f%MK~^#R0|3T#+wuqk0038yQ#Akp diff --git a/tests/testthat/ref-svyCatTable_noSpaces b/tests/testthat/ref-svyCatTable_noSpaces index 5880e835cc818df019bd7aaf28a39d13bdf83734..f58eb96e47c830eb5dec4083f682658ce61fe8c1 100644 GIT binary patch literal 265 zcmV+k0rvhMiwFP!000001C5YPYr;SfhG#bkHqsiQmmc?0sFyI?QNe>CNPj^OZI8A| zX`p_fi_kxBog}+r)*QU-eC+$|&O7g20FV$!0Wv7lJ|78$5OeJ45vHi0ZJCTFDWXCPYKO^#u>s?iFxVLBvnLt_Tto;ZAHvo_RxCN(RlDJ` z479KL6AUw+)*E`Ge4!DUg=}@P%p-hH5>fnNBbxYi>TOycL=^b#=FjJ02XwV6c0^9_Pgn|c-k0021ua#jEU diff --git a/tests/testthat/ref-svyCatTable_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyCatTable_noSpaces_showAllLevels_quote index b60209e682ba9288997cc3e42f475abb6d469155..4de27cc3a4ef2faadead400e1472dcf3212f2c4f 100644 GIT binary patch literal 297 zcmV+^0oMK>iwFP!000001Iq$OC(r zBcIbGL!PC9n&lj6B6EHbsF6T4T$b^9E3=f8T&CYA3v0p8mXIv}O)@kcI3oUq{Jlb- zm<{*qs3=#u9NFKeGxZ&JBttD(FIQ@#B`01twpt&-*382_c1M%*G%N`VXvh|#`^Kfj zjkQu+Rk0>iv~b!&*}|6qV^*t8%{pTb{LHos2`<`#{B%OI6VOH+p3z+I2!k vTlKJbu5QYrelp*GY%(rS-9~n+^G5H!XY}Q?PXmyy73@9$P0I~aI0FCx@t=j# literal 279 zcmV+y0qFi8iwFP!000001I<#=O2aS|y-PZr+mwm>fDjPcmyj&3qi@347x#EokCTGtdY~_NF9h33FyewbKha#`G?wXg*<8JC- d7<6mhOFu&<{q^)_2y`6<$1miTrh&x*007I6h1mcA diff --git a/tests/testthat/ref-svyCatTable_showAllLevels b/tests/testthat/ref-svyCatTable_showAllLevels index 096ec7ba068860bc07f1c9f936cab802d1a4a87e..93b5232e17b20786a26e3bb164833a628c83db6a 100644 GIT binary patch literal 282 zcmV+#0pBVHZG*b#o_C`Yd0uJgC-5NJp z&`3k#&m(QOMJYi%+QZK5%X{;tGkrJ*00NXWfKZ$E%;yFYI0Jj?*uap8qexSXkO%aV z<;ce@&5&n(wgX2wN0!Q*55GZyXu&Mwl6RjZTCH@{VAFT!DwD{+JJTO?UA~m6U{9ay&On<;f3a52)3@rrEcC0r gWXH~Ba$R>D$68CjydC|mcV`8gEm~Tgv@`<%0C;nWAOHXW literal 262 zcmV+h0r~zPiwFP!000001ItdwDM}n@0dZfKdk!*5gPmV+h~@^jGg4<_3Nh>GBz)4t*vu zqjM5Qj7AgEfU}q~5{j6<{ezq_4Mq{2pEC_81QiYF8*n3IZJ9F=_hkS9(p}k~IL!*p zG0iJq({r2BSCld-79r+LqSt)|zZKd!X~?@#b}A(uY$32myrwgh;}0#8Jp|hXMd;Zbz?zv+ve*D6# xs-}Y7I2Pxh?5TcxU3V>ik!z9bi}m_EpR7gS`o{POQ>u<&^8*I>6C>LL008f`lRf|d literal 280 zcmV+z0q6c7iwFP!000001FexwPlG@ZhKJp@sjZksFCOE diff --git a/tests/testthat/ref-svyContTable_defaultPrint b/tests/testthat/ref-svyContTable_defaultPrint index e38e84bf0ac4aca01d13eb750b6dda9792fb38a3..4f0cf92c614321ca79158506bb9ee764a0eff059 100644 GIT binary patch literal 270 zcmV+p0rCDHiwFP!000001FcX^Z^AGPb(0pcj}9dG0XddSm9|3+iCe`l-~iWd&9q8u zH?0v8f1VMy4v32FfH)+6etCYey}1Vf2Any-IKrX1#^A!8iM?nlLm5%_5QS2Tz%X)R zsW^-hq+aGnN`}ufq^3tzYa>rJH?c{sv;k|kz*;+8PvCU&Vg`RkaGALr%6VRtCiu-p zQ3T+1Bz+^PvQpJXG9ulu(YEhSMZjN*pj25Uf;ykr*8TJX`IN?IY-{LQLpz`oTaZ}r zO~BQv)}2N@>asCooxuky{gdh9y->M$-HD~4_MQ62t$ItpKG#LAKX6!F3a6#eK|TMa UFZh4`HukVT0Gyz4JFEf#08$cu+yDRo literal 240 zcmVaVs12pQH_yivGih_|uFcD(n z%d6ekG!hS*co;3ee*M;N(*pnklo&v$NJsdwz=STwwm;<__tjtD_c&(`67Fggcz!6* zeDOrwo6H27K2^01fA##uCj8k3OoGTzC7NV823zirHGvwE4oZqRPfL`Hm2M=pb=@db zVlSDKr*XlYGI90YcJu)bqTr3zhEyBsw>AQugpHY6Y9QH16a*EAtLhwA**;4Xw!N|? qqFbZix}>}4bX;dibr5^m_1 diff --git a/tests/testthat/ref-svyContTable_digits b/tests/testthat/ref-svyContTable_digits index a2485fec14c443155a41824efad690022216783c..b9d3f5bbbb53947c520b3875803c5b693fc5557c 100644 GIT binary patch literal 285 zcmV+&0pk82iwFP!000001Eo>RPQx$|T-%8#h({&(03VY}v`(7RO5CD;0SCASVnieo z5V4T>`GW1(scN7X4)%J-vg)PhQ;pTVYTH?wQ|RFYUnw|ztq6R*^L!I;d5?1Pi4X! z{)`Y&y%CqQrtM5^J8VM&hy%(@Q~J7-gQi?M-rRD>d(wLY8=iEs?s+ma>Ex>V1w60v zJ#-X|y`VQq{09^NH{{J7A|(eEG#a}utr!iAU)-wqTD4EDZ1}?`-)LwXyg&VrkJanT jUE8Q^3AO1W*rs18$s=Z8oQ zhEGa)-9A#ir|My&UNe8O34gQ!wj1Frhby?4PQC5mV+C87!=hfs>DH85_D4|!;N&Dl zBiYTj$;n8Xq-$i_$Gx>N#0P`^_|s^%{dnLS+Z#?a7yhynlr%qw%n literal 226 zcmV<803H7yiwFP!000001B>8dU|?WkU}j=uU}6R_1%Lz(0}BHukY+P9HPACKgz~rz z^$ZLYG=L%onlK?FJws!VkcA~&$Ux7;93*54R|PS~0HKE}#u$@q32yK#hj9v z3#53#{s+o|gwT|50F~q==B5?{l?X%C34ql?1q+9}`rN0ZQ`+mlP$IWTs`NrYIy;D!2lL{-NpTDN9Xu&d&+YOex6#xtSN@ cC$Qh37^I&0KT%Et8PD(!0I!@=Q6T~V0PJB^j{pDw diff --git a/tests/testthat/ref-svyContTable_noSpaces b/tests/testthat/ref-svyContTable_noSpaces index e38e84bf0ac4aca01d13eb750b6dda9792fb38a3..f30fd55432e647094a4a811fed287d488bbc2d44 100644 GIT binary patch literal 269 zcmV+o0rLJIiwFP!000001FcX^Ps1<_b(0qHv9d|<19I#xRoZTXNxN111svd7Xb_cX zK{T4QKR>WrXA{-fVd9YZ`Q`b=_R}Q*2#~@9Aqh_Kx& zqtZCZh`L|wC>_u4h??(Iy^Y@2{EJO?q768^CDpp&0vb*qO5o23zQD`lT$WXhA?)@^ zBJ>$Z&Qa17wP{gu!@5bQ?ccqILAX*;ZHh)kZ8>#~hxq~WI!}MGy|y%@YIo-issaE2@7skP literal 240 zcmVaVs12pQH_yivGih_|uFcD(n z%d6ekG!hS*co;3ee*M;N(*pnklo&v$NJsdwz=STwwm;<__tjtD_c&(`67Fggcz!6* zeDOrwo6H27K2^01fA##uCj8k3OoGTzC7NV823zirHGvwE4oZqRPfL`Hm2M=pb=@db zVlSDKr*XlYGI90YcJu)bqTr3zhEyBsw>AQugpHY6Y9QH16a*EAtLhwA**;4Xw!N|? qqFbZix}>}4bX;dibr5^m_1 diff --git a/tests/testthat/ref-svyContTable_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyContTable_noSpaces_showAllLevels_quote index 24bca0dd7e738712ffae3277c03f22249a9f13ff..debfa92fd7c9d01404a39bf4a427851686a7a3c0 100644 GIT binary patch literal 281 zcmV+!0p|W6iwFP!000001Fca_PlPZK9ol8%XT<0aXnKMRX~B(a;*IPt@Ss}f8&kF-?y4l2=wcTg$s+sB55eIWtmO!^3FZ@g z_i!n#>8zZM9@5->Eb}fQz3W`w*^koJ&$X$<uC literal 253 zcmV_GVxyJ+MGOqqc++~c|f-pxT&*i>E z%TU@qdni4id;vOE^w5F`4E0#hOGdOJ7*>C`)d_GE+XQ^r{G& zQza*KP3$a*a$?_N$7yi*4O=wyK6w?4>tIf6={3@)tq!}Yy|NlVUfD6d2f>Bp~Dmxg{BhNp#J#l!Ora!hllSONe5 DG{|#c diff --git a/tests/testthat/ref-svyContTable_nonnormal b/tests/testthat/ref-svyContTable_nonnormal new file mode 100644 index 0000000000000000000000000000000000000000..d49797dd239e1e5fc8221b60535cdd204bfa0f82 GIT binary patch literal 291 zcmV+;0o?u{iwFP!000001FcX^OT;h`ohI%2xmwX5kYg95q^*k=Z)Fc2)q}#ahiW1Q zY%1Fz_~%zMZL(kxFM8Y&IuXPIUA z%uy#LQcHX|XO)dBujTp0C2Hqe?P$imp!`p>>Q83iO|Q_wuRCGb%zvyP$UC~zx?8tf z8e(EY3fDU_v` z*EhE-&mYz0H}&Y5cu&7-RC-W(@a8~lWN(656F2B!MuJlu-8dU|?WkU}j=uU}6R_1%Lz(0}BHukY+P9HPACKgz~rz z^$ZLYG=L%onouD@Bal!uNJ2-!7)Zv#)EelSn1j@s!qq|yGk_^DqNZWSWE#f6!UPmz zgi0}|Waa`XUT}y2DcN;rT@@)C1Xi-Agnq3Q&{Y9aEBc~AzgtAa*uYGR&(MsbQJ z%uxc)Ai}qK!B162*q$}%@xFOX#FT(@{H#$JI*uCS!xkJ zbI^H#&>9QZY+>!jb9uJ7LGE(L9mKdN6#pqU|C1Pa(OXpT>y8*U^Sv1aeykgn8oFu?HXtC|M@s-oE_`x4k6R+x*jS3&keemvr*vQTV(sjF+MAGVURtez`B`Z}ax@u>A%HZqzZ#0ssJJdW*#X literal 260 zcmV+f0sH$xXOcQDO5^MHe&kLp^3B8i(@koR=?l@16TB{lzz_(x>`g5Tw3YvI^cSJxS@%I4|7^Ckn@=1uv=oxISWbQ zk&$ktw7t{PN{E;wnlWP9#(1nUjl_RsDw<|5#ouWBG+J_A+H5z5O*Arzg-ZFBR>{6U zc)uN;yxvKey!set=N{uGI(bgqL@WOn2l@%`dkCJmgI}-UyEHk&-YcrQzqI^+=ujGg zWeLdA{)XENqKNm$}X+#Q8IOV93H7Ei5v$l*>#UB`Rj1 zuZ^jGDNmR%F(IaC3}_5Gbl!%*@5;8bN}dh%N~UYI@anO9&%5fiDhu}V!47GLq<;3} M3+%0QUx)+%0KtWtSO5S3 literal 294 zcmV+>0onc^iwFP!000001GSR9PQx%1g>UQ@wWUQByuckmN*2r4X{j2CDe4n+fiWmS z%8(4S3onmw92+Mg3xW>*$>(!?>>EEX0Du8!0WjW7*Sfoh3C#6)MN$e$_UoF2lo)Cv zBaa>p+Uy-#DkU`1Jw@nbC`Ie^Nd9oPY0?SQ@6zPo(&EdeO}E{!kwV5owU%$RjCak( zyG>{3)z*ZWqj%$m-hSLjB`+B_Qp*2|g9+0puuD8ItHx$tu>PZM>q%x>QfF0h(vmx? zTN_=w9@H-TfMHc+HHN1=a)(@{BXItLPe>R(IIu`*KyFgiGxjq%C9YOn`DyH@l#myY s7tr8#Q+qYDJ+lz(czZm*XXo;*EOLDPz(bO1JA5|n3)b}Jg7pIc0HOhkB>(^b diff --git a/tests/testthat/ref-svyTableOne_defaultPrint b/tests/testthat/ref-svyTableOne_defaultPrint index 6c744ae1a15909c06f43519a9401e612d73e5589..96fecc44ca20097884e170035f6d029705df3c74 100644 GIT binary patch literal 274 zcmV+t0qy=DiwFP!000001GSOCPJ}=VhRXmOcUN>1@1_?MxJ+i4B}$?vvQOYej~FoF z05QVFmp67`ijnNWjqxzk_T!)aX?fZJfB;{3Abgwd=(>gg))ZGdQ&MSHZM9SiVl!5nW>Q(X=b)na(`=|W^=d6PJQ=2$7az>J_Z0nvRS5CJZwbOU6b4hf-xUI_$ Y=C!FSeEGlwp-+3h0CB`1YvSEd`LNYUNCNobGpAP_FgJWA@JCl2)=@wkrlii6FIf@un90-o|u@Gk) zX*uRX%6O9VJWaHGObbdAER+RLFpJo#&)Z3tTuQO(0rDivvZ+i`6l<9U0ww-*+lG(} zL?$jl(DDX^G$8I3L}5VS3L*avf&YZabs5kw4@*~}W462tt}$|A&*RPY^B8_@!L@0! zRP5AkN5-H3Ab=|xo{_Snl)mbkfl_W%-f_-d)~#MS{)vTMQ}rwy>PR2hFE5Du7xu{L zLGQG1D21V1m+{%grKhKR>U*>F1zA!%@5*t4480$ z7~$g28)spsjid+aft@#xH}jZbUspm1DSYV(>07v=<4y!(N%6|0puxE8+Gqe369ZeO z5^c~@PZ?9|G$VmgF=l!P4=38zQ8}VUG{**@caOF~dh9ux!pY%6Q$##(it|lzzA60Q zRIvH8t>86>cFk~EB4$SsNIE>1`(@owh=w~rA7cAXBny(XMN@SoxplhDpdH_Ptpm|s z#Z6VTD(=cHj~L}=$mN@QQS`I!nONm!!rbJ^pTf~IWKZ6emoPvEpAH0l)%BBELO00J hOip&QKJ;HjUw_n9souZUo~R%D`~qmcy_X^b006l`gem|4 literal 260 zcmV+f0sH+kXfrTHJOK-gK?zcZ zWB?Xk9`&5qphgVP!S?y*@9sO<-i-i2fG<1{z6mEhO`!)vUO#k<3boyhwL+936I?hH zDNP3bBo2MW2@A9gDN##YJ+R5+bRtEh?*&jTzfFPoUb8jDhr^quMD*O0UN@!JP4Pdb z&=ZV2d*tV3#Y@n<1ovW4M>1eZomIt|B{Qp=G}`vut8EZ$WLOnhEyHuZaNa@s1P=Fd zE&0mk4vbRWA)jgVC$aVPou~U4UgQGmwB5HoH+jNBa2K_`oU%)KEQ?$ou5!cZX2vfn KLT#Co0ssInT5~Y~ diff --git a/tests/testthat/ref-svyTableOne_noSpaces_showAllLevels_quote b/tests/testthat/ref-svyTableOne_noSpaces_showAllLevels_quote index fc0ccb5cb4ba3b9810489ffbfcd071a19181e2cf..6cb5a8a4bc7edb1556543728d55e91cc51df3b4b 100644 GIT binary patch literal 335 zcmV-V0kHlbiwFP!000001D#UOOT#b}&eC=MsA8vg2?3!6DM_;`13gID!Hb|?l(9p# z6?$kUYY+3E7hk$0V|54Jq3_4{zW2VDG%tq;A&eZ{L)cNF59S>8(E<1YPgumb&O9D5 zMgl-ssG(u3ps6Zc5&?Fm3n$4KGEM?9jz;V%w6N-iAwon#a07cR8eOZ&iJiQXW`+>& zCM|^6E-n5pE&eObc9%wGg&WmjF5Xp2W*_`;w+-G%P{;4dxs>xoWw^yMdvAVmQ6Gcp z>Dt>D@fIJIHC4#hhBG~s|YMcvTOAzgjKb}Tks hgqp4)eQp+6Q+||1PTs!AM6K|xz8@8;VG>&d0079Nn0f#J literal 287 zcmV+)0pR{0iwFP!000001D%nvPQx$|hTWu~LO`VD1x_a+B@(jiTvODcQ`CVGSU^>W zpadyHGSDu(JmQ?%MnnwIA@=#Z|L#9K&*wsjK!m|a1fdCIUS?t}&Uio7xspoTQ>3L* zkT6lHMbpfnjY-@B@w&B%t9;2P4GAsfTrE74t{2W#a7*>ToH z^t(0v-J1Sut&Xu4A40BWUzt_8k%q?s8%; l(pLvg2k1(s__Tj7_sv^VSMd4)Yvc53zAx=LDU`ng006`SiOT$1AhBsf;wpJtFWiCPjvTU*qQqY5h9=r(ZMJYW* z6CsCerO846yf~Ze1R6alc*yL`GjHb24tbm~#%$);7PB3l`WQ}`%f@()qC{{JnQ9tw zAs|2^LW7QDjaIsG4ie+qG!BvlN3C4&c?dldEt6dKY%2KtLeEV4nVqR1LHrw2`A1Xv zFQ$ylFSQe`c?8;oKE;9C>mM7t6&sv;YNOO zXh06rcxPZ|>ya((&Wb6Kl)Rb5ZHl@XT*otaX@}W^^&CAk+pH;H%OZ#84_G4l)Xx_X K1WjBr0{{Ty8IRNe literal 87 zcmb2|=3oE==I#ec2?+^F328|w2}x{5k}M4~CN{P<3VUR?r=*B!GXySj^2*H1Tj~^; m6_pj36<4&%$UCc6Ox9#rtKGjHBJ<}t%Q&Iuuu_|zlRH*kgFhD^u|^Hijqabc^4V4OpU z438{z85?SE8h4OjJlMurx@M@AYnDVXaJ=IrlLNQlEV(x`(_vYKI!6oY4LzbGqA%kDeiY<$5;a*7h2SE@nDwbiXU zZQu8_1X`&`JXg>fw>eE%ChS!A%~vCC&;BGC2bQ>Z}ltEj_q1{=RSL8_>5I00{7f2g0}QhK?KZ*wh`!hnbh z89hc89j)+!F`XwC7Rg?c*X(5+V$W2|j5Ix)D;e+X%%q>$g(_!=eiLf`7;64G6h?xO z$C6)EHI-%iC1@9m29^m~n!GMAWO-uWruBBZ*Ko7UFsRGC!QfJaZuxC$VNnr2p7Z9b zJUM0hj<2XOcy?fx>H%4$(cQ={*muG1@9-kmn8EI2Uc9|07y{Sz;d;)m)n`=}`06AE6W^x#EMFG}el zniT>~Ds2$^=f$146Kz@*4}yVgCeOaiyt_MlyC;NjMBS+gr%qwl3@936SJ1QlTVp}Z z`;xGB2fP7FWZVHyB7$oW_AEOBpV)+EPC=P*YG?Lgh%y8>KpFI)goB|pDb!H*KcI(5 zFbHJ$Sy@1(q$*(tQ1(M|Fen{ZlUPdp-u`Bqm9GiDr)6hl^DLV$Qv2J~FVRE(L+4W9P@A%qI7w-F#U&7;O+_n`wvl8}s+UG` zY<1m2Ydb#UJsN|X>L>$u8TWWUx+8*dV({eR>Uzq&c?a&v#-@$DE%adIuO)sj-{M3w z{j6sj_tED-aqwh=My{86WsOa{z#_9#segErFQPnoOmqzQD;OK}O79zdL z0!%oIyAe-Tve`o$7bAJo~3_Lag=IJm{2Z9erpr8HU3AsT0NSyW% zMM9h$o}=JI7%D`OW#<@cw$hm^l+qL7<2MjNx(GngMVh=qn z;z8k$_P#5$sbA{Nw?&U#AV=d&?JTAU8?`#S+dY@N=BcSGe0;^FLT~zg2fKlBEPn$4 E0H)24m;e9( From 4eb2d31739d494da992a7593d10bbc7541a0d372 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 22:06:01 -0400 Subject: [PATCH 069/219] Add printing to user function unit testing; add test-all.txt Occasionally do: make test > test-all.txt --- .Rbuildignore | 4 + .gitignore | 7 + test-all.txt | 936 +++++++++++++++++++++++++++ tests/testthat/test-CreateTableOne.R | 66 +- 4 files changed, 980 insertions(+), 33 deletions(-) create mode 100644 .gitignore create mode 100644 test-all.txt diff --git a/.Rbuildignore b/.Rbuildignore index bd7579b..096149a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,7 @@ Makefile tableone.Rcheck .*.tar.gz .*.gif + +## unit testing +test-all.txt +tests/testthat/ref-* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5f15b2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*~ +*.DS_Store +*.zip +*.pdf +*.Rhistory +*.tar.gz +*.Rcheck diff --git a/test-all.txt b/test-all.txt new file mode 100644 index 0000000..ad61cfc --- /dev/null +++ b/test-all.txt @@ -0,0 +1,936 @@ +Rscript -e "devtools::test()" +Unit tests for the CreateTableOne function : ........... Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 + chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 + alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. + Overall + n 418 + time (mean (sd)) 1917.78 (1104.67) + status (%) + 0 232 (55.5) + 1 25 ( 6.0) + 2 161 (38.5) + age (mean (sd)) 50.74 (10.45) + sex = f (%) 374 (89.5) + ascites = 1 (%) 24 (7.7) + hepato = 1 (%) 160 (51.3) + spiders = 1 (%) 90 (28.8) + edema (%) + 0 354 (84.7) + 0.5 44 (10.5) + 1 20 ( 4.8) + bili (mean (sd)) 3.22 (4.41) + chol (mean (sd)) 369.51 (231.94) + albumin (mean (sd)) 3.50 (0.42) + copper (mean (sd)) 97.65 (85.61) + alk.phos (mean (sd)) 1982.66 (2140.39) + ast (mean (sd)) 122.56 (56.70) + trig (mean (sd)) 124.70 (65.15) + platelet (mean (sd)) 257.02 (98.33) + protime (mean (sd)) 10.73 (1.02) + stage (%) + 1 21 ( 5.1) + 2 92 (22.3) + 3 155 (37.6) + 4 144 (35.0) +. Stratified by trt:sex + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 + status (%) 0.033 + 0 4 (19.0) 7 (46.7) 79 (57.7) 78 (56.1) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) + 2 14 (66.7) 8 (53.3) 51 (37.2) 52 (37.4) + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 + sex = f (%) 0 (0.0) 0 (0.0) 137 (100.0) 139 (100.0) <0.001 + ascites = 1 (%) 1 (4.8) 2 (13.3) 13 (9.5) 8 (5.8) 0.516 + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 (44.5) 78 (56.1) 0.208 + spiders = 1 (%) 3 (14.3) 1 (6.7) 42 (30.7) 44 (31.7) 0.089 + edema (%) 0.906 + 0 17 (81.0) 12 (80.0) 115 (83.9) 119 (85.6) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) 12 ( 8.6) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) 8 ( 5.8) + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 + stage (%) 0.646 + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) 3 ( 2.2) + 2 4 (19.0) 2 (13.3) 31 (22.6) 30 (21.6) + 3 7 (33.3) 5 (33.3) 49 (35.8) 59 (42.4) + 4 8 (38.1) 7 (46.7) 47 (34.3) 47 (33.8) +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 + status (%) 0.89351 + 0 83 (52.532) 85 (55.195) + 1 10 ( 6.329) 9 ( 5.844) + 2 65 (41.139) 60 (38.961) + age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 + sex = f (%) 137 (86.709) 139 (90.260) 0.42123 + ascites = 1 (%) 14 (8.861) 10 (6.494) 0.56729 + hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 + spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 + edema (%) 0.87682 + 0 132 (83.544) 131 (85.065) + 0.5 16 (10.127) 13 ( 8.442) + 1 10 ( 6.329) 10 ( 6.494) + bili (mean (sd)) 2.8734 (3.6289) 3.6487 (5.2819) 0.13094 + chol (mean (sd)) 365.0143 (209.5439) 373.8819 (252.4846) 0.74799 + albumin (mean (sd)) 3.5163 (0.4433) 3.5238 (0.3958) 0.87388 + copper (mean (sd)) 97.6433 (90.5901) 97.6536 (80.4865) 0.99916 + alk.phos (mean (sd)) 2021.2975 (2183.4358) 1943.0104 (2101.6873) 0.74726 + ast (mean (sd)) 120.2087 (54.5214) 124.9650 (58.9313) 0.45970 + trig (mean (sd)) 124.1367 (71.5391) 125.2517 (58.5211) 0.88604 + platelet (mean (sd)) 258.7500 (100.3247) 265.2039 (90.7294) 0.55451 + protime (mean (sd)) 10.6532 (0.8514) 10.8000 (1.1382) 0.19714 + stage (%) 0.20130 + 1 12 ( 7.595) 4 ( 2.597) + 2 35 (22.152) 32 (20.779) + 3 56 (35.443) 64 (41.558) + 4 55 (34.810) 54 (35.065) +. Stratified by trt + 1 2 + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) + status (%) + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) + sex = f (%) 137 (86.7) 139 (90.3) + ascites = 1 (%) 14 (8.9) 10 (6.5) + hepato = 1 (%) 73 (46.2) 87 (56.5) + spiders = 1 (%) 45 (28.5) 45 (29.2) + edema (%) + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) + chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) + copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) + alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) + trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) + stage (%) + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.884 exact + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.205 exact + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.884 exact + 0 83 (52.5) 85 (55.2) + 1 10 (6.3) 9 (5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 (8.4) + 1 10 (6.3) 10 (6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.205 exact + 1 12 (7.6) 4 (2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + level 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0 83 (52.5) 85 (55.2) 0.884 exact + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex (%) m 21 (13.3) 15 ( 9.7) 0.421 + f 137 (86.7) 139 (90.3) + ascites (%) 0 144 (91.1) 144 (93.5) 0.567 + 1 14 ( 8.9) 10 ( 6.5) + hepato (%) 0 85 (53.8) 67 (43.5) 0.088 + 1 73 (46.2) 87 (56.5) + spiders (%) 0 113 (71.5) 109 (70.8) 0.985 + 1 45 (28.5) 45 (29.2) + edema (%) 0 132 (83.5) 131 (85.1) 0.877 + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 1 12 ( 7.6) 4 ( 2.6) 0.205 exact + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. "Stratified by trt" + "" "1" "2" "p" "test" + "n" "158" "154" "" "" + "time (mean (sd))" "2015.62 (1094.12)" "1996.86 (1155.93)" "0.883" "" + "status (%)" "" "" "0.884" "exact" + " 0" "83 (52.5)" "85 (55.2)" "" "" + " 1" "10 (6.3)" "9 (5.8)" "" "" + " 2" "65 (41.1)" "60 (39.0)" "" "" + "age (mean (sd))" "51.42 (11.01)" "48.58 (9.96)" "0.018" "" + "sex = f (%)" "137 (86.7)" "139 (90.3)" "0.421" "" + "ascites = 1 (%)" "14 (8.9)" "10 (6.5)" "0.567" "" + "hepato = 1 (%)" "73 (46.2)" "87 (56.5)" "0.088" "" + "spiders = 1 (%)" "45 (28.5)" "45 (29.2)" "0.985" "" + "edema (%)" "" "" "0.877" "" + " 0" "132 (83.5)" "131 (85.1)" "" "" + " 0.5" "16 (10.1)" "13 (8.4)" "" "" + " 1" "10 (6.3)" "10 (6.5)" "" "" + "bili (median [IQR])" "1.40 [0.80, 3.20]" "1.30 [0.72, 3.60]" "0.842" "nonnorm" + "chol (median [IQR])" "315.50 [247.75, 417.00]" "303.50 [254.25, 377.00]" "0.544" "nonnorm" + "albumin (mean (sd))" "3.52 (0.44)" "3.52 (0.40)" "0.874" "" + "copper (median [IQR])" "73.00 [40.00, 121.00]" "73.00 [43.00, 139.00]" "0.717" "nonnorm" + "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" + "ast (mean (sd))" "120.21 (54.52)" "124.97 (58.93)" "0.460" "" + "trig (median [IQR])" "106.00 [84.50, 146.00]" "113.00 [84.50, 155.00]" "0.370" "nonnorm" + "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" + "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" + "stage (%)" "" "" "0.205" "exact" + " 1" "12 (7.6)" "4 (2.6)" "" "" + " 2" "35 (22.2)" "32 (20.8)" "" "" + " 3" "56 (35.4)" "64 (41.6)" "" "" + " 4" "55 (34.8)" "54 (35.1)" "" "" +. Stratified by trt + 1 2 p test + n 158 154 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. + Overall + n 418 + status (%) + 0 232 (55.5) + 1 25 ( 6.0) + 2 161 (38.5) + sex = f (%) 374 (89.5) + ascites = 1 (%) 24 ( 7.7) + hepato = 1 (%) 160 (51.3) + spiders = 1 (%) 90 (28.8) + edema (%) + 0 354 (84.7) + 0.5 44 (10.5) + 1 20 ( 4.8) + stage (%) + 1 21 ( 5.1) + 2 92 (22.3) + 3 155 (37.6) + 4 144 (35.0) +. Stratified by trt:sex + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + status (%) 0.033 + 0 4 (19.0) 7 (46.7) 79 ( 57.7) 78 ( 56.1) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) + 2 14 (66.7) 8 (53.3) 51 ( 37.2) 52 ( 37.4) + sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) 139 (100.0) <0.001 + ascites = 1 (%) 1 ( 4.8) 2 (13.3) 13 ( 9.5) 8 ( 5.8) 0.516 + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 ( 44.5) 78 ( 56.1) 0.208 + spiders = 1 (%) 3 (14.3) 1 ( 6.7) 42 ( 30.7) 44 ( 31.7) 0.089 + edema (%) 0.906 + 0 17 (81.0) 12 (80.0) 115 ( 83.9) 119 ( 85.6) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) 12 ( 8.6) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) 8 ( 5.8) + stage (%) 0.646 + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) 3 ( 2.2) + 2 4 (19.0) 2 (13.3) 31 ( 22.6) 30 ( 21.6) + 3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4) + 4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8) +. Stratified by trt:sex + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + status (%) 0.03270 + 0 4 (19.048) 7 (46.667) 79 ( 57.664) 78 ( 56.115) + 1 3 (14.286) 0 ( 0.000) 7 ( 5.109) 9 ( 6.475) + 2 14 (66.667) 8 (53.333) 51 ( 37.226) 52 ( 37.410) + sex = f (%) 0 ( 0.000) 0 ( 0.000) 137 (100.000) 139 (100.000) <0.00001 + ascites = 1 (%) 1 ( 4.762) 2 (13.333) 13 ( 9.489) 8 ( 5.755) 0.51569 + hepato = 1 (%) 12 (57.143) 9 (60.000) 61 ( 44.526) 78 ( 56.115) 0.20806 + spiders = 1 (%) 3 (14.286) 1 ( 6.667) 42 ( 30.657) 44 ( 31.655) 0.08899 + edema (%) 0.90584 + 0 17 (80.952) 12 (80.000) 115 ( 83.942) 119 ( 85.612) + 0.5 3 (14.286) 1 ( 6.667) 13 ( 9.489) 12 ( 8.633) + 1 1 ( 4.762) 2 (13.333) 9 ( 6.569) 8 ( 5.755) + stage (%) 0.64630 + 1 2 ( 9.524) 1 ( 6.667) 10 ( 7.299) 3 ( 2.158) + 2 4 (19.048) 2 (13.333) 31 ( 22.628) 30 ( 21.583) + 3 7 (33.333) 5 (33.333) 49 ( 35.766) 59 ( 42.446) + 4 8 (38.095) 7 (46.667) 47 ( 34.307) 47 ( 33.813) +. Stratified by trt:sex + 1:m 2:m 1:f 2:f + n 21 15 137 139 + status (%) + 0 4 (19.0) 7 (46.7) 79 ( 57.7) 78 ( 56.1) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) + 2 14 (66.7) 8 (53.3) 51 ( 37.2) 52 ( 37.4) + sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) 139 (100.0) + ascites = 1 (%) 1 ( 4.8) 2 (13.3) 13 ( 9.5) 8 ( 5.8) + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 ( 44.5) 78 ( 56.1) + spiders = 1 (%) 3 (14.3) 1 ( 6.7) 42 ( 30.7) 44 ( 31.7) + edema (%) + 0 17 (81.0) 12 (80.0) 115 ( 83.9) 119 ( 85.6) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) 12 ( 8.6) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) 8 ( 5.8) + stage (%) + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) 3 ( 2.2) + 2 4 (19.0) 2 (13.3) 31 ( 22.6) 30 ( 21.6) + 3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4) + 4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8) +. Stratified by trt + 1 2 p test + n 158 154 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 (6.3) 9 (5.8) + 2 65 (41.1) 60 (39.0) + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 (8.4) + 1 10 (6.3) 10 (6.5) + stage (%) 0.201 + 1 12 (7.6) 4 (2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + level 1 2 p test + n 158 154 + status (%) 0 83 (52.5) 85 (55.2) 0.894 + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + sex (%) m 21 (13.3) 15 ( 9.7) 0.421 + f 137 (86.7) 139 (90.3) + ascites (%) 0 144 (91.1) 144 (93.5) 0.567 + 1 14 ( 8.9) 10 ( 6.5) + hepato (%) 0 85 (53.8) 67 (43.5) 0.088 + 1 73 (46.2) 87 (56.5) + spiders (%) 0 113 (71.5) 109 (70.8) 0.985 + 1 45 (28.5) 45 (29.2) + edema (%) 0 132 (83.5) 131 (85.1) 0.877 + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + stage (%) 1 12 ( 7.6) 4 ( 2.6) 0.201 + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + 1 2 p test + n 158 154 + status 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + sex = f 137 (86.7) 139 (90.3) 0.421 + ascites = 1 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 73 (46.2) 87 (56.5) 0.088 + spiders = 1 45 (28.5) 45 (29.2) 0.985 + edema 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + stage 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. Stratified by trt + 1 2 p test + n 158 154 + status 0.894 + 0 83 85 + 1 10 9 + 2 65 60 + sex = f 137 139 0.421 + ascites = 1 14 10 0.567 + hepato = 1 73 87 0.088 + spiders = 1 45 45 0.985 + edema 0.877 + 0 132 131 + 0.5 16 13 + 1 10 10 + stage 0.201 + 1 12 4 + 2 35 32 + 3 56 64 + 4 55 54 +. Stratified by trt + 1 2 p test + n 158 154 + status (%) 0.894 + 0 52.5 55.2 + 1 6.3 5.8 + 2 41.1 39.0 + sex = f (%) 86.7 90.3 0.421 + ascites = 1 (%) 8.9 6.5 0.567 + hepato = 1 (%) 46.2 56.5 0.088 + spiders = 1 (%) 28.5 29.2 0.985 + edema (%) 0.877 + 0 83.5 85.1 + 0.5 10.1 8.4 + 1 6.3 6.5 + stage (%) 0.201 + 1 7.6 2.6 + 2 22.2 20.8 + 3 35.4 41.6 + 4 34.8 35.1 +. Stratified by trt + 1 2 p test + n 158 154 + status % (freq) 0.894 + 0 52.5 ( 83) 55.2 ( 85) + 1 6.3 ( 10) 5.8 ( 9) + 2 41.1 ( 65) 39.0 ( 60) + sex = f % (freq) 86.7 (137) 90.3 (139) 0.421 + ascites = 1 % (freq) 8.9 ( 14) 6.5 ( 10) 0.567 + hepato = 1 % (freq) 46.2 ( 73) 56.5 ( 87) 0.088 + spiders = 1 % (freq) 28.5 ( 45) 29.2 ( 45) 0.985 + edema % (freq) 0.877 + 0 83.5 (132) 85.1 (131) + 0.5 10.1 ( 16) 8.4 ( 13) + 1 6.3 ( 10) 6.5 ( 10) + stage % (freq) 0.201 + 1 7.6 ( 12) 2.6 ( 4) + 2 22.2 ( 35) 20.8 ( 32) + 3 35.4 ( 56) 41.6 ( 64) + 4 34.8 ( 55) 35.1 ( 54) +. Stratified by trt + 1 2 p test + n 158 154 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + sex = m/f (%) 21/137 (13.3/86.7) 15/139 (9.7/90.3) 0.421 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) +. "Stratified by trt" + "" "level" "1" "2" "p" "test" + "n" "" "158" "154" "" "" + "status (%)" "0" "83 (52.5)" "85 (55.2)" "0.894" "" + "" "1" "10 (6.3)" "9 (5.8)" "" "" + "" "2" "65 (41.1)" "60 (39.0)" "" "" + "sex (%)" "m" "21 (13.3)" "15 (9.7)" "0.421" "" + "" "f" "137 (86.7)" "139 (90.3)" "" "" + "ascites (%)" "0" "144 (91.1)" "144 (93.5)" "0.567" "" + "" "1" "14 (8.9)" "10 (6.5)" "" "" + "hepato (%)" "0" "85 (53.8)" "67 (43.5)" "0.088" "" + "" "1" "73 (46.2)" "87 (56.5)" "" "" + "spiders (%)" "0" "113 (71.5)" "109 (70.8)" "0.985" "" + "" "1" "45 (28.5)" "45 (29.2)" "" "" + "edema (%)" "0" "132 (83.5)" "131 (85.1)" "0.877" "" + "" "0.5" "16 (10.1)" "13 (8.4)" "" "" + "" "1" "10 (6.3)" "10 (6.5)" "" "" + "stage (%)" "1" "12 (7.6)" "4 (2.6)" "0.201" "" + "" "2" "35 (22.2)" "32 (20.8)" "" "" + "" "3" "56 (35.4)" "64 (41.6)" "" "" + "" "4" "55 (34.8)" "54 (35.1)" "" "" +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 + chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 + alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 +. + Overall + n 418 + time (mean (sd)) 1917.78 (1104.67) + age (mean (sd)) 50.74 (10.45) + bili (mean (sd)) 3.22 (4.41) + chol (mean (sd)) 369.51 (231.94) + albumin (mean (sd)) 3.50 (0.42) + copper (mean (sd)) 97.65 (85.61) + alk.phos (mean (sd)) 1982.66 (2140.39) + ast (mean (sd)) 122.56 (56.70) + trig (mean (sd)) 124.70 (65.15) + platelet (mean (sd)) 257.02 (98.33) + protime (mean (sd)) 10.73 (1.02) +. Stratified by trt:sex + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.620 (1094.123) 1996.864 (1155.929) 0.88305 + age (mean (sd)) 51.419 (11.007) 48.583 (9.958) 0.01767 + bili (mean (sd)) 2.873 (3.629) 3.649 (5.282) 0.13094 + chol (mean (sd)) 365.014 (209.544) 373.882 (252.485) 0.74799 + albumin (mean (sd)) 3.516 (0.443) 3.524 (0.396) 0.87388 + copper (mean (sd)) 97.643 (90.590) 97.654 (80.486) 0.99916 + alk.phos (mean (sd)) 2021.297 (2183.436) 1943.010 (2101.687) 0.74726 + ast (mean (sd)) 120.209 (54.521) 124.965 (58.931) 0.45970 + trig (mean (sd)) 124.137 (71.539) 125.252 (58.521) 0.88604 + platelet (mean (sd)) 258.750 (100.325) 265.204 (90.729) 0.55451 + protime (mean (sd)) 10.653 (0.851) 10.800 (1.138) 0.19714 +. Stratified by trt + 1 2 + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) + bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) + chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) + copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) + alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) + trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 +. Stratified by trt + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 + chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 + alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 +. Stratified by trt + 1 2 p test + n 158 154 + time 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age 51.42 (11.01) 48.58 (9.96) 0.018 + bili 2.87 (3.63) 3.65 (5.28) 0.131 + chol 365.01 (209.54) 373.88 (252.48) 0.748 + albumin 3.52 (0.44) 3.52 (0.40) 0.874 + copper 97.64 (90.59) 97.65 (80.49) 0.999 + alk.phos 2021.30 (2183.44) 1943.01 (2101.69) 0.747 + ast 120.21 (54.52) 124.97 (58.93) 0.460 + trig 124.14 (71.54) 125.25 (58.52) 0.886 + platelet 258.75 (100.32) 265.20 (90.73) 0.555 + protime 10.65 (0.85) 10.80 (1.14) 0.197 +. "Stratified by trt" + "" "1" "2" "p" "test" + "n" "158" "154" "" "" + "time (mean (sd))" "2015.62 (1094.12)" "1996.86 (1155.93)" "0.883" "" + "age (mean (sd))" "51.42 (11.01)" "48.58 (9.96)" "0.018" "" + "bili (mean (sd))" "2.87 (3.63)" "3.65 (5.28)" "0.131" "" + "chol (mean (sd))" "365.01 (209.54)" "373.88 (252.48)" "0.748" "" + "albumin (mean (sd))" "3.52 (0.44)" "3.52 (0.40)" "0.874" "" + "copper (mean (sd))" "97.64 (90.59)" "97.65 (80.49)" "0.999" "" + "alk.phos (mean (sd))" "2021.30 (2183.44)" "1943.01 (2101.69)" "0.747" "" + "ast (mean (sd))" "120.21 (54.52)" "124.97 (58.93)" "0.460" "" + "trig (mean (sd))" "124.14 (71.54)" "125.25 (58.52)" "0.886" "" + "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" + "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" +. +Unit tests for the modules : ........ +Unit tests for svy* user functions : .... Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. + Overall + n 450.01 + E (mean (sd)) 2.00 (0.82) + C (mean (sd)) 2.13 (0.88) + Y = 1 (%) 177.0 (39.4) + C1 = 1 (%) 150.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.01 100.00 100.00 50.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 (74.0) 37.0 (74.0) 37.0 (74.0) <0.001 + C1 = 1 (%) 0.0 (0.0) 0.0 (0.0) 0.0 (0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 +. Stratified by E + 1 2 3 p test + n 150.0120 150.0030 150.0000 + E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) <0.00001 + C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) 1.00000 + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 0.99982 + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.00000 + C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) 1.00000 +. Stratified by E + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) NA exact + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 1.000 + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + level 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + Y (%) 0 90.7 (60.6) 91.0 (60.7) 91.0 (60.7) NA exact + 1 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 (%) 0 100.0 (66.7) 100.0 (66.7) 100.0 (66.7) 1.000 + 1 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. "Stratified by E" + "" "1" "2" "3" "p" "test" + "n" "150.01" "150.00" "150.00" "" "" + "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" "3.00 (0.00)" "<0.001" "" + "C (median [IQR])" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "1.000" "nonnorm" + "Y = 1 (%)" "59.001 (39.406)" "59.001 (39.333)" "59.000 (39.333)" "NA" "exact" + "C1 = 1 (%)" "50.000 (33.331)" "50.000 (33.333)" "50.000 (33.333)" "1.000" "" + "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" "0.47 (0.50)" "1.000" "" +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 +. Stratified by + Overall + n 450.0 + Y = 1 (%) 177.0 (39.4) + C1 = 1 (%) 150.0 (33.3) +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 + n 100.012 100.003 100.000 50.000 50.000 + Y = 1 (%) 22.001 (22.062) 22.001 (22.000) 22.000 (22.000) 37.000 ( 74.000) 37.000 ( 74.000) + C1 = 1 (%) 0.000 ( 0.000) 0.000 ( 0.000) 0.000 ( 0.000) 50.000 (100.000) 50.000 (100.000) + Stratified by E:C1 + 3:1 p test + n 50.000 + Y = 1 (%) 37.000 ( 74.000) <0.00001 + C1 = 1 (%) 50.000 (100.000) <0.00001 +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 3:1 + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) +. Stratified by E + 1 2 3 p test + n 150.012 150.003 150.000 + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 1.000 + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.000 +. Stratified by E + level 1 2 3 p test + n 150.0 150.0 150.0 + Y (%) 0 90.7 (60.6) 91.0 (60.7) 91.0 (60.7) 1.000 + 1 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 (%) 0 100.0 (66.7) 100.0 (66.7) 100.0 (66.7) 1.000 + 1 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 1 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 1 59.0 59.0 59.0 1.000 + C1 = 1 50.0 50.0 50.0 1.000 +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 1 (%) 39.4 39.3 39.3 1.000 + C1 = 1 (%) 33.3 33.3 33.3 1.000 +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 1 % (freq) 39.4 (59.0) 39.3 (59.0) 39.3 (59.0) 1.000 + C1 = 1 % (freq) 33.3 (50.0) 33.3 (50.0) 33.3 (50.0) 1.000 +. Stratified by E + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 0/1 (%) 90.7/59.0 (60.6/39.4) 91.0/59.0 (60.7/39.3) 91.0/59.0 (60.7/39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 +. "Stratified by E" + "" "level" "1" "2" "3" "p" "test" + "n" "" "150.0" "150.0" "150.0" "" "" + "Y (%)" "0" "90.7 (60.6)" "91.0 (60.7)" "91.0 (60.7)" "1.000" "" + "" "1" "59.0 (39.4)" "59.0 (39.3)" "59.0 (39.3)" "" "" + "C1 (%)" "0" "100.0 (66.7)" "100.0 (66.7)" "100.0 (66.7)" "1.000" "" + "" "1" "50.0 (33.3)" "50.0 (33.3)" "50.0 (33.3)" "" "" +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by + Overall + n 450.01 + E (mean (sd)) 2.00 (0.82) + C (mean (sd)) 2.13 (0.88) + C2 (mean (sd)) 0.47 (0.50) +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.01 100.00 100.00 50.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 +. Stratified by E + 1 2 3 p test + n 150.012 150.003 150.000 + E (mean (sd)) 1.000 (0.000) 2.000 (0.000) 3.000 (0.000) <0.00001 + C (mean (sd)) 2.133 (0.885) 2.133 (0.886) 2.133 (0.886) 1.00000 + C2 (mean (sd)) 0.467 (0.499) 0.467 (0.500) 0.467 (0.500) 1.00000 +. Stratified by E + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. Stratified by E + 1 2 3 p test + n 150.01 150.00 150.00 + E 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + C2 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +. "Stratified by E" + "" "1" "2" "3" "p" "test" + "n" "150.01" "150.00" "150.00" "" "" + "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" "3.00 (0.00)" "<0.001" "" + "C (mean (sd))" "2.13 (0.89)" "2.13 (0.89)" "2.13 (0.89)" "1.000" "" + "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" "0.47 (0.50)" "1.000" "" +..... +Unit tests for the survey-related modules : ................................................ + +DONE diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 5bb769e..16871b1 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -141,35 +141,35 @@ exactVars <- c("status","stage") test_that("printing of a TableOne object does not regress", { ## Expectations - expect_equal_to_reference(print(pbcByTrt, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, printToggle = TRUE), "ref-TableOne_defaultPrint") - expect_equal_to_reference(print(pbcOverall, printToggle = FALSE), + expect_equal_to_reference(print(pbcOverall, printToggle = TRUE), "ref-TableOne_overallPrint") - expect_equal_to_reference(print(pbcByTrtSex, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrtSex, printToggle = TRUE), "ref-TableOne_2StrataVars") ## 2015-07-25 pDigits is not functional now - expect_equal_to_reference(print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE), "ref-TableOne_digits") - expect_equal_to_reference(print(pbcByTrt, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, test = FALSE, printToggle = TRUE), "ref-TableOne_noTests") - expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE), "ref-TableOne_nonnormal_exact") - expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE), "ref-TableOne_nonnormal_minMax") - expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, printToggle = TRUE), "ref-TableOne_noSpaces") - expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE), "ref-TableOne_showAllLevels") - expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = TRUE), "ref-TableOne_noSpaces_showAllLevels_quote") }) @@ -177,43 +177,43 @@ test_that("printing of a TableOne object does not regress", { test_that("printing of a TableOne$CatTable object do not regress", { ## Expectations - expect_equal_to_reference(print(pbcByTrt$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, printToggle = TRUE), "ref-CatTable_defaultPrint") - expect_equal_to_reference(print(pbcOverall$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcOverall$CatTable, printToggle = TRUE), "ref-CatTable_overallPrint") - expect_equal_to_reference(print(pbcByTrtSex$CatTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrtSex$CatTable, printToggle = TRUE), "ref-CatTable_2StrataVars") - expect_equal_to_reference(print(pbcByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-CatTable_digits") - expect_equal_to_reference(print(pbcByTrtSex$CatTable, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrtSex$CatTable, test = FALSE, printToggle = TRUE), "ref-CatTable_noTests") - expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, printToggle = TRUE), "ref-CatTable_noSpaces") - expect_equal_to_reference(print(pbcByTrt$CatTable, showAllLevels = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, showAllLevels = TRUE, printToggle = TRUE), "ref-CatTable_showAllLevels") - expect_equal_to_reference(print(pbcByTrt$CatTable, explain = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, explain = FALSE, printToggle = TRUE), "ref-CatTable_explain") - expect_equal_to_reference(print(pbcByTrt$CatTable, format = "f", printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "f", printToggle = TRUE), "ref-CatTable_format_f") - expect_equal_to_reference(print(pbcByTrt$CatTable, format = "p", printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "p", printToggle = TRUE), "ref-CatTable_format_p") - expect_equal_to_reference(print(pbcByTrt$CatTable, format = "pf", printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, format = "pf", printToggle = TRUE), "ref-CatTable_format_pf") - expect_equal_to_reference(print(pbcByTrt$CatTable, cramVars = "sex", printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, cramVars = "sex", printToggle = TRUE), "ref-CatTable_cramVars") - expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-CatTable_noSpaces_showAllLevels_quote") }) @@ -221,33 +221,33 @@ test_that("printing of a TableOne$CatTable object do not regress", { test_that("printing of a TableOne$ContTable object do not regress", { ## Expectations - expect_equal_to_reference(print(pbcByTrt$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, printToggle = TRUE), "ref-ContTable_defaultPrint") - expect_equal_to_reference(print(pbcOverall$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcOverall$ContTable, printToggle = TRUE), "ref-ContTable_overallPrint") - expect_equal_to_reference(print(pbcByTrtSex$ContTable, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrtSex$ContTable, printToggle = TRUE), "ref-ContTable_2StrataVars") - expect_equal_to_reference(print(pbcByTrt$ContTable, digits = 3, pDigits = 5, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, digits = 3, pDigits = 5, printToggle = TRUE), "ref-ContTable_digits") - expect_equal_to_reference(print(pbcByTrt$ContTable, test = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, test = FALSE, printToggle = TRUE), "ref-ContTable_noTests") - expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE), "ref-ContTable_nonnormal_exact") - expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE), "ref-ContTable_nonnormal_minMax") - expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, printToggle = TRUE), "ref-ContTable_noSpaces") - expect_equal_to_reference(print(pbcByTrt$ContTable, explain = FALSE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, explain = FALSE, printToggle = TRUE), "ref-ContTable_explain") - expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = FALSE), + expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-ContTable_noSpaces_showAllLevels_quote") }) From 41ea8f8228da7b3d8630903b040b448c0b71f187 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 22:22:32 -0400 Subject: [PATCH 070/219] Add includeNA to svyCreateTableOne and add regression tests --- R/svyCreateCatTable.R | 16 ++++++++-------- R/svyCreateTableOne.R | 2 ++ tests/testthat/ref-svyCatTable_IncludeNA | Bin 0 -> 248 bytes tests/testthat/ref-svyTableOne_IncludeNA | Bin 0 -> 246 bytes tests/testthat/test-svyCreateTableOne.R | 7 +++++++ 5 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 tests/testthat/ref-svyCatTable_IncludeNA create mode 100644 tests/testthat/ref-svyTableOne_IncludeNA diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index e71fc1b..e93eb46 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -130,14 +130,14 @@ function(vars, # character vector of variable names ## Add NA as a new level unless already present data$variables[logiAnyNA] <- - lapply(data$variables[logiAnyNA], - function(var) { - if (all(!is.na(levels(var)))) { - var <- factor(var, c(levels(var), NA), - exclude = NULL) - } - var - }) + lapply(data$variables[logiAnyNA], + function(var) { + if (all(!is.na(levels(var)))) { + var <- factor(var, c(levels(var), NA), + exclude = NULL) + } + var + }) } ### Actual descriptive statistics are calculated here. diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 87025e1..2b7d184 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -87,6 +87,7 @@ function(vars, # character vector of variable strata, # character vector of variable names data, # data frame factorVars, # variables to be transformed to factors + includeNA = FALSE, # include NA as a category (categoricals only) test = TRUE, # whether to put p-values ## Test configuration for categorical data testApprox = svyTestChisq, # function for approximation test (only choice) @@ -159,6 +160,7 @@ function(vars, # character vector of variable argsNonNormal = argsNonNormal ) argsCreateCatTable <- list(data = data, + includeNA = includeNA, test = test, testApprox = testApprox, argsApprox = argsApprox diff --git a/tests/testthat/ref-svyCatTable_IncludeNA b/tests/testthat/ref-svyCatTable_IncludeNA new file mode 100644 index 0000000000000000000000000000000000000000..b53e21f9913c7010d0fec818ff9cfc312e5ce73e GIT binary patch literal 248 zcmVIZ!ppgUA@ z=wXr6K_C^n{z&@&Nkk=mbjj)x$uo)ca}pduNy`-NC^<5dYhoQ-dPN$9oWf&#A*5@# zvS#a4h~J>w^Gx6%X({=-fXJUuP0*TY9HY+Loc9HwbSOU($$SyB0?_A)z% yS+Y;!2)BQqUZg<0RRAr)^Yp* literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-svyTableOne_IncludeNA b/tests/testthat/ref-svyTableOne_IncludeNA new file mode 100644 index 0000000000000000000000000000000000000000..e29d8ee7893c8ea16504ae88f5d55db9afdaa840 GIT binary patch literal 246 zcmV&Gk>^&!haK`=@7hFK)Mvm&6%qS=RY`J6?9a0XGu67~uf`0G=LkS^xk5 literal 0 HcmV?d00001 diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 6fbe386..760e0be 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -95,6 +95,7 @@ test_that("data assessment detects anomalies", { ## Create a table to test mwOverall <- svyCreateTableOne(vars = vars, data = datSvy, factorVars = factorVars) +mwInclNa <- svyCreateTableOne(vars = vars, data = datSvy, factorVars = factorVars, includeNA = TRUE) mwByTrt <- svyCreateTableOne(vars = vars, strata = c("E"), data = datSvy, factorVars = factorVars) mwByTrtSex <- svyCreateTableOne(vars = vars, strata = c("E","C1"), data = datSvy, factorVars = factorVars) @@ -112,6 +113,9 @@ test_that("printing of a svyTableOne object does not regress", { expect_equal_to_reference(print(mwOverall, printToggle = TRUE), "ref-svyTableOne_overallPrint") + expect_equal_to_reference(print(mwInclNa, printToggle = TRUE), + "ref-svyTableOne_IncludeNA") + expect_equal_to_reference(print(mwByTrtSex, printToggle = TRUE), "ref-svyTableOne_2StrataVars") @@ -148,6 +152,9 @@ test_that("printing of a svyTableOne$CatTable object do not regress", { expect_equal_to_reference(print(mwOverall$CatTable, printToggle = TRUE), "ref-svyCatTable_overallPrint") + expect_equal_to_reference(print(mwInclNa$CatTable, printToggle = TRUE), + "ref-svyCatTable_IncludeNA") + expect_equal_to_reference(print(mwByTrtSex$CatTable, printToggle = TRUE), "ref-svyCatTable_2StrataVars") From 73b8dbdc0656f20d95349dca989c2eec81e4fe55 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 22:37:16 -0400 Subject: [PATCH 071/219] Add includeNA functionality to unweighted functions --- R/CreateCatTable.R | 27 +++++++++++++++++++++----- R/CreateTableOne.R | 2 ++ tests/testthat/ref-CatTable_IncludeNA | Bin 0 -> 393 bytes tests/testthat/ref-TableOne_IncludeNA | Bin 0 -> 568 bytes tests/testthat/test-CreateTableOne.R | 7 +++++++ 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/testthat/ref-CatTable_IncludeNA create mode 100644 tests/testthat/ref-TableOne_IncludeNA diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index fa8b516..859357c 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -84,9 +84,10 @@ CreateCatTable <- function(vars, # character vector of variable names strata, # character vector of variable names data, # data frame - test = TRUE, # whether to put p-values + includeNA = FALSE, # include NA as a category + test = TRUE, # whether to put p-values testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox + argsApprox = list(correct = TRUE), # arguments passed to testApprox testExact = fisher.test, # function for exact test argsExact = list(workspace = 2*10^5) # arguments passed to testExact ) { @@ -107,6 +108,9 @@ CreateCatTable <- ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + ## Create strata data frame (data frame with only strata variables) + strata <- ModuleReturnStrata(strata, data) + ## Convert to a factor if it is not a factor already. (categorical version only) ## Not done on factors, to avoid dropping zero levels. ## Probably this cannot handle Surv object?? @@ -118,9 +122,22 @@ CreateCatTable <- dat[logiNotFactor] <- lapply(dat[logiNotFactor], factor) - ## Create strata data frame (data frame with only strata variables) - strata <- ModuleReturnStrata(strata, data) - + ## If including NA as a level, include NA as a factor level before subsetting + if (includeNA) { + ## Logical vector for variables that have any NA + logiAnyNA <- (colSums(is.na(dat)) > 0) + + ## Add NA as a new level unless already present + dat[logiAnyNA] <- + lapply(dat[logiAnyNA], + function(var) { + if (all(!is.na(levels(var)))) { + var <- factor(var, c(levels(var), NA), + exclude = NULL) + } + var + }) + } ### Actual descriptive statistics are calculated here. diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 0b6ec15..e2f7b62 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -87,6 +87,7 @@ CreateTableOne <- strata, # character vector of variable names data, # data frame factorVars, # variables to be transformed to factors + includeNA = FALSE, # include NA as a category (categoricals only) test = TRUE, # whether to put p-values ## Test configuration for categorical data testApprox = chisq.test, # function for approximation test @@ -161,6 +162,7 @@ CreateTableOne <- argsNonNormal = argsNonNormal ) argsCreateCatTable <- list(data = data, + includeNA = includeNA, test = test, testApprox = testApprox, argsApprox = argsApprox, diff --git a/tests/testthat/ref-CatTable_IncludeNA b/tests/testthat/ref-CatTable_IncludeNA new file mode 100644 index 0000000000000000000000000000000000000000..22fa7ebee34f76e01d842e1fa2b8b884eefcba52 GIT binary patch literal 393 zcmV;40e1c$iwFP!000001C>%uPr^VDU0P5+)R=hnFc*_@X}Vvf985Ic^{Cf|uF{0B z&`SLE=xlAnw4ebF?91$%w{Pb4t}LyiwFP!000001C>)vkJB&^bw3v9Rk;E@Qk-lmZ7Zc7%{;%Ec{BcTO9+{g*>pmtGjFc&?=zW`1)ej-lh%CCQyxQ{ z(1>%Uz{Hz2FsJxy?K^J^DQKiM=uOW}g{BcT!1``(IE`e|M{5SL!b}X5-h^oB-ANjt zpQlf-Mw37~OpiCIhIo*k85#)<>M|kM*pD;;q%E8^h0Ci6h42DN;DZWNBout8+Y1P# z_Nu61Z&W>L_-qiEhblPzv@JOKcN^7dMg$ z-prm21xG$CVz`kSn~?EvJlv}()o=|c#TF=U++;pQ_oRC~yR5+DZS%hToARMP`3{Fh;hl+#mXd z{tVcbw%TU3dr5*Dw7-4r>e{=~*2inFEvquyxzp9@7H;PXd*RkAZ-XA;SlwrNHX_7o zyFcb5{+*EG zup|py5sI%9j`Z5i0Aul3VzcDwuf`)_x$c|KU_n|7ZY?6h@~^GV2G|NR5rnHJ%8 G1^@tO%?>I6 literal 0 HcmV?d00001 diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 16871b1..19afb3b 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -130,6 +130,7 @@ test_that("P-values should be NA for 1xM xtabs", { ## Create a table to test pbcOverall <- CreateTableOne(vars = vars, data = pbc) +pbcInclNa <- CreateTableOne(vars = vars, data = pbc, includeNA = TRUE) pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) pbcByTrtSex <- CreateTableOne(vars = vars, strata = c("trt","sex"), data = pbc) @@ -147,6 +148,9 @@ test_that("printing of a TableOne object does not regress", { expect_equal_to_reference(print(pbcOverall, printToggle = TRUE), "ref-TableOne_overallPrint") + expect_equal_to_reference(print(pbcInclNa, printToggle = TRUE), + "ref-TableOne_IncludeNA") + expect_equal_to_reference(print(pbcByTrtSex, printToggle = TRUE), "ref-TableOne_2StrataVars") @@ -183,6 +187,9 @@ test_that("printing of a TableOne$CatTable object do not regress", { expect_equal_to_reference(print(pbcOverall$CatTable, printToggle = TRUE), "ref-CatTable_overallPrint") + expect_equal_to_reference(print(pbcInclNa$CatTable, printToggle = TRUE), + "ref-CatTable_IncludeNA") + expect_equal_to_reference(print(pbcByTrtSex$CatTable, printToggle = TRUE), "ref-CatTable_2StrataVars") From 246e75291ab9b6242e23c71830e5bbca3dfe518f Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 22:43:46 -0400 Subject: [PATCH 072/219] Document includeNA for both regular and svy* functions --- R/CreateCatTable.R | 1 + R/CreateTableOne.R | 1 + R/svyCreateCatTable.R | 1 + R/svyCreateTableOne.R | 1 + 4 files changed, 4 insertions(+) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 859357c..782b701 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -8,6 +8,7 @@ ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. ##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index e2f7b62..7cbfae5 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -6,6 +6,7 @@ ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. ##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. +##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. ##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index e93eb46..32197c6 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -8,6 +8,7 @@ ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. ##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 2b7d184..34fdc5a 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -6,6 +6,7 @@ ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. ##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. +##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. ##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. From d102373849b0276c492dd8a8d2f64e33fffec452 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 22:57:45 -0400 Subject: [PATCH 073/219] Explain arguments for svy* constructors; drop irrelevant examples --- R/svyCreateCatTable.R | 78 +++++--------------------------------- R/svyCreateContTable.R | 82 ++++++---------------------------------- R/svyCreateTableOne.R | 85 ++++++++---------------------------------- 3 files changed, 38 insertions(+), 207 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 32197c6..c12c00f 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -3,82 +3,24 @@ ##' Create an object summarizing categorical variables optionally stratifying ##' by one or more startifying variables and performing statistical tests. The ##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +##' also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. -##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. -##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. -##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. -##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. -##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{svychisq}}. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. +##' @return An object of class \code{svyCatTable}. +##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for categorical variables -##' catVars <- c("status","ascites","hepato","spiders","edema","stage") -##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.CatTable method, -##' ## which will show the sample size, frequencies and percentages. -##' ## For 2-level variables, only the higher level is shown for simplicity -##' ## unless the variables are specified in the cramVars argument. -##' catTableOverall -##' -##' ## If you need to show both levels for some 2-level factors, use cramVars -##' print(catTableOverall, cramVars = "hepato") -##' -##' ## Use the showAllLevels argument to see all levels for all variables. -##' print(catTableOverall, showAllLevels = TRUE) -##' -##' ## You can choose form frequencies ("f") and/or percentages ("p") or both. -##' ## "fp" frequency (percentage) is the default. Row names change accordingly. -##' print(catTableOverall, format = "f") -##' print(catTableOverall, format = "p") -##' -##' ## To further examine the variables, use the summary.CatTable method, -##' ## which will show more details. -##' summary(catTableOverall) -##' -##' ## The table can be stratified by one or more variables -##' catTableBySexTrt <- CreateCatTable(vars = catVars, -##' strata = c("sex","trt"), data = pbc) -##' -##' ## print now includes p-values which are by default calculated by chisq.test. -##' ## It is formatted at the decimal place specified by the pDigits argument -##' ## (3 by default). It does <0.001 for you. -##' catTableBySexTrt -##' -##' ## The exact argument toggles the p-values to the exact test result from -##' ## fisher.test. It will show which ones are from exact tests. -##' print(catTableBySexTrt, exact = "ascites") -##' -##' ## summary now includes both types of p-values -##' summary(catTableBySexTrt) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(catTableBySexTrt, exact = "ascites", quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +##' ## Placeholder ##' ##' @export svyCreateCatTable <- diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 6ab6b26..c662d80 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -3,80 +3,25 @@ ##' Create an object summarizing continous variables optionally stratifying by ##' one or more startifying variables and performing statistical tests. The ##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +##' also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. -##' @param funcNames Not available for weighted dataset -##' @param funcAdditional Not available for weighted dataset +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method. -##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. -##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. -##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. -##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. -##' @return An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. -##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) +##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{\link{svyglm}} and \code{\link{regTermTest}}. This is equivalent of the \code{\link{svyttest}} when there are only two groups. +##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{\link{svyranktest}}. +##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. +##' @return An object of class \code{svyContTable}. +##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for continuous variables -##' contVars <- c("time","age","bili","chol","albumin","copper", -##' "alk.phos","ast","trig","platelet","protime") -##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.ContTable method, -##' ## which will show the sample size, means and standard deviations. -##' contTableOverall -##' -##' ## To further examine the variables, use the summary.ContTable method, -##' ## which will show more details. -##' summary(contTableOverall) -##' -##' ## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. -##' ## Specify them in the nonnormal argument, and the display changes to the median, -##' ## and the [25th, 75th] percentile. -##' nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") -##' print(contTableOverall, nonnormal = nonNormalVars) -##' -##' ## To show median [min,max] for nonnormal variables, use minMax = TRUE -##' print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) -##' -##' ## The table can be stratified by one or more variables -##' contTableBySexTrt <- CreateContTable(vars = contVars, -##' strata = c("sex","trt"), data = pbc) -##' -##' ## print now includes p-values which are by default calculated by oneway.test (t-test -##' ## equivalent in the two group case). It is formatted at the decimal place specified -##' ## by the pDigits argument (3 by default). It does <0.001 for you. -##' contTableBySexTrt -##' -##' ## The nonnormal argument toggles the p-values to the nonparametric result from -##' ## kruskal.test (wilcox.test equivalent for the two group case). -##' print(contTableBySexTrt, nonnormal = nonNormalVars) -##' -##' ## summary now includes both types of p-values -##' summary(contTableBySexTrt) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +##' ## Placeholder ##' ##' @export svyCreateContTable <- @@ -90,9 +35,6 @@ function(vars, # character vector of variable n argsNonNormal = NULL # arguments passed to testNonNormal ) { - ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) - ## require(e1071) # for skewness and kurtosis - ### Data check ## Check if the data given is a survey design object StopIfNotSurveyDesign(data) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 34fdc5a..de1c0fb 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -2,85 +2,32 @@ ##' ##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. ##' -##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used. +##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. ##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. -##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. -##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. -##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. -##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. -##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. -##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. -##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. -##' @return An object of class \code{TableOne}, which really is a list of three objects. +##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{\link{svyglm}} and \code{\link{regTermTest}}. This is equivalent of the \code{\link{svyttest}} when there are only two groups. +##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{\link{svyranktest}}. +##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{svychisq}}. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. +##' @return An object of class \code{svyTableOne}, which really is a list of three objects. ##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} -##' @return \item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} -##' @return \item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} +##' @return \item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} +##' @return \item{CatTable}{ an object of class \code{svyCatTable}, containing categorical variables only} ##' @return The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. ##' -##' @author Justin Bohn, Kazuki Yoshida +##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Make categorical variables factors -##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -##' -##' ## Create a variable list -##' dput(names(pbc)) -##' vars <- c("time","status","age","sex","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage") -##' -##' ## Create Table 1 stratified by trt -##' tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) -##' -##' ## Just typing the object name will invoke the print.TableOne method -##' tableOne -##' -##' ## Specifying nonnormal variables will show the variables appropriately, -##' ## and show nonparametric test p-values. Specify variables in the exact -##' ## argument to obtain the exact test p-values. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage")) -##' -##' ## Use the summary.TableOne method for detailed summary -##' summary(tableOne) -##' -##' ## See the categorical part only using $ operator -##' tableOne$CatTable -##' summary(tableOne$CatTable) -##' -##' ## See the continuous part only using $ operator -##' tableOne$ContTable -##' summary(tableOne$ContTable) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) +##' ## Placeholder ##' ##' @export svyCreateTableOne <- From b67ce4c7ff7314853d58e2f03fe22bfa68ef627a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 25 Jul 2015 23:14:49 -0400 Subject: [PATCH 074/219] Import survey correctly --- NAMESPACE | 1 + R/tableone-package.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 02f4633..9ce0f65 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,3 +19,4 @@ export(svyCreateContTable) export(svyCreateTableOne) import(e1071) import(gmodels) +import(survey) diff --git a/R/tableone-package.R b/R/tableone-package.R index 698448c..b9d988d 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -5,7 +5,7 @@ ##' @name tableone-package ##' @aliases tableone-package tableone ##' @docType package -##' @import e1071 gmodels +##' @import survey e1071 gmodels ##' @note Special Thanks: ##' ##' Ian Fellows for developing the Deducer package, which this package is based on. From e522e6f37f85237a6b968c6ab30e4ecbbb5c0269 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 13:13:46 -0400 Subject: [PATCH 075/219] Add unit test results for test-all.txt --- test-all.txt | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test-all.txt b/test-all.txt index ad61cfc..d99e14b 100644 --- a/test-all.txt +++ b/test-all.txt @@ -61,6 +61,47 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) +. + Overall + n 418 + time (mean (sd)) 1917.78 (1104.67) + status (%) + 0 232 (55.5) + 1 25 ( 6.0) + 2 161 (38.5) + age (mean (sd)) 50.74 (10.45) + sex = f (%) 374 (89.5) + ascites (%) + 0 288 (68.9) + 1 24 ( 5.7) + NA 106 (25.4) + hepato (%) + 0 152 (36.4) + 1 160 (38.3) + NA 106 (25.4) + spiders (%) + 0 222 (53.1) + 1 90 (21.5) + NA 106 (25.4) + edema (%) + 0 354 (84.7) + 0.5 44 (10.5) + 1 20 ( 4.8) + bili (mean (sd)) 3.22 (4.41) + chol (mean (sd)) 369.51 (231.94) + albumin (mean (sd)) 3.50 (0.42) + copper (mean (sd)) 97.65 (85.61) + alk.phos (mean (sd)) 1982.66 (2140.39) + ast (mean (sd)) 122.56 (56.70) + trig (mean (sd)) 124.70 (65.15) + platelet (mean (sd)) 257.02 (98.33) + protime (mean (sd)) 10.73 (1.02) + stage (%) + 1 21 ( 5.0) + 2 92 (22.0) + 3 155 (37.1) + 4 144 (34.4) + NA 6 ( 1.4) . Stratified by trt:sex 1:m 2:m 1:f 2:f p test n 21 15 137 139 @@ -350,6 +391,36 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) +. + Overall + n 418 + status (%) + 0 232 (55.5) + 1 25 ( 6.0) + 2 161 (38.5) + sex = f (%) 374 (89.5) + ascites (%) + 0 288 (68.9) + 1 24 ( 5.7) + NA 106 (25.4) + hepato (%) + 0 152 (36.4) + 1 160 (38.3) + NA 106 (25.4) + spiders (%) + 0 222 (53.1) + 1 90 (21.5) + NA 106 (25.4) + edema (%) + 0 354 (84.7) + 0.5 44 (10.5) + 1 20 ( 4.8) + stage (%) + 1 21 ( 5.0) + 2 92 (22.0) + 3 155 (37.1) + 4 144 (34.4) + NA 6 ( 1.4) . Stratified by trt:sex 1:m 2:m 1:f 2:f p test n 21 15 137 139 @@ -730,6 +801,17 @@ Unit tests for svy* user functions : .... Stratified by E Y = 1 (%) 177.0 (39.4) C1 = 1 (%) 150.0 (33.3) C2 (mean (sd)) 0.47 (0.50) +. + Overall + n 450.01 + E (mean (sd)) 2.00 (0.82) + C (mean (sd)) 2.13 (0.88) + Y (%) + 0 272.7 (60.6) + 1 177.0 (39.3) + NA 0.3 ( 0.1) + C1 = 1 (%) 150.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) . Stratified by E:C1 1:0 2:0 3:0 1:1 2:1 3:1 p test n 100.01 100.00 100.00 50.00 50.00 50.00 @@ -806,6 +888,14 @@ Unit tests for svy* user functions : .... Stratified by E n 450.0 Y = 1 (%) 177.0 (39.4) C1 = 1 (%) 150.0 (33.3) +. Stratified by + Overall + n 450.0 + Y (%) + 0 272.7 (60.6) + 1 177.0 (39.3) + NA 0.3 ( 0.1) + C1 = 1 (%) 150.0 (33.3) . Stratified by E:C1 1:0 2:0 3:0 1:1 2:1 3:1 p test n 100.0 100.0 100.0 50.0 50.0 50.0 From b7c8381d6a93e917e9c241f5cb83689bc46adaa8 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 16:42:51 -0400 Subject: [PATCH 076/219] Change manual entries for svy print and summary methods --- R/print.svyCatTable.R | 99 +++++++++------------------------------- R/print.svyContTable.R | 92 ++++++++----------------------------- R/summary.svyCatTable.R | 34 +++----------- R/summary.svyContTable.R | 34 +++----------- 4 files changed, 54 insertions(+), 205 deletions(-) diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index dc929eb..d5b4e2b 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -1,8 +1,8 @@ -##' Format and print the \code{CatTable} class objects +##' Format and print the \code{svyCatTable} class objects ##' -##' This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +##' This is the \code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. ##' -##' @param x The result of a call to the \code{\link{CreateCatTable}} function. +##' @param x The result of a call to the \code{\link{svyCreateCatTable}} function. ##' @param digits Number of digits to print in the table. ##' @param pDigits Number of digits to print for p-values. ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. @@ -14,94 +14,39 @@ ##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. ##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. -##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test). +##' @param exact This option is not available for tables from weighted data. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for categorical variables -##' catVars <- c("status","ascites","hepato","spiders","edema","stage") -##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.CatTable method, -##' ## which will show the sample size, frequencies and percentages. -##' ## For 2-level variables, only the higher level is shown for simplicity. -##' catTableOverall -##' -##' ## If you need to show both levels for some 2-level factors, use cramVars -##' print(catTableOverall, cramVars = "hepato") -##' -##' ## Use the showAllLevels argument to see all levels for all variables. -##' print(catTableOverall, showAllLevels = TRUE) -##' -##' ## You can choose form frequencies ("f") and/or percentages ("p") or both. -##' ## "fp" frequency (percentage) is the default. Row names change accordingly. -##' print(catTableOverall, format = "f") -##' print(catTableOverall, format = "p") -##' -##' ## To further examine the variables, use the summary.CatTable method, -##' ## which will show more details. -##' summary(catTableOverall) -##' -##' ## The table can be stratified by one or more variables -##' catTableBySexTrt <- CreateCatTable(vars = catVars, -##' strata = c("sex","trt"), data = pbc) -##' -##' ## print now includes p-values which are by default calculated by chisq.test. -##' ## It is formatted at the decimal place specified by the pDigits argument -##' ## (3 by default). It does <0.001 for you. -##' catTableBySexTrt -##' -##' ## The exact argument toggles the p-values to the exact test result from -##' ## fisher.test. It will show which ones are from exact tests. -##' print(catTableBySexTrt, exact = "ascites") -##' -##' ## summary now includes both types of p-values -##' summary(catTableBySexTrt) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(catTableBySexTrt, exact = "ascites", quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +##' ## ##' ##' @export print.svyCatTable <- function(x, # CatTable object - digits = 1, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes + digits = 1, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes - missing = FALSE, # Show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + missing = FALSE, # Show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent - showAllLevels = FALSE, - cramVars = NULL, # variables to be crammed into one row + format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent + showAllLevels = FALSE, + cramVars = NULL, # variables to be crammed into one row - test = TRUE, # Whether to add p-values - exact = NULL, # Which variables should be tested with exact tests + test = TRUE, # Whether to add p-values + exact = NULL, # Which variables should be tested with exact tests - CrossTable = FALSE, # Whether to show gmodels::CrossTable + CrossTable = FALSE, # Whether to show gmodels::CrossTable - ...) { + ...) { ## x and ... required to be consistent with generic print(x, ...) CatTable <- x @@ -355,7 +300,7 @@ print.svyCatTable <- function(x, # CatTable object colnames(out) <- ModuleCreateStrataNames(CatTable) } - + ## Set the variables names rownames(out) <- CatTableCollapsed[[posFirstNonNullElement]][,"var"] ## Get positions of rows with variable names diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 97bc985..751025d 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -1,8 +1,8 @@ -##' Format and print the \code{ContTable} class objects +##' Format and print the \code{svyContTable} class objects ##' -##' This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +##' This is the \code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. ##' -##' @param x The result of a call to the \code{\link{CreateContTable}} function. +##' @param x The result of a call to the \code{\link{svyCreateContTable}} function. ##' @param digits Number of digits to print in the table. ##' @param pDigits Number of digits to print for p-values. ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. @@ -18,86 +18,30 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for continuous variables -##' contVars <- c("time","age","bili","chol","albumin","copper", -##' "alk.phos","ast","trig","platelet","protime") -##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.ContTable method, -##' ## which will show the sample size, means and standard deviations. -##' contTableOverall -##' -##' ## To further examine the variables, use the summary.ContTable method, -##' ## which will show more details. -##' summary(contTableOverall) -##' -##' ## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. -##' ## Specify them in the nonnormal argument, and the display changes to the median, -##' ## and the [25th, 75th] percentile. -##' nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") -##' print(contTableOverall, nonnormal = nonNormalVars) -##' -##' ## To show median [min,max] for nonnormal variables, use minMax = TRUE -##' print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) -##' -##' ## The table can be stratified by one or more variables -##' contTableBySexTrt <- CreateContTable(vars = contVars, -##' strata = c("sex","trt"), data = pbc) -##' -##' ## print now includes p-values which are by default calculated by oneway.test (t-test -##' ## equivalent in the two group case). It is formatted at the decimal place specified -##' ## by the pDigits argument (3 by default). It does <0.001 for you. -##' contTableBySexTrt -##' -##' ## The nonnormal argument toggles the p-values to the nonparametric result from -##' ## kruskal.test (wilcox.test equivalent for the two group case). -##' print(contTableBySexTrt, nonnormal = nonNormalVars) -##' -##' ## The minMax argument toggles whether to show median [range] -##' print(contTableBySexTrt, nonnormal = nonNormalVars, minMax = TRUE) -##' -##' ## summary now includes both types of p-values -##' summary(contTableBySexTrt) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +##' ## ##' ##' @export print.svyContTable <- function(x, # ContTable object - digits = 2, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes + digits = 2, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes - missing = FALSE, # show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + missing = FALSE, # show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - nonnormal = NULL, # Which variables should be treated as nonnormal - minMax = FALSE, # median [range] instead of median [IQR] - insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable + nonnormal = NULL, # Which variables should be treated as nonnormal + minMax = FALSE, # median [range] instead of median [IQR] + insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable - test = TRUE, # Whether to add p-values + test = TRUE, # Whether to add p-values - ...) { + ...) { ## x and ... required to be consistent with generic print(x, ...) ContTable <- x diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index aa700c6..d9ab72d 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -1,39 +1,19 @@ -##' Shows all results in a \code{CatTable} class object +##' Shows all results in a \code{svyCatTable} class object ##' -##' This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +##' This method shows all the data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). ##' -##' @param object An object that has the \code{CatTable} class to be shown. +##' @param object An object that has the \code{svyCatTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. ##' @return It will print the results. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for categorical variables -##' catVars <- c("status","ascites","hepato","spiders","edema","stage") -##' catTableOverall <- CreateCatTable(vars = catVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.CatTable method, -##' ## which will show the sample size, frequencies and percentages. -##' ## For 2-level variables, only the higher level is shown for simplicity. -##' catTableOverall -##' -##' ## To further examine the variables, use the summary.CatTable method, -##' ## which will show more details. -##' summary(catTableOverall) +##' ## ##' ##' @export summary.svyCatTable <- function(object, digits = 1, ...) { diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 9067d64..e812424 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -1,39 +1,19 @@ -##' Shows all results in a \code{ContTable} class object +##' Shows all results in a \code{svyContTable} class object ##' -##' This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +##' This method shows all the data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). ##' -##' @param object An object that has the \code{ContTable} class to be shown. +##' @param object An object that has the \code{svyContTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. ##' @return It will print the results. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Create an overall table for continuous variables -##' contVars <- c("time","age","bili","chol","albumin","copper", -##' "alk.phos","ast","trig","platelet","protime") -##' contTableOverall <- CreateContTable(vars = contVars, data = pbc) -##' -##' ## Simply typing the object name will invoke the print.ContTable method, -##' ## which will show the sample size, means and standard deviations. -##' contTableOverall -##' -##' ## To further examine the variables, use the summary.ContTable method, -##' ## which will show more details. -##' summary(contTableOverall) +##' ## ##' ##' @export summary.svyContTable <- function(object, digits = 2, ...) { From b42a98bfc5a792042cbb9a7141fddcab9844f098 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 17:11:34 -0400 Subject: [PATCH 077/219] Fix links in constructors and package overall --- R/svyCreateCatTable.R | 6 +++--- R/svyCreateContTable.R | 10 +++++----- R/svyCreateTableOne.R | 10 +++++----- R/tableone-package.R | 9 ++++++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index c12c00f..1bf63f1 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -7,17 +7,17 @@ ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{svychisq}}. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{svychisq}. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. ##' @return An object of class \code{svyCatTable}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, ##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Placeholder diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index c662d80..0a0c242 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -7,18 +7,18 @@ ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method. -##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{\link{svyglm}} and \code{\link{regTermTest}}. This is equivalent of the \code{\link{svyttest}} when there are only two groups. +##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{svyglm} and \code{regTermTest}. This is equivalent of the \code{svyttest} when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. -##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{\link{svyranktest}}. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{svyranktest}. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. ##' @return An object of class \code{svyContTable}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Placeholder diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index de1c0fb..51f2975 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -4,15 +4,15 @@ ##' ##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. -##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{\link{svydesign}} function in the \code{\link{survey}} package. +##' @param data A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package. ##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. -##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{\link{svyglm}} and \code{\link{regTermTest}}. This is equivalent of the \code{\link{svyttest}} when there are only two groups. +##' @param testNormal A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{svyglm} and \code{regTermTest}. This is equivalent of the \code{svyttest} when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. -##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{\link{svyranktest}}. +##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{svyranktest}. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{svychisq}}. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{svychisq}. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. ##' @return An object of class \code{svyTableOne}, which really is a list of three objects. ##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} @@ -22,7 +22,7 @@ ##' ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, ##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, ##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} ##' @examples diff --git a/R/tableone-package.R b/R/tableone-package.R index b9d988d..7899bbe 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -28,9 +28,12 @@ ##' ##' Maintainer: Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, ##' \code{\link{ShowRegTable}} ##' @examples ##' From 0de6430cab767b55aadb5e1685596e2daa56920d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 18:42:04 -0400 Subject: [PATCH 078/219] Add print() method validation unit tests (strings compared) --- test-all.txt | 143 +++++++++++++++++++++++- tests/testthat/test-svyCreateTableOne.R | 126 +++++++++++++++++++++ 2 files changed, 268 insertions(+), 1 deletion(-) diff --git a/test-all.txt b/test-all.txt index d99e14b..31bf9fb 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1020,7 +1020,148 @@ Unit tests for svy* user functions : .... Stratified by E "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" "3.00 (0.00)" "<0.001" "" "C (mean (sd))" "2.13 (0.89)" "2.13 (0.89)" "2.13 (0.89)" "1.000" "" "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" "0.47 (0.50)" "1.000" "" -..... +....... Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 +... Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.009 nonnorm +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [range]) 0.00 [0.00, 1.00] 0.00 [0.00, 1.00] 0.009 nonnorm +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm +. Stratified by RIAGENDR + 1 2 p test + n 134944553.923 141591891.998 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 ( 14.303) + 2 89315751.415 (66.187) 92486945.142 ( 65.319) + 3 15045455.461 (11.149) 17967228.319 ( 12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 ( 19.882) + (19,39] 40497613.070 (30.011) 40640361.534 ( 28.702) + (39,59] 41053579.409 (30.423) 42817044.014 ( 30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 ( 21.176) + RIAGENDR = 2 (%) 0.000 ( 0.000) 141591891.998 (100.000) <0.001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.923 141591891.998 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 ( 14.303) + 2 89315751.415 (66.187) 92486945.142 ( 65.319) + 3 15045455.461 (11.149) 17967228.319 ( 12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 ( 19.882) + (19,39] 40497613.070 (30.011) 40640361.534 ( 28.702) + (39,59] 41053579.409 (30.423) 42817044.014 ( 30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 ( 21.176) + RIAGENDR = 2 (%) 0.000 ( 0.000) 141591891.998 (100.000) <0.001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.9 141591892.0 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 +. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 (14.303) + 2 89315751.415 (66.187) 92486945.142 (65.319) + 3 15045455.461 (11.149) 17967228.319 (12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 (19.882) + (19,39] 40497613.070 (30.011) 40640361.534 (28.702) + (39,59] 41053579.409 (30.423) 42817044.014 (30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 (21.176) + RIAGENDR = 2 (%) 0.000 (0.000) 141591891.998 (100.000) <0.001 +.. Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 +. Unit tests for the survey-related modules : ................................................ DONE diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 760e0be..b3a1f88 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -256,3 +256,129 @@ test_that("p values are correctly calculated", { expect_equal(attr(mwByTrt$ContTable, "pValues")[, "pNonNormal"], pValuesTestNonNormal) }) + + + +### Correctness of data object and final print out +################################################################################ + +## Create svydesign and TableOne object +data(nhanes) +nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, nest = TRUE, data = nhanes) +tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), + strata = "RIAGENDR", data = nhanesSvy, + factorVars = c("race","RIAGENDR")) + +### Gold standar data +## Sample size +outTotals <- svyby(formula = ~ tableone:::one(HI_CHOL), by = ~ RIAGENDR, design = nhanesSvy, + FUN = svytotal, na.rm = TRUE) +## Means +outMeans <- svyby(formula = ~ HI_CHOL, by = ~ RIAGENDR, design = nhanesSvy, FUN = svymean, na.rm = TRUE) +## Variances (for SD) +outVar <- svyby(formula = ~ HI_CHOL, by = ~ RIAGENDR, design = nhanesSvy, FUN = svyvar, na.rm = TRUE) +## Quantiles +outQt1 <- svyquantile( ~ HI_CHOL, subset(nhanesSvy, RIAGENDR == 1), quantiles = c(0.5,0.25,0.75,0,1), na.rm = TRUE) +outQt2 <- svyquantile( ~ HI_CHOL, subset(nhanesSvy, RIAGENDR == 2), quantiles = c(0.5,0.25,0.75,0,1), na.rm = TRUE) +## Tests +pTTest <- sprintf(" %.7f", as.vector(svyttest(HI_CHOL ~ RIAGENDR, nhanesSvy)$p.value)) +pRankTest <- sprintf(" %.7f", as.vector(svyranktest(HI_CHOL ~ RIAGENDR, nhanesSvy)$p.value)) + +test_that("continuous data object and final print outs are numerically correct", { + +### Continuous part +### Sample sizes +## Correctness of one() function for sample size against total weights +expect_equal(as.vector(by(nhanes$WTMEC2YR, nhanes$RIAGENDR, sum)), + outTotals[,2]) +## Numerical correctness +expect_equal(c(tab1$ContTable[[1]][,"n"], tab1$ContTable[[2]][,"n"]), + outTotals[,2]) +## print out correctness +expect_equal(as.vector(print(tab1$ContTable, printToggle = TRUE)[1,1:2]), + sprintf("%.2f", outTotals[,2])) + +### Means +## Numerical correctness +expect_equal(c(tab1$ContTable[[1]][,"mean"], tab1$ContTable[[2]][,"mean"]), + outMeans[,2]) + +### Standard deviations +## Numerically +expect_equal(c(tab1$ContTable[[1]][,"sd"], tab1$ContTable[[2]][,"sd"]), + sqrt(outVar[,2])) +## print out (mean and sd) +expect_equal(as.vector(print(tab1$ContTable, digits = 2, printToggle = TRUE)[2,1:2]), + sprintf("%.2f (%.2f)", outMeans[,2], sqrt(outVar[,2]))) + +### Quantiles +## median [p25, p75] +expect_equal(as.vector(print(tab1$ContTable, nonnormal = "HI_CHOL", printToggle = TRUE)[2,1:2]), + c(do.call(sprintf, c(list(fmt = "%.2f [%.2f, %.2f]"), outQt1[1:3])), + do.call(sprintf, c(list(fmt = "%.2f [%.2f, %.2f]"), outQt2[1:3])))) +## median [min,max] +expect_equal(as.vector(print(tab1$ContTable, nonnormal = "HI_CHOL", minMax = TRUE, printToggle = TRUE)[2,1:2]), + c(do.call(sprintf, c(list(fmt = "%.2f [%.2f, %.2f]"), outQt1[c(1,4,5)])), + do.call(sprintf, c(list(fmt = "%.2f [%.2f, %.2f]"), outQt2[c(1,4,5)])))) + +### p-values +## t test +expect_equal(print(tab1$ContTable, pDigits = 7, printToggle = TRUE)[2,3], + ## One space for < + pTTest) +## KW +expect_equal(print(tab1$ContTable, pDigits = 7, nonnormal = "HI_CHOL", printToggle = TRUE)[2,3], + ## One space for < + pRankTest) +}) + + +### Gold standard for categorical +outFreq <- svytable( ~ race + RIAGENDR, nhanesSvy) +outPerc <- prop.table(outFreq, margin = 2) +## Take first three rows only as space pading is tedious to reproduce +outFP <- cbind(sprintf("%.3f (%.3f) ", outFreq[,1], (outPerc[,1] * 100)), + sprintf(" %.3f ( %.3f) ", outFreq[,2], (outPerc[,2] * 100)))[1:3,] +## Test +pChisq <- sprintf(" %.7f", as.vector(svychisq( ~ race + RIAGENDR, nhanesSvy)$p.value)) + +test_that("categorical data object and final print outs are numerically correct", { + +### Categorical part + +### Sample sizes +expect_equal(as.vector(print(tab1$CatTable, digits = 3, printToggle = TRUE)[1,1:2]), + sprintf("%.3f", outTotals[,2])) +### Frequencies and percentages +matFP <- print(tab1$CatTable, digits = 3, printToggle = TRUE)[3:5,1:2] +dimnames(matFP) <- NULL +expect_equal(matFP, outFP) + +### p-values +expect_equal(print(tab1$CatTable, pDigits = 7, printToggle = TRUE)[2,3], + pChisq) +}) + + +test_that("mixed data object print outs are numerically correct", { + +### Mixed object +## Mean and SD +expect_equal(as.vector(gsub("^ *", "", print(tab1, pDigits = 7)[2,1:2])), + sprintf("%.2f (%.2f)", outMeans[,2], sqrt(outVar[,2]))) +## normal test +expect_equal(print(tab1, pDigits = 7)[2,3], pTTest) +## nonnormal test +expect_equal(print(tab1, pDigits = 7, nonnormal = "HI_CHOL")[2,3], pTTest) + +## Table +matFP <- print(tab1, catDigits = 3, printToggle = TRUE)[4:6,1:2] +dimnames(matFP) <- NULL +## column by column deleting spaces +expect_equal(matFP[,1], outFP[,1]) +expect_equal(gsub(" ", "", matFP[,1]), gsub(" ", "", outFP[,1])) +## chisq test +expect_equal(print(tab1, pDigits = 7, nonnormal = "HI_CHOL")[3,3], + pChisq) + +}) From dfba6ce01569857923cdec792a1449a84a6f090b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 19:44:07 -0400 Subject: [PATCH 079/219] Add NEWS --- NEWS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/NEWS b/NEWS index 225f00a..c055a61 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,25 @@ +tableone 0.7.0 (2015-07-26) +---------------------------------------------------------------- + +NEW FEATURES + +* Weighted data are now supported via the survey package. + The svydesign() should be used to create a survey design + object, and this object should be used for svyCreateTableOne() + instead of the orginal data frame. + +MINOR CHANGES + +* ShowRegTable() uses coef to refer to coefficients. + +* Unit tests were extended to cover more functions. + +BUG FIXES + +* pDigits option was not correctly functional in print.ContTable(). + + + tableone 0.6.3 (2014-12-28) ---------------------------------------------------------------- From 069bee819acdc767d397115e500592f26b1afb32 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 20:43:49 -0400 Subject: [PATCH 080/219] Add examples for weighted data --- R/print.svyCatTable.R | 2 +- R/print.svyContTable.R | 4 ++-- R/summary.svyCatTable.R | 2 +- R/summary.svyContTable.R | 2 +- R/svyCreateCatTable.R | 2 +- R/svyCreateContTable.R | 2 +- R/svyCreateTableOne.R | 40 ++++++++++++++++++++++++++++++++++++- R/tableone-package.R | 43 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 8 deletions(-) diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index d5b4e2b..604b53c 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -25,7 +25,7 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## +##' ## See the examples for svyCreateTableOne() ##' ##' @export print.svyCatTable <- function(x, # CatTable object diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 751025d..fab2e08 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -23,8 +23,8 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## -##' +##' ## See the examples for svyCreateTableOne() +##' ##' @export print.svyContTable <- function(x, # ContTable object digits = 2, pDigits = 3, # Number of digits to show diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index d9ab72d..0340112 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -13,7 +13,7 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## +##' ## See the examples for svyCreateTableOne() ##' ##' @export summary.svyCatTable <- function(object, digits = 1, ...) { diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index e812424..921ef14 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -13,7 +13,7 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## +##' ## See the examples for svyCreateTableOne() ##' ##' @export summary.svyContTable <- function(object, digits = 2, ...) { diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 1bf63f1..601b870 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -20,7 +20,7 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Placeholder +##' ## See the examples for svyCreateTableOne() ##' ##' @export svyCreateCatTable <- diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 0a0c242..bb999b8 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -21,7 +21,7 @@ ##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Placeholder +##' ## See the examples for svyCreateTableOne() ##' ##' @export svyCreateContTable <- diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 51f2975..4598432 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -27,7 +27,45 @@ ##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} ##' @examples ##' -##' ## Placeholder +##' ## Load packages +##' library(tableone) +##' library(survey) +##' +##' ## Create a weighted survey design object +##' data(nhanes) +##' nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, +##' nest = TRUE, data = nhanes) +##' +##' ## Create a table object +##' ## factorVars are converted to factors; no need to do this if variables are already factors +##' ## strata will stratify summaries; leave it unspecified, and overview is obtained +##' tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), +##' strata = "RIAGENDR", data = nhanesSvy, +##' factorVars = c("race","RIAGENDR")) +##' +##' ## Detailed output +##' summary(tab1) +##' +##' ## Default formatted printing +##' tab1 +##' +##' ## nonnormal specifies variables to be shown as median [IQR] +##' print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) +##' +##' ## minMax changes it to median [min, max] +##' print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) +##' +##' ## showAllLevels can be used tow show levels for all categorical variables +##' print(tab1, showAllLevels = TRUE) +##' +##' ## To see all printing options +##' ?print.TableOne +##' +##' ## To examine categorical variables only +##' tab1$CatTable +##' +##' ## To examine continuous variables only +##' tab1$ContTable ##' ##' @export svyCreateTableOne <- diff --git a/R/tableone-package.R b/R/tableone-package.R index 7899bbe..03e9753 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -94,4 +94,47 @@ ##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), ##' exact = c("status","stage"), cramVars = "sex", quote = TRUE, noSpaces = TRUE) ##' +##' +##' ## Analysis for weighted data +##' +##' ## Load packages +##' library(tableone) +##' library(survey) +##' +##' ## Create a weighted survey design object +##' data(nhanes) +##' nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, +##' nest = TRUE, data = nhanes) +##' +##' ## Create a table object +##' ## factorVars are converted to factors; no need to do this if variables are already factors +##' ## strata will stratify summaries; leave it unspecified, and overview is obtained +##' tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), +##' strata = "RIAGENDR", data = nhanesSvy, +##' factorVars = c("race","RIAGENDR")) +##' +##' ## Detailed output +##' summary(tab1) +##' +##' ## Default formatted printing +##' tab1 +##' +##' ## nonnormal specifies variables to be shown as median [IQR] +##' print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) +##' +##' ## minMax changes it to median [min, max] +##' print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) +##' +##' ## showAllLevels can be used tow show levels for all categorical variables +##' print(tab1, showAllLevels = TRUE) +##' +##' ## To see all printing options +##' ?print.TableOne +##' +##' ## To examine categorical variables only +##' tab1$CatTable +##' +##' ## To examine continuous variables only +##' tab1$ContTable +##' NULL From fe9c1d1a11e767ce12ece52695e0d52a3120962b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 20:48:00 -0400 Subject: [PATCH 081/219] Explain includeNA in NEWS --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index c055a61..b680b5d 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,9 @@ NEW FEATURES object, and this object should be used for svyCreateTableOne() instead of the orginal data frame. +* The includeNA option for CreateTableOne() and svyCreateTableOne() + make NA's in factors treated as a regular level. + MINOR CHANGES * ShowRegTable() uses coef to refer to coefficients. From 7a6d766002822ab44a701d25d7dc3f833861dfb4 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 20:51:12 -0400 Subject: [PATCH 082/219] Update LaTeX documents for modified functions/examples --- man/CreateCatTable.Rd | 8 +- man/CreateTableOne.Rd | 6 +- man/print.svyCatTable.Rd | 71 +-- man/print.svyContTable.Rd | 70 +-- man/summary.svyCatTable.Rd | 34 +- man/summary.svyContTable.Rd | 34 +- man/svyCreateCatTable.Rd | 85 +-- man/svyCreateContTable.Rd | 85 +-- man/svyCreateTableOne.Rd | 132 ++--- man/tableone-package.Rd | 52 +- tableone.Rcheck/tableone-Ex.Rout | 918 ++++++++++++++++++++++++++++++- 11 files changed, 1064 insertions(+), 431 deletions(-) diff --git a/man/CreateCatTable.Rd b/man/CreateCatTable.Rd index 81dd3d2..ced763a 100644 --- a/man/CreateCatTable.Rd +++ b/man/CreateCatTable.Rd @@ -4,9 +4,9 @@ \alias{CreateCatTable} \title{Create an object summarizing categorical variables} \usage{ -CreateCatTable(vars, strata, data, test = TRUE, testApprox = chisq.test, - argsApprox = list(correct = TRUE), testExact = fisher.test, - argsExact = list(workspace = 2 * 10^5)) +CreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, + testApprox = chisq.test, argsApprox = list(correct = TRUE), + testExact = fisher.test, argsExact = list(workspace = 2 * 10^5)) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} @@ -15,6 +15,8 @@ CreateCatTable(vars, strata, data, test = TRUE, testApprox = chisq.test, \item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} +\item{includeNA}{If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables.} + \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method.} \item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index a7fc58f..2d6c6ea 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -4,8 +4,8 @@ \alias{CreateTableOne} \title{Create an object summarizing both categorical and continuous variables} \usage{ -CreateTableOne(vars, strata, data, factorVars, test = TRUE, - testApprox = chisq.test, argsApprox = list(correct = TRUE), +CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, + test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), testNormal = oneway.test, argsNormal = list(var.equal = TRUE), testNonNormal = kruskal.test, argsNonNormal = list(NULL)) @@ -19,6 +19,8 @@ CreateTableOne(vars, strata, data, factorVars, test = TRUE, \item{factorVars}{Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument.} +\item{includeNA}{If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables.} + \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} \item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} diff --git a/man/print.svyCatTable.Rd b/man/print.svyCatTable.Rd index afd17ab..4123945 100644 --- a/man/print.svyCatTable.Rd +++ b/man/print.svyCatTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.svyCatTable.R \name{print.svyCatTable} \alias{print.svyCatTable} -\title{Format and print the \code{CatTable} class objects} +\title{Format and print the \code{svyCatTable} class objects} \usage{ \method{print}{svyCatTable}(x, digits = 1, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -10,7 +10,7 @@ cramVars = NULL, test = TRUE, exact = NULL, CrossTable = FALSE, ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{CreateCatTable}} function.} +\item{x}{The result of a call to the \code{\link{svyCreateCatTable}} function.} \item{digits}{Number of digits to print in the table.} @@ -34,7 +34,7 @@ \item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} -\item{exact}{A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).} +\item{exact}{This option is not available for tables from weighted data.} \item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} @@ -44,72 +44,17 @@ It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. } \description{ -This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +This is the \code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for categorical variables -catVars <- c("status","ascites","hepato","spiders","edema","stage") -catTableOverall <- CreateCatTable(vars = catVars, data = pbc) - -## Simply typing the object name will invoke the print.CatTable method, -## which will show the sample size, frequencies and percentages. -## For 2-level variables, only the higher level is shown for simplicity. -catTableOverall - -## If you need to show both levels for some 2-level factors, use cramVars -print(catTableOverall, cramVars = "hepato") - -## Use the showAllLevels argument to see all levels for all variables. -print(catTableOverall, showAllLevels = TRUE) - -## You can choose form frequencies ("f") and/or percentages ("p") or both. -## "fp" frequency (percentage) is the default. Row names change accordingly. -print(catTableOverall, format = "f") -print(catTableOverall, format = "p") - -## To further examine the variables, use the summary.CatTable method, -## which will show more details. -summary(catTableOverall) - -## The table can be stratified by one or more variables -catTableBySexTrt <- CreateCatTable(vars = catVars, - strata = c("sex","trt"), data = pbc) - -## print now includes p-values which are by default calculated by chisq.test. -## It is formatted at the decimal place specified by the pDigits argument -## (3 by default). It does <0.001 for you. -catTableBySexTrt - -## The exact argument toggles the p-values to the exact test result from -## fisher.test. It will show which ones are from exact tests. -print(catTableBySexTrt, exact = "ascites") - -## summary now includes both types of p-values -summary(catTableBySexTrt) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(catTableBySexTrt, exact = "ascites", quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +## See the examples for svyCreateTableOne() } \author{ Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/print.svyContTable.Rd b/man/print.svyContTable.Rd index 74d4bd1..bbc28d6 100644 --- a/man/print.svyContTable.Rd +++ b/man/print.svyContTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.svyContTable.R \name{print.svyContTable} \alias{print.svyContTable} -\title{Format and print the \code{ContTable} class objects} +\title{Format and print the \code{svyContTable} class objects} \usage{ \method{print}{svyContTable}(x, digits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -10,7 +10,7 @@ ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{CreateContTable}} function.} +\item{x}{The result of a call to the \code{\link{svyCreateContTable}} function.} \item{digits}{Number of digits to print in the table.} @@ -40,73 +40,17 @@ It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. } \description{ -This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +This is the \code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for continuous variables -contVars <- c("time","age","bili","chol","albumin","copper", - "alk.phos","ast","trig","platelet","protime") -contTableOverall <- CreateContTable(vars = contVars, data = pbc) - -## Simply typing the object name will invoke the print.ContTable method, -## which will show the sample size, means and standard deviations. -contTableOverall - -## To further examine the variables, use the summary.ContTable method, -## which will show more details. -summary(contTableOverall) - -## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. -## Specify them in the nonnormal argument, and the display changes to the median, -## and the [25th, 75th] percentile. -nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") -print(contTableOverall, nonnormal = nonNormalVars) - -## To show median [min,max] for nonnormal variables, use minMax = TRUE -print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) - -## The table can be stratified by one or more variables -contTableBySexTrt <- CreateContTable(vars = contVars, - strata = c("sex","trt"), data = pbc) - -## print now includes p-values which are by default calculated by oneway.test (t-test -## equivalent in the two group case). It is formatted at the decimal place specified -## by the pDigits argument (3 by default). It does <0.001 for you. -contTableBySexTrt - -## The nonnormal argument toggles the p-values to the nonparametric result from -## kruskal.test (wilcox.test equivalent for the two group case). -print(contTableBySexTrt, nonnormal = nonNormalVars) - -## The minMax argument toggles whether to show median [range] -print(contTableBySexTrt, nonnormal = nonNormalVars, minMax = TRUE) - -## summary now includes both types of p-values -summary(contTableBySexTrt) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +## See the examples for svyCreateTableOne() } \author{ Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/summary.svyCatTable.Rd b/man/summary.svyCatTable.Rd index 846d79d..d0892f6 100644 --- a/man/summary.svyCatTable.Rd +++ b/man/summary.svyCatTable.Rd @@ -2,12 +2,12 @@ % Please edit documentation in R/summary.svyCatTable.R \name{summary.svyCatTable} \alias{summary.svyCatTable} -\title{Shows all results in a \code{CatTable} class object} +\title{Shows all results in a \code{svyCatTable} class object} \usage{ \method{summary}{svyCatTable}(object, digits = 1, ...) } \arguments{ -\item{object}{An object that has the \code{CatTable} class to be shown.} +\item{object}{An object that has the \code{svyCatTable} class to be shown.} \item{digits}{Number of digits to print.} @@ -17,37 +17,17 @@ It will print the results. } \description{ -This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +This method shows all the data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for categorical variables -catVars <- c("status","ascites","hepato","spiders","edema","stage") -catTableOverall <- CreateCatTable(vars = catVars, data = pbc) - -## Simply typing the object name will invoke the print.CatTable method, -## which will show the sample size, frequencies and percentages. -## For 2-level variables, only the higher level is shown for simplicity. -catTableOverall - -## To further examine the variables, use the summary.CatTable method, -## which will show more details. -summary(catTableOverall) +## See the examples for svyCreateTableOne() } \author{ Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/summary.svyContTable.Rd b/man/summary.svyContTable.Rd index 87ea637..397156f 100644 --- a/man/summary.svyContTable.Rd +++ b/man/summary.svyContTable.Rd @@ -2,12 +2,12 @@ % Please edit documentation in R/summary.svyContTable.R \name{summary.svyContTable} \alias{summary.svyContTable} -\title{Shows all results in a \code{ContTable} class object} +\title{Shows all results in a \code{svyContTable} class object} \usage{ \method{summary}{svyContTable}(object, digits = 2, ...) } \arguments{ -\item{object}{An object that has the \code{ContTable} class to be shown.} +\item{object}{An object that has the \code{svyContTable} class to be shown.} \item{digits}{Number of digits to print.} @@ -17,37 +17,17 @@ It will print the results. } \description{ -This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +This method shows all the data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for continuous variables -contVars <- c("time","age","bili","chol","albumin","copper", - "alk.phos","ast","trig","platelet","protime") -contTableOverall <- CreateContTable(vars = contVars, data = pbc) - -## Simply typing the object name will invoke the print.ContTable method, -## which will show the sample size, means and standard deviations. -contTableOverall - -## To further examine the variables, use the summary.ContTable method, -## which will show more details. -summary(contTableOverall) +## See the examples for svyCreateTableOne() } \author{ Kazuki Yoshida } \seealso{ -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/svyCreateCatTable.Rd b/man/svyCreateCatTable.Rd index fce73eb..5363dcd 100644 --- a/man/svyCreateCatTable.Rd +++ b/man/svyCreateCatTable.Rd @@ -5,100 +5,41 @@ \title{Create an object summarizing categorical variables for weighted data} \usage{ svyCreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, - testApprox = chisq.test, argsApprox = list(correct = TRUE), - testExact = fisher.test, argsExact = list(workspace = 2 * 10^5)) + testApprox = svyTestChisq, argsApprox = NULL) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} \item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} -\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} +\item{data}{A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package.} -\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method.} - -\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} +\item{includeNA}{If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables.} -\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method.} -\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{svychisq}.} -\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox.} } \value{ -An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +An object of class \code{svyCatTable}. } \description{ Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See -also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for categorical variables -catVars <- c("status","ascites","hepato","spiders","edema","stage") -catTableOverall <- CreateCatTable(vars = catVars, data = pbc) - -## Simply typing the object name will invoke the print.CatTable method, -## which will show the sample size, frequencies and percentages. -## For 2-level variables, only the higher level is shown for simplicity -## unless the variables are specified in the cramVars argument. -catTableOverall - -## If you need to show both levels for some 2-level factors, use cramVars -print(catTableOverall, cramVars = "hepato") - -## Use the showAllLevels argument to see all levels for all variables. -print(catTableOverall, showAllLevels = TRUE) - -## You can choose form frequencies ("f") and/or percentages ("p") or both. -## "fp" frequency (percentage) is the default. Row names change accordingly. -print(catTableOverall, format = "f") -print(catTableOverall, format = "p") - -## To further examine the variables, use the summary.CatTable method, -## which will show more details. -summary(catTableOverall) - -## The table can be stratified by one or more variables -catTableBySexTrt <- CreateCatTable(vars = catVars, - strata = c("sex","trt"), data = pbc) - -## print now includes p-values which are by default calculated by chisq.test. -## It is formatted at the decimal place specified by the pDigits argument -## (3 by default). It does <0.001 for you. -catTableBySexTrt - -## The exact argument toggles the p-values to the exact test result from -## fisher.test. It will show which ones are from exact tests. -print(catTableBySexTrt, exact = "ascites") - -## summary now includes both types of p-values -summary(catTableBySexTrt) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(catTableBySexTrt, exact = "ascites", quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) +## See the examples for svyCreateTableOne() } \author{ -Kazuki Yoshida (based on \code{Deducer::frequencies()}) +Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/svyCreateContTable.Rd b/man/svyCreateContTable.Rd index 4df2dea..1a1c921 100644 --- a/man/svyCreateContTable.Rd +++ b/man/svyCreateContTable.Rd @@ -5,101 +5,44 @@ \title{Create an object summarizing continous variables for weighted dataset} \usage{ svyCreateContTable(vars, strata, data, test = TRUE, - testNormal = oneway.test, argsNormal = list(var.equal = TRUE), - testNonNormal = kruskal.test, argsNonNormal = list(NULL)) + testNormal = svyTestNormal, argsNormal = list(method = "Wald"), + testNonNormal = svyTestNonNormal, argsNonNormal = NULL) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} \item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} -\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} +\item{data}{A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package.} \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method.} -\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} +\item{testNormal}{A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{svyglm} and \code{regTermTest}. This is equivalent of the \code{svyttest} when there are only two groups.} -\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} +\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}.} -\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} +\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{svyranktest}.} -\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} - -\item{funcNames}{Not available for weighted dataset} - -\item{funcAdditional}{Not available for weighted dataset} +\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}.} } \value{ -An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +An object of class \code{svyContTable}. } \description{ Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See -also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Create an overall table for continuous variables -contVars <- c("time","age","bili","chol","albumin","copper", - "alk.phos","ast","trig","platelet","protime") -contTableOverall <- CreateContTable(vars = contVars, data = pbc) - -## Simply typing the object name will invoke the print.ContTable method, -## which will show the sample size, means and standard deviations. -contTableOverall - -## To further examine the variables, use the summary.ContTable method, -## which will show more details. -summary(contTableOverall) - -## c("age","chol","copper","alk.phos","trig","protime") appear highly skewed. -## Specify them in the nonnormal argument, and the display changes to the median, -## and the [25th, 75th] percentile. -nonNormalVars <- c("age","chol","copper","alk.phos","trig","protime") -print(contTableOverall, nonnormal = nonNormalVars) - -## To show median [min,max] for nonnormal variables, use minMax = TRUE -print(contTableOverall, nonnormal = nonNormalVars, minMax = TRUE) - -## The table can be stratified by one or more variables -contTableBySexTrt <- CreateContTable(vars = contVars, - strata = c("sex","trt"), data = pbc) - -## print now includes p-values which are by default calculated by oneway.test (t-test -## equivalent in the two group case). It is formatted at the decimal place specified -## by the pDigits argument (3 by default). It does <0.001 for you. -contTableBySexTrt - -## The nonnormal argument toggles the p-values to the nonparametric result from -## kruskal.test (wilcox.test equivalent for the two group case). -print(contTableBySexTrt, nonnormal = nonNormalVars) - -## summary now includes both types of p-values -summary(contTableBySexTrt) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) +## See the examples for svyCreateTableOne() } \author{ -Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) +Kazuki Yoshida } \seealso{ -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/svyCreateTableOne.Rd b/man/svyCreateTableOne.Rd index ee84153..a314912 100644 --- a/man/svyCreateTableOne.Rd +++ b/man/svyCreateTableOne.Rd @@ -4,47 +4,44 @@ \alias{svyCreateTableOne} \title{Create an object summarizing any variables for weighted data} \usage{ -svyCreateTableOne(vars, strata, data, factorVars, test = TRUE, - testApprox = chisq.test, argsApprox = list(correct = TRUE), - testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), - testNormal = oneway.test, argsNormal = list(var.equal = TRUE), - testNonNormal = kruskal.test, argsNonNormal = list(NULL)) +svyCreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, + test = TRUE, testApprox = svyTestChisq, argsApprox = NULL, + testNormal = svyTestNormal, argsNormal = list(method = "Wald"), + testNonNormal = svyTestNonNormal, argsNonNormal = NULL) } \arguments{ -\item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.} +\item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used.} \item{strata}{Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.} -\item{data}{A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame.} +\item{data}{A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the \code{svydesign} function in the \code{survey} package.} \item{factorVars}{Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument.} -\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} - -\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} +\item{includeNA}{If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables.} -\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} +\item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} -\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{svychisq}.} -\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox.} -\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} +\item{testNormal}{A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using \code{svyglm} and \code{regTermTest}. This is equivalent of the \code{svyttest} when there are only two groups.} -\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} +\item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}.} -\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} +\item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{svyranktest}.} -\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} +\item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}.} } \value{ -An object of class \code{TableOne}, which really is a list of three objects. +An object of class \code{svyTableOne}, which really is a list of three objects. \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} -\item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} +\item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} -\item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} +\item{CatTable}{ an object of class \code{svyCatTable}, containing categorical variables only} The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. } @@ -52,65 +49,52 @@ The second and third objects can be then be examined with the \code{print} and \ Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. } \examples{ -## Load +## Load packages library(tableone) +library(survey) + +## Create a weighted survey design object +data(nhanes) +nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, + nest = TRUE, data = nhanes) + +## Create a table object +## factorVars are converted to factors; no need to do this if variables are already factors +## strata will stratify summaries; leave it unspecified, and overview is obtained +tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), + strata = "RIAGENDR", data = nhanesSvy, + factorVars = c("race","RIAGENDR")) + +## Detailed output +summary(tab1) + +## Default formatted printing +tab1 + +## nonnormal specifies variables to be shown as median [IQR] +print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) + +## minMax changes it to median [min, max] +print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + +## showAllLevels can be used tow show levels for all categorical variables +print(tab1, showAllLevels = TRUE) + +## To see all printing options +?print.TableOne + +## To examine categorical variables only +tab1$CatTable -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Make categorical variables factors -varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - -## Create a variable list -dput(names(pbc)) -vars <- c("time","status","age","sex","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage") - -## Create Table 1 stratified by trt -tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) - -## Just typing the object name will invoke the print.TableOne method -tableOne - -## Specifying nonnormal variables will show the variables appropriately, -## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage")) - -## Use the summary.TableOne method for detailed summary -summary(tableOne) - -## See the categorical part only using $ operator -tableOne$CatTable -summary(tableOne$CatTable) - -## See the continuous part only using $ operator -tableOne$ContTable -summary(tableOne$ContTable) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) +## To examine continuous variables only +tab1$ContTable } \author{ -Justin Bohn, Kazuki Yoshida +Kazuki Yoshida } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} } diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index 217b4b9..f11d988 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -84,6 +84,49 @@ print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), ## If you want to center-align values in Word, use noSpaces option. print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), cramVars = "sex", quote = TRUE, noSpaces = TRUE) + + +## Analysis for weighted data + +## Load packages +library(tableone) +library(survey) + +## Create a weighted survey design object +data(nhanes) +nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, + nest = TRUE, data = nhanes) + +## Create a table object +## factorVars are converted to factors; no need to do this if variables are already factors +## strata will stratify summaries; leave it unspecified, and overview is obtained +tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), + strata = "RIAGENDR", data = nhanesSvy, + factorVars = c("race","RIAGENDR")) + +## Detailed output +summary(tab1) + +## Default formatted printing +tab1 + +## nonnormal specifies variables to be shown as median [IQR] +print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) + +## minMax changes it to median [min, max] +print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + +## showAllLevels can be used tow show levels for all categorical variables +print(tab1, showAllLevels = TRUE) + +## To see all printing options +?print.TableOne + +## To examine categorical variables only +tab1$CatTable + +## To examine continuous variables only +tab1$ContTable } \author{ Kazuki Yoshida, Justin Bohn @@ -91,9 +134,12 @@ Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, \code{\link{ShowRegTable}} } diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 485d6fe..d1d8504 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -1,6 +1,6 @@ -R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" -Copyright (C) 2014 The R Foundation for Statistical Computing +R version 3.2.1 (2015-06-18) -- "World-Famous Astronaut" +Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-apple-darwin13.4.0 (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. @@ -53,7 +53,6 @@ Type 'q()' to quit R. > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -472,7 +471,7 @@ stage 0.64630048 NA > base::cat("CreateCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("CreateContTable") > ### * CreateContTable @@ -491,7 +490,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -932,7 +930,7 @@ protime 1.365463e-01 8.114383e-02 > base::cat("CreateContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("CreateTableOne") > ### * CreateTableOne @@ -952,7 +950,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -1519,7 +1516,7 @@ protime 0.19714026 0.58802048 > base::cat("CreateTableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("ShowRegTable") > ### * ShowRegTable @@ -1538,7 +1535,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -1563,7 +1559,7 @@ Loading required package: splines > > ## Show the simple table > ShowRegTable(objCoxph) - exp(beta) [confint] p + exp(coef) [confint] p trt 1.03 [0.72, 1.47] 0.891 age 1.03 [1.01, 1.05] 0.005 albumin 0.26 [0.17, 0.41] <0.001 @@ -1571,7 +1567,7 @@ ascites 2.93 [1.68, 5.11] <0.001 > > ## Show with quote to ease copy and paste > ShowRegTable(objCoxph, quote = TRUE) - "exp(beta) [confint]" "p" + "exp(coef) [confint]" "p" "trt" "1.03 [0.72, 1.47]" " 0.891" "age" "1.03 [1.01, 1.05]" " 0.005" "albumin" "0.26 [0.17, 0.41]" "<0.001" @@ -1583,7 +1579,7 @@ ascites 2.93 [1.68, 5.11] <0.001 > base::cat("ShowRegTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("print.CatTable") > ### * print.CatTable @@ -1602,7 +1598,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -2020,7 +2015,7 @@ stage 0.64630048 NA > base::cat("print.CatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("print.ContTable") > ### * print.ContTable @@ -2039,7 +2034,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -2539,7 +2533,7 @@ protime 1.365463e-01 8.114383e-02 > base::cat("print.ContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("print.TableOne") > ### * print.TableOne @@ -2558,7 +2552,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -3488,8 +3481,46 @@ protime 1.365463e-01 8.114383e-02 > base::cat("print.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ +> nameEx("print.svyCatTable") +> ### * print.svyCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: print.svyCatTable +> ### Title: Format and print the 'svyCatTable' class objects +> ### Aliases: print.svyCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("print.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("print.svyContTable") +> ### * print.svyContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: print.svyContTable +> ### Title: Format and print the 'svyContTable' class objects +> ### Aliases: print.svyContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("print.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() > nameEx("summary.CatTable") > ### * summary.CatTable > @@ -3507,7 +3538,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -3588,7 +3618,7 @@ strata: Overall > base::cat("summary.CatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("summary.ContTable") > ### * summary.ContTable @@ -3607,7 +3637,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -3684,7 +3713,7 @@ protime 2.223 10.04 > base::cat("summary.ContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ > nameEx("summary.TableOne") > ### * summary.TableOne @@ -3703,7 +3732,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -3998,7 +4026,474 @@ stage 0.64630048 NA > base::cat("summary.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > cleanEx() -detaching ‘package:survival’, ‘package:splines’ +detaching ‘package:survival’ + +> nameEx("summary.svyCatTable") +> ### * summary.svyCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.svyCatTable +> ### Title: Shows all results in a 'svyCatTable' class object +> ### Aliases: summary.svyCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("summary.svyContTable") +> ### * summary.svyContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.svyContTable +> ### Title: Shows all results in a 'svyContTable' class object +> ### Aliases: summary.svyContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateCatTable") +> ### * svyCreateCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateCatTable +> ### Title: Create an object summarizing categorical variables for weighted +> ### data +> ### Aliases: svyCreateCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateContTable") +> ### * svyCreateContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateContTable +> ### Title: Create an object summarizing continous variables for weighted +> ### dataset +> ### Aliases: svyCreateContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateTableOne") +> ### * svyCreateTableOne +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateTableOne +> ### Title: Create an object summarizing any variables for weighted data +> ### Aliases: svyCreateTableOne +> +> ### ** Examples +> +> ## Load packages +> library(tableone) +> library(survey) +Loading required package: grid + +Attaching package: ‘survey’ + +The following object is masked from ‘package:graphics’: + + dotchart + +> +> ## Create a weighted survey design object +> data(nhanes) +> nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, ++ nest = TRUE, data = nhanes) +> +> ## Create a table object +> ## factorVars are converted to factors; no need to do this if variables are already factors +> ## strata will stratify summaries; leave it unspecified, and overview is obtained +> tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), ++ strata = "RIAGENDR", data = nhanesSvy, ++ factorVars = c("race","RIAGENDR")) +> +> ## Detailed output +> summary(tab1) + + ### Summary of continuous variables ### + +RIAGENDR: 1 + n miss p.miss mean sd median p25 p75 min max +HI_CHOL 1e+08 1e+07 7 0.1 0.3 0 0 0 0 1 +------------------------------------------------------------ +RIAGENDR: 2 + n miss p.miss mean sd median p25 p75 min max +HI_CHOL 1e+08 1e+07 8 0.1 0.3 0 0 0 0 1 + +p-values + pNormal pNonNormal +HI_CHOL 0.009221135 0.009221135 + +======================================================================================= + + ### Summary of categorical variables ### + +RIAGENDR: 1 + var n miss p.miss level freq percent cum.percent + race 134944553.9 0.0 0.0 1 21381884.2 15.8 15.8 + 2 89315751.4 66.2 82.0 + 3 15045455.5 11.1 93.2 + 4 9201462.9 6.8 100.0 + + agecat 134944553.9 0.0 0.0 (0,19] 29299546.1 21.7 21.7 + (19,39] 40497613.1 30.0 51.7 + (39,59] 41053579.4 30.4 82.1 + (59,Inf] 24093815.3 17.9 100.0 + + RIAGENDR 134944553.9 0.0 0.0 1 134944553.9 100.0 100.0 + 2 0.0 0.0 100.0 + +------------------------------------------------------------ +RIAGENDR: 2 + var n miss p.miss level freq percent cum.percent + race 141591892.0 0.0 0.0 1 20251367.4 14.3 14.3 + 2 92486945.1 65.3 79.6 + 3 17967228.3 12.7 92.3 + 4 10886351.1 7.7 100.0 + + agecat 141591892.0 0.0 0.0 (0,19] 28150760.5 19.9 19.9 + (19,39] 40640361.5 28.7 48.6 + (39,59] 42817044.0 30.2 78.8 + (59,Inf] 29983725.9 21.2 100.0 + + RIAGENDR 141591892.0 0.0 0.0 1 0.0 0.0 0.0 + 2 141591892.0 100.0 100.0 + + +p-values + pApprox pExact +race 4.162884e-02 NA +agecat 1.175703e-03 NA +RIAGENDR 2.688704e-49 NA +> +> ## Default formatted printing +> tab1 + Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.001 +> +> ## nonnormal specifies variables to be shown as median [IQR] +> print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 2 + n 134944553.923 141591891.998 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.000 [0.000, 0.000] + race (%) + 1 21381884.19 (15.84) 20251367.39 (14.30) + 2 89315751.41 (66.19) 92486945.14 (65.32) + 3 15045455.46 (11.15) 17967228.32 (12.69) + 4 9201462.86 ( 6.82) 10886351.15 ( 7.69) + agecat (%) + (0,19] 29299546.11 (21.71) 28150760.54 (19.88) + (19,39] 40497613.07 (30.01) 40640361.53 (28.70) + (39,59] 41053579.41 (30.42) 42817044.01 (30.24) + (59,Inf] 24093815.33 (17.85) 29983725.90 (21.18) + RIAGENDR = 2 (%) 0.00 (0.00) 141591892.00 (100.00) + Stratified by RIAGENDR + p test + n + HI_CHOL (median [IQR]) 0.0092 nonnorm + race (%) 0.0416 + 1 + 2 + 3 + 4 + agecat (%) 0.0012 + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) <0.0001 +> +> ## minMax changes it to median [min, max] +> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 + n 134944553.923 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] + race (%) + 1 21381884.19 (15.84) + 2 89315751.41 (66.19) + 3 15045455.46 (11.15) + 4 9201462.86 ( 6.82) + agecat (%) + (0,19] 29299546.11 (21.71) + (19,39] 40497613.07 (30.01) + (39,59] 41053579.41 (30.42) + (59,Inf] 24093815.33 (17.85) + RIAGENDR = 2 (%) 0.00 (0.00) + Stratified by RIAGENDR + 2 p test + n 141591891.998 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 (14.30) + 2 92486945.14 (65.32) + 3 17967228.32 (12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 (19.88) + (19,39] 40640361.53 (28.70) + (39,59] 42817044.01 (30.24) + (59,Inf] 29983725.90 (21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 +> +> ## showAllLevels can be used tow show levels for all categorical variables +> print(tab1, showAllLevels = TRUE) + Stratified by RIAGENDR + level 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 1 21381884.2 (15.8) 20251367.4 (14.3) 0.042 + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) (0,19] 29299546.1 (21.7) 28150760.5 (19.9) 0.001 + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) <0.001 + 2 0.0 ( 0.0) 141591892.0 (100.0) + Stratified by RIAGENDR + test + n + HI_CHOL (mean (sd)) + race (%) + + + + agecat (%) + + + + RIAGENDR (%) + +> +> ## To see all printing options +> ?print.TableOne +print.TableOne package:tableone R Documentation + +_F_o_r_m_a_t _a_n_d _p_r_i_n_t _t_h_e '_T_a_b_l_e_O_n_e' _c_l_a_s_s _o_b_j_e_c_t_s + +_D_e_s_c_r_i_p_t_i_o_n: + + This is the ‘print’ method for the ‘TableOne’ class objects + created by ‘CreateTableOne’ function. + +_U_s_a_g_e: + + ## S3 method for class 'TableOne' + print(x, catDigits = 1, contDigits = 2, pDigits = 3, + quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, + test = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], + showAllLevels = FALSE, cramVars = NULL, exact = NULL, + nonnormal = NULL, minMax = FALSE, ...) + +_A_r_g_u_m_e_n_t_s: + + x: The result of a call to the ‘CreateTableOne’ function. + +catDigits: Number of digits to print for proportions. Default 1. + +contDigits: Number of digits to print for continuous variables. Default + 2. + + pDigits: Number of digits to print for p-values. Default 3. + + quote: Whether to show everything in quotes. The default is FALSE. + If TRUE, everything including the row and column names are + quoted so that you can copy it to Excel easily. + + missing: Whether to show missing data information (not implemented + yet, placeholder) + + explain: Whether to add explanation to the variable names, i.e., (%) + is added to the variable names when percentage is shown. + +printToggle: Whether to print the output. If FLASE, no output is + created, and a matrix is invisibly returned. + + test: Whether to show the p-values. TRUE by default. If FALSE, only + the numerical summaries are shown. + +noSpaces: Whether to remove spaces added for alignment. Use this option + if you prefer to align numbers yourself in other software. + + format: The default is "fp" frequency (percentage). You can also + choose from "f" frequency only, "p" percentage only, and "pf" + percentage (frequency). + +showAllLevels: Whether to show all levels. FALSE by default, i.e., for + 2-level categorical variables, only the higher level is shown + to avoid redundant information. + +cramVars: A character vector to specify the two-level categorical + variables, for which both levels should be shown in one row. + + exact: A character vector to specify the variables for which the + p-values should be those of exact tests. By default all + p-values are from large sample approximation tests + (chisq.test). + +nonnormal: A character vector to specify the variables for which the + p-values should be those of nonparametric tests. By default + all p-values are from normal assumption-based tests + (oneway.test). + + minMax: Whether to use [min,max] instead of [p25,p75] for nonnormal + variables. The default is FALSE. + + ...: For compatibility with generic. Ignored. + +_V_a_l_u_e: + + It is mainly for printing the result. But this function does + return a matrix containing what you see in the output invisibly. + You can assign it to an object to save it. + +_A_u_t_h_o_r(_s): + + Kazuki Yoshida, Justin Bohn + +_S_e_e _A_l_s_o: + + ‘CreateTableOne’, ‘print.TableOne’, ‘summary.TableOne’, + ‘CreateCatTable’, ‘print.CatTable’, ‘summary.CatTable’, + ‘CreateContTable’, ‘print.ContTable’, ‘summary.ContTable’ + +_E_x_a_m_p_l_e_s: + + ## Load + library(tableone) + + ## Load Mayo Clinic Primary Biliary Cirrhosis Data + library(survival) + data(pbc) + ## Check variables + head(pbc) + + ## Make categorical variables factors + varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") + pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + + ## Create Table 1 stratified by sex and trt + tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage"), + strata = c("sex","trt"), data = pbc) + + ## Just typing the object name will invoke the print.TableOne method + tableOne + + ## Specifying nonnormal variables will show the variables appropriately, + ## and show nonparametric test p-values. Specify variables in the exact + ## argument to obtain the exact test p-values. cramVars can be used to + ## show both levels for a 2-level categorical variables. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato") + + ## Use the summary.TableOne method for detailed summary + summary(tableOne) + + ## See the categorical part only using $ operator + tableOne$CatTable + summary(tableOne$CatTable) + + ## See the continuous part only using $ operator + tableOne$ContTable + summary(tableOne$ContTable) + + ## If your work flow includes copying to Excel and Word when writing manuscripts, + ## you may benefit from the quote argument. This will quote everything so that + ## Excel does not mess up the cells. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato", quote = TRUE) + + ## If you want to center-align values in Word, use noSpaces option. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) + + +> +> ## To examine categorical variables only +> tab1$CatTable + Stratified by RIAGENDR + 1 2 p test + n 134944553.9 141591892.0 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 +> +> ## To examine continuous variables only +> tab1$ContTable + Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateTableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() + +detaching ‘package:survey’, ‘package:grid’ > nameEx("tableone-package") > ### * tableone-package @@ -4017,7 +4512,6 @@ detaching ‘package:survival’, ‘package:splines’ > > ## Load Mayo Clinic Primary Biliary Cirrhosis Data > library(survival) -Loading required package: splines > data(pbc) > ## Check variables > head(pbc) @@ -4583,6 +5077,378 @@ protime 0.19714026 0.58802048 " 4" "54 (35.1)" "" "" > > +> ## Analysis for weighted data +> +> ## Load packages +> library(tableone) +> library(survey) +Loading required package: grid + +Attaching package: ‘survey’ + +The following object is masked from ‘package:graphics’: + + dotchart + +> +> ## Create a weighted survey design object +> data(nhanes) +> nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, ++ nest = TRUE, data = nhanes) +> +> ## Create a table object +> ## factorVars are converted to factors; no need to do this if variables are already factors +> ## strata will stratify summaries; leave it unspecified, and overview is obtained +> tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), ++ strata = "RIAGENDR", data = nhanesSvy, ++ factorVars = c("race","RIAGENDR")) +> +> ## Detailed output +> summary(tab1) + + ### Summary of continuous variables ### + +RIAGENDR: 1 + n miss p.miss mean sd median p25 p75 min max +HI_CHOL 1e+08 1e+07 7 0.1 0.3 0 0 0 0 1 +------------------------------------------------------------ +RIAGENDR: 2 + n miss p.miss mean sd median p25 p75 min max +HI_CHOL 1e+08 1e+07 8 0.1 0.3 0 0 0 0 1 + +p-values + pNormal pNonNormal +HI_CHOL 0.009221135 0.009221135 + +======================================================================================= + + ### Summary of categorical variables ### + +RIAGENDR: 1 + var n miss p.miss level freq percent cum.percent + race 134944553.9 0.0 0.0 1 21381884.2 15.8 15.8 + 2 89315751.4 66.2 82.0 + 3 15045455.5 11.1 93.2 + 4 9201462.9 6.8 100.0 + + agecat 134944553.9 0.0 0.0 (0,19] 29299546.1 21.7 21.7 + (19,39] 40497613.1 30.0 51.7 + (39,59] 41053579.4 30.4 82.1 + (59,Inf] 24093815.3 17.9 100.0 + + RIAGENDR 134944553.9 0.0 0.0 1 134944553.9 100.0 100.0 + 2 0.0 0.0 100.0 + +------------------------------------------------------------ +RIAGENDR: 2 + var n miss p.miss level freq percent cum.percent + race 141591892.0 0.0 0.0 1 20251367.4 14.3 14.3 + 2 92486945.1 65.3 79.6 + 3 17967228.3 12.7 92.3 + 4 10886351.1 7.7 100.0 + + agecat 141591892.0 0.0 0.0 (0,19] 28150760.5 19.9 19.9 + (19,39] 40640361.5 28.7 48.6 + (39,59] 42817044.0 30.2 78.8 + (59,Inf] 29983725.9 21.2 100.0 + + RIAGENDR 141591892.0 0.0 0.0 1 0.0 0.0 0.0 + 2 141591892.0 100.0 100.0 + + +p-values + pApprox pExact +race 4.162884e-02 NA +agecat 1.175703e-03 NA +RIAGENDR 2.688704e-49 NA +> +> ## Default formatted printing +> tab1 + Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.001 +> +> ## nonnormal specifies variables to be shown as median [IQR] +> print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 2 + n 134944553.923 141591891.998 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.000 [0.000, 0.000] + race (%) + 1 21381884.19 (15.84) 20251367.39 (14.30) + 2 89315751.41 (66.19) 92486945.14 (65.32) + 3 15045455.46 (11.15) 17967228.32 (12.69) + 4 9201462.86 ( 6.82) 10886351.15 ( 7.69) + agecat (%) + (0,19] 29299546.11 (21.71) 28150760.54 (19.88) + (19,39] 40497613.07 (30.01) 40640361.53 (28.70) + (39,59] 41053579.41 (30.42) 42817044.01 (30.24) + (59,Inf] 24093815.33 (17.85) 29983725.90 (21.18) + RIAGENDR = 2 (%) 0.00 (0.00) 141591892.00 (100.00) + Stratified by RIAGENDR + p test + n + HI_CHOL (median [IQR]) 0.0092 nonnorm + race (%) 0.0416 + 1 + 2 + 3 + 4 + agecat (%) 0.0012 + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) <0.0001 +> +> ## minMax changes it to median [min, max] +> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 + n 134944553.923 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] + race (%) + 1 21381884.19 (15.84) + 2 89315751.41 (66.19) + 3 15045455.46 (11.15) + 4 9201462.86 ( 6.82) + agecat (%) + (0,19] 29299546.11 (21.71) + (19,39] 40497613.07 (30.01) + (39,59] 41053579.41 (30.42) + (59,Inf] 24093815.33 (17.85) + RIAGENDR = 2 (%) 0.00 (0.00) + Stratified by RIAGENDR + 2 p test + n 141591891.998 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 (14.30) + 2 92486945.14 (65.32) + 3 17967228.32 (12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 (19.88) + (19,39] 40640361.53 (28.70) + (39,59] 42817044.01 (30.24) + (59,Inf] 29983725.90 (21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 +> +> ## showAllLevels can be used tow show levels for all categorical variables +> print(tab1, showAllLevels = TRUE) + Stratified by RIAGENDR + level 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 1 21381884.2 (15.8) 20251367.4 (14.3) 0.042 + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) (0,19] 29299546.1 (21.7) 28150760.5 (19.9) 0.001 + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) <0.001 + 2 0.0 ( 0.0) 141591892.0 (100.0) + Stratified by RIAGENDR + test + n + HI_CHOL (mean (sd)) + race (%) + + + + agecat (%) + + + + RIAGENDR (%) + +> +> ## To see all printing options +> ?print.TableOne +print.TableOne package:tableone R Documentation + +_F_o_r_m_a_t _a_n_d _p_r_i_n_t _t_h_e '_T_a_b_l_e_O_n_e' _c_l_a_s_s _o_b_j_e_c_t_s + +_D_e_s_c_r_i_p_t_i_o_n: + + This is the ‘print’ method for the ‘TableOne’ class objects + created by ‘CreateTableOne’ function. + +_U_s_a_g_e: + + ## S3 method for class 'TableOne' + print(x, catDigits = 1, contDigits = 2, pDigits = 3, + quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, + test = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], + showAllLevels = FALSE, cramVars = NULL, exact = NULL, + nonnormal = NULL, minMax = FALSE, ...) + +_A_r_g_u_m_e_n_t_s: + + x: The result of a call to the ‘CreateTableOne’ function. + +catDigits: Number of digits to print for proportions. Default 1. + +contDigits: Number of digits to print for continuous variables. Default + 2. + + pDigits: Number of digits to print for p-values. Default 3. + + quote: Whether to show everything in quotes. The default is FALSE. + If TRUE, everything including the row and column names are + quoted so that you can copy it to Excel easily. + + missing: Whether to show missing data information (not implemented + yet, placeholder) + + explain: Whether to add explanation to the variable names, i.e., (%) + is added to the variable names when percentage is shown. + +printToggle: Whether to print the output. If FLASE, no output is + created, and a matrix is invisibly returned. + + test: Whether to show the p-values. TRUE by default. If FALSE, only + the numerical summaries are shown. + +noSpaces: Whether to remove spaces added for alignment. Use this option + if you prefer to align numbers yourself in other software. + + format: The default is "fp" frequency (percentage). You can also + choose from "f" frequency only, "p" percentage only, and "pf" + percentage (frequency). + +showAllLevels: Whether to show all levels. FALSE by default, i.e., for + 2-level categorical variables, only the higher level is shown + to avoid redundant information. + +cramVars: A character vector to specify the two-level categorical + variables, for which both levels should be shown in one row. + + exact: A character vector to specify the variables for which the + p-values should be those of exact tests. By default all + p-values are from large sample approximation tests + (chisq.test). + +nonnormal: A character vector to specify the variables for which the + p-values should be those of nonparametric tests. By default + all p-values are from normal assumption-based tests + (oneway.test). + + minMax: Whether to use [min,max] instead of [p25,p75] for nonnormal + variables. The default is FALSE. + + ...: For compatibility with generic. Ignored. + +_V_a_l_u_e: + + It is mainly for printing the result. But this function does + return a matrix containing what you see in the output invisibly. + You can assign it to an object to save it. + +_A_u_t_h_o_r(_s): + + Kazuki Yoshida, Justin Bohn + +_S_e_e _A_l_s_o: + + ‘CreateTableOne’, ‘print.TableOne’, ‘summary.TableOne’, + ‘CreateCatTable’, ‘print.CatTable’, ‘summary.CatTable’, + ‘CreateContTable’, ‘print.ContTable’, ‘summary.ContTable’ + +_E_x_a_m_p_l_e_s: + + ## Load + library(tableone) + + ## Load Mayo Clinic Primary Biliary Cirrhosis Data + library(survival) + data(pbc) + ## Check variables + head(pbc) + + ## Make categorical variables factors + varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") + pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) + + ## Create Table 1 stratified by sex and trt + tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", + "spiders","edema","bili","chol","albumin", + "copper","alk.phos","ast","trig","platelet", + "protime","stage"), + strata = c("sex","trt"), data = pbc) + + ## Just typing the object name will invoke the print.TableOne method + tableOne + + ## Specifying nonnormal variables will show the variables appropriately, + ## and show nonparametric test p-values. Specify variables in the exact + ## argument to obtain the exact test p-values. cramVars can be used to + ## show both levels for a 2-level categorical variables. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato") + + ## Use the summary.TableOne method for detailed summary + summary(tableOne) + + ## See the categorical part only using $ operator + tableOne$CatTable + summary(tableOne$CatTable) + + ## See the continuous part only using $ operator + tableOne$ContTable + summary(tableOne$ContTable) + + ## If your work flow includes copying to Excel and Word when writing manuscripts, + ## you may benefit from the quote argument. This will quote everything so that + ## Excel does not mess up the cells. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato", quote = TRUE) + + ## If you want to center-align values in Word, use noSpaces option. + print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), + exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) + + +> +> ## To examine categorical variables only +> tab1$CatTable + Stratified by RIAGENDR + 1 2 p test + n 134944553.9 141591892.0 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 +> +> ## To examine continuous variables only +> tab1$ContTable + Stratified by RIAGENDR + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 +> +> > > base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") > base::cat("tableone-package", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") @@ -4590,7 +5456,7 @@ protime 0.19714026 0.58802048 > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 6.968 0.167 7.23 0 0 +Time elapsed: 11.317 0.258 11.701 0.011 0.01 > grDevices::dev.off() null device 1 From ce00db4df02fb7ab460da5067898bda4c1c4e6b9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 21:02:52 -0400 Subject: [PATCH 083/219] Change CRAN URL in the vignette --- vignettes/introduction.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index 65f3280..0bf1850 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -160,5 +160,5 @@ print(tab3$ContTable, nonnormal = biomarkers) -------------------- - Authored by Kazuki Yoshida -- CRAN page: http://cran.r-project.org/web/packages/tableone +- CRAN page: http://cran.r-project.org/package=tableone - github page: https://github.com/kaz-yos/tableone From fe3626aafcfbe8ec3cef50fda5fb000bf783e280 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sun, 26 Jul 2015 21:05:52 -0400 Subject: [PATCH 084/219] Fix indentation --- R/svyCreateContTable.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index bb999b8..ae98935 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -55,7 +55,7 @@ function(vars, # character vector of variable n ## Create a single stratification variable ## Keeps non-existing levels - data$variables$..strataVar.. <- interaction(strata, sep = ":") + data$variables$..strataVar.. <- interaction(strata, sep = ":") strataVarLevels <- levels(data$variables$..strataVar..) ## Handle non-numeric elements (intergers give TRUE, and pass) From ea90b906e507e202a12a6f79e85dba6513c7018c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 14:01:32 -0400 Subject: [PATCH 085/219] Correct indentation of "" padding --- R/print.CatTable.R | 8 ++++---- R/print.ContTable.R | 6 +++--- R/print.svyCatTable.R | 10 +++++----- R/print.svyContTable.R | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 9b4c8de..8002df7 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -415,10 +415,10 @@ print.CatTable <- function(x, # CatTable object outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasExactColumnAdded) # Add "" padding if exact test used - ), + strataN, + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasExactColumnAdded) # Add "" padding if exact test used + ), out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 46c251d..4eae77c 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -286,9 +286,9 @@ print.ContTable <- function(x, # ContTable object outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) out <- rbind(n = c(strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used - ), + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used + ), out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 604b53c..2c23c29 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -361,11 +361,11 @@ print.svyCatTable <- function(x, # CatTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasExactColumnAdded) # Add "" padding if exact test used - ), + out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added + strataN, + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasExactColumnAdded) # Add "" padding if exact test used + ), out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index fab2e08..2a0c1b9 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -232,9 +232,9 @@ print.svyContTable <- function(x, # ContTable object outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) out <- rbind(n = c(strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used - ), + p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added + test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used + ), out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames From cc8a4363372fc2306b5d4b973f57078affb0daee Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 14:10:14 -0400 Subject: [PATCH 086/219] Refactor padding around stratum size row (passing) Less reliant on memorizing which padding was done --- R/print.CatTable.R | 18 ++++-------------- R/print.ContTable.R | 18 +++--------------- R/print.svyCatTable.R | 18 ++++-------------- R/print.svyContTable.R | 18 +++--------------- 4 files changed, 14 insertions(+), 58 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 8002df7..be2253a 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -149,8 +149,6 @@ print.CatTable <- function(x, # CatTable object ## Provide indicators to show what columns were added. wasLevelColumnAdded <- FALSE - wasPValueColumnAdded <- FALSE - wasExactColumnAdded <- FALSE ### Formatting for printing @@ -387,18 +385,12 @@ print.CatTable <- function(x, # CatTable object ## Put the values at the non-empty positions out[logiNonEmptyRowNames,"p"] <- pVec - ## Change the indicator - wasPValueColumnAdded <- TRUE - - ## Create an empty test type column, and add test types out <- cbind(out, test = rep("", nrow(out))) # Column for test types ## Put the test types at the non-empty positions (all rows in continuous!) out[logiNonEmptyRowNames,"test"] <- testTypes - ## Change the indicator - wasExactColumnAdded <- TRUE } @@ -414,12 +406,10 @@ print.CatTable <- function(x, # CatTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasExactColumnAdded) # Add "" padding if exact test used - ), - out) + nRow <- c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added + strataN) + nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 4eae77c..7e51c6d 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -143,10 +143,6 @@ print.ContTable <- function(x, # ContTable object }, simplify = TRUE) # vector with as many elements as strata - ## Provide indicators to show what columns were added. - wasPValueColumnAdded <- FALSE - wasNonNormalColumnAdded <- FALSE - ### Conversion of data for printing @@ -255,18 +251,12 @@ print.ContTable <- function(x, # ContTable object ## Column combine with the output out <- cbind(out, p = pVec) - ## Change the indicator - wasPValueColumnAdded <- TRUE - - ## Create an empty test type column, and add test types out <- cbind(out, test = rep("", nrow(out))) # Column for test types ## Put the test types at the non-empty positions (all rows in continuous!) out[ ,"test"] <- testTypes - ## Change the indicator - wasNonNormalColumnAdded <- TRUE } @@ -285,11 +275,9 @@ print.ContTable <- function(x, # ContTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - out <- rbind(n = c(strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used - ), - out) + nRow <- strataN + nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 2c23c29..e189c6e 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -96,8 +96,6 @@ print.svyCatTable <- function(x, # CatTable object ## Provide indicators to show what columns were added. wasLevelColumnAdded <- FALSE - wasPValueColumnAdded <- FALSE - wasExactColumnAdded <- FALSE ### Formatting for printing @@ -334,18 +332,12 @@ print.svyCatTable <- function(x, # CatTable object ## Put the values at the non-empty positions out[logiNonEmptyRowNames,"p"] <- pVec - ## Change the indicator - wasPValueColumnAdded <- TRUE - - ## Create an empty test type column, and add test types out <- cbind(out, test = rep("", nrow(out))) # Column for test types ## Put the test types at the non-empty positions (all rows in continuous!) out[logiNonEmptyRowNames,"test"] <- testTypes - ## Change the indicator - wasExactColumnAdded <- TRUE } @@ -361,12 +353,10 @@ print.svyCatTable <- function(x, # CatTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - out <- rbind(n = c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasExactColumnAdded) # Add "" padding if exact test used - ), - out) + nRow <- c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added + strataN) + nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 2a0c1b9..d487a16 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -89,10 +89,6 @@ print.svyContTable <- function(x, # ContTable object }, simplify = TRUE) # vector with as many elements as strata - ## Provide indicators to show what columns were added. - wasPValueColumnAdded <- FALSE - wasNonNormalColumnAdded <- FALSE - ### Conversion of data for printing @@ -201,18 +197,12 @@ print.svyContTable <- function(x, # ContTable object ## Column combine with the output out <- cbind(out, p = pVec) - ## Change the indicator - wasPValueColumnAdded <- TRUE - - ## Create an empty test type column, and add test types out <- cbind(out, test = rep("", nrow(out))) # Column for test types ## Put the test types at the non-empty positions (all rows in continuous!) out[ ,"test"] <- testTypes - ## Change the indicator - wasNonNormalColumnAdded <- TRUE } @@ -231,11 +221,9 @@ print.svyContTable <- function(x, # ContTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - out <- rbind(n = c(strataN, - p = rep("", wasPValueColumnAdded), # Add "" padding if p-value added - test = rep("", wasNonNormalColumnAdded) # Add "" padding if nonnormal test used - ), - out) + nRow <- strataN + nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames From fa3e0739b1b2ff39afb37cbe9ff87b187403bd0c Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 16:19:16 -0400 Subject: [PATCH 087/219] Add initial functions for standardize mean differences (passing) Continuous/binary functions Categorical (including binary) functions for both unweighted and weighted --- R/smdModules.R | 215 ++++++ test-all.txt | 1194 ++++++++++++++++++++---------- tests/testthat/test-smdModules.R | 274 +++++++ 3 files changed, 1293 insertions(+), 390 deletions(-) create mode 100644 R/smdModules.R create mode 100755 tests/testthat/test-smdModules.R diff --git a/R/smdModules.R b/R/smdModules.R new file mode 100644 index 0000000..c9bdc69 --- /dev/null +++ b/R/smdModules.R @@ -0,0 +1,215 @@ +################################################################################ +### Modules for standardized mean difference support +## +## Created on: 2015-07-29 +## Author: Kazuki Yoshida +################################################################################ + +### +### References +################################################################################ +## A unified approach to measuring the effect size between two groups using SAS® +## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf + + +### +### Helpers common to both +################################################################################ + +## Multinomial standardized differences +## A unified approach to measuring the effect size between two groups using SAS® +## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf +## R multinomial distribution variance +## http://stackoverflow.com/questions/19960605/r-multinomial-distribution-variance +## Receives dummie variable matrix with no redundant column + +## Dummy matrix to means (proportions for each dummy) +MultinomialMeans <- function(dummyMat, na.rm = TRUE) { + colMeans(dummyMat, na.rm = na.rm) +} + +## Proportions to variance-covariance matrix +MultinomialVar <- function(multinomialMeans) { + ## Mean for each + p <- multinomialMeans + ## Diagonal elements are p_i(1-p_i) + vars <- p * (1 - p) + ## Off-diagonal elements are - p_i p_j where i != j + covs <- - outer(p, p) + ## Put diagonal elements + diag(covs) <- vars + ## Reduce to a scalar if 1x1 + drop(covs) +} + +## +StdDiffFromLstMeans <- function(lstMeans) { + + ## list of covariance matrices + lstCovs <- lapply(lstMeans, MultinomialVar) + + ## All possible mean vector differences + lstMeanDiffs <- lapply(lstMeans, function(x) { + lapply(lstMeans, function(y) { + x - y + }) + }) + + ## All possible covariance matrix means + lstCovMeans <- lapply(lstCovs, function(x) { + lapply(lstCovs, function(y) { + (x + y) / 2 + }) + }) + + ## Initialize a numeric vector object for capturing values + smds <- vector(mode = "numeric") + + ## Add upper triangle elements (i < j) to output list + for (i in seq_along(lstMeans)) { + for (j in seq_along(lstMeans)) { + if (i < j) { + ## For upper triangle elements only + ## Squared Mahalanobis distance + ## meanDiffs^T covMean^-1 meanDiffs + sqMahaDist <- + t(lstMeanDiffs[[i]][[j]]) %*% + MASS::ginv(lstCovMeans[[i]][[j]]) %*% + t(t(lstMeanDiffs[[i]][[j]])) + ## Add sqrt of MD to output + ## Not efficient; room for improvement + smds <- c(smds, sqrt(sqMahaDist)) + } + } + } + smds +} + + +## Given strata x levels of variable table +## Return list of proportions of levels dropping redundant first level +LstMeansFromFullTable <- function(strataByLevels) { + ## Proportion within each stratum + ## Equivalent to mean of dummy variables + propTables <- prop.table(strataByLevels, margin = 1) + ## Drop first level to eliminate dependence + propTables <- propTables[, -1, drop = FALSE] + + ## list of mean vectors (Missing values are discarded) + lstMeans <- lapply(seq_len(nrow(propTables)), function(i) { + + propTables[i,] + }) + lstMeans +} + + + + + +### +### Functions for unweighted data only +################################################################################ + +### Continuous/binary standardized mean differences +## Expects continuous or 0,1 binary variable +StdDiff <- function(variable, group, binary = FALSE, na.rm = TRUE) { + + ## Proportion of 1 is the mean of variable + means <- tapply(variable, group, mean, na.rm = na.rm) + + ## Variance is p(1-p) + if (binary) { + vars <- means * (1 - means) + } else { + vars <- tapply(variable, group, var, na.rm = na.rm) + } + + ## Outer to obtain all pairwise differences + meanDiffs <- outer(X = means, Y = means, FUN = "-") + ## Outer to obtain all pairwise variance mean + varMeans <- outer(X = vars, Y = vars, FUN = "+") / 2 + + out <- meanDiffs / sqrt(varMeans) + + abs(out[upper.tri(out)]) +} + +### Categorical (including binary) standardizzed mean difference +StdDiffMulti <- function(variable, group) { + + ## strata x variable table + strataByLevels <- table(group, variable) + lstMeans <- LstMeansFromFullTable(strataByLevels) + ## Return vector of SMDs + StdDiffFromLstMeans(lstMeans) +} + + +### Standardized mean differences for multiple variables +## Continuous or binary only +StdDiffs <- function(data, vars, groupVar, binaryVars) { + + lapply(vars, function(var) { + + StdDiff(variable = data[,var], group = data[,groupVar], + binary = (var %in% binaryVars)) + }) +} + + +### +### Functions for weighted data only +################################################################################ + +### Continuous/binary standardized mean differences +## Expects continuous or 0,1 binary variable +svyStdDiff <- function(varName, groupName, design, binary = FALSE, na.rm = TRUE) { + + varFormula <- as.formula(paste("~", varName)) + groupFormula <- as.formula(paste("~", groupName)) + + means <- svyby(formula = varFormula, by = groupFormula, + FUN = svymean, design = design, na.rm = na.rm)[,2] + + if (binary) { + vars <- means * (1 - means) + } else { + vars <- svyby(formula = varFormula, by = groupFormula, + FUN = svyvar, design = design, na.rm = na.rm)[,2] + } + + ## Outer to obtain all pairwise differences + meanDiffs <- outer(X = means, Y = means, FUN = "-") + ## Outer to obtain all pairwise variance mean + varMeans <- outer(X = vars, Y = vars, FUN = "+") / 2 + + out <- meanDiffs / sqrt(varMeans) + + abs(out[upper.tri(out)]) +} + + +### Categorical (including binary) standardizzed mean difference +svyStdDiffMulti <- function(varName, groupName, design) { + + tabFormula <- as.formula(sprintf("~ %s + %s", groupName, varName)) + + ## strata x variable table + strataByLevels <- svytable(formula = tabFormula, design = design) + lstMeans <- LstMeansFromFullTable(strataByLevels) + ## Return vector of SMDs + StdDiffFromLstMeans(lstMeans) +} + + +### Standardized mean differences for multiple variables +## Continuous or binary only +svyStdDiffs <- function(data, vars, groupVar, binaryVars) { + + lapply(vars, function(var) { + + svyStdDiff(varName = var, groupName = groupVar, design = data, + binary = (var %in% binaryVars)) + }) +} diff --git a/test-all.txt b/test-all.txt index 31bf9fb..ccba653 100644 --- a/test-all.txt +++ b/test-all.txt @@ -103,67 +103,129 @@ Unit tests for the CreateTableOne function : ........... St 4 144 (34.4) NA 6 ( 1.4) . Stratified by trt:sex - 1:m 2:m 1:f 2:f p test - n 21 15 137 139 - time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 - status (%) 0.033 - 0 4 (19.0) 7 (46.7) 79 (57.7) 78 (56.1) - 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) - 2 14 (66.7) 8 (53.3) 51 (37.2) 52 (37.4) - age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 - sex = f (%) 0 (0.0) 0 (0.0) 137 (100.0) 139 (100.0) <0.001 - ascites = 1 (%) 1 (4.8) 2 (13.3) 13 (9.5) 8 (5.8) 0.516 - hepato = 1 (%) 12 (57.1) 9 (60.0) 61 (44.5) 78 (56.1) 0.208 - spiders = 1 (%) 3 (14.3) 1 (6.7) 42 (30.7) 44 (31.7) 0.089 - edema (%) 0.906 - 0 17 (81.0) 12 (80.0) 115 (83.9) 119 (85.6) - 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) 12 ( 8.6) - 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) 8 ( 5.8) - bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 - chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 - copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 - trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 - platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 - stage (%) 0.646 - 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) 3 ( 2.2) - 2 4 (19.0) 2 (13.3) 31 (22.6) 30 (21.6) - 3 7 (33.3) 5 (33.3) 49 (35.8) 59 (42.4) - 4 8 (38.1) 7 (46.7) 47 (34.3) 47 (33.8) + 1:m 2:m 1:f + n 21 15 137 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) + status (%) + 0 4 (19.0) 7 (46.7) 79 (57.7) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) + 2 14 (66.7) 8 (53.3) 51 (37.2) + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) + sex = f (%) 0 (0.0) 0 (0.0) 137 (100.0) + ascites = 1 (%) 1 (4.8) 2 (13.3) 13 (9.5) + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 (44.5) + spiders = 1 (%) 3 (14.3) 1 (6.7) 42 (30.7) + edema (%) + 0 17 (81.0) 12 (80.0) 115 (83.9) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) + stage (%) + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) + 2 4 (19.0) 2 (13.3) 31 (22.6) + 3 7 (33.3) 5 (33.3) 49 (35.8) + 4 8 (38.1) 7 (46.7) 47 (34.3) + Stratified by trt:sex + 2:f p test + n 139 + time (mean (sd)) 1979.65 (1127.52) 0.730 + status (%) 0.033 + 0 78 (56.1) + 1 9 ( 6.5) + 2 52 (37.4) + age (mean (sd)) 47.66 (9.54) <0.001 + sex = f (%) 139 (100.0) <0.001 + ascites = 1 (%) 8 (5.8) 0.516 + hepato = 1 (%) 78 (56.1) 0.208 + spiders = 1 (%) 44 (31.7) 0.089 + edema (%) 0.906 + 0 119 (85.6) + 0.5 12 ( 8.6) + 1 8 ( 5.8) + bili (mean (sd)) 3.75 (5.50) 0.394 + chol (mean (sd)) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.53 (0.39) 0.585 + copper (mean (sd)) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 126.30 (60.27) 0.598 + trig (mean (sd)) 126.38 (60.22) 0.370 + platelet (mean (sd)) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.75 (1.15) 0.137 + stage (%) 0.646 + 1 3 ( 2.2) + 2 30 (21.6) + 3 59 (42.4) + 4 47 (33.8) . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 - status (%) 0.89351 - 0 83 (52.532) 85 (55.195) - 1 10 ( 6.329) 9 ( 5.844) - 2 65 (41.139) 60 (38.961) - age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 - sex = f (%) 137 (86.709) 139 (90.260) 0.42123 - ascites = 1 (%) 14 (8.861) 10 (6.494) 0.56729 - hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 - spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 - edema (%) 0.87682 - 0 132 (83.544) 131 (85.065) - 0.5 16 (10.127) 13 ( 8.442) - 1 10 ( 6.329) 10 ( 6.494) - bili (mean (sd)) 2.8734 (3.6289) 3.6487 (5.2819) 0.13094 - chol (mean (sd)) 365.0143 (209.5439) 373.8819 (252.4846) 0.74799 - albumin (mean (sd)) 3.5163 (0.4433) 3.5238 (0.3958) 0.87388 - copper (mean (sd)) 97.6433 (90.5901) 97.6536 (80.4865) 0.99916 - alk.phos (mean (sd)) 2021.2975 (2183.4358) 1943.0104 (2101.6873) 0.74726 - ast (mean (sd)) 120.2087 (54.5214) 124.9650 (58.9313) 0.45970 - trig (mean (sd)) 124.1367 (71.5391) 125.2517 (58.5211) 0.88604 - platelet (mean (sd)) 258.7500 (100.3247) 265.2039 (90.7294) 0.55451 - protime (mean (sd)) 10.6532 (0.8514) 10.8000 (1.1382) 0.19714 - stage (%) 0.20130 - 1 12 ( 7.595) 4 ( 2.597) - 2 35 (22.152) 32 (20.779) - 3 56 (35.443) 64 (41.558) - 4 55 (34.810) 54 (35.065) + 1 2 p + n 158 154 + time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 + status (%) 0.89351 + 0 83 (52.532) 85 (55.195) + 1 10 ( 6.329) 9 ( 5.844) + 2 65 (41.139) 60 (38.961) + age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 + sex = f (%) 137 (86.709) 139 (90.260) 0.42123 + ascites = 1 (%) 14 (8.861) 10 (6.494) 0.56729 + hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 + spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 + edema (%) 0.87682 + 0 132 (83.544) 131 (85.065) + 0.5 16 (10.127) 13 ( 8.442) + 1 10 ( 6.329) 10 ( 6.494) + bili (mean (sd)) 2.8734 (3.6289) 3.6487 (5.2819) 0.13094 + chol (mean (sd)) 365.0143 (209.5439) 373.8819 (252.4846) 0.74799 + albumin (mean (sd)) 3.5163 (0.4433) 3.5238 (0.3958) 0.87388 + copper (mean (sd)) 97.6433 (90.5901) 97.6536 (80.4865) 0.99916 + alk.phos (mean (sd)) 2021.2975 (2183.4358) 1943.0104 (2101.6873) 0.74726 + ast (mean (sd)) 120.2087 (54.5214) 124.9650 (58.9313) 0.45970 + trig (mean (sd)) 124.1367 (71.5391) 125.2517 (58.5211) 0.88604 + platelet (mean (sd)) 258.7500 (100.3247) 265.2039 (90.7294) 0.55451 + protime (mean (sd)) 10.6532 (0.8514) 10.8000 (1.1382) 0.19714 + stage (%) 0.20130 + 1 12 ( 7.595) 4 ( 2.597) + 2 35 (22.152) 32 (20.779) + 3 56 (35.443) 64 (41.558) + 4 55 (34.810) 54 (35.065) + Stratified by trt + test + n + time (mean (sd)) + status (%) + 0 + 1 + 2 + age (mean (sd)) + sex = f (%) + ascites = 1 (%) + hepato = 1 (%) + spiders = 1 (%) + edema (%) + 0 + 0.5 + 1 + bili (mean (sd)) + chol (mean (sd)) + albumin (mean (sd)) + copper (mean (sd)) + alk.phos (mean (sd)) + ast (mean (sd)) + trig (mean (sd)) + platelet (mean (sd)) + protime (mean (sd)) + stage (%) + 1 + 2 + 3 + 4 . Stratified by trt 1 2 n 158 154 @@ -196,161 +258,317 @@ Unit tests for the CreateTableOne function : ........... St 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0.884 exact - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 0.205 exact - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) + 1 2 + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) + status (%) + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) + sex = f (%) 137 (86.7) 139 (90.3) + ascites = 1 (%) 14 (8.9) 10 (6.5) + hepato = 1 (%) 73 (46.2) 87 (56.5) + spiders = 1 (%) 45 (28.5) 45 (29.2) + edema (%) + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) + stage (%) + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) + Stratified by trt + p test + n + time (mean (sd)) 0.883 + status (%) 0.884 exact + 0 + 1 + 2 + age (mean (sd)) 0.018 + sex = f (%) 0.421 + ascites = 1 (%) 0.567 + hepato = 1 (%) 0.088 + spiders = 1 (%) 0.985 + edema (%) 0.877 + 0 + 0.5 + 1 + bili (median [IQR]) 0.842 nonnorm + chol (median [IQR]) 0.544 nonnorm + albumin (mean (sd)) 0.874 + copper (median [IQR]) 0.717 nonnorm + alk.phos (median [IQR]) 0.812 nonnorm + ast (mean (sd)) 0.460 + trig (median [IQR]) 0.370 nonnorm + platelet (mean (sd)) 0.555 + protime (mean (sd)) 0.197 + stage (%) 0.205 exact + 1 + 2 + 3 + 4 . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0.894 - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm - chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm - alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 0.201 - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) + 1 + n 158 + time (mean (sd)) 2015.62 (1094.12) + status (%) + 0 83 (52.5) + 1 10 ( 6.3) + 2 65 (41.1) + age (mean (sd)) 51.42 (11.01) + sex = f (%) 137 (86.7) + ascites = 1 (%) 14 (8.9) + hepato = 1 (%) 73 (46.2) + spiders = 1 (%) 45 (28.5) + edema (%) + 0 132 (83.5) + 0.5 16 (10.1) + 1 10 ( 6.3) + bili (median [range]) 1.40 [0.30, 20.00] + chol (median [range]) 315.50 [127.00, 1712.00] + albumin (mean (sd)) 3.52 (0.44) + copper (median [range]) 73.00 [9.00, 588.00] + alk.phos (median [range]) 1214.50 [369.00, 11552.00] + ast (mean (sd)) 120.21 (54.52) + trig (median [range]) 106.00 [33.00, 598.00] + platelet (mean (sd)) 258.75 (100.32) + protime (mean (sd)) 10.65 (0.85) + stage (%) + 1 12 ( 7.6) + 2 35 (22.2) + 3 56 (35.4) + 4 55 (34.8) + Stratified by trt + 2 p test + n 154 + time (mean (sd)) 1996.86 (1155.93) 0.883 + status (%) 0.894 + 0 85 (55.2) + 1 9 ( 5.8) + 2 60 (39.0) + age (mean (sd)) 48.58 (9.96) 0.018 + sex = f (%) 139 (90.3) 0.421 + ascites = 1 (%) 10 (6.5) 0.567 + hepato = 1 (%) 87 (56.5) 0.088 + spiders = 1 (%) 45 (29.2) 0.985 + edema (%) 0.877 + 0 131 (85.1) + 0.5 13 ( 8.4) + 1 10 ( 6.5) + bili (median [range]) 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 124.97 (58.93) 0.460 + trig (median [range]) 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.80 (1.14) 0.197 + stage (%) 0.201 + 1 4 ( 2.6) + 2 32 (20.8) + 3 64 (41.6) + 4 54 (35.1) . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0.884 exact - 0 83 (52.5) 85 (55.2) - 1 10 (6.3) 9 (5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 (8.4) - 1 10 (6.3) 10 (6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 0.205 exact - 1 12 (7.6) 4 (2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) + 1 2 + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) + status (%) + 0 83 (52.5) 85 (55.2) + 1 10 (6.3) 9 (5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) + sex = f (%) 137 (86.7) 139 (90.3) + ascites = 1 (%) 14 (8.9) 10 (6.5) + hepato = 1 (%) 73 (46.2) 87 (56.5) + spiders = 1 (%) 45 (28.5) 45 (29.2) + edema (%) + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 (8.4) + 1 10 (6.3) 10 (6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) + stage (%) + 1 12 (7.6) 4 (2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) + Stratified by trt + p test + n + time (mean (sd)) 0.883 + status (%) 0.884 exact + 0 + 1 + 2 + age (mean (sd)) 0.018 + sex = f (%) 0.421 + ascites = 1 (%) 0.567 + hepato = 1 (%) 0.088 + spiders = 1 (%) 0.985 + edema (%) 0.877 + 0 + 0.5 + 1 + bili (median [IQR]) 0.842 nonnorm + chol (median [IQR]) 0.544 nonnorm + albumin (mean (sd)) 0.874 + copper (median [IQR]) 0.717 nonnorm + alk.phos (median [IQR]) 0.812 nonnorm + ast (mean (sd)) 0.460 + trig (median [IQR]) 0.370 nonnorm + platelet (mean (sd)) 0.555 + protime (mean (sd)) 0.197 + stage (%) 0.205 exact + 1 + 2 + 3 + 4 . Stratified by trt - level 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0 83 (52.5) 85 (55.2) 0.884 exact - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex (%) m 21 (13.3) 15 ( 9.7) 0.421 - f 137 (86.7) 139 (90.3) - ascites (%) 0 144 (91.1) 144 (93.5) 0.567 - 1 14 ( 8.9) 10 ( 6.5) - hepato (%) 0 85 (53.8) 67 (43.5) 0.088 - 1 73 (46.2) 87 (56.5) - spiders (%) 0 113 (71.5) 109 (70.8) 0.985 - 1 45 (28.5) 45 (29.2) - edema (%) 0 132 (83.5) 131 (85.1) 0.877 - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 1 12 ( 7.6) 4 ( 2.6) 0.205 exact - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) + level 1 + n 158 + time (mean (sd)) 2015.62 (1094.12) + status (%) 0 83 (52.5) + 1 10 ( 6.3) + 2 65 (41.1) + age (mean (sd)) 51.42 (11.01) + sex (%) m 21 (13.3) + f 137 (86.7) + ascites (%) 0 144 (91.1) + 1 14 ( 8.9) + hepato (%) 0 85 (53.8) + 1 73 (46.2) + spiders (%) 0 113 (71.5) + 1 45 (28.5) + edema (%) 0 132 (83.5) + 0.5 16 (10.1) + 1 10 ( 6.3) + bili (median [IQR]) 1.40 [0.80, 3.20] + chol (median [IQR]) 315.50 [247.75, 417.00] + albumin (mean (sd)) 3.52 (0.44) + copper (median [IQR]) 73.00 [40.00, 121.00] + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] + ast (mean (sd)) 120.21 (54.52) + trig (median [IQR]) 106.00 [84.50, 146.00] + platelet (mean (sd)) 258.75 (100.32) + protime (mean (sd)) 10.65 (0.85) + stage (%) 1 12 ( 7.6) + 2 35 (22.2) + 3 56 (35.4) + 4 55 (34.8) + Stratified by trt + 2 p test + n 154 + time (mean (sd)) 1996.86 (1155.93) 0.883 + status (%) 85 (55.2) 0.884 exact + 9 ( 5.8) + 60 (39.0) + age (mean (sd)) 48.58 (9.96) 0.018 + sex (%) 15 ( 9.7) 0.421 + 139 (90.3) + ascites (%) 144 (93.5) 0.567 + 10 ( 6.5) + hepato (%) 67 (43.5) 0.088 + 87 (56.5) + spiders (%) 109 (70.8) 0.985 + 45 (29.2) + edema (%) 131 (85.1) 0.877 + 13 ( 8.4) + 10 ( 6.5) + bili (median [IQR]) 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 124.97 (58.93) 0.460 + trig (median [IQR]) 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.80 (1.14) 0.197 + stage (%) 4 ( 2.6) 0.205 exact + 32 (20.8) + 64 (41.6) + 54 (35.1) . "Stratified by trt" - "" "1" "2" "p" "test" - "n" "158" "154" "" "" - "time (mean (sd))" "2015.62 (1094.12)" "1996.86 (1155.93)" "0.883" "" - "status (%)" "" "" "0.884" "exact" - " 0" "83 (52.5)" "85 (55.2)" "" "" - " 1" "10 (6.3)" "9 (5.8)" "" "" - " 2" "65 (41.1)" "60 (39.0)" "" "" - "age (mean (sd))" "51.42 (11.01)" "48.58 (9.96)" "0.018" "" - "sex = f (%)" "137 (86.7)" "139 (90.3)" "0.421" "" - "ascites = 1 (%)" "14 (8.9)" "10 (6.5)" "0.567" "" - "hepato = 1 (%)" "73 (46.2)" "87 (56.5)" "0.088" "" - "spiders = 1 (%)" "45 (28.5)" "45 (29.2)" "0.985" "" - "edema (%)" "" "" "0.877" "" - " 0" "132 (83.5)" "131 (85.1)" "" "" - " 0.5" "16 (10.1)" "13 (8.4)" "" "" - " 1" "10 (6.3)" "10 (6.5)" "" "" - "bili (median [IQR])" "1.40 [0.80, 3.20]" "1.30 [0.72, 3.60]" "0.842" "nonnorm" - "chol (median [IQR])" "315.50 [247.75, 417.00]" "303.50 [254.25, 377.00]" "0.544" "nonnorm" - "albumin (mean (sd))" "3.52 (0.44)" "3.52 (0.40)" "0.874" "" - "copper (median [IQR])" "73.00 [40.00, 121.00]" "73.00 [43.00, 139.00]" "0.717" "nonnorm" - "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" - "ast (mean (sd))" "120.21 (54.52)" "124.97 (58.93)" "0.460" "" - "trig (median [IQR])" "106.00 [84.50, 146.00]" "113.00 [84.50, 155.00]" "0.370" "nonnorm" - "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" - "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" - "stage (%)" "" "" "0.205" "exact" - " 1" "12 (7.6)" "4 (2.6)" "" "" - " 2" "35 (22.2)" "32 (20.8)" "" "" - " 3" "56 (35.4)" "64 (41.6)" "" "" - " 4" "55 (34.8)" "54 (35.1)" "" "" + "" "1" + "n" "158" + "time (mean (sd))" "2015.62 (1094.12)" + "status (%)" "" + " 0" "83 (52.5)" + " 1" "10 (6.3)" + " 2" "65 (41.1)" + "age (mean (sd))" "51.42 (11.01)" + "sex = f (%)" "137 (86.7)" + "ascites = 1 (%)" "14 (8.9)" + "hepato = 1 (%)" "73 (46.2)" + "spiders = 1 (%)" "45 (28.5)" + "edema (%)" "" + " 0" "132 (83.5)" + " 0.5" "16 (10.1)" + " 1" "10 (6.3)" + "bili (median [IQR])" "1.40 [0.80, 3.20]" + "chol (median [IQR])" "315.50 [247.75, 417.00]" + "albumin (mean (sd))" "3.52 (0.44)" + "copper (median [IQR])" "73.00 [40.00, 121.00]" + "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" + "ast (mean (sd))" "120.21 (54.52)" + "trig (median [IQR])" "106.00 [84.50, 146.00]" + "platelet (mean (sd))" "258.75 (100.32)" + "protime (mean (sd))" "10.65 (0.85)" + "stage (%)" "" + " 1" "12 (7.6)" + " 2" "35 (22.2)" + " 3" "56 (35.4)" + " 4" "55 (34.8)" + "Stratified by trt" + "" "2" "p" "test" + "n" "154" "" "" + "time (mean (sd))" "1996.86 (1155.93)" "0.883" "" + "status (%)" "" "0.884" "exact" + " 0" "85 (55.2)" "" "" + " 1" "9 (5.8)" "" "" + " 2" "60 (39.0)" "" "" + "age (mean (sd))" "48.58 (9.96)" "0.018" "" + "sex = f (%)" "139 (90.3)" "0.421" "" + "ascites = 1 (%)" "10 (6.5)" "0.567" "" + "hepato = 1 (%)" "87 (56.5)" "0.088" "" + "spiders = 1 (%)" "45 (29.2)" "0.985" "" + "edema (%)" "" "0.877" "" + " 0" "131 (85.1)" "" "" + " 0.5" "13 (8.4)" "" "" + " 1" "10 (6.5)" "" "" + "bili (median [IQR])" "1.30 [0.72, 3.60]" "0.842" "nonnorm" + "chol (median [IQR])" "303.50 [254.25, 377.00]" "0.544" "nonnorm" + "albumin (mean (sd))" "3.52 (0.40)" "0.874" "" + "copper (median [IQR])" "73.00 [43.00, 139.00]" "0.717" "nonnorm" + "alk.phos (median [IQR])" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" + "ast (mean (sd))" "124.97 (58.93)" "0.460" "" + "trig (median [IQR])" "113.00 [84.50, 155.00]" "0.370" "nonnorm" + "platelet (mean (sd))" "265.20 (90.73)" "0.555" "" + "protime (mean (sd))" "10.80 (1.14)" "0.197" "" + "stage (%)" "" "0.205" "exact" + " 1" "4 (2.6)" "" "" + " 2" "32 (20.8)" "" "" + " 3" "64 (41.6)" "" "" + " 4" "54 (35.1)" "" "" . Stratified by trt 1 2 p test n 158 154 @@ -442,25 +660,45 @@ Unit tests for the CreateTableOne function : ........... St 3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4) 4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8) . Stratified by trt:sex - 1:m 2:m 1:f 2:f p test - n 21 15 137 139 - status (%) 0.03270 - 0 4 (19.048) 7 (46.667) 79 ( 57.664) 78 ( 56.115) - 1 3 (14.286) 0 ( 0.000) 7 ( 5.109) 9 ( 6.475) - 2 14 (66.667) 8 (53.333) 51 ( 37.226) 52 ( 37.410) - sex = f (%) 0 ( 0.000) 0 ( 0.000) 137 (100.000) 139 (100.000) <0.00001 - ascites = 1 (%) 1 ( 4.762) 2 (13.333) 13 ( 9.489) 8 ( 5.755) 0.51569 - hepato = 1 (%) 12 (57.143) 9 (60.000) 61 ( 44.526) 78 ( 56.115) 0.20806 - spiders = 1 (%) 3 (14.286) 1 ( 6.667) 42 ( 30.657) 44 ( 31.655) 0.08899 - edema (%) 0.90584 - 0 17 (80.952) 12 (80.000) 115 ( 83.942) 119 ( 85.612) - 0.5 3 (14.286) 1 ( 6.667) 13 ( 9.489) 12 ( 8.633) - 1 1 ( 4.762) 2 (13.333) 9 ( 6.569) 8 ( 5.755) - stage (%) 0.64630 - 1 2 ( 9.524) 1 ( 6.667) 10 ( 7.299) 3 ( 2.158) - 2 4 (19.048) 2 (13.333) 31 ( 22.628) 30 ( 21.583) - 3 7 (33.333) 5 (33.333) 49 ( 35.766) 59 ( 42.446) - 4 8 (38.095) 7 (46.667) 47 ( 34.307) 47 ( 33.813) + 1:m 2:m 1:f 2:f + n 21 15 137 139 + status (%) + 0 4 (19.048) 7 (46.667) 79 ( 57.664) 78 ( 56.115) + 1 3 (14.286) 0 ( 0.000) 7 ( 5.109) 9 ( 6.475) + 2 14 (66.667) 8 (53.333) 51 ( 37.226) 52 ( 37.410) + sex = f (%) 0 ( 0.000) 0 ( 0.000) 137 (100.000) 139 (100.000) + ascites = 1 (%) 1 ( 4.762) 2 (13.333) 13 ( 9.489) 8 ( 5.755) + hepato = 1 (%) 12 (57.143) 9 (60.000) 61 ( 44.526) 78 ( 56.115) + spiders = 1 (%) 3 (14.286) 1 ( 6.667) 42 ( 30.657) 44 ( 31.655) + edema (%) + 0 17 (80.952) 12 (80.000) 115 ( 83.942) 119 ( 85.612) + 0.5 3 (14.286) 1 ( 6.667) 13 ( 9.489) 12 ( 8.633) + 1 1 ( 4.762) 2 (13.333) 9 ( 6.569) 8 ( 5.755) + stage (%) + 1 2 ( 9.524) 1 ( 6.667) 10 ( 7.299) 3 ( 2.158) + 2 4 (19.048) 2 (13.333) 31 ( 22.628) 30 ( 21.583) + 3 7 (33.333) 5 (33.333) 49 ( 35.766) 59 ( 42.446) + 4 8 (38.095) 7 (46.667) 47 ( 34.307) 47 ( 33.813) + Stratified by trt:sex + p test + n + status (%) 0.03270 + 0 + 1 + 2 + sex = f (%) <0.00001 + ascites = 1 (%) 0.51569 + hepato = 1 (%) 0.20806 + spiders = 1 (%) 0.08899 + edema (%) 0.90584 + 0 + 0.5 + 1 + stage (%) 0.64630 + 1 + 2 + 3 + 4 . Stratified by trt:sex 1:m 2:m 1:f 2:f n 21 15 137 139 @@ -672,19 +910,33 @@ Unit tests for the CreateTableOne function : ........... St platelet (mean (sd)) 257.02 (98.33) protime (mean (sd)) 10.73 (1.02) . Stratified by trt:sex - 1:m 2:m 1:f 2:f p test - n 21 15 137 139 - time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 - age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 - bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 - chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 - copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 - trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 - platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 + 1:m 2:m 1:f + n 21 15 137 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) + Stratified by trt:sex + 2:f p test + n 139 + time (mean (sd)) 1979.65 (1127.52) 0.730 + age (mean (sd)) 47.66 (9.54) <0.001 + bili (mean (sd)) 3.75 (5.50) 0.394 + chol (mean (sd)) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.53 (0.39) 0.585 + copper (mean (sd)) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 126.30 (60.27) 0.598 + trig (mean (sd)) 126.38 (60.22) 0.370 + platelet (mean (sd)) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.75 (1.15) 0.137 . Stratified by trt 1 2 p test n 158 154 @@ -714,33 +966,61 @@ Unit tests for the CreateTableOne function : ........... St platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + 1 2 + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) + Stratified by trt + p test + n + time (mean (sd)) 0.883 + age (mean (sd)) 0.018 + bili (median [IQR]) 0.842 nonnorm + chol (median [IQR]) 0.544 nonnorm + albumin (mean (sd)) 0.874 + copper (median [IQR]) 0.717 nonnorm + alk.phos (median [IQR]) 0.812 nonnorm + ast (mean (sd)) 0.460 + trig (median [IQR]) 0.370 nonnorm + platelet (mean (sd)) 0.555 + protime (mean (sd)) 0.197 . Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm - chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm - alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + 1 + n 158 + time (mean (sd)) 2015.62 (1094.12) + age (mean (sd)) 51.42 (11.01) + bili (median [range]) 1.40 [0.30, 20.00] + chol (median [range]) 315.50 [127.00, 1712.00] + albumin (mean (sd)) 3.52 (0.44) + copper (median [range]) 73.00 [9.00, 588.00] + alk.phos (median [range]) 1214.50 [369.00, 11552.00] + ast (mean (sd)) 120.21 (54.52) + trig (median [range]) 106.00 [33.00, 598.00] + platelet (mean (sd)) 258.75 (100.32) + protime (mean (sd)) 10.65 (0.85) + Stratified by trt + 2 p test + n 154 + time (mean (sd)) 1996.86 (1155.93) 0.883 + age (mean (sd)) 48.58 (9.96) 0.018 + bili (median [range]) 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 124.97 (58.93) 0.460 + trig (median [range]) 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.80 (1.14) 0.197 . Stratified by trt 1 2 p test n 158 154 @@ -785,6 +1065,7 @@ Unit tests for the CreateTableOne function : ........... St "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" . Unit tests for the modules : ........ +Tests for functions for standardized mean differences : ...................... Unit tests for svy* user functions : .... Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -813,21 +1094,37 @@ Unit tests for svy* user functions : .... Stratified by E C1 = 1 (%) 150.0 (33.3) C2 (mean (sd)) 0.47 (0.50) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 3:1 p test - n 100.01 100.00 100.00 50.00 50.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 (74.0) 37.0 (74.0) 37.0 (74.0) <0.001 - C1 = 1 (%) 0.0 (0.0) 0.0 (0.0) 0.0 (0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 - C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 + 1:0 2:0 3:0 1:1 + n 100.01 100.00 100.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 (74.0) + C1 = 1 (%) 0.0 (0.0) 0.0 (0.0) 0.0 (0.0) 50.0 (100.0) + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) + Stratified by E:C1 + 2:1 3:1 p test + n 50.00 50.00 + E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 + Y = 1 (%) 37.0 (74.0) 37.0 (74.0) <0.001 + C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 + C2 (mean (sd)) 0.20 (0.40) 0.20 (0.40) <0.001 . Stratified by E - 1 2 3 p test - n 150.0120 150.0030 150.0000 - E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) <0.00001 - C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) 1.00000 - Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 0.99982 - C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.00000 - C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) 1.00000 + 1 2 3 p + n 150.0120 150.0030 150.0000 + E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) <0.00001 + C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) 1.00000 + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 0.99982 + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.00000 + C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) 1.00000 + Stratified by E + test + n + E (mean (sd)) + C (mean (sd)) + Y = 1 (%) + C1 = 1 (%) + C2 (mean (sd)) . Stratified by E 1 2 3 n 150.01 150.00 150.00 @@ -837,21 +1134,37 @@ Unit tests for svy* user functions : .... Stratified by E C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) . Stratified by E - 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) NA exact - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + 1 2 3 p + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) NA + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + Stratified by E + test + n + E (mean (sd)) + C (median [IQR]) nonnorm + Y = 1 (%) exact + C1 = 1 (%) + C2 (mean (sd)) . Stratified by E - 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) + Stratified by E + p test + n + E (mean (sd)) <0.001 + C (median [range]) 1.000 nonnorm + Y = 1 (%) 1.000 + C1 = 1 (%) 1.000 + C2 (mean (sd)) 1.000 . Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -861,23 +1174,41 @@ Unit tests for svy* user functions : .... Stratified by E C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.000 C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E - level 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm - Y (%) 0 90.7 (60.6) 91.0 (60.7) 91.0 (60.7) NA exact - 1 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) - C1 (%) 0 100.0 (66.7) 100.0 (66.7) 100.0 (66.7) 1.000 - 1 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + level 1 2 + n 150.01 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] + Y (%) 0 90.7 (60.6) 91.0 (60.7) + 1 59.0 (39.4) 59.0 (39.3) + C1 (%) 0 100.0 (66.7) 100.0 (66.7) + 1 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) + Stratified by E + 3 p test + n 150.00 + E (mean (sd)) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 1.000 nonnorm + Y (%) 91.0 (60.7) NA exact + 59.0 (39.3) + C1 (%) 100.0 (66.7) 1.000 + 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 1.000 . "Stratified by E" - "" "1" "2" "3" "p" "test" - "n" "150.01" "150.00" "150.00" "" "" - "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" "3.00 (0.00)" "<0.001" "" - "C (median [IQR])" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "1.000" "nonnorm" - "Y = 1 (%)" "59.001 (39.406)" "59.001 (39.333)" "59.000 (39.333)" "NA" "exact" - "C1 = 1 (%)" "50.000 (33.331)" "50.000 (33.333)" "50.000 (33.333)" "1.000" "" - "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" "0.47 (0.50)" "1.000" "" + "" "1" "2" + "n" "150.01" "150.00" + "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" + "C (median [IQR])" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" + "Y = 1 (%)" "59.001 (39.406)" "59.001 (39.333)" + "C1 = 1 (%)" "50.000 (33.331)" "50.000 (33.333)" + "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" + "Stratified by E" + "" "3" "p" "test" + "n" "150.00" "" "" + "E (mean (sd))" "3.00 (0.00)" "<0.001" "" + "C (median [IQR])" "2.00 [1.00, 3.00]" "1.000" "nonnorm" + "Y = 1 (%)" "59.000 (39.333)" "NA" "exact" + "C1 = 1 (%)" "50.000 (33.333)" "1.000" "" + "C2 (mean (sd))" "0.47 (0.50)" "1.000" "" . Stratified by E 1 2 3 p test n 150.0 150.0 150.0 @@ -897,25 +1228,40 @@ Unit tests for svy* user functions : .... Stratified by E NA 0.3 ( 0.1) C1 = 1 (%) 150.0 (33.3) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 3:1 p test - n 100.0 100.0 100.0 50.0 50.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 + 1:0 2:0 3:0 1:1 2:1 + n 100.0 100.0 100.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) + Stratified by E:C1 + 3:1 p test + n 50.0 + Y = 1 (%) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 50.0 (100.0) <0.001 . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 - n 100.012 100.003 100.000 50.000 50.000 - Y = 1 (%) 22.001 (22.062) 22.001 (22.000) 22.000 (22.000) 37.000 ( 74.000) 37.000 ( 74.000) - C1 = 1 (%) 0.000 ( 0.000) 0.000 ( 0.000) 0.000 ( 0.000) 50.000 (100.000) 50.000 (100.000) + 1:0 2:0 3:0 + n 100.012 100.003 100.000 + Y = 1 (%) 22.001 (22.062) 22.001 (22.000) 22.000 (22.000) + C1 = 1 (%) 0.000 ( 0.000) 0.000 ( 0.000) 0.000 ( 0.000) + Stratified by E:C1 + 1:1 2:1 3:1 p + n 50.000 50.000 50.000 + Y = 1 (%) 37.000 ( 74.000) 37.000 ( 74.000) 37.000 ( 74.000) <0.00001 + C1 = 1 (%) 50.000 (100.000) 50.000 (100.000) 50.000 (100.000) <0.00001 Stratified by E:C1 - 3:1 p test - n 50.000 - Y = 1 (%) 37.000 ( 74.000) <0.00001 - C1 = 1 (%) 50.000 (100.000) <0.00001 + test + n + Y = 1 (%) + C1 = 1 (%) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 3:1 - n 100.0 100.0 100.0 50.0 50.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) + 1:0 2:0 3:0 1:1 2:1 + n 100.0 100.0 100.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) + Stratified by E:C1 + 3:1 + n 50.0 + Y = 1 (%) 37.0 ( 74.0) + C1 = 1 (%) 50.0 (100.0) . Stratified by E 1 2 3 p test n 150.012 150.003 150.000 @@ -949,10 +1295,15 @@ Unit tests for svy* user functions : .... Stratified by E Y = 1 % (freq) 39.4 (59.0) 39.3 (59.0) 39.3 (59.0) 1.000 C1 = 1 % (freq) 33.3 (50.0) 33.3 (50.0) 33.3 (50.0) 1.000 . Stratified by E - 1 2 3 p test - n 150.0 150.0 150.0 - Y = 0/1 (%) 90.7/59.0 (60.6/39.4) 91.0/59.0 (60.7/39.3) 91.0/59.0 (60.7/39.3) 1.000 - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + 1 2 + n 150.0 150.0 + Y = 0/1 (%) 90.7/59.0 (60.6/39.4) 91.0/59.0 (60.7/39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) + Stratified by E + 3 p test + n 150.0 + Y = 0/1 (%) 91.0/59.0 (60.7/39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 1.000 . "Stratified by E" "" "level" "1" "2" "3" "p" "test" "n" "" "150.0" "150.0" "150.0" "" "" @@ -973,11 +1324,17 @@ Unit tests for svy* user functions : .... Stratified by E C (mean (sd)) 2.13 (0.88) C2 (mean (sd)) 0.47 (0.50) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 3:1 p test - n 100.01 100.00 100.00 50.00 50.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 - C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 + 1:0 2:0 3:0 1:1 2:1 + n 100.01 100.00 100.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) + Stratified by E:C1 + 3:1 p test + n 50.00 + E (mean (sd)) 3.00 (0.00) <0.001 + C (mean (sd)) 3.20 (0.40) <0.001 + C2 (mean (sd)) 0.20 (0.40) <0.001 . Stratified by E 1 2 3 p test n 150.012 150.003 150.000 @@ -991,17 +1348,29 @@ Unit tests for svy* user functions : .... Stratified by E C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) . Stratified by E - 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + 1 2 3 p + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + Stratified by E + test + n + E (mean (sd)) + C (median [IQR]) nonnorm + C2 (mean (sd)) . Stratified by E - 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) + Stratified by E + p test + n + E (mean (sd)) <0.001 + C (median [range]) 1.000 nonnorm + C2 (mean (sd)) 1.000 . Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -1117,50 +1486,95 @@ Unit tests for svy* user functions : .... Stratified by E (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 + 1 2 + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] + race (%) + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) + Stratified by RIAGENDR + p test + n + HI_CHOL (median [IQR]) 0.0092211 nonnorm + race (%) 0.0416288 + 1 + 2 + 3 + 4 + agecat (%) 0.0011757 + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) <0.0000001 . Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.189 (15.845) 20251367.389 (14.303) - 2 89315751.415 (66.187) 92486945.142 (65.319) - 3 15045455.461 (11.149) 17967228.319 (12.689) - 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) - agecat (%) 0.001 - (0,19] 29299546.109 (21.712) 28150760.544 (19.882) - (19,39] 40497613.070 (30.011) 40640361.534 (28.702) - (39,59] 41053579.409 (30.423) 42817044.014 (30.240) - (59,Inf] 24093815.335 (17.855) 29983725.904 (21.176) - RIAGENDR = 2 (%) 0.000 (0.000) 141591891.998 (100.000) <0.001 + 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 (14.303) + 2 89315751.415 (66.187) 92486945.142 (65.319) + 3 15045455.461 (11.149) 17967228.319 (12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 (19.882) + (19,39] 40497613.070 (30.011) 40640361.534 (28.702) + (39,59] 41053579.409 (30.423) 42817044.014 (30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 (21.176) + RIAGENDR = 2 (%) 0.000 (0.000) 141591891.998 (100.000) <0.001 + Stratified by RIAGENDR + test + n + HI_CHOL (mean (sd)) + race (%) + 1 + 2 + 3 + 4 + agecat (%) + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) .. Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 + 1 2 + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] + race (%) + 1 21381884.2 (15.8) 20251367.4 (14.3) + 2 89315751.4 (66.2) 92486945.1 (65.3) + 3 15045455.5 (11.1) 17967228.3 (12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) + (0,19] 29299546.1 (21.7) 28150760.5 (19.9) + (19,39] 40497613.1 (30.0) 40640361.5 (28.7) + (39,59] 41053579.4 (30.4) 42817044.0 (30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) + RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) + Stratified by RIAGENDR + p test + n + HI_CHOL (median [IQR]) 0.0092211 nonnorm + race (%) 0.0416288 + 1 + 2 + 3 + 4 + agecat (%) 0.0011757 + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) <0.0000001 . Unit tests for the survey-related modules : ................................................ diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R new file mode 100755 index 0000000..ae15dad --- /dev/null +++ b/tests/testthat/test-smdModules.R @@ -0,0 +1,274 @@ +################################################################################ +### Unit tests for the standardized mean difference modules +## Reference: http://adv-r.had.co.nz/Testing.html +## Created on: +## Author: Kazuki Yoshida +################################################################################ + +### Structure +## expectations within tests within context + + +### +### References +################################################################################ +## A unified approach to measuring the effect size between two groups using SAS® +## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf + + +### +### Prepare environment +################################################################################ +library(testthat) +library(survey) + + +### +### Actual tests +################################################################################ +context("Tests for functions for standardized mean differences") + + +### Old functions explicitly for 3 groups +## Standardize differences +StdDiffOld <- function(variable, group) { + ## For each group + means <- tapply(variable, group, mean) + vars <- tapply(variable, group, var) + + ## Calculate for all three possible pairs + g1g2 <- abs(means[1] - means[2]) / sqrt((vars[1] + vars[2]) / 2) + g2g3 <- abs(means[2] - means[3]) / sqrt((vars[2] + vars[3]) / 2) + g3g1 <- abs(means[3] - means[1]) / sqrt((vars[3] + vars[1]) / 2) + + ## 2vs1, 3vs1, then 3vs2 to be consistent with regression + out <- c(g1g2, g3g1, g2g3) + names(out) <- c("3vs2","3vs1","2vs1") + out +} + +svyStdDiffOld <- function(varName, groupName, design) { + + varFormula <- as.formula(paste("~", varName)) + groupFormula <- as.formula(paste("~", groupName)) + + means <- svyby(formula = varFormula, by = groupFormula, FUN = svymean, design = design)[,2] + vars <- svyby(formula = varFormula, by = groupFormula, FUN = svyvar, design = design)[,2] + + ## Calculate for all three possible pairs + g1g2 <- abs(means[1] - means[2]) / sqrt((vars[1] + vars[2]) / 2) + g2g3 <- abs(means[2] - means[3]) / sqrt((vars[2] + vars[3]) / 2) + g3g1 <- abs(means[3] - means[1]) / sqrt((vars[3] + vars[1]) / 2) + + ## 2vs1, 3vs1, then 3vs2 to be consistent with regression + out <- c(g1g2, g3g1, g2g3) + names(out) <- c("3vs2","3vs1","2vs1") + out +} + + +test_that("binary standardized difference is correct", { + + ## Prepare data + variable <- c(1,0,0,0,0, 1,1,0,0,0, 1,1,1,0,0) + group <- rep(1:3, each = 5) + + data1 <- data.frame(variable = variable, group = group, + weight = rep(0.5, 15)) + data1Svy <- svydesign(ids = ~ 1, data = data1, weights = ~ weight) + + ## Gold standard + props <- c(0.2, 0.4, 0.6) + vars <- c(0.2*0.8, 0.4*0.6, 0.6*0.4) + + g1g2 <- abs(props[1] - props[2]) / sqrt((vars[1] + vars[2]) / 2) + g2g3 <- abs(props[2] - props[3]) / sqrt((vars[2] + vars[3]) / 2) + g3g1 <- abs(props[3] - props[1]) / sqrt((vars[3] + vars[1]) / 2) + + + ## Expectations + ## Binary case + expect_equal(StdDiff(variable, group, binary = TRUE), + c(g1g2, g3g1, g2g3)) + ## Continuous case + expect_equal(StdDiff(variable, group, binary = FALSE), + as.vector(StdDiffOld(variable, group))) + + ## Weighted + ## Binary case + expect_equal(svyStdDiff("variable","group", design = data1Svy, binary = TRUE), + c(g1g2, g3g1, g2g3)) + ## Continuous case + expect_equal(svyStdDiff("variable","group", design = data1Svy, binary = FALSE), + as.vector(svyStdDiffOld("variable","group", design = data1Svy))) + + + ## Multiple variables + expect_equal(StdDiffs(data = data1, vars = c("variable","variable"), + groupVar = "group", binaryVars = "variable"), + list(c(g1g2, g3g1, g2g3), c(g1g2, g3g1, g2g3))) + + expect_equal(StdDiffs(data = data1, vars = c("variable","variable"), + groupVar = "group", binaryVars = NA), + list(as.vector(StdDiffOld(variable, group)), + as.vector(StdDiffOld(variable, group)))) + + expect_equal(svyStdDiffs(data = data1Svy, vars = c("variable","variable"), + groupVar = "group", binaryVars = "variable"), + list(c(g1g2, g3g1, g2g3), c(g1g2, g3g1, g2g3))) + + expect_equal(svyStdDiffs(data = data1Svy, vars = c("variable","variable"), + groupVar = "group", binaryVars = NA), + list(as.vector(svyStdDiffOld("variable","group", design = data1Svy)), + as.vector(svyStdDiffOld("variable","group", design = data1Svy)))) +}) + +test_that("Multinomial SMD is correct", { + + set.seed(102) + ## 4-category variable + probs <- c(0.1,0.3,0.5,0.2) + X <- rmultinom(n = 100, size = 1, prob = probs) + X <- as.vector(seq_along(probs) %*% X) + ## Three groups + group <- c(rep(1,20), rep(2,30), rep(3,50)) + + ## Drop first column to avoid dependent column + ## The result does not change if generalized inverse is used + dummyX <- dummies::dummy(X)[, -1, drop = FALSE] + + lstDummyX <- split(x = as.data.frame(dummyX), f = group, drop = FALSE) + + ## Means for each indicator + means <- lapply(lstDummyX, MultinomialMeans) + ## cov mat for each indicators + covs <- lapply(means, MultinomialVar) + + meanDiff1 <- means[[1]] - means[[2]] + meanDiff2 <- means[[1]] - means[[3]] + meanDiff3 <- means[[2]] - means[[3]] + + covMean1 <- (covs[[1]] + covs[[2]]) / 2 + covMean2 <- (covs[[1]] + covs[[3]]) / 2 + covMean3 <- (covs[[2]] + covs[[3]]) / 2 + + smd1 <- drop(sqrt(t(meanDiff1) %*% MASS::ginv(covMean1) %*% t(t(meanDiff1)))) + smd2 <- drop(sqrt(t(meanDiff2) %*% MASS::ginv(covMean2) %*% t(t(meanDiff2)))) + smd3 <- drop(sqrt(t(meanDiff3) %*% MASS::ginv(covMean3) %*% t(t(meanDiff3)))) + + ## Calculate using multi-category to SMD function + outSmd <- StdDiffMulti(variable = X, group = group) + + expect_equal(length(outSmd), 3) + expect_equal(outSmd, c(smd1,smd2,smd3)) + + + ## + ## Repeat for dummy variable matrix with all columns (k-1 independent) + dummyX <- dummies::dummy(X) + lstDummyX <- split(x = as.data.frame(dummyX), f = group, drop = FALSE) + ## Means for each indicator + means <- lapply(lstDummyX, MultinomialMeans) + ## cov mat for each indicators + covs <- lapply(means, MultinomialVar) + meanDiff1 <- means[[1]] - means[[2]] + meanDiff2 <- means[[1]] - means[[3]] + meanDiff3 <- means[[2]] - means[[3]] + covMean1 <- (covs[[1]] + covs[[2]]) / 2 + covMean2 <- (covs[[1]] + covs[[3]]) / 2 + covMean3 <- (covs[[2]] + covs[[3]]) / 2 + smd1 <- drop(sqrt(t(meanDiff1) %*% MASS::ginv(covMean1) %*% t(t(meanDiff1)))) + smd2 <- drop(sqrt(t(meanDiff2) %*% MASS::ginv(covMean2) %*% t(t(meanDiff2)))) + smd3 <- drop(sqrt(t(meanDiff3) %*% MASS::ginv(covMean3) %*% t(t(meanDiff3)))) + + expect_equal(outSmd, c(smd1,smd2,smd3)) + + + ## Check behavior with a binary variable + set.seed(102) + ## Binary variable + X <- rbinom(n = 100, size = 1, prob = 0.2) + group <- rep(c(0,1), c(20,80)) + + dummyX <- dummies::dummy(X)[, -1, drop = FALSE] + + lstDummyX <- split(x = as.data.frame(dummyX), f = group, drop = FALSE) + + ## Means for each indicator + means <- lapply(lstDummyX, MultinomialMeans) + ## cov mat for each indicators + covs <- lapply(means, MultinomialVar) + ## + meanDiff1 <- means[[1]] - means[[2]] + covMean1 <- (covs[[1]] + covs[[2]]) / 2 + + smd1 <- drop(sqrt(t(meanDiff1) %*% MASS::ginv(covMean1) %*% t(t(meanDiff1)))) + + ## Comparison to manual calculation + expect_equal(StdDiffMulti(variable = X, group = group), smd1) + ## Comparison to continuous version with binary support + expect_equal(StdDiffMulti(variable = X, group = group), + StdDiff(variable = X, group = group, binary = TRUE)) + + ## Check missing value handling (binary) + X[13] <- NA + ## within group values + means <- tapply(X, group, mean, na.rm = TRUE) + covs <- means * (1 - means) + ## Diff and cov mean + meanDiff1 <- means[[1]] - means[[2]] + covMean1 <- (covs[[1]] + covs[[2]]) / 2 + smd1 <- drop(sqrt(t(meanDiff1) %*% MASS::ginv(covMean1) %*% t(t(meanDiff1)))) + smd2 <- meanDiff1 / sqrt(covMean1) + + expect_equal(smd1, smd2) + + expect_equal(StdDiff(variable = X, group = group, binary = TRUE), smd1) + expect_equal(StdDiff(variable = X, group = group, binary = TRUE), smd2) + + expect_equal(StdDiffMulti(variable = X, group = group), + StdDiff(variable = X, group = group, binary = TRUE)) + + expect_equal(StdDiffMulti(variable = X, group = group), + StdDiff(variable = X, group = group, binary = TRUE)) + +}) + + +test_that("mutlinomial SMD for survey data is correct", { + + set.seed(102) + ## 4-category variable + probs <- c(0.1,0.3,0.5,0.2) + X <- rmultinom(n = 100, size = 1, prob = probs) + X <- as.vector(seq_along(probs) %*% X) + ## Three groups + group <- c(rep(1,20), rep(2,30), rep(3,50)) + + dat <- data.frame(X = X, group = group, weight = 1) + datSvy <- svydesign(ids = ~ 1, data = dat, weights = ~ weight) + + ## Check tables match with weight of 1 for everyone + tab1svytable <- svytable(~ group + X, design = datSvy) + tab1xtabs <- xtabs(~ group + X, data = dat) + expect_true(all(tab1svytable == tab1xtabs)) + + ## Check equality for equal weight case + expect_equal(svyStdDiffMulti("X", "group", datSvy), + StdDiffMulti(dat$X, group = dat$group)) + + ## Missing value is introduced + dat$X[13] <- NA + ## Recreate + datSvy <- svydesign(ids = ~ 1, data = dat, weights = ~ weight) + ## Tables again + tab1svytable <- svytable(~ group + X, design = datSvy) + tab1xtabs <- xtabs(~ group + X, data = dat) + + expect_true(all(tab1svytable == tab1xtabs)) + + + expect_equal(svyStdDiffMulti("X", "group", datSvy), + StdDiffMulti(dat$X, group = dat$group)) + +}) From 7cbda6d97724fdd186718fe89d35d05a46ed3f47 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 16:55:02 -0400 Subject: [PATCH 088/219] Add unit test for continuous SMD (failing due to ordering) --- tests/testthat/test-smdModules.R | 83 ++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index ae15dad..ac154b1 100755 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -29,6 +29,24 @@ library(survey) context("Tests for functions for standardized mean differences") +### Provide data +data(nhanes) +nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, + nest = TRUE, data = nhanes) +## ‘SDMVPSU’ Primary sampling units +## ‘SDMVSTRA’ Sampling strata +## ‘WTMEC2YR’ Sampling weights +## ‘HI_CHOL’ Numeric vector: 1 for total cholesterol over 240mg/dl, 0 +## under 240mg/dl +## ‘race’ 1=Hispanic, 2=non-Hispanic white, 3=non-Hispanic black, +## 4=other +## ‘agecat’ Age group ‘(0,19]’ ‘(19,39]’ ‘(39,59]’ ‘(59,Inf]’ +## ‘RIAGENDR’ Gender: 1=male, 2=female + +## Use HI_CHOL for continuous, RIAGENDR for binary, race and agecat as categorical + + + ### Old functions explicitly for 3 groups ## Standardize differences StdDiffOld <- function(variable, group) { @@ -67,6 +85,71 @@ svyStdDiffOld <- function(varName, groupName, design) { } +test_that("continuous standardized difference is correct (nhanes unweighted)", { + + ## Two group with only one contrast 1 vs 2 + means1 <- tapply(nhanes$HI_CHOL, nhanes$RIAGENDR, mean, na.rm = TRUE) + vars1 <- tapply(nhanes$HI_CHOL, nhanes$RIAGENDR, var, na.rm = TRUE) + meanDiffs1 <- (means1[1] - means1[2]) / sqrt((vars1[1] + vars1[2]) / 2) + names(meanDiffs1) <- NULL + + expect_equal(StdDiff(nhanes$HI_CHOL, nhanes$RIAGENDR), abs(meanDiffs1)) + + + ## Four groups with 6 contrasts + means2 <- tapply(nhanes$HI_CHOL, nhanes$race, mean, na.rm = TRUE) + vars2 <- tapply(nhanes$HI_CHOL, nhanes$race, var, na.rm = TRUE) + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(StdDiff(nhanes$HI_CHOL, nhanes$race), abs(meanDiffs2)) + ## Average across + expect_equal(mean(StdDiff(nhanes$HI_CHOL, nhanes$race)), + mean(abs(meanDiffs2))) + +}) + + +test_that("continuous standardized difference is correct (nhanes weighted)", { + + ## Two group + means1 <- svyby( ~ HI_CHOL, by = ~ RIAGENDR, design = nhanesSvy, FUN = svymean, na.rm = TRUE)[,2] + vars1 <- svyby( ~ HI_CHOL, by = ~ RIAGENDR, design = nhanesSvy, FUN = svyvar, na.rm = TRUE)[,2] + meanDiffs1 <- (means1[1] - means1[2]) / sqrt((vars1[1] + vars1[2]) / 2) + + expect_equal(svyStdDiff("HI_CHOL", "RIAGENDR", design = nhanesSvy), + abs(meanDiffs1)) + + + ## Four groups + means2 <- svyby( ~ HI_CHOL, by = ~ race, design = nhanesSvy, FUN = svymean, na.rm = TRUE)[,2] + vars2 <- svyby( ~ HI_CHOL, by = ~ race, design = nhanesSvy, FUN = svyvar, na.rm = TRUE)[,2] + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(svyStdDiff("HI_CHOL", "race", design = nhanesSvy), + abs(meanDiffs2)) + ## Average across + expect_equal(mean(svyStdDiff("HI_CHOL", "race", design = nhanesSvy)), + mean(abs(meanDiffs2))) + +}) + + test_that("binary standardized difference is correct", { ## Prepare data From 4eaec3e3f9494fb935c958afd471df4174cb8808 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 16:59:51 -0400 Subject: [PATCH 089/219] Change upper.tri to lower.tri to pick elements better With this in a four group setting, contrasts are ordered 1v2, 1v3, 1v4, 2v3, 2v4, and 3v4. order is column first, using the lower triangle allows 1 is fixed --- R/smdModules.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/smdModules.R b/R/smdModules.R index c9bdc69..45ea8b7 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -132,7 +132,7 @@ StdDiff <- function(variable, group, binary = FALSE, na.rm = TRUE) { out <- meanDiffs / sqrt(varMeans) - abs(out[upper.tri(out)]) + abs(out[lower.tri(out)]) } ### Categorical (including binary) standardizzed mean difference @@ -186,7 +186,7 @@ svyStdDiff <- function(varName, groupName, design, binary = FALSE, na.rm = TRUE) out <- meanDiffs / sqrt(varMeans) - abs(out[upper.tri(out)]) + abs(out[lower.tri(out)]) } From 9fa302b60e81bf49b4e9f020da141144a8e40c97 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 17:08:57 -0400 Subject: [PATCH 090/219] Add real data unit tests for continuous and binary SMD --- tests/testthat/test-smdModules.R | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index ac154b1..1ec41ad 100755 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -150,6 +150,73 @@ test_that("continuous standardized difference is correct (nhanes weighted)", { }) +test_that("binary standardized difference is correct (nhanes unweighted)", { + + ## Two group with only one contrast 1 vs 2 + means1 <- tapply(nhanes$HI_CHOL, nhanes$RIAGENDR, mean, na.rm = TRUE) + vars1 <- means1 * (1 - means1) + meanDiffs1 <- (means1[1] - means1[2]) / sqrt((vars1[1] + vars1[2]) / 2) + names(meanDiffs1) <- NULL + + expect_equal(StdDiff(nhanes$HI_CHOL, nhanes$RIAGENDR, binary = TRUE), + abs(meanDiffs1)) + + + ## Four groups with 6 contrasts + means2 <- tapply(nhanes$HI_CHOL, nhanes$race, mean, na.rm = TRUE) + vars2 <- means2 * (1 - means2) + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(StdDiff(nhanes$HI_CHOL, nhanes$race, binary = TRUE), + abs(meanDiffs2)) + ## Average across + expect_equal(mean(StdDiff(nhanes$HI_CHOL, nhanes$race, binary = TRUE)), + mean(abs(meanDiffs2))) + +}) + + +test_that("binary standardized difference is correct (nhanes weighted)", { + + ## Two group + means1 <- svyby( ~ HI_CHOL, by = ~ RIAGENDR, design = nhanesSvy, FUN = svymean, na.rm = TRUE)[,2] + vars1 <- means1 * (1 - means1) + meanDiffs1 <- (means1[1] - means1[2]) / sqrt((vars1[1] + vars1[2]) / 2) + + expect_equal(svyStdDiff("HI_CHOL", "RIAGENDR", design = nhanesSvy, binary = TRUE), + abs(meanDiffs1)) + + + ## Four groups + means2 <- svyby( ~ HI_CHOL, by = ~ race, design = nhanesSvy, FUN = svymean, na.rm = TRUE)[,2] + vars2 <- means2 * (1 - means2) + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(svyStdDiff("HI_CHOL", "race", design = nhanesSvy, binary = TRUE), + abs(meanDiffs2)) + ## Average across + expect_equal(mean(svyStdDiff("HI_CHOL", "race", design = nhanesSvy, binary = TRUE)), + mean(abs(meanDiffs2))) + +}) + + test_that("binary standardized difference is correct", { ## Prepare data From 18880f6f6651c4aa7547bb2d9e5a9d665d0760ca Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 19:13:01 -0400 Subject: [PATCH 091/219] Add unit tests for categorical variables (failing) --- tests/testthat/test-smdModules.R | 166 +++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) mode change 100755 => 100644 tests/testthat/test-smdModules.R diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R old mode 100755 new mode 100644 index 1ec41ad..c5e1ef1 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -217,6 +217,172 @@ test_that("binary standardized difference is correct (nhanes weighted)", { }) +test_that("multinomal helpers are correct", { + + means <- c(0.310336708264657, 0.224393689663292, 0.234283023310572, 0.230986578761479) + covs <- MultinomialVar(means) + + ## Expectations + ## Diagonal p(1-p) + expect_equal(diag(covs), means * (1 - means)) + ## Off diagonal -1 * p_i * p_j + expect_equal(covs[1,2], -1 * means[1] * means[2]) + expect_equal(covs[1,3], -1 * means[1] * means[3]) + expect_equal(covs[1,4], -1 * means[1] * means[4]) + expect_equal(covs[2,3], -1 * means[2] * means[3]) + expect_equal(covs[2,4], -1 * means[2] * means[4]) + expect_equal(covs[3,4], -1 * means[3] * means[4]) + +}) + + +test_that("categorical standardized difference is correct (nhanes unweighted)", { + + ## Four groups with 6 contrasts + means2 <- tapply(nhanes$HI_CHOL, nhanes$race, mean, na.rm = TRUE) + vars2 <- means2 * (1 - means2) + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(StdDiffMulti(nhanes$HI_CHOL, nhanes$race), + abs(meanDiffs2)) + ## Average across + expect_equal(mean(StdDiffMulti(nhanes$HI_CHOL, nhanes$race)), + mean(abs(meanDiffs2))) + + + ## Two group with only one contrast 1 vs 2 + strataByLevels1 <- xtabs( ~ RIAGENDR + agecat, data = nhanes) + ## drop first column after calculating proportion + propTable1 <- prop.table(strataByLevels1, margin = 1)[, -1, drop = FALSE] + meanDiffs1 <- propTable1[1,] - propTable1[2,] + covMean1 <- (MultinomialVar(propTable1[1,]) + MultinomialVar(propTable1[2,])) / 2 + + ## R is not strict about transposition + expect_equal(meanDiffs1 %*% MASS::ginv(covMean1) %*% meanDiffs1, + t(meanDiffs1) %*% MASS::ginv(covMean1) %*% t(t(meanDiffs1))) + + ## Test actual functions + expect_equal(StdDiffMulti(nhanes$agecat, nhanes$RIAGENDR), + sqrt(drop(t(meanDiffs1) %*% MASS::ginv(covMean1) %*% t(t(meanDiffs1))))) + + + ## Four groups with 6 contrasts + strataByLevels2 <- xtabs( ~ race + agecat, data = nhanes) + propTable2 <- prop.table(strataByLevels2, margin = 1)[, -1, drop = FALSE] + meanDiffs2 <- list(propTable2[1,] - propTable2[2,], + propTable2[1,] - propTable2[3,], + propTable2[1,] - propTable2[4,], + propTable2[2,] - propTable2[3,], + propTable2[2,] - propTable2[4,], + propTable2[3,] - propTable2[4,]) + + covMean2 <- + list((MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2) + + ## These should match in length. + expect_equal(length(meanDiffs2), length(covMean2)) + + smds <- unlist(lapply(seq_along(meanDiffs2), function(i) { + + sqrt(drop(t(meanDiffs2[[i]]) %*% MASS::ginv(covMean2[[i]]) %*% t(t(meanDiffs2[[i]])))) + })) + + + ## Individual numbers + expect_equal(StdDiffMulti(nhanes$agecat, nhanes$race), + smds) + ## Average across + expect_equal(mean(StdDiffMulti(nhanes$agecat, nhanes$race)), + mean(smds)) + +}) + + +test_that("categorical standardized difference is correct (nhanes weighted)", { + + ## Binary four groups + means2 <- svyby( ~ HI_CHOL, by = ~ race, design = nhanesSvy, FUN = svymean, na.rm = TRUE)[,2] + vars2 <- means2 * (1 - means2) + meanDiffs2 <- + c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + names(meanDiffs2) <- NULL + + ## Individual numbers + expect_equal(svyStdDiffMulti("HI_CHOL", "race", design = nhanesSvy), + abs(meanDiffs2)) + ## Average across + expect_equal(mean(svyStdDiffMulti("HI_CHOL", "race", design = nhanesSvy)), + mean(abs(meanDiffs2))) + + + ## Two group with only one contrast 1 vs 2 + strataByLevels1 <- svytable( ~ RIAGENDR + agecat, design = nhanesSvy) + propTable1 <- prop.table(strataByLevels1, margin = 1)[, -1, drop = FALSE] + meanDiffs1 <- propTable1[1,] - propTable1[2,] + covMean1 <- (MultinomialVar(propTable1[1,]) + MultinomialVar(propTable1[2,])) / 2 + + ## Test actual functions + expect_equal(svyStdDiffMulti("agecat", "RIAGENDR", design = nhanesSvy), + sqrt(drop(t(meanDiffs1) %*% MASS::ginv(covMean1) %*% t(t(meanDiffs1))))) + + + ## Four groups with 6 contrasts + strataByLevels2 <- svytable( ~ race + agecat, design = nhanesSvy) + propTable2 <- prop.table(strataByLevels2, margin = 1)[, -1, drop = FALSE] + meanDiffs2 <- list(propTable2[1,] - propTable2[2,], + propTable2[1,] - propTable2[3,], + propTable2[1,] - propTable2[4,], + propTable2[2,] - propTable2[3,], + propTable2[2,] - propTable2[4,], + propTable2[3,] - propTable2[4,]) + + covMean2 <- + list((MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2) + + ## These should match in length. + expect_equal(length(meanDiffs2), length(covMean2)) + + smds <- unlist(lapply(seq_along(meanDiffs2), function(i) { + + sqrt(drop(t(meanDiffs2[[i]]) %*% MASS::ginv(covMean2[[i]]) %*% t(t(meanDiffs2[[i]])))) + })) + + ## Individual numbers + expect_equal(StdDiffMulti(nhanes$agecat, nhanes$race), + smds) + ## Average across + expect_equal(mean(StdDiffMulti(nhanes$agecat, nhanes$race)), + mean(smds)) + +}) + + +### Older tests with simpler data +################################################################################ + test_that("binary standardized difference is correct", { ## Prepare data From 178ea36c770bd5bd8f8c0da9ab97dfe3a3e5e910 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 19:13:28 -0400 Subject: [PATCH 092/219] Avoid sqrt() within nested for loop; sqrt() on final result --- R/smdModules.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/smdModules.R b/R/smdModules.R index 45ea8b7..d7a223c 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -63,7 +63,7 @@ StdDiffFromLstMeans <- function(lstMeans) { }) ## Initialize a numeric vector object for capturing values - smds <- vector(mode = "numeric") + sqSmds <- vector(mode = "numeric") ## Add upper triangle elements (i < j) to output list for (i in seq_along(lstMeans)) { @@ -78,11 +78,12 @@ StdDiffFromLstMeans <- function(lstMeans) { t(t(lstMeanDiffs[[i]][[j]])) ## Add sqrt of MD to output ## Not efficient; room for improvement - smds <- c(smds, sqrt(sqMahaDist)) + sqSmds <- c(sqSmds, sqMahaDist) } } } - smds + ## We want it on the original scale + sqrt(sqSmds) } From 21213e11f81a25fd8587df66e6f9166fc6cf08ee Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 19:26:11 -0400 Subject: [PATCH 093/219] Fix errors in unit tests for categorical SMD function testing --- tests/testthat/test-smdModules.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index c5e1ef1..bc0fde6 100644 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -286,11 +286,11 @@ test_that("categorical standardized difference is correct (nhanes unweighted)", covMean2 <- list((MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2) + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[3,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[4,])) / 2, + (MultinomialVar(propTable2[2,]) + MultinomialVar(propTable2[3,])) / 2, + (MultinomialVar(propTable2[2,]) + MultinomialVar(propTable2[4,])) / 2, + (MultinomialVar(propTable2[3,]) + MultinomialVar(propTable2[4,])) / 2) ## These should match in length. expect_equal(length(meanDiffs2), length(covMean2)) @@ -356,11 +356,11 @@ test_that("categorical standardized difference is correct (nhanes weighted)", { covMean2 <- list((MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2, - (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[2,])) / 2) + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[3,])) / 2, + (MultinomialVar(propTable2[1,]) + MultinomialVar(propTable2[4,])) / 2, + (MultinomialVar(propTable2[2,]) + MultinomialVar(propTable2[3,])) / 2, + (MultinomialVar(propTable2[2,]) + MultinomialVar(propTable2[4,])) / 2, + (MultinomialVar(propTable2[3,]) + MultinomialVar(propTable2[4,])) / 2) ## These should match in length. expect_equal(length(meanDiffs2), length(covMean2)) @@ -371,10 +371,10 @@ test_that("categorical standardized difference is correct (nhanes weighted)", { })) ## Individual numbers - expect_equal(StdDiffMulti(nhanes$agecat, nhanes$race), + expect_equal(svyStdDiffMulti("agecat", "race", design = nhanesSvy), smds) ## Average across - expect_equal(mean(StdDiffMulti(nhanes$agecat, nhanes$race)), + expect_equal(mean(svyStdDiffMulti("agecat", "race", design = nhanesSvy)), mean(smds)) }) From f48082c203f87b89c010ee0b5cf86b60bc79b647 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 19:39:08 -0400 Subject: [PATCH 094/219] Add MASS to import; drop special characters; modify DESCRIPTION --- DESCRIPTION | 3 ++- NAMESPACE | 1 + R/smdModules.R | 15 ++++++--------- R/tableone-package.R | 2 +- tests/testthat/test-smdModules.R | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b59984b..35bf23b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,7 +5,7 @@ Version: 0.7.0 Date: 2015-07-24 Author: Kazuki Yoshida, Justin Bohn. Maintainer: Kazuki Yoshida -Description: tableone creates "Table 1", i.e., description of baseline +Description: Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. It provides functions to create such summaries for continuous and categorical variables, optionally with subgroup comparisons. tableone @@ -15,6 +15,7 @@ Description: tableone creates "Table 1", i.e., description of baseline License: GPL-2 Imports: survey, + MASS, e1071, gmodels Suggests: diff --git a/NAMESPACE b/NAMESPACE index 9ce0f65..582141b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(ShowRegTable) export(svyCreateCatTable) export(svyCreateContTable) export(svyCreateTableOne) +import(MASS) import(e1071) import(gmodels) import(survey) diff --git a/R/smdModules.R b/R/smdModules.R index d7a223c..66949be 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -8,21 +8,16 @@ ### ### References ################################################################################ -## A unified approach to measuring the effect size between two groups using SAS® +## A unified approach to measuring the effect size between two groups using SAS ## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf +## R multinomial distribution variance +## http://stackoverflow.com/questions/19960605/r-multinomial-distribution-variance ### -### Helpers common to both +### Helpers common to both unweighted and weighed functions ################################################################################ -## Multinomial standardized differences -## A unified approach to measuring the effect size between two groups using SAS® -## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf -## R multinomial distribution variance -## http://stackoverflow.com/questions/19960605/r-multinomial-distribution-variance -## Receives dummie variable matrix with no redundant column - ## Dummy matrix to means (proportions for each dummy) MultinomialMeans <- function(dummyMat, na.rm = TRUE) { colMeans(dummyMat, na.rm = na.rm) @@ -72,6 +67,8 @@ StdDiffFromLstMeans <- function(lstMeans) { ## For upper triangle elements only ## Squared Mahalanobis distance ## meanDiffs^T covMean^-1 meanDiffs + ## Generalized inverse for protection against singularity + ## Reduces to true inverse if non-singular sqMahaDist <- t(lstMeanDiffs[[i]][[j]]) %*% MASS::ginv(lstCovMeans[[i]][[j]]) %*% diff --git a/R/tableone-package.R b/R/tableone-package.R index 03e9753..b3f2379 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -5,7 +5,7 @@ ##' @name tableone-package ##' @aliases tableone-package tableone ##' @docType package -##' @import survey e1071 gmodels +##' @import survey MASS e1071 gmodels ##' @note Special Thanks: ##' ##' Ian Fellows for developing the Deducer package, which this package is based on. diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index bc0fde6..ee154a8 100644 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -12,7 +12,7 @@ ### ### References ################################################################################ -## A unified approach to measuring the effect size between two groups using SAS® +## A unified approach to measuring the effect size between two groups using SAS ## http://support.sas.com/resources/papers/proceedings12/335-2012.pdf From 4794deed1ef74ecc78f800112ed9bc491b278057 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 21:57:41 -0400 Subject: [PATCH 095/219] Factor out formatting loop for categorical variables --- R/modules.R | 174 ++++++++++++++++++++++++++++++++++++++++++ R/print.CatTable.R | 160 +++----------------------------------- R/print.svyCatTable.R | 159 +++----------------------------------- 3 files changed, 193 insertions(+), 300 deletions(-) diff --git a/R/modules.R b/R/modules.R index 40b61f8..ba6f68c 100644 --- a/R/modules.R +++ b/R/modules.R @@ -400,6 +400,180 @@ ModuleRemoveSpaces <- function(mat, noSpaces) { mat } +## Module to loop over variables within a stratum formatting categorical variables +ModuleCatFormatVariables <- function(lstVars, varsToFormat, fmt, level, cramVars, showAllLevels) { + + ## Loop over variables within a stratum + ## Each list element is a data frame summarizing levels + sapply(X = seq_along(lstVars), + FUN = function(i) { + + ## Extract the data frame (list element) + DF <- lstVars[[i]] + + ## Extract the variable name + varName <- names(lstVars)[i] + + ## Check number of rows (levels) + nRow <- nrow(DF) + + ## Add a variable name to the left as a character vector + DF <- cbind(var = rep(varName, nRow), DF) + + ## Format percent and cum.percent as strings + DF[varsToFormat] <- lapply(X = DF[varsToFormat], + FUN = sprintf, + fmt = fmt) + + ## Make all variables strings (if freq is an integer, direct convert is ok) + DF[] <- lapply(X = DF, FUN = as.character) + + ## Add first row indicator column + DF$firstRowInd <- "" + ## Add crammed row indicator column + DF$crammedRowInd <- "" + + + ## Format based on the number of levels + if (!showAllLevels & nRow == 1) { + ## If showAllLevels is FALSE AND there are only ONE levels, + ## change variable name to "var = level" + DF$var <- with(DF, paste0(var, " = ", level)) + + } else if (!showAllLevels & nRow == 2) { + ## If showAllLevels is FALSE AND there are only TWO levels, + ## cram two levels in one row if requested + if (unique(DF$var) %in% cramVars) { + ## If cramVars includes var, cram into one line + ## Cram two freq and count with / in between + DF$freq <- paste0(DF$freq, collapse = "/") + DF$percent <- paste0(DF$percent, collapse = "/") + ## change variable name, and delete the first level. + DF$var <- paste0(DF$var, " = ", + paste0(DF$level, collapse = "/")) + ## Delete the first row + DF <- DF[-1, , drop = FALSE] + ## Add crammed row indicator (used for formatting) + DF[1,"crammedRowInd"] <- "crammed" + + } else { + ## Otherwise, keep the second level only + ## change variable name, and delete the first level. + DF$var <- sprintf("%s = %s", DF$var, DF$level) + DF <- DF[-1, , drop = FALSE] + } + + } else if (!showAllLevels & nRow > 2) { + ## If showAllLevels is FALSE AND there are MORE THAN two levels, + ## add an empty row and put the var name, then levels below. + DF <- rbind(rep("", ncol(DF)), DF) + ## Add variable name in the first row + DF[1,"var"] <- DF[2,"var"] + + ## 2nd to last have level names. (nrow has changed by +1) + secondToLastRows <- seq(from = 2,to = nrow(DF), by = 1) + DF[secondToLastRows, "var"] <- + paste0(" ", DF[secondToLastRows, "level"]) # preceding spaces + + } else if (showAllLevels) { + ## If showAllLevels is TRUE, clear these except in 1st row + DF[-1, c("var","n","miss","p.miss")] <- "" + } + + ## Add first row indicator (used to add (%)) + DF[1,"firstRowInd"] <- "first" + + ## Return a data frame + DF + }, + simplify = FALSE) # Looped over variables (list element is DF) +} + +## Module to loop over strata formatting categorical variables +ModuleCatFormatStrata <- function(CatTable, digits, varsToFormat, cramVars, showAllLevels) { + + ## Create format for percent used in the loop + fmt1 <- paste0("%.", digits, "f") + + ## Obtain collpased result + CatTableCollapsed <- + ## Loop over strata extracting list of variables + sapply(X = CatTable, + FUN = function(lstVars) { + + ## Do the following formatting only if the stratum is non-null. Do nothing if null. + if (!is.null(lstVars)) { + ## Returns an empty list if the stratum is null (empty). + + ## Loop over list of variables formatting them + lstVarsFormatted <- + ModuleCatFormatVariables(lstVars = lstVars, + varsToFormat = varsToFormat, + fmt = fmt1, + cramVars = cramVars, + showAllLevels = showAllLevels) + + + ## Collapse DFs within each stratum + DF <- do.call(rbind, lstVarsFormatted) + + ## Justification should happen here after combining variable DFs into a stratum DF. + ## Check non-empty rows + posNonEmptyRows <- DF$freq != "" + + + ## Create freq to be added on to the right side within () + DF$freqAddOn <- DF$freq + ## Right justify frequency (crammed and non-crammed at once) + DF$freq <- format(DF$freq, justify = "right") + ## Right justify frequency (non-crammed only) + DF[DF$crammedRowInd == "","freqAddOn"] <- + format(DF[DF$crammedRowInd == "","freqAddOn"], justify = "right") + ## Obtain the max width of characters + nCharFreq <- max(nchar(DF$freq)) + + + ## Create percent to be added on to the right side within () + DF$percentAddOn <- DF$percent + ## Right justify percent (crammed and non-crammed at once) + DF$percent <- format(DF$percent, justify = "right") + ## Right justify percent (non-crammed only) + DF[DF$crammedRowInd == "","percentAddOn"] <- + format(DF[DF$crammedRowInd == "","percentAddOn"], justify = "right") + ## Obtain the max width of characters + nCharPercent <- max(nchar(DF$percent)) + + + ## Add freq (percent) column (only in non-empty rows) + DF$freqPer <- "" + DF[posNonEmptyRows,]$freqPer <- sprintf(fmt = "%s (%s) ", + DF[posNonEmptyRows,]$freq, + DF[posNonEmptyRows,]$percentAddOn) + + ## Add percent (freq) column (only in non-empty rows) + DF$perFreq <- "" + DF[posNonEmptyRows,]$perFreq <- sprintf(fmt = "%s (%s) ", + DF[posNonEmptyRows,]$percent, + DF[posNonEmptyRows,]$freqAddOn) + + ## Add aditional attributes + attributes(DF) <- c(attributes(DF), + list(nCharFreq = nCharFreq, + nCharPercent = nCharPercent)) + + ## Return a data frame (2014-02-12 sapply breaks attributes?) + DF + } # end of non-null condition (Null strata skip all this. No action.) + + }, simplify = FALSE) + + CatTableCollapsed +} + + +## Module to loop over strata formatting continuous variables + + ### Modules by both print and summary methods ## ModuleQuoteAndPrintMat() diff --git a/R/print.CatTable.R b/R/print.CatTable.R index be2253a..d85eae0 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -153,158 +153,18 @@ print.CatTable <- function(x, # CatTable object ### Formatting for printing - ## Create format for percent used in the loop - fmt1 <- paste0("%.", digits, "f") + ## Variables to format using digits option + ## Full list c("n","miss","p.miss","freq","percent","cum.percent") + varsToFormat <- c("p.miss","percent","cum.percent") - ## Obtain collpased result + ## Obtain collpased result by looping over strata + ## within each stratum, loop over variables CatTableCollapsed <- - sapply(X = CatTable, # Loop over strata - FUN = function(LIST) { - - ## Do the following formatting only if the stratum is non-null. Do nothing if null. - if (!is.null(LIST)) { - - ## Returns an empty list if the stratum is null (empty). - LIST <- - sapply(X = seq_along(LIST), # Loop over variables (list element is DF) - FUN = function(i) { - - ## Extract the data frame (list element) - DF <- LIST[[i]] - - ## Extract the variable name - varName <- names(LIST)[i] - - ## Check number of rows (levels) - nRow <- nrow(DF) - - ## Add a variable name to the left as a character vector - DF <- cbind(var = rep(varName, nRow), - DF) - - ## Format percent and cum.percent as strings - DF[c("p.miss","percent","cum.percent")] <- - lapply(X = DF[c("p.miss","percent","cum.percent")], - FUN = sprintf, - fmt = fmt1) - - - ## Make all variables strings (freq is an integer, so direct convert ok) - DF[] <- lapply(X = DF, FUN = as.character) - - ## Add first row indicator column - DF$firstRowInd <- "" - ## Add crammed row indicator column - DF$crammedRowInd <- "" - - ## Format based on the number of levels - if (!showAllLevels & nRow == 1) { - ## If showAllLevels is FALSE AND there are only ONE levels, - ## change variable name to "var = level" - DF$var <- with(DF, paste0(var, " = ", level)) - - } else if (!showAllLevels & nRow == 2) { - ## If showAllLevels is FALSE AND there are only TWO levels, - ## cram two levels in one row if requested - if (unique(DF$var) %in% cramVars) { - ## If cramVars includes var, cram into one line - ## Cram two freq and count with / in between - DF$freq <- paste0(DF$freq, collapse = "/") - DF$percent <- paste0(DF$percent, collapse = "/") - ## change variable name, and delete the first level. - DF$var <- paste0(DF$var, " = ", - paste0(DF$level, collapse = "/")) - ## Delete the first row - DF <- DF[-1, , drop = FALSE] - ## Add crammed row indicator (used for formatting) - DF[1,"crammedRowInd"] <- "crammed" - } else { - ## Otherwise, keep the second level only - ## change variable name, and delete the first level. - DF$var <- with(DF, paste0(var, " = ", level)) - DF <- DF[-1, , drop = FALSE] - } - - } else if (!showAllLevels & nRow > 2) { - ## If showAllLevels is FALSE AND there are MORE THAN two levels, - ## add an empty row and put the var name, then levels below. - DF <- rbind(rep("", ncol(DF)), - DF) - ## Add variable name in the first row - DF[1,"var"] <- DF[2,"var"] - - ## 2nd to last have level names. (nrow has changed by +1) - secondToLastRows <- seq(from = 2,to = nrow(DF), by = 1) - DF[secondToLastRows, "var"] <- - paste0(" ", DF[secondToLastRows, "level"]) # preceding spaces - - } else if (showAllLevels) { - ## If showAllLevels is TRUE, clear these except in 1st row - DF[-1, c("var","n","miss","p.miss")] <- "" - } - - ## Add first row indicator (used to add (%)) - DF[1,"firstRowInd"] <- "first" - - ## Return a data frame - DF - }, - simplify = FALSE) # Looped over variables (list element is DF) - - - ## Collapse DFs within each stratum - DF <- do.call(rbind, LIST) - - ## Justification should happen here after combining variable DFs into a stratum DF. - ## Check non-empty rows - posNonEmptyRows <- DF$freq != "" - - - ## Create freq to be added on to the right side within () - DF$freqAddOn <- DF$freq - ## Right justify frequency (crammed and non-crammed at once) - DF$freq <- format(DF$freq, justify = "right") - ## Right justify frequency (non-crammed only) - DF[DF$crammedRowInd == "","freqAddOn"] <- - format(DF[DF$crammedRowInd == "","freqAddOn"], justify = "right") - ## Obtain the max width of characters - nCharFreq <- max(nchar(DF$freq)) - - - ## Create percent to be added on to the right side within () - DF$percentAddOn <- DF$percent - ## Right justify percent (crammed and non-crammed at once) - DF$percent <- format(DF$percent, justify = "right") - ## Right justify percent (non-crammed only) - DF[DF$crammedRowInd == "","percentAddOn"] <- - format(DF[DF$crammedRowInd == "","percentAddOn"], justify = "right") - ## Obtain the max width of characters - nCharPercent <- max(nchar(DF$percent)) - - - ## Add freq (percent) column (only in non-empty rows) - DF$freqPer <- "" - DF[posNonEmptyRows,]$freqPer <- sprintf(fmt = "%s (%s) ", - DF[posNonEmptyRows,]$freq, - DF[posNonEmptyRows,]$percentAddOn) - - ## Add percent (freq) column (only in non-empty rows) - DF$perFreq <- "" - DF[posNonEmptyRows,]$perFreq <- sprintf(fmt = "%s (%s) ", - DF[posNonEmptyRows,]$percent, - DF[posNonEmptyRows,]$freqAddOn) - - ## Add aditional attributes - attributes(DF) <- c(attributes(DF), - list(nCharFreq = nCharFreq, - nCharPercent = nCharPercent) - ) - - ## Return a data frame (2014-02-12 sapply breaks attributes?) - DF - } # end of non-null condition (Null strata skip all this. No action.) - - }, simplify = FALSE) + ModuleCatFormatStrata(CatTable = CatTable, + digits = digits, + varsToFormat = varsToFormat, + cramVars = cramVars, + showAllLevels = showAllLevels) ### Obtain the original column width in characters for alignment in print.TableOne diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index e189c6e..85c2f07 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -100,158 +100,17 @@ print.svyCatTable <- function(x, # CatTable object ### Formatting for printing - ## Create format for percent used in the loop - fmt1 <- paste0("%.", digits, "f") - varsNumeric <- c("n","miss","p.miss","freq","percent","cum.percent") + ## Variables to format using digits option + varsToFormat <- c("n","miss","p.miss","freq","percent","cum.percent") - ## Obtain collpased result + ## Obtain collpased result by looping over strata + ## within each stratum, loop over variables CatTableCollapsed <- - sapply(X = CatTable, # Loop over strata - FUN = function(LIST) { - - ## Do the following formatting only if the stratum is non-null. Do nothing if null. - if (!is.null(LIST)) { - - ## Returns an empty list if the stratum is null (empty). - LIST <- - sapply(X = seq_along(LIST), # Loop over variables (list element is DF) - FUN = function(i) { - - ## Extract the data frame (list element) - DF <- LIST[[i]] - - ## Extract the variable name - varName <- names(LIST)[i] - - ## Check number of rows (levels) - nRow <- nrow(DF) - - ## Add a variable name to the left as a character vector - DF <- cbind(var = rep(varName, nRow), - DF) - - ## Format percent and cum.percent as strings - DF[varsNumeric] <- lapply(X = DF[varsNumeric], - FUN = sprintf, - fmt = fmt1) - - - ## Make all variables strings (freq is an integer, so direct convert ok) - DF[] <- lapply(X = DF, FUN = as.character) - - ## Add first row indicator column - DF$firstRowInd <- "" - ## Add crammed row indicator column - DF$crammedRowInd <- "" - - ## Format based on the number of levels - if (!showAllLevels & nRow == 1) { - ## If showAllLevels is FALSE AND there are only ONE levels, - ## change variable name to "var = level" - DF$var <- with(DF, paste0(var, " = ", level)) - - } else if (!showAllLevels & nRow == 2) { - ## If showAllLevels is FALSE AND there are only TWO levels, - ## cram two levels in one row if requested - if (unique(DF$var) %in% cramVars) { - ## If cramVars includes var, cram into one line - ## Cram two freq and count with / in between - DF$freq <- paste0(DF$freq, collapse = "/") - DF$percent <- paste0(DF$percent, collapse = "/") - ## change variable name, and delete the first level. - DF$var <- paste0(DF$var, " = ", - paste0(DF$level, collapse = "/")) - ## Delete the first row - DF <- DF[-1, , drop = FALSE] - ## Add crammed row indicator (used for formatting) - DF[1,"crammedRowInd"] <- "crammed" - } else { - ## Otherwise, keep the second level only - ## change variable name, and delete the first level. - DF$var <- with(DF, paste0(var, " = ", level)) - DF <- DF[-1, , drop = FALSE] - } - - } else if (!showAllLevels & nRow > 2) { - ## If showAllLevels is FALSE AND there are MORE THAN two levels, - ## add an empty row and put the var name, then levels below. - DF <- rbind(rep("", ncol(DF)), - DF) - ## Add variable name in the first row - DF[1,"var"] <- DF[2,"var"] - - ## 2nd to last have level names. (nrow has changed by +1) - secondToLastRows <- seq(from = 2,to = nrow(DF), by = 1) - DF[secondToLastRows, "var"] <- - paste0(" ", DF[secondToLastRows, "level"]) # preceding spaces - - } else if (showAllLevels) { - ## If showAllLevels is TRUE, clear these except in 1st row - DF[-1, c("var","n","miss","p.miss")] <- "" - } - - ## Add first row indicator (used to add (%)) - DF[1,"firstRowInd"] <- "first" - - ## Return a data frame - DF - }, - simplify = FALSE) # Looped over variables (list element is DF) - - - ## Collapse DFs within each stratum - DF <- do.call(rbind, LIST) - - ## Justification should happen here after combining variable DFs into a stratum DF. - ## Check non-empty rows - posNonEmptyRows <- DF$freq != "" - - - ## Create freq to be added on to the right side within () - DF$freqAddOn <- DF$freq - ## Right justify frequency (crammed and non-crammed at once) - DF$freq <- format(DF$freq, justify = "right") - ## Right justify frequency (non-crammed only) - DF[DF$crammedRowInd == "","freqAddOn"] <- - format(DF[DF$crammedRowInd == "","freqAddOn"], justify = "right") - ## Obtain the max width of characters - nCharFreq <- max(nchar(DF$freq)) - - - ## Create percent to be added on to the right side within () - DF$percentAddOn <- DF$percent - ## Right justify percent (crammed and non-crammed at once) - DF$percent <- format(DF$percent, justify = "right") - ## Right justify percent (non-crammed only) - DF[DF$crammedRowInd == "","percentAddOn"] <- - format(DF[DF$crammedRowInd == "","percentAddOn"], justify = "right") - ## Obtain the max width of characters - nCharPercent <- max(nchar(DF$percent)) - - - ## Add freq (percent) column (only in non-empty rows) - DF$freqPer <- "" - DF[posNonEmptyRows,]$freqPer <- sprintf(fmt = "%s (%s) ", - DF[posNonEmptyRows,]$freq, - DF[posNonEmptyRows,]$percentAddOn) - - ## Add percent (freq) column (only in non-empty rows) - DF$perFreq <- "" - DF[posNonEmptyRows,]$perFreq <- sprintf(fmt = "%s (%s) ", - DF[posNonEmptyRows,]$percent, - DF[posNonEmptyRows,]$freqAddOn) - - ## Add aditional attributes - attributes(DF) <- c(attributes(DF), - list(nCharFreq = nCharFreq, - nCharPercent = nCharPercent) - ) - - ## Return a data frame (2014-02-12 sapply breaks attributes?) - DF - } # end of non-null condition (Null strata skip all this. No action.) - - }, simplify = FALSE) + ModuleCatFormatStrata(CatTable = CatTable, + digits = digits, + varsToFormat = varsToFormat, + cramVars = cramVars, + showAllLevels = showAllLevels) ### Obtain the original column width in characters for alignment in print.TableOne From 656a415167e99fb2772f6dd0aee2ab199fbc205f Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 22:09:47 -0400 Subject: [PATCH 096/219] Factor out formatting loop for continuous variables --- R/modules.R | 63 ++++++++++++++++++++++++++++++++++++++++-- R/print.ContTable.R | 53 ++++------------------------------- R/print.svyContTable.R | 53 ++++------------------------------- 3 files changed, 70 insertions(+), 99 deletions(-) diff --git a/R/modules.R b/R/modules.R index ba6f68c..e684f6d 100644 --- a/R/modules.R +++ b/R/modules.R @@ -498,13 +498,13 @@ ModuleCatFormatStrata <- function(CatTable, digits, varsToFormat, cramVars, show ## Obtain collpased result CatTableCollapsed <- ## Loop over strata extracting list of variables - sapply(X = CatTable, + sapply(X = CatTable, FUN = function(lstVars) { ## Do the following formatting only if the stratum is non-null. Do nothing if null. if (!is.null(lstVars)) { ## Returns an empty list if the stratum is null (empty). - + ## Loop over list of variables formatting them lstVarsFormatted <- ModuleCatFormatVariables(lstVars = lstVars, @@ -512,7 +512,7 @@ ModuleCatFormatStrata <- function(CatTable, digits, varsToFormat, cramVars, show fmt = fmt1, cramVars = cramVars, showAllLevels = showAllLevels) - + ## Collapse DFs within each stratum DF <- do.call(rbind, lstVarsFormatted) @@ -572,6 +572,63 @@ ModuleCatFormatStrata <- function(CatTable, digits, varsToFormat, cramVars, show ## Module to loop over strata formatting continuous variables +## No variable level looping here as each stratum is a matrix of all variables +ModuleContFormatStrata <- function(ContTable, nVars, listOfFunctions, digits) { + + ## Return a formatted table looping over strata + sapply(ContTable, + ## Each stratum is a matrix containing summaries + ## One row is one variable + FUN = function(stratum) { + + ## In an empty stratum, return empty + if (is.null(stratum)) { + + out <- rep("-", nVars) + ## Give NA to the width of the mean/median column in characters + nCharMeanOrMedian <- NA + + } else { + + ## Apply row by row within each non-empty stratum + ## This row-by-row operation is necessary to handle mean (sd) and median [IQR] + out <- sapply(seq_len(nVars), + FUN = function(i) { + + ## Choose between normal or nonnormal function + fun <- listOfFunctions[[i]] + ## Convert a row matrix to 1x2 df (numeric, character) + fun(stratum[i, , drop = FALSE]) + + ## Create a 1-row DF (numeric, character) + }, + simplify = FALSE) + + ## nx2 data frame by row binding multiple 1-row data frames + out <- do.call(rbind, out) + + ## Format for decimals + out$col1 <- sprintf(fmt = paste0("%.", digits, "f"), out$col1) + + ## right justify by adding spaces (to align at the decimal point of mean/median) + out$col1 <- format(out$col1, justify = "right") + + ## Obtain the width of the mean/median column in characters + nCharMeanOrMedian <- nchar(out$col1[1]) + + ## Create mean (SD) or median [p25, p75] as a character vector + out <- do.call(paste0, out) + } + + ## Add attributes + attributes(out) <- c(attributes(out), + list(nCharMeanOrMedian = nCharMeanOrMedian)) + + ## Return + out + }, + simplify = FALSE) +} diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 7e51c6d..831be4d 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -164,54 +164,11 @@ print.ContTable <- function(x, # ContTable object listOfFunctions <- listOfFunctions[nonnormal] ## Loop over strata (There may be just one) - out <- sapply(ContTable, - FUN = function(stratum) { - - ## In an empty stratum, return empty - if (is.null(stratum)) { - out <- rep("-", nVars) - ## Give NA to the width of the mean/median column in characters - nCharMeanOrMedian <- NA - } else { - - ## Apply row by row within each non-empty stratum - ## This row-by-row operation is necessary to handle mean (sd) and median [IQR] - out <- sapply(seq_len(nVars), - FUN = function(i) { - - ## Choose between normal or nonnormal function - fun <- listOfFunctions[[i]] - ## Convert a row matrix to 1x2 df (numeric, character) - fun(stratum[i, , drop = FALSE]) - - ## Create a 1-row DF (numeric, character) - }, - simplify = FALSE) - - ## nx2 data frame by row binding multiple 1-row data frames - out <- do.call(rbind, out) - - ## Format for decimals - out$col1 <- sprintf(fmt = paste0("%.", digits, "f"), out$col1) - - ## right justify by adding spaces (to align at the decimal point of mean/median) - out$col1 <- format(out$col1, justify = "right") - - ## Obtain the width of the mean/median column in characters - nCharMeanOrMedian <- nchar(out$col1[1]) - - ## Create mean (SD) or median [p25, p75] as a character vector - out <- do.call(paste0, out) - } - - ## Add attributes - attributes(out) <- c(attributes(out), - list(nCharMeanOrMedian = nCharMeanOrMedian)) - - ## Return - out - }, - simplify = FALSE) + out <- ModuleContFormatStrata(ContTable = ContTable, + nVars = nVars, + listOfFunctions = listOfFunctions, + digits = digits) + ### Obtain the original column width in characters for alignment in print.TableOne vecColWidths <- sapply(out, diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index d487a16..2f14474 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -110,54 +110,11 @@ print.svyContTable <- function(x, # ContTable object listOfFunctions <- listOfFunctions[nonnormal] ## Loop over strata (There may be just one) - out <- sapply(ContTable, - FUN = function(stratum) { - - ## In an empty stratum, return empty - if (is.null(stratum)) { - out <- rep("-", nVars) - ## Give NA to the width of the mean/median column in characters - nCharMeanOrMedian <- NA - } else { - - ## Apply row by row within each non-empty stratum - ## This row-by-row operation is necessary to handle mean (sd) and median [IQR] - out <- sapply(seq_len(nVars), - FUN = function(i) { - - ## Choose between normal or nonnormal function - fun <- listOfFunctions[[i]] - ## Convert a row matrix to 1x2 df (numeric, character) - fun(stratum[i, , drop = FALSE]) - - ## Create a 1-row DF (numeric, character) - }, - simplify = FALSE) - - ## nx2 data frame by row binding multiple 1-row data frames - out <- do.call(rbind, out) - - ## Format for decimals - out$col1 <- sprintf(fmt = paste0("%.", digits, "f"), out$col1) - - ## right justify by adding spaces (to align at the decimal point of mean/median) - out$col1 <- format(out$col1, justify = "right") - - ## Obtain the width of the mean/median column in characters - nCharMeanOrMedian <- nchar(out$col1[1]) - - ## Create mean (SD) or median [p25, p75] as a character vector - out <- do.call(paste0, out) - } - - ## Add attributes - attributes(out) <- c(attributes(out), - list(nCharMeanOrMedian = nCharMeanOrMedian)) - - ## Return - out - }, - simplify = FALSE) + out <- ModuleContFormatStrata(ContTable = ContTable, + nVars = nVars, + listOfFunctions = listOfFunctions, + digits = digits) + ### Obtain the original column width in characters for alignment in print.TableOne vecColWidths <- sapply(out, From 9449bce8c9f8bbd18900fc54adb0521b240443b2 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 22:13:40 -0400 Subject: [PATCH 097/219] Fix trailing parens in (svy)CreateTableOne --- R/CreateTableOne.R | 10 ++++------ R/svyCreateTableOne.R | 7 +++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 7cbfae5..85df1dc 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -160,16 +160,15 @@ CreateTableOne <- testNormal = testNormal, argsNormal = argsNormal, testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal - ) + argsNonNormal = argsNonNormal) argsCreateCatTable <- list(data = data, includeNA = includeNA, test = test, testApprox = testApprox, argsApprox = argsApprox, testExact = testExact, - argsExact = argsExact - ) + argsExact = argsExact) + ## Add strata = strata for argument only if strata is given if (!missing(strata)) { @@ -241,8 +240,7 @@ CreateTableOne <- ## Create a list for output TableOneObject <- list(TableOne = TableOne, ContTable = ContTable, - CatTable = CatTable - ) + CatTable = CatTable) ## Give a class class(TableOneObject) <- "TableOne" diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 4598432..35c2f19 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -143,14 +143,13 @@ function(vars, # character vector of variable testNormal = testNormal, argsNormal = argsNormal, testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal - ) + argsNonNormal = argsNonNormal) argsCreateCatTable <- list(data = data, includeNA = includeNA, test = test, testApprox = testApprox, - argsApprox = argsApprox - ) + argsApprox = argsApprox) + ## Add strata = strata for argument only if strata is given if (!missing(strata)) { From 8b09bb91a024e8a5e972e6e5d7bf022d9f5f7fb6 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 22:45:34 -0400 Subject: [PATCH 098/219] Factor out testing from CreateCatTable --- R/CreateCatTable.R | 72 +++++++++++++++------------------------------- R/modules.R | 44 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 49 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 782b701..fd3b985 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -82,16 +82,16 @@ ##' ##' @export CreateCatTable <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - includeNA = FALSE, # include NA as a category - test = TRUE, # whether to put p-values - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5) # arguments passed to testExact - ) { +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + includeNA = FALSE, # include NA as a category + test = TRUE, # whether to put p-values + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5) # arguments passed to testExact + ) { ### Data check ## Check if the data given is a dataframe @@ -173,45 +173,19 @@ CreateCatTable <- listXtabs <- list() ## Only when test is asked for - if (test == TRUE) { - - ## Create a single variable representation of multivariable stratification - strataVar <- ModuleCreateStrataVarAsFactor(result, strata) - - ## Loop over variables in dat, and create a list of xtabs - ## Empty strata are kept in the corss tables. Different behavior than the cont counterpart! - listXtabs <- sapply(X = names(dat), - FUN = function(var) { - ## Create a formula - formula <- paste0("~ ", var, " + ", "strataVar") - formula <- as.formula(formula) - - ## Create a 2-dimensional crosstable - xtabs(formula = formula, data = dat) - }, - simplify = FALSE) - - ## Rename the second dimension of the xtabs with the newly create name. - for (i in seq_along(listXtabs)) { - - names(dimnames(listXtabs[[i]]))[2] <- strataVarName - } - - ## Loop over xtabs, and create p-values - pValues <- sapply(X = listXtabs, - FUN = function(xtabs) { - ## Perform tests and return the result as 1x2 DF - data.frame( - pApprox = ModuleTestSafe(xtabs, testApprox, argsApprox), - pExact = ModuleTestSafe(xtabs, testExact, argsExact) - ) - }, - simplify = FALSE) - - ## Create a single data frame (n x 2 (normal,nonormal)) - pValues <- do.call(rbind, pValues) - } # Conditional for test == TRUE ends here. - + if (test) { + lstXtabsPVals <- + ModuleApproxExactTests(result = result, + strata = strata, + dat = dat, + strataVarName = strataVarName, + testApprox = testApprox, + argsApprox = argsApprox, + testExact = testExact, + argsExact = argsExact) + pValues <- lstXtabsPVals$pValues + listXtabs <- lstXtabsPVals$xtabs + } ## Return object ## Give an S3 class diff --git a/R/modules.R b/R/modules.R index e684f6d..bcd24db 100644 --- a/R/modules.R +++ b/R/modules.R @@ -239,6 +239,50 @@ ModuleCreateStrataVarAsFactor <- function(result, strata) { } +### Module for testing multiple variables +################################################################################ + +ModuleApproxExactTests <- function(result, strata, dat, strataVarName, + testApprox, argsApprox, + testExact, argsExact) { + ## Create a single variable representation of multivariable stratification + strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + + ## Loop over variables in dat, and create a list of xtabs + ## Empty strata are kept in the corss tables. Different behavior than the cont counterpart! + listXtabs <- sapply(X = names(dat), + FUN = function(var) { + ## Create a formula + formula <- as.formula(paste0("~ ", var, " + ", "strataVar")) + + ## Create a 2-dimensional crosstable + xtabs(formula = formula, data = dat) + }, + simplify = FALSE) + + ## Rename the second dimension of the xtabs with the newly create name. + for (i in seq_along(listXtabs)) { + + names(dimnames(listXtabs[[i]]))[2] <- strataVarName + } + + ## Loop over xtabs, and create p-values + pValues <- + sapply(X = listXtabs, + FUN = function(xtabs) { + ## Perform tests and return the result as 1x2 DF + data.frame(pApprox = ModuleTestSafe(xtabs, testApprox, argsApprox), + pExact = ModuleTestSafe(xtabs, testExact, argsExact)) + }, + simplify = FALSE) + + ## Create a single data frame (n x 2 (normal,nonormal)) + pValues <- do.call(rbind, pValues) + + ## Return both xtabs and p value df + list(pValues = pValues, xtabs = listXtabs) +} + ### Modules intented for the print methods ################################################################################ From 1a8368cb3a4f3c471dbe4823cfffb49cf55c08bd Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 22:47:55 -0400 Subject: [PATCH 099/219] Factor out testing from svyCreateCatTable --- R/svyCreateCatTable.R | 44 +++++++++---------------------------------- R/svyModules.R | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 601b870..18dc88e 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -118,41 +118,15 @@ function(vars, # character vector of variable names ## Only when test is asked for if (test) { - listXtabs <- sapply(X = vars, - FUN = function(var) { - ## Create a formula - formula <- as.formula(paste0("~ ", var, " + ", "..strataVar..")) - - ## Create a 2-dimensional crosstable - svytable(formula = formula, design = data) - }, - simplify = FALSE) - - ## Rename the second dimension of the xtabs with the newly create name. - for (i in seq_along(listXtabs)) { - - names(dimnames(listXtabs[[i]]))[2] <- strataVarName - } - - - ## Loop over variables, and create p-values - pValues <- - sapply(X = vars, - FUN = function(var) { - - formulaString <- paste0(" ~ ", var, " + ..strataVar..") - - ## Perform tests and return the result as 1x2 DF - data.frame(pApprox = ModuleTestSafe(formulaString, testApprox, - c(list(design = data), argsApprox)), - ## Not available for survey data. Just fill in with NA - pExact = NA) - }, - simplify = FALSE) - - ## Create a single data frame (n x 2 (normal,nonormal)) - pValues <- do.call(rbind, pValues) - } # Conditional for test == TRUE ends here. + lstXtabsPVals <- + svyModuleApproxExactTests(data = data, + vars = vars, + strataVarName = strataVarName, + testApprox = testApprox, + argsApprox = argsApprox) + pValues <- lstXtabsPVals$pValues + listXtabs <- lstXtabsPVals$xtabs + } ## Return object diff --git a/R/svyModules.R b/R/svyModules.R index fd470cb..9489a20 100644 --- a/R/svyModules.R +++ b/R/svyModules.R @@ -238,3 +238,44 @@ svyTestChisq <- function(formulaString, design) { ## This returns an htest object that has a scalar $p.value element svychisq(formula = as.formula(formulaString), design = design) } + + +svyModuleApproxExactTests <- function(data, vars, strataVarName, + testApprox, argsApprox) { + + ## Loop over variables and create a list of xtabs + ## Empty strata are kept in the corss tables. Different behavior than the cont counterpart! + listXtabs <- sapply(X = vars, + FUN = function(var) { + ## Create a formula + formula <- as.formula(paste0("~ ", var, " + ", "..strataVar..")) + + ## Create a 2-dimensional crosstable + svytable(formula = formula, design = data) + }, + simplify = FALSE) + + ## Rename the second dimension of the xtabs with the newly create name. + for (i in seq_along(listXtabs)) { + + names(dimnames(listXtabs[[i]]))[2] <- strataVarName + } + + ## Loop over variables, and create p-values + pValues <- + sapply(X = vars, + FUN = function(var) { + formulaString <- paste0(" ~ ", var, " + ..strataVar..") + ## Perform tests and return the result as 1x2 DF + data.frame(pApprox = ModuleTestSafe(formulaString, testApprox, + c(list(design = data), argsApprox)), + pExact = NA) # Not available for survey data. Just fill in with NA + }, + simplify = FALSE) + + ## Create a single data frame (n x 2 (normal,nonormal)) + pValues <- do.call(rbind, pValues) + + ## Return both xtabs and p value df + list(pValues = pValues, xtabs = listXtabs) +} From 26a3e7a4342fe7db31bd94a56a4b0c0c948931f4 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Wed, 29 Jul 2015 22:56:08 -0400 Subject: [PATCH 100/219] Factor out inclusion of NA as a level --- R/CreateCatTable.R | 14 +------------- R/modules.R | 20 ++++++++++++++++++++ R/svyCreateCatTable.R | 20 ++------------------ 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index fd3b985..3fe1324 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -125,19 +125,7 @@ function(vars, # character vector of variable na ## If including NA as a level, include NA as a factor level before subsetting if (includeNA) { - ## Logical vector for variables that have any NA - logiAnyNA <- (colSums(is.na(dat)) > 0) - - ## Add NA as a new level unless already present - dat[logiAnyNA] <- - lapply(dat[logiAnyNA], - function(var) { - if (all(!is.na(levels(var)))) { - var <- factor(var, c(levels(var), NA), - exclude = NULL) - } - var - }) + dat <- ModuleIncludeNaAsLevel(dat) } ### Actual descriptive statistics are calculated here. diff --git a/R/modules.R b/R/modules.R index bcd24db..6e9e0e1 100644 --- a/R/modules.R +++ b/R/modules.R @@ -163,6 +163,26 @@ ModuleCreateStrataVarName <- function(obj) { paste0(names(attr(obj, "dimnames")), collapse = ":") } + +## Convert variables with NA to include NA as a level (for CatTable constructor) +ModuleIncludeNaAsLevel <- function(data) { + ## Logical vector for variables that have any NA + logiAnyNA <- (colSums(is.na(data)) > 0) + + ## Add NA as a new level unless already present + data[logiAnyNA] <- + lapply(data[logiAnyNA], + function(var) { + if (all(!is.na(levels(var)))) { + var <- factor(var, c(levels(var), NA), + exclude = NULL) + } + var + }) + data +} + + ### ModuleTryCatchWE ## Try catch function # Taken from demo(error.catching) ## Used to define non-failing functions, that return NA when there is an error diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 18dc88e..4c1e36b 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -68,28 +68,12 @@ function(vars, # character vector of variable names ## If including NA as a level, include NA as a factor level before subsetting if (includeNA) { - ## Logical vector for variables that have any NA - logiAnyNA <- (colSums(is.na(data$variables)) > 0) - - ## Add NA as a new level unless already present - data$variables[logiAnyNA] <- - lapply(data$variables[logiAnyNA], - function(var) { - if (all(!is.na(levels(var)))) { - var <- factor(var, c(levels(var), NA), - exclude = NULL) - } - var - }) + data$variables <- ModuleIncludeNaAsLevel(data$variables) } ### Actual descriptive statistics are calculated here. - ## To implement - ## Create a single grouping variable from strata variables - ## Create a list of subgroup data by the grouping variable - ## Loop over each stratum with matrix forming function - + ## Return a list of summary matrices result <- sapply(strataVarLevels, function(level) { ## Create a matrix including vars X c(n,miss,...) matrix From f0008d2c1a84ff0eb8f4306dfbd5118b8bcc2720 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 09:05:14 -0400 Subject: [PATCH 101/219] Drop first column of propTables only if ncol > 1 Safeguard against failure when the variable is a constant --- R/smdModules.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/smdModules.R b/R/smdModules.R index 66949be..e8efedd 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -90,8 +90,12 @@ LstMeansFromFullTable <- function(strataByLevels) { ## Proportion within each stratum ## Equivalent to mean of dummy variables propTables <- prop.table(strataByLevels, margin = 1) - ## Drop first level to eliminate dependence - propTables <- propTables[, -1, drop = FALSE] + + ## Drop first level to eliminate dependence if more than two levels + ## Avoids errors with constant variable + if (ncol(propTables) > 1) { + propTables <- propTables[, -1, drop = FALSE] + } ## list of mean vectors (Missing values are discarded) lstMeans <- lapply(seq_len(nrow(propTables)), function(i) { From 5db5cce74750bb6170b3558874cd443c81eb3cc3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 09:18:21 -0400 Subject: [PATCH 102/219] Add initial attempt to incorporate SMD in svyCreateCatTable --- R/svyCreateCatTable.R | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 4c1e36b..e778108 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -26,11 +26,12 @@ svyCreateCatTable <- function(vars, # character vector of variable names strata, # character vector of variable names - data, # data frame + data, # survey design object includeNA = FALSE, # include NA as a category test = TRUE, # whether to put p-values testApprox = svyTestChisq, # function for approximation test (only choice) - argsApprox = NULL # arguments passed to testApprox + argsApprox = NULL, # arguments passed to testApprox + smd = TRUE ) { ### Data check @@ -84,10 +85,10 @@ function(vars, # character vector of variable names ## Make it a by object class(result) <- "by" + ## strataVarName from dimension headers + strataVarName <- paste0(names(strata), collapse = ":") ## Add stratification variable information as an attribute if (length(result) > 1) { - ## strataVarName from dimension headers - strataVarName <- paste0(names(strata), collapse = ":") ## Add an attribute for the stratifying variable name attributes(result) <- c(attributes(result), list(strataVarName = strataVarName)) @@ -112,6 +113,19 @@ function(vars, # character vector of variable names listXtabs <- lstXtabsPVals$xtabs } +### Perform SMD when requested + smds <- NULL + + ## Only when SMD is asked for + ## TURN OFF FOR NOW + if (smd & FALSE) { + ## list of smds + smds <- sapply(vars, function(var) { + svyStdDiffMulti(varName = var, groupName = strataVarName, design = data) + }, simplify = FALSE) + + smds <- do.call(rbind, smds) + } ## Return object ## Give an S3 class @@ -120,7 +134,8 @@ function(vars, # character vector of variable names ## Give additional attributes attributes(result) <- c(attributes(result), list(pValues = pValues), - list(xtabs = listXtabs)) + list(xtabs = listXtabs), + list(smd = smds)) ## Return return(result) From 7590240384a4816ef8e2c8bcf5914062c908ac25 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 13:37:42 -0400 Subject: [PATCH 103/219] Add handling of NA-only strata for svyStdDiff(Multi) --- R/smdModules.R | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/R/smdModules.R b/R/smdModules.R index e8efedd..62a41d1 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -164,10 +164,29 @@ StdDiffs <- function(data, vars, groupVar, binaryVars) { ### Functions for weighted data only ################################################################################ +### Check strata for NA-only strata +svyCheckNaOnlyStrata <- function(varName, groupName, design) { + + unlist(lapply(split(design$variables[,varName], + design$variables[,groupName]), + function(var) { + ## TRUE if only NA's within stratum + all(is.na(var)) + })) +} + ### Continuous/binary standardized mean differences ## Expects continuous or 0,1 binary variable svyStdDiff <- function(varName, groupName, design, binary = FALSE, na.rm = TRUE) { + ## Check strata for all NA strata + logiAllNaStrata <- svyCheckNaOnlyStrata(varName, groupName, design) + ## If ANY strata have only NA's do not remove NA's + if (any(logiAllNaStrata)) { + warning(varName, " has only NA's in at least one stratum. na.rm turned off.") + na.rm = FALSE + } + varFormula <- as.formula(paste("~", varName)) groupFormula <- as.formula(paste("~", groupName)) @@ -195,6 +214,20 @@ svyStdDiff <- function(varName, groupName, design, binary = FALSE, na.rm = TRUE) ### Categorical (including binary) standardizzed mean difference svyStdDiffMulti <- function(varName, groupName, design) { + ## Check strata for all NA strata + logiAllNaStrata <- svyCheckNaOnlyStrata(varName, groupName, design) + + ## If ALL strata have only NA's convert to a level + ## If any strata have valid levels, table is ok + ## Empty table breaks the function + if (all(logiAllNaStrata)) { + + warning(varName, " has only NA's in all strata. Regarding NA as a level") + + design$variables[,varName] <- factor(design$variables[,varName], + exclude = NULL) + } + tabFormula <- as.formula(sprintf("~ %s + %s", groupName, varName)) ## strata x variable table From 02a3d3bd4982cdd0ff217bdeea05267619ff8a6b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 13:45:36 -0400 Subject: [PATCH 104/219] Add handling of NA-only strata for StdDiff(Multi) --- R/smdModules.R | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/R/smdModules.R b/R/smdModules.R index 62a41d1..e259855 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -113,10 +113,29 @@ LstMeansFromFullTable <- function(strataByLevels) { ### Functions for unweighted data only ################################################################################ +### Check strata for NA-only strata +CheckNaOnlyStrata <- function(variable, group) { + + unlist(lapply(split(variable, group), + function(var) { + ## TRUE if only NA's within stratum + all(is.na(var)) + })) +} + + ### Continuous/binary standardized mean differences ## Expects continuous or 0,1 binary variable StdDiff <- function(variable, group, binary = FALSE, na.rm = TRUE) { + ## Check strata for all NA strata + logiAllNaStrata <- CheckNaOnlyStrata(variable, group) + ## If ANY strata have only NA's do not remove NA's + if (any(logiAllNaStrata)) { + warning("Variable has only NA's in at least one stratum. na.rm turned off.") + na.rm = FALSE + } + ## Proportion of 1 is the mean of variable means <- tapply(variable, group, mean, na.rm = na.rm) @@ -140,6 +159,19 @@ StdDiff <- function(variable, group, binary = FALSE, na.rm = TRUE) { ### Categorical (including binary) standardizzed mean difference StdDiffMulti <- function(variable, group) { + ## Check strata for all NA strata + logiAllNaStrata <- CheckNaOnlyStrata(variable, group) + + ## If ALL strata have only NA's convert to a level + ## If any strata have valid levels, table is ok + ## Empty table breaks the function + if (all(logiAllNaStrata)) { + + warning("Variable has only NA's in all strata. Regarding NA as a level.") + + variable <- factor(variable, exclude = NULL) + } + ## strata x variable table strataByLevels <- table(group, variable) lstMeans <- LstMeansFromFullTable(strataByLevels) @@ -222,7 +254,7 @@ svyStdDiffMulti <- function(varName, groupName, design) { ## Empty table breaks the function if (all(logiAllNaStrata)) { - warning(varName, " has only NA's in all strata. Regarding NA as a level") + warning(varName, " has only NA's in all strata. Regarding NA as a level.") design$variables[,varName] <- factor(design$variables[,varName], exclude = NULL) From 7c85ebbc8d7f6953e4905e119750e30c9ff9bdc5 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 13:50:23 -0400 Subject: [PATCH 105/219] Add unit tests of SMD functions with anomalous data --- tests/testthat/test-smdModules.R | 133 +++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) mode change 100644 => 100755 tests/testthat/test-smdModules.R diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R old mode 100644 new mode 100755 index ee154a8..67c911e --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -380,6 +380,139 @@ test_that("categorical standardized difference is correct (nhanes weighted)", { }) +### Test on anomalous data +################################################################################ + +test_that("decent results are returned for anomalous/difficult data", { + + data(nhanes) + nhanes$onlyOne <- 1 + nhanes$onlyNa <- as.numeric(NA) + nhanes$logi <- nhanes$RIAGENDR == 1 + nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, + nest = TRUE, data = nhanes) + + ## Logical + ## 0 due to [0]^- = 0 + expect_equal(StdDiffMulti(nhanes$logi, group = nhanes$RIAGENDR), 0) + ## Matches with result from original variable + expect_equal(StdDiffMulti(nhanes$logi, group = nhanes$race), + StdDiffMulti(nhanes$RIAGENDR, group = nhanes$race)) + + + ## Only one value + ## NaN due to division by zero variance + expect_equal(StdDiff(nhanes$onlyOne, group = nhanes$RIAGENDR), NaN) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(StdDiffMulti(nhanes$onlyOne, group = nhanes$RIAGENDR), 0) + ## When weighted problematic + means1 <- svyby(~ onlyOne, by = ~ RIAGENDR, nhanesSvy, FUN = svymean)[,2] + vars1 <- svyby(~ onlyOne, by = ~ RIAGENDR, nhanesSvy, FUN = svyvar)[,2] + ## Very small difference is inflated by even smaller variance + expect_equal(svyStdDiff("onlyOne", "RIAGENDR", nhanesSvy), + (means1[1] - means1[2]) / sqrt(sum(vars1) / 2)) + expect_equal(svyStdDiff("onlyOne", "RIAGENDR", nhanesSvy), NaN) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(svyStdDiffMulti("onlyOne", "RIAGENDR", nhanesSvy), 0) + + ## Four groups (six contrasts) + ## NaN due to division by zero variance + expect_equal(StdDiff(nhanes$onlyOne, group = nhanes$race), rep(NaN, 6)) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(StdDiffMulti(nhanes$onlyOne, group = nhanes$race), rep(0, 6)) + ## When weighted problematic; not in this case?? + means2 <- svyby(~ onlyOne, by = ~ race, nhanesSvy, FUN = svymean)[,2] + vars2 <- svyby(~ onlyOne, by = ~ race, nhanesSvy, FUN = svyvar)[,2] + meanDiffs2 <- c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + expect_equal(svyStdDiff("onlyOne", "race", nhanesSvy), meanDiffs2) + expect_equal(svyStdDiff("onlyOne", "race", nhanesSvy), rep(NaN, 6)) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(svyStdDiffMulti("onlyOne", "race", nhanesSvy), rep(0, 6)) + + + ## onlyNa + ## NA as na.rm is turned off + expect_warning(expect_equal(StdDiff(nhanes$onlyNa, group = nhanes$RIAGENDR), + as.numeric(NA)), + "Variable has only NA's in at least one stratum. na.rm turned off.") + ## 0 only one level + expect_warning(expect_equal(StdDiffMulti(nhanes$onlyNa, group = nhanes$RIAGENDR), 0), + "Variable has only NA's in all strata. Regarding NA as a level") + ## When weighted problematic + means1 <- svyby(~ onlyNa, by = ~ RIAGENDR, nhanesSvy, FUN = svymean)[,2] + vars1 <- svyby(~ onlyNa, by = ~ RIAGENDR, nhanesSvy, FUN = svyvar)[,2] + ## Very small difference is inflated by even smaller variance + expect_warning(svyStdDiff("onlyNa", "RIAGENDR", nhanesSvy), + "onlyNa has only NA's in at least one stratum. na.rm turned off.") + expect_warning(expect_equal(svyStdDiff("onlyNa", "RIAGENDR", nhanesSvy), + as.numeric(NA)), + "onlyNa has only NA's in at least one stratum. na.rm turned off.") + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(svyStdDiffMulti("onlyNa", "RIAGENDR", nhanesSvy), 0) + + ## Four groups (six contrasts) + ## NaN due to division by zero variance + expect_equal(StdDiff(nhanes$onlyNa, group = nhanes$race), rep(NaN, 6)) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(StdDiffMulti(nhanes$onlyNa, group = nhanes$race), rep(0, 6)) + ## When weighted problematic; not in this case?? + means2 <- svyby(~ onlyNa, by = ~ race, nhanesSvy, FUN = svymean)[,2] + vars2 <- svyby(~ onlyNa, by = ~ race, nhanesSvy, FUN = svyvar)[,2] + meanDiffs2 <- c((means2[1] - means2[2]) / sqrt((vars2[1] + vars2[2]) / 2), + (means2[1] - means2[3]) / sqrt((vars2[1] + vars2[3]) / 2), + (means2[1] - means2[4]) / sqrt((vars2[1] + vars2[4]) / 2), + (means2[2] - means2[3]) / sqrt((vars2[2] + vars2[3]) / 2), + (means2[2] - means2[4]) / sqrt((vars2[2] + vars2[4]) / 2), + (means2[3] - means2[4]) / sqrt((vars2[3] + vars2[4]) / 2)) + expect_equal(svyStdDiff("onlyNa", "race", nhanesSvy), meanDiffs2) + expect_equal(svyStdDiff("onlyNa", "race", nhanesSvy), rep(NaN, 6)) + ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 + expect_equal(svyStdDiffMulti("onlyNa", "race", nhanesSvy), rep(0, 6)) + + +}) + + +### Tests working on multiple variables +################################################################################ + +test_that("multiple variables can be looped", { + + + contVars <- c("WTMEC2YR", "HI_CHOL", "race", "RIAGENDR") + catVars <- c("HI_CHOL", "race", "agecat", "RIAGENDR") + + ## Expectations + + expect_true(FALSE) + + ## Two groups + sapply(contVars, function(var) { + StdDiff(variable = nhanes[,var], group = nhanes[,"RIAGENDR"]) + }, simplify = FALSE) + + sapply(catVars, function(var) { + StdDiffMulti(variable = nhanes[,var], group = nhanes[,"RIAGENDR"]) + }, simplify = FALSE) + + + ## Four groups + sapply(contVars, function(var) { + StdDiff(variable = nhanes[,var], group = nhanes[,"race"]) + }, simplify = FALSE) + + sapply(catVars, function(var) { + StdDiffMulti(variable = nhanes[,var], group = nhanes[,"race"]) + }, simplify = FALSE) + +}) + + ### Older tests with simpler data ################################################################################ From 340186802243f52ff731e86fe6e71b35e34b5486 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 14:10:38 -0400 Subject: [PATCH 106/219] Add tests looping over variables; allow ~ var1+var1 in svyStdDiffMulti --- R/smdModules.R | 5 +++ tests/testthat/test-smdModules.R | 71 ++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 12 deletions(-) diff --git a/R/smdModules.R b/R/smdModules.R index e259855..07d4f7e 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -260,6 +260,11 @@ svyStdDiffMulti <- function(varName, groupName, design) { exclude = NULL) } + ## If same variable is used as a group, factor() to allow tabling + if (varName == groupName) { + groupName <- sprintf("factor(%s)", groupName) + } + tabFormula <- as.formula(sprintf("~ %s + %s", groupName, varName)) ## strata x variable table diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index 67c911e..02a9478 100755 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -487,29 +487,76 @@ test_that("multiple variables can be looped", { contVars <- c("WTMEC2YR", "HI_CHOL", "race", "RIAGENDR") catVars <- c("HI_CHOL", "race", "agecat", "RIAGENDR") - ## Expectations - - expect_true(FALSE) ## Two groups - sapply(contVars, function(var) { + expect_equal(as.numeric(sapply(contVars, function(var) { StdDiff(variable = nhanes[,var], group = nhanes[,"RIAGENDR"]) - }, simplify = FALSE) + })), + c(StdDiff(variable = nhanes[,contVars[1]], group = nhanes[,"RIAGENDR"]), + StdDiff(variable = nhanes[,contVars[2]], group = nhanes[,"RIAGENDR"]), + StdDiff(variable = nhanes[,contVars[3]], group = nhanes[,"RIAGENDR"]), + StdDiff(variable = nhanes[,contVars[4]], group = nhanes[,"RIAGENDR"]))) - sapply(catVars, function(var) { + expect_equal(as.numeric(sapply(catVars, function(var) { StdDiffMulti(variable = nhanes[,var], group = nhanes[,"RIAGENDR"]) - }, simplify = FALSE) - + })), + c(StdDiffMulti(variable = nhanes[,catVars[1]], group = nhanes[,"RIAGENDR"]), + StdDiffMulti(variable = nhanes[,catVars[2]], group = nhanes[,"RIAGENDR"]), + StdDiffMulti(variable = nhanes[,catVars[3]], group = nhanes[,"RIAGENDR"]), + StdDiffMulti(variable = nhanes[,catVars[4]], group = nhanes[,"RIAGENDR"]))) ## Four groups - sapply(contVars, function(var) { + expect_equal(lapply(contVars, function(var) { StdDiff(variable = nhanes[,var], group = nhanes[,"race"]) - }, simplify = FALSE) + }), + list(StdDiff(variable = nhanes[,contVars[1]], group = nhanes[,"race"]), + StdDiff(variable = nhanes[,contVars[2]], group = nhanes[,"race"]), + StdDiff(variable = nhanes[,contVars[3]], group = nhanes[,"race"]), + StdDiff(variable = nhanes[,contVars[4]], group = nhanes[,"race"]))) - sapply(catVars, function(var) { + expect_equal(lapply(catVars, function(var) { StdDiffMulti(variable = nhanes[,var], group = nhanes[,"race"]) - }, simplify = FALSE) + }), + list(StdDiffMulti(variable = nhanes[,catVars[1]], group = nhanes[,"race"]), + StdDiffMulti(variable = nhanes[,catVars[2]], group = nhanes[,"race"]), + StdDiffMulti(variable = nhanes[,catVars[3]], group = nhanes[,"race"]), + StdDiffMulti(variable = nhanes[,catVars[4]], group = nhanes[,"race"]))) + + ## Two groups + expect_equal(as.numeric(sapply(contVars, function(var) { + svyStdDiff(var, "RIAGENDR", nhanesSvy) + })), + c(svyStdDiff(contVars[1], "RIAGENDR", nhanesSvy), + svyStdDiff(contVars[2], "RIAGENDR", nhanesSvy), + svyStdDiff(contVars[3], "RIAGENDR", nhanesSvy), + svyStdDiff(contVars[4], "RIAGENDR", nhanesSvy))) + + expect_equal(as.numeric(sapply(catVars, function(var) { + svyStdDiffMulti(var, "RIAGENDR", nhanesSvy) + })), + c(svyStdDiffMulti(catVars[1], "RIAGENDR", nhanesSvy), + svyStdDiffMulti(catVars[2], "RIAGENDR", nhanesSvy), + svyStdDiffMulti(catVars[3], "RIAGENDR", nhanesSvy), + svyStdDiffMulti(catVars[4], "RIAGENDR", nhanesSvy))) + + ## Four groups + expect_equal(lapply(contVars, function(var) { + svyStdDiff(var, "race", nhanesSvy) + }), + list(svyStdDiff(contVars[1], "race", nhanesSvy), + svyStdDiff(contVars[2], "race", nhanesSvy), + svyStdDiff(contVars[3], "race", nhanesSvy), + svyStdDiff(contVars[4], "race", nhanesSvy))) + + expect_equal(lapply(catVars, function(var) { + svyStdDiffMulti(var, "race", nhanesSvy) + }), + list(svyStdDiffMulti(catVars[1], "race", nhanesSvy), + svyStdDiffMulti(catVars[2], "race", nhanesSvy), + svyStdDiffMulti(catVars[3], "race", nhanesSvy), + svyStdDiffMulti(catVars[4], "race", nhanesSvy))) + }) From 070c369c6b8727c3c3308818a97ed40bc2084c10 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 14:13:23 -0400 Subject: [PATCH 107/219] Allow illogical result that is consistent with survey package --- test-all.txt | 2 +- tests/testthat/test-smdModules.R | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test-all.txt b/test-all.txt index ccba653..336624a 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1065,7 +1065,7 @@ Unit tests for the CreateTableOne function : ........... St "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" . Unit tests for the modules : ........ -Tests for functions for standardized mean differences : ...................... +Tests for functions for standardized mean differences : ................................................................................... Unit tests for svy* user functions : .... Stratified by E 1 2 3 p test n 150.01 150.00 150.00 diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index 02a9478..3f8df7d 100755 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -410,8 +410,9 @@ test_that("decent results are returned for anomalous/difficult data", { vars1 <- svyby(~ onlyOne, by = ~ RIAGENDR, nhanesSvy, FUN = svyvar)[,2] ## Very small difference is inflated by even smaller variance expect_equal(svyStdDiff("onlyOne", "RIAGENDR", nhanesSvy), - (means1[1] - means1[2]) / sqrt(sum(vars1) / 2)) - expect_equal(svyStdDiff("onlyOne", "RIAGENDR", nhanesSvy), NaN) + (means1[1] - means1[2]) / sqrt(sum(vars1) / 2)) + ## NaN should be the case, but it's not, but it's consistent with survey + ## expect_equal(svyStdDiff("onlyOne", "RIAGENDR", nhanesSvy), NaN) ## 0 because [0]^- = 0, and [1]^T [0]^-1 [1] = 0 expect_equal(svyStdDiffMulti("onlyOne", "RIAGENDR", nhanesSvy), 0) From 1b3605595d37e78ae115471526736fdde0a76239 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 14:41:06 -0400 Subject: [PATCH 108/219] Simplify level column addition in print.(svy)CatTable --- R/print.CatTable.R | 38 +++++++++++++++++--------------------- R/print.ContTable.R | 3 +-- R/print.svyCatTable.R | 31 +++++++++++++------------------ R/print.svyContTable.R | 3 +-- 4 files changed, 32 insertions(+), 43 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index d85eae0..6ff1fce 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -147,9 +147,6 @@ print.CatTable <- function(x, # CatTable object }, simplify = TRUE) # vector with as many elements as strata - ## Provide indicators to show what columns were added. - wasLevelColumnAdded <- FALSE - ### Formatting for printing @@ -211,25 +208,16 @@ print.CatTable <- function(x, # CatTable object colnames(out) <- ModuleCreateStrataNames(CatTable) } - + ## Set the variables names rownames(out) <- CatTableCollapsed[[posFirstNonNullElement]][,"var"] ## Get positions of rows with variable names + ## Used for adding p values in place logiNonEmptyRowNames <- CatTableCollapsed[[posFirstNonNullElement]][, "firstRowInd"] != "" - - ## Add level names if showAllLevels is TRUE. This adds the level column. Need come after column naming. - if (showAllLevels) { - out <- cbind(level = CatTableCollapsed[[posFirstNonNullElement]][,"level"], # Cannot be DF - out) - ## Changed the indicator - wasLevelColumnAdded <- TRUE - } - - ## Add p-values when requested and available - if (test == TRUE & !is.null(attr(CatTable, "pValues"))) { + if (test & !is.null(attr(CatTable, "pValues"))) { ## Pick test types used (used for annonation) testTypes <- c("","exact")[exact] @@ -241,7 +229,7 @@ print.CatTable <- function(x, # CatTable object ## Create an empty p-value column and test column out <- cbind(out, - p = rep("", nrow(out))) # Column for p-values + p = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions out[logiNonEmptyRowNames,"p"] <- pVec @@ -263,16 +251,24 @@ print.CatTable <- function(x, # CatTable object explainString) } - ## Keep column names (strataN does not have correct names if stratification is by multiple variables) + ## Keep column names (strataN does not have correct names + ## if stratification is by multiple variables) outColNames <- colnames(out) - ## Add n at the correct location depending on the number of columns added (level and/or p) - nRow <- c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN) - nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + ## rbind sample size row, padding necessary "" for p value, etc + nRow <- c(strataN, rep("", ncol(out) - length(strataN))) out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames + ## Add level names if showAllLevels is TRUE. + ## This adds the level column to the left, thus, after nRow addition. + ## Need come after column naming. + if (showAllLevels) { + out <- + cbind(level = c("", CatTableCollapsed[[posFirstNonNullElement]][,"level"]), + out) + } + ## Add stratification information to the column header depending on the dimension names(dimnames(out)) <- ModuleReturnDimHeaders(CatTable) diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 831be4d..1b545c2 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -232,8 +232,7 @@ print.ContTable <- function(x, # ContTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - nRow <- strataN - nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + nRow <- c(strataN, rep("", ncol(out) - length(strataN))) # Additional padding to right out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 85c2f07..ffb269e 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -94,9 +94,6 @@ print.svyCatTable <- function(x, # CatTable object }, simplify = TRUE) # vector with as many elements as strata - ## Provide indicators to show what columns were added. - wasLevelColumnAdded <- FALSE - ### Formatting for printing @@ -164,16 +161,6 @@ print.svyCatTable <- function(x, # CatTable object logiNonEmptyRowNames <- CatTableCollapsed[[posFirstNonNullElement]][, "firstRowInd"] != "" - - ## Add level names if showAllLevels is TRUE. This adds the level column. Need come after column naming. - if (showAllLevels) { - out <- cbind(level = CatTableCollapsed[[posFirstNonNullElement]][,"level"], # Cannot be DF - out) - ## Changed the indicator - wasLevelColumnAdded <- TRUE - } - - ## Add p-values when requested and available if (test == TRUE & !is.null(attr(CatTable, "pValues"))) { @@ -209,16 +196,24 @@ print.svyCatTable <- function(x, # CatTable object explainString) } - ## Keep column names (strataN does not have correct names if stratification is by multiple variables) + ## Keep column names (strataN does not have correct names + ## if stratification is by multiple variables) outColNames <- colnames(out) - ## Add n at the correct location depending on the number of columns added (level and/or p) - nRow <- c(level = rep("", wasLevelColumnAdded), # Add "" padding if level added - strataN) - nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + ## rbind sample size row, padding necessary "" for p value, etc + nRow <- c(strataN, rep("", ncol(out) - length(strataN))) out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames + ## Add level names if showAllLevels is TRUE. + ## This adds the level column to the left, thus, after nRow addition. + ## Need come after column naming. + if (showAllLevels) { + out <- + cbind(level = c("", CatTableCollapsed[[posFirstNonNullElement]][,"level"]), + out) + } + ## Add stratification information to the column header depending on the dimension names(dimnames(out)) <- c("", paste0("Stratified by ", attr(CatTable, "strataVarName"))) diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 2f14474..9f6c31d 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -178,8 +178,7 @@ print.svyContTable <- function(x, # ContTable object ## Keep column names (strataN does not have correct names if stratification is by multiple variables) outColNames <- colnames(out) ## Add n at the correct location depending on the number of columns added (level and/or p) - nRow <- strataN - nRow <- c(nRow, rep("", ncol(out) - length(nRow))) # Additional padding to right + nRow <- c(strataN, rep("", ncol(out) - length(strataN))) # Additional padding to right out <- rbind(n = nRow, out) ## Put back the column names (overkill for non-multivariable cases) colnames(out) <- outColNames From bc5efecd4c3470a13671d5a6b4b9debce20d4f63 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 14:58:43 -0400 Subject: [PATCH 109/219] Clean indentation etc --- R/CreateCatTable.R | 2 +- R/CreateContTable.R | 25 ++++++++++++------------- R/CreateTableOne.R | 34 +++++++++++++++++----------------- R/print.CatTable.R | 1 - R/print.svyCatTable.R | 1 - R/svyCreateCatTable.R | 4 ++-- R/svyCreateContTable.R | 2 +- R/svyCreateTableOne.R | 2 +- 8 files changed, 34 insertions(+), 37 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 3fe1324..7915f4e 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -86,7 +86,7 @@ function(vars, # character vector of variable na strata, # character vector of variable names data, # data frame includeNA = FALSE, # include NA as a category - test = TRUE, # whether to put p-values + test = TRUE, # whether to include p-values testApprox = chisq.test, # function for approximation test argsApprox = list(correct = TRUE), # arguments passed to testApprox testExact = fisher.test, # function for exact test diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 27f6e1e..7660b20 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -80,22 +80,21 @@ ##' ##' @export CreateContTable <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - funcNames = c( # can pick a subset of them +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + funcNames = c( # can pick a subset of them "n","miss","p.miss", "mean","sd", "median","p25","p75","min","max", - "skew","kurt" - ), - funcAdditional, # named list of additional functions - test = TRUE, # Whether to put p-values - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { + "skew","kurt"), + funcAdditional, # named list of additional functions + test = TRUE, # Whether to include p-values + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) ## require(e1071) # for skewness and kurtosis diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 85df1dc..441a2fe 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -84,23 +84,23 @@ ##' ##' @export CreateTableOne <- - function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - factorVars, # variables to be transformed to factors - includeNA = FALSE, # include NA as a category (categoricals only) - test = TRUE, # whether to put p-values - ## Test configuration for categorical data - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5), # arguments passed to testExact - ## Test configuration for continuous data - testNormal = oneway.test, # test for normally distributed variables - argsNormal = list(var.equal = TRUE), # arguments passed to testNormal - testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal - ) { +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + factorVars, # variables to be transformed to factors + includeNA = FALSE, # include NA as a category (categoricals only) + test = TRUE, # whether to include p-values + ## Test configuration for categorical data + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5), # arguments passed to testExact + ## Test configuration for continuous data + testNormal = oneway.test, # test for normally distributed variables + argsNormal = list(var.equal = TRUE), # arguments passed to testNormal + testNonNormal = kruskal.test, # test for nonnormally distributed variables + argsNonNormal = list(NULL) # arguments passed to testNonNormal + ) { ### Data check ## Check if the data given is a dataframe diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 6ff1fce..f686f30 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -281,7 +281,6 @@ print.CatTable <- function(x, # CatTable object ## Print CrossTable() if requested if (CrossTable) { - junk <- lapply(attributes(CatTable)$xtabs, gmodels::CrossTable) } diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index ffb269e..47ca443 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -227,7 +227,6 @@ print.svyCatTable <- function(x, # CatTable object ## Print CrossTable() if requested if (CrossTable) { - junk <- lapply(attributes(CatTable)$xtabs, gmodels::CrossTable) } diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index e778108..143fa21 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -28,10 +28,10 @@ function(vars, # character vector of variable names strata, # character vector of variable names data, # survey design object includeNA = FALSE, # include NA as a category - test = TRUE, # whether to put p-values + test = TRUE, # whether to include p-values testApprox = svyTestChisq, # function for approximation test (only choice) argsApprox = NULL, # arguments passed to testApprox - smd = TRUE + smd = TRUE # whether to include standardize mean differences ) { ### Data check diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index ae98935..8e6066b 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -28,7 +28,7 @@ svyCreateContTable <- function(vars, # character vector of variable names strata, # character vector of variable names data, # survey design data - test = TRUE, # Whether to put p-values + test = TRUE, # Whether to include p-values testNormal = svyTestNormal, # test for normally distributed variables argsNormal = list(method = "Wald"), # arguments passed to testNormal testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 35c2f19..d379e8a 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -74,7 +74,7 @@ function(vars, # character vector of variable data, # data frame factorVars, # variables to be transformed to factors includeNA = FALSE, # include NA as a category (categoricals only) - test = TRUE, # whether to put p-values + test = TRUE, # whether to include p-values ## Test configuration for categorical data testApprox = svyTestChisq, # function for approximation test (only choice) argsApprox = NULL, # arguments passed to testApprox From 7976bf3b5114472d227fa7848452305425a2d8fb Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:34:05 -0400 Subject: [PATCH 110/219] Add SMD inclusion to all constructors --- R/CreateCatTable.R | 42 +++++++++++++++++++++++++++++++----------- R/CreateContTable.R | 35 ++++++++++++++++++++++++++--------- R/CreateTableOne.R | 10 +++++++--- R/svyCreateCatTable.R | 7 +++---- R/svyCreateContTable.R | 20 ++++++++++++++++++-- R/svyCreateTableOne.R | 10 +++++++--- 6 files changed, 92 insertions(+), 32 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 7915f4e..e6c91ef 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -14,6 +14,7 @@ ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. ##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. ##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) ##' @seealso @@ -82,15 +83,16 @@ ##' ##' @export CreateCatTable <- -function(vars, # character vector of variable names - strata, # character vector of variable names - data, # data frame - includeNA = FALSE, # include NA as a category - test = TRUE, # whether to include p-values - testApprox = chisq.test, # function for approximation test - argsApprox = list(correct = TRUE), # arguments passed to testApprox - testExact = fisher.test, # function for exact test - argsExact = list(workspace = 2*10^5) # arguments passed to testExact +function(vars, # character vector of variable names + strata, # character vector of variable names + data, # data frame + includeNA = FALSE, # include NA as a category + test = TRUE, # whether to include p-values + testApprox = chisq.test, # function for approximation test + argsApprox = list(correct = TRUE), # arguments passed to testApprox + testExact = fisher.test, # function for exact test + argsExact = list(workspace = 2*10^5), # arguments passed to testExact + smd = TRUE # whether to include standardize mean differences ) { ### Data check @@ -129,7 +131,6 @@ function(vars, # character vector of variable na } ### Actual descriptive statistics are calculated here. - ## strata--variable-CreateTableForOneVar structure ## Devide by strata result <- by(data = dat, INDICES = strata, # INDICES can be a multi-column data frame @@ -160,6 +161,10 @@ function(vars, # character vector of variable na pValues <- NULL listXtabs <- list() + ## Create a single variable representation of multivariable stratification + ## Respect ordering of levels in by() + strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + ## Only when test is asked for if (test) { lstXtabsPVals <- @@ -175,6 +180,20 @@ function(vars, # character vector of variable na listXtabs <- lstXtabsPVals$xtabs } + +### Perform SMD when requested + smds <- NULL + + ## Only when SMD is asked for + if (smd) { + ## list of smds + smds <- sapply(dat, function(var) { + StdDiffMulti(variable = var, group = strataVar) + }, simplify = FALSE) + smds <- do.call(rbind, smds) + } + + ## Return object ## Give an S3 class class(result) <- c("CatTable", class(result)) @@ -182,7 +201,8 @@ function(vars, # character vector of variable na ## Give additional attributes attributes(result) <- c(attributes(result), list(pValues = pValues), - list(xtabs = listXtabs)) + list(xtabs = listXtabs), + list(smd = smds)) ## Return return(result) diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 7660b20..949ac9b 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -15,6 +15,7 @@ ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. ##' @return An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. ##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) ##' @seealso @@ -83,17 +84,18 @@ CreateContTable <- function(vars, # character vector of variable names strata, # character vector of variable names data, # data frame - funcNames = c( # can pick a subset of them + funcNames = c( # can pick a subset of them "n","miss","p.miss", "mean","sd", "median","p25","p75","min","max", "skew","kurt"), - funcAdditional, # named list of additional functions + funcAdditional, # named list of additional functions test = TRUE, # Whether to include p-values testNormal = oneway.test, # test for normally distributed variables argsNormal = list(var.equal = TRUE), # arguments passed to testNormal testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal + argsNonNormal = list(NULL), # arguments passed to testNonNormal + smd = TRUE # whether to include standardize mean differences ) { ## Require dependencies (DELETE before CRAN release. Use Depends in DESCRIPTION) @@ -207,15 +209,16 @@ function(vars, # character vector of variable ## Initialize to avoid error when it does not exist at the attribute assignment pValues <- NULL + ## Create a single variable representation of multivariable stratification + ## Respect ordering of levels in by() + strataVar <- ModuleCreateStrataVarAsFactor(result, strata) ## Only when test is asked for - if (test == TRUE) { - - ## Create a single variable representation of multivariable stratification - strataVar <- ModuleCreateStrataVarAsFactor(result, strata) + if (test) { ## Loop over variables in dat, and obtain p values for two tests - ## DF = 6 when there are 8 levels (one empty), i.e., empty strata dropped by oneway.test/kruskal.test + ## DF = 6 when there are 8 levels (one empty), + ## i.e., empty strata dropped by oneway.test/kruskal.test pValues <- sapply(X = dat, FUN = function(var) { @@ -232,13 +235,27 @@ function(vars, # character vector of variable } # Conditional for test == TRUE ends here. +### Perform SMD when requested + smds <- NULL + + ## Only when SMD is asked for + if (smd) { + ## list of smds + smds <- sapply(dat, function(var) { + StdDiff(variable = var, group = strataVar) + }, simplify = FALSE) + smds <- do.call(rbind, smds) + } + + ## Return object ## Give an S3 class class(result) <- c("ContTable", class(result)) ## Give additional attributes attributes(result) <- c(attributes(result), - list(pValues = pValues)) + list(pValues = pValues), + list(smd = smds)) ## Return return(result) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 441a2fe..a3a116d 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -16,6 +16,7 @@ ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. ##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{TableOne}, which really is a list of three objects. ##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} ##' @return \item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} @@ -99,7 +100,8 @@ function(vars, # character vector of variab testNormal = oneway.test, # test for normally distributed variables argsNormal = list(var.equal = TRUE), # arguments passed to testNormal testNonNormal = kruskal.test, # test for nonnormally distributed variables - argsNonNormal = list(NULL) # arguments passed to testNonNormal + argsNonNormal = list(NULL), # arguments passed to testNonNormal + smd = TRUE # whether to include standardize mean differences ) { ### Data check @@ -160,14 +162,16 @@ function(vars, # character vector of variab testNormal = testNormal, argsNormal = argsNormal, testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal) + argsNonNormal = argsNonNormal, + smd = smd) argsCreateCatTable <- list(data = data, includeNA = includeNA, test = test, testApprox = testApprox, argsApprox = argsApprox, testExact = testExact, - argsExact = argsExact) + argsExact = argsExact, + smd = smd) ## Add strata = strata for argument only if strata is given if (!missing(strata)) { diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 143fa21..991fe20 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -12,6 +12,7 @@ ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. ##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{svychisq}. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{svyCatTable}. ##' @author Kazuki Yoshida ##' @seealso @@ -117,13 +118,11 @@ function(vars, # character vector of variable names smds <- NULL ## Only when SMD is asked for - ## TURN OFF FOR NOW - if (smd & FALSE) { + if (smd) { ## list of smds smds <- sapply(vars, function(var) { - svyStdDiffMulti(varName = var, groupName = strataVarName, design = data) + svyStdDiffMulti(varName = var, groupName = "..strataVar..", design = data) }, simplify = FALSE) - smds <- do.call(rbind, smds) } diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 8e6066b..29ee745 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -13,6 +13,7 @@ ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{svyranktest}. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. ##' @return An object of class \code{svyContTable}. ##' @author Kazuki Yoshida ##' @seealso @@ -32,7 +33,8 @@ function(vars, # character vector of variable n testNormal = svyTestNormal, # test for normally distributed variables argsNormal = list(method = "Wald"), # arguments passed to testNormal testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables - argsNonNormal = NULL # arguments passed to testNonNormal + argsNonNormal = NULL, # arguments passed to testNonNormal + smd = TRUE # whether to include standardize mean differences ) { ### Data check @@ -132,13 +134,27 @@ function(vars, # character vector of variable n } # Conditional for test == TRUE ends here. +### Perform SMD when requested + smds <- NULL + + ## Only when SMD is asked for + if (smd) { + ## list of smds + smds <- sapply(vars, function(var) { + svyStdDiff(varName = var, groupName = "..strataVar..", design = data) + }, simplify = FALSE) + smds <- do.call(rbind, smds) + } + + ## Return object ## Give an S3 class class(result) <- c("svyContTable", "ContTable", class(result)) ## Give additional attributes attributes(result) <- c(attributes(result), - list(pValues = pValues)) + list(pValues = pValues), + list(smd = smds)) ## Return return(result) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index d379e8a..38b839b 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -14,6 +14,7 @@ ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. ##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{svychisq}. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. +##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{svyTableOne}, which really is a list of three objects. ##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} ##' @return \item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} @@ -82,7 +83,8 @@ function(vars, # character vector of variable testNormal = svyTestNormal, # test for normally distributed variables argsNormal = list(method = "Wald"), # arguments passed to testNormal testNonNormal = svyTestNonNormal, # test for nonnormally distributed variables - argsNonNormal = NULL # arguments passed to testNonNormal + argsNonNormal = NULL, # arguments passed to testNonNormal + smd = TRUE # whether to include standardize mean differences ) { ### Data check @@ -143,12 +145,14 @@ function(vars, # character vector of variable testNormal = testNormal, argsNormal = argsNormal, testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal) + argsNonNormal = argsNonNormal, + smd = smd) argsCreateCatTable <- list(data = data, includeNA = includeNA, test = test, testApprox = testApprox, - argsApprox = argsApprox) + argsApprox = argsApprox, + smd = smd) ## Add strata = strata for argument only if strata is given if (!missing(strata)) { From c23d93ab30334db6921d50f452f4e7f05a3cce90 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:40:28 -0400 Subject: [PATCH 111/219] Add dummy object ..strataVar.. to avoid CRAN check note --- R/svyCreateCatTable.R | 2 ++ R/svyCreateContTable.R | 2 ++ 2 files changed, 4 insertions(+) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 991fe20..f49c8b9 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -56,6 +56,8 @@ function(vars, # character vector of variable names ## Keeps non-existing levels data$variables$..strataVar.. <- interaction(strata, sep = ":") strataVarLevels <- levels(data$variables$..strataVar..) + ## Dummy and dumb object to avoid CRAN check "no visible binding for global variable" + ..strataVar.. <- NULL ## Convert to a factor if it is not a factor already. (categorical version only) ## Not done on factors, to avoid dropping zero levels. diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 29ee745..51c7ca2 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -59,6 +59,8 @@ function(vars, # character vector of variable n ## Keeps non-existing levels data$variables$..strataVar.. <- interaction(strata, sep = ":") strataVarLevels <- levels(data$variables$..strataVar..) + ## Dummy and dumb object to avoid CRAN check "no visible binding for global variable" + ..strataVar.. <- NULL ## Handle non-numeric elements (intergers give TRUE, and pass) if(any(!sapply(data$variables[vars], is.numeric))){ From 6e0989cf073f3dde22b3ccb3be1353687240ca37 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:41:05 -0400 Subject: [PATCH 112/219] Add changes in manual for SMD inclusion --- man/CreateCatTable.Rd | 5 ++++- man/CreateContTable.Rd | 4 +++- man/CreateTableOne.Rd | 4 +++- man/svyCreateCatTable.Rd | 4 +++- man/svyCreateContTable.Rd | 4 +++- man/svyCreateTableOne.Rd | 4 +++- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/man/CreateCatTable.Rd b/man/CreateCatTable.Rd index ced763a..2e4651e 100644 --- a/man/CreateCatTable.Rd +++ b/man/CreateCatTable.Rd @@ -6,7 +6,8 @@ \usage{ CreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), - testExact = fisher.test, argsExact = list(workspace = 2 * 10^5)) + testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), + smd = TRUE) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} @@ -26,6 +27,8 @@ CreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, \item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} \item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. diff --git a/man/CreateContTable.Rd b/man/CreateContTable.Rd index 9135f9d..6409e59 100644 --- a/man/CreateContTable.Rd +++ b/man/CreateContTable.Rd @@ -8,7 +8,7 @@ CreateContTable(vars, strata, data, funcNames = c("n", "miss", "p.miss", "mean", "sd", "median", "p25", "p75", "min", "max", "skew", "kurt"), funcAdditional, test = TRUE, testNormal = oneway.test, argsNormal = list(var.equal = TRUE), testNonNormal = kruskal.test, - argsNonNormal = list(NULL)) + argsNonNormal = list(NULL), smd = TRUE) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} @@ -30,6 +30,8 @@ CreateContTable(vars, strata, data, funcNames = c("n", "miss", "p.miss", \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated.} } \value{ An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 2d6c6ea..73c977b 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -8,7 +8,7 @@ CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), testExact = fisher.test, argsExact = list(workspace = 2 * 10^5), testNormal = oneway.test, argsNormal = list(var.equal = TRUE), - testNonNormal = kruskal.test, argsNonNormal = list(NULL)) + testNonNormal = kruskal.test, argsNonNormal = list(NULL), smd = TRUE) } \arguments{ \item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used.} @@ -38,6 +38,8 @@ CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ An object of class \code{TableOne}, which really is a list of three objects. diff --git a/man/svyCreateCatTable.Rd b/man/svyCreateCatTable.Rd index 5363dcd..cc1fc40 100644 --- a/man/svyCreateCatTable.Rd +++ b/man/svyCreateCatTable.Rd @@ -5,7 +5,7 @@ \title{Create an object summarizing categorical variables for weighted data} \usage{ svyCreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, - testApprox = svyTestChisq, argsApprox = NULL) + testApprox = svyTestChisq, argsApprox = NULL, smd = TRUE) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} @@ -21,6 +21,8 @@ svyCreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, \item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{svychisq}.} \item{argsApprox}{A named list of arguments passed to the function specified in testApprox.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ An object of class \code{svyCatTable}. diff --git a/man/svyCreateContTable.Rd b/man/svyCreateContTable.Rd index 1a1c921..144a082 100644 --- a/man/svyCreateContTable.Rd +++ b/man/svyCreateContTable.Rd @@ -6,7 +6,7 @@ \usage{ svyCreateContTable(vars, strata, data, test = TRUE, testNormal = svyTestNormal, argsNormal = list(method = "Wald"), - testNonNormal = svyTestNonNormal, argsNonNormal = NULL) + testNonNormal = svyTestNonNormal, argsNonNormal = NULL, smd = TRUE) } \arguments{ \item{vars}{Variable(s) to be summarized given as a character vector.} @@ -24,6 +24,8 @@ svyCreateContTable(vars, strata, data, test = TRUE, \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{svyranktest}.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated.} } \value{ An object of class \code{svyContTable}. diff --git a/man/svyCreateTableOne.Rd b/man/svyCreateTableOne.Rd index a314912..e8f6009 100644 --- a/man/svyCreateTableOne.Rd +++ b/man/svyCreateTableOne.Rd @@ -7,7 +7,7 @@ svyCreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, test = TRUE, testApprox = svyTestChisq, argsApprox = NULL, testNormal = svyTestNormal, argsNormal = list(method = "Wald"), - testNonNormal = svyTestNonNormal, argsNonNormal = NULL) + testNonNormal = svyTestNonNormal, argsNonNormal = NULL, smd = TRUE) } \arguments{ \item{vars}{Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used.} @@ -33,6 +33,8 @@ svyCreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, \item{testNonNormal}{A function used to perform the nonparametric tests. The default is \code{svyranktest}.} \item{argsNonNormal}{A named list of arguments passed to the function specified in \code{testNonNormal}.} + +\item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ An object of class \code{svyTableOne}, which really is a list of three objects. From 4ad06c381284f33adcbd371f2a630815368b1fe5 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:44:48 -0400 Subject: [PATCH 113/219] Include SMDs in summary method output --- R/summary.CatTable.R | 6 ++++++ R/summary.ContTable.R | 6 ++++++ R/summary.svyCatTable.R | 6 ++++++ R/summary.svyContTable.R | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/R/summary.CatTable.R b/R/summary.CatTable.R index 052b18f..b9e3be2 100644 --- a/R/summary.CatTable.R +++ b/R/summary.CatTable.R @@ -106,4 +106,10 @@ summary.CatTable <- function(object, digits = 1, ...) { cat("\np-values\n") print(attributes(CatTable)$pValues) } + + ## Print SMDs if it exist + if (!is.null(attributes(CatTable)$smd)) { + cat("\nStandardize mean differences\n") + print(attributes(CatTable)$smd) + } } diff --git a/R/summary.ContTable.R b/R/summary.ContTable.R index 869e0aa..adec7e2 100644 --- a/R/summary.ContTable.R +++ b/R/summary.ContTable.R @@ -46,4 +46,10 @@ summary.ContTable <- function(object, digits = 2, ...) { cat("\np-values\n") print(attributes(object)$pValues) } + + ## Print SMDs if it exist + if (!is.null(attributes(object)$smd)) { + cat("\nStandardize mean differences\n") + print(attributes(object)$smd) + } } diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index 0340112..5c9e977 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -88,4 +88,10 @@ summary.svyCatTable <- function(object, digits = 1, ...) { cat("\np-values\n") print(attributes(CatTable)$pValues) } + + ## Print SMDs if it exist + if (!is.null(attributes(CatTable)$smd)) { + cat("\nStandardize mean differences\n") + print(attributes(CatTable)$smd) + } } diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 921ef14..926ec8f 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -33,4 +33,10 @@ summary.svyContTable <- function(object, digits = 2, ...) { cat("\np-values\n") print(attributes(object)$pValues) } + + ## Print SMDs if it exist + if (!is.null(attributes(object)$smd)) { + cat("\nStandardize mean differences\n") + print(attributes(object)$smd) + } } From 1a918ac77fa8d49778d3d86602d83bb945f72e8a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:52:13 -0400 Subject: [PATCH 114/219] Toggle smd to FALSE if no strata is given to constructors --- R/CreateCatTable.R | 1 + R/CreateContTable.R | 1 + R/CreateTableOne.R | 3 ++- R/svyCreateCatTable.R | 1 + R/svyCreateContTable.R | 1 + R/svyCreateTableOne.R | 3 ++- 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index e6c91ef..6b8dfd0 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -110,6 +110,7 @@ function(vars, # character vector of variable n ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Create strata data frame (data frame with only strata variables) strata <- ModuleReturnStrata(strata, data) diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 949ac9b..a66bc23 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -116,6 +116,7 @@ function(vars, # character vector of variable ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Create strata data frame (data frame with only strata variables) strata <- ModuleReturnStrata(strata, data) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index a3a116d..dd88aad 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -128,7 +128,8 @@ function(vars, # character vector of variab } ## Toggle test FALSE if no strata is given - test <- ModuleReturnFalseIfNoStrata(strata, test) + test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Get the classes of the variables varClasses <- lapply(data[vars], class) diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index f49c8b9..2b2620c 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -47,6 +47,7 @@ function(vars, # character vector of variable names ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Create strata data frame (data frame with only strata variables) ## FIXME: This changes type of strata; not a good practice diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 51c7ca2..8215f4e 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -50,6 +50,7 @@ function(vars, # character vector of variable n ## Toggle test FALSE if no strata test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Create strata data frame (data frame with only strata variables) ## FIXME: This changes type of strata; not a good practice diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 38b839b..9675304 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -111,7 +111,8 @@ function(vars, # character vector of variable } ## Toggle test FALSE if no strata is given - test <- ModuleReturnFalseIfNoStrata(strata, test) + test <- ModuleReturnFalseIfNoStrata(strata, test) + smd <- ModuleReturnFalseIfNoStrata(strata, smd) ## Get the classes of the variables varClasses <- lapply(data$variables[vars], class) From bd0e29ca767d376addc3ddc3465a58fcb2392f11 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 15:54:02 -0400 Subject: [PATCH 115/219] Fix indentation of (svy)CreateTableOne --- R/CreateTableOne.R | 234 ++++++++++++++++++------------------ R/svyCreateTableOne.R | 272 +++++++++++++++++++++--------------------- 2 files changed, 253 insertions(+), 253 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index dd88aad..b6f1f64 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -105,152 +105,152 @@ function(vars, # character vector of variab ) { ### Data check - ## Check if the data given is a dataframe - ModuleStopIfNotDataFrame(data) + ## Check if the data given is a dataframe + ModuleStopIfNotDataFrame(data) - ## Check if vars argument is missing. If so, add all names in data. - if (missing(vars)) { - vars <- names(data) - } + ## Check if vars argument is missing. If so, add all names in data. + if (missing(vars)) { + vars <- names(data) + } - ## Check if variables exist. Drop them if not. - vars <- ModuleReturnVarsExist(vars, data) + ## Check if variables exist. Drop them if not. + vars <- ModuleReturnVarsExist(vars, data) - ## Abort if no variables exist at this point - ModuleStopIfNoVarsLeft(vars) + ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) - ## Factor conversions if the factorVars argument exist - if (!missing(factorVars)) { - ## Check if variables exist. Drop them if not. - factorVars <- ModuleReturnVarsExist(factorVars, data) - ## Convert to factor - data[factorVars] <- lapply(data[factorVars], factor) - } + ## Factor conversions if the factorVars argument exist + if (!missing(factorVars)) { + ## Check if variables exist. Drop them if not. + factorVars <- ModuleReturnVarsExist(factorVars, data) + ## Convert to factor + data[factorVars] <- lapply(data[factorVars], factor) + } - ## Toggle test FALSE if no strata is given + ## Toggle test FALSE if no strata is given test <- ModuleReturnFalseIfNoStrata(strata, test) smd <- ModuleReturnFalseIfNoStrata(strata, smd) - ## Get the classes of the variables - varClasses <- lapply(data[vars], class) + ## Get the classes of the variables + varClasses <- lapply(data[vars], class) - ## Classify as varFactors if any one of these classes are contained - varFactors <-sapply(varClasses, function(VEC) { - any(VEC %in% c("factor", "ordered", "logical", "character")) - }) - varFactors <- names(varFactors)[varFactors] + ## Classify as varFactors if any one of these classes are contained + varFactors <-sapply(varClasses, function(VEC) { + any(VEC %in% c("factor", "ordered", "logical", "character")) + }) + varFactors <- names(varFactors)[varFactors] - ## Classify as varNumerics if any one of these classes are contained - varNumerics <-sapply(varClasses, function(VEC) { - any(VEC %in% c("numeric", "integer")) - }) - varNumerics <- names(varNumerics)[varNumerics] + ## Classify as varNumerics if any one of these classes are contained + varNumerics <-sapply(varClasses, function(VEC) { + any(VEC %in% c("numeric", "integer")) + }) + varNumerics <- names(varNumerics)[varNumerics] - ## Drop variables that do not meet either because it is unsupported - varDrop <- setdiff(vars, c(varFactors, varNumerics)) - if (length(varDrop) > 0) { - warning("Dropping variable(s) ", paste0(varDrop, sep = " "), - " due to unsupported class.\n") - vars <- setdiff(vars, varDrop) - } + ## Drop variables that do not meet either because it is unsupported + varDrop <- setdiff(vars, c(varFactors, varNumerics)) + if (length(varDrop) > 0) { + warning("Dropping variable(s) ", paste0(varDrop, sep = " "), + " due to unsupported class.\n") + vars <- setdiff(vars, varDrop) + } - ## Create a logical vector indicator for factors (vars in varFactors = TRUE) - logiFactors <- vars %in% varFactors + ## Create a logical vector indicator for factors (vars in varFactors = TRUE) + logiFactors <- vars %in% varFactors - ## Create lists of arguments - argsCreateContTable <- list(data = data, - test = test, - testNormal = testNormal, - argsNormal = argsNormal, - testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal, - smd = smd) - argsCreateCatTable <- list(data = data, - includeNA = includeNA, - test = test, - testApprox = testApprox, - argsApprox = argsApprox, - testExact = testExact, - argsExact = argsExact, - smd = smd) + ## Create lists of arguments + argsCreateContTable <- list(data = data, + test = test, + testNormal = testNormal, + argsNormal = argsNormal, + testNonNormal = testNonNormal, + argsNonNormal = argsNonNormal, + smd = smd) + argsCreateCatTable <- list(data = data, + includeNA = includeNA, + test = test, + testApprox = testApprox, + argsApprox = argsApprox, + testExact = testExact, + argsExact = argsExact, + smd = smd) - ## Add strata = strata for argument only if strata is given - if (!missing(strata)) { + ## Add strata = strata for argument only if strata is given + if (!missing(strata)) { - ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. - ## Must not be place outside if (!missing(strata)) { }. - dfStrata <- ModuleReturnStrata(strata, data) - ## Return variable names. Code inefficient in exchange for code simplicity. - strata <- names(dfStrata) + ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. + ## Must not be place outside if (!missing(strata)) { }. + dfStrata <- ModuleReturnStrata(strata, data) + ## Return variable names. Code inefficient in exchange for code simplicity. + strata <- names(dfStrata) - ## Create lists of arguments including strata - argsCreateContTable <- c(list(strata = strata), argsCreateContTable) - argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) - } + ## Create lists of arguments including strata + argsCreateContTable <- c(list(strata = strata), argsCreateContTable) + argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) + } - ## Condition on the absence of factor/numeric - if (length(varNumerics) == 0) { - ## No numerics - message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') - CatTable <- do.call(CreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) - return(CatTable) + ## Condition on the absence of factor/numeric + if (length(varNumerics) == 0) { + ## No numerics + message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) + return(CatTable) - } else if (length(varFactors) == 0) { - ## No factors - message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') - ContTable <- do.call(CreateContTable, - args = c(list(vars = varNumerics), argsCreateContTable)) - return(ContTable) + } else if (length(varFactors) == 0) { + ## No factors + message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') + ContTable <- do.call(CreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + return(ContTable) ### Proceed if both types of variables are present (both factors and numerics) - } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { + } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { - ## Create a list of constructors - listOfConstructors <- list(CreateContTable = CreateContTable, - CreateCatTable = CreateCatTable) - ## CreateCatTable for categorical. CreateContTable for continuous. - listOfConstructors <- listOfConstructors[logiFactors + 1] - ## Create a list of arguments - listOfArgs <- list(argsCreateContTable = argsCreateContTable, - argsCreateCatTable = argsCreateCatTable) - ## argsCreateCatTable for categorical. argsCreateContTable for continuous. - listOfArgs <- listOfArgs[logiFactors + 1] + ## Create a list of constructors + listOfConstructors <- list(CreateContTable = CreateContTable, + CreateCatTable = CreateCatTable) + ## CreateCatTable for categorical. CreateContTable for continuous. + listOfConstructors <- listOfConstructors[logiFactors + 1] + ## Create a list of arguments + listOfArgs <- list(argsCreateContTable = argsCreateContTable, + argsCreateCatTable = argsCreateCatTable) + ## argsCreateCatTable for categorical. argsCreateContTable for continuous. + listOfArgs <- listOfArgs[logiFactors + 1] - ## Create a list of tables by looping over variables/constructors/arguments - TableOne <- sapply(seq_along(listOfConstructors), - FUN = function(i) { + ## Create a list of tables by looping over variables/constructors/arguments + TableOne <- sapply(seq_along(listOfConstructors), + FUN = function(i) { - args <- c(list(vars = vars[i]), # vector element - listOfArgs[[i]]) # list element + args <- c(list(vars = vars[i]), # vector element + listOfArgs[[i]]) # list element - do.call(listOfConstructors[[i]], # list element - args = args) - }, - simplify = FALSE) + do.call(listOfConstructors[[i]], # list element + args = args) + }, + simplify = FALSE) - ## Give variable names to the result object - names(TableOne) <- vars + ## Give variable names to the result object + names(TableOne) <- vars - ## Create ContTable and CatTable objects (this is redundant, but easy) - ## Aggregated ContTable - ContTable <- do.call(CreateContTable, - args = c(list(vars = varNumerics), argsCreateContTable)) - ## Aggregated CatTable - CatTable <- do.call(CreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) + ## Create ContTable and CatTable objects (this is redundant, but easy) + ## Aggregated ContTable + ContTable <- do.call(CreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + ## Aggregated CatTable + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) - ## Create a list for output - TableOneObject <- list(TableOne = TableOne, - ContTable = ContTable, - CatTable = CatTable) + ## Create a list for output + TableOneObject <- list(TableOne = TableOne, + ContTable = ContTable, + CatTable = CatTable) - ## Give a class - class(TableOneObject) <- "TableOne" + ## Give a class + class(TableOneObject) <- "TableOne" - ## Return the object - return(TableOneObject) - } + ## Return the object + return(TableOneObject) } +} diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 9675304..f5c0901 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -88,150 +88,150 @@ function(vars, # character vector of variable ) { ### Data check - ## Check if the data given is a dataframe - StopIfNotSurveyDesign(data) + ## Check if the data given is a dataframe + StopIfNotSurveyDesign(data) - ## Check if vars argument is missing. If so, add all names in data. - if (missing(vars)) { - vars <- names(data$variables) - } + ## Check if vars argument is missing. If so, add all names in data. + if (missing(vars)) { + vars <- names(data$variables) + } - ## Check if variables exist. Drop them if not. - vars <- ModuleReturnVarsExist(vars, data$variables) + ## Check if variables exist. Drop them if not. + vars <- ModuleReturnVarsExist(vars, data$variables) - ## Abort if no variables exist at this point - ModuleStopIfNoVarsLeft(vars) + ## Abort if no variables exist at this point + ModuleStopIfNoVarsLeft(vars) - ## Factor conversions if the factorVars argument exist - if (!missing(factorVars)) { - ## Check if variables exist. Drop them if not. - factorVars <- ModuleReturnVarsExist(factorVars, data$variables) - ## Convert to factor - data$variables[factorVars] <- lapply(data$variables[factorVars], factor) - } + ## Factor conversions if the factorVars argument exist + if (!missing(factorVars)) { + ## Check if variables exist. Drop them if not. + factorVars <- ModuleReturnVarsExist(factorVars, data$variables) + ## Convert to factor + data$variables[factorVars] <- lapply(data$variables[factorVars], factor) + } - ## Toggle test FALSE if no strata is given + ## Toggle test FALSE if no strata is given test <- ModuleReturnFalseIfNoStrata(strata, test) smd <- ModuleReturnFalseIfNoStrata(strata, smd) - ## Get the classes of the variables - varClasses <- lapply(data$variables[vars], class) - - ## Classify as varFactors if any one of these classes are contained - varFactors <- sapply(varClasses, function(VEC) { - any(VEC %in% c("factor", "ordered", "logical", "character")) - }) - varFactors <- names(varFactors)[varFactors] - - ## Classify as varNumerics if any one of these classes are contained - varNumerics <- sapply(varClasses, function(VEC) { - any(VEC %in% c("numeric", "integer")) - }) - varNumerics <- names(varNumerics)[varNumerics] - - ## Drop variables that do not meet either because it is unsupported - varDrop <- setdiff(vars, c(varFactors, varNumerics)) - if (length(varDrop) > 0) { - warning("Dropping variable(s) ", paste0(varDrop, sep = " "), - " due to unsupported class.\n") - vars <- setdiff(vars, varDrop) - } - - ## Create a logical vector indicator for factors (vars in varFactors = TRUE) - logiFactors <- vars %in% varFactors - - ## Create lists of arguments - argsCreateContTable <- list(data = data, - test = test, - testNormal = testNormal, - argsNormal = argsNormal, - testNonNormal = testNonNormal, - argsNonNormal = argsNonNormal, - smd = smd) - argsCreateCatTable <- list(data = data, - includeNA = includeNA, - test = test, - testApprox = testApprox, - argsApprox = argsApprox, - smd = smd) - - ## Add strata = strata for argument only if strata is given - if (!missing(strata)) { - - ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. - ## Must not be place outside if (!missing(strata)) { }. - dfStrata <- ModuleReturnStrata(strata, data$variable) - ## Return variable names. Code inefficient in exchange for code simplicity. - strata <- names(dfStrata) - - ## Create lists of arguments including strata - argsCreateContTable <- c(list(strata = strata), argsCreateContTable) - argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) - } - - - ## Condition on the absence of factor/numeric - if (length(varNumerics) == 0) { - ## No numerics - message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') - CatTable <- do.call(svyCreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) - return(CatTable) - - } else if (length(varFactors) == 0) { - ## No factors - message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') - ContTable <- do.call(svyCreateContTable, - args = c(list(vars = varNumerics), argsCreateContTable)) - return(ContTable) + ## Get the classes of the variables + varClasses <- lapply(data$variables[vars], class) + + ## Classify as varFactors if any one of these classes are contained + varFactors <- sapply(varClasses, function(VEC) { + any(VEC %in% c("factor", "ordered", "logical", "character")) + }) + varFactors <- names(varFactors)[varFactors] + + ## Classify as varNumerics if any one of these classes are contained + varNumerics <- sapply(varClasses, function(VEC) { + any(VEC %in% c("numeric", "integer")) + }) + varNumerics <- names(varNumerics)[varNumerics] + + ## Drop variables that do not meet either because it is unsupported + varDrop <- setdiff(vars, c(varFactors, varNumerics)) + if (length(varDrop) > 0) { + warning("Dropping variable(s) ", paste0(varDrop, sep = " "), + " due to unsupported class.\n") + vars <- setdiff(vars, varDrop) + } + + ## Create a logical vector indicator for factors (vars in varFactors = TRUE) + logiFactors <- vars %in% varFactors + + ## Create lists of arguments + argsCreateContTable <- list(data = data, + test = test, + testNormal = testNormal, + argsNormal = argsNormal, + testNonNormal = testNonNormal, + argsNonNormal = argsNonNormal, + smd = smd) + argsCreateCatTable <- list(data = data, + includeNA = includeNA, + test = test, + testApprox = testApprox, + argsApprox = argsApprox, + smd = smd) + + ## Add strata = strata for argument only if strata is given + if (!missing(strata)) { + + ## Check strata. This returns a DF. Returns a "Overall" DF if strata is missing. + ## Must not be place outside if (!missing(strata)) { }. + dfStrata <- ModuleReturnStrata(strata, data$variable) + ## Return variable names. Code inefficient in exchange for code simplicity. + strata <- names(dfStrata) + + ## Create lists of arguments including strata + argsCreateContTable <- c(list(strata = strata), argsCreateContTable) + argsCreateCatTable <- c(list(strata = strata), argsCreateCatTable) + } + + + ## Condition on the absence of factor/numeric + if (length(varNumerics) == 0) { + ## No numerics + message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') + CatTable <- do.call(svyCreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) + return(CatTable) + + } else if (length(varFactors) == 0) { + ## No factors + message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') + ContTable <- do.call(svyCreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + return(ContTable) ### Proceed if both types of variables are present (both factors and numerics) - } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { - - ## Create a list of constructors - listOfConstructors <- list(CreateContTable = svyCreateContTable, - CreateCatTable = svyCreateCatTable) - ## CreateCatTable for categorical. CreateContTable for continuous. - listOfConstructors <- listOfConstructors[logiFactors + 1] - ## Create a list of arguments - listOfArgs <- list(argsCreateContTable = argsCreateContTable, - argsCreateCatTable = argsCreateCatTable) - ## argsCreateCatTable for categorical. argsCreateContTable for continuous. - listOfArgs <- listOfArgs[logiFactors + 1] - - ## Create a list of tables by looping over variables/constructors/arguments - TableOne <- sapply(seq_along(listOfConstructors), - FUN = function(i) { - - args <- c(list(vars = vars[i]), # vector element - listOfArgs[[i]]) # list element - - do.call(listOfConstructors[[i]], # list element - args = args) - }, - simplify = FALSE) - - ## Give variable names to the result object - names(TableOne) <- vars - - - ## Create ContTable and CatTable objects (this is redundant, but easy) - ## Aggregated ContTable - ContTable <- do.call(svyCreateContTable, - args = c(list(vars = varNumerics), argsCreateContTable)) - ## Aggregated CatTable - CatTable <- do.call(svyCreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) - - ## Create a list for output - TableOneObject <- list(TableOne = TableOne, - ContTable = ContTable, - CatTable = CatTable) - - ## Give a class - class(TableOneObject) <- c("svyTableOne", "TableOne") - - ## Return the object - return(TableOneObject) - } + } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { + + ## Create a list of constructors + listOfConstructors <- list(CreateContTable = svyCreateContTable, + CreateCatTable = svyCreateCatTable) + ## CreateCatTable for categorical. CreateContTable for continuous. + listOfConstructors <- listOfConstructors[logiFactors + 1] + ## Create a list of arguments + listOfArgs <- list(argsCreateContTable = argsCreateContTable, + argsCreateCatTable = argsCreateCatTable) + ## argsCreateCatTable for categorical. argsCreateContTable for continuous. + listOfArgs <- listOfArgs[logiFactors + 1] + + ## Create a list of tables by looping over variables/constructors/arguments + TableOne <- sapply(seq_along(listOfConstructors), + FUN = function(i) { + + args <- c(list(vars = vars[i]), # vector element + listOfArgs[[i]]) # list element + + do.call(listOfConstructors[[i]], # list element + args = args) + }, + simplify = FALSE) + + ## Give variable names to the result object + names(TableOne) <- vars + + + ## Create ContTable and CatTable objects (this is redundant, but easy) + ## Aggregated ContTable + ContTable <- do.call(svyCreateContTable, + args = c(list(vars = varNumerics), argsCreateContTable)) + ## Aggregated CatTable + CatTable <- do.call(svyCreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) + + ## Create a list for output + TableOneObject <- list(TableOne = TableOne, + ContTable = ContTable, + CatTable = CatTable) + + ## Give a class + class(TableOneObject) <- c("svyTableOne", "TableOne") + + ## Return the object + return(TableOneObject) } +} From 45bcd964da2ac342cbfc65e27066aed81843b542 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 16:16:25 -0400 Subject: [PATCH 116/219] Add smd option to print methods --- R/print.CatTable.R | 42 ++++++++----- R/print.ContTable.R | 41 +++++++++---- R/print.TableOne.R | 136 +++++++++++++++++++++-------------------- R/print.svyCatTable.R | 42 ++++++++----- R/print.svyContTable.R | 38 ++++++++---- R/smdModules.R | 3 - 6 files changed, 180 insertions(+), 122 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index f686f30..2d4a16a 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -83,25 +83,28 @@ ##' print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) ##' ##' @export -print.CatTable <- function(x, # CatTable object - digits = 1, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes +print.CatTable <- +function(x, # CatTable object + digits = 1, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes - missing = FALSE, # Show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + missing = FALSE, # Show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent - showAllLevels = FALSE, - cramVars = NULL, # variables to be crammed into one row + format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent + showAllLevels = FALSE, + cramVars = NULL, # variables to be crammed into one row - test = TRUE, # Whether to add p-values - exact = NULL, # Which variables should be tested with exact tests + test = TRUE, # Whether to add p-values + exact = NULL, # Which variables should be tested with exact tests - CrossTable = FALSE, # Whether to show gmodels::CrossTable + smd = FALSE, # Whether to add standardized mean differences - ...) { + CrossTable = FALSE, # Whether to show gmodels::CrossTable + + ...) { ## x and ... required to be consistent with generic print(x, ...) CatTable <- x @@ -242,6 +245,17 @@ print.CatTable <- function(x, # CatTable object } + ## Add SMDs when requested and available + if (smd & !is.null(attr(CatTable, "smd"))) { + + ## Create an empty column + out <- cbind(out, + SMD = rep("", nrow(out))) # Column for p-values + ## Put the values at the non-empty positions + out[logiNonEmptyRowNames,"SMD"] <- attr(CatTable, "smd")[,1] + } + + ## Add freq () explanation if requested if (explain) { ## Choose the format of the explanation string diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 1b545c2..ebaf2eb 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -80,24 +80,27 @@ ##' ##' ## If you want to center-align values in Word, use noSpaces option. ##' print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRUE) -##' +##' ##' @export -print.ContTable <- function(x, # ContTable object - digits = 2, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes +print.ContTable <- +function(x, # ContTable object + digits = 2, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes + + missing = FALSE, # show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - missing = FALSE, # show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + nonnormal = NULL, # Which variables should be treated as nonnormal + minMax = FALSE, # median [range] instead of median [IQR] + insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable - nonnormal = NULL, # Which variables should be treated as nonnormal - minMax = FALSE, # median [range] instead of median [IQR] - insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable + test = TRUE, # Whether to add p-values - test = TRUE, # Whether to add p-values + smd = FALSE, # Whether to add standardized mean differences - ...) { + ...) { ## x and ... required to be consistent with generic print(x, ...) ContTable <- x @@ -217,6 +220,18 @@ print.ContTable <- function(x, # ContTable object } + ## Add SMDs when requested and available + if (smd & !is.null(attr(ContTable, "smd"))) { + + ## Create an empty column + out <- cbind(out, + SMD = rep("", nrow(out))) # Column for p-values + ## Put the values at the non-empty positions + out[logiNonEmptyRowNames,"SMD"] <- attr(ContTable, "smd")[,1] + } + + + ## Add mean (sd) or median [IQR]/median [range] explanation if requested if (explain) { ## Create a vector of explanations to be pasted diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 19ec1b4..cdf93be 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -67,7 +67,7 @@ ##' ## See the continuous part only using $ operator ##' tableOne$ContTable ##' summary(tableOne$ContTable) -##' +##' ##' ## If your work flow includes copying to Excel and Word when writing manuscripts, ##' ## you may benefit from the quote argument. This will quote everything so that ##' ## Excel does not mess up the cells. @@ -79,28 +79,30 @@ ##' exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) ##' ##' @export -print.TableOne <- function(x, # TableOne object - catDigits = 1, contDigits = 2, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes - - ## Common options - missing = FALSE, # Not implemented yet - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - test = TRUE, # Whether to add p-values - noSpaces = FALSE, # Whether to remove spaces for alignments - - ## Categorical options - format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent - showAllLevels = FALSE, # Show all levels of a categorical variable - cramVars = NULL, # Which 2-level variables to show both levels in one row - exact = NULL, # Which variables should be tested with exact tests - - ## Continuous options - nonnormal = NULL, # Which variables should be treated as nonnormal - minMax = FALSE, # Whether to show median - - ...) { +print.TableOne <- +function(x, # TableOne object + catDigits = 1, contDigits = 2, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes + + ## Common options + missing = FALSE, # Not implemented yet + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + test = TRUE, # Whether to add p-values + smd = FALSE, # Whether to add standardized mean differences + noSpaces = FALSE, # Whether to remove spaces for alignments + + ## Categorical options + format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent + showAllLevels = FALSE, # Show all levels of a categorical variable + cramVars = NULL, # Which 2-level variables to show both levels in one row + exact = NULL, # Which variables should be tested with exact tests + + ## Continuous options + nonnormal = NULL, # Which variables should be treated as nonnormal + minMax = FALSE, # Whether to show median + + ...) { ## Get the mixed element only TableOne <- x$TableOne @@ -112,23 +114,24 @@ print.TableOne <- function(x, # TableOne object ## Get the formatted tables - formattedTables <- sapply(seq_along(TableOne), - FUN = function(i) { + formattedTables <- + sapply(seq_along(TableOne), + FUN = function(i) { - ## print.CatTable or print.ContTable called depending on the class - print(TableOne[[i]], printToggle = FALSE, test = test, explain = explain, - digits = digits[i], pDigits = pDigits, + ## print.CatTable or print.ContTable called depending on the class + print(TableOne[[i]], printToggle = FALSE, test = test, smd = smd, + explain = explain, digits = digits[i], pDigits = pDigits, - ## print.CatTable arguments - format = format, exact = exact, - showAllLevels = showAllLevels, # Returns one more column if TRUE - cramVars = cramVars, + ## print.CatTable arguments + format = format, exact = exact, + showAllLevels = showAllLevels, # Returns one more column if TRUE + cramVars = cramVars, - ## print.ContTable argument - nonnormal = nonnormal, minMax = minMax, insertLevel = showAllLevels - ) # Method dispatch at work - }, - simplify = FALSE) + ## print.ContTable argument + nonnormal = nonnormal, minMax = minMax, insertLevel = showAllLevels + ) # Method dispatch at work + }, + simplify = FALSE) ## Get the column width information (strata x vars format) columnWidthInfo <- sapply(formattedTables, @@ -153,35 +156,36 @@ print.TableOne <- function(x, # TableOne object nSpacesToAdd[is.na(nSpacesToAdd)] <- 0 ## For each matrix, add spaces - spaceFormattedTables <- sapply(seq_along(formattedTables), - FUN = function(i) { - - ## For i-th variable - matObj <- formattedTables[[i]] - nSpaces <- nSpacesToAdd[, i] - - ## For j-th stratum (column), add spaces. - ## Be aware of the p-value column (last. not included in first palce) - ## and level column (1st. explicitly ignore). - for (j in seq_along(nSpaces)) { - - ## If showAllLevels is requested, ignore the first column (level column). - if (showAllLevels) { - matObj[, (j + 1)] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), - matObj[, (j + 1)]) - - } else { - ## if not, no need to ignore the first column - matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), - matObj[, j]) - } - - } - - ## Return the adjusted table - matObj - }, - simplify = FALSE) + spaceFormattedTables <- + sapply(seq_along(formattedTables), + FUN = function(i) { + + ## For i-th variable + matObj <- formattedTables[[i]] + nSpaces <- nSpacesToAdd[, i] + + ## For j-th stratum (column), add spaces. + ## Be aware of the p-value column (last. not included in first palce) + ## and level column (1st. explicitly ignore). + for (j in seq_along(nSpaces)) { + + ## If showAllLevels is requested, ignore the first column (level column). + if (showAllLevels) { + matObj[, (j + 1)] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), + matObj[, (j + 1)]) + + } else { + ## if not, no need to ignore the first column + matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), + matObj[, j]) + } + + } + + ## Return the adjusted table + matObj + }, + simplify = FALSE) ## Set aside the n row (stratum sizes). 1st element, 1st row stratumSizesRow <- spaceFormattedTables[[1]][1, , drop = FALSE] diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 47ca443..03d9a52 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -28,25 +28,28 @@ ##' ## See the examples for svyCreateTableOne() ##' ##' @export -print.svyCatTable <- function(x, # CatTable object - digits = 1, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes +print.svyCatTable <- +function(x, # CatTable object + digits = 1, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes - missing = FALSE, # Show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + missing = FALSE, # Show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent - showAllLevels = FALSE, - cramVars = NULL, # variables to be crammed into one row + format = c("fp","f","p","pf")[1], # Format f_requency and/or p_ercent + showAllLevels = FALSE, + cramVars = NULL, # variables to be crammed into one row - test = TRUE, # Whether to add p-values - exact = NULL, # Which variables should be tested with exact tests + test = TRUE, # Whether to add p-values + exact = NULL, # Which variables should be tested with exact tests - CrossTable = FALSE, # Whether to show gmodels::CrossTable + smd = FALSE, # Whether to add standardized mean differences - ...) { + CrossTable = FALSE, # Whether to show gmodels::CrossTable + + ...) { ## x and ... required to be consistent with generic print(x, ...) CatTable <- x @@ -187,6 +190,17 @@ print.svyCatTable <- function(x, # CatTable object } + ## Add SMDs when requested and available + if (smd & !is.null(attr(CatTable, "smd"))) { + + ## Create an empty column + out <- cbind(out, + SMD = rep("", nrow(out))) # Column for p-values + ## Put the values at the non-empty positions + out[logiNonEmptyRowNames,"SMD"] <- attr(CatTable, "smd")[,1] + } + + ## Add freq () explanation if requested if (explain) { ## Choose the format of the explanation string diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 9f6c31d..c53952b 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -26,22 +26,25 @@ ##' ## See the examples for svyCreateTableOne() ##' ##' @export -print.svyContTable <- function(x, # ContTable object - digits = 2, pDigits = 3, # Number of digits to show - quote = FALSE, # Whether to show quotes +print.svyContTable <- +function(x, # ContTable object + digits = 2, pDigits = 3, # Number of digits to show + quote = FALSE, # Whether to show quotes - missing = FALSE, # show missing values (not implemented yet) - explain = TRUE, # Whether to show explanation in variable names - printToggle = TRUE, # Whether to print the result visibly - noSpaces = FALSE, # Whether to remove spaces for alignments + missing = FALSE, # show missing values (not implemented yet) + explain = TRUE, # Whether to show explanation in variable names + printToggle = TRUE, # Whether to print the result visibly + noSpaces = FALSE, # Whether to remove spaces for alignments - nonnormal = NULL, # Which variables should be treated as nonnormal - minMax = FALSE, # median [range] instead of median [IQR] - insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable + nonnormal = NULL, # Which variables should be treated as nonnormal + minMax = FALSE, # median [range] instead of median [IQR] + insertLevel = FALSE, # insert the level column to match showAllLevels in print.CatTable - test = TRUE, # Whether to add p-values + test = TRUE, # Whether to add p-values - ...) { + smd = FALSE, # Whether to add standardized mean differences + + ...) { ## x and ... required to be consistent with generic print(x, ...) ContTable <- x @@ -163,6 +166,17 @@ print.svyContTable <- function(x, # ContTable object } + ## Add SMDs when requested and available + if (smd & !is.null(attr(ContTable, "smd"))) { + + ## Create an empty column + out <- cbind(out, + SMD = rep("", nrow(out))) # Column for p-values + ## Put the values at the non-empty positions + out[logiNonEmptyRowNames,"SMD"] <- attr(ContTable, "smd")[,1] + } + + ## Add mean (sd) or median [IQR]/median [range] explanation if requested if (explain) { ## Create a vector of explanations to be pasted diff --git a/R/smdModules.R b/R/smdModules.R index 07d4f7e..7cb92ed 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -106,9 +106,6 @@ LstMeansFromFullTable <- function(strataByLevels) { } - - - ### ### Functions for unweighted data only ################################################################################ From 02de5760420f7d81861cb7a86ad85bf021225a54 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 16:36:39 -0400 Subject: [PATCH 117/219] Add SMD matrix names and average SMD --- R/CreateCatTable.R | 3 ++- R/CreateContTable.R | 3 ++- R/smdModules.R | 25 +++++++++++++++++++++++++ R/svyCreateCatTable.R | 3 ++- R/svyCreateContTable.R | 3 ++- 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 6b8dfd0..c5dbb49 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -191,7 +191,8 @@ function(vars, # character vector of variable n smds <- sapply(dat, function(var) { StdDiffMulti(variable = var, group = strataVar) }, simplify = FALSE) - smds <- do.call(rbind, smds) + ## Give name and add mean column + smds <- FormatLstSmds(smds, nStrata = length(result)) } diff --git a/R/CreateContTable.R b/R/CreateContTable.R index a66bc23..7578166 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -245,7 +245,8 @@ function(vars, # character vector of variable smds <- sapply(dat, function(var) { StdDiff(variable = var, group = strataVar) }, simplify = FALSE) - smds <- do.call(rbind, smds) + ## Give name and add mean column + smds <- FormatLstSmds(smds, nStrata = length(result)) } diff --git a/R/smdModules.R b/R/smdModules.R index 7cb92ed..0643254 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -106,6 +106,31 @@ LstMeansFromFullTable <- function(strataByLevels) { } +## Create a matrix form +FormatLstSmds <- function(lstSmds, nStrata) { + + if (nStrata < 2) { + warning("nStrata has to be >= 2.") + } + + ## matrix form + matSmds <- do.call(rbind, lstSmds) + + ## Create contrast names + allCombns <- t(combn(nStrata, 2)) + combnNames <- apply(allCombns, MARGIN = 1, FUN = paste, collapse = " vs ") + colnames(matSmds) <- combnNames + + ## Add a mean column if more than two columns + if (ncol(matSmds) > 1) { + matSmds <- cbind(mean = rowMeans(matSmds), + matSmds) + } + + matSmds +} + + ### ### Functions for unweighted data only ################################################################################ diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 2b2620c..bf72bf2 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -126,7 +126,8 @@ function(vars, # character vector of variable names smds <- sapply(vars, function(var) { svyStdDiffMulti(varName = var, groupName = "..strataVar..", design = data) }, simplify = FALSE) - smds <- do.call(rbind, smds) + ## Give name and add mean column + smds <- FormatLstSmds(smds, nStrata = length(result)) } ## Return object diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 8215f4e..39a4195 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -146,7 +146,8 @@ function(vars, # character vector of variable n smds <- sapply(vars, function(var) { svyStdDiff(varName = var, groupName = "..strataVar..", design = data) }, simplify = FALSE) - smds <- do.call(rbind, smds) + ## Give name and add mean column + smds <- FormatLstSmds(smds, nStrata = length(result)) } From 1a4e9a7793b903f1a884186ebe319096b204913f Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 16:59:09 -0400 Subject: [PATCH 118/219] Change wording from mean SMD to average SMD --- R/smdModules.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/smdModules.R b/R/smdModules.R index 0643254..d85c190 100644 --- a/R/smdModules.R +++ b/R/smdModules.R @@ -123,7 +123,7 @@ FormatLstSmds <- function(lstSmds, nStrata) { ## Add a mean column if more than two columns if (ncol(matSmds) > 1) { - matSmds <- cbind(mean = rowMeans(matSmds), + matSmds <- cbind(average = rowMeans(matSmds), matSmds) } From b15fe58b41232a54b5948e4288d29e998da0db6b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 17:02:59 -0400 Subject: [PATCH 119/219] Drop erroneous use of logiNonEmptyRowNames from continuous print methods --- R/print.ContTable.R | 2 +- R/print.svyContTable.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/print.ContTable.R b/R/print.ContTable.R index ebaf2eb..82c73d5 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -227,7 +227,7 @@ function(x, # ContTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[logiNonEmptyRowNames,"SMD"] <- attr(ContTable, "smd")[,1] + out[,"SMD"] <- attr(ContTable, "smd")[,1] } diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index c53952b..dacdbb0 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -173,7 +173,7 @@ function(x, # ContTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[logiNonEmptyRowNames,"SMD"] <- attr(ContTable, "smd")[,1] + out[,"SMD"] <- attr(ContTable, "smd")[,1] } From 217bedebaab92ba4120b89769edef630da97d7f9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 17:08:13 -0400 Subject: [PATCH 120/219] Separate p-value picker and formatter to reuse for smd --- R/modules.R | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/R/modules.R b/R/modules.R index 6e9e0e1..a2b118a 100644 --- a/R/modules.R +++ b/R/modules.R @@ -395,6 +395,25 @@ ModuleCreateStrataNames <- function(TableObject) { return(strataNames) } +## p-value formatter +ModuleFormatPValues <- function(pValues, pDigits) { + + ## Format p value + fmt <- paste0("%.", pDigits, "f") + pVec <- sprintf(fmt = fmt, pValues) + + ## Create a string like <0.001 + smallPString <- paste0("<0.", paste0(rep("0", pDigits - 1), collapse = ""), "1") + ## Check positions where it is all zero like 0.000 + posAllZeros <- grepl("^0\\.0*$", pVec) + ## Put the string where it is all zero like 0.000 + pVec[posAllZeros] <- smallPString + ## Put a preceding space where it is not like 0.000 + pVec[!posAllZeros] <- paste0(" ", pVec[!posAllZeros]) + + ## Return formatted p-values (as many as there are variables) + return(pVec) +} ## p-value picker/formatter ModulePickAndFormatPValues <- function(TableObject, switchVec, pDigits) { @@ -411,21 +430,9 @@ ModulePickAndFormatPValues <- function(TableObject, switchVec, pDigits) { }, simplify = TRUE) - ## Format p value - fmt <- paste0("%.", pDigits, "f") - pVec <- sprintf(fmt = fmt, pValues) - - ## Create a string like <0.001 - smallPString <- paste0("<0.", paste0(rep("0", pDigits - 1), collapse = ""), "1") - ## Check positions where it is all zero like 0.000 - posAllZeros <- grepl("^0\\.0*$", pVec) - ## Put the string where it is all zero like 0.000 - pVec[posAllZeros] <- smallPString - ## Put a preceding space where it is not like 0.000 - pVec[!posAllZeros] <- paste0(" ", pVec[!posAllZeros]) - ## Return formatted p-values (as many as there are variables) - return(pVec) + ## e.g. <0.001 if too small to show + ModuleFormatPValues(pValues, pDigits) } From 74a8f816e99d485cab1cfc9c22dc963ab3a5b044 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 17:12:42 -0400 Subject: [PATCH 121/219] Format SMD reusing p value formatter --- R/print.CatTable.R | 4 +++- R/print.ContTable.R | 3 ++- R/print.svyCatTable.R | 3 ++- R/print.svyContTable.R | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 2d4a16a..6d0cd10 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -252,7 +252,9 @@ function(x, # CatTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[logiNonEmptyRowNames,"SMD"] <- attr(CatTable, "smd")[,1] + out[logiNonEmptyRowNames,"SMD"] <- + ModuleFormatPValues(attr(CatTable, "smd")[,1], + pDigits = pDigits) } diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 82c73d5..bbb108e 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -227,7 +227,8 @@ function(x, # ContTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[,"SMD"] <- attr(ContTable, "smd")[,1] + out[,"SMD"] <- ModuleFormatPValues(attr(ContTable, "smd")[,1], + pDigits = pDigits) } diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 03d9a52..b53abcf 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -197,7 +197,8 @@ function(x, # CatTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[logiNonEmptyRowNames,"SMD"] <- attr(CatTable, "smd")[,1] + out[logiNonEmptyRowNames,"SMD"] <- + ModuleFormatPValues(attr(CatTable, "smd")[,1], pDigits = pDigits) } diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index dacdbb0..77130d1 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -173,7 +173,8 @@ function(x, # ContTable object out <- cbind(out, SMD = rep("", nrow(out))) # Column for p-values ## Put the values at the non-empty positions - out[,"SMD"] <- attr(ContTable, "smd")[,1] + out[,"SMD"] <- ModuleFormatPValues(attr(ContTable, "smd")[,1], + pDigits = pDigits) } From c20d72b209247430a012eaaadc3fbbb736ce1c53 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 17:25:21 -0400 Subject: [PATCH 122/219] Add initial functional SMD implementation along with docs --- R/print.CatTable.R | 1 + R/print.ContTable.R | 1 + R/print.TableOne.R | 1 + R/print.svyCatTable.R | 1 + R/print.svyContTable.R | 1 + man/print.CatTable.Rd | 5 +- man/print.ContTable.Rd | 4 +- man/print.TableOne.Rd | 6 +- man/print.svyCatTable.Rd | 5 +- man/print.svyContTable.Rd | 4 +- tableone.Rcheck/tableone-Ex.Rout | 346 ++++++++++++++++++++++++++++++- tests/testthat/test-smdModules.R | 49 ++++- 12 files changed, 412 insertions(+), 12 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 6d0cd10..a3aebf7 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -15,6 +15,7 @@ ##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test). +##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. diff --git a/R/print.ContTable.R b/R/print.ContTable.R index bbb108e..e314484 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -14,6 +14,7 @@ ##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. ##' @param insertLevel Whether to add an empty level column to the left of strata. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida diff --git a/R/print.TableOne.R b/R/print.TableOne.R index cdf93be..b2d53a2 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -11,6 +11,7 @@ ##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown. ##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param noSpaces Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. ##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency). ##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index b53abcf..f7c3e11 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -15,6 +15,7 @@ ##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param exact This option is not available for tables from weighted data. +##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 77130d1..bda4439 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -14,6 +14,7 @@ ##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. ##' @param insertLevel Whether to add an empty level column to the left of strata. ##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida diff --git a/man/print.CatTable.Rd b/man/print.CatTable.Rd index 0e893f6..d57e4e6 100644 --- a/man/print.CatTable.Rd +++ b/man/print.CatTable.Rd @@ -7,7 +7,8 @@ \method{print}{CatTable}(x, digits = 1, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], showAllLevels = FALSE, - cramVars = NULL, test = TRUE, exact = NULL, CrossTable = FALSE, ...) + cramVars = NULL, test = TRUE, exact = NULL, smd = FALSE, + CrossTable = FALSE, ...) } \arguments{ \item{x}{The result of a call to the \code{\link{CreateCatTable}} function.} @@ -36,6 +37,8 @@ \item{exact}{A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).} +\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} + \item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} \item{...}{For compatibility with generic. Ignored.} diff --git a/man/print.ContTable.Rd b/man/print.ContTable.Rd index 0bcf1c2..1399cb3 100644 --- a/man/print.ContTable.Rd +++ b/man/print.ContTable.Rd @@ -7,7 +7,7 @@ \method{print}{ContTable}(x, digits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, nonnormal = NULL, minMax = FALSE, insertLevel = FALSE, test = TRUE, - ...) + smd = FALSE, ...) } \arguments{ \item{x}{The result of a call to the \code{\link{CreateContTable}} function.} @@ -34,6 +34,8 @@ \item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} + \item{...}{For compatibility with generic. Ignored.} } \value{ diff --git a/man/print.TableOne.Rd b/man/print.TableOne.Rd index 641d27f..67ccca3 100644 --- a/man/print.TableOne.Rd +++ b/man/print.TableOne.Rd @@ -6,8 +6,8 @@ \usage{ \method{print}{TableOne}(x, catDigits = 1, contDigits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, - test = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], - showAllLevels = FALSE, cramVars = NULL, exact = NULL, + test = TRUE, smd = FALSE, noSpaces = FALSE, format = c("fp", "f", "p", + "pf")[1], showAllLevels = FALSE, cramVars = NULL, exact = NULL, nonnormal = NULL, minMax = FALSE, ...) } \arguments{ @@ -29,6 +29,8 @@ \item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} + \item{noSpaces}{Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software.} \item{format}{The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency).} diff --git a/man/print.svyCatTable.Rd b/man/print.svyCatTable.Rd index 4123945..8d891d6 100644 --- a/man/print.svyCatTable.Rd +++ b/man/print.svyCatTable.Rd @@ -7,7 +7,8 @@ \method{print}{svyCatTable}(x, digits = 1, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], showAllLevels = FALSE, - cramVars = NULL, test = TRUE, exact = NULL, CrossTable = FALSE, ...) + cramVars = NULL, test = TRUE, exact = NULL, smd = FALSE, + CrossTable = FALSE, ...) } \arguments{ \item{x}{The result of a call to the \code{\link{svyCreateCatTable}} function.} @@ -36,6 +37,8 @@ \item{exact}{This option is not available for tables from weighted data.} +\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} + \item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} \item{...}{For compatibility with generic. Ignored.} diff --git a/man/print.svyContTable.Rd b/man/print.svyContTable.Rd index bbc28d6..5b5a82b 100644 --- a/man/print.svyContTable.Rd +++ b/man/print.svyContTable.Rd @@ -7,7 +7,7 @@ \method{print}{svyContTable}(x, digits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, nonnormal = NULL, minMax = FALSE, insertLevel = FALSE, test = TRUE, - ...) + smd = FALSE, ...) } \arguments{ \item{x}{The result of a call to the \code{\link{svyCreateContTable}} function.} @@ -34,6 +34,8 @@ \item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} + \item{...}{For compatibility with generic. Ignored.} } \value{ diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index d1d8504..717a129 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -380,6 +380,22 @@ hepato 0.20805680 0.20480121 spiders 0.08898575 0.08569292 edema 0.90584197 0.84833223 stage 0.64630048 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 +ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 +hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 +spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 +edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 +stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 + 3 vs 4 +status 0.46214324 +ascites 0.26007640 +hepato 0.07878788 +spiders 0.66954801 +edema 0.26502087 +stage 0.39205566 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -803,6 +819,32 @@ ast 5.982898e-01 5.086616e-01 trig 3.701073e-01 5.827726e-02 platelet 3.624740e-01 4.451277e-01 protime 1.365463e-01 8.114383e-02 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 +age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 +bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 +chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 +albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 +copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 +alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 +ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 +trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 +platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 +protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 + 3 vs 4 +time 0.13729269 +age 0.96133382 +bili 0.24158721 +chol 0.40072828 +albumin 0.05159074 +copper 0.36464167 +alk.phos 0.10128012 +ast 0.25929154 +trig 0.22610097 +platelet 0.33286083 +protime 0.44433997 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -1134,6 +1176,20 @@ trig 0.88604213 0.36980434 platelet 0.55451136 0.45482564 protime 0.19714026 0.58802048 +Standardize mean differences + 1 vs 2 +time 0.0166658751 +age 0.2702619258 +bili 0.1710905651 +chol 0.0382210537 +albumin 0.0180021838 +copper 0.0001200022 +alk.phos 0.0365323630 +ast 0.0837836058 +trig 0.0170615337 +platelet 0.0674763888 +protime 0.1460939117 + ======================================================================================= ### Summary of categorical variables ### @@ -1203,6 +1259,16 @@ hepato 0.08820884 0.07137522 spiders 0.98466036 0.90113734 edema 0.87681949 0.89370131 stage 0.20129629 0.20455558 + +Standardize mean differences + 1 vs 2 +status 0.05375763 +sex 0.11141161 +ascites 0.08900618 +hepato 0.20699413 +spiders 0.01632844 +edema 0.05811659 +stage 0.24600834 > > ## See the categorical part only using $ operator > tableOne$CatTable @@ -1292,6 +1358,16 @@ hepato 0.08820884 0.07137522 spiders 0.98466036 0.90113734 edema 0.87681949 0.89370131 stage 0.20129629 0.20455558 + +Standardize mean differences + 1 vs 2 +status 0.05375763 +sex 0.11141161 +ascites 0.08900618 +hepato 0.20699413 +spiders 0.01632844 +edema 0.05811659 +stage 0.24600834 > > ## See the continuous part only using $ operator > tableOne$ContTable @@ -1375,6 +1451,20 @@ ast 0.45969842 0.45892358 trig 0.88604213 0.36980434 platelet 0.55451136 0.45482564 protime 0.19714026 0.58802048 + +Standardize mean differences + 1 vs 2 +time 0.0166658751 +age 0.2702619258 +bili 0.1710905651 +chol 0.0382210537 +albumin 0.0180021838 +copper 0.0001200022 +alk.phos 0.0365323630 +ast 0.0837836058 +trig 0.0170615337 +platelet 0.0674763888 +protime 0.1460939117 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -1924,6 +2014,22 @@ hepato 0.20805680 0.20480121 spiders 0.08898575 0.08569292 edema 0.90584197 0.84833223 stage 0.64630048 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 +ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 +hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 +spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 +edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 +stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 + 3 vs 4 +status 0.46214324 +ascites 0.26007640 +hepato 0.07878788 +spiders 0.66954801 +edema 0.26502087 +stage 0.39205566 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -2406,6 +2512,32 @@ ast 5.982898e-01 5.086616e-01 trig 3.701073e-01 5.827726e-02 platelet 3.624740e-01 4.451277e-01 protime 1.365463e-01 8.114383e-02 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 +age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 +bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 +chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 +albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 +copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 +alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 +ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 +trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 +platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 +protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 + 3 vs 4 +time 0.13729269 +age 0.96133382 +bili 0.24158721 +chol 0.40072828 +albumin 0.05159074 +copper 0.36464167 +alk.phos 0.10128012 +ast 0.25929154 +trig 0.22610097 +platelet 0.33286083 +protime 0.44433997 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -2820,6 +2952,32 @@ trig 3.701073e-01 5.827726e-02 platelet 3.624740e-01 4.451277e-01 protime 1.365463e-01 8.114383e-02 +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 +age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 +bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 +chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 +albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 +copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 +alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 +ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 +trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 +platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 +protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 + 3 vs 4 +time 0.13729269 +age 0.96133382 +bili 0.24158721 +chol 0.40072828 +albumin 0.05159074 +copper 0.36464167 +alk.phos 0.10128012 +ast 0.25929154 +trig 0.22610097 +platelet 0.33286083 +protime 0.44433997 + ======================================================================================= ### Summary of categorical variables ### @@ -2936,6 +3094,22 @@ hepato 0.20805680 0.20480121 spiders 0.08898575 0.08569292 edema 0.90584197 0.84833223 stage 0.64630048 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 +ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 +hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 +spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 +edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 +stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 + 3 vs 4 +status 0.46214324 +ascites 0.26007640 +hepato 0.07878788 +spiders 0.66954801 +edema 0.26502087 +stage 0.39205566 > > ## See the categorical part only using $ operator > tableOne$CatTable @@ -3071,6 +3245,22 @@ hepato 0.20805680 0.20480121 spiders 0.08898575 0.08569292 edema 0.90584197 0.84833223 stage 0.64630048 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 +ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 +hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 +spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 +edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 +stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 + 3 vs 4 +status 0.46214324 +ascites 0.26007640 +hepato 0.07878788 +spiders 0.66954801 +edema 0.26502087 +stage 0.39205566 > > ## See the continuous part only using $ operator > tableOne$ContTable @@ -3224,6 +3414,32 @@ ast 5.982898e-01 5.086616e-01 trig 3.701073e-01 5.827726e-02 platelet 3.624740e-01 4.451277e-01 protime 1.365463e-01 8.114383e-02 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 +age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 +bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 +chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 +albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 +copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 +alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 +ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 +trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 +platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 +protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 + 3 vs 4 +time 0.13729269 +age 0.96133382 +bili 0.24158721 +chol 0.40072828 +albumin 0.05159074 +copper 0.36464167 +alk.phos 0.10128012 +ast 0.25929154 +trig 0.22610097 +platelet 0.33286083 +protime 0.44433997 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -3903,6 +4119,32 @@ trig 3.701073e-01 5.827726e-02 platelet 3.624740e-01 4.451277e-01 protime 1.365463e-01 8.114383e-02 +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 +age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 +bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 +chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 +albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 +copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 +alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 +ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 +trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 +platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 +protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 + 3 vs 4 +time 0.13729269 +age 0.96133382 +bili 0.24158721 +chol 0.40072828 +albumin 0.05159074 +copper 0.36464167 +alk.phos 0.10128012 +ast 0.25929154 +trig 0.22610097 +platelet 0.33286083 +protime 0.44433997 + ======================================================================================= ### Summary of categorical variables ### @@ -4019,6 +4261,22 @@ hepato 0.20805680 0.20480121 spiders 0.08898575 0.08569292 edema 0.90584197 0.84833223 stage 0.64630048 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 +ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 +hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 +spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 +edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 +stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 + 3 vs 4 +status 0.46214324 +ascites 0.26007640 +hepato 0.07878788 +spiders 0.66954801 +edema 0.26502087 +stage 0.39205566 > > > @@ -4159,6 +4417,10 @@ p-values pNormal pNonNormal HI_CHOL 0.009221135 0.009221135 +Standardize mean differences + 1 vs 2 +HI_CHOL 0.07093003 + ======================================================================================= ### Summary of categorical variables ### @@ -4200,6 +4462,12 @@ p-values race 4.162884e-02 NA agecat 1.175703e-03 NA RIAGENDR 2.688704e-49 NA + +Standardize mean differences + 1 vs 2 +race 0.06878329 +agecat 0.08873652 +RIAGENDR 0.00000000 > > ## Default formatted printing > tab1 @@ -4332,8 +4600,8 @@ _U_s_a_g_e: ## S3 method for class 'TableOne' print(x, catDigits = 1, contDigits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, - test = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], - showAllLevels = FALSE, cramVars = NULL, exact = NULL, + test = TRUE, smd = FALSE, noSpaces = FALSE, format = c("fp", "f", "p", + "pf")[1], showAllLevels = FALSE, cramVars = NULL, exact = NULL, nonnormal = NULL, minMax = FALSE, ...) _A_r_g_u_m_e_n_t_s: @@ -4363,6 +4631,11 @@ printToggle: Whether to print the output. If FLASE, no output is test: Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. + smd: Whether to show the standardized mean difference. If there + are more than one contrasts, the average of all possible + standardized mean differences is shown. For categorical + variables, Yang and Dalton's definition is used. + noSpaces: Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. @@ -4700,6 +4973,20 @@ trig 0.88604213 0.36980434 platelet 0.55451136 0.45482564 protime 0.19714026 0.58802048 +Standardize mean differences + 1 vs 2 +time 0.0166658751 +age 0.2702619258 +bili 0.1710905651 +chol 0.0382210537 +albumin 0.0180021838 +copper 0.0001200022 +alk.phos 0.0365323630 +ast 0.0837836058 +trig 0.0170615337 +platelet 0.0674763888 +protime 0.1460939117 + ======================================================================================= ### Summary of categorical variables ### @@ -4769,6 +5056,16 @@ hepato 0.08820884 0.07137522 spiders 0.98466036 0.90113734 edema 0.87681949 0.89370131 stage 0.20129629 0.20455558 + +Standardize mean differences + 1 vs 2 +status 0.05375763 +sex 0.11141161 +ascites 0.08900618 +hepato 0.20699413 +spiders 0.01632844 +edema 0.05811659 +stage 0.24600834 > > ## See the categorical part only using $ operator > tableOne$CatTable @@ -4858,6 +5155,16 @@ hepato 0.08820884 0.07137522 spiders 0.98466036 0.90113734 edema 0.87681949 0.89370131 stage 0.20129629 0.20455558 + +Standardize mean differences + 1 vs 2 +status 0.05375763 +sex 0.11141161 +ascites 0.08900618 +hepato 0.20699413 +spiders 0.01632844 +edema 0.05811659 +stage 0.24600834 > > ## See the continuous part only using $ operator > tableOne$ContTable @@ -4941,6 +5248,20 @@ ast 0.45969842 0.45892358 trig 0.88604213 0.36980434 platelet 0.55451136 0.45482564 protime 0.19714026 0.58802048 + +Standardize mean differences + 1 vs 2 +time 0.0166658751 +age 0.2702619258 +bili 0.1710905651 +chol 0.0382210537 +albumin 0.0180021838 +copper 0.0001200022 +alk.phos 0.0365323630 +ast 0.0837836058 +trig 0.0170615337 +platelet 0.0674763888 +protime 0.1460939117 > > ## If your work flow includes copying to Excel and Word when writing manuscripts, > ## you may benefit from the quote argument. This will quote everything so that @@ -5120,6 +5441,10 @@ p-values pNormal pNonNormal HI_CHOL 0.009221135 0.009221135 +Standardize mean differences + 1 vs 2 +HI_CHOL 0.07093003 + ======================================================================================= ### Summary of categorical variables ### @@ -5161,6 +5486,12 @@ p-values race 4.162884e-02 NA agecat 1.175703e-03 NA RIAGENDR 2.688704e-49 NA + +Standardize mean differences + 1 vs 2 +race 0.06878329 +agecat 0.08873652 +RIAGENDR 0.00000000 > > ## Default formatted printing > tab1 @@ -5293,8 +5624,8 @@ _U_s_a_g_e: ## S3 method for class 'TableOne' print(x, catDigits = 1, contDigits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, - test = TRUE, noSpaces = FALSE, format = c("fp", "f", "p", "pf")[1], - showAllLevels = FALSE, cramVars = NULL, exact = NULL, + test = TRUE, smd = FALSE, noSpaces = FALSE, format = c("fp", "f", "p", + "pf")[1], showAllLevels = FALSE, cramVars = NULL, exact = NULL, nonnormal = NULL, minMax = FALSE, ...) _A_r_g_u_m_e_n_t_s: @@ -5324,6 +5655,11 @@ printToggle: Whether to print the output. If FLASE, no output is test: Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. + smd: Whether to show the standardized mean difference. If there + are more than one contrasts, the average of all possible + standardized mean differences is shown. For categorical + variables, Yang and Dalton's definition is used. + noSpaces: Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. @@ -5456,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 11.317 0.258 11.701 0.011 0.01 +Time elapsed: 9.219 0.19 9.541 0.008 0.008 > grDevices::dev.off() null device 1 diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-smdModules.R index 3f8df7d..8ad0b4b 100755 --- a/tests/testthat/test-smdModules.R +++ b/tests/testthat/test-smdModules.R @@ -557,7 +557,7 @@ test_that("multiple variables can be looped", { svyStdDiffMulti(catVars[2], "race", nhanesSvy), svyStdDiffMulti(catVars[3], "race", nhanesSvy), svyStdDiffMulti(catVars[4], "race", nhanesSvy))) - + }) @@ -769,3 +769,50 @@ test_that("mutlinomial SMD for survey data is correct", { StdDiffMulti(dat$X, group = dat$group)) }) + + + +### +### User level functionality check +################################################################################ + +test_that("SMDs are correctly shown in print()", { + + vars <- c("race","agecat") + strata <- c("HI_CHOL","RIAGENDR") + + ## Create an interaction variable + nhanes$strataVar <- interaction(nhanes$HI_CHOL, nhanes$RIAGENDR, sep = ":") + ## Create an weighted data + nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, + nest = TRUE, data = nhanes) + + + ## Unweighed version + ## Create a table + tab1 <- CreateTableOne(vars = vars, strata = strata, data = nhanes) + + ## Show summary including + summary(tab1) + expect_output(summary(tab1), "Standardize mean differences") + + ## First variable changes fastest, and its consistent with by()'s order + expect_equal(levels(nhanes$strataVar), + c("0:1", "1:1", "0:2", "1:2")) + expect_equal(levels(nhanes$strataVar), + colnames(print(tab1$ContTable))[1:4]) + + ## Check ordering is correct (continuous) + expect_equal(as.vector(attr(tab1$ContTable, "smd"))[-1], + StdDiff(nhanes$race, nhanes$strataVar)) + + ## Check ordering is correct (categorical) + expect_equal(as.vector(attr(tab1$CatTable, "smd"))[-1], + StdDiffMulti(nhanes$agecat, nhanes$strataVar)) + + out1 <- print(tab1, smd = TRUE) + expect_equal(as.vector(out1[,"SMD"][2:3]), + c(sprintf(" %.3f", attr(tab1$ContTable, "smd")[1,1]), + sprintf(" %.3f", attr(tab1$CatTable, "smd")[1,1]))) + +}) From e942543b887f7bf13c6a856941c04a63a1812179 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 18:47:51 -0400 Subject: [PATCH 123/219] Update DESCRIPTION and NEWS for new features --- DESCRIPTION | 17 +++++++++-------- NEWS | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 35bf23b..5d2445e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,16 +2,17 @@ Package: tableone Type: Package Title: Create "Table 1" to Describe Baseline Characteristics Version: 0.7.0 -Date: 2015-07-24 +Date: 2015-07-30 Author: Kazuki Yoshida, Justin Bohn. Maintainer: Kazuki Yoshida -Description: Creates "Table 1", i.e., description of baseline - patient characteristics, which is essential in every medical research. - It provides functions to create such summaries for continuous and - categorical variables, optionally with subgroup comparisons. tableone - was inspired by and based on descriptive statistics functions in Deducer, - a Java-based GUI package by Ian Fellows. This package does not require GUI - or Java, and intended for command-line users. +Description: Creates "Table 1", i.e., description of baseline patient + characteristics, which is essential in every medical research. + Supports both continuous and categorical variables, as well as + p-values and standardized mean differences. Weighted data are + supported via the survey package. See github for a screencast. + tableone was inspired by descriptive statistics functions in + Deducer , a Java-based GUI package by Ian Fellows. This package + does not require GUI or Java, and intended for command-line users. License: GPL-2 Imports: survey, diff --git a/NEWS b/NEWS index b680b5d..afc0bc7 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,4 @@ -tableone 0.7.0 (2015-07-26) +tableone 0.7.0 (2015-07-30) ---------------------------------------------------------------- NEW FEATURES @@ -6,21 +6,32 @@ NEW FEATURES * Weighted data are now supported via the survey package. The svydesign() should be used to create a survey design object, and this object should be used for svyCreateTableOne() - instead of the orginal data frame. + instead of a data frame. Other options are essentially the same. + +* Standardized mean differences are calculated. print() methods + include smd option, which defaults to FALSE for backward + compatibility. If TRUE, SMD is shown on the right side of the + table. To suppress p-values, use test = FALSE option. + summary() methods also print SMDs. If there are more than two + strata, all possible pairwise contrasts are shown along with the + average SMD across all contrats. In this case, print methods only + prints the average SMD for brevity. * The includeNA option for CreateTableOne() and svyCreateTableOne() make NA's in factors treated as a regular level. + MINOR CHANGES * ShowRegTable() uses coef to refer to coefficients. * Unit tests were extended to cover more functions. -BUG FIXES -* pDigits option was not correctly functional in print.ContTable(). +BUG FIXES +* Fixed pDigits option in print.ContTable(), which was not correctly + functional as advertised. tableone 0.6.3 (2014-12-28) From 56e8a63986216870b53b8d8e610b38fe4dfccc3d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 19:04:13 -0400 Subject: [PATCH 124/219] Update example run result --- tableone.Rcheck/tableone-Ex.Rout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 717a129..a149ed8 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -5792,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 9.219 0.19 9.541 0.008 0.008 +Time elapsed: 13.999 0.353 14.605 0.013 0.014 > grDevices::dev.off() null device 1 From dcb335ca3f5fe806dddb5c9956f196c2160ed76a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Thu, 30 Jul 2015 23:38:03 -0400 Subject: [PATCH 125/219] Make (svy)CatTable print object to have logiNameRows attribute logiNameRows indicates rows where variable names exists --- R/print.CatTable.R | 4 +++- R/print.svyCatTable.R | 4 +++- tableone.Rcheck/tableone-Ex.Rout | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index a3aebf7..56fddc8 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -303,7 +303,9 @@ function(x, # CatTable object ## Add attributes for column widths in characters attributes(out) <- c(attributes(out), - list(vecColWidths = vecColWidths)) + list(vecColWidths = vecColWidths, + ## Add one FALSE for sample size row + logiNameRows = c(FALSE, logiNonEmptyRowNames))) ## return a matrix invisibly return(invisible(out)) diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index f7c3e11..316bf05 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -248,7 +248,9 @@ function(x, # CatTable object ## Add attributes for column widths in characters attributes(out) <- c(attributes(out), - list(vecColWidths = vecColWidths)) + list(vecColWidths = vecColWidths, + ## Add one FALSE for sample size row + logiNameRows = c(FALSE, logiNonEmptyRowNames))) ## return a matrix invisibly return(invisible(out)) diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index a149ed8..fc6400e 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -5792,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 13.999 0.353 14.605 0.013 0.014 +Time elapsed: 16.203 0.542 17.139 0.016 0.02 > grDevices::dev.off() null device 1 From cd0d44cd8d7204591033c8495561b2b9ac761a21 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 07:19:49 -0400 Subject: [PATCH 126/219] Update refrences to reflect inclusion of logiNameRows as attribute The following errors were all in attributes only Reference update supressed all these Unit tests for the survey-related modules : ................................................ 1. Failure (at test-CreateTableOne.R#184): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, printToggle = TRUE) not equal to reference from ref-CatTable_defaultPrint Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > 2. Failure (at test-CreateTableOne.R#187): printing of a TableOne$CatTable object do not regress --------------------- print(pbcOverall$CatTable, printToggle = TRUE) not equal to reference from ref-CatTable_overallPrint Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 1, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > 3. Failure (at test-CreateTableOne.R#190): printing of a TableOne$CatTable object do not regress --------------------- print(pbcInclNa$CatTable, printToggle = TRUE) not equal to reference from ref-CatTable_IncludeNA Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 1, 28 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > 4. Failure (at test-CreateTableOne.R#193): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrtSex$CatTable, printToggle = TRUE) not equal to reference from ref-CatTable_2StrataVars Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 4, 18 > Attributes: < Component 3: target is numeric, current is logical > 5. Failure (at test-CreateTableOne.R#196): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = TRUE) not equal to reference from ref-CatTable_digits Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 4, 18 > Attributes: < Component 3: target is numeric, current is logical > 6. Failure (at test-CreateTableOne.R#199): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrtSex$CatTable, test = FALSE, printToggle = TRUE) not equal to reference from ref-CatTable_noTests Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 4, 18 > Attributes: < Component 3: target is numeric, current is logical > 7. Failure (at test-CreateTableOne.R#202): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, noSpaces = TRUE, printToggle = TRUE) not equal to reference from ref-CatTable_noSpaces Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > 8. Failure (at test-CreateTableOne.R#205): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-CatTable_showAllLevels Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 19 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > 9. Failure (at test-CreateTableOne.R#208): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, explain = FALSE, printToggle = TRUE) not equal to reference from ref-CatTable_explain Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > a. Failure (at test-CreateTableOne.R#211): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, format = "f", printToggle = TRUE) not equal to reference from ref-CatTable_format_f Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > b. Failure (at test-CreateTableOne.R#214): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, format = "p", printToggle = TRUE) not equal to reference from ref-CatTable_format_p Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > c. Failure (at test-CreateTableOne.R#217): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, format = "pf", printToggle = TRUE) not equal to reference from ref-CatTable_format_pf Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > d. Failure (at test-CreateTableOne.R#220): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, cramVars = "sex", printToggle = TRUE) not equal to reference from ref-CatTable_cramVars Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 18 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > e. Failure (at test-CreateTableOne.R#223): printing of a TableOne$CatTable object do not regress --------------------- print(pbcByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE) not equal to reference from ref-CatTable_noSpaces_showAllLevels_quote Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 2, 19 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > f. Failure (at test-svyCreateTableOne.R#149): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, printToggle = TRUE) not equal to reference from ref-svyCatTable_defaultPrint Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > g. Failure (at test-svyCreateTableOne.R#152): printing of a svyTableOne$CatTable object do not regress --------------- print(mwOverall$CatTable, printToggle = TRUE) not equal to reference from ref-svyCatTable_overallPrint Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 1, 3 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > h. Failure (at test-svyCreateTableOne.R#155): printing of a svyTableOne$CatTable object do not regress --------------- print(mwInclNa$CatTable, printToggle = TRUE) not equal to reference from ref-svyCatTable_IncludeNA Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 1, 6 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > i. Failure (at test-svyCreateTableOne.R#158): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrtSex$CatTable, printToggle = TRUE) not equal to reference from ref-svyCatTable_2StrataVars Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 6, 3 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > j. Failure (at test-svyCreateTableOne.R#161): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrtSex$CatTable, digits = 3, pDigits = 5, printToggle = TRUE) not equal to reference from ref-svyCatTable_digits Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 6, 3 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > k. Failure (at test-svyCreateTableOne.R#164): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrtSex$CatTable, test = FALSE, printToggle = TRUE) not equal to reference from ref-svyCatTable_noTests Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 6, 3 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > l. Failure (at test-svyCreateTableOne.R#167): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, digits = 3, noSpaces = TRUE, printToggle = TRUE) not equal to reference from ref-svyCatTable_noSpaces Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > m. Failure (at test-svyCreateTableOne.R#170): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-svyCatTable_showAllLevels Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 3, 5 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > n. Failure (at test-svyCreateTableOne.R#173): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, explain = FALSE, printToggle = TRUE) not equal to reference from ref-svyCatTable_explain Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > o. Failure (at test-svyCreateTableOne.R#176): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, format = "f", printToggle = TRUE) not equal to reference from ref-svyCatTable_format_f Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > p. Failure (at test-svyCreateTableOne.R#179): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, format = "p", printToggle = TRUE) not equal to reference from ref-svyCatTable_format_p Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > q. Failure (at test-svyCreateTableOne.R#182): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, format = "pf", printToggle = TRUE) not equal to reference from ref-svyCatTable_format_pf Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > r. Failure (at test-svyCreateTableOne.R#185): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, cramVars = "Y", printToggle = TRUE) not equal to reference from ref-svyCatTable_cramVars Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > s. Failure (at test-svyCreateTableOne.R#188): printing of a svyTableOne$CatTable object do not regress --------------- print(mwByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE) not equal to reference from ref-svyCatTable_noSpaces_showAllLevels_quote Attributes: < Names: 1 string mismatch > Attributes: < Length mismatch: comparison on first 3 components > Attributes: < Component 3: Modes: numeric, logical > Attributes: < Component 3: Lengths: 3, 5 > Attributes: < Component 3: names for target but not for current > Attributes: < Component 3: target is numeric, current is logical > --- tests/testthat/ref-CatTable_2StrataVars | Bin 612 -> 640 bytes tests/testthat/ref-CatTable_IncludeNA | Bin 393 -> 422 bytes tests/testthat/ref-CatTable_cramVars | Bin 516 -> 541 bytes tests/testthat/ref-CatTable_defaultPrint | Bin 492 -> 520 bytes tests/testthat/ref-CatTable_digits | Bin 670 -> 698 bytes tests/testthat/ref-CatTable_explain | Bin 484 -> 512 bytes tests/testthat/ref-CatTable_format_f | Bin 384 -> 411 bytes tests/testthat/ref-CatTable_format_p | Bin 423 -> 449 bytes tests/testthat/ref-CatTable_format_pf | Bin 503 -> 531 bytes tests/testthat/ref-CatTable_noSpaces | Bin 482 -> 515 bytes .../ref-CatTable_noSpaces_showAllLevels_quote | Bin 550 -> 576 bytes tests/testthat/ref-CatTable_noTests | Bin 565 -> 594 bytes tests/testthat/ref-CatTable_overallPrint | Bin 347 -> 374 bytes tests/testthat/ref-CatTable_showAllLevels | Bin 530 -> 555 bytes tests/testthat/ref-svyCatTable_2StrataVars | Bin 282 -> 301 bytes tests/testthat/ref-svyCatTable_IncludeNA | Bin 248 -> 269 bytes tests/testthat/ref-svyCatTable_cramVars | Bin 270 -> 289 bytes tests/testthat/ref-svyCatTable_defaultPrint | Bin 243 -> 265 bytes tests/testthat/ref-svyCatTable_digits | Bin 298 -> 317 bytes tests/testthat/ref-svyCatTable_explain | Bin 237 -> 259 bytes tests/testthat/ref-svyCatTable_format_f | Bin 220 -> 238 bytes tests/testthat/ref-svyCatTable_format_p | Bin 232 -> 252 bytes tests/testthat/ref-svyCatTable_format_pf | Bin 249 -> 269 bytes tests/testthat/ref-svyCatTable_noSpaces | Bin 265 -> 282 bytes ...ref-svyCatTable_noSpaces_showAllLevels_quote | Bin 297 -> 317 bytes tests/testthat/ref-svyCatTable_noTests | Bin 259 -> 279 bytes tests/testthat/ref-svyCatTable_overallPrint | Bin 212 -> 232 bytes tests/testthat/ref-svyCatTable_showAllLevels | Bin 282 -> 300 bytes 28 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/testthat/ref-CatTable_2StrataVars b/tests/testthat/ref-CatTable_2StrataVars index d04710d6bfdf4dde15f16b0f2e21619bb705e06d..970b44a32c12f8934cdb9e93887034c3aad6d014 100644 GIT binary patch delta 615 zcmV-t0+{{e1b_vQB!8qzz4y=_+N&E(VhIAm?$@7>Is-NyuU$}YwFEmJzj-tBW(;4a zLI_6;oq=$MWM1RfN{qyWZUR|ZqB^IbVI~vLzlEbmp+|eF@kqpkp%*cX4>RyvQ4&4c zi&<0vGZT681oN>98Nn=;r>p2>XnMd*ka&h+yIo-hrCNM3dVgY8pCe6&8Kd;M&XLEo znY$RQP_{7%YT8wh=Mr4W_%ybgLHq-D3Z|ou-T6?e$f9;3!Y%-Z+`wF*NC3lxb-_># zD)NHHhjdtl&)afADvIT!bRpc&UAKIiCa(M*v0N#!7l@UYoZ+Pj016X!IY80`A!35K zps0=@V0f&9IDeF3ONl<}U-8vN>5{H=F-aG;WU5QzWt!k1o#xUdUFm2INp@aJUk+k(Lk1TfT0trZ3n_9q>`(q)0m1;xLp;2fVLJI@QBFruRuH%WI$GcZl*O zi!m}}cYz;szBplbi65S0M^vcKq5i*9j2!$L)XTWY*ME4t67)AA#A|BIf?OcvDP3m; zLT)PD^&We8K6t8sC5kdFzZWojds}%%0N^uQGCQd3mqqpq?qJEnuF~Q@FS7#OlDRJ* zvu#>#EbmpZ%@^6u22Zj@wod<2%b0A>^i(#%9v(6)tgmdc6|;4v%J}$}&)2mXG^U&{ z8*gn6wqP|8HeFiszo@j|vpd!}-+V52X_+tcYysbXL%A#GC?`I6wpiRB+5Lyj>Px;T zABpUeDBd3yLLASF_GxphHV^qntmf0^Cvi-xg%Nv9`x^9o?C19N{0FoXY{sq#004A{ BDU|>K delta 587 zcmV-R0<`^r1>^*fB!8ty{Rus^S2vi(Qb-VXtM<=FodFwRCW*6?*M zgz&`J8wqbr;Wd6diiw!fLnNC>H0K;NEMyjhw{S!hB05kVB9RlvLBcp8EFkPlz;W-N#iJEmOeK*>X^Q= z%fSw1pOc}du7kXm;7+Eexo!pV58OEz#~pj}u~dmA?L&f704}+s`9PTfh8gRFp&nEc zL>-25*hR?4@Y{a-Yh6m##XXzamUx>cI#{Qk`W);3JH^Dqk5PLWSLFteH-CcuCWLrPgISadq&(%DqC(0| z!@J&d58scT+FyyP&g&l)EZ*NX$OHgF7E2aKP5inle!)jrv$U(cx-aXZLRd2R@}bz~ z^|OUuRoik^>}>L^SQVT6FTG4D4$MGjGo0ajVWkbVO|fFJZd{oj-}2?A4WllU%XNpg z;b_|m;Y852W&f+j`@Onnt@GXIdY9Mbx-3@k?KjlBdWm-87cZ8I|FgLN^!)gxT-6UG Zc1aR<23+e(5OwRFLQU|TU{?SbEedvZ2WX11 zT3-dWnh$lKR9(Y8y>XZ&r7U5iGNVzF_`lB!w zCFo^&n15to-wn!03jkaVQw_7qTqeKZ9^SRIewa<-Tppv;Mm&D349w&*%+piT`q?s$ zx-ydU@Icm?!j9OZ(Zx1RWg~50XB6fd_Ua}!Q>dnN{=Al}Fi9H2YnPKNxMt&x zsrB7RxLC`{Q<}WSQ9e@>zfxxposwN}t)GK;@5&|VG#;aem-JKF=#`I*Y#v%|83$tj Q`LEXZFIojc$k+q`0Eb}700000 literal 393 zcmV;40e1c$iwFP!000001C>%uPr^VDU0P5+)R=hnFc*_@X}Vvf985Ic^{Cf|uF{0B z&`SLE=xlAnw4ebF?91$%w{Pb4t89b%_v4(JW0+I;r>t(f!{ zfKtY!xB>yvD?fM(qIpH~WA+u5;4NS)Qm(5!?uEN#WQc-Z$WgYpw(@j@)>5!mj!fiz z>%;dI1*f`OrmU5;mq5{!B)S(M%?SIS#eO8V?& z`48+Yr%#~%zZuO__$0$)ZQ2b?r^x=tg?(2>20CM4Q=RNkYpWM4(*_qmW z?{N0!(q-n*#N3Oi7c&>1cKRoNi#O|Qukftyu3Doz*q~l|b*p!^*+$v3Zr3(?AA=XV z(VO}&YEEoS}^Ls2qRB)b6)S2K~#&z#3SM;f*5{hrW8hz5CKO=GHcAWr^OsK6HJU4>hyj(Lui03Ff=)P5Tk_ fecC=)iA(oXP>%^mGVzP|8eId zBcM(Ui!ItepY|wI21PkY$9T}4PVXMyy(9efgb> z0{*msOmV6%A*`|-GAO7RR|^H1WR&fz7o4q_C?R8lij^*C8PQ0j(X<*@OFU8*l#iVxmAn368(ZCFuprpmPN4V2@tVtoiP*g@$#0p9EzKY(;gWe)g zshAWh6rh6kowq1jR5agL-!p~YBDSLCs>w#m)F+v{dwdoLY;c@3ZcK1Db@X1MMYx}c< z?Bk`c%yEf%kh37?K0ocuZ@7Z>>Mm$JtGnCQnhrm(puD^{o7z4`)w6EXHf9@x7p5`m z`WZDxE~n~%wgpb{-9&ANgu7e>x%9rw2VaJ!WavmX0~|-Qk~C~XD7I%NPyYbKxx9cu G1^@tj+5o=* diff --git a/tests/testthat/ref-CatTable_defaultPrint b/tests/testthat/ref-CatTable_defaultPrint index aea4951e72688d41c9bb11e8704290ed5185b0d4..82b3c9b611409fa484894330176622df51eb622e 100644 GIT binary patch literal 520 zcmV+j0{8tNiwFP!000001I<%SZ__{!T_>Sx0<;DGz+8~r%gXy@uMbF-df~(Y4sbQ~ zwzbqWQEa~cd|}qHo7qkHIAST@@$;KEGjE(v3&z-lO(zMPOnrEUx3_G@=6Ftpu|vp) z^C?&bsgc~A!y_azNFnEnK)Hcb3odq$Pz9tm=LJpFm}q%PpaSJ}&Lx2~YDr5fvYnK1OG)wQBg)CzNEhw>~A&F=f z_NPjoQL~U$W`U){6m(XLmYNXi%_>PnVwOO&Oz4d27oh)CW;YG^b;-~y^iO8tG`e3s zWf|T3C-yXt0CUUOxA^odEd_Zpc|o2sYsph-4OK6Se^8g1_zUa*JK1c4w`BbM>Sl?@ zbLRifjJ@oMA>|k;_tnz1NO?8z&U)_leR4kpi?*w}FD<06&j(}%02zq|iRHNF)_sRJ za81%qtM;ntT#K+E@X4)PSKTT?Puq1%o=T=*pOsj2X##q~mB^Wb%{2;a+1BE$zjJZc}y5b>nLI`~$iTX0wM#;n`Prb-B9x z*wo#vU)6~hx;WnMd_1=~)1Ofx+Ux=4yVXte4*Pq*`sQ0)3?B;XIpLKY_{Hzz>){uS K5swy51^@s>rvRS- literal 492 zcmVH38 zDkzNP<^modQ9=O~R|KjI6k2exhlHx3uobUqp~gbX8v@lRuPZJIq)|&+(vj^oC2Fd8 zm&@5yb6KO$%9Stc&vv5Au z@RFK^tfq`CowlI6TC~)}&}ddeIuf%4nq^{V)OY~>r#Aa-Ae>9aW}$zwjJMI_=_$+T z(LZsZc?4M7q`svwu(TB9%~UmcE3GAOjWtxguKz(@mf|n0|1Yv-j*o2q`*r;q!*dos zXU1NR#F%o7l$&<#2Bf^2c;_Q`_j`6TB`1S#{kH*%*B2AA1b~v{g5+{O^Wc8K8@M86 zXYFv=dp95~2z+|&Hm$!+(6eFFcW#@KSFUsG_BXQ}g`As5CR^bSUtCi5*w`UgB-fKG z%h{E=D4Q#?%}mGDd}8vG$>C8WPmcEDgWtBkzv^8FpMQeiVl}%<6rO!|m+x-Be(XDc i9Zq!`gx((SZa&9d&Eh_3M28)f+1)RH4M5T21pol*3h@E} diff --git a/tests/testthat/ref-CatTable_digits b/tests/testthat/ref-CatTable_digits index 1804d64cae0ab2af4eae58e54ec5612bee41d121..ef2330f4e7c923d39160f08ebdeb02a7ab0b6f90 100644 GIT binary patch delta 688 zcmV;h0#E&(1-b>07Jo4ni2GcS(#vYUy<35V#GL~i;2IjYwbV3KW4``;#cb-tmTA(UFr<+$m2v zMI>!;qII_>sGbQy}^&qQ}g320lvc?gPjVUcf$Y(Pq;!2d& z=46dryyZ^zWQ|*UQ^DOfq$OJ=fW{YZtAurpwlXdLF{^+JPj#kaA`L=@T>(kb=4*-JLlGv)XpRTH( z@D?t}v47{Y)p^}iD|AcZF0QKES+h*M&sVqgyt+$+536~#nEipvLA1HeFgwH=F015N zj&`&)u}!PW!S?syY_Ty_XUemS&bu*3w;LcVx=G}J(rUj(A1Cd6^{Kg=HT6YZ&Ee}W zXzrRbloL1Z6O`lc)%pA7_2+utTt%=VLcDtz2r0H*C;c_WxL#h?ACS$*<&TJQ)D8?= W$MmmJ=1%w1>;5;cq-ek_2><|*s%Itu delta 660 zcmV;F0&D%c1)c?v7JqRo5cjztrI*!yd$$4!iJ!m$uAy;hq^7NEgW%62W)df!*h>R9 z4)KnkXWzVeJ9a*w2qDJeU_27z0}9Xaaw`tSG2Iy5MxtF$!NF7~sa(8(EoKpO(!|hV z8uLPsA(Sjn!4#BKN-<0$=42TR+iPIzOR1fGvc^`EE@2v#On=@yttnHh>kDf_lHNF$ zpX(KCSu3sO+9G06s^quWSo=W*-0A+t5oGiI3b{N~towNhUC%kZTUT(W72hqyp%wB#vB|yu3NJA#jbk>0S6W?P=lQA-w$Tbm@ z^*GWyO34@Nq*Xh%rlGBoYz-3CXXLq(qu#7-by{&-Q_fZzVLF)7bB261=ZIIMtv+Wf zX^CD2y<;nBfhYr;rF_+{S6Cf|k=k~>ZMFDE6_atHv5#hS&Yji1-m4|oUH zY}?tazJFRYRgJJ_aB)*T%$oZidR9Ly=G9|A`M8=_%h?~a98oNNM%gj;@U`k~%gLtL zve>n*9Bsb`m&;9Px=>$UcjzV@J#2`u>85A@v)20+`?zZ zq8zbg&+Pcko0&KE*Ck^tWwSJ4=`6VC`1ru)>?zurFm`a+V9&rR$c*IX4LpQI4jB|& zkx*eE(}IhANT?DrTkw)5YD~1eBB2uLb-^VGY2=cYRAhTjiGQ3bZl-`txoNj5;vLsSMXNgeaxCeF&jg`cN!H8540qg%u4+M6s|xRq>pPg{UfzBps%p zvs#qY#GziSic}oU zwE?B2ASY9loFe45 zUbzk-uLsyJ)@ZFf^i<*KSk$ zHHn;co3?RV3R<|vt?DCnPlC_QkuDb4>y>+?z2Gb2>uzE4`8fHQl#Ch4W`yGyej?;z zP_gGoCyROc*>7v#Ube1*Z+GCgn9c4d49|YJi}&lBFKy$m!#Z9BqIajey^eO5Gy6R$ rM4LUre6zl4KVpBM);~jw%i&{SJtn@ABlq zM=qJ!mp5-_-Xvd67-KnGm46OXK_N=o`Eb7dHUb5p z<`rS9&`u^37}QjTYYHJtX>K1NG)o_vg)CzdEoiW#A%$ob&Zin)QnQfNl!>L&7IasO zmYNhA&1y(TVwOO&OzMmp51^lFv)=~7xnyb<`X|eD8$F($vWy=669<|{fVIusw|NXK zEd_a*swS_}T7U9ttfA_4{SWH06wk2!zsQz3eq{0I*Y#@*uUYszGxl~Qrj%o(+_q~s zAm!b}I~%#X@3Y(J$lzQ5W0+n`04PZ=NG_-R#o&Iy2e^(GZ-=Yiy8)rdKDlw5*5482 zblCKr+fvfXb#C20()TFj+&nVH3TOT1o*6IXisX9Qd{P-Vk40Im$TpFVYxtRwtI5St zBcC1S{L*h*-(UBxgRj5AZ?T%)&lFz$bXOnmzJKmJe-qB}CJ0>|@9rAou4eIP)`$)} PDzp2)Z;lVX#svTXnw#mx diff --git a/tests/testthat/ref-CatTable_format_f b/tests/testthat/ref-CatTable_format_f index 9c233d69902dea1be71a6adb0209dabbca05a72d..8b2ea4066e23c165f997003a5074c4d862c3117b 100644 GIT binary patch literal 411 zcmV;M0c8FkiwFP!000001I<&(PQx$|b(TVD0TuWGe?b*Dah3xT5*JP!-~iXqxUHqO zsT#BWe8EoRrIw{~#8NVE>^I{#Gs)`!0N{hb_kbS=IO4Ad5P~yq1B7!4A%qI%v4SX4 zFvTh?&NLxWFwoBb4;KW&lp`p-KL|RVa(vWAzsz5r- z*(gH;)XI$FQ@yLCgU+77Xq*@Ju5AS?nIOZ%X=Zp)o*Q1FTG3|DvOi>>MCb_X|5*_F z{N>5!R&>S91rR>~0M{+?kkaRrb-5x9r`&YBQOn(*du!Q|hL!BS>AaASI5IFYu$=N~ zL%!fGoOSN7Y^IcvhHpvsU_mw|tBsvuv!NB)nxr17$f|VQdm``{J5=DEg79rQo*-x$hJHh?5qsuA7px8FJEZI z7GfNiBGFxcKUZn@F~N^@ktx=Zd0EftBiHv-e+r3%?qdKg=WuzB$3C~$?iVU?{<>rZ F004<%#C`w( literal 384 zcmV-`0e}7~I5cnSWfrL|WJU|HNA_kb`3L=Cw%wr94q+v?5 zEY1ue(J(WzggENrcy45=>j}#PHr&`0BSuDy9g;Y^usjr|i^$k1Tpsf5R2SIDoP)AF zAmhwxJ~g-6I&^V}qFG+_Z~IZQk~y|Al4e#G<++s=dK69dEc-+Cd4x}}{$GU97l)^Y zTh$v8EWSea&!|?~6qy8=U1ONcdA-ebg diff --git a/tests/testthat/ref-CatTable_format_p b/tests/testthat/ref-CatTable_format_p index ce04295fccb5c54ffafb686d7dceb5047ce7f014..c936fad3b9c5eb26ae49e425e462b2bfaf0b983e 100644 GIT binary patch literal 449 zcmV;y0Y3g8iwFP!000001I<&*PQx$|bRHmDpe^tNz97NH%FBs!Ktkfei31$q8XC8a z)HYRPUO!)O(m2^zLE?y|WXJ2-$*k?X3=u*mvP=V+RtYEab&qT`kkN7}tD%kMP?&mz zHu;eF3I{H66=orc8V)0I!wHF}u*ZN7&}V*|cb!%fehcz(M8ZbXYxR9ff(8eKwQU8x zZPB(A(}r&QF>w@*9bh4BZBl@}80f&ZC}@SX)}T(OEf2Kiw0`6^hoD8JiRyTWB{vSV ztR72N;JIK%!wAeA#=tCQ6skwjAJjcZclQ4yvQ7Ci)I~|Nl?hc<#wF9sVu)06T1^>i1cm~SGNiod?FJ#&U>Cu93 z5|L}!ak0r#zSYSCp7K@litpu=czrkXq6Gi|?rGb2 literal 423 zcmV;Y0a*SYiwFP!000001I<%CPs1<}bv~$Qfi}P&@PY)3l{j(Y3`j^U>VJ6F{i+y)pimoF?gsv2!Ah0_l)y$t1&zO5g@ RW?N;n{Q;lniQhH_005(S#W4T? diff --git a/tests/testthat/ref-CatTable_format_pf b/tests/testthat/ref-CatTable_format_pf index e2b69a285df934b89ba4bdc607590a24b0fe7cbe..745591bf6e3db5ee512657e970b81100484396e8 100644 GIT binary patch literal 531 zcmV+u0_^=CiwFP!000001I<%SZ__{!T|1$I0wJaS0dql0FDvhty*?lz_0kiE_5fE? zZ(2)D6Jk@~&zJ6Q?0USl0!J*xGoE?#cIM6I>meZ|CX+ZK@x-}v`#L96^2*u?Q@V9Y zYhNo)6)ZrDQ|LmFQei_Z=|hrHW<#m!Lpr4yESShpp{BVjl&CPJ+=enl&$T~M_FPZR zXyH;!@E*+)e=0$* z5m!zVCl=B#Ph87P%6O*qWMw72Usk(=KE6}O0z2VHF@BCszzF# z*$J=BSnb$Q&KJm+t#H#$xUMMbDxysXw=*}v9$vId@Emcl*Q3j3TQt?OG9`Tb4b9e8 zlZSxe&AqugTi<@E%I3yxbLNOX&3D(Lv%8wfpWqA|Ic~NBiqLLP$y`X+qM8cjxZ-M5g4evlFIt=aSC8 zSDY$XfEE|fhajiIg;+L(B%{oQay5i>P77EtQJ_LiOJ68aVNSUV6^Nee@S+^JUYgOu zrq1fKLJDyTNwp6RC?}SDC6)?Y8gYRNg-{}{ zl4f2kq+gl&mYFDbrcjZ}Y8%o>QeK7^N5xWJ87A1y0{mc1?0aSqiwCg)t&3-28oU6v zdXLKGj(&b8O1|Pe07p>9y2aL`BxmTR@&es5t^Su#!Ck@TNm z-K?DXK>Y7a$Y}uXLJl3|zFL{qLC!kdJYcu^1P~qdmOomJm47Xs;)q?WVHLvN1J$djh+0)#N#1 tIQnI7t{?8cG_}3;+njl#tNHe`=K455+RhMS)QSMX45lxeMECqK%7yjT#8&Q z6vw4xM4r3Cf>yY!3HR%wmbes@P+wS5-r!QzqzM!O1=8**4QPs*uzf**22)`Z6toyn zdH7P$8ke*R+ok=WeI1w$srN)~_h8Yc5|p?kA`}3@1ySe04)Kp2fRQq&9JjCzl%j@i zcuT6t4M4P2XwWqrPNcvt85bru+OS9D1_d`{e0Xl16_06q<}nO_#a@6ntcu$f(+~qf zipd%9+cbkNOvWhc6@A zX*XUBMvqXYQTgOrZ#uJ1s;A>-==C-Q7rNK0?vY-e*__A&ofU9~E1l2|wQX}A<-)l# z_pW$S<{8<>!{KNqG5N?jJZa>~&|ZBp+s+J^gYNP7-`H${jqVeL7eDpIhxN_Zp*Pod zR3}#G{bDzBA9tMDpJb!B*#pWq>#N}t^!IsvXIosli-IQ1!zVlNOTVYj{acG-%ts1XhnCbA|o9P?4+CT`!XcR{%9(Cy+JkHS=B@jncsv$)~OcckdWJDeh zg(=N&niFo%NiK0JD518nL3x2wm6O6z1QbZQq77;x0UAuXCdg?qpmO&np*c=z z=Gukxpj9211<6-L-t}N!Qwd6365$Gf;DV@QXNUM^2VkUhDw7hp#+jE>FK0u(+3Ht(f^R+AZq?p2Mz>I= zUU}zU&nxp3RCn8XQ|mb##?}=}iYz0V zTR2?J1SYQy4)+>yu(bUPv#3mS+vpl!zhScgHhK>fwqEqj+0(;iQ=9v4RXd%~>2$es Y8<(8XN6^S0wpT{)pFO3AwqiwFP!000001I<-UZ<|06UE{a`$EhOu51^GQkqcr!S#Fhj@1Z@kw~EG_ z1j&vqL(}%pC!NJCy8&BiZ{@%~9y4!d-Y)jnIYKBv(_n&vsexB;`-aX?gv@nVCz%Dr z0&2m=g4@%<|H4eORE%DZ%Q6eN%_Bl}Fj6c|1Wma0SZi{+z}ALxa$R3 zU?lZRNZy_k7a@4-WM9F4Av4G-_<;0Ya!SUekolO*lp2$T5=RQ=!*uT@&4va4{}r7D zaGTgOxvDm>Tq5)PgwWE=H3$hI0@?i^iwFP!000001I<;-Zrd;rq~*A=5~m2@9}ox>P%eb{6m=`mPw1h&6>7vZ z0_?=F)S&(Ov`bkO87V^0TYV5$!=2gPA#H!XKnO)>87)w>wBa>8zM(S|Bl|h6i_8Vo z1mBVXS$QN=D>O53FgHq>6C&9xIuof)Y9aj3z1N zKI4M&JV~`8xkrRZ(jp+ODFB)jgNO!I$%!6-9QqK7Ft0%Y$*J!w7QkWJ15lWODi2bq zg5I*Q?#pS`6c{;C1A$vj=F7$s6u2b91CYUm?-a}vFQ$;5eO|zOFqDGoydaq`4}>B# ziUXs_LNhz-_~bzRj0)Tq;m{fYsX|{eP|dTTk^Y8g7k?Foswvggni3ylLK zSy)1e?w5@*3LCbSwqT0xi<}@Z2P?HF1MG!54aCExM|DwXOpBKZX6cjX%yqe z{CYj<3YX1o-I^JV4Zb&rvVEK*H;1}1#~Jb^HkH|zZ*_NRr}$ysO0&_)iIuzQcxRr> z4iCmqA2J^vT=)*doGl*tz3R>Gq$9^lhPqq)xjmL`eOH?*`Tjd;k5&Rbk7PDa=JwO$ o?n_;@_x9-CTeXkt(;aZ@iL?AOsuungbjs-YFHQfur^5yS0QGMMcmMzZ diff --git a/tests/testthat/ref-CatTable_noTests b/tests/testthat/ref-CatTable_noTests index 73ab1b715cb4adeb921377dcc0e4d62c84a133ab..793a086c092cf3d875c85e2c6132096f85c3a6d3 100644 GIT binary patch literal 594 zcmV-Y0-wZ__{!-8ca?!L${K`&^LHi{wYcoq5{ zuoC2vVOYN_te}*|mtiJj`T}V@X1t}J>Ku8D&Fo`Pp|mkMdg?pKYYFaTb{gwf5dVRl zf$`jNJ0DAxI@BSg*ahH_dsql`6TmQILolR4rBTx7kPcPEysZ$VqPu*QAuQUtYb&Q| z;wm06E0hv@flNjD6TCD5Kw}m@2S}PAq|A^I6zND3hDRO5p$uC}%u)Y}uP$1b`_^S- z-NLfzAc@N~$=*86t;>DuXbs7BE@h~O*2E`=t)u#xv09|%LvkzU*XsL%*6M_h8Ye~8 zNsGf!EuHYbI_p%+D<%QvMh6R5)dr83?Vp!xUa)G&X0)nz6C5VKgaIO*aSb@?0K!J1vWDC+B~DQiqimOj5NABtw{WH0K6YE|xB z@U&c&o8li@o>Lr|0cBI{;ih!14aufhu~>JmOpd#`+#JHB59M;*XV;F?&pMl1qQKdJ zH(#1v(NycIT*3E0(CnHeI)^VF9hUHCdHrE~_qAFzw?uYM6z|3UIi6?s>2lm{Z>mqI g=JWO!am>2i5G}@jMgt%Bz56`=1*R2yYEK6M02}NlxBvhE literal 565 zcmV-50?Pd#iwFP!000001C><4Zqq;z-8ca?!L${K`&^LRi{CUM=JYB^v@M& zh-48bH*i7}B05$BB9XIR#~I@!5JBQ(Nknv; z)3GJqrb!RhX>MKNTSsR|w)0k|YG_S*a@snopBraHIzAM4Fu&F?7j#yqeAT!qvQ9c0 zhHB}Q&(&L}I$f~{5Stw>tm+*;UUq+OLcHnyY9G$_p|%sZ8vS% z{%9b2d($He07zIYS)BIqi^l$fcd%t?S7mcsx3)o8GWhb&K9=pn2)$|^>&ouO*z=uf?{!w&7!RLvo;&B9iGVKN;1#u9Yfgz@+0XI}rq*xLpdunfn3zai66F`I% z4ZCG90Yrxq07IW30&14S1{pIQP=O8dIG7leD#Jz7GwHcVIqlH0e2Ld(GgmcB_0*O0 zQL;*xvO>wN)|qp6RvHYeI;}q{@bAW&=>b4!U}|92nycg&+{3#OHcG2mUdsw;YS32; zxlZfSVn@|F&*a7y4`e2n=@Bod3J2nVvjO%nmsZ#z+X{07M|vvl)Xtu_a+4N?HOvz| z$wup13sz@m1zc?9?6E9f^Q>N|4P2?WhrU)fTJQU4?f>bDa-Kh-hnMnG*%<1jli$U6 Uj&tC%-|e&e0UwR#*P{af0Q@AaQ2+n{ literal 347 zcmV-h0i^yPiwFP!0000019ef$PQx$|bdv&Yffm6J>;);kSg{>9=>Z9e58w#bs4+BB zU#dgJ*B922({7_Shj=ue-JKnO4j5wr3xf^|LI)r4_sF`ek7t;O%tPkSTd5>OT5~;y zh61S}f(eh0l$Z#JR7O=QO(4pqr-evC%2QexV|&3BQB9GO8P5*X!Hm+bXF?l5f|Q6) z$6y0U&NTpuK0$Lq$KirfQU^lgf-2<`Lb)+Y*E_RrfK;amttgjx+}F9fEZx9rQ%-+_EkFu!d?gfVK?zQLDwKn{_INP;j`+qz7?uR!6002Zsq16BY diff --git a/tests/testthat/ref-CatTable_showAllLevels b/tests/testthat/ref-CatTable_showAllLevels index 4defa1da7e9c19761f51c1e00442f78172dd1c3c..0585da0be84983466fed4105bbc81607f6a5def9 100644 GIT binary patch literal 555 zcmV+`0@VE^Lm(_lIeM92T0S<6Orrx%e zk|v5xfj?guJ2u^QHWA#g6z}Bio0&H=>;1eWgd}8|Oh__q%?o^eAv3Zd?XzDeY%us> zh{0G7#?5i^zaUda^}*(0S~(bM@Z;L{<~djisTNdU!5@e-NWoC)K}JKWIOQHBIHX+q zEG{!ht)ZC*DFtaBI&y@-(%geAhS!o>56V!NGE{i6I6@f@q$+e2)`z$hC_;t>8I;OG z5r;K$bcBo=50Y(o;fnx`v81NThma+eryd)u!rF8Y19HrygK`b(kvV0)9(05}=%z%+ zoCQ7a8Z2Y;^C5$iQ6bABqyrXb7(QcxuCBp(Fb0W(w>s>m>_)0ii-30UB5W}BT!a~o z>W-Sv(yHtEQ^w(Idj{y6s}bt&D#0VDHdzE^)<)3W>R8rn9KqieY@GG~U&$=N*JL=t zWwplTC26lbLN4()A5qSba$l@njg-rtchPbC`{uqkmUUA!-)czTTph{&ymmh#+vi1n zT{SM|xx91RqS?fp>TOlJUCe3WO1Caf=vbiATX%v$`Wol`|M|*2xYhByciS5?tfCq9 zZ{9br3z&=&z5dwjil(}$TnS%)LbF3}@;Hj{;=x_N+pIoSWpmd~;Z+;x?b%-Du_2)GqBqQ@|MzVPyUg6^lS&$X!KZkY3e87Dm ze6aPw-D&c_Aah3b(dKbk=>z3;T-!0c1S=ueg6bRi191j97%BtEXvh_(Jb(m;oXe2K zWdXT0v9$^}v$s;z60ay{~{2JU#@JdDA*?W*p33;Da76V+d~?nh$#vTARe z&ZU&=d$+5)$CRkuHMQHPL@QUjZFR=S3Y~s)X9#3G<8u7H+_)#VIequ;#$bV`=qCMJ zj?EhqW|Km1KX&`7Ywj9X!`GkC?NLphCmCKnx!Vtqn@>&M-S<;?(G>d5i4M@$A z3uyy2RQ&VRnRJ3_#5wHF$FsBV%wq@u3Vh{(^4UG7;|Kycp}Ti=ZM2a9CTWvI8;s%`9sec~jgB#*)3!+NNn~7;5GYD|QuH&oVy4!_I=FO*^a)v~tNeqI z3*p+Dy>%o038Udif&fWN%eM_g{`^jYaAt9ewtlv6+I)I^zs)ykQFOHQL`co5&YlK~ zYLiy()#VvJf6=6{>pVZ*<}b6dSh}ow=WzyHyS)T4X8rGfmHcg2ly7cMiXO^O78S|{ TVZX%#<9PQ2BB@4|`~d&}BfEco literal 248 zcmVIZ!ppgUA@ z=wXr6K_C^n{z&@&Nkk=mbjj)x$uo)ca}pduNy`-NC^<5dYhoQ-dPN$9oWf&#A*5@# zvS#a4h~J>w^Gx6%X({=-fXJUuP0*TY9HY+Loc9HwbSOU($$SyB0?_A)z% yS+Y;!2)BQqUZg<0RRAr)^Yp* diff --git a/tests/testthat/ref-svyCatTable_cramVars b/tests/testthat/ref-svyCatTable_cramVars index be2cf0071aa20cb8b8b5c59657c0a9f115e51b02..5a3d3e8f7757c0b040a4e8e224bef79fdc3268f3 100644 GIT binary patch literal 289 zcmV++0p9)}iwFP!000001HDj9Ps1<_b<-9>`PdK==LiX@yQC>$n|hdpG;!qs2jDnp zfk@kmSj4nHKX4isq|h^w5_E7)R1IX@hESIv=gFhA`hEG6#Sn36u z!)9gZT4^3-7b(lxqFN#4gn0di>+->p!2TnjaGB*iJs(ggndTUC5myzrRe1|8TA*6+ zP9QSX%6MvGlF~F|-gLb?^D#5}MOP(%+VE=(ZN2(~&+2(v&+m0<-t0t2c9N?zw;JEN n+VIPtxJ!G-SM&N+-=N&vdTkXav|wmB?ry&UlUTZ8t^xo6J8OvC literal 270 zcmV+p0rCDHiwFP!000001HDj9O9L?woz3nRtskuvJP(4fy<{h*AM8OW6n{Yv)nj#6 zT(DJa5d8DClTB73_G}KBH#6_O%;dfc00LqWfru^a^VNd{jya}kOp<(ZS&*FO<3bW< z6Oxl$7jiU2-@QP4EFCkgrT%FI9!k=$$JBc0|M37HJIHdPgBkpZkO;mapT}jr=5W@0 z8K-u%fO5o?&1zk3nKJOae#3SBXyd`j1KuL#3bX5>FLmdNYp&u{X{%B#xM_iI!Mg{E zskSDVCiSBLiH~1+$E97MKmDwp=5Mddx->6#qjS5-?8<#j7@ao$ U4mUnDd-D|R_JoyNxPAfv0C9kS=>Px# diff --git a/tests/testthat/ref-svyCatTable_defaultPrint b/tests/testthat/ref-svyCatTable_defaultPrint index 0509ca9309bbfb23f1ae64dfedbbf4b278eb683c..874eef4c6434c29d19fb1744e8b3a4ab5e336a7b 100644 GIT binary patch literal 265 zcmV+k0rvhMiwFP!000001B>8dU|?WkU}j=uU}6R_1%L!U0}BHukY+VBHPADFa(GNF z^$Zj=j4ky{G!@`t24FE`J!7~S4o$|?*Tev&*%S=*3=9mg@)$5^1{NkD!3gCur)1^= zDPC|W0J$Kypef-1D#=UCO)Um05r(Q00IP+_Gv+}VoRJE)3Wf?As+v#%E@wly2t*Gn zOphUqVFY6s!x#ln21`k5aS57RSfLI98^(m@H~!#~qQsKSw9M2Lg``RaSD?^8H2pkf zsmadyIpLWpB^e<9@PYi{AOHy%bQ+?U`9HdUvAG?KRXO?TnSMa$2IZH7T+9UxUIwrl P2>u5EHa+qKe*ypibQfg+ literal 243 zcmVhiwFP!000001FcZ83c@fHd`(+XQCsi_vIx3_#Mq&OAc$Y!ppMm6ENB%Q z1b@DorfG+$n@jHAP&4iC0o8 tjC}8r9G2JfCXL0ZoM%wZvGA+Km{?`)mpSjZ-qlx7ya5+~kfTom000*Tb%Fo@ diff --git a/tests/testthat/ref-svyCatTable_digits b/tests/testthat/ref-svyCatTable_digits index 5373eb37e152f98728213f7a3ba10d024d782683..6d2fdba0686f5289db25b910d81584b9d69811cd 100644 GIT binary patch literal 317 zcmV-D0mA+tiwFP!000001IdnEk!*#+F(PIa9<+!Q2HEtzTZQX zqNDKK?}{=nNQEdm8kc!($6%X%MfQsw*X+2nz0qHFw}Jty24`!sR-f&B+rRMxqjOQ@ zQT`Ca27+zUVQ_54>4f00*fWKyL`~w5WICE8Gm@OJ&MUO~zcFRfd=Qs{Hh9|Qgd53a zMthv{S{atJTYg1@ipo${0$B-4YP>PA^JJFSTHfP+i#yHQ6CB^>@1s0@PLo(X&c!f{ zBxM)15(gj2Q>`)1z0Hy^vV9ROg!SpbaNFg8aYLTDS@mxv>jiqcrA5uy|W zi)U&mDqa{Bq8NBw@!pQfPxdw0FLvCp*4 z7sCAD$&iRnCRdF2 zL{(dvR=aamhe;jERMrAn3#u@9r6APBLN`XqNm_rfy_*!4Uzao5QJMn)09)6Q@c;k- diff --git a/tests/testthat/ref-svyCatTable_explain b/tests/testthat/ref-svyCatTable_explain index 79fb30d17d516589b9ce04c96286bbdb31a8f6bc..f852f0b92a317144a6edd58109b835927f9fb9e5 100644 GIT binary patch literal 259 zcmV+e0sQ_SiwFP!000001FcX!Z^AGTy*LS?h?YqF0gq*|oVpAQNJxm40fy2sG-+!I zNL8#N{ycF0Vle5(;CuJZ@9cNC>Hq+Nm_$Hgon{z%kiY|Cnh!bSj&z43#_6*dvDX2; z*0`w&Ca$%An#BE^z+sE#jC0<|;07Tf7$V2xQf?6*%@&YqFM*_ul3lT__9*E)U1qfQ zKHB*q-sza;-o`XH%xY7w_1DphPlQi?T#~42uL2LLGhiMg!A!lS`Yn|FlvPRBM>@mO zDd_M1RUgxO^CnC6t><{s{wJATNQkyKK8JHQd2je?Q-8@h+FjHK?YQIC3Pxkk=>id0 Je~5Pi008{4eewVR literal 237 zcmV> ze_l<~#3AbDa_`>VyX4(%+5mvT!w9ffrI89f@S&wJh$oCPL&C|FGBV&(Iv$dDjp-Vv z{9XGo#Q#481{)-%jIpl_J`jAY0y5l7MXsQuub^n<#gR0Xq)76tRFb~YMOs_;QDK+Z zk{OAujYX_ktqrW!w$aEY+$I;3_%bV{;~_8x^kdlBskf5XM2dsRQnI^~r7As~`S6zQ n7w6Mjr1Dtp(XIT?qxv8&*0bKz-SeAw{S`c3Lij7@M*;uh=qkjBDNMRu*3|S3?nqe z&*SzLQnR$^J@?$6w&!#i0RRD?ctCvF##mYqKn*cW`mDnY3HpPt{xkod2n<$e(qW91 zGWbCV2o}$9KjlY+hDwE0zU@e=C^@Z<*%c*iql=YR?|Ua}dPRpcu{OquVp+sy3!aLD%+ZwoN3s48 o7xh{H<>oB&Uh-64?D-V!&WgKq9GPzgrP1s81~d;;2S)+`01yUnd;kCd literal 220 zcmV<203-h&iwFP!000001B>8dU|?WkU}j=uU}6R_1%L!U0}BHukY+VBHPADFa#&0) zk=O`v>M3G?(rgNbdIkmtSa}Q>Gy@A0kYI%JnNu=zffO&;S3oYvZZstvKqYyJxv9lK zCBjg30${ZedB!}Lqazh;6%1j{a5e<pwK@w{XAu<$qaXMgk`}HimSU2+96JcytPJ+Odwwr@clUh&V34u|Sn6O&R{a1ok;n(_-AO{QFo z@rP4f5hs3e2PXAjCJ6NiB^N?;c5qN3V{|2Qb#(^zn@-OY(dFz%fIB$V!!D|4S)jJ!d%0r~)V=S7oxU<`Z zHA|x_eEh^~qV|!0@UEX`^=fV^`{E`Wx{0nzzoNK$Z~7Ha-j%)MSF8Hj+)&)x`okse Thebo9@n`=HVNb}+i2?us>Y9Cw literal 249 zcmVAl9^dF0f2$eJYarKV>%)Tpg|bQq2R(6Ej8i;><&j<^zfl6 zu1FJ4+Dl0NR|qWDP;w!}+X`L~0!D{tYd_6)1Ruo~sLXqDEOoN%lbybhrDJ_@;VtjI zy(R5$9HYcf?5@xH)U#?dm4D?j9ad>sk$y!~MUIvPMqiB6RcKo(9%Igw(cGL9ldUtI z;_?S)B;A~R>#A4N!}cpn%_g6$oli80%N4m;X8m7x@^`%#U%~ATP+tX^Spon6Jxg>! diff --git a/tests/testthat/ref-svyCatTable_noSpaces b/tests/testthat/ref-svyCatTable_noSpaces index f58eb96e47c830eb5dec4083f682658ce61fe8c1..a3f737c8f5a575271c1aa4317e3670e9b7140434 100644 GIT binary patch literal 282 zcmV+#0p;T+o)F&P-*`^fv)@7;Y402~s|fG0K`(NRDOLyCKHiY3ZZUl!9@i73U1 znw4jGKH0TNgh*{wDkUc!7*!9fltel1Qu{WQjrrwyy zOXiKVm+@$};?}$`jDFU2B_6-T6}7ezzyDD`&70+&uFR{Q=g`h^Id+SQqhpirc-}tm gJx?v07ky23Z<09pctBme*a literal 265 zcmV+k0rvhMiwFP!000001C5YPYr;SfhG#bkHqsiQmmc?0sFyI?QNe>CNPj^OZI8A| zX`p_fi_kxBog}+r)*QU-eC+$|&O7g20FV$!0Wv7lJ|78$5OeJ45vHi0ZJCTFDWXCPYKO^#u>s?iFxVLBvnLt_Tto;ZAHvo_RxCN(RlDJ` z479KL6AUw+)*E`Ge4!DUg=}@P%p-hH5>fh{`@palUBQl9xb%r%j^5z_nP#shY-TZ!!3k84F~FRhT3Q!>8q?QaDe~FbodCE zV-I3rV-iHbqR>&Jm;nhy%q|?&=Kz|EA~vpNh7y8_aJMrzE%3F)Ig5YejH(F?0RBS$ zUQrwC4YzAAN$08@n&VTR>h>Fwu97TfbGcNK6RR5-t+k*FYT+KeC&78>mY6!!r4!zK zQ@Z$7YbIARqm?PI;jo6HhOZ9#w2;e!Hez>dW-|r5E>cB0rZ>ggtVo|ynUIGynd(HF zhDm=VA18TsniwFP!000001Iq$OC(r zBcIbGL!PC9n&lj6B6EHbsF6T4T$b^9E3=f8T&CYA3v0p8mXIv}O)@kcI3oUq{Jlb- zm<{*qs3=#u9NFKeGxZ&JBttD(FIQ@#B`01twpt&-*382_c1M%*G%N`VXvh|#`^Kfj zjkQu+Rk0>iv~b!&*}|6qV^*t8%{pTb{LHos2`<`#{B%OI6VOH+p3z+I2!k vTlKJbu5QYrelp*GY%(rS-9~n+^G5H!XY}Q?PXmyy73@9$P0I~aI0FCx@t=j# diff --git a/tests/testthat/ref-svyCatTable_noTests b/tests/testthat/ref-svyCatTable_noTests index 87257bb87c1ddd131217967e0afaa1e77594fcb6..e3565865f1b4126c855d3af8d0a42a1f669db60c 100644 GIT binary patch delta 41 xcmZo>n$9%gtJ2YuOuxFSW%3seJN|sCU|;OGxQB5KTho6=2BX%p1WRTH1^|GU5M=-W delta 21 ccmbQv)XX&DDR diff --git a/tests/testthat/ref-svyCatTable_overallPrint b/tests/testthat/ref-svyCatTable_overallPrint index ef598b24f7defeefadd549b246417eaa34b3f491..2a3399e6187f0b1c03b56f5dcb82e49fcb850ec1 100644 GIT binary patch delta 41 zcmV+^0M`H10q6mc#v;KqE+;=d(+}vPp!{->qqv{}!~h8-F#ZPsHYEa6odEy6CtPw(A(KIf_r00b!M0HL-WnAZU$unG2QY6n9jzD2rXggl_z zEJr?OX@)!-vNbr$IkHsd{P-Odh!)H;KK{sbpp;y$!Pr1J8MbA?K>kOAu+APcqY?jv z{$3#=_8$B-tv%gKI|Hm;49zIr?QQ}!>c%IaR9nYicGvrXLhI|s*U*VP-{i&nyH0{{S$ACIX3 literal 282 zcmV+#0pBVHZG*b#o_C`Yd0uJgC-5NJp z&`3k#&m(QOMJYi%+QZK5%X{;tGkrJ*00NXWfKZ$E%;yFYI0Jj?*uap8qexSXkO%aV z<;ce@&5&n(wgX2wN0!Q*55GZyXu&Mwl6RjZTCH@{VAFT!DwD{+JJTO?UA~m6U{9ay&On<;f3a52)3@rrEcC0r gWXH~Ba$R>D$68CjydC|mcV`8gEm~Tgv@`<%0C;nWAOHXW From abfe061bd84af74b29a30548cf2c5aedcb731ecc Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 09:21:45 -0400 Subject: [PATCH 127/219] Drop TableOne part from TableOne constructor TableOne object no longer contains the mixed list of continuous and categorical variables, and is simplified to contain only CatTable and ContTable parts. --- R/CreateTableOne.R | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index b6f1f64..efe6c9d 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -189,7 +189,8 @@ function(vars, # character vector of variab } - ## Condition on the absence of factor/numeric +### If only varFactors/varNumerics are present, just call one constructor and return + if (length(varNumerics) == 0) { ## No numerics message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') @@ -204,47 +205,19 @@ function(vars, # character vector of variab args = c(list(vars = varNumerics), argsCreateContTable)) return(ContTable) + ### Proceed if both types of variables are present (both factors and numerics) } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { - ## Create a list of constructors - listOfConstructors <- list(CreateContTable = CreateContTable, - CreateCatTable = CreateCatTable) - ## CreateCatTable for categorical. CreateContTable for continuous. - listOfConstructors <- listOfConstructors[logiFactors + 1] - ## Create a list of arguments - listOfArgs <- list(argsCreateContTable = argsCreateContTable, - argsCreateCatTable = argsCreateCatTable) - ## argsCreateCatTable for categorical. argsCreateContTable for continuous. - listOfArgs <- listOfArgs[logiFactors + 1] - - ## Create a list of tables by looping over variables/constructors/arguments - TableOne <- sapply(seq_along(listOfConstructors), - FUN = function(i) { - - args <- c(list(vars = vars[i]), # vector element - listOfArgs[[i]]) # list element - - do.call(listOfConstructors[[i]], # list element - args = args) - }, - simplify = FALSE) - - ## Give variable names to the result object - names(TableOne) <- vars - - - ## Create ContTable and CatTable objects (this is redundant, but easy) - ## Aggregated ContTable + ## ContTable ContTable <- do.call(CreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) - ## Aggregated CatTable + ## CatTable CatTable <- do.call(CreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) ## Create a list for output - TableOneObject <- list(TableOne = TableOne, - ContTable = ContTable, + TableOneObject <- list(ContTable = ContTable, CatTable = CatTable) ## Give a class From df7170bad4a33ca3ed1be1566994769b22eec3be Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 10:07:03 -0400 Subject: [PATCH 128/219] Save metadata in TableOne object --- R/CreateTableOne.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index efe6c9d..bc577d6 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -218,7 +218,13 @@ function(vars, # character vector of variab ## Create a list for output TableOneObject <- list(ContTable = ContTable, - CatTable = CatTable) + CatTable = CatTable, + MetaData = list(vars = vars, + ## describes which pos is vars is factor + logiFactors = logiFactors, + ## names of vars of each type + varFactors = varFactors, + varNumerics = varNumerics)) ## Give a class class(TableOneObject) <- "TableOne" From 76e04c640f9382d8e8a5ddf27a5081fd65e0d68d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 11:15:35 -0400 Subject: [PATCH 129/219] Change print.TableOne to use $ContTable and $CatTable print.TableOne now uses - TableOne$ContTable - TableOne$CatTable - TableOne$MetaData to construct a list of single-variable table This list can then be rbind()'ed to construct a single table Potential issues unnecessary spaces after parens ( 34.5), which does not variables from the other type (either Cont or Cat) --- R/modules.R | 212 +++++++++++++++++++++++++++++++++++++++++++++ R/print.TableOne.R | 150 ++++++++++++-------------------- 2 files changed, 266 insertions(+), 96 deletions(-) diff --git a/R/modules.R b/R/modules.R index a2b118a..814c1fd 100644 --- a/R/modules.R +++ b/R/modules.R @@ -703,6 +703,218 @@ ModuleContFormatStrata <- function(ContTable, nVars, listOfFunctions, digits) { +## Extract vecColWidths from a stratum sample size row +## Used by print.(svy)TableOne() +ModuleStratumSizesRow <- function(FmtTable, showAllLevels) { + + ## Length of vecColWidths is number of strata + nStrata <- length(attr(FmtTable, "vecColWidths")) + + ## Extract the sample size row from Fmt*Table + stratumSizesRow <- FmtTable[1, , drop = FALSE] + + + ## showAllLevels indicates if level column exists + if (showAllLevels) { + + ## Teke first nStrata columns after level column (position 1) + vecColWidths <- nchar(stratumSizesRow[1, 1 + seq_len(nStrata)]) + } else { + + ## Teke first nStrata columns + vecColWidths <- nchar(stratumSizesRow[1, seq_len(nStrata)]) + } + + ## Add + attr(stratumSizesRow, "vecColWidths") <- vecColWidths + + ## Return a single row matrix with vecColWidths attribute + stratumSizesRow +} + + +## Given a list of tables with vecColWidths, +## return a strata-by-table df containing spaces to add +ModuleNSpacesToAdd <- function(FmtElementTables) { + ## + ## Get the column width information for each object + ## each object has widths as many as strata + colWidthInfo <- sapply(FmtElementTables, + FUN = function(matObj) { + + attributes(matObj)$vecColWidths + }, + simplify = FALSE) + ## list to df + colWidthInfo <- as.data.frame(colWidthInfo) + + ## Get the max values for each stratum + vecMaxValues <- do.call(function(...) {pmax(..., na.rm = TRUE)}, colWidthInfo) + + ## Get the difference (value - max. Must be negated) + nSpacesToAdd <- sweep(x = colWidthInfo, + MARGIN = 1, + STATS = vecMaxValues, + FUN = "-") + ## Make sure these negative numbers are made positive + nSpacesToAdd <- abs(nSpacesToAdd) + ## Get rid of NA, so that it does not cause problem in rep() as a times argument + nSpacesToAdd[is.na(nSpacesToAdd)] <- 0 + nSpacesToAdd +} + + +## Add spaces to table columns as specified in nSpacesToAdd and considering showAllLevels +ModuleAddSpacesToTable <- function(FmtElementTables, nSpacesToAdd, showAllLevels) { + ## For each matrix, add spaces + spaceFormattedTables <- + sapply(seq_along(FmtElementTables), + FUN = function(i) { + + ## For i-th table + matObj <- FmtElementTables[[i]] + nSpaces <- nSpacesToAdd[, i] + + ## For j-th stratum (column), add spaces. + ## Be aware of the p-value column (last. not included in first palce) + ## and level column (1st. explicitly ignore). + for (j in seq_along(nSpaces)) { + + ## If showAllLevels is requested, ignore the first column (level column). + if (showAllLevels) { + matObj[, (j + 1)] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), + matObj[, (j + 1)]) + + } else { + ## if not, no need to ignore the first column + matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), + matObj[, j]) + } + + } + + ## Return the adjusted table + matObj + }, + simplify = FALSE) + + ## Restore names for easy acces + names(spaceFormattedTables) <- names(FmtElementTables) + spaceFormattedTables +} + + +## Extract Cont/CatTable elements of x and dispatch print() appropriately +ModuleFormatTables <- function(x, catDigits, contDigits, + ## Generic argumetns passed + test, smd, + explain, pDigits, + ## print.CatTable arguments passed + format, exact, + showAllLevels, cramVars, + ## print.ContTable arguments passed + nonnormal, minMax, insertLevel + ) { + + ## Two-element list(ContTable, CatTable) + ## Cont first throughout this function + TableOne <- list(x$ContTable, x$CatTable) + + ## Get the Cont/Cat status (1st of classes) + ## Always (ContTable, CatTable) by new definition + classOfTables <- sapply(TableOne, class)[1,] + + ## Decimal point vector + contCatDigitis <- c(CatTable = catDigits, ContTable = contDigits)[classOfTables] + + ## Get the formatted tables (FmtContTable, FmtCatTable) + FmtTables <- + sapply(seq_along(TableOne), + ## loop over ContTable and CatTable + FUN = function(i) { + + ## print.CatTable or print.ContTable called depending on the class + print(TableOne[[i]], + ## Number of digits depends on Cont or CatTable + digits = contCatDigitis[i], + + ## Do not print + printToggle = FALSE, + + ## The rests are just passed + ## generic arguments passed + test = test, smd = smd, + explain = explain, pDigits = pDigits, + + ## print.CatTable arguments passed + format = format, exact = exact, + showAllLevels = showAllLevels, # Returns one more column if TRUE + cramVars = cramVars, + + ## print.ContTable arguments passed + nonnormal = nonnormal, minMax = minMax, insertLevel = showAllLevels + ) # Method dispatch at work + }, + simplify = FALSE) + ## Name formatted tables for easier access (Cont first!) + names(FmtTables) <- c("FmtContTable", "FmtCatTable") + + FmtTables +} + + +## Obtain a vector indictor showing n-th variable's +## correspondence row(s) in FmtCatTable +ModuleVarToRowFmtCatTable <- function(spaceFmtEltTables) { + ## Extract logical vector of which rows are title rows + logiNameRows <- attr(spaceFmtEltTables$FmtCatTable, "logiNameRows") + ## Create a numeric representation of which row(s) belong to which variable + numNameRows <- as.numeric(logiNameRows) + numNameRows[logiNameRows] <- seq_len(sum(logiNameRows)) + numNameRows[!logiNameRows] <- NA + ## LOCF for subheaders (some variables have multiple rows) + numNameRows <- zoo::na.locf(numNameRows, na.rm = FALSE) + ## First element is always sample size and should be 0 to avoid NA, + ## which breaks == use + numNameRows[1] <- 0 + numNameRows +} + + +## Create a list of one variable tables excluding sample size row +ModuleListOfOneVarTables <- function(spaceFmtEltTables, MetaData) { + + ## Obtain a vector indictor showing n-th variable's + ## correspondence row(s) in FmtCatTable + vecVarToRow <- ModuleVarToRowFmtCatTable(spaceFmtEltTables) + + ## Pick elements and construct a list of rows to rbind + ## loop over vars picking elements from appropriate objects + lstOneVarTables <- lapply(seq_along(MetaData$vars), function(i) { + + ## Extract current elements + var <- MetaData$vars[i] + logiFactor <- MetaData$logiFactors[i] + + ## Conditional on if its logical + if (logiFactor) { + ## If cat + nthElt <- which(var == MetaData$varFactors) + rowsToPick <- which(nthElt == vecVarToRow) + + spaceFmtEltTables$FmtCatTable[rowsToPick, , drop = FALSE] + + } else { + ## If Cont + nthElt <- which(var == MetaData$varNumerics) + + ## + 1 because of sample size row + spaceFmtEltTables$FmtContTable[nthElt + 1, , drop = FALSE] + } + }) + lstOneVarTables +} + ### Modules by both print and summary methods ## ModuleQuoteAndPrintMat() ## Takes an matrix object format, print, and (invisibly) return it diff --git a/R/print.TableOne.R b/R/print.TableOne.R index b2d53a2..4ff3411 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -105,107 +105,65 @@ function(x, # TableOne object ...) { - ## Get the mixed element only - TableOne <- x$TableOne - - ## Get the Cont/Cat status (1st of classes) - classOfTables <- sapply(TableOne, class)[1,] - ## This relies on Cat/Cont alphabetical order (svyCat/svyCont work similarly) - digits <- c(CatTable = catDigits, ContTable = contDigits)[as.numeric(factor(classOfTables))] - - - ## Get the formatted tables - formattedTables <- - sapply(seq_along(TableOne), - FUN = function(i) { - - ## print.CatTable or print.ContTable called depending on the class - print(TableOne[[i]], printToggle = FALSE, test = test, smd = smd, - explain = explain, digits = digits[i], pDigits = pDigits, - - ## print.CatTable arguments - format = format, exact = exact, - showAllLevels = showAllLevels, # Returns one more column if TRUE - cramVars = cramVars, - - ## print.ContTable argument - nonnormal = nonnormal, minMax = minMax, insertLevel = showAllLevels - ) # Method dispatch at work - }, - simplify = FALSE) - - ## Get the column width information (strata x vars format) - columnWidthInfo <- sapply(formattedTables, - FUN = function(matObj) { - - attributes(matObj)$vecColWidths - }, - simplify = FALSE) - columnWidthInfo <- do.call(cbind, columnWidthInfo) - - ## Get the max values for each stratum - vecMaxValues <- apply(columnWidthInfo, MARGIN = 1, FUN = max, na.rm = TRUE) - - ## Get the difference (value - max. Must be negated) - nSpacesToAdd <- sweep(x = columnWidthInfo, - MARGIN = 1, - STATS = vecMaxValues, - FUN = "-" - ) - nSpacesToAdd <- -1 * nSpacesToAdd - ## Get rid of NA, so that it does not cause problem in rep() as a times argument - nSpacesToAdd[is.na(nSpacesToAdd)] <- 0 - - ## For each matrix, add spaces - spaceFormattedTables <- - sapply(seq_along(formattedTables), - FUN = function(i) { - - ## For i-th variable - matObj <- formattedTables[[i]] - nSpaces <- nSpacesToAdd[, i] - - ## For j-th stratum (column), add spaces. - ## Be aware of the p-value column (last. not included in first palce) - ## and level column (1st. explicitly ignore). - for (j in seq_along(nSpaces)) { - - ## If showAllLevels is requested, ignore the first column (level column). - if (showAllLevels) { - matObj[, (j + 1)] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), - matObj[, (j + 1)]) - - } else { - ## if not, no need to ignore the first column - matObj[, j] <- paste0(paste0(rep(" ", nSpaces[j]), collapse = ""), - matObj[, j]) - } - - } - - ## Return the adjusted table - matObj - }, - simplify = FALSE) - - ## Set aside the n row (stratum sizes). 1st element, 1st row - stratumSizesRow <- spaceFormattedTables[[1]][1, , drop = FALSE] - - ## Remove 1st rows from each table (stratum sizes) - spaceFormattedTables <- sapply(spaceFormattedTables, - FUN = function(matObj) { - - matObj[-1, , drop = FALSE] - }, - simplify = FALSE) + ## Extract Cont/CatTable elements of x and dispatch print() appropriately + FmtTables <- ModuleFormatTables(x, + catDigits = catDigits, contDigits = contDigits, + test = test, smd = smd, + explain = explain, pDigits = pDigits, + + ## print.CatTable arguments passed + format = format, exact = exact, + ## Returns one more column if TRUE + showAllLevels = showAllLevels, + cramVars = cramVars, + + ## print.ContTable arguments passed + nonnormal = nonnormal, minMax = minMax, + insertLevel = showAllLevels) + + ## List of stratum sample size row only tables + FmtStratumSizesTables <- sapply(FmtTables, + FUN = ModuleStratumSizesRow, + showAllLevels = showAllLevels, + simplify = FALSE) + names(FmtStratumSizesTables) <- paste0(names(FmtStratumSizesTables), "N") + + ## Combine as a list of necessary table elements + FmtElementTables <- c(FmtTables, FmtStratumSizesTables) + + + ## Add space paddings + ## Given a list of tables with vecColWidths, + ## return a strata-by-table df containing spaces to add + nSpacesToAdd <- ModuleNSpacesToAdd(FmtElementTables) + ## Actually add spaces to tables + spaceFmtEltTables <- ModuleAddSpacesToTable(FmtElementTables, nSpacesToAdd, showAllLevels) + + + ## Create a list of one variable tables excluding sample size row + lstOneVarTables <- ModuleListOfOneVarTables(spaceFmtEltTables, + MetaData = x$MetaData) + + + ## Check if the first row is CatTable element + ## if so, pick sample size row from CatTable element + ## Intentionally a one-element list + lstStratumSizesRow <- ifelse(x$MetaData$logiFactors[1], + ## Change this to spaceFmtEltTables$ after tests pass + ## These are not space-padded yet + list(FmtElementTables$FmtCatTableN), + list(FmtElementTables$FmtContTableN)) ## Row-combin n and all variables - out <- do.call(rbind, c(list(stratumSizesRow), spaceFormattedTables)) + out <- do.call(rbind, + ## List concatenation (both are lists) + c(lstStratumSizesRow, lstOneVarTables)) + ## Add stratification information to the column header (This is also in the constructor) - if (length(TableOne[[1]]) > 1 ) { + if (length(x$ContTable) > 1 ) { ## Combine variable names with : in between - strataVarName <- attributes(TableOne[[1]])$strataVarName + strataVarName <- attributes(x$ContTable)$strataVarName ## Create strata string strataString <- paste0("Stratified by ", strataVarName) From 70d81f5cbc563f75f2232764d67e9abfeaa14049 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 11:31:21 -0400 Subject: [PATCH 130/219] Change svyCreateTableOne constructor following CreateTableOne No variable level invocations of print() --- R/svyCreateTableOne.R | 45 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index f5c0901..e2b6985 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -170,7 +170,7 @@ function(vars, # character vector of variable } - ## Condition on the absence of factor/numeric +### If only varFactors/varNumerics are present, just call one constructor and return if (length(varNumerics) == 0) { ## No numerics message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') @@ -188,45 +188,22 @@ function(vars, # character vector of variable ### Proceed if both types of variables are present (both factors and numerics) } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { - ## Create a list of constructors - listOfConstructors <- list(CreateContTable = svyCreateContTable, - CreateCatTable = svyCreateCatTable) - ## CreateCatTable for categorical. CreateContTable for continuous. - listOfConstructors <- listOfConstructors[logiFactors + 1] - ## Create a list of arguments - listOfArgs <- list(argsCreateContTable = argsCreateContTable, - argsCreateCatTable = argsCreateCatTable) - ## argsCreateCatTable for categorical. argsCreateContTable for continuous. - listOfArgs <- listOfArgs[logiFactors + 1] - - ## Create a list of tables by looping over variables/constructors/arguments - TableOne <- sapply(seq_along(listOfConstructors), - FUN = function(i) { - - args <- c(list(vars = vars[i]), # vector element - listOfArgs[[i]]) # list element - - do.call(listOfConstructors[[i]], # list element - args = args) - }, - simplify = FALSE) - - ## Give variable names to the result object - names(TableOne) <- vars - - - ## Create ContTable and CatTable objects (this is redundant, but easy) - ## Aggregated ContTable + ## ContTable ContTable <- do.call(svyCreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) - ## Aggregated CatTable + ## CatTable CatTable <- do.call(svyCreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) ## Create a list for output - TableOneObject <- list(TableOne = TableOne, - ContTable = ContTable, - CatTable = CatTable) + TableOneObject <- list(ContTable = ContTable, + CatTable = CatTable, + MetaData = list(vars = vars, + ## describes which pos is vars is factor + logiFactors = logiFactors, + ## names of vars of each type + varFactors = varFactors, + varNumerics = varNumerics)) ## Give a class class(TableOneObject) <- c("svyTableOne", "TableOne") From 18e0b733949c7e65b9fef2b95d6d2fb0c24ba372 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 11:42:16 -0400 Subject: [PATCH 131/219] Fix decimal point picker to support svy* objects Only errors remaining are spacing errors --- R/modules.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/modules.R b/R/modules.R index 814c1fd..3a9c641 100644 --- a/R/modules.R +++ b/R/modules.R @@ -824,8 +824,11 @@ ModuleFormatTables <- function(x, catDigits, contDigits, ## Always (ContTable, CatTable) by new definition classOfTables <- sapply(TableOne, class)[1,] - ## Decimal point vector - contCatDigitis <- c(CatTable = catDigits, ContTable = contDigits)[classOfTables] + ## Decimal point vector; pick appropriately depending on class + contCatDigits <- c(ContTable = contDigits, + CatTable = catDigits, + svyContTable = contDigits, + svyCatTable = catDigits)[classOfTables] ## Get the formatted tables (FmtContTable, FmtCatTable) FmtTables <- @@ -836,7 +839,7 @@ ModuleFormatTables <- function(x, catDigits, contDigits, ## print.CatTable or print.ContTable called depending on the class print(TableOne[[i]], ## Number of digits depends on Cont or CatTable - digits = contCatDigitis[i], + digits = contCatDigits[i], ## Do not print printToggle = FALSE, From 0eab85b075f5314e3c30d397d63641476c3c5ab3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 12:57:54 -0400 Subject: [PATCH 132/219] Record error logs for spacing difference (expected behavior) Now print.TableOne prints all categorical variables at the same time. Individual variables in the categorical group, may appear with different spacing before parenthesis compared to the old refs. This is an expected behavior and it not an issue. --- test-all.txt | 884 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 657 insertions(+), 227 deletions(-) diff --git a/test-all.txt b/test-all.txt index 336624a..d86d0c3 100644 --- a/test-all.txt +++ b/test-all.txt @@ -9,7 +9,7 @@ Unit tests for the CreateTableOne function : ........... St 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 edema (%) 0.877 @@ -30,7 +30,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -. +1 Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -40,7 +40,7 @@ Unit tests for the CreateTableOne function : ........... St 2 161 (38.5) age (mean (sd)) 50.74 (10.45) sex = f (%) 374 (89.5) - ascites = 1 (%) 24 (7.7) + ascites = 1 (%) 24 ( 7.7) hepato = 1 (%) 160 (51.3) spiders = 1 (%) 90 (28.8) edema (%) @@ -61,7 +61,7 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) -. +2 Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -107,18 +107,18 @@ Unit tests for the CreateTableOne function : ........... St n 21 15 137 time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) status (%) - 0 4 (19.0) 7 (46.7) 79 (57.7) - 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) - 2 14 (66.7) 8 (53.3) 51 (37.2) + 0 4 (19.0) 7 (46.7) 79 ( 57.7) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) + 2 14 (66.7) 8 (53.3) 51 ( 37.2) age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) - sex = f (%) 0 (0.0) 0 (0.0) 137 (100.0) - ascites = 1 (%) 1 (4.8) 2 (13.3) 13 (9.5) - hepato = 1 (%) 12 (57.1) 9 (60.0) 61 (44.5) - spiders = 1 (%) 3 (14.3) 1 (6.7) 42 (30.7) + sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) + ascites = 1 (%) 1 ( 4.8) 2 (13.3) 13 ( 9.5) + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 ( 44.5) + spiders = 1 (%) 3 (14.3) 1 ( 6.7) 42 ( 30.7) edema (%) - 0 17 (81.0) 12 (80.0) 115 (83.9) - 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) - 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) + 0 17 (81.0) 12 (80.0) 115 ( 83.9) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) @@ -129,27 +129,27 @@ Unit tests for the CreateTableOne function : ........... St platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) stage (%) - 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) - 2 4 (19.0) 2 (13.3) 31 (22.6) - 3 7 (33.3) 5 (33.3) 49 (35.8) - 4 8 (38.1) 7 (46.7) 47 (34.3) + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) + 2 4 (19.0) 2 (13.3) 31 ( 22.6) + 3 7 (33.3) 5 (33.3) 49 ( 35.8) + 4 8 (38.1) 7 (46.7) 47 ( 34.3) Stratified by trt:sex 2:f p test n 139 time (mean (sd)) 1979.65 (1127.52) 0.730 status (%) 0.033 - 0 78 (56.1) - 1 9 ( 6.5) - 2 52 (37.4) + 0 78 ( 56.1) + 1 9 ( 6.5) + 2 52 ( 37.4) age (mean (sd)) 47.66 (9.54) <0.001 sex = f (%) 139 (100.0) <0.001 - ascites = 1 (%) 8 (5.8) 0.516 - hepato = 1 (%) 78 (56.1) 0.208 - spiders = 1 (%) 44 (31.7) 0.089 + ascites = 1 (%) 8 ( 5.8) 0.516 + hepato = 1 (%) 78 ( 56.1) 0.208 + spiders = 1 (%) 44 ( 31.7) 0.089 edema (%) 0.906 - 0 119 (85.6) - 0.5 12 ( 8.6) - 1 8 ( 5.8) + 0 119 ( 85.6) + 0.5 12 ( 8.6) + 1 8 ( 5.8) bili (mean (sd)) 3.75 (5.50) 0.394 chol (mean (sd)) 381.73 (262.26) 0.512 albumin (mean (sd)) 3.53 (0.39) 0.585 @@ -160,11 +160,11 @@ Unit tests for the CreateTableOne function : ........... St platelet (mean (sd)) 267.95 (92.20) 0.362 protime (mean (sd)) 10.75 (1.15) 0.137 stage (%) 0.646 - 1 3 ( 2.2) - 2 30 (21.6) - 3 59 (42.4) - 4 47 (33.8) -. Stratified by trt + 1 3 ( 2.2) + 2 30 ( 21.6) + 3 59 ( 42.4) + 4 47 ( 33.8) +3 Stratified by trt 1 2 p n 158 154 time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 @@ -174,7 +174,7 @@ Unit tests for the CreateTableOne function : ........... St 2 65 (41.139) 60 (38.961) age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 sex = f (%) 137 (86.709) 139 (90.260) 0.42123 - ascites = 1 (%) 14 (8.861) 10 (6.494) 0.56729 + ascites = 1 (%) 14 ( 8.861) 10 ( 6.494) 0.56729 hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 edema (%) 0.87682 @@ -226,7 +226,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -. Stratified by trt +4 Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -236,7 +236,7 @@ Unit tests for the CreateTableOne function : ........... St 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) sex = f (%) 137 (86.7) 139 (90.3) - ascites = 1 (%) 14 (8.9) 10 (6.5) + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) hepato = 1 (%) 73 (46.2) 87 (56.5) spiders = 1 (%) 45 (28.5) 45 (29.2) edema (%) @@ -257,7 +257,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -. Stratified by trt +5 Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -267,7 +267,7 @@ Unit tests for the CreateTableOne function : ........... St 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) sex = f (%) 137 (86.7) 139 (90.3) - ascites = 1 (%) 14 (8.9) 10 (6.5) + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) hepato = 1 (%) 73 (46.2) 87 (56.5) spiders = 1 (%) 45 (28.5) 45 (29.2) edema (%) @@ -319,7 +319,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -. Stratified by trt +6 Stratified by trt 1 n 158 time (mean (sd)) 2015.62 (1094.12) @@ -329,7 +329,7 @@ Unit tests for the CreateTableOne function : ........... St 2 65 (41.1) age (mean (sd)) 51.42 (11.01) sex = f (%) 137 (86.7) - ascites = 1 (%) 14 (8.9) + ascites = 1 (%) 14 ( 8.9) hepato = 1 (%) 73 (46.2) spiders = 1 (%) 45 (28.5) edema (%) @@ -360,7 +360,7 @@ Unit tests for the CreateTableOne function : ........... St 2 60 (39.0) age (mean (sd)) 48.58 (9.96) 0.018 sex = f (%) 139 (90.3) 0.421 - ascites = 1 (%) 10 (6.5) 0.567 + ascites = 1 (%) 10 ( 6.5) 0.567 hepato = 1 (%) 87 (56.5) 0.088 spiders = 1 (%) 45 (29.2) 0.985 edema (%) 0.877 @@ -381,7 +381,7 @@ Unit tests for the CreateTableOne function : ........... St 2 32 (20.8) 3 64 (41.6) 4 54 (35.1) -. Stratified by trt +7 Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -1066,106 +1066,208 @@ Unit tests for the CreateTableOne function : ........... St . Unit tests for the modules : ........ Tests for functions for standardized mean differences : ................................................................................... + ### Summary of continuous variables ### + +HI_CHOL: 0 +RIAGENDR: 1 + n miss p.miss mean sd median p25 p75 min max skew kurt +race 3526 0 0 2 0.9 2 1 2 1 4 0.6 -0.3 +------------------------------------------------------------ +HI_CHOL: 1 +RIAGENDR: 1 + n miss p.miss mean sd median p25 p75 min max skew kurt +race 363 0 0 2 0.9 2 1 2 1 4 0.8 -0.1 +------------------------------------------------------------ +HI_CHOL: 0 +RIAGENDR: 2 + n miss p.miss mean sd median p25 p75 min max skew kurt +race 3533 0 0 2 0.9 2 1 2 1 4 0.6 -0.4 +------------------------------------------------------------ +HI_CHOL: 1 +RIAGENDR: 2 + n miss p.miss mean sd median p25 p75 min max skew kurt +race 424 0 0 2 0.8 2 1 2 1 4 0.7 0.6 + +p-values + pNormal pNonNormal +race 0.5071597 0.5761282 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +race 0.04247045 0.03492105 0.0006074061 0.07524267 0.03396878 0.03638678 + 3 vs 4 +race 0.073696 + +======================================================================================= + + ### Summary of categorical variables ### + +HI_CHOL: 0 +RIAGENDR: 1 + var n miss p.miss level freq percent cum.percent + agecat 3526 0 0.0 (0,19] 1119 31.7 31.7 + (19,39] 797 22.6 54.3 + (39,59] 775 22.0 76.3 + (59,Inf] 835 23.7 100.0 + +------------------------------------------------------------ +HI_CHOL: 1 +RIAGENDR: 1 + var n miss p.miss level freq percent cum.percent + agecat 363 0 0.0 (0,19] 10 2.8 2.8 + (19,39] 88 24.2 27.0 + (39,59] 173 47.7 74.7 + (59,Inf] 92 25.3 100.0 + +------------------------------------------------------------ +HI_CHOL: 0 +RIAGENDR: 2 + var n miss p.miss level freq percent cum.percent + agecat 3533 0 0.0 (0,19] 1015 28.7 28.7 + (19,39] 950 26.9 55.6 + (39,59] 796 22.5 78.1 + (59,Inf] 772 21.9 100.0 + +------------------------------------------------------------ +HI_CHOL: 1 +RIAGENDR: 2 + var n miss p.miss level freq percent cum.percent + agecat 424 0 0.0 (0,19] 6 1.4 1.4 + (19,39] 70 16.5 17.9 + (39,59] 167 39.4 57.3 + (59,Inf] 181 42.7 100.0 + + +p-values + pApprox pExact +agecat 9.387606e-89 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +agecat 0.702331 0.9040822 0.109801 0.985333 0.8536402 0.3838583 0.9772713 +.. Stratified by HI_CHOL:RIAGENDR + 0:1 1:1 0:2 1:2 p test + n 3526 363 3533 424 + race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 +... Stratified by HI_CHOL:RIAGENDR + 0:1 1:1 0:2 1:2 p + n 3526 363 3533 424 + race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 + agecat (%) <0.001 + (0,19] 1119 (31.7) 10 ( 2.8) 1015 (28.7) 6 ( 1.4) + (19,39] 797 (22.6) 88 (24.2) 950 (26.9) 70 (16.5) + (39,59] 775 (22.0) 173 (47.7) 796 (22.5) 167 (39.4) + (59,Inf] 835 (23.7) 92 (25.3) 772 (21.9) 181 (42.7) + Stratified by HI_CHOL:RIAGENDR + test SMD + n + race (mean (sd)) 0.042 + agecat (%) 0.702 + (0,19] + (19,39] + (39,59] + (59,Inf] +. Unit tests for svy* user functions : .... Stratified by E - 1 2 3 p test - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 -. - Overall - n 450.01 - E (mean (sd)) 2.00 (0.82) - C (mean (sd)) 2.13 (0.88) - Y = 1 (%) 177.0 (39.4) - C1 = 1 (%) 150.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) -. - Overall - n 450.01 - E (mean (sd)) 2.00 (0.82) - C (mean (sd)) 2.13 (0.88) - Y (%) - 0 272.7 (60.6) - 1 177.0 (39.3) - NA 0.3 ( 0.1) - C1 = 1 (%) 150.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) -. Stratified by E:C1 - 1:0 2:0 3:0 1:1 - n 100.01 100.00 100.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 (74.0) - C1 = 1 (%) 0.0 (0.0) 0.0 (0.0) 0.0 (0.0) 50.0 (100.0) - C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) 1.000 + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 +8 + Overall + n 450.01 + E (mean (sd)) 2.00 (0.82) + C (mean (sd)) 2.13 (0.88) + Y = 1 (%) 177.0 (39.4) + C1 = 1 (%) 150.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) +9 + Overall + n 450.01 + E (mean (sd)) 2.00 (0.82) + C (mean (sd)) 2.13 (0.88) + Y (%) + 0 272.7 (60.6) + 1 177.0 (39.3) + NA 0.3 ( 0.1) + C1 = 1 (%) 150.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) +a Stratified by E:C1 + 1:0 2:0 3:0 1:1 + n 100.01 100.00 100.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) Stratified by E:C1 - 2:1 3:1 p test - n 50.00 50.00 - E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 - Y = 1 (%) 37.0 (74.0) 37.0 (74.0) <0.001 - C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 - C2 (mean (sd)) 0.20 (0.40) 0.20 (0.40) <0.001 -. Stratified by E - 1 2 3 p - n 150.0120 150.0030 150.0000 - E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) <0.00001 - C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) 1.00000 - Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 0.99982 - C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.00000 - C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) 1.00000 + 2:1 3:1 p test + n 50.00 50.00 + E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 + Y = 1 (%) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 + C2 (mean (sd)) 0.20 (0.40) 0.20 (0.40) <0.001 +b Stratified by E + 1 2 3 + n 150.0120 150.0030 150.0000 + E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) + C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) + C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) Stratified by E - test - n - E (mean (sd)) - C (mean (sd)) - Y = 1 (%) - C1 = 1 (%) - C2 (mean (sd)) -. Stratified by E - 1 2 3 - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) - C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) -. Stratified by E - 1 2 3 p - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) NA - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 + p test + n + E (mean (sd)) <0.00001 + C (mean (sd)) 1.00000 + Y = 1 (%) 0.99982 + C1 = 1 (%) 1.00000 + C2 (mean (sd)) 1.00000 +c Stratified by E + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) +d Stratified by E + 1 2 3 + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) Stratified by E - test - n - E (mean (sd)) - C (median [IQR]) nonnorm - Y = 1 (%) exact - C1 = 1 (%) - C2 (mean (sd)) -. Stratified by E - 1 2 3 - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) - C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) + p test + n + E (mean (sd)) <0.001 + C (median [IQR]) 1.000 nonnorm + Y = 1 (%) NA exact + C1 = 1 (%) 1.000 + C2 (mean (sd)) 1.000 +e Stratified by E + 1 2 + n 150.01 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) Stratified by E - p test - n - E (mean (sd)) <0.001 - C (median [range]) 1.000 nonnorm - Y = 1 (%) 1.000 - C1 = 1 (%) 1.000 - C2 (mean (sd)) 1.000 -. Stratified by E + 3 p test + n 150.00 + E (mean (sd)) 3.00 (0.00) <0.001 + C (median [range]) 2.00 [1.00, 4.00] 1.000 nonnorm + Y = 1 (%) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 1.000 +f Stratified by E 1 2 3 p test n 150.01 150.00 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 @@ -1174,26 +1276,26 @@ Unit tests for svy* user functions : .... Stratified by E C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.000 C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E - level 1 2 - n 150.01 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] - Y (%) 0 90.7 (60.6) 91.0 (60.7) - 1 59.0 (39.4) 59.0 (39.3) - C1 (%) 0 100.0 (66.7) 100.0 (66.7) - 1 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) + level 1 2 + n 150.01 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] + Y (%) 0 90.7 (60.6) 91.0 (60.7) + 1 59.0 (39.4) 59.0 (39.3) + C1 (%) 0 100.0 (66.7) 100.0 (66.7) + 1 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) Stratified by E - 3 p test - n 150.00 - E (mean (sd)) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 1.000 nonnorm - Y (%) 91.0 (60.7) NA exact - 59.0 (39.3) - C1 (%) 100.0 (66.7) 1.000 - 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 1.000 -. "Stratified by E" + 3 p test + n 150.00 + E (mean (sd)) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 1.000 nonnorm + Y (%) 91.0 (60.7) NA exact + 59.0 (39.3) + C1 (%) 100.0 (66.7) 1.000 + 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 1.000 +g "Stratified by E" "" "1" "2" "n" "150.01" "150.00" "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" @@ -1456,50 +1558,80 @@ Unit tests for svy* user functions : .... Stratified by E (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 + 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 + Stratified by RIAGENDR + test + n + HI_CHOL (mean (sd)) + race (%) + 1 + 2 + 3 + 4 + agecat (%) + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) . Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.0000001 + 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 + Stratified by RIAGENDR + test + n + HI_CHOL (mean (sd)) + race (%) + 1 + 2 + 3 + 4 + agecat (%) + (0,19] + (19,39] + (39,59] + (59,Inf] + RIAGENDR = 2 (%) . Stratified by RIAGENDR - 1 2 - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] - race (%) - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) + 1 2 + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] + race (%) + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) Stratified by RIAGENDR p test n @@ -1516,20 +1648,20 @@ Unit tests for svy* user functions : .... Stratified by E (59,Inf] RIAGENDR = 2 (%) <0.0000001 . Stratified by RIAGENDR - 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.189 (15.845) 20251367.389 (14.303) - 2 89315751.415 (66.187) 92486945.142 (65.319) - 3 15045455.461 (11.149) 17967228.319 (12.689) - 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) - agecat (%) 0.001 - (0,19] 29299546.109 (21.712) 28150760.544 (19.882) - (19,39] 40497613.070 (30.011) 40640361.534 (28.702) - (39,59] 41053579.409 (30.423) 42817044.014 (30.240) - (59,Inf] 24093815.335 (17.855) 29983725.904 (21.176) - RIAGENDR = 2 (%) 0.000 (0.000) 141591891.998 (100.000) <0.001 + 1 2 p + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 ( 14.303) + 2 89315751.415 (66.187) 92486945.142 ( 65.319) + 3 15045455.461 (11.149) 17967228.319 ( 12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 ( 19.882) + (19,39] 40497613.070 (30.011) 40640361.534 ( 28.702) + (39,59] 41053579.409 (30.423) 42817044.014 ( 30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 ( 21.176) + RIAGENDR = 2 (%) 0.000 ( 0.000) 141591891.998 (100.000) <0.001 Stratified by RIAGENDR test n @@ -1545,21 +1677,21 @@ Unit tests for svy* user functions : .... Stratified by E (39,59] (59,Inf] RIAGENDR = 2 (%) -.. Stratified by RIAGENDR - 1 2 - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] - race (%) - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) +h. Stratified by RIAGENDR + 1 2 + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] + race (%) + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) Stratified by RIAGENDR p test n @@ -1578,4 +1710,302 @@ Unit tests for svy* user functions : .... Stratified by E . Unit tests for the survey-related modules : ................................................ -DONE +1. Failure (at test-CreateTableOne.R#145): printing of a TableOne object does not regress +print(pbcByTrt, printToggle = TRUE) not equal to reference from ref-TableOne_defaultPrint +6 string mismatches: +x[3]: " " +y[3]: " " + +x[9]: " 14 (8.9) " +y[9]: " 14 ( 8.9) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[38]: " 10 (6.5) " +y[38]: " 10 ( 6.5) " + +2. Failure (at test-CreateTableOne.R#148): printing of a TableOne object does not regress +print(pbcOverall, printToggle = TRUE) not equal to reference from ref-TableOne_overallPrint +1 string mismatches: +x[9]: " 24 (7.7) " +y[9]: " 24 ( 7.7) " + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +3. Failure (at test-CreateTableOne.R#154): printing of a TableOne object does not regress +print(pbcByTrtSex, printToggle = TRUE) not equal to reference from ref-TableOne_2StrataVars +37 string mismatches: +x[8]: " 0 (0.0) " +y[8]: " 0 ( 0.0) " + +x[9]: " 1 (4.8) " +y[9]: " 1 ( 4.8) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[37]: " 0 (0.0) " +y[37]: " 0 ( 0.0) " + +4. Failure (at test-CreateTableOne.R#158): printing of a TableOne object does not regress +print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-TableOne_digits +6 string mismatches: +x[3]: " " +y[3]: " " + +x[9]: " 14 (8.861) " +y[9]: " 14 ( 8.861) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[38]: " 10 (6.494) " +y[38]: " 10 ( 6.494) " + +5. Failure (at test-CreateTableOne.R#161): printing of a TableOne object does not regress +print(pbcByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-TableOne_noTests +6 string mismatches: +x[3]: " " +y[3]: " " + +x[9]: " 14 (8.9) " +y[9]: " 14 ( 8.9) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[38]: " 10 (6.5) " +y[38]: " 10 ( 6.5) " + +6. Failure (at test-CreateTableOne.R#164): printing of a TableOne object does not regress +print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_exact +6 string mismatches: +x[3]: " " +y[3]: " " + +x[9]: " 14 (8.9) " +y[9]: " 14 ( 8.9) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[38]: " 10 (6.5) " +y[38]: " 10 ( 6.5) " + +7. Failure (at test-CreateTableOne.R#167): printing of a TableOne object does not regress +print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_minMax +6 string mismatches: +x[3]: " " +y[3]: " " + +x[9]: " 14 (8.9) " +y[9]: " 14 ( 8.9) " + +x[25]: " " +y[25]: " " + +x[32]: " " +y[32]: " " + +x[38]: " 10 (6.5) " +y[38]: " 10 ( 6.5) " + +8. Failure (at test-svyCreateTableOne.R#110): printing of a svyTableOne object does not regress +print(mwByTrt, printToggle = TRUE) not equal to reference from ref-svyTableOne_defaultPrint +15 string mismatches: +x[2]: "1.00 (0.00)" +y[2]: " 1.00 (0.00)" + +x[3]: "2.13 (0.89)" +y[3]: " 2.13 (0.89)" + +x[4]: "59.0 (39.4) " +y[4]: " 59.0 (39.4) " + +x[5]: "50.0 (33.3) " +y[5]: " 50.0 (33.3) " + +x[6]: "0.47 (0.50)" +y[6]: " 0.47 (0.50)" + +9. Failure (at test-svyCreateTableOne.R#113): printing of a svyTableOne object does not regress +print(mwOverall, printToggle = TRUE) not equal to reference from ref-svyTableOne_overallPrint +6 string mismatches: +x[1]: " 450.01" +y[1]: "450.01" + +x[2]: " 2.00 (0.82)" +y[2]: " 2.00 (0.82)" + +x[3]: " 2.13 (0.88)" +y[3]: " 2.13 (0.88)" + +x[4]: "177.0 (39.4) " +y[4]: " 177.0 (39.4) " + +x[5]: "150.0 (33.3) " +y[5]: " 150.0 (33.3) " + +a. Failure (at test-svyCreateTableOne.R#116): printing of a svyTableOne object does not regress +print(mwInclNa, printToggle = TRUE) not equal to reference from ref-svyTableOne_IncludeNA +9 string mismatches: +x[1]: " 450.01" +y[1]: "450.01" + +x[2]: " 2.00 (0.82)" +y[2]: " 2.00 (0.82)" + +x[3]: " 2.13 (0.88)" +y[3]: " 2.13 (0.88)" + +x[4]: "" +y[4]: " " + +x[5]: "272.7 (60.6) " +y[5]: " 272.7 (60.6) " + +b. Failure (at test-svyCreateTableOne.R#119): printing of a svyTableOne object does not regress +print(mwByTrtSex, printToggle = TRUE) not equal to reference from ref-svyTableOne_2StrataVars +30 string mismatches: +x[2]: "1.00 (0.00)" +y[2]: " 1.00 (0.00)" + +x[3]: "1.60 (0.49)" +y[3]: " 1.60 (0.49)" + +x[4]: "22.0 (22.1) " +y[4]: " 22.0 (22.1) " + +x[5]: " 0.0 (0.0) " +y[5]: " 0.0 ( 0.0) " + +x[6]: "0.60 (0.49)" +y[6]: " 0.60 (0.49)" + +c. Failure (at test-svyCreateTableOne.R#122): printing of a svyTableOne object does not regress +print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-svyTableOne_digits +15 string mismatches: +x[2]: "1.0000 (0.0000)" +y[2]: " 1.0000 (0.0000)" + +x[3]: "2.1332 (0.8854)" +y[3]: " 2.1332 (0.8854)" + +x[4]: "59.001 (39.406) " +y[4]: " 59.001 (39.406) " + +x[5]: "50.000 (33.331) " +y[5]: " 50.000 (33.331) " + +x[6]: "0.4666 (0.4994)" +y[6]: " 0.4666 (0.4994)" + +d. Failure (at test-svyCreateTableOne.R#125): printing of a svyTableOne object does not regress +print(mwByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-svyTableOne_noTests +15 string mismatches: +x[2]: "1.00 (0.00)" +y[2]: " 1.00 (0.00)" + +x[3]: "2.13 (0.89)" +y[3]: " 2.13 (0.89)" + +x[4]: "59.0 (39.4) " +y[4]: " 59.0 (39.4) " + +x[5]: "50.0 (33.3) " +y[5]: " 50.0 (33.3) " + +x[6]: "0.47 (0.50)" +y[6]: " 0.47 (0.50)" + +e. Failure (at test-svyCreateTableOne.R#128): printing of a svyTableOne object does not regress +print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-svyTableOne_nonnormal_exact +15 string mismatches: +x[2]: "1.00 (0.00)" +y[2]: " 1.00 (0.00)" + +x[3]: "2.00 [1.00, 3.00]" +y[3]: " 2.00 [1.00, 3.00]" + +x[4]: "59.0 (39.4) " +y[4]: " 59.0 (39.4) " + +x[5]: "50.0 (33.3) " +y[5]: " 50.0 (33.3) " + +x[6]: "0.47 (0.50)" +y[6]: " 0.47 (0.50)" + +f. Failure (at test-svyCreateTableOne.R#131): printing of a svyTableOne object does not regress +print(mwByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-svyTableOne_nonnormal_minMax +15 string mismatches: +x[2]: "1.00 (0.00)" +y[2]: " 1.00 (0.00)" + +x[3]: "2.00 [1.00, 4.00]" +y[3]: " 2.00 [1.00, 4.00]" + +x[4]: "59.0 (39.4) " +y[4]: " 59.0 (39.4) " + +x[5]: "50.0 (33.3) " +y[5]: " 50.0 (33.3) " + +x[6]: "0.47 (0.50)" +y[6]: " 0.47 (0.50)" + +g. Failure (at test-svyCreateTableOne.R#137): printing of a svyTableOne object does not regress +print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-svyTableOne_showAllLevels +24 string mismatches: +x[9]: " 150.01" +y[9]: "150.01" + +x[10]: " 1.00 (0.00)" +y[10]: " 1.00 (0.00)" + +x[11]: " 2.00 [1.00, 3.00]" +y[11]: " 2.00 [1.00, 3.00]" + +x[12]: " 90.7 (60.6) " +y[12]: " 90.7 (60.6) " + +x[13]: " 59.0 (39.4) " +y[13]: " 59.0 (39.4) " + +h. Failure (at test-svyCreateTableOne.R#378): mixed data object print outs are numerically correct +matFP[, 1] not equal to outFP[, 1] +3 string mismatches: +x[1]: "21381884.189 (15.845) " +y[1]: " 21381884.189 (15.845) " + +x[2]: "89315751.415 (66.187) " +y[2]: " 89315751.415 (66.187) " + +x[3]: "15045455.461 (11.149) " +y[3]: " 15045455.461 (11.149) " From e9a9f95542bd1335401e176ff375b38ebed14a60 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 13:11:01 -0400 Subject: [PATCH 133/219] Fix outdated references and test to accommodate new print.TableOne behavior --- test-all.txt | 334 +----------------- tests/testthat/ref-TableOne_2StrataVars | Bin 1128 -> 1129 bytes tests/testthat/ref-TableOne_defaultPrint | Bin 790 -> 781 bytes tests/testthat/ref-TableOne_digits | Bin 912 -> 907 bytes tests/testthat/ref-TableOne_noTests | Bin 705 -> 697 bytes tests/testthat/ref-TableOne_nonnormal_exact | Bin 872 -> 867 bytes tests/testthat/ref-TableOne_nonnormal_minMax | Bin 856 -> 849 bytes tests/testthat/ref-TableOne_overallPrint | Bin 517 -> 515 bytes tests/testthat/ref-svyTableOne_2StrataVars | Bin 314 -> 322 bytes tests/testthat/ref-svyTableOne_IncludeNA | Bin 246 -> 246 bytes tests/testthat/ref-svyTableOne_defaultPrint | Bin 274 -> 277 bytes tests/testthat/ref-svyTableOne_digits | Bin 319 -> 324 bytes tests/testthat/ref-svyTableOne_noTests | Bin 250 -> 249 bytes .../testthat/ref-svyTableOne_nonnormal_exact | Bin 312 -> 317 bytes .../testthat/ref-svyTableOne_nonnormal_minMax | Bin 299 -> 303 bytes tests/testthat/ref-svyTableOne_overallPrint | Bin 213 -> 215 bytes tests/testthat/ref-svyTableOne_showAllLevels | Bin 356 -> 357 bytes tests/testthat/test-svyCreateTableOne.R | 6 +- 18 files changed, 23 insertions(+), 317 deletions(-) diff --git a/test-all.txt b/test-all.txt index d86d0c3..69494d9 100644 --- a/test-all.txt +++ b/test-all.txt @@ -30,7 +30,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -1 +. Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -61,7 +61,7 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) -2 +. Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -164,7 +164,7 @@ Unit tests for the CreateTableOne function : ........... St 2 30 ( 21.6) 3 59 ( 42.4) 4 47 ( 33.8) -3 Stratified by trt +. Stratified by trt 1 2 p n 158 154 time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 @@ -226,7 +226,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -4 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -257,7 +257,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -5 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -319,7 +319,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -6 Stratified by trt +. Stratified by trt 1 n 158 time (mean (sd)) 2015.62 (1094.12) @@ -381,7 +381,7 @@ Unit tests for the CreateTableOne function : ........... St 2 32 (20.8) 3 64 (41.6) 4 54 (35.1) -7 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -1176,7 +1176,7 @@ Unit tests for svy* user functions : .... Stratified by E Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 -8 +. Overall n 450.01 E (mean (sd)) 2.00 (0.82) @@ -1184,7 +1184,7 @@ Unit tests for svy* user functions : .... Stratified by E Y = 1 (%) 177.0 (39.4) C1 = 1 (%) 150.0 (33.3) C2 (mean (sd)) 0.47 (0.50) -9 +. Overall n 450.01 E (mean (sd)) 2.00 (0.82) @@ -1195,7 +1195,7 @@ Unit tests for svy* user functions : .... Stratified by E NA 0.3 ( 0.1) C1 = 1 (%) 150.0 (33.3) C2 (mean (sd)) 0.47 (0.50) -a Stratified by E:C1 +. Stratified by E:C1 1:0 2:0 3:0 1:1 n 100.01 100.00 100.00 50.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) @@ -1211,7 +1211,7 @@ a Stratified by E:C1 Y = 1 (%) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 C2 (mean (sd)) 0.20 (0.40) 0.20 (0.40) <0.001 -b Stratified by E +. Stratified by E 1 2 3 n 150.0120 150.0030 150.0000 E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) @@ -1227,7 +1227,7 @@ b Stratified by E Y = 1 (%) 0.99982 C1 = 1 (%) 1.00000 C2 (mean (sd)) 1.00000 -c Stratified by E +. Stratified by E 1 2 3 n 150.01 150.00 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) @@ -1235,7 +1235,7 @@ c Stratified by E Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) -d Stratified by E +. Stratified by E 1 2 3 n 150.01 150.00 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) @@ -1251,7 +1251,7 @@ d Stratified by E Y = 1 (%) NA exact C1 = 1 (%) 1.000 C2 (mean (sd)) 1.000 -e Stratified by E +. Stratified by E 1 2 n 150.01 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) @@ -1267,7 +1267,7 @@ e Stratified by E Y = 1 (%) 59.0 (39.3) 1.000 C1 = 1 (%) 50.0 (33.3) 1.000 C2 (mean (sd)) 0.47 (0.50) 1.000 -f Stratified by E +. Stratified by E 1 2 3 p test n 150.01 150.00 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 @@ -1295,7 +1295,7 @@ f Stratified by E C1 (%) 100.0 (66.7) 1.000 50.0 (33.3) C2 (mean (sd)) 0.47 (0.50) 1.000 -g "Stratified by E" +. "Stratified by E" "" "1" "2" "n" "150.01" "150.00" "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" @@ -1677,7 +1677,7 @@ g "Stratified by E" (39,59] (59,Inf] RIAGENDR = 2 (%) -h. Stratified by RIAGENDR +.. Stratified by RIAGENDR 1 2 n 134944553.92 141591892.00 HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] @@ -1710,302 +1710,4 @@ h. Stratified by RIAGENDR . Unit tests for the survey-related modules : ................................................ -1. Failure (at test-CreateTableOne.R#145): printing of a TableOne object does not regress -print(pbcByTrt, printToggle = TRUE) not equal to reference from ref-TableOne_defaultPrint -6 string mismatches: -x[3]: " " -y[3]: " " - -x[9]: " 14 (8.9) " -y[9]: " 14 ( 8.9) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[38]: " 10 (6.5) " -y[38]: " 10 ( 6.5) " - -2. Failure (at test-CreateTableOne.R#148): printing of a TableOne object does not regress -print(pbcOverall, printToggle = TRUE) not equal to reference from ref-TableOne_overallPrint -1 string mismatches: -x[9]: " 24 (7.7) " -y[9]: " 24 ( 7.7) " - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -3. Failure (at test-CreateTableOne.R#154): printing of a TableOne object does not regress -print(pbcByTrtSex, printToggle = TRUE) not equal to reference from ref-TableOne_2StrataVars -37 string mismatches: -x[8]: " 0 (0.0) " -y[8]: " 0 ( 0.0) " - -x[9]: " 1 (4.8) " -y[9]: " 1 ( 4.8) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[37]: " 0 (0.0) " -y[37]: " 0 ( 0.0) " - -4. Failure (at test-CreateTableOne.R#158): printing of a TableOne object does not regress -print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-TableOne_digits -6 string mismatches: -x[3]: " " -y[3]: " " - -x[9]: " 14 (8.861) " -y[9]: " 14 ( 8.861) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[38]: " 10 (6.494) " -y[38]: " 10 ( 6.494) " - -5. Failure (at test-CreateTableOne.R#161): printing of a TableOne object does not regress -print(pbcByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-TableOne_noTests -6 string mismatches: -x[3]: " " -y[3]: " " - -x[9]: " 14 (8.9) " -y[9]: " 14 ( 8.9) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[38]: " 10 (6.5) " -y[38]: " 10 ( 6.5) " - -6. Failure (at test-CreateTableOne.R#164): printing of a TableOne object does not regress -print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_exact -6 string mismatches: -x[3]: " " -y[3]: " " - -x[9]: " 14 (8.9) " -y[9]: " 14 ( 8.9) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[38]: " 10 (6.5) " -y[38]: " 10 ( 6.5) " - -7. Failure (at test-CreateTableOne.R#167): printing of a TableOne object does not regress -print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_minMax -6 string mismatches: -x[3]: " " -y[3]: " " - -x[9]: " 14 (8.9) " -y[9]: " 14 ( 8.9) " - -x[25]: " " -y[25]: " " - -x[32]: " " -y[32]: " " - -x[38]: " 10 (6.5) " -y[38]: " 10 ( 6.5) " - -8. Failure (at test-svyCreateTableOne.R#110): printing of a svyTableOne object does not regress -print(mwByTrt, printToggle = TRUE) not equal to reference from ref-svyTableOne_defaultPrint -15 string mismatches: -x[2]: "1.00 (0.00)" -y[2]: " 1.00 (0.00)" - -x[3]: "2.13 (0.89)" -y[3]: " 2.13 (0.89)" - -x[4]: "59.0 (39.4) " -y[4]: " 59.0 (39.4) " - -x[5]: "50.0 (33.3) " -y[5]: " 50.0 (33.3) " - -x[6]: "0.47 (0.50)" -y[6]: " 0.47 (0.50)" - -9. Failure (at test-svyCreateTableOne.R#113): printing of a svyTableOne object does not regress -print(mwOverall, printToggle = TRUE) not equal to reference from ref-svyTableOne_overallPrint -6 string mismatches: -x[1]: " 450.01" -y[1]: "450.01" - -x[2]: " 2.00 (0.82)" -y[2]: " 2.00 (0.82)" - -x[3]: " 2.13 (0.88)" -y[3]: " 2.13 (0.88)" - -x[4]: "177.0 (39.4) " -y[4]: " 177.0 (39.4) " - -x[5]: "150.0 (33.3) " -y[5]: " 150.0 (33.3) " - -a. Failure (at test-svyCreateTableOne.R#116): printing of a svyTableOne object does not regress -print(mwInclNa, printToggle = TRUE) not equal to reference from ref-svyTableOne_IncludeNA -9 string mismatches: -x[1]: " 450.01" -y[1]: "450.01" - -x[2]: " 2.00 (0.82)" -y[2]: " 2.00 (0.82)" - -x[3]: " 2.13 (0.88)" -y[3]: " 2.13 (0.88)" - -x[4]: "" -y[4]: " " - -x[5]: "272.7 (60.6) " -y[5]: " 272.7 (60.6) " - -b. Failure (at test-svyCreateTableOne.R#119): printing of a svyTableOne object does not regress -print(mwByTrtSex, printToggle = TRUE) not equal to reference from ref-svyTableOne_2StrataVars -30 string mismatches: -x[2]: "1.00 (0.00)" -y[2]: " 1.00 (0.00)" - -x[3]: "1.60 (0.49)" -y[3]: " 1.60 (0.49)" - -x[4]: "22.0 (22.1) " -y[4]: " 22.0 (22.1) " - -x[5]: " 0.0 (0.0) " -y[5]: " 0.0 ( 0.0) " - -x[6]: "0.60 (0.49)" -y[6]: " 0.60 (0.49)" - -c. Failure (at test-svyCreateTableOne.R#122): printing of a svyTableOne object does not regress -print(mwByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-svyTableOne_digits -15 string mismatches: -x[2]: "1.0000 (0.0000)" -y[2]: " 1.0000 (0.0000)" - -x[3]: "2.1332 (0.8854)" -y[3]: " 2.1332 (0.8854)" - -x[4]: "59.001 (39.406) " -y[4]: " 59.001 (39.406) " - -x[5]: "50.000 (33.331) " -y[5]: " 50.000 (33.331) " - -x[6]: "0.4666 (0.4994)" -y[6]: " 0.4666 (0.4994)" - -d. Failure (at test-svyCreateTableOne.R#125): printing of a svyTableOne object does not regress -print(mwByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-svyTableOne_noTests -15 string mismatches: -x[2]: "1.00 (0.00)" -y[2]: " 1.00 (0.00)" - -x[3]: "2.13 (0.89)" -y[3]: " 2.13 (0.89)" - -x[4]: "59.0 (39.4) " -y[4]: " 59.0 (39.4) " - -x[5]: "50.0 (33.3) " -y[5]: " 50.0 (33.3) " - -x[6]: "0.47 (0.50)" -y[6]: " 0.47 (0.50)" - -e. Failure (at test-svyCreateTableOne.R#128): printing of a svyTableOne object does not regress -print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-svyTableOne_nonnormal_exact -15 string mismatches: -x[2]: "1.00 (0.00)" -y[2]: " 1.00 (0.00)" - -x[3]: "2.00 [1.00, 3.00]" -y[3]: " 2.00 [1.00, 3.00]" - -x[4]: "59.0 (39.4) " -y[4]: " 59.0 (39.4) " - -x[5]: "50.0 (33.3) " -y[5]: " 50.0 (33.3) " - -x[6]: "0.47 (0.50)" -y[6]: " 0.47 (0.50)" - -f. Failure (at test-svyCreateTableOne.R#131): printing of a svyTableOne object does not regress -print(mwByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-svyTableOne_nonnormal_minMax -15 string mismatches: -x[2]: "1.00 (0.00)" -y[2]: " 1.00 (0.00)" - -x[3]: "2.00 [1.00, 4.00]" -y[3]: " 2.00 [1.00, 4.00]" - -x[4]: "59.0 (39.4) " -y[4]: " 59.0 (39.4) " - -x[5]: "50.0 (33.3) " -y[5]: " 50.0 (33.3) " - -x[6]: "0.47 (0.50)" -y[6]: " 0.47 (0.50)" - -g. Failure (at test-svyCreateTableOne.R#137): printing of a svyTableOne object does not regress -print(mwByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-svyTableOne_showAllLevels -24 string mismatches: -x[9]: " 150.01" -y[9]: "150.01" - -x[10]: " 1.00 (0.00)" -y[10]: " 1.00 (0.00)" - -x[11]: " 2.00 [1.00, 3.00]" -y[11]: " 2.00 [1.00, 3.00]" - -x[12]: " 90.7 (60.6) " -y[12]: " 90.7 (60.6) " - -x[13]: " 59.0 (39.4) " -y[13]: " 59.0 (39.4) " - -h. Failure (at test-svyCreateTableOne.R#378): mixed data object print outs are numerically correct -matFP[, 1] not equal to outFP[, 1] -3 string mismatches: -x[1]: "21381884.189 (15.845) " -y[1]: " 21381884.189 (15.845) " - -x[2]: "89315751.415 (66.187) " -y[2]: " 89315751.415 (66.187) " - -x[3]: "15045455.461 (11.149) " -y[3]: " 15045455.461 (11.149) " +DONE diff --git a/tests/testthat/ref-TableOne_2StrataVars b/tests/testthat/ref-TableOne_2StrataVars index a54f80ca7a97ca68ba70bdf91ae00832c44d1b05..4d846fe54599a92b310854788ded891a9b17c87c 100644 GIT binary patch literal 1129 zcmV-v1eW_BiwFP!000001Lc=ZZ{s!)h7~6pG+T7zZQ5f2UJBS3g5MuO`zw0sRf(02 zQ9ChgEztg{{=`M!kz{);%TDeMkcb?Ohr@Rs4xK+g7DX{CE=L!|=#qwG{Q0-IDsE_E zbT|5}W46*IG11038P&9V@j=i}H@R&l!oe#`HSL)#%ud>#S;IR78M)be=_4&AgPtA+ zQDP$0acm84F_rCN$Ph`n{VtTK^MlMrP<`q~7geES!Rhh+&kI*-x3b zl>v5zw|j3L;e{P*<)z)(KO2{V)B#a!!V9yPNSh=ha&dS#W_DgCn0=6ec^eCXy_n=E zZDP4-C6l9EvO8C1h%2)6eJM^>;uW7!yQVGgeyU zylRlkoFFe9tSL*qV*;n&I_ZFlaWNezq;W_+^h8tGGel;b1`uii2#ao+sCgwLP28iGp^|EXcmV74>23_uqSKu;vYy=tot^No`~m@f zdB4|~n~scA6{R<4@JobWIKpgOn|{r_Y4LNsW-iKrnxVq3M_(SMj~XYz-QU%zY@DN2 z^?CXzV^qGcAaz45cw|4$q2(z;HhgVRj6U4ok?vYl-t_5fx{YP6Nn|Gj@UG zrJkzrB}H@k3@#_tG5A@ojSDVX#b(Odo=^XI{TsZL9-bkB*MZH9N<4bXY?f7cYb`;=atF~3 zpCx}XkEnPaKJz?m?r1NOUe@$hvye;Ii7bCy&hV>UeCV_ zg<37jx>{62pSfGDUr$u<1{I`g9H=u?G#Xnrb{#9%yZiEfxgDDQP~Si8t=r+nY8wc( vt$R>@=!k5hk9v^*{71bm>-p2Xnu&*hM7^%>K@DDfqu>7kmPIK1H4gv)W!5Zx literal 1128 zcmV-u1eg0CiwFP!000001Lc>^ZW}ic$JerB)F~P(b$TqoO9A;p@cYAPo}!mt*VZ~- zRI&tV1GF#IM+`bct+XR9CFfoP_L8&IaOOWh4&^`JS5-BsE+-e&87E#XE*S{p2=Hn1NN1i~G#1!ECtB%o0{R$2~P$%dN+)xRd*h zKJ1(bHWS2kZw#Um5>96p|B6KRmd#geutb_ zh@5c)L|OpG2$7V8l^t?6Wo9BJ$Z`YL5V<@s0cT$uZU7Z!d?5P3dN`sM)P$BWFob3} z4M3;{K8SZ^1eZ`yuX)szILTF_Kl-yp{!S@+vn>;slX5AwKOiSembhnXGq91Edq&(#reg8Pt&b9Sf~rm0f|V~S9_@riRX>7Sbo$f5-a@G8$iN{}c( zE%Lsp%O^V~`CW!wsx$N#f}9OpK^stz+JNE_a-=&kXkys3g5t^#$VHGxBqtWYwUn*E zBX%<+m68hu3yCd5Vo?qNjXOE5KJIc(VJyL%sj|cd;ztl^*k36kMK3vQr0wV)GT8g* ztpUizAyFSw8-}CgxmD+o3#o^X?z3H8@^V>~kTbMg#&hQqLnb3GmWfN9a+J`CKn#>i z%k#v+K2YymIP85ajLf(@v)R3>xwjaU6@)mrt3BSUP;HeHmpY3kZHPs~9mER4D@%xT z;1v6(fUhHx5~tuE5~;5%pP9qXOs`ev;cf?!6=@(l;4pAWT$jE(;n`EijRLI#Pr^tb zB-bj+3PET=W6 z3-)9jUeGvfq;Y6ZbJmXf9NIt5oOvt8|If3!n!ulnebbt^OL+WL;lB%2^(zXNE%^bK zyw=NR3rp_$b?6G2IemIrEeiI#dhz&m*}fKD{rt3AubWNb&8K?t7hk`uwuN_)dso`O+q7Rw zuGWjXYZguEGk5FF>O=)^pn_P9BXvqe!?7k~)3b7YxFa8y`=J_!^5J=~?uQray(6e? umqGciCo*}TWRU;zN4KfF_PK55?C~GgZMp}b23~x_-~Rxmq6sM+4*&q>Mf&U40Y11krX9=w%r#X5luajkK~i{?J`M{ zd2%+NCG)djF7c;H7Rd#!XTrG7ypdcOu#%;MdksRax{U?HPiJ2Tn>oc&Bf+eOZoyf~ zEU3tB4NJ8ELET1x4w(dSv7%_9GL||ESsYtqYzIDaXUIfbkda$sO6dr}Q4K<2dZ)%U z*iiqF>{MxgSLl@BkgNi$`Vy8*S%W2EcJ9IG6+vSzOvyoOQn1g!Vr8C#@vGNCNC65n zN`VY1UPulSqZ^IEs2k^nVKPB-E}1kAG85|Ipd{gf1%{z;aOU)o1+ryGFY1H}t(BvW z8|<4hpkp_pl?M0XM#1U6PT{=;7aA^%0k8fbI1Gb-kT@yxNYRk!o#3!_$^)mv(x?W9 zjRtQcz4^BNv1q%2$MOgRH)D6JH&6IY=nco_%ve~e)pgvrQTn5T!ql)0j_55@;IJ@> z_ffk^z41tI7{j6aRd2#;brh}O0<0ej%ZHL38BcH{3Ddf%3?*t`^0u9s8p_R~8(#tX z^oUu1xZrXuHyQ5Ic*MGWr^INZTNS=GIqBAOhB2I?PhLlucnv5n9C^}GkSAj^igXm| zouRq1>>qNWM95R7-5`Rd(Y+raDGzP=pk_-M8_G&}dJfo06mZVQ%fi+sn@dcErJ!)4v%&2!Dt z&-8|HVhdu+UiA6nRIqn-@q>L~4f&U40Y19krX9=yWJNckwiU_kK~i`{US+{ zd2%wJCG(RoUE)uZERu5^PlR#Z^jdOZz)F@1?llOx>NZYU_;ib_cHtCDjRdnAngwSm zv!EigH7wNv1T`B0I)oCy#fqYZ%2?_wWY6f!qi>C7@R92biD(NlGHZ+|9pSf#QxFQH zJ2g(hhWv+rT&FS%q$D`xs=%r~gC$eeU`807doX%M&=?Cta?qOO>oc&JnCD>p>ZK7< zfWnAUAVZ25l7mF=Mx!%o#(trjOpusMCXIv4gnT$CNw{Ewp(h-id85e!=`!ROl|qHu z%2CM;7ET$^u^G`ygL^ik;&h*=@ZN$86&J>US8pkQ4*eh|j>z-hZQ z>cL^D!P`i1zHNYt1&2QDNFSl&W^8T+=Lx+D!C~K=87m7F%-pDMo#4!Xlxo|CRd7Ub znF5D-NxYBRO$v@jf_~fp8A+JdOm!$x{F1lT%+yeC z4$b&~1n4(f%uvC2r$%~{;Wmw1tlLK=MjPGA@TJO0H=Z%{;S^nY9bw`zptx{krKKP% zV>60$6zQFzv9jzRVxdOJD${P@K~wME50I3HwtSGYrHl<_B|JTc@Bd#o{y$@~nB&i^ zf3w!*7KaZ>_#;h{&n<8Wd54f)zAb8m+;q5qWs5!T&vyNdZOU!I(ruCNSX!@F{e`%w zo4k3dS^A~7geQcPxgc}di#~sta`wJ1ezLFZo_M>;>$|ckYBURCzI-gIyxB+AtGX)J z#UTct7wcl1ze4dW%)v|$Uf!0Qa)RaZ?s31Fu;1jH+ox^0o7nnzx38+=FtPI~-~51L z>TzFB>|yTBRQ%>pK1{i)HhEKQim5X<)nWfi2hXvCp&NthOf@ac6`AW!D~nz${h?WZ xVpjEV>|hf~@3hlh>th~C`TARP$eZ%MEY|Gy7i$i9I{6*Ge*hAhv8xyg004!Fdg}lH diff --git a/tests/testthat/ref-TableOne_digits b/tests/testthat/ref-TableOne_digits index f2447000ad311ed68528e37f010cc3281a325bcd..f3f531c381ba7a57b032756a3de68e7fc7d27daa 100644 GIT binary patch delta 900 zcmV-~1AF|C2a5-g6n|l-NUX%ku>daxqzl0zhhK;Oid=GCTbp=M$r7|1p#AejAJ^K5 zt6ep@$AHC;H{?9dycy}!tD-38#npUP%&*dPfseMhE^aYikqyV`2d&6TrPqAcLb30!|BxIE6HehHqtVWJ-ZYuM9Tk20N!C+%is<8 z8bmt8{*mv6aaJl~(A6r!m-&XJQ}9j>n3Bw=q`+15(qTs|qmni%TAh-qN$Tj+BMI!; z*l;>WS|KI@A%C?jttQSPWZpPHo{-r{Cyv?%>8(=f%?dALpK(MOoK2xpGT76F)50Ox z2@l406gQI?Ye{yjDT`7#;LsQo6`m8MD}5kTx!aAx$t8 z5#+556MArnjR`VlN)jzqBtpAk#s1ip?ssWpa`)>LjwrZEcp(C=;;J$R3Cc8OCr3EJQQ|No#;^)LI1yO zL~2Foh<|b15K?WR?7W}oh}?BVivWy-&7J1+6cxwuMu1r`%I526ES=e%kI7DvcRpLQ zMz_z_)*%YHeF&PebwnCn?$^7Zf50ype6wV0&pyV%JtlQ`A5HV4biJ?PT9Oy*j@Q$>ayRO>TmI< z_?+E#S2mAzTQ%6GZ2QeqwJ+P<+3sDluh-S#-1xRySKIOe#nc8MvkAhBhk8>_uv|Po z?R_>A`}gJM;p?`3o`Bvx?)LlYFoC=;H-E|f)2^Ao@b-4fe|xCEOkK6#lx?-Crq0~& z54#H)yhR36HU`m|N?MwmY|clmT=!b(56$`$vwd%l47O*|`{k&+?vDAHl;3`A4`o|_ auB)|p_(!w{oG$)N|Nj9@+U{Hq3jhF@tHxIV delta 906 zcmV;519kk12apGl6n_(^XspEPu>daxqzl0zIs7=}SLD*`+S*5CE6>;dMe`rN4omNIHNkuD3 z8?)-bSK|4vTi$ic09)3Qjb5EYq{LD=Sxj>XcFBr|}Rq<^JI2u@NduUErUWV~1g zC%rnIdf&&gfMjqq3gto2I*Ch-APW{cNE=S4ex14`84d47vbEz&x|Azq%Kymy6J0HX zH=t{f=@9!neh|j7RAfO{tB6?UJC;r%IyqoUT6-!ALPakfcEmC&$x+ejR7_1$N1rZ9 zU~dhF(>c-#Ie!VrC|k*zY!0FF#sTt#!bUoA)EuN|rP7@hZf1SP5ovIoQl(_zlfw(b zAs7k|$~;P(NtCrD9&3t`Zo?@DV+f~=m4VcE2->!NIw(d5ftXY;VwN#W{v~b0BP?lx zqKIJ6GE6AKAv-3>m}wEou|aasa2RD|A4bxSZ2`4YV}EJGpOZF@Bem6=hFWPysr8G} zM!N+F&yDX$5S2iC*o&>5M}8Kmvn?s91Le~8Mh5JF6W$6NtUHsoHX+Hz#9X4Sv^f9w$a}LwlXCEi$bJ z`EV-t&uls8P0>@1<6F1E{4#75#*aN(M^-fcub zq9!ZBpGS<-gmoO3N^M5Z)0uhmp7Y~ANs?)DH=QKYI~OkT=W8-c=J>p0N_XKSr%XY{ zNy?~^!1%g5m=XMR@xsMK3z8}hYCVJ*B`L{31aPKEDj6^zRt%);#DKE3pUp&0Qk_8_ z)|OaXg9+dqCy^QO0G8O2Yj4022PUw+7Gn;X<3AiWM(qJX4jP9Qkcpncl88(pCG1WO zD7p5su@|b{ZgnmBb6gXB_5{vmT>V;);=Ji|>t~BJz z@u48NHwzMUqEOK4w#W>pB{*KN3E@`DM;lkTH=#g=FlGx0`X7vjlRZynOa|I5oGArH z{Ks%u22;YO#Ndd^tKJz7S0@ZmUo44k(70$YS>QL*u0J$wCwOQNC%78Jt>26{U&L=H zn^t3EiPqQQ-bU@O4sxpD8noxPT!2Pm9PgvlQNPi^Z&*Vk{OUJmq_~=vQ3jbA8p}A! z+LOn@ID~3p--aB$&uP2PTnz1|5yn@5ye%!=>q58WWHv>3 z(%WuV9`W&^eHA9j=j(Hj@(xo@#nIMywCeJfZSM7aa_X1flt)X_qb*J(t#|95(|z3( z%}Y(vFFs4^#mtL&KX~yREB3y&zsNW8 z&K`>!BffPpsK~&}O?fCIQ!cmr^C5z-io@pRSe_zBAGhbKvX{uor{eGvs{Of+oFVrn z*1x%w&#_X~p=j*E#{RRaF6SEx&QU?9#$Y=!(OfLNSax2S_Fn1#G~t2E-gFilq$mAN f{N7xOrhF>xj%{K{`sn777}Beti)oThnY9?p80i^W!W-2TQ0KYnP0B(?|XKhUE=+WDKjiTamo~E zPI5-A1jdVDp83NouI6xWI2+JQ z7!GwaYVIs_Ffp^a4Te(_Qlgg)r(goZl>!X*#qm5!lQbNS42L-k!Y_tnR*I8r8D*gD z)LGWIYyx>aj3iVKhd$(Jeop&omSXBRgD`#q>E5|51sfmF#Wk zr<|QH5nhbG+tfR}ee6GmS@!jGpM<=}kbSjtEpDxcxK$r}+F$I)sdx3xk$mT>J;~cm zF*bG8c2)P(lKfi{*nkFW7OeS5yn09_`_Q^SK)KcrGM+p2S0mwIR291pK3c!>&nH73(ZiRRZLSj)jH%h4<2OA8*k n>|(IkBs?3B;?M3_b@hGiHstm%>5d(O|NQkITYtF@#|Hoaqdrhw diff --git a/tests/testthat/ref-TableOne_nonnormal_exact b/tests/testthat/ref-TableOne_nonnormal_exact index 815828fb5b44b326691d19207c4e4fc6da86c6a8..a5acf7db62a2af29f29d14e3a623abe05bf04ab7 100644 GIT binary patch literal 867 zcmV-p1DyOHiwFP!000001ErNqPuoBc$DI&pp(+7|iuO=xFO`ghR{OMf5B&f=w!KtB z986-sY93Z>B>Ls6&N_A&ubn<iyPiKz6<|;dZ5_$~S{rDr&Z7z*03>a%&@MTwA!-)XLvr31L9uA4)8w zs8RG9OK7RIlx@vWvI1rd2`#meMm0wKQdU&P!ciGvDw*6+34jOyNX9#MzZSCW7&q%fEivVYBvbPy(~l*N~jGUkq!u|dO!JUttwWZS`pOa z0f87swpPm1_@h%XZqP~zj#fH~vC?3rH5#84$A58_Q36L-sucmRVvbKX9Q&z=p_PpB zN^6`Iw>XMm`VTqo8u!!3WLiGc`CrEu%hhtZS}*#S|D}3nUBPGwKZE8iILj6=ybj#| zcM!arN`|W`D43-t%R)NJ+RzlO+j@*+uj492I3!J`^PUfFCD@ z<{Zr%IL66cU$9q2`ba*KTNG`a6w|Cs3ovtJKE6-$q+EH{agk@UbnS}|(^ z_ynuDj7exB8t>G@ZEOW*YQ4}gB%&fJJhOrmg+ciZ{1Ui?(~WGG5V`uBxpq}{=8RM^ za>=M+7erFQuByFvM8ZvK*b^$IvA!UR$CT~%T|sa%B*3Urb@k`28c>l-#bCG~TyW&{ z9+s*MYGB_56%0yz6pX-uQNf`zpc9W_Ig84$#<@dS6(O$^BD8^Uu4+c*&TZ&wrmk~P zpMC-b4rP#-M&5-<*8$OLjE3u#nkwH6YN@E%nSo1HbIGlZsBwMaT2m{Z;u7M3#y^!< z$Wf#46_?OdX(_{`DWJxX&{7+DSV9cT5COv-7*UHN0}Si7xx~_<^g6JF{u$lo4>%{L zb#E1x+QU+oSjNI(8DT7$++qoY2p~wtd$D94SjsJy?#eKhX1i^n-6daESpW)Ssi<`q zVo>t{OD-E&LfF7iSqIaCD^_5%4PJ_+-PepNbe- z$r!J+##wQTqX?$|kmJ7bFnvg-#WS7%b$q#8Etjj!qI>yYs%O>}4EpfVtDnJHwt(SH z;C{h_;6o{FN?w6vnJm&AB;!hVQfjyRy=DE<7ug~u;UZ0zB+O@%`rC7y7fErSlkj70 zajz0XbB^XU9HZp6E7w3R zpzFI;-n|X?P;`VG7n|(1+v99KPl|M&cDk)Mt33@pf`+>0G%l;Fhi)#>Tvg}{YIJI+ yUhUCa*K%lR;gNV)VOYlKdt{$}D>g}y-DK&ET>m7+2E2n`?*BLLo#}3%3IG6XtEzzj diff --git a/tests/testthat/ref-TableOne_nonnormal_minMax b/tests/testthat/ref-TableOne_nonnormal_minMax index 919962eb87611babb1864f946e3793367c398847..cf31816e9e8b791d68b0f24fbeeea6da4690ea58 100644 GIT binary patch literal 849 zcmV-X1FrlZiwFP!000001I1NaYuhjscG9d{JJz&xS?OS)mw^LC=x*s@zhW^s*ux5qj*h0G`jUyg$ym<9*aNiaRI<|%ws!7Mm}^?*v< zm}iVoi4{X3B}QP%md(Ko!Czy~t&KECp=4MtyKYKQh!p0YTS*iOimB_C6bpM3#e^Ksj8mdA|l_>+dEzRNBHiu^{N0U{0y zm%6J8r<-th;b<(`(UuXETJ~2y(a}xzfnF~idwDD!w8!75CMng?#>7g!JXFF z-T5SI-}frrBq-b@afZTjwQRpK$7K~)PbCUJx?dvV*wnFGNzCJiA+pzH@(q1L_YT`U zF7MJRDZx!0_sL_D$JN&J&dWSqC4~<@N><4x9!c@g+E@-Gytqx*sm*egLY~(}oINBr zEyd#Qal0NnJdfA6Pn$FwDDmQMo99U}7I_)3zvBFHTaE#sAJqWuqAJpdv6#2{IHksm^y76nx?h6V~a*avsOfH(4>u+2ZV{oF literal 856 zcmV-e1E>5SiwFP!000001I3l!Yuhjo$DK6o){Z4DT~<06=w;wQ5&CWEVSmM52Bi;f zMkqI^9Gf?ymRj7P!vz)nx$qY5U$F^mUP z>SlVz2$fhd6jEXYrfkt{93uPIEN1mWa}-L3<)Uk*1cgXp?wOTDp`e($W=XNIM^Q}Z z!c|iqp-?Lv?bOq4YyoC$ywDLOA{1txS-^=*JNZrg5-5k$HSd?8Z2jF_hbo&}BNhZ* z6U@mKVgwU%(`;TM4p%8*ld=fxSBOTGIRaY}oDC@uEJR!Xds`2v(6yI_jxgHh-W2zULvfb3Nrmh){~4C|g!PH$a32(q84VaPK2PWx*DYgJf4@|w?Wx4^AYsJ9d1yf*SuS7fT12Ab5b{kjl zF3wCrCrN$l5$|%T!3b(kdyzOda#|G0Ed<<5_2Ao-UKZ7au3fWF7BG@yO1x97uS6o32uu7k8UHPl|n>m+|Tw&L21BJ^|cEH4t`Q73sr1 zpLh8xu98(UPhSu6Pb*^own|98fxo9Aov=FsUqt;`Tw{mE05x0f1Me+tI*^J_6k_F$umaT7VZX=Q= zN^%ijj~JJvIH_By_2|s$@j2u9{y+#>lGSoSmMd58@aHpGlMS9L$+DsRz;c#Cn$d`{ zM1oG^p|Pg;8S1U8x!^QX3RFCSDOWV28j>l@G^3Horfii!D)FWSq>6pEaB!C2Y9mb1 z-dsCDCk(`log>UM$gc2B2BF+NaxO^aKUX)`qac-@;G@$3j)RaO*%)C*g+}ifm(YAB)#vW~D?pS>7YES{gyQiWo z0xoxlQ(Xq|y(ynws^T1IeLU1nW7|OIlPP~fbE>;Q53~27`}?+d4oNko>1}C4|JgTf zedh%?_=4^=CesN$nyZCZ%VAf>U3&BFmu*d1&Q|QzuwNJMasbKoB;=3#{sp}fK{r7K F002A(`ZoXo literal 517 zcmV+g0{Zo#dhM05*;uG# z36fIu>x(WO$)Ob5fX&71csR4%pLc|iC0Q*OWVv$X4u8IqHQC^~k}Mm_Pb_CCq#2DE zOC;zt9vW+kpP}BmnhQ=Nr9j0Km~urUsv()eOfwpZY|2&%q!MpRK&seh3kPSp$G(5o zMi|}Ar4uy5K+KHf2=ffGEBq>gQ0^Kz7o_sp)T?ADNTny}ObOsP2MLmm33gOyw2pbX zV35mr!d57PdAXN2PeJ3*G6ni7g71)V&>BUUOhDu>e8xE_Y$y$B;=>pO#kB(FO_Qq> z5_FhnAcSWH^Q8h~V)Nz`Q;s1h>dhyMdT3%caHcSXz$`P^O;f1LLXh7)620C9%`5T&3-35A>y${{rx5Z;fswquxOB?#n zzG>?lFSx-Mbgwa)PUz8GExcL|yE5+5yB~jSYszxAVsD21x^R~RNUkR#|J?UK0xOWc HKm`B*E&TU2 diff --git a/tests/testthat/ref-svyTableOne_2StrataVars b/tests/testthat/ref-svyTableOne_2StrataVars index 76d2114bbab52de05a5cac2b3dbc4db6f408b09c..cf0c972a2598627bd4763f5694aa22d8a06ecefa 100644 GIT binary patch literal 322 zcmV-I0loeoiwFP!000001HF^KPQx$|#+^S!X_ZzLyud9;$rAaTmWrxOQJ;VX#-Ic# zLn1`7@bZYW6UVLF0R(jL`TXUxfA-mVnlZ*)=D7}YJ((^kaOSfq^;gJw!f_bQ0Wjel zBGPz#DBdY?b+5$*fDj3Z6fp*)0+*_cqdJ$Oy+9A<#v*f54ho(LWi^! z(NE%rnr_tco7E9@t)S{CqZ$&_o^L@Uho~;|2BNlz$G4fC5vR}a00_~o7G@b* z$|4g-6MJT$w~bqUU!E{&YEs;yF`zN%)Oi~czbo6$I`U*VuVT7Z39lc!_q?lKtFnNX U57=)rB=u9aFR%9PK)VD00Qe!A%m4rY literal 314 zcmV-A0mc3wiwFP!000001GSS)PlPZKhKG+e?3dZ-ALzvdE~Ha--AMFA_7`~3BL+-3 zK#Xwl&l`u9TDEe~tb1rXeR-!(XBwUs0N{e>I^cSJxS@%I4|7^Ckn@=1uv=oxISWbQ zk&$ktw7t{PN{E;wnlWP9#(1nUjl_RsDw<|5#ouWBG+J_A+H5z5O*Arzg-ZFBR>{6U zc)uN;yxvKey!set=N{uGI(bgqL@WOn2l@%`dkCJmgI}-UyEHk&-YcrQzqI^+=ujGg zWeLdA{)XENqKNm$}X+#Q8IOV93H7Ei5v$l*>#UB`Rj1 zuZ^jGDNmR%F(IaC3}_5Gbl!%*@5;8bN}dh%N~UYI@anO9&%5fiDhu}V!47GLq<;3} M3+%0QUx)+%0KtWtSO5S3 diff --git a/tests/testthat/ref-svyTableOne_IncludeNA b/tests/testthat/ref-svyTableOne_IncludeNA index e29d8ee7893c8ea16504ae88f5d55db9afdaa840..0de5d666ea9d1747beedef4c02dddfdffc642810 100644 GIT binary patch literal 246 zcmV%;1(fWLXxV{!9j|vt~wU%AlMEH z{(SLL6OH1K{P!Qcxw@Rmj>Ih|L3bXwjLmUFR|bNSN*FF5}a= zwoGdbUIYCgJwlqYu5N@(92Xjo8sBJ(yspXy`R$awJr{q(^oV@wlf-%nV*iCH#k-A5 w28F^ks^HnE&|j5bL;0b*`+IdQFP9%LsWZ~D%!%+m0UmZe0Yos~iRb|U0NLwsYXATM literal 246 zcmV&Gk>^&!haK`=@7hFK)Mvm&6%qS=RY`J6?9a0XGu67~uf`0G=LkS^xk5 diff --git a/tests/testthat/ref-svyTableOne_defaultPrint b/tests/testthat/ref-svyTableOne_defaultPrint index 96fecc44ca20097884e170035f6d029705df3c74..53bacb434eadd18a4395d0e628777552a76ea26f 100644 GIT binary patch literal 277 zcmV+w0qXuAiwFP!000001HF>LO2jY_hNo$}xC^ce-eoRAdkIOiMGJZ=`vhL}SZReG zTEzC^%ZrmVQ`h3b1@Vw%=IfvNGeaLY03aX~0f^9sJKC-wf;F8hohzxd&(0CGR01@1_?MxJ+i4B}$?vvQOYej~FoF z05QVFmp67`ijnNWjqxzk_T!)aX?fZJfB;{3Abgwd=(>gg))ZGdQ&MSHZM9SiVl!5nW>Q(X=b)na(`=|W^=d6PJQ=2$7az>J_Z0nvRS5CJZwbOU6b4hf-xUI_$ Y=C!FSeEGlwp-+3h0CB`1N46ca+lkcV*`_r=0Aor;ZeP~yDn zPjciaCl<%$5aFa8c_8Ob$w?P-a3)9oO%DD;PNIu3E$e>lE_AH!45t`5O_2mA@%@ZR%{rUpo!%l&I0{{R*MUi6w literal 319 zcmV-F0l@wriwFP!000001D%phYlJWmhR3h6yI@`Dz2s8ROPCn73hhbu7xdB|En4uP zlYvSEd`LNYUNCNobGpAP_FgJWA@JCl2)=@wkrlii6FIf@un90-o|u@Gk) zX*uRX%6O9VJWaHGObbdAER+RLFpJo#&)Z3tTuQO(0rDivvZ+i`6l<9U0ww-*+lG(} zL?$jl(DDX^G$8I3L}5VS3L*avf&YZabs5kw4@*~}W462tt}$|A&*RPY^B8_@!L@0! zRP5AkN5-H3Ab=|xo{_Snl)mbkfl_W%-f_-d)~#MS{)vTMQ}rwy>PR2hFE5Du7xu{L zLGQG1D21V1m+{%grKhKR>U*>F1zA!%@5*tW03jRS~;1;1>Lef~YgH!PdTy(6oLWg!x z7hhhyv`N+CBIuCh^1JWuJ4p6J0AS!U2binFDQz?8z<|!4364^PitIv?xzSB4ZJl>YYqUkL$dVGhOX@e{#~ZOT#b}$J1Y%8#oKQ%ex3INJyI%8O(!}9lQwYMHxF( zTcL+$vi6|=y!g`Q&8>P8@zCVu^S*uGyd)1}#+c0<+hVq(Lm!7z=CTpagD4SPL}qmi z5OE_XR0cC|Zu@g<3W zYcK!AUjC~+qirm-BVEFvy#v~m12pDL5jPy+w}>|~hx literal 312 zcmV-80muFyiwFP!000001HF<>OT$1AhBsf;wpJtFWiCPjvTU*qQqY5h9=r(ZMJYW* z6CsCerO846yf~Ze1R6alc*yL`GjHb24tbm~#%$);7PB3l`WQ}`%f@()qC{{JnQ9tw zAs|2^LW7QDjaIsG4ie+qG!BvlN3C4&c?dldEt6dKY%2KtLeEV4nVqR1LHrw2`A1Xv zFQ$ylFSQe`c?8;oKE;9C>mM7t6&sv;YNOO zXh06rcxPZ|>ya((&Wb6Kl)Rb5ZHl@XT*otaX@}W^^&CAk+pH;H%OZ#84_G4l)Xx_X K1WjBr0{{Ty8IRNe diff --git a/tests/testthat/ref-svyTableOne_nonnormal_minMax b/tests/testthat/ref-svyTableOne_nonnormal_minMax index a37e0fc89e82fbf9a1a17da8ee7b1d9d83210e9e..f522c2558614448e866bd399120e6f7316963e2a 100644 GIT binary patch literal 303 zcmV+~0nq**iwFP!000001HDo~OT#b}PSbU|fpfUKyo=C+gtTdq!911y0x!zgq0%Tl zG?TU$|GfB;CQ}0*6!DOk_rCY>eR)al=Y$YSLK+Yn>U4?Wl1#`9_i0*i##39J0i=v` zh!Nw71y=x>26wu34LQcWZ7l$bHAB8wvpj)MC^x8J;)tR)XZelRE{@uxJ^!F&zqJ>C zVlV#Hp15Odw4-~3sd)qbTZeVi>Vulkg4(zuk8+9>RkgB5 z%F6PVhCB8H<)+<2+{#Kp+}DYl_M+5a-5|W{D)lV)t}}apTSy_ka=^SyJ!Da4UnEE4 z$Qir43o@4om%P|yGRS`L28!%7MvQtFbbdE<)zCaOvWCZ3*dp|%*E@ODsen)e003$I Bm6rej literal 299 zcmV+`0o48UCc6Ox9#rtKGjHBJ<}t%Q&Iuuu_|zlRH*kgFhD^u|^Hijqabc^4V4OpU z438{z85?SE8h4OjJlMurx@M@AYnDVXaJ=IrlLNQlEV(x`(_vYKI!6oY4LzbGqA%kDeiY<$5;a*7h2SE@nDwbiXU zZQu8_1Q)7?_2H+759ouxvM`JX7Mw835=8~3w_4j{WZGO`)w8JUMbwqe*=vb~ RFjj!KSs%suL!*)b007qQUeEvl literal 213 zcmV;`04o0hv+qIOD=RBTN|Q7;|#@gq)?h?#?&`@Q7lLskzm&)qR7XcG9JJWTPTo+19;^987NN z?{wqvE5>bIb{O{+wVK5r7(DQT0^{Qd!a^*_u1IE$znP4%rUbl5>A{PjUX;>9 zG%Ey}RN5f==f$0Lr?qKSJO~Doojm(8^UgARcO-;xMa^}DTcfaJJ}BzqP|&k~by(o| zUlP_f{Q*j3dJN!8MDPs5o`qe2fZ&9-&On*()NZu_B9ue$LX=?-Hgph4lSM_c|B3pD zM8i-Hx3ncyN~$$AK2Y|DTp z(zUuyskL_?=kpkYm+3eMZ<+M?JUSzSNow%q^7>}Vym1fS>CT~z{5`Zi3bqoj$~QUD zOuy*a&J7JXP#iqlpkC-@QR%T^8!R)smHH>Q#Ud`!r&K5K@CIXp-s$}SE6AE6W^x#EMFG}el zniT>~Ds2$^=f$146Kz@*4}yVgCeOaiyt_MlyC;NjMBS+gr%qwl3@936SJ1QlTVp}Z z`;xGB2fP7FWZVHyB7$oW_AEOBpV)+EPC=P*YG?Lgh%y8>KpFI)goB|pDb!H*KcI(5 zFbHJ$Sy@1(q$*(tQ1(M|Fen{ZlUPdp-u`Bqm9GiDr)6hl^DLV$Qv2J~FVRE(L+4W9P@A%qI7w-F#U&7;O+_n`wvl8}s+UG` zY<1m2Ydb#UJsN|X>L>$u8TWWUx+8*dV({eR>Uzq&c?a&v#-@$DE%adIuO)sj-{M3w z{j6sj_tED-aqwh=My{86WsOa{z#_9#segErFQPnoOmqzQD;OK}O79zdL Date: Fri, 31 Jul 2015 13:19:32 -0400 Subject: [PATCH 134/219] Change sample sizes row to space padded one --- R/print.TableOne.R | 13 +- test-all.txt | 208 +++++++++++++++++++++++---- tests/testthat/test-CreateTableOne.R | 1 - 3 files changed, 190 insertions(+), 32 deletions(-) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 4ff3411..5e47db9 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -137,22 +137,21 @@ function(x, # TableOne object ## return a strata-by-table df containing spaces to add nSpacesToAdd <- ModuleNSpacesToAdd(FmtElementTables) ## Actually add spaces to tables - spaceFmtEltTables <- ModuleAddSpacesToTable(FmtElementTables, nSpacesToAdd, showAllLevels) + spcFmtEltTables <- ModuleAddSpacesToTable(FmtElementTables, nSpacesToAdd, showAllLevels) ## Create a list of one variable tables excluding sample size row - lstOneVarTables <- ModuleListOfOneVarTables(spaceFmtEltTables, + lstOneVarTables <- ModuleListOfOneVarTables(spcFmtEltTables, MetaData = x$MetaData) ## Check if the first row is CatTable element - ## if so, pick sample size row from CatTable element + ## if so, pick sample size row from space-padded CatTable element + ## if not, pick sample size row from space-padded ContTable element ## Intentionally a one-element list lstStratumSizesRow <- ifelse(x$MetaData$logiFactors[1], - ## Change this to spaceFmtEltTables$ after tests pass - ## These are not space-padded yet - list(FmtElementTables$FmtCatTableN), - list(FmtElementTables$FmtContTableN)) + list(spcFmtEltTables$FmtCatTableN), + list(spcFmtEltTables$FmtContTableN)) ## Row-combin n and all variables out <- do.call(rbind, diff --git a/test-all.txt b/test-all.txt index 69494d9..f866986 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1,7 +1,7 @@ Rscript -e "devtools::test()" Unit tests for the CreateTableOne function : ........... Stratified by trt 1 2 p test - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 status (%) 0.894 0 83 (52.5) 85 (55.2) @@ -30,9 +30,9 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -. +1 Overall - n 418 + n 418 time (mean (sd)) 1917.78 (1104.67) status (%) 0 232 (55.5) @@ -61,9 +61,9 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) -. +2 Overall - n 418 + n 418 time (mean (sd)) 1917.78 (1104.67) status (%) 0 232 (55.5) @@ -102,9 +102,9 @@ Unit tests for the CreateTableOne function : ........... St 3 155 (37.1) 4 144 (34.4) NA 6 ( 1.4) -. Stratified by trt:sex +3 Stratified by trt:sex 1:m 2:m 1:f - n 21 15 137 + n 21 15 137 time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) status (%) 0 4 (19.0) 7 (46.7) 79 ( 57.7) @@ -135,7 +135,7 @@ Unit tests for the CreateTableOne function : ........... St 4 8 (38.1) 7 (46.7) 47 ( 34.3) Stratified by trt:sex 2:f p test - n 139 + n 139 time (mean (sd)) 1979.65 (1127.52) 0.730 status (%) 0.033 0 78 ( 56.1) @@ -164,9 +164,9 @@ Unit tests for the CreateTableOne function : ........... St 2 30 ( 21.6) 3 59 ( 42.4) 4 47 ( 33.8) -. Stratified by trt +4 Stratified by trt 1 2 p - n 158 154 + n 158 154 time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 status (%) 0.89351 0 83 (52.532) 85 (55.195) @@ -226,9 +226,9 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -. Stratified by trt +5 Stratified by trt 1 2 - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) status (%) 0 83 (52.5) 85 (55.2) @@ -257,9 +257,9 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -. Stratified by trt +6 Stratified by trt 1 2 - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) status (%) 0 83 (52.5) 85 (55.2) @@ -319,9 +319,9 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -. Stratified by trt +7 Stratified by trt 1 - n 158 + n 158 time (mean (sd)) 2015.62 (1094.12) status (%) 0 83 (52.5) @@ -352,7 +352,7 @@ Unit tests for the CreateTableOne function : ........... St 4 55 (34.8) Stratified by trt 2 p test - n 154 + n 154 time (mean (sd)) 1996.86 (1155.93) 0.883 status (%) 0.894 0 85 (55.2) @@ -381,7 +381,7 @@ Unit tests for the CreateTableOne function : ........... St 2 32 (20.8) 3 64 (41.6) 4 54 (35.1) -. Stratified by trt +8 Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -445,7 +445,7 @@ Unit tests for the CreateTableOne function : ........... St 4 . Stratified by trt level 1 - n 158 + n 158 time (mean (sd)) 2015.62 (1094.12) status (%) 0 83 (52.5) 1 10 ( 6.3) @@ -477,7 +477,7 @@ Unit tests for the CreateTableOne function : ........... St 4 55 (34.8) Stratified by trt 2 p test - n 154 + n 154 time (mean (sd)) 1996.86 (1155.93) 0.883 status (%) 85 (55.2) 0.884 exact 9 ( 5.8) @@ -507,7 +507,7 @@ Unit tests for the CreateTableOne function : ........... St 32 (20.8) 64 (41.6) 54 (35.1) -. "Stratified by trt" +9 "Stratified by trt" "" "1" "n" "158" "time (mean (sd))" "2015.62 (1094.12)" @@ -1151,7 +1151,7 @@ agecat 0.702331 0.9040822 0.109801 0.985333 0.8536402 0.3838583 0.9772713 race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 ... Stratified by HI_CHOL:RIAGENDR 0:1 1:1 0:2 1:2 p - n 3526 363 3533 424 + n 3526 363 3533 424 race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 agecat (%) <0.001 (0,19] 1119 (31.7) 10 ( 2.8) 1015 (28.7) 6 ( 1.4) @@ -1649,7 +1649,7 @@ Unit tests for svy* user functions : .... Stratified by E RIAGENDR = 2 (%) <0.0000001 . Stratified by RIAGENDR 1 2 p - n 134944553.92 141591892.00 + n 134944553.92 141591892.00 HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 race (%) 0.042 1 21381884.189 (15.845) 20251367.389 ( 14.303) @@ -1710,4 +1710,164 @@ Unit tests for svy* user functions : .... Stratified by E . Unit tests for the survey-related modules : ................................................ -DONE +1. Failure (at test-CreateTableOne.R#145): printing of a TableOne object does not regress +print(pbcByTrt, printToggle = TRUE) not equal to reference from ref-TableOne_defaultPrint +2 string mismatches: +x[1]: "158" +y[1]: " 158" + +x[30]: "154" +y[30]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +2. Failure (at test-CreateTableOne.R#148): printing of a TableOne object does not regress +print(pbcOverall, printToggle = TRUE) not equal to reference from ref-TableOne_overallPrint +1 string mismatches: +x[1]: "418" +y[1]: " 418" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +3. Failure (at test-CreateTableOne.R#151): printing of a TableOne object does not regress +print(pbcInclNa, printToggle = TRUE) not equal to reference from ref-TableOne_IncludeNA +1 string mismatches: +x[1]: "418" +y[1]: " 418" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +4. Failure (at test-CreateTableOne.R#154): printing of a TableOne object does not regress +print(pbcByTrtSex, printToggle = TRUE) not equal to reference from ref-TableOne_2StrataVars +4 string mismatches: +x[1]: "21" +y[1]: " 21" + +x[30]: "15" +y[30]: " 15" + +x[59]: "137" +y[59]: " 137" + +x[88]: "139" +y[88]: " 139" + +x[NA]: NA +y[NA]: NA + +5. Failure (at test-CreateTableOne.R#158): printing of a TableOne object does not regress +print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-TableOne_digits +2 string mismatches: +x[1]: "158" +y[1]: " 158" + +x[30]: "154" +y[30]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +6. Failure (at test-CreateTableOne.R#161): printing of a TableOne object does not regress +print(pbcByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-TableOne_noTests +2 string mismatches: +x[1]: "158" +y[1]: " 158" + +x[30]: "154" +y[30]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +7. Failure (at test-CreateTableOne.R#164): printing of a TableOne object does not regress +print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_exact +2 string mismatches: +x[1]: "158" +y[1]: " 158" + +x[30]: "154" +y[30]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +8. Failure (at test-CreateTableOne.R#167): printing of a TableOne object does not regress +print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_minMax +2 string mismatches: +x[1]: "158" +y[1]: " 158" + +x[30]: "154" +y[30]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +9. Failure (at test-CreateTableOne.R#173): printing of a TableOne object does not regress +print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_showAllLevels +2 string mismatches: +x[31]: "158" +y[31]: " 158" + +x[61]: "154" +y[61]: " 154" + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA + +x[NA]: NA +y[NA]: NA diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 19afb3b..f46524d 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -154,7 +154,6 @@ test_that("printing of a TableOne object does not regress", { expect_equal_to_reference(print(pbcByTrtSex, printToggle = TRUE), "ref-TableOne_2StrataVars") - ## 2015-07-25 pDigits is not functional now expect_equal_to_reference(print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE), "ref-TableOne_digits") From bc6870fe6fee7c8b700d98147dab8ea29584a184 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 13:21:16 -0400 Subject: [PATCH 135/219] Update refs after sample sizes row is added --- test-all.txt | 180 ++----------------- tests/testthat/ref-TableOne_2StrataVars | Bin 1129 -> 1134 bytes tests/testthat/ref-TableOne_IncludeNA | Bin 568 -> 571 bytes tests/testthat/ref-TableOne_defaultPrint | Bin 781 -> 782 bytes tests/testthat/ref-TableOne_digits | Bin 907 -> 910 bytes tests/testthat/ref-TableOne_noTests | Bin 697 -> 700 bytes tests/testthat/ref-TableOne_nonnormal_exact | Bin 867 -> 870 bytes tests/testthat/ref-TableOne_nonnormal_minMax | Bin 849 -> 851 bytes tests/testthat/ref-TableOne_overallPrint | Bin 515 -> 518 bytes tests/testthat/ref-TableOne_showAllLevels | Bin 917 -> 920 bytes 10 files changed, 10 insertions(+), 170 deletions(-) diff --git a/test-all.txt b/test-all.txt index f866986..663aeec 100644 --- a/test-all.txt +++ b/test-all.txt @@ -30,7 +30,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -1 +. Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -61,7 +61,7 @@ Unit tests for the CreateTableOne function : ........... St 2 92 (22.3) 3 155 (37.6) 4 144 (35.0) -2 +. Overall n 418 time (mean (sd)) 1917.78 (1104.67) @@ -102,7 +102,7 @@ Unit tests for the CreateTableOne function : ........... St 3 155 (37.1) 4 144 (34.4) NA 6 ( 1.4) -3 Stratified by trt:sex +. Stratified by trt:sex 1:m 2:m 1:f n 21 15 137 time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) @@ -164,7 +164,7 @@ Unit tests for the CreateTableOne function : ........... St 2 30 ( 21.6) 3 59 ( 42.4) 4 47 ( 33.8) -4 Stratified by trt +. Stratified by trt 1 2 p n 158 154 time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 @@ -226,7 +226,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -5 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -257,7 +257,7 @@ Unit tests for the CreateTableOne function : ........... St 2 35 (22.2) 32 (20.8) 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) -6 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -319,7 +319,7 @@ Unit tests for the CreateTableOne function : ........... St 2 3 4 -7 Stratified by trt +. Stratified by trt 1 n 158 time (mean (sd)) 2015.62 (1094.12) @@ -381,7 +381,7 @@ Unit tests for the CreateTableOne function : ........... St 2 32 (20.8) 3 64 (41.6) 4 54 (35.1) -8 Stratified by trt +. Stratified by trt 1 2 n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) @@ -507,7 +507,7 @@ Unit tests for the CreateTableOne function : ........... St 32 (20.8) 64 (41.6) 54 (35.1) -9 "Stratified by trt" +. "Stratified by trt" "" "1" "n" "158" "time (mean (sd))" "2015.62 (1094.12)" @@ -1710,164 +1710,4 @@ Unit tests for svy* user functions : .... Stratified by E . Unit tests for the survey-related modules : ................................................ -1. Failure (at test-CreateTableOne.R#145): printing of a TableOne object does not regress -print(pbcByTrt, printToggle = TRUE) not equal to reference from ref-TableOne_defaultPrint -2 string mismatches: -x[1]: "158" -y[1]: " 158" - -x[30]: "154" -y[30]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -2. Failure (at test-CreateTableOne.R#148): printing of a TableOne object does not regress -print(pbcOverall, printToggle = TRUE) not equal to reference from ref-TableOne_overallPrint -1 string mismatches: -x[1]: "418" -y[1]: " 418" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -3. Failure (at test-CreateTableOne.R#151): printing of a TableOne object does not regress -print(pbcInclNa, printToggle = TRUE) not equal to reference from ref-TableOne_IncludeNA -1 string mismatches: -x[1]: "418" -y[1]: " 418" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -4. Failure (at test-CreateTableOne.R#154): printing of a TableOne object does not regress -print(pbcByTrtSex, printToggle = TRUE) not equal to reference from ref-TableOne_2StrataVars -4 string mismatches: -x[1]: "21" -y[1]: " 21" - -x[30]: "15" -y[30]: " 15" - -x[59]: "137" -y[59]: " 137" - -x[88]: "139" -y[88]: " 139" - -x[NA]: NA -y[NA]: NA - -5. Failure (at test-CreateTableOne.R#158): printing of a TableOne object does not regress -print(pbcByTrt, catDigits = 3, contDigits = 4, pDigits = 5, printToggle = TRUE) not equal to reference from ref-TableOne_digits -2 string mismatches: -x[1]: "158" -y[1]: " 158" - -x[30]: "154" -y[30]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -6. Failure (at test-CreateTableOne.R#161): printing of a TableOne object does not regress -print(pbcByTrt, test = FALSE, printToggle = TRUE) not equal to reference from ref-TableOne_noTests -2 string mismatches: -x[1]: "158" -y[1]: " 158" - -x[30]: "154" -y[30]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -7. Failure (at test-CreateTableOne.R#164): printing of a TableOne object does not regress -print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_exact -2 string mismatches: -x[1]: "158" -y[1]: " 158" - -x[30]: "154" -y[30]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -8. Failure (at test-CreateTableOne.R#167): printing of a TableOne object does not regress -print(pbcByTrt, nonnormal = nonnormalVars, minMax = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_nonnormal_minMax -2 string mismatches: -x[1]: "158" -y[1]: " 158" - -x[30]: "154" -y[30]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -9. Failure (at test-CreateTableOne.R#173): printing of a TableOne object does not regress -print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, showAllLevels = TRUE, printToggle = TRUE) not equal to reference from ref-TableOne_showAllLevels -2 string mismatches: -x[31]: "158" -y[31]: " 158" - -x[61]: "154" -y[61]: " 154" - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA - -x[NA]: NA -y[NA]: NA +DONE diff --git a/tests/testthat/ref-TableOne_2StrataVars b/tests/testthat/ref-TableOne_2StrataVars index 4d846fe54599a92b310854788ded891a9b17c87c..64c460a081d7e23092060761b90ab5c4a01cb3de 100644 GIT binary patch literal 1134 zcmV-!1d;n6iwFP!000001Lc>?ZsSG}Md`;l@dO!b;$#`1Hvyzgqu&oB`HF0^rEPjF zM6v~m10+9{PYiO4q{I?M$==6+&F*5Uy871XYWa_kMNym=7w2ci`2`Ip`14P3SzP1! zji4W+yXj{gvz0E1sW#5ZsAk=Z4~<_pxoIZC!7EEO8<;K3PTGN4!#e~Sx!HT^BP}I^ zp6v%wVk*>OYz?!MX&BpxsgF{>mC48^G}cf0y_+~#{}YKPGxRc2@AfbePC-S)Fv`j7 zXUyBm0K3B5-djg_VaHl|X?OO|#-$*2Kopzs!t@eplVn6L4iCr7&dUU|4>B-sV3Nww^Z?c+(839vMU4$M=0e9j&X;G=^YYj>9{pGg}DwI*=-Sd-ln zSe~KX+CAlOqcnTqDH&4(Uhp&Sj+DsEfoQ{!fMW0Xwf4|-B6nbSbXu)qX&!7vYltNh zs`AdY2y?6`!vMdg=4dz!KcA#QV=&lZkL4bItX&CoHR@u?NE3VfGE`Dc5D$nw=Pb!g z?Tx7A6r*yf;momIOaQF8Rn^=5wigWLlHBofYia}{GNM|$CEbl-T6DUTM%J^dp|cYn zmfs{Dg1O&s%uRd7>59^u69^_kFdU$^tLi)_{O3+fd-e9YMQ=@19NK4{N4=_mp`;Nth2NLQsSD0J}kCq4x?fHqXUq@ zH2OdyLLH}{6`KQSnRG?>yuw8ntzt7}?Z9XFy!sVhN{`PF!Rx?gMkO9SWj4zyytS5~ zV!6HOhR>2ennzST51)A+Hu62&z+?7T1I>baE64xOv$#CRpR;a$@i<@N@qI!6Sro<3 zB-p^^Te!TG%W4Cc+s<#&__puQUbdXp^JOKb%c^`4)6L^-dnP_^>aza25z}AzDN$^! z*?3#UoAS$8u7ln}>N_ZD7{S{OP$`mG$eudb3&0AFK7y`MP?nmgSKY zuV^g&NWzo*`C>kj<>cY{bunVUEf@D+m-CmAS3f+wu2$80Yr=V@0E}Wn$09d&8tUo|F@{u^&P0ei+}0&Ke3(JO-By^0BJKe A8UO$Q literal 1129 zcmV-v1eW_BiwFP!000001Lc=ZZ{s!)h7~6pG+T7zZQ5f2UJBS3g5MuO`zw0sRf(02 zQ9ChgEztg{{=`M!kz{);%TDeMkcb?Ohr@Rs4xK+g7DX{CE=L!|=#qwG{Q0-IDsE_E zbT|5}W46*IG11038P&9V@j=i}H@R&l!oe#`HSL)#%ud>#S;IR78M)be=_4&AgPtA+ zQDP$0acm84F_rCN$Ph`n{VtTK^MlMrP<`q~7geES!Rhh+&kI*-x3b zl>v5zw|j3L;e{P*<)z)(KO2{V)B#a!!V9yPNSh=ha&dS#W_DgCn0=6ec^eCXy_n=E zZDP4-C6l9EvO8C1h%2)6eJM^>;uW7!yQVGgeyU zylRlkoFFe9tSL*qV*;n&I_ZFlaWNezq;W_+^h8tGGel;b1`uii2#ao+sCgwLP28iGp^|EXcmV74>23_uqSKu;vYy=tot^No`~m@f zdB4|~n~scA6{R<4@JobWIKpgOn|{r_Y4LNsW-iKrnxVq3M_(SMj~XYz-QU%zY@DN2 z^?CXzV^qGcAaz45cw|4$q2(z;HhgVRj6U4ok?vYl-t_5fx{YP6Nn|Gj@UG zrJkzrB}H@k3@#_tG5A@ojSDVX#b(Odo=^XI{TsZL9-bkB*MZH9N<4bXY?f7cYb`;=atF~3 zpCx}XkEnPaKJz?m?r1NOUe@$hvye;Ii7bCy&hV>UeCV_ zg<37jx>{62pSfGDUr$u<1{I`g9H=u?G#Xnrb{#9%yZiEfxgDDQP~Si8t=r+nY8wc( vt$R>@=!k5hk9v^*{71bm>-p2Xnu&*hM7^%>K@DDfqu>7kmPIK1H4gv)W!5Zx diff --git a/tests/testthat/ref-TableOne_IncludeNA b/tests/testthat/ref-TableOne_IncludeNA index da68d2c26fd9d8c84fc3be2fea538619dfb69bcc..25917754471499f31b8c8233384225d972247522 100644 GIT binary patch literal 571 zcmV-B0>u3viwFP!000001C>)vZ`&{oRX(~d4Yp>@et<5+oC{%n+CKEKKd@bQRTHf- zW+z7M4*T^(snpJ7R{@#;i5T+fk$j|n-Vj2@WHKI+@x+-6{P{|zWQON8#gAlZ`}Y&e zSOQ5(BgSG0I$5=Wsl&DQt+Tn{G*SxGs^_L$(THk@`);NgjYQfH}Wl0o`d(}*jO=Lwm@euVZQZQ=2;aB(pq=T0C2Y*1l_gq#g^ zdjp|RP8B)qjmj4dUkw8DPzmYD{n2rNt4e}oo!|>9G%Ahb;etUXS3R^s5*!cr#*-zW zamJ|veImiNNjYfO0+TU_>_47y4hjQGLlXOLYy`=*0_F{$s{~@KFhj+KR|@u*2y7FB zXE%~^cAR}Y6dd`mh~Y*mY(gZ%@i3>Rki#{g6kDL|=qA%Kx<_qzvdK$4J{;eedsi;h zhrCC~&Xl%B$g;)xZ*a8hX3^xOrBP|kjz;xn)wOz4H>P>2Y4pW!KK5+p*}N;$wb{7X|jJeBz_5V~9MtI8e%kP+`xP4g!aPO!n0*x>zCc^cK7}LyiwFP!000001C>)vkJB&^bw3v9Rk;E@Qk-lmZ7Zc7%{;%Ec{BcTO9+{g*>pmtGjFc&?=zW`1)ej-lh%CCQyxQ{ z(1>%Uz{Hz2FsJxy?K^J^DQKiM=uOW}g{BcT!1``(IE`e|M{5SL!b}X5-h^oB-ANjt zpQlf-Mw37~OpiCIhIo*k85#)<>M|kM*pD;;q%E8^h0Ci6h42DN;DZWNBout8+Y1P# z_Nu61Z&W>L_-qiEhblPzv@JOKcN^7dMg$ z-prm21xG$CVz`kSn~?EvJlv}()o=|c#TF=U++;pQ_oRC~yR5+DZS%hToARMP`3{Fh;hl+#mXd z{tVcbw%TU3dr5*Dw7-4r>e{=~*2inFEvquyxzp9@7H;PXd*RkAZ-XA;SlwrNHX_7o zyFcb5{+*EG zup|py5sI%9j`Z5i0Aul3VzcDwuf`)_x$c|KU_n|7ZY?6h@~^GV2G|NR5rnHJ%8 G1^@tO%?>I6 diff --git a/tests/testthat/ref-TableOne_defaultPrint b/tests/testthat/ref-TableOne_defaultPrint index 6aef72c9227d3ed4c09792d379036c48b285abbb..1596fa97f79286dfd504f6b80965571c6e602d6b 100644 GIT binary patch literal 782 zcmV+p1M&PHiwFP!000001LalAZqzUo%}j?vi)g2mEs{4#na!2ou@`&=8@6dDZ6oFp zO;QPd9&w#X=#7&B_KY;KeSCbM$H~{rBuVDU*?gAF&%$(xk0x0p7dXCV_!Gu;%Nxms z0V`Q5xYr=$s@qruUN^rEbLJFFjRdnA!h*AuSx^yd4NJ8EL18062TuaHSW&i68B3jo zEVixDwgVr*8AhTl$OzWxQaTdgC{M!32ug4mtOBe06qZa`gDIhR z?!o94VWTf}$w6z9u+P9^W}bubtCvPd0SY}zfe})^kQ^jhHyVvm82g20GC_PUnKTYE z6Y}ApB#8wR3{BzS%;_czjFw?|Q6*F;tsGU{VBM4f9mB|08r*NV6P@mJ72aELq3FUG z@ahkuLsLkJ9W#$%8sec79hOgd;Iv^H72&Yh;BBNi-?ktYZrAi!BBAMK47Zx|B)$pF zVe6b3i%YfIj%zn^e^gQE9G1Zm&1DK4CMNMtYB#Al9%&A3ID}s`C%jfi;R-Im`k}ad zNZFD01Q>%bEli~-QU8*+<;>Jjat>j94d~M?X5o^{vE*d9PvaKr_Pr9bjc%3rQskr? z&l%cqimtqlIPn-*TsX4QQjnFg8D%=k^v+OUS@sXUP$FcNX*aN-sdeuMOd5x_e2}xH z5gQtn@bnyh0sa!>|1&0wIX-6H`fOcpad?-6&uNl;Y>7k48>H;=ZBZlTw&N{Z?s0#% z>o06mZVQ%fi+sn@dcErJ!)4v%&2!DtPxOXxG8bend(r2QQ^wxb#dr3ZJrHZxd3|3t zMUAi^@YPdM<;^}quj{H@7l)X9QLKw?ej>#4Fb6Xc@ba$QloL@d@1ORY3H&zS+&yp0 z-Ne@W`+Zdvhl!mJ`Q{r`Py2de4|8v({5Oa4amrM+$(v$ROr5!{4*L@wyuc2IZVak3 z)wD2IWUf1{EPAcVIiwFP!000001LajsZ`&{ob<(U@JFHFDT?gngz_}3mwshF9*kxC@aa&{g zFk%oc&Bf+eOZoyf~EU3tB4NJ8ELET1x4w(dSv7%_9GL||E zSsYtqYzIDaXUIfbkda$sO6dr}Q4K<2dZ)%U*iiqF>{Mx2=#=1)tOBe05|&I^gC${h z?!o94L1QjV$w6yUu+P9^WuAlatJgtD0SYrpfea~LNDdOC8;!xJ8|Q^#GC^`KnKTYE z6YAlhB;kSuhM{n9=Jb#SvSmmw>Vyidm7|Uu?3*&6V>hCe2KVAd!RfwE;k^YH8ZL|h zul^u7416Nz9}3Hd zk{uaOa3cxRx~U8$YG3lUotYZS&7m7#0s8caS-9YGEH@eM(s;zWeW%1|qgxfeHaY3m zbA~aTqEB8&n0O5+E*yE%QjjNOGm3N+>7Ajuvg{vnp+v}2rrjWdrqR70ASn-R`JiS? z85_zhm9;LnxV%ro-)NG2YJo$@TZHWLZBZlSw!~Vj# z>o06mZVQ%fi+sn@dcErJ!)4v%&2!Dt&-8|HVhdu+UiA6nRIqn-@q>L~4daxqzl0zIs7>ESLBlG+SWKM3PkDzc!fRYWZFiltMCP7auo)}D)kP|-_=9kGl`a#XZB7gLke(Wgri z*jvNle2%n2PJaSY%2u)_n?tC)aezFbvXRalH3#WgsdQ(Bn^~W6L>e5YR4Ezw>~LB* z1Uuoum`8atiLsW%V@)x#Z8)W14B?cqGLU+OUIlLZoKTDoDlw^O#4KZ0fhz)sTNu&= zPZ4nimSI8_4jD2*#!Qb$kPVW9hQlZ$`!LdXY>TL!x_>4m8^@vA5>7*{zN6IooBBr6 z1*p%BFG;5DENibecpmwrRA*aKQU}WQ?TrlB0Vli|HduF|Z*4--j)}QWTYYmXSb+2c z7@lis4H`z-q;Eyip{<4@j*dYQl8uH25U4Tv7J~HY3~BTrUW!v8ypDD#@1R=gqdS8B zZ`p|SAb;UqjN@k^bqJcz`-ykaw(lY%0V8?aR{42}if()(z$_TW`8pb=3%koP*(vhQ zXKSnR=4Wem$U<%(f~IU8QAU@?^)Be|h)V|FFWK5#ALGD}2_cUYBe|iy&es;1R)c&v zmHTJ5ob#sWDaY~6XVf=%|9{5fc8-r(x4v1|TYn5c7wM-&QT)~#4o%*`Zx zc8k{bgwI~O$)c&Zl~``8@s8-HZ;wscd_9Wg@BPj#M6a?rW%FKP_vM!7JU-P;b;LGh+rK}3JzeRJv>EfUC|1W_to{1U@0097@UB*TL delta 900 zcmV-~1AF|A2a5-g6n|l-NUX%ku>daxqzl0zhhK;Oid=GCTbp=M$r7|1p#AejAJ^K5 zt6ep@$AHC;H{?9dycy}!tD-38#npUP%&*dPfseMhE^aYikqyV`2d&6TrPqAcLb30!|BxIE6HehHqtVWJ-ZYuM9Tk20N!C+%is<8 z8bmt8{*mv6aaJl~(A6r!m-&XJQ}9j>n3Bw=q`+15(qTs|qmni%TAh-qN$Tj+BMI!; z*l;>WS|KI@A%C?jttQSPWZpPHo{-r{Cyv?%>8(=f%?dALpK(MOoK2xpGT76F)50Ox z2@l406gQI?Ye{yjDT`7#;LsQo6`m8MD}5kTx!aAx$t8 z5#+556MArnjR`VlN)jzqBtpAk#s1ip?ssWpa`)>LjwrZEcp(C=;;J$R3Cc8OCr3EJQQ|No#;^)LI1yO zL~2Foh<|b15K?WR?7W}oh}?BVivWy-&7J1+6cxwuMu1r`%I526ES=e%kI7DvcRpLQ zMz_z_)*%YHeF&PebwnCn?$^7Zf50ype6wV0&pyV%JtlQ`A5HV4biJ?PT9Oy*j@Q$>ayRO>TmI< z_?+E#S2mAzTQ%6GZ2QeqwJ+P<+3sDluh-S#-1xRySKIOe#nc8MvkAhBhk8>_uv|Po z?R_>A`}gJM;p?`3o`Bvx?)LlYFoC=;H-E|f)2^Ao@b-4fe|xCEOkK6#lx?-Crq0~& z54#H)yhR36HU`m|N?MwmY|clmT=!b(56$`$vwd%l47O*|`{k&+?vDAHl;3`A4`o|_ auB)|p_(!w{oG$)N|Nj9@+U{Hq3jhF+qsCPL diff --git a/tests/testthat/ref-TableOne_noTests b/tests/testthat/ref-TableOne_noTests index b9c704178a4d57c97bd9aa4db8457b32d9e01c2a..2b9b6d755473c9f497e9c1b4f119180fdce3ff93 100644 GIT binary patch delta 686 zcmV;f0#W_B1-u1+ABzY80000000Vtg+m6#P5KS*!x`^FEc}4OIQu;FTHL;QS3SM|k zTkkfam#E1~@bidqny`-JQmM`Kcrr6*&PjgUB}p<(X46SBow;y{KVOr1vcT&bf*+=I z_xA&*OhLv;%BYdR__{loySy%ba52$>q>6)D4`D`0N-_|C0h}q4N(Rh_6$9xyF`#Vi zXETwLRA-QfwI$ZpU;;SDNn{2*fF-u%+8c1hfeCD{#h63p_z#DTQM*TwgT`S6WTL0A zBqCEt3A?oB9=A&l8Vg8m10rjtEa zW=sa!EuAR^M*PQgSPE0Z#>C*5%InaX4%a6PP+u^Kj?lPlFj?R^(@GE;w-Y_Ih!b6n z;ns7;n=j%yluoO$xkT&jaCf8jR~I?ua1Gk?TrNO=BQcK8q|{N*(ZF+9LnHj+IcB7| z8kbQ9nHiePILg|S$H6#+YGL1s9R1H}yUtt;EvFI2*MPh&F>wz$A6t&Q=V>glY~L$k zwvw$A-I9~}6yZsCJlmB=yu5E;iAnPLdL5*^#gtQVv^5^By1ZqZdp)0=`lUDJ(USCN zixWv$>)pENbXPY;^IVhki_emJG4o>H4_-XQioL7tFY=8%det6^dRsQOMwof<{oYnZ za}Lmlx+-_}5+*O~&K`>!BffSqsK~&}O?fCIQ!cmr^C5z-io@pllTiX3Oi!^=)uCwY z!N%@cRhRP(1sABGQ)955m}o8*UMxGWOna~NH%)lpvR9qO2I)!vBz|u$MN>YOc1Je9 UNpoos{NuiV0qo;=;LQgB0I6n6oB#j- literal 697 zcmV;q0!IBGiwFP!000001ASCYkJB&^O}horMQpp2E0Qlr>1E{4#75#*aN(M^-fcub zq9!ZBpGS<-gmoO3N^M5Z)0uhmp7Y~ANs?)DH=QKYI~OkT=W8-c=J>p0N_XKSr%XY{ zNy?~^!1%g5m=XMR@xsMK3z8}hYCVJ*B`L{31aPKEDj6^zRt%);#DKE3pUp&0Qk_8_ z)|OaXg9+dqCy^QO0G8O2Yj4022PUw+7Gn;X<3AiWM(qJX4jP9Qkcpncl88(pCG1WO zD7p5su@|b{ZgnmBb6gXB_5{vmT>V;);=Ji|>t~BJz z@u48NHwzMUqEOK4w#W>pB{*KN3E@`DM;lkTH=#g=FlGx0`X7vjlRZynOa|I5oGArH z{Ks%u22;YO#Ndd^tKJz7S0@ZmUo44k(70$YS>QL*u0J$wCwOQNC%78Jt>26{U&L=H zn^t3EiPqQQ-bU@O4sxpD8noxPT!2Pm9PgvlQNPi^Z&*Vk{OUJmq_~=vQ3jbA8p}A! z+LOn@ID~3p--aB$&uP2PTnz1|5yn@5ye%!=>q58WWHv>3 z(%WuV9`W&^eHA9j=j(Hj@(xo@#nIMywCeJfZSM7aa_X1flt)X_qb*J(t#|95(|z3( z%}Y(vFFs4^#mtL&KX~yREB3y&zsNW8 z&K`>!BffPpsK~&}O?fCIQ!cmr^C5z-io@pRSe_zBAGhbKvX{uor{eGvs{Of+oFVrn z*1x%w&#_X~p=j*E#{RRaF6SEx&QU?9#$Y=!(OfLNSax2S_Fn1#G~t2E-gFilq$mAN f{N7xOrhF>xj%gB0mT+>L9kTa_&7Z>%$$m#0&*v*NNB-DcH zi?*3F5|W5Y&m3tIDo!~zYfhCriBrZeu$s%5geIb~A6r3eL#=0yArlo*;h7a2DGW-m zQv;W9ypi1+B3FMq*}l@woRKOqwIDyV^d7gR7P@kuZS2Sx>l)__hth2<=&!W!oe zVO4~@PKeM3!nvv$m0P!CS2K03gZlJt6gX5tVj6k(C0zqVr!N|AS8A$!GpMDaW^1m| zR1KQk+K3w08m=|9@;85ILMV{<2NMfvYIH)4CbU&r%C=@GTLCwQgqGUKBNJj+*1@|* z!w1O#$GU5-$h0WG9x|bYMt2dE)f3>~UFY}>nX)1?7LLpalgZ?UOn^iHL^9qRH( zAnt`Bx?nRn{0ocxh!WH+G)I<1C*iWjarL-SYKn zM?(*xp{_Zt%j)Z)n@coTH9DgPoyKXiyPiKz6YuRB&hw=)_Z4&Y~);aqbXS zMab)f2yGyotC~@{bvt%7Q`b7EPwz&7Llq>Zk#}FxH9&OwqTzO>rph;iS}JO`X24Q4 zSaNG4YFt~m*3`=1U#F;wLNm{d?;izoAlARK~(l8DT1!+)xRC2mnaNJE>$nRLTvN z?#?ikX0vUf-4$L|S>Op%si<`qVo>vdN-kSeLgO&YB7#P;>e7E>*@n`98D1x9HweVN zEJPPds0|*G4hX7xKly5{DpsFb5!B-Wffz=%R?5@(qf;?%&`Jr8RyvBY(qN@E8lM%% ze{q&k0!LS>6#=hej!!lm`>BYbm5lL9Yn&CgIErBU4>|4{_tVE@T0YbHU&j~A)pEI7 zFZ!4NrFv#v!DxR7KZE8iILj6=ybj#|cM!arN`|W`D43-t%R) zNJ+RzlO+j@*+uj492I3!J`^PUfFCD@<{Zr%IL66cU$9q2`ba*KTNG`a6w|Cs3ovtJ zKE6-$q+EH{agk@UbnS}|(^@lu*jA@<-M7%@;qJl`<*BA?=-((75&?A4`oltNx9DM`aRC_c~YkHwAU?PuXZ%_ z5E|;5)4Hs_9=f?ib5)}=YS3w%293ucZ{*O>(j#%d#;}Sp^vFK_TCS5ayUo%Wx%olL THFyU<-S-I>`KM=~o(cc}+Nypw diff --git a/tests/testthat/ref-TableOne_nonnormal_minMax b/tests/testthat/ref-TableOne_nonnormal_minMax index cf31816e9e8b791d68b0f24fbeeea6da4690ea58..da1e6a891f37367f5bad1befd9183a5c13174c6b 100644 GIT binary patch delta 844 zcmV-S1GD_m2Ga(R6n|Yi*0gk4>0qFjfdfP6YD*9M6?++!KDdqBnkA00UD*Eo*pVZr zvTX0d9u`O>9ew9Jx6jU(lOPDD!NGJAOb^WV41Vfh797KRgy2J^vd42qsKgONAthR1 z%9i$GW^i^tH+!Tw3MIpG*)>ywLKI={nInlpK{0jBl44;ZQGZP6(nV7qqfkXS_PGUc zE37?p44H@sGtVp_BvVd;y&5Qo@QU|qh)n(6WQR&y7$X)0T@%d7N5lvwMJG4R~wn0TjB{jgwT$@p(rX6%8qmcK4J@>9Wodg)|t2 z;Q(+yze~tIYJX@s-|=df_Y5(qa4b#TP|M!!)Krbl@Ca6NTnrSdKrxQIj&U;r)|-rk z{&I?M zP-7i=+5`?wdIGoN@TH_c$+B;5w5gr^2DAwyRI)EZ-hVs;e(!qWciQC7+EiU_5^l9g ztTtmgrcKh-@}vcNyeZ*u(K>ruYV z^KH2qKK>Kx?^6n9Q}~(K^T8_H!16jU|KLIJz5#Y2F9DJ#o3sMRg~gpU*xmgkZ{P8C zwnUYAM!klwTui@V3| zdhGHdS>HZwvV5S#%e!q+q~)0BRkHqyi^pv>27rFl1GI~}%pS&k-W2PkPS@#><3&+! zM@2?^45Kw;>a=ZWnr6?Py|5yhwIXVrCauS$XyGv0+SB9S_G^b6qBNcAupy Wbo(9EC3puv%=ae_@9mzd3IG6HbesqP delta 842 zcmV-Q1GW6q2GItP6n|Sg*0gk4>0qFjfdfV8Zs}paVlRWz2e)xsv&1pB3)`O`J96w) zmhD~G!wQX#j=uBhT)rq@j)NeW1_#qgFg>v5DSTAHEI5MofJ)t%XN*vZ6+Ksj8mdA|l_>+dEzRNBHiu^{N0U{0Y6u(pGNg0bPh5GK$7#J?07NKrcMjWA)T99p?|L&*YEqfuzE zQJyY=!;qf18)5h|(x775ch|Z!PJRQrgz;(F7a*_o?|=8Lcl}P6{8^W}t4qQgU6MwZ zksQ+{>FZML^dmi8>fI^RjV`%X4B}l~3T$jkv@<@?C2eSTyn=Vt%oL20)NPM=SC$&w z@T7=wDIoh`u)ZvzHmJQP1yR3IK3a-etc$C0oE?wcos@1?)VM70Yx0{M|M&Vb+h*Ce z*bHy~3HA3W1+yu9Oxo9Pm2O~p6WCwwAox%NyO37^$>L2?0_42Goz~dh`6O%K_bS~a zDBL7*hQe~SY`-$cWffOXB?>>fUn1hz)UjJh%zxvDA+pzH@(q1L_YT`UF7MJRDZx!0 z_sL_D$JN&J&dWSqC4~<@N><4x9!c@g+E@-Gytqx*sm*egLY~(}oINBrEyd#Qal0Nn zJdfA6Pn$FwDDmQMo99U}7I_)3zvBFHTaE#sAJqWuqAJpdv6#2{IZ*0s3r=e1yq6tj7q9IKnp293)G!)sCtzt+e-V}pWk;@hq&hl$* zgejIc*N(9g24cp}5#||W7x>D9Q1%`<7o_s7s;lc!kV;4J!D;}B5y3%Z9Fhb@n2bT>|M`q_P?%5&q_GR55fo1pFsGed zr4VC0ZF3J_il>E)rQ z@c49IPrH&fHKlw&%1KwIL&|R8x$C<)jZN>1%FwVf`b5L-5RIPhyI%LN9Sy&`E@LNV zPRz%`^@~sJV`u)*AM~fAw$a_b=uL+(bKr-gX>?!D&`sAA2h+~UYjZG_zER?P8-wx` zynQap!c*mTf2>OnzSHINYgL>)sW1DwX-wUAlYxZCYKHvlV+c?AMta3?R9jg#5M7KQnh- ISVaW@0C1E5cmMzZ literal 515 zcmV+e0{s0SiwFP!0000019ei%uG26Obss!>5x0f1Me+tI*^J_6k_F$umaT7VZX=Q= zN^%ijj~JJvIH_By_2|s$@j2u9{y+#>lGSoSmMd58@aHpGlMS9L$+DsRz;c#Cn$d`{ zM1oG^p|Pg;8S1U8x!^QX3RFCSDOWV28j>l@G^3Horfii!D)FWSq>6pEaB!C2Y9mb1 z-dsCDCk(`log>UM$gc2B2BF+NaxO^aKUX)`qac-@;G@$3j)RaO*%)C*g+}ifm(YAB)#vW~D?pS>7YES{gyQiWo z0xoxlQ(Xq|y(ynws^T1IeLU1nW7|OIlPP~fbE>;Q53~27`}?+d4oNko>1}C4|JgTf zedh%?_=4^=CesN$nyZCZ%VAf>U3&BFmu*d1&Q|QzuwNJMasbKoB;=3#{sp}fK{r7K F002A(`ZoXo diff --git a/tests/testthat/ref-TableOne_showAllLevels b/tests/testthat/ref-TableOne_showAllLevels index 192c819055adca6124a9ab7b071cf7c591c9e4d7..3b5ae81e2636af85e4b3cad18c30154339a070ec 100644 GIT binary patch literal 920 zcmV;J184jniwFP!000001Fe=zZ`3dlfV10{(jxj$iwYOy3sP39EWcy_1dhN3sp=u! zP1}flX_KPzNBFsjaW-ik+Y1zkv}=1jGnvQdB%k+_BpD`K!$C6KveP5@`<`qkdx^dJ zJBDctcsCL4WEa6jrEZtUj8KUcLn$RjV9G}A z#-Y_inxj-QEJvs(rUa!(VeW~QM5&;dx?)MOu-+*qwC|fy5Od!NIgBZ!JW;TVE$lsU~|S61;|hK zTTUTzlwsx7h}%Llzb!~YMY+Vn7lSqzPH$VJJHn5tF$!zj4k{%!d=#P~gPS1(p~-+4 z1?}SolLs-RCx8hJG-9K?^uRST0lFMq8xnxt5FO!Y4U8{Va4bZqtwAgUZ8*z7Gzqe4 zh&BQL99pksh%Rr=mS6uMz%|jlAv$B0Xyp=3_?l>divfH*+ekEt5Y5*_+a9-Dw) zY#KC;fVxYUXn~EbjdlPyvq!y0G=Siq1Ev5B(sV21eV{dn;qfE-9Y^-@!$P1T9~PEh ziRSs}YfI5^{#gF*dHxK656yck;pw=#glcCcnE!sUQmL|-rPdLt(J~fM=6mSv3g+HT zh@Pdp%4p{9QP)l=;;eY)uB4RCiW=7oBYwoc8+VHPd|dzM7xABtyYt0-zF5uT%YV{( zVxGzN5dH@3dTUb7V0f9>Z>c1CYwbOi=b$prXGH}nC#~L5quYLP%)9qQUCs)W&We1F z(rPm54$yv8=k;BM(s!c`Q61(tF~i-exQ|%9$g6Q#7cqzXx5YBA7crx1Sx$;o%xJHe z6tnyn;hkKS)6&K_DIvm(_a8o9cB&`i+r@OlRzAJDo0aoOVz0)F<+51C?auP)7reY( zRPpV@ys9HEPwG{96Sp{BPV>5$7E!b1YO$ehd(bx9mW^deS`c0JJhXyamFG#60S-!{q2|NNXNYfs& zHrpb4QWC>pDN>kwVkJ>3D5kDhQY@@@iV5xdW)#HScS3oFQmt_2iG@I^@q9OO zh(u%Ki8VwbIo6&ygLH(#%=1k_oY5dl0Zy3q#gs!jnuj$}wuWJVeyL8a5DS7X2-f5r zam>i&X74rP&t=iu|)y$liik6 zh#X~Dc{Sp;(9CZOl2B1DvGB#9&4trjz_}&+gc_r;wymI2V#7xv7BaXIG7y#wXi?BQ zZZLTeLuvwe&_E(K%1aGgBNJfD!L=a))#bZHjY*xG0ZfHQl{J2V3b?ipYTz#vVxGTwz*gBTt?qT6v~A3ZFD8S-Ia`ITs% zjlQ-N4dajHZ=d7O5ctr%vl5<;t4pYMR)YEO6)Tl0i&<(Nks2*y5oNxI&aPnY-Gt~^ zx~q(4?jCjRgd)z0XYNW$>8z-6y)fcO{JU|lxX;J+e|`b~>9{{%%;$^MEWZ3FttaN0 z?DpZW*FH@rIj;PC7fznx#&rw=U zM(qJQtm?eJt5EuGv?Z!ReiJj?uZsJK)r-6umvs?ycz9bZ^Li08s+Q%XSjCJEib*lc ze-YmBs+^WKzDWrYUcCSC@v>DNj&B#!EnE5Y>TXufBZ<8lFP6(<6}LOfr(f{$c2UK* z2YFRTTn_71c@wudT~715m=;m9bBK$I4ZYI0X ryV`?nZ$nt)u+-rRCg|!Ls#jp0{II{DFHP4){R;p9#c9D- From 3db6f03ed6f23e06024d44a374be552c9a80aa97 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 13:36:47 -0400 Subject: [PATCH 136/219] Add unit testing for gmodels::CrossTable --- test-all.txt | 369 ++++++++++++++++++++++++ tests/testthat/test-CreateTableOne.R | 12 + tests/testthat/test-svyCreateTableOne.R | 18 +- 3 files changed, 396 insertions(+), 3 deletions(-) diff --git a/test-all.txt b/test-all.txt index 663aeec..0a1d6c3 100644 --- a/test-all.txt +++ b/test-all.txt @@ -881,6 +881,295 @@ Unit tests for the CreateTableOne function : ........... St "" "2" "35 (22.2)" "32 (20.8)" "" "" "" "3" "56 (35.4)" "64 (41.6)" "" "" "" "4" "55 (34.8)" "54 (35.1)" "" "" +. Stratified by trt + 1 2 p test + n 158 154 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + status | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 0 | 83 | 85 | 168 | + | 0.051 | 0.052 | | + | 0.494 | 0.506 | 0.538 | + | 0.525 | 0.552 | | + | 0.266 | 0.272 | | +-------------|-----------|-----------|-----------| + 1 | 10 | 9 | 19 | + | 0.015 | 0.015 | | + | 0.526 | 0.474 | 0.061 | + | 0.063 | 0.058 | | + | 0.032 | 0.029 | | +-------------|-----------|-----------|-----------| + 2 | 65 | 60 | 125 | + | 0.046 | 0.047 | | + | 0.520 | 0.480 | 0.401 | + | 0.411 | 0.390 | | + | 0.208 | 0.192 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + sex | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + m | 21 | 15 | 36 | + | 0.421 | 0.432 | | + | 0.583 | 0.417 | 0.115 | + | 0.133 | 0.097 | | + | 0.067 | 0.048 | | +-------------|-----------|-----------|-----------| + f | 137 | 139 | 276 | + | 0.055 | 0.056 | | + | 0.496 | 0.504 | 0.885 | + | 0.867 | 0.903 | | + | 0.439 | 0.446 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + ascites | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 0 | 144 | 144 | 288 | + | 0.023 | 0.024 | | + | 0.500 | 0.500 | 0.923 | + | 0.911 | 0.935 | | + | 0.462 | 0.462 | | +-------------|-----------|-----------|-----------| + 1 | 14 | 10 | 24 | + | 0.280 | 0.288 | | + | 0.583 | 0.417 | 0.077 | + | 0.089 | 0.065 | | + | 0.045 | 0.032 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + hepato | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 0 | 85 | 67 | 152 | + | 0.837 | 0.859 | | + | 0.559 | 0.441 | 0.487 | + | 0.538 | 0.435 | | + | 0.272 | 0.215 | | +-------------|-----------|-----------|-----------| + 1 | 73 | 87 | 160 | + | 0.795 | 0.816 | | + | 0.456 | 0.544 | 0.513 | + | 0.462 | 0.565 | | + | 0.234 | 0.279 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + spiders | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 0 | 113 | 109 | 222 | + | 0.003 | 0.003 | | + | 0.509 | 0.491 | 0.712 | + | 0.715 | 0.708 | | + | 0.362 | 0.349 | | +-------------|-----------|-----------|-----------| + 1 | 45 | 45 | 90 | + | 0.007 | 0.007 | | + | 0.500 | 0.500 | 0.288 | + | 0.285 | 0.292 | | + | 0.144 | 0.144 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + edema | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 0 | 132 | 131 | 263 | + | 0.011 | 0.011 | | + | 0.502 | 0.498 | 0.843 | + | 0.835 | 0.851 | | + | 0.423 | 0.420 | | +-------------|-----------|-----------|-----------| + 0.5 | 16 | 13 | 29 | + | 0.118 | 0.121 | | + | 0.552 | 0.448 | 0.093 | + | 0.101 | 0.084 | | + | 0.051 | 0.042 | | +-------------|-----------|-----------|-----------| + 1 | 10 | 10 | 20 | + | 0.002 | 0.002 | | + | 0.500 | 0.500 | 0.064 | + | 0.063 | 0.065 | | + | 0.032 | 0.032 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 312 + + + | trt + stage | 1 | 2 | Row Total | +-------------|-----------|-----------|-----------| + 1 | 12 | 4 | 16 | + | 1.875 | 1.923 | | + | 0.750 | 0.250 | 0.051 | + | 0.076 | 0.026 | | + | 0.038 | 0.013 | | +-------------|-----------|-----------|-----------| + 2 | 35 | 32 | 67 | + | 0.034 | 0.035 | | + | 0.522 | 0.478 | 0.215 | + | 0.222 | 0.208 | | + | 0.112 | 0.103 | | +-------------|-----------|-----------|-----------| + 3 | 56 | 64 | 120 | + | 0.374 | 0.384 | | + | 0.467 | 0.533 | 0.385 | + | 0.354 | 0.416 | | + | 0.179 | 0.205 | | +-------------|-----------|-----------|-----------| + 4 | 55 | 54 | 109 | + | 0.001 | 0.001 | | + | 0.505 | 0.495 | 0.349 | + | 0.348 | 0.351 | | + | 0.176 | 0.173 | | +-------------|-----------|-----------|-----------| +Column Total | 158 | 154 | 312 | + | 0.506 | 0.494 | | +-------------|-----------|-----------|-----------| + + . Stratified by trt 1 2 p test n 158 154 @@ -1413,6 +1702,86 @@ Unit tests for svy* user functions : .... Stratified by E "" "1" "59.0 (39.4)" "59.0 (39.3)" "59.0 (39.3)" "" "" "C1 (%)" "0" "100.0 (66.7)" "100.0 (66.7)" "100.0 (66.7)" "1.000" "" "" "1" "50.0 (33.3)" "50.0 (33.3)" "50.0 (33.3)" "" "" +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 2:1 + n 100.0 100.0 100.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) + Stratified by E:C1 + 3:1 p test + n 50.0 + Y = 1 (%) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 50.0 (100.0) <0.001 + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 449.7292 + + + | E:C1 + Y | 1:0 | 2:0 | 3:0 | 1:1 | 2:1 | 3:1 | Row Total | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + 0 | 77 | 78 | 78 | 13 | 13 | 13 | 272 | + | 4.919 | 4.968 | 4.968 | 9.895 | 9.895 | 9.895 | | + | 0.285 | 0.286 | 0.286 | 0.048 | 0.048 | 0.048 | 0.606 | + | 0.779 | 0.780 | 0.780 | 0.260 | 0.260 | 0.260 | | + | 0.173 | 0.173 | 0.173 | 0.029 | 0.029 | 0.029 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + 1 | 22 | 22 | 22 | 37 | 37 | 37 | 177 | + | 7.580 | 7.655 | 7.655 | 15.246 | 15.246 | 15.246 | | + | 0.124 | 0.124 | 0.124 | 0.209 | 0.209 | 0.209 | 0.394 | + | 0.221 | 0.220 | 0.220 | 0.740 | 0.740 | 0.740 | | + | 0.049 | 0.049 | 0.049 | 0.082 | 0.082 | 0.082 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| +Column Total | 99 | 100 | 100 | 50 | 50 | 50 | 449 | + | 0.222 | 0.222 | 0.222 | 0.111 | 0.111 | 0.111 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + + + + + Cell Contents +|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------| + + +Total Observations in Table: 450.015 + + + | E:C1 + C1 | 1:0 | 2:0 | 3:0 | 1:1 | 2:1 | 3:1 | Row Total | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + 0 | 100 | 100 | 100 | 0 | 0 | 0 | 300 | + | 16.667 | 16.666 | 16.665 | 33.334 | 33.334 | 33.334 | | + | 0.333 | 0.333 | 0.333 | 0.000 | 0.000 | 0.000 | 0.667 | + | 1.000 | 1.000 | 1.000 | 0.000 | 0.000 | 0.000 | | + | 0.222 | 0.222 | 0.222 | 0.000 | 0.000 | 0.000 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + 1 | 0 | 0 | 0 | 50 | 50 | 50 | 150 | + | 33.336 | 33.333 | 33.332 | 66.671 | 66.671 | 66.671 | | + | 0.000 | 0.000 | 0.000 | 0.333 | 0.333 | 0.333 | 0.333 | + | 0.000 | 0.000 | 0.000 | 1.000 | 1.000 | 1.000 | | + | 0.000 | 0.000 | 0.000 | 0.111 | 0.111 | 0.111 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| +Column Total | 100 | 100 | 100 | 50 | 50 | 50 | 450 | + | 0.222 | 0.222 | 0.222 | 0.111 | 0.111 | 0.111 | | +-------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------| + + . Stratified by E 1 2 3 p test n 150.01 150.00 150.00 diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index f46524d..421d045 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -221,6 +221,18 @@ test_that("printing of a TableOne$CatTable object do not regress", { expect_equal_to_reference(print(pbcByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-CatTable_noSpaces_showAllLevels_quote") + + ## gmodels::CrossTable + print(pbcByTrt$CatTable, CrossTable = TRUE) + expect_output(print(pbcByTrt$CatTable, CrossTable = TRUE), +"|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------|") + }) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 646281c..14a8857 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -187,6 +187,18 @@ test_that("printing of a svyTableOne$CatTable object do not regress", { expect_equal_to_reference(print(mwByTrt$CatTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-svyCatTable_noSpaces_showAllLevels_quote") + + ## gmodels::CrossTable + print(mwByTrtSex$CatTable, CrossTable = TRUE) + expect_output(print(mwByTrtSex$CatTable, CrossTable = TRUE), +"|-------------------------| +| N | +| Chi-square contribution | +| N / Row Total | +| N / Col Total | +| N / Table Total | +|-------------------------|") + }) @@ -324,11 +336,11 @@ expect_equal(as.vector(print(tab1$ContTable, nonnormal = "HI_CHOL", minMax = TRU ### p-values ## t test expect_equal(print(tab1$ContTable, pDigits = 7, printToggle = TRUE)[2,3], - ## One space for < + ## One space for < pTTest) ## KW expect_equal(print(tab1$ContTable, pDigits = 7, nonnormal = "HI_CHOL", printToggle = TRUE)[2,3], - ## One space for < + ## One space for < pRankTest) }) @@ -365,7 +377,7 @@ expect_equal(print(tab1$CatTable, pDigits = 7, printToggle = TRUE)[2,3], test_that("mixed data object print outs are numerically correct", { - + ### Mixed object ## Mean and SD expect_equal(as.vector(gsub("^ *", "", print(tab1, pDigits = 7)[2,1:2])), From 3e36fadd321bebe4248122e9f1bd04108a44c12d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 13:43:29 -0400 Subject: [PATCH 137/219] Add zoo as an import package zoo::na.locf() is used in retrieving appropriate rows from CatTable --- DESCRIPTION | 1 + NAMESPACE | 1 + R/tableone-package.R | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5d2445e..f1370ce 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,6 +18,7 @@ Imports: survey, MASS, e1071, + zoo, gmodels Suggests: survival, diff --git a/NAMESPACE b/NAMESPACE index 582141b..ac23e04 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,3 +21,4 @@ import(MASS) import(e1071) import(gmodels) import(survey) +import(zoo) diff --git a/R/tableone-package.R b/R/tableone-package.R index b3f2379..2b6c452 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -5,7 +5,7 @@ ##' @name tableone-package ##' @aliases tableone-package tableone ##' @docType package -##' @import survey MASS e1071 gmodels +##' @import survey MASS e1071 zoo gmodels ##' @note Special Thanks: ##' ##' Ian Fellows for developing the Deducer package, which this package is based on. From 04b1e4f09201873a28d7f5b15a4334a987201d1d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 13:45:11 -0400 Subject: [PATCH 138/219] Add passing CRAN check --- cran-check.txt | 65 ++++ tableone.Rcheck/tableone-Ex.Rout | 488 +++++++++++++++---------------- 2 files changed, 309 insertions(+), 244 deletions(-) create mode 100644 cran-check.txt diff --git a/cran-check.txt b/cran-check.txt new file mode 100644 index 0000000..819de2f --- /dev/null +++ b/cran-check.txt @@ -0,0 +1,65 @@ +R CMD check --as-cran ./tableone_0.7.0.tar.gz +* using log directory ‘/Users/kazuki/Documents/programming/r/tableone/tableone.Rcheck’ +* using R version 3.2.1 (2015-06-18) +* using platform: x86_64-apple-darwin13.4.0 (64-bit) +* using session charset: UTF-8 +* using option ‘--as-cran’ +* checking for file ‘tableone/DESCRIPTION’ ... OK +* checking extension type ... Package +* this is package ‘tableone’ version ‘0.7.0’ +* checking CRAN incoming feasibility ... Note_to_CRAN_maintainers +Maintainer: ‘Kazuki Yoshida ’ +* checking package namespace information ... OK +* checking package dependencies ... OK +* checking if this is a source package ... OK +* checking if there is a namespace ... OK +* checking for executable files ... OK +* checking for hidden files and directories ... OK +* checking for portable file names ... OK +* checking for sufficient/correct file permissions ... OK +* checking whether package ‘tableone’ can be installed ... OK +* checking installed package size ... OK +* checking package directory ... OK +* checking ‘build’ directory ... OK +* checking DESCRIPTION meta-information ... OK +* checking top-level files ... OK +* checking for left-over files ... OK +* checking index information ... OK +* checking package subdirectories ... OK +* checking R files for non-ASCII characters ... OK +* checking R files for syntax errors ... OK +* checking whether the package can be loaded ... OK +* checking whether the package can be loaded with stated dependencies ... OK +* checking whether the package can be unloaded cleanly ... OK +* checking whether the namespace can be loaded with stated dependencies ... OK +* checking whether the namespace can be unloaded cleanly ... OK +* checking use of S3 registration ... OK +* checking dependencies in R code ... OK +* checking S3 generic/method consistency ... OK +* checking replacement functions ... OK +* checking foreign function calls ... OK +* checking R code for possible problems ... OK +* checking Rd files ... OK +* checking Rd metadata ... OK +* checking Rd line widths ... OK +* checking Rd cross-references ... OK +* checking for missing documentation entries ... OK +* checking for code/documentation mismatches ... OK +* checking Rd \usage sections ... OK +* checking Rd contents ... OK +* checking for unstated dependencies in examples ... OK +* checking installed files from ‘inst/doc’ ... OK +* checking files in ‘vignettes’ ... OK +* checking examples ... OK +* checking for unstated dependencies in ‘tests’ ... OK +* checking tests ... + OK +* checking for unstated dependencies in vignettes ... OK +* checking package vignettes in ‘inst/doc’ ... OK +* checking running R code from vignettes ... + ‘introduction.Rmd’ using ‘UTF-8’ ... OK + OK +* checking re-building of vignette outputs ... OK +* checking PDF version of manual ... OK +* DONE +Status: OK diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index fc6400e..31d6b00 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -1031,7 +1031,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", > tableOne Stratified by trt 1 2 p test - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 status (%) 0.894 0 83 (52.5) 85 (55.2) @@ -1039,7 +1039,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 edema (%) 0.877 @@ -1068,7 +1068,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", + exact = c("status","stage")) Stratified by trt 1 2 - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) status (%) 0 83 (52.5) 85 (55.2) @@ -1076,7 +1076,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) sex = f (%) 137 (86.7) 139 (90.3) - ascites = 1 (%) 14 (8.9) 10 (6.5) + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) hepato = 1 (%) 73 (46.2) 87 (56.5) spiders = 1 (%) 45 (28.5) 45 (29.2) edema (%) @@ -1473,15 +1473,15 @@ protime 0.1460939117 + exact = c("status","stage"), quote = TRUE) "Stratified by trt" "" "1" - "n" "158" + "n" " 158" "time (mean (sd))" "2015.62 (1094.12)" - "status (%)" " " + "status (%)" " " " 0" " 83 (52.5) " " 1" " 10 ( 6.3) " " 2" " 65 (41.1) " "age (mean (sd))" " 51.42 (11.01)" "sex = f (%)" " 137 (86.7) " - "ascites = 1 (%)" " 14 (8.9) " + "ascites = 1 (%)" " 14 ( 8.9) " "hepato = 1 (%)" " 73 (46.2) " "spiders = 1 (%)" " 45 (28.5) " "edema (%)" " " @@ -1497,22 +1497,22 @@ protime 0.1460939117 "trig (median [IQR])" " 106.00 [84.50, 146.00]" "platelet (mean (sd))" " 258.75 (100.32)" "protime (mean (sd))" " 10.65 (0.85)" - "stage (%)" " " + "stage (%)" " " " 1" " 12 ( 7.6) " " 2" " 35 (22.2) " " 3" " 56 (35.4) " " 4" " 55 (34.8) " "Stratified by trt" "" "2" "p" "test" - "n" "154" "" "" + "n" " 154" "" "" "time (mean (sd))" "1996.86 (1155.93)" " 0.883" "" - "status (%)" " " " 0.884" "exact" + "status (%)" " " " 0.884" "exact" " 0" " 85 (55.2) " "" "" " 1" " 9 ( 5.8) " "" "" " 2" " 60 (39.0) " "" "" "age (mean (sd))" " 48.58 (9.96)" " 0.018" "" "sex = f (%)" " 139 (90.3) " " 0.421" "" - "ascites = 1 (%)" " 10 (6.5) " " 0.567" "" + "ascites = 1 (%)" " 10 ( 6.5) " " 0.567" "" "hepato = 1 (%)" " 87 (56.5) " " 0.088" "" "spiders = 1 (%)" " 45 (29.2) " " 0.985" "" "edema (%)" " " " 0.877" "" @@ -1528,7 +1528,7 @@ protime 0.1460939117 "trig (median [IQR])" " 113.00 [84.50, 155.00]" " 0.370" "nonnorm" "platelet (mean (sd))" " 265.20 (90.73)" " 0.555" "" "protime (mean (sd))" " 10.80 (1.14)" " 0.197" "" - "stage (%)" " " " 0.205" "exact" + "stage (%)" " " " 0.205" "exact" " 1" " 4 ( 2.6) " "" "" " 2" " 32 (20.8) " "" "" " 3" " 64 (41.6) " "" "" @@ -2717,16 +2717,16 @@ detaching ‘package:survival’ > tableOne Stratified by sex:trt m:1 f:1 m:2 - n 21 137 15 + n 21 137 15 time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) 2156.33 (1428.56) status (%) 0 4 (19.0) 79 (57.7) 7 (46.7) 1 3 (14.3) 7 ( 5.1) 0 ( 0.0) 2 14 (66.7) 51 (37.2) 8 (53.3) age (mean (sd)) 55.57 (12.61) 50.78 (10.65) 57.09 (10.07) - ascites = 1 (%) 1 (4.8) 13 (9.5) 2 (13.3) + ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) 2 (13.3) hepato = 1 (%) 12 (57.1) 61 (44.5) 9 (60.0) - spiders = 1 (%) 3 (14.3) 42 (30.7) 1 (6.7) + spiders = 1 (%) 3 (14.3) 42 (30.7) 1 ( 6.7) edema (%) 0 17 (81.0) 115 (83.9) 12 (80.0) 0.5 3 (14.3) 13 ( 9.5) 1 ( 6.7) @@ -2747,14 +2747,14 @@ detaching ‘package:survival’ 4 8 (38.1) 47 (34.3) 7 (46.7) Stratified by sex:trt f:2 p test - n 139 + n 139 time (mean (sd)) 1979.65 (1127.52) 0.730 status (%) 0.033 0 78 (56.1) 1 9 ( 6.5) 2 52 (37.4) age (mean (sd)) 47.66 (9.54) <0.001 - ascites = 1 (%) 8 (5.8) 0.516 + ascites = 1 (%) 8 ( 5.8) 0.516 hepato = 1 (%) 78 (56.1) 0.208 spiders = 1 (%) 44 (31.7) 0.089 edema (%) 0.906 @@ -2784,14 +2784,14 @@ detaching ‘package:survival’ + exact = c("status","stage"), cramVars = "hepato") Stratified by sex:trt m:1 f:1 - n 21 137 + n 21 137 time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) status (%) 0 4 (19.0) 79 (57.7) 1 3 (14.3) 7 ( 5.1) 2 14 (66.7) 51 (37.2) age (mean (sd)) 55.57 (12.61) 50.78 (10.65) - ascites = 1 (%) 1 (4.8) 13 (9.5) + ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) hepato = 0/1 (%) 9/12 (42.9/57.1) 76/61 (55.5/44.5) spiders = 1 (%) 3 (14.3) 42 (30.7) edema (%) @@ -2814,16 +2814,16 @@ detaching ‘package:survival’ 4 8 (38.1) 47 (34.3) Stratified by sex:trt m:2 f:2 - n 15 139 + n 15 139 time (mean (sd)) 2156.33 (1428.56) 1979.65 (1127.52) status (%) 0 7 (46.7) 78 (56.1) 1 0 ( 0.0) 9 ( 6.5) 2 8 (53.3) 52 (37.4) age (mean (sd)) 57.09 (10.07) 47.66 (9.54) - ascites = 1 (%) 2 (13.3) 8 (5.8) + ascites = 1 (%) 2 (13.3) 8 ( 5.8) hepato = 0/1 (%) 6/9 (40.0/60.0) 61/78 (43.9/56.1) - spiders = 1 (%) 1 (6.7) 44 (31.7) + spiders = 1 (%) 1 ( 6.7) 44 (31.7) edema (%) 0 12 (80.0) 119 (85.6) 0.5 1 ( 6.7) 12 ( 8.6) @@ -3448,17 +3448,17 @@ protime 0.44433997 + exact = c("status","stage"), cramVars = "hepato", quote = TRUE) "Stratified by sex:trt" "" "m:1" - "n" "21" + "n" " 21" "time (mean (sd))" "1793.48 (1244.70)" - "status (%)" " " + "status (%)" " " " 0" " 4 (19.0) " " 1" " 3 (14.3) " " 2" " 14 (66.7) " "age (mean (sd))" " 55.57 (12.61)" - "ascites = 1 (%)" " 1 (4.8) " + "ascites = 1 (%)" " 1 ( 4.8) " "hepato = 0/1 (%)" " 9/12 (42.9/57.1) " "spiders = 1 (%)" " 3 (14.3) " - "edema (%)" " " + "edema (%)" " " " 0" " 17 (81.0) " " 0.5" " 3 (14.3) " " 1" " 1 ( 4.8) " @@ -3471,24 +3471,24 @@ protime 0.44433997 "trig (median [IQR])" " 142.00 [107.00, 194.00]" "platelet (mean (sd))" " 232.65 (97.38)" "protime (mean (sd))" " 10.84 (0.94)" - "stage (%)" " " + "stage (%)" " " " 1" " 2 ( 9.5) " " 2" " 4 (19.0) " " 3" " 7 (33.3) " " 4" " 8 (38.1) " "Stratified by sex:trt" "" "f:1" - "n" "137" + "n" " 137" "time (mean (sd))" "2049.67 (1070.20)" - "status (%)" " " + "status (%)" " " " 0" " 79 (57.7) " " 1" " 7 ( 5.1) " " 2" " 51 (37.2) " "age (mean (sd))" " 50.78 (10.65)" - "ascites = 1 (%)" " 13 (9.5) " + "ascites = 1 (%)" " 13 ( 9.5) " "hepato = 0/1 (%)" " 76/61 (55.5/44.5) " "spiders = 1 (%)" " 42 (30.7) " - "edema (%)" " " + "edema (%)" " " " 0" " 115 (83.9) " " 0.5" " 13 ( 9.5) " " 1" " 9 ( 6.6) " @@ -3501,24 +3501,24 @@ protime 0.44433997 "trig (median [IQR])" " 101.00 [84.00, 134.00]" "platelet (mean (sd))" " 262.59 (100.53)" "protime (mean (sd))" " 10.62 (0.84)" - "stage (%)" " " + "stage (%)" " " " 1" " 10 ( 7.3) " " 2" " 31 (22.6) " " 3" " 49 (35.8) " " 4" " 47 (34.3) " "Stratified by sex:trt" "" "m:2" - "n" "15" + "n" " 15" "time (mean (sd))" "2156.33 (1428.56)" - "status (%)" " " + "status (%)" " " " 0" " 7 (46.7) " " 1" " 0 ( 0.0) " " 2" " 8 (53.3) " "age (mean (sd))" " 57.09 (10.07)" "ascites = 1 (%)" " 2 (13.3) " "hepato = 0/1 (%)" " 6/9 (40.0/60.0) " - "spiders = 1 (%)" " 1 (6.7) " - "edema (%)" " " + "spiders = 1 (%)" " 1 ( 6.7) " + "edema (%)" " " " 0" " 12 (80.0) " " 0.5" " 1 ( 6.7) " " 1" " 2 (13.3) " @@ -3531,24 +3531,24 @@ protime 0.44433997 "trig (median [IQR])" " 108.50 [90.25, 137.00]" "platelet (mean (sd))" " 240.13 (73.93)" "protime (mean (sd))" " 11.23 (0.97)" - "stage (%)" " " + "stage (%)" " " " 1" " 1 ( 6.7) " " 2" " 2 (13.3) " " 3" " 5 (33.3) " " 4" " 7 (46.7) " "Stratified by sex:trt" "" "f:2" "p" "test" - "n" "139" "" "" + "n" " 139" "" "" "time (mean (sd))" "1979.65 (1127.52)" " 0.730" "" - "status (%)" " " " 0.024" "exact" + "status (%)" " " " 0.024" "exact" " 0" " 78 (56.1) " "" "" " 1" " 9 ( 6.5) " "" "" " 2" " 52 (37.4) " "" "" "age (mean (sd))" " 47.66 (9.54)" "<0.001" "" - "ascites = 1 (%)" " 8 (5.8) " " 0.516" "" + "ascites = 1 (%)" " 8 ( 5.8) " " 0.516" "" "hepato = 0/1 (%)" " 61/78 (43.9/56.1) " " 0.208" "" "spiders = 1 (%)" " 44 (31.7) " " 0.089" "" - "edema (%)" " " " 0.906" "" + "edema (%)" " " " 0.906" "" " 0" " 119 (85.6) " "" "" " 0.5" " 12 ( 8.6) " "" "" " 1" " 8 ( 5.8) " "" "" @@ -3561,7 +3561,7 @@ protime 0.44433997 "trig (median [IQR])" " 113.00 [84.00, 157.00]" " 0.058" "nonnorm" "platelet (mean (sd))" " 267.95 (92.20)" " 0.362" "" "protime (mean (sd))" " 10.75 (1.15)" " 0.137" "" - "stage (%)" " " " NA" "exact" + "stage (%)" " " " NA" "exact" " 1" " 3 ( 2.2) " "" "" " 2" " 30 (21.6) " "" "" " 3" " 59 (42.4) " "" "" @@ -3981,16 +3981,16 @@ detaching ‘package:survival’ > tableOne Stratified by sex:trt m:1 f:1 m:2 - n 21 137 15 + n 21 137 15 time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) 2156.33 (1428.56) status (%) 0 4 (19.0) 79 (57.7) 7 (46.7) 1 3 (14.3) 7 ( 5.1) 0 ( 0.0) 2 14 (66.7) 51 (37.2) 8 (53.3) age (mean (sd)) 55.57 (12.61) 50.78 (10.65) 57.09 (10.07) - ascites = 1 (%) 1 (4.8) 13 (9.5) 2 (13.3) + ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) 2 (13.3) hepato = 1 (%) 12 (57.1) 61 (44.5) 9 (60.0) - spiders = 1 (%) 3 (14.3) 42 (30.7) 1 (6.7) + spiders = 1 (%) 3 (14.3) 42 (30.7) 1 ( 6.7) edema (%) 0 17 (81.0) 115 (83.9) 12 (80.0) 0.5 3 (14.3) 13 ( 9.5) 1 ( 6.7) @@ -4011,14 +4011,14 @@ detaching ‘package:survival’ 4 8 (38.1) 47 (34.3) 7 (46.7) Stratified by sex:trt f:2 p test - n 139 + n 139 time (mean (sd)) 1979.65 (1127.52) 0.730 status (%) 0.033 0 78 (56.1) 1 9 ( 6.5) 2 52 (37.4) age (mean (sd)) 47.66 (9.54) <0.001 - ascites = 1 (%) 8 (5.8) 0.516 + ascites = 1 (%) 8 ( 5.8) 0.516 hepato = 1 (%) 78 (56.1) 0.208 spiders = 1 (%) 44 (31.7) 0.089 edema (%) 0.906 @@ -4472,60 +4472,27 @@ RIAGENDR 0.00000000 > ## Default formatted printing > tab1 Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.001 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.001 + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 > > ## nonnormal specifies variables to be shown as median [IQR] > print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) Stratified by RIAGENDR - 1 2 - n 134944553.923 141591891.998 - HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.000 [0.000, 0.000] - race (%) - 1 21381884.19 (15.84) 20251367.39 (14.30) - 2 89315751.41 (66.19) 92486945.14 (65.32) - 3 15045455.46 (11.15) 17967228.32 (12.69) - 4 9201462.86 ( 6.82) 10886351.15 ( 7.69) - agecat (%) - (0,19] 29299546.11 (21.71) 28150760.54 (19.88) - (19,39] 40497613.07 (30.01) 40640361.53 (28.70) - (39,59] 41053579.41 (30.42) 42817044.01 (30.24) - (59,Inf] 24093815.33 (17.85) 29983725.90 (21.18) - RIAGENDR = 2 (%) 0.00 (0.00) 141591892.00 (100.00) - Stratified by RIAGENDR - p test - n - HI_CHOL (median [IQR]) 0.0092 nonnorm - race (%) 0.0416 - 1 - 2 - 3 - 4 - agecat (%) 0.0012 - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) <0.0001 -> -> ## minMax changes it to median [min, max] -> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) - Stratified by RIAGENDR - 1 - n 134944553.923 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] + 1 + n 134944553.923 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] race (%) 1 21381884.19 (15.84) 2 89315751.41 (66.19) @@ -4536,53 +4503,86 @@ RIAGENDR 0.00000000 (19,39] 40497613.07 (30.01) (39,59] 41053579.41 (30.42) (59,Inf] 24093815.33 (17.85) - RIAGENDR = 2 (%) 0.00 (0.00) + RIAGENDR = 2 (%) 0.00 ( 0.00) + Stratified by RIAGENDR + 2 p test + n 141591891.998 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 +> +> ## minMax changes it to median [min, max] +> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 + n 134944553.923 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] + race (%) + 1 21381884.19 (15.84) + 2 89315751.41 (66.19) + 3 15045455.46 (11.15) + 4 9201462.86 ( 6.82) + agecat (%) + (0,19] 29299546.11 (21.71) + (19,39] 40497613.07 (30.01) + (39,59] 41053579.41 (30.42) + (59,Inf] 24093815.33 (17.85) + RIAGENDR = 2 (%) 0.00 ( 0.00) Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 (14.30) - 2 92486945.14 (65.32) - 3 17967228.32 (12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 (19.88) - (19,39] 40640361.53 (28.70) - (39,59] 42817044.01 (30.24) - (59,Inf] 29983725.90 (21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 + 2 p test + n 141591891.998 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 > > ## showAllLevels can be used tow show levels for all categorical variables > print(tab1, showAllLevels = TRUE) Stratified by RIAGENDR - level 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 1 21381884.2 (15.8) 20251367.4 (14.3) 0.042 - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) (0,19] 29299546.1 (21.7) 28150760.5 (19.9) 0.001 - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) <0.001 - 2 0.0 ( 0.0) 141591892.0 (100.0) + level 1 2 + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) + race (%) 1 21381884.2 ( 15.8) 20251367.4 ( 14.3) + 2 89315751.4 ( 66.2) 92486945.1 ( 65.3) + 3 15045455.5 ( 11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) (0,19] 29299546.1 ( 21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 ( 30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 ( 30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 ( 17.9) 29983725.9 ( 21.2) + RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) + 2 0.0 ( 0.0) 141591892.0 (100.0) Stratified by RIAGENDR - test - n - HI_CHOL (mean (sd)) - race (%) - - - - agecat (%) - - - - RIAGENDR (%) - + p test + n + HI_CHOL (mean (sd)) 0.009 + race (%) 0.042 + + + + agecat (%) 0.001 + + + + RIAGENDR (%) <0.001 + > > ## To see all printing options > ?print.TableOne @@ -4826,7 +4826,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", > tableOne Stratified by trt 1 2 p test - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 status (%) 0.894 0 83 (52.5) 85 (55.2) @@ -4834,7 +4834,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 edema (%) 0.877 @@ -4865,7 +4865,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", + exact = c("status","stage"), cramVars = "sex") Stratified by trt 1 2 - n 158 154 + n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) status (%) 0 83 (52.5) 85 (55.2) @@ -4873,7 +4873,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", 2 65 (41.1) 60 (39.0) age (mean (sd)) 51.42 (11.01) 48.58 (9.96) sex = m/f (%) 21/137 (13.3/86.7) 15/139 (9.7/90.3) - ascites = 1 (%) 14 (8.9) 10 (6.5) + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) hepato = 1 (%) 73 (46.2) 87 (56.5) spiders = 1 (%) 45 (28.5) 45 (29.2) edema (%) @@ -5270,18 +5270,18 @@ protime 0.1460939117 + exact = c("status","stage"), cramVars = "sex", quote = TRUE) "Stratified by trt" "" "1" - "n" "158" + "n" " 158" "time (mean (sd))" "2015.62 (1094.12)" - "status (%)" " " + "status (%)" " " " 0" " 83 (52.5) " " 1" " 10 ( 6.3) " " 2" " 65 (41.1) " "age (mean (sd))" " 51.42 (11.01)" "sex = m/f (%)" " 21/137 (13.3/86.7) " - "ascites = 1 (%)" " 14 (8.9) " + "ascites = 1 (%)" " 14 ( 8.9) " "hepato = 1 (%)" " 73 (46.2) " "spiders = 1 (%)" " 45 (28.5) " - "edema (%)" " " + "edema (%)" " " " 0" " 132 (83.5) " " 0.5" " 16 (10.1) " " 1" " 10 ( 6.3) " @@ -5294,25 +5294,25 @@ protime 0.1460939117 "trig (median [IQR])" " 106.00 [84.50, 146.00]" "platelet (mean (sd))" " 258.75 (100.32)" "protime (mean (sd))" " 10.65 (0.85)" - "stage (%)" " " + "stage (%)" " " " 1" " 12 ( 7.6) " " 2" " 35 (22.2) " " 3" " 56 (35.4) " " 4" " 55 (34.8) " "Stratified by trt" "" "2" "p" "test" - "n" "154" "" "" + "n" " 154" "" "" "time (mean (sd))" "1996.86 (1155.93)" " 0.883" "" - "status (%)" " " " 0.884" "exact" + "status (%)" " " " 0.884" "exact" " 0" " 85 (55.2) " "" "" " 1" " 9 ( 5.8) " "" "" " 2" " 60 (39.0) " "" "" "age (mean (sd))" " 48.58 (9.96)" " 0.018" "" "sex = m/f (%)" " 15/139 (9.7/90.3) " " 0.421" "" - "ascites = 1 (%)" " 10 (6.5) " " 0.567" "" + "ascites = 1 (%)" " 10 ( 6.5) " " 0.567" "" "hepato = 1 (%)" " 87 (56.5) " " 0.088" "" "spiders = 1 (%)" " 45 (29.2) " " 0.985" "" - "edema (%)" " " " 0.877" "" + "edema (%)" " " " 0.877" "" " 0" " 131 (85.1) " "" "" " 0.5" " 13 ( 8.4) " "" "" " 1" " 10 ( 6.5) " "" "" @@ -5325,7 +5325,7 @@ protime 0.1460939117 "trig (median [IQR])" " 113.00 [84.50, 155.00]" " 0.370" "nonnorm" "platelet (mean (sd))" " 265.20 (90.73)" " 0.555" "" "protime (mean (sd))" " 10.80 (1.14)" " 0.197" "" - "stage (%)" " " " 0.205" "exact" + "stage (%)" " " " 0.205" "exact" " 1" " 4 ( 2.6) " "" "" " 2" " 32 (20.8) " "" "" " 3" " 64 (41.6) " "" "" @@ -5496,60 +5496,27 @@ RIAGENDR 0.00000000 > ## Default formatted printing > tab1 Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.2 (15.8) 20251367.4 (14.3) - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.001 - (0,19] 29299546.1 (21.7) 28150760.5 (19.9) - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR = 2 (%) 0.0 (0.0) 141591892.0 (100.0) <0.001 + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.001 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 > > ## nonnormal specifies variables to be shown as median [IQR] > print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) Stratified by RIAGENDR - 1 2 - n 134944553.923 141591891.998 - HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.000 [0.000, 0.000] - race (%) - 1 21381884.19 (15.84) 20251367.39 (14.30) - 2 89315751.41 (66.19) 92486945.14 (65.32) - 3 15045455.46 (11.15) 17967228.32 (12.69) - 4 9201462.86 ( 6.82) 10886351.15 ( 7.69) - agecat (%) - (0,19] 29299546.11 (21.71) 28150760.54 (19.88) - (19,39] 40497613.07 (30.01) 40640361.53 (28.70) - (39,59] 41053579.41 (30.42) 42817044.01 (30.24) - (59,Inf] 24093815.33 (17.85) 29983725.90 (21.18) - RIAGENDR = 2 (%) 0.00 (0.00) 141591892.00 (100.00) - Stratified by RIAGENDR - p test - n - HI_CHOL (median [IQR]) 0.0092 nonnorm - race (%) 0.0416 - 1 - 2 - 3 - 4 - agecat (%) 0.0012 - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) <0.0001 -> -> ## minMax changes it to median [min, max] -> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) - Stratified by RIAGENDR - 1 - n 134944553.923 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] + 1 + n 134944553.923 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] race (%) 1 21381884.19 (15.84) 2 89315751.41 (66.19) @@ -5560,53 +5527,86 @@ RIAGENDR 0.00000000 (19,39] 40497613.07 (30.01) (39,59] 41053579.41 (30.42) (59,Inf] 24093815.33 (17.85) - RIAGENDR = 2 (%) 0.00 (0.00) + RIAGENDR = 2 (%) 0.00 ( 0.00) + Stratified by RIAGENDR + 2 p test + n 141591891.998 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 +> +> ## minMax changes it to median [min, max] +> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) + Stratified by RIAGENDR + 1 + n 134944553.923 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] + race (%) + 1 21381884.19 (15.84) + 2 89315751.41 (66.19) + 3 15045455.46 (11.15) + 4 9201462.86 ( 6.82) + agecat (%) + (0,19] 29299546.11 (21.71) + (19,39] 40497613.07 (30.01) + (39,59] 41053579.41 (30.42) + (59,Inf] 24093815.33 (17.85) + RIAGENDR = 2 (%) 0.00 ( 0.00) Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 (14.30) - 2 92486945.14 (65.32) - 3 17967228.32 (12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 (19.88) - (19,39] 40640361.53 (28.70) - (39,59] 42817044.01 (30.24) - (59,Inf] 29983725.90 (21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 + 2 p test + n 141591891.998 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm + race (%) 0.0416 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 > > ## showAllLevels can be used tow show levels for all categorical variables > print(tab1, showAllLevels = TRUE) Stratified by RIAGENDR - level 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 1 21381884.2 (15.8) 20251367.4 (14.3) 0.042 - 2 89315751.4 (66.2) 92486945.1 (65.3) - 3 15045455.5 (11.1) 17967228.3 (12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) (0,19] 29299546.1 (21.7) 28150760.5 (19.9) 0.001 - (19,39] 40497613.1 (30.0) 40640361.5 (28.7) - (39,59] 41053579.4 (30.4) 42817044.0 (30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 (21.2) - RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) <0.001 - 2 0.0 ( 0.0) 141591892.0 (100.0) + level 1 2 + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) + race (%) 1 21381884.2 ( 15.8) 20251367.4 ( 14.3) + 2 89315751.4 ( 66.2) 92486945.1 ( 65.3) + 3 15045455.5 ( 11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) (0,19] 29299546.1 ( 21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 ( 30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 ( 30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 ( 17.9) 29983725.9 ( 21.2) + RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) + 2 0.0 ( 0.0) 141591892.0 (100.0) Stratified by RIAGENDR - test - n - HI_CHOL (mean (sd)) - race (%) - - - - agecat (%) - - - - RIAGENDR (%) - + p test + n + HI_CHOL (mean (sd)) 0.009 + race (%) 0.042 + + + + agecat (%) 0.001 + + + + RIAGENDR (%) <0.001 + > > ## To see all printing options > ?print.TableOne @@ -5792,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 16.203 0.542 17.139 0.016 0.02 +Time elapsed: 8.622 0.207 9.343 0.01 0.009 > grDevices::dev.off() null device 1 From ffe9431306ed122910f2ba768da7066abf70a223 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 14:13:23 -0400 Subject: [PATCH 139/219] R build ignores cran-check.txt (file to save CRAN check results) --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 096149a..68d48c0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -14,3 +14,6 @@ tableone.Rcheck ## unit testing test-all.txt tests/testthat/ref-* + +## CRAN compatibility check +cran-check.txt From e3ad1fae04e1ed5eadb947730ba8ce3b3eeeaca7 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 14:52:40 -0400 Subject: [PATCH 140/219] Comment ModuleStratumSizesRow function better --- R/modules.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/modules.R b/R/modules.R index 3a9c641..ac841df 100644 --- a/R/modules.R +++ b/R/modules.R @@ -702,8 +702,7 @@ ModuleContFormatStrata <- function(ContTable, nVars, listOfFunctions, digits) { } - -## Extract vecColWidths from a stratum sample size row +## Extract stratumSizesRow from vecColWidths attribute of a FmtTable object ## Used by print.(svy)TableOne() ModuleStratumSizesRow <- function(FmtTable, showAllLevels) { From e4a5a4cac9f0e89852ab4fb709c957ed49a9d717 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 15:07:30 -0400 Subject: [PATCH 141/219] Change CreateTableOne to always return a TableOne object Even if only one type of variables are present, a TableOne object with two slots is returned --- R/CreateTableOne.R | 53 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index bc577d6..769c3a5 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -189,24 +189,20 @@ function(vars, # character vector of variab } -### If only varFactors/varNumerics are present, just call one constructor and return - +### If only varFactors/varNumerics are present, just call one constructor if (length(varNumerics) == 0) { ## No numerics - message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') - CatTable <- do.call(CreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) - return(CatTable) + ContTable <- NULL + CatTable <- do.call(CreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) } else if (length(varFactors) == 0) { ## No factors - message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') ContTable <- do.call(CreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) - return(ContTable) + CatTable <- NULL - -### Proceed if both types of variables are present (both factors and numerics) +### Both types of variables are present, call both constructors } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { ## ContTable @@ -215,21 +211,28 @@ function(vars, # character vector of variab ## CatTable CatTable <- do.call(CreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) + } else { - ## Create a list for output - TableOneObject <- list(ContTable = ContTable, - CatTable = CatTable, - MetaData = list(vars = vars, - ## describes which pos is vars is factor - logiFactors = logiFactors, - ## names of vars of each type - varFactors = varFactors, - varNumerics = varNumerics)) - - ## Give a class - class(TableOneObject) <- "TableOne" - - ## Return the object - return(TableOneObject) + ## vars never empty by data check with ModuleStopIfNoVarsLeft() + ## Just to make sure + warning("No variables left to analyzed in vars.") } + + + ## Create a list for output + ## Either one of the two tables may be NULL + TableOneObject <- list(ContTable = ContTable, + CatTable = CatTable, + MetaData = list(vars = vars, + ## describes which pos is vars is factor + logiFactors = logiFactors, + ## names of vars of each type + varFactors = varFactors, + varNumerics = varNumerics)) + + ## Give a class + class(TableOneObject) <- "TableOne" + + ## Return the object + return(TableOneObject) } From 11be9c613edbcb8c46dee10e49473a99ff639b70 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 15:59:46 -0400 Subject: [PATCH 142/219] Redesign p value examining unit tests for new TableOne object --- tests/testthat/test-CreateTableOne.R | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 421d045..6335fa8 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -97,11 +97,16 @@ test_that("P-values are returned for appropriate 2x2 xtabs, even with an empty f xtabs2 <- xtabs(~ rowVar + colVar, dat2) ## chisq.test - expect_that(attributes(tab1)$pValues["rowVar","pApprox"], equals(chisq.test(xtabs1)$p.value)) - expect_that(attributes(tab2)$pValues["rowVar","pApprox"], equals(chisq.test(xtabs2)$p.value)) + expect_that(attributes(tab1$CatTable)$pValues["rowVar","pApprox"], + equals(chisq.test(xtabs1)$p.value)) + expect_warning(expect_that(attributes(tab2$CatTable)$pValues["rowVar","pApprox"], + equals(chisq.test(xtabs2)$p.value)), + "Chi-squared approximation may be incorrect") ## fisher.test - expect_that(attributes(tab1)$pValues["rowVar","pExact"], equals(fisher.test(xtabs1)$p.value)) - expect_that(attributes(tab2)$pValues["rowVar","pExact"], equals(fisher.test(xtabs2)$p.value)) + expect_that(attributes(tab1$CatTable)$pValues["rowVar","pExact"], + equals(fisher.test(xtabs1)$p.value)) + expect_that(attributes(tab2$CatTable)$pValues["rowVar","pExact"], + equals(fisher.test(xtabs2)$p.value)) }) @@ -116,11 +121,15 @@ test_that("P-values should be NA for 1xM xtabs", { xtabs4 <- xtabs(~ rowVar + colVar, dat4) ## chisq.test - expect_that(attributes(tab3)$pValues["rowVar","pApprox"], equals(NA)) - expect_that(attributes(tab4)$pValues["rowVar","pApprox"], equals(NA)) + expect_that(attributes(tab3$CatTable)$pValues["rowVar","pApprox"], + equals(NA)) + expect_that(attributes(tab4$CatTable)$pValues["rowVar","pApprox"], + equals(NA)) ## fisher.test - expect_that(attributes(tab3)$pValues["rowVar","pExact"], equals(NA)) - expect_that(attributes(tab4)$pValues["rowVar","pExact"], equals(NA)) + expect_that(attributes(tab3$CatTable)$pValues["rowVar","pExact"], + equals(NA)) + expect_that(attributes(tab4$CatTable)$pValues["rowVar","pExact"], + equals(NA)) }) From 776bd65b916bb0991486d9d1c407caf34afafc51 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 16:08:24 -0400 Subject: [PATCH 143/219] Change print.TableOne and related modules to handle partial NULL TableOne A TableOne object with only one of ContTable or CatTable can be handled correctly. --- R/modules.R | 31 ++++++++++++++++++++------- R/print.TableOne.R | 14 +++++++++--- test-all.txt | 21 ++++++++++++++++++ tests/testthat/ref-TableOne_CatOnly | Bin 0 -> 347 bytes tests/testthat/ref-TableOne_ContOnly | Bin 0 -> 345 bytes tests/testthat/test-CreateTableOne.R | 13 ++++++++++- 6 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/testthat/ref-TableOne_CatOnly create mode 100644 tests/testthat/ref-TableOne_ContOnly diff --git a/R/modules.R b/R/modules.R index ac841df..ecef309 100644 --- a/R/modules.R +++ b/R/modules.R @@ -817,7 +817,13 @@ ModuleFormatTables <- function(x, catDigits, contDigits, ## Two-element list(ContTable, CatTable) ## Cont first throughout this function - TableOne <- list(x$ContTable, x$CatTable) + TableOne <- list(ContTable = x$ContTable, + CatTable = x$CatTable) + ## Drop NULL element + TableOne <- TableOne[!sapply(TableOne, is.null)] + if (length(TableOne) == 0) { + warning("This object does not have valid ContTable or CatTable") + } ## Get the Cont/Cat status (1st of classes) ## Always (ContTable, CatTable) by new definition @@ -859,7 +865,7 @@ ModuleFormatTables <- function(x, catDigits, contDigits, }, simplify = FALSE) ## Name formatted tables for easier access (Cont first!) - names(FmtTables) <- c("FmtContTable", "FmtCatTable") + names(FmtTables) <- paste0("Fmt", names(TableOne)) FmtTables } @@ -867,15 +873,24 @@ ModuleFormatTables <- function(x, catDigits, contDigits, ## Obtain a vector indictor showing n-th variable's ## correspondence row(s) in FmtCatTable -ModuleVarToRowFmtCatTable <- function(spaceFmtEltTables) { +ModuleVarToRowFmtCatTable <- function(spcFmtEltTables) { + + ## If no categorical elements, return NULL + if (!("FmtCatTable" %in% names(spcFmtEltTables))) { + return(NULL) + } + ## Extract logical vector of which rows are title rows - logiNameRows <- attr(spaceFmtEltTables$FmtCatTable, "logiNameRows") + logiNameRows <- attr(spcFmtEltTables$FmtCatTable, "logiNameRows") + ## Create a numeric representation of which row(s) belong to which variable numNameRows <- as.numeric(logiNameRows) numNameRows[logiNameRows] <- seq_len(sum(logiNameRows)) numNameRows[!logiNameRows] <- NA + ## LOCF for subheaders (some variables have multiple rows) numNameRows <- zoo::na.locf(numNameRows, na.rm = FALSE) + ## First element is always sample size and should be 0 to avoid NA, ## which breaks == use numNameRows[1] <- 0 @@ -884,11 +899,11 @@ ModuleVarToRowFmtCatTable <- function(spaceFmtEltTables) { ## Create a list of one variable tables excluding sample size row -ModuleListOfOneVarTables <- function(spaceFmtEltTables, MetaData) { +ModuleListOfOneVarTables <- function(spcFmtEltTables, MetaData) { ## Obtain a vector indictor showing n-th variable's ## correspondence row(s) in FmtCatTable - vecVarToRow <- ModuleVarToRowFmtCatTable(spaceFmtEltTables) + vecVarToRow <- ModuleVarToRowFmtCatTable(spcFmtEltTables) ## Pick elements and construct a list of rows to rbind ## loop over vars picking elements from appropriate objects @@ -904,14 +919,14 @@ ModuleListOfOneVarTables <- function(spaceFmtEltTables, MetaData) { nthElt <- which(var == MetaData$varFactors) rowsToPick <- which(nthElt == vecVarToRow) - spaceFmtEltTables$FmtCatTable[rowsToPick, , drop = FALSE] + spcFmtEltTables$FmtCatTable[rowsToPick, , drop = FALSE] } else { ## If Cont nthElt <- which(var == MetaData$varNumerics) ## + 1 because of sample size row - spaceFmtEltTables$FmtContTable[nthElt + 1, , drop = FALSE] + spcFmtEltTables$FmtContTable[nthElt + 1, , drop = FALSE] } }) lstOneVarTables diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 5e47db9..3b0ab22 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -159,16 +159,24 @@ function(x, # TableOne object c(lstStratumSizesRow, lstOneVarTables)) - ## Add stratification information to the column header (This is also in the constructor) - if (length(x$ContTable) > 1 ) { + ## Add stratification information to the column header + ## NULL element has a length of zero + if (length(x$ContTable) > 1) { ## Combine variable names with : in between strataVarName <- attributes(x$ContTable)$strataVarName - ## Create strata string strataString <- paste0("Stratified by ", strataVarName) + ## Name the row dimension with it. 1st dimension name should be empty. + names(dimnames(out)) <- c("", strataString) + } else if (length(x$CatTable) > 1) { + ## Combine variable names with : in between + strataVarName <- attributes(x$CatTable)$strataVarName + ## Create strata string + strataString <- paste0("Stratified by ", strataVarName) ## Name the row dimension with it. 1st dimension name should be empty. names(dimnames(out)) <- c("", strataString) + } else { names(dimnames(out)) <- c("", "") diff --git a/test-all.txt b/test-all.txt index 0a1d6c3..5b61800 100644 --- a/test-all.txt +++ b/test-all.txt @@ -569,6 +569,27 @@ Unit tests for the CreateTableOne function : ........... St " 2" "32 (20.8)" "" "" " 3" "64 (41.6)" "" "" " 4" "54 (35.1)" "" "" +. Stratified by trt:sex + 1:m 2:m 1:f + n 21 15 137 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) + Stratified by trt:sex + 2:f p test + n 139 + time (mean (sd)) 1979.65 (1127.52) 0.730 + age (mean (sd)) 47.66 (9.54) <0.001 + protime (mean (sd)) 10.75 (1.15) 0.137 +. Stratified by trt:sex + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + status (%) 0.033 + 0 4 (19.0) 7 ( 46.7) 79 ( 57.7) 78 ( 56.1) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) + 2 14 (66.7) 8 ( 53.3) 51 ( 37.2) 52 ( 37.4) + trt = 2 (%) 0 ( 0.0) 15 (100.0) 0 ( 0.0) 139 (100.0) <0.001 + sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) 139 (100.0) <0.001 . Stratified by trt 1 2 p test n 158 154 diff --git a/tests/testthat/ref-TableOne_CatOnly b/tests/testthat/ref-TableOne_CatOnly new file mode 100644 index 0000000000000000000000000000000000000000..af9d7318b2bccbeb8d52fb445593eee8ac641961 GIT binary patch literal 347 zcmV-h0i^yPiwFP!0000019g&3PlPZKhRcVj3nrTw?{hI>JrGLyScv`#FJ3VV2?sW2 zsfqr1B~EPrXL?0LWoTq+ak6j(k%`z#3lD)lF%t5Q`|rbAuXeL2WN$$ zl16M+D0=cdDl|_FA;gO+Q?Y4guzV=clj;lkvTRZ3!ycuKX$|-^!@xOIc z&uHK^{~jQG-c5=Ncm-NcwLDRefuA_ML86uUL-T`DE2Rh1t0XwX)CH(OxzJCmUe6^+n001LnokIWs literal 0 HcmV?d00001 diff --git a/tests/testthat/ref-TableOne_ContOnly b/tests/testthat/ref-TableOne_ContOnly new file mode 100644 index 0000000000000000000000000000000000000000..3dba0ae265604e7166a04c6235c2367ca7468450 GIT binary patch literal 345 zcmV-f0jB;RiwFP!0000019g#2PlG@Zh8J4vN21m=CLZ@lFO!{RKcMknc=3uUH5{l- z*@OOh<1Ae$ppvjNyYD*>Gt27@V=QK~IAZb4r%PI%*qmKcyyX6o7`6{+^AuFZ6O>AU z73(0}bFMXL>jf~_9p7<|0y4!D0l8X_pr|{jL~S5VsaDAhv>8Gzh@1og!VaMbGHs!D z1jW?$P@!@#z9C@+$Wf;PY}P`J9(QV_hh}O5&HM3lOHfUCQ^7S+>;eD)@ZO;? literal 0 HcmV?d00001 diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 6335fa8..7e9c6a4 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -30,7 +30,8 @@ vars <- c("time","status","age","sex","ascites","hepato", "spiders","edema","bili","chol","albumin", "copper","alk.phos","ast","trig","platelet", "protime","stage") - +varsContOnly <- c("time","age","protime") +varsCatOnly <- c("status","trt","sex") ### Tests for data checkers @@ -142,6 +143,9 @@ pbcOverall <- CreateTableOne(vars = vars, data = pbc) pbcInclNa <- CreateTableOne(vars = vars, data = pbc, includeNA = TRUE) pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) pbcByTrtSex <- CreateTableOne(vars = vars, strata = c("trt","sex"), data = pbc) +pbcContByTrtSex <- CreateTableOne(vars = varsContOnly, strata = c("trt","sex"), data = pbc) +pbcCatByTrtSex <- CreateTableOne(vars = varsCatOnly, strata = c("trt","sex"), data = pbc) + ## Specify variables for special handling nonnormalVars <- c("bili","chol","copper","alk.phos","trig") @@ -183,6 +187,13 @@ test_that("printing of a TableOne object does not regress", { expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = TRUE), "ref-TableOne_noSpaces_showAllLevels_quote") + + expect_equal_to_reference(print(pbcContByTrtSex), + "ref-TableOne_ContOnly") + + expect_equal_to_reference(print(pbcCatByTrtSex), + "ref-TableOne_CatOnly") + }) From 6e61a5ee7ce2fc6acfa07d24582c4b0e124982a0 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 16:28:15 -0400 Subject: [PATCH 144/219] Change svyCreateTableOne to always create svyTableOne object Even if only continuous or categorical variables are given, svyTableOne object is always returned. --- R/svyCreateTableOne.R | 51 +++++++------- cran-check.txt | 1 + tableone.Rcheck/tableone-Ex.Rout | 2 +- test-all.txt | 20 ++++++ tests/testthat/ref-svyTableOne_CatOnly | Bin 0 -> 240 bytes tests/testthat/ref-svyTableOne_ContOnly | Bin 0 -> 250 bytes tests/testthat/test-svyCreateTableOne.R | 86 +++++++++++++----------- 7 files changed, 97 insertions(+), 63 deletions(-) create mode 100644 tests/testthat/ref-svyTableOne_CatOnly create mode 100644 tests/testthat/ref-svyTableOne_ContOnly diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index e2b6985..54ee570 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -170,22 +170,20 @@ function(vars, # character vector of variable } -### If only varFactors/varNumerics are present, just call one constructor and return +### If only varFactors/varNumerics are present, just call one constructor if (length(varNumerics) == 0) { ## No numerics - message('NOTE: no numeric/integer variables supplied, using CreateCatTable()\n') - CatTable <- do.call(svyCreateCatTable, - args = c(list(vars = varFactors), argsCreateCatTable)) - return(CatTable) + ContTable <- NULL + CatTable <- do.call(svyCreateCatTable, + args = c(list(vars = varFactors), argsCreateCatTable)) } else if (length(varFactors) == 0) { ## No factors - message('NOTE: no factor/logical/character variables supplied, using CreateContTable()\n') ContTable <- do.call(svyCreateContTable, args = c(list(vars = varNumerics), argsCreateContTable)) - return(ContTable) + CatTable <- NULL -### Proceed if both types of variables are present (both factors and numerics) +### Both types of variables are present, call both constructors } else if ((length(varFactors) > 0) & (length(varNumerics) > 0)) { ## ContTable @@ -194,21 +192,28 @@ function(vars, # character vector of variable ## CatTable CatTable <- do.call(svyCreateCatTable, args = c(list(vars = varFactors), argsCreateCatTable)) + } else { - ## Create a list for output - TableOneObject <- list(ContTable = ContTable, - CatTable = CatTable, - MetaData = list(vars = vars, - ## describes which pos is vars is factor - logiFactors = logiFactors, - ## names of vars of each type - varFactors = varFactors, - varNumerics = varNumerics)) - - ## Give a class - class(TableOneObject) <- c("svyTableOne", "TableOne") - - ## Return the object - return(TableOneObject) + ## vars never empty by data check with ModuleStopIfNoVarsLeft() + ## Just to make sure + warning("No variables left to analyzed in vars.") } + + + ## Create a list for output + ## Either one of the two tables may be NULL + TableOneObject <- list(ContTable = ContTable, + CatTable = CatTable, + MetaData = list(vars = vars, + ## describes which pos is vars is factor + logiFactors = logiFactors, + ## names of vars of each type + varFactors = varFactors, + varNumerics = varNumerics)) + + ## Give a class + class(TableOneObject) <- c("svyTableOne", "TableOne") + + ## Return the object + return(TableOneObject) } diff --git a/cran-check.txt b/cran-check.txt index 819de2f..d3b965d 100644 --- a/cran-check.txt +++ b/cran-check.txt @@ -1,3 +1,4 @@ +Rscript -e "library(methods); library(roxygen2); roxygenize('.')" R CMD check --as-cran ./tableone_0.7.0.tar.gz * using log directory ‘/Users/kazuki/Documents/programming/r/tableone/tableone.Rcheck’ * using R version 3.2.1 (2015-06-18) diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 31d6b00..66ca54e 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -5792,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 8.622 0.207 9.343 0.01 0.009 +Time elapsed: 8.89 0.258 10.448 0.01 0.012 > grDevices::dev.off() null device 1 diff --git a/test-all.txt b/test-all.txt index 5b61800..de9e20b 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1621,6 +1621,26 @@ Unit tests for svy* user functions : .... Stratified by E "Y = 1 (%)" "59.000 (39.333)" "NA" "exact" "C1 = 1 (%)" "50.000 (33.333)" "1.000" "" "C2 (mean (sd))" "0.47 (0.50)" "1.000" "" +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 + n 100.01 100.00 100.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) + Stratified by E:C1 + 2:1 3:1 p test + n 50.00 50.00 + E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 +. Stratified by E:C1 + 1:0 2:0 3:0 1:1 + n 100.0 100.0 100.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) + Stratified by E:C1 + 2:1 3:1 p test + n 50.0 50.0 + Y = 1 (%) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 . Stratified by E 1 2 3 p test n 150.0 150.0 150.0 diff --git a/tests/testthat/ref-svyTableOne_CatOnly b/tests/testthat/ref-svyTableOne_CatOnly new file mode 100644 index 0000000000000000000000000000000000000000..d304ac56e45fd9f81d5f538a489eecdd9ba1c533 GIT binary patch literal 240 zcmV$TMoy1?@qGQDh9Td?n z{&_KXy|z+y6o*S*Uf#Qp+|~yG0k*I}*b4SJjKBepbBCl1r73zCMWMuiBTcX-Q7Tf! zn*3&yKe0LU7uPh_{do53nroBZ{Vy&sxw~Li(#HzkGB|>RWorA7pVa>Px47ixwj?e~ z&gm(;v1Dj;eXT9~*4Y4Whf5?3#uG#ME2^2&<5tH~QoYxX8aQnrCDaJ05meB+RI@9x qThY35$J|$+DOw{KY>I1IoB5jK9Fe6$2&=5F;%9 zdE)`CRltNew0-w@uYGr%#{j^z5QSI@l+~1TTnfQm;)M4}ZYy%V z^S*pSOZ-25tA4)0=EFAWNI9XK{MsabnA#D0nA-WeOrYA^mrCrcpml=9XftGOMoC(> zU;QmAY1s{lO_D53 Date: Fri, 31 Jul 2015 16:38:14 -0400 Subject: [PATCH 145/219] Add unit tests to confirm cont/cat only data give (svy)TableOne --- test-all.txt | 4 ++-- tests/testthat/test-CreateTableOne.R | 20 ++++++++++++++++---- tests/testthat/test-svyCreateTableOne.R | 12 ++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/test-all.txt b/test-all.txt index de9e20b..0d2863e 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1,5 +1,5 @@ Rscript -e "devtools::test()" -Unit tests for the CreateTableOne function : ........... Stratified by trt +Unit tests for the CreateTableOne function : ................. Stratified by trt 1 2 p test n 158 154 time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 @@ -1478,7 +1478,7 @@ agecat 0.702331 0.9040822 0.109801 0.985333 0.8536402 0.3838583 0.9772713 (39,59] (59,Inf] . -Unit tests for svy* user functions : .... Stratified by E +Unit tests for svy* user functions : .......... Stratified by E 1 2 3 p test n 150.01 150.00 150.00 E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 7e9c6a4..ea57a88 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -143,8 +143,8 @@ pbcOverall <- CreateTableOne(vars = vars, data = pbc) pbcInclNa <- CreateTableOne(vars = vars, data = pbc, includeNA = TRUE) pbcByTrt <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc) pbcByTrtSex <- CreateTableOne(vars = vars, strata = c("trt","sex"), data = pbc) -pbcContByTrtSex <- CreateTableOne(vars = varsContOnly, strata = c("trt","sex"), data = pbc) -pbcCatByTrtSex <- CreateTableOne(vars = varsCatOnly, strata = c("trt","sex"), data = pbc) +pbcContOnlyByTrtSex <- CreateTableOne(vars = varsContOnly, strata = c("trt","sex"), data = pbc) +pbcCatOnlyByTrtSex <- CreateTableOne(vars = varsCatOnly, strata = c("trt","sex"), data = pbc) ## Specify variables for special handling @@ -152,6 +152,18 @@ nonnormalVars <- c("bili","chol","copper","alk.phos","trig") exactVars <- c("status","stage") +test_that("TableOne objects are always returned", { + + expect_equal(class(pbcOverall), "TableOne") + expect_equal(class(pbcInclNa), "TableOne") + expect_equal(class(pbcByTrt), "TableOne") + expect_equal(class(pbcByTrtSex), "TableOne") + expect_equal(class(pbcContOnlyByTrtSex), "TableOne") + expect_equal(class(pbcCatOnlyByTrtSex), "TableOne") + +}) + + test_that("printing of a TableOne object does not regress", { ## Expectations @@ -188,10 +200,10 @@ test_that("printing of a TableOne object does not regress", { expect_equal_to_reference(print(pbcByTrt, nonnormal = nonnormalVars, exact = exactVars, noSpaces = TRUE, showAllLevels = FALSE, quote = TRUE, printToggle = TRUE), "ref-TableOne_noSpaces_showAllLevels_quote") - expect_equal_to_reference(print(pbcContByTrtSex), + expect_equal_to_reference(print(pbcContOnlyByTrtSex), "ref-TableOne_ContOnly") - expect_equal_to_reference(print(pbcCatByTrtSex), + expect_equal_to_reference(print(pbcCatOnlyByTrtSex), "ref-TableOne_CatOnly") }) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 94bcf35..4fe4836 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -106,6 +106,18 @@ nonnormalVars <- c("C") exactVars <- c("Y") +test_that("svyTableOne objects are always returned", { + + expect_equal(class(mwOverall), c("svyTableOne","TableOne")) + expect_equal(class(mwInclNa), c("svyTableOne","TableOne")) + expect_equal(class(mwByE), c("svyTableOne","TableOne")) + expect_equal(class(mwByEC1), c("svyTableOne","TableOne")) + expect_equal(class(mwContOnlyByEC1), c("svyTableOne","TableOne")) + expect_equal(class(mwCatOnlyByEC1), c("svyTableOne","TableOne")) + +}) + + test_that("printing of a svyTableOne object does not regress", { ## Expectations From 9949b176522df9d430d2c3ff471bfb374abf62fa Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 17:08:58 -0400 Subject: [PATCH 146/219] Add simple expectations for summary methods --- test-all.txt | 4 ++-- tests/testthat/test-CreateTableOne.R | 17 +++++++++++++++++ tests/testthat/test-svyCreateTableOne.R | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/test-all.txt b/test-all.txt index 0d2863e..bdf174c 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1373,7 +1373,7 @@ Column Total | 158 | 154 | 312 | "trig (mean (sd))" "124.14 (71.54)" "125.25 (58.52)" "0.886" "" "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" -. +....... Unit tests for the modules : ........ Tests for functions for standardized mean differences : ................................................................................... ### Summary of continuous variables ### @@ -2117,7 +2117,7 @@ Column Total | 100 | 100 | 100 | 50 | 50 | (39,59] (59,Inf] RIAGENDR = 2 (%) <0.0000001 -. +....... Unit tests for the survey-related modules : ................................................ DONE diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index ea57a88..563e63b 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -301,3 +301,20 @@ test_that("printing of a TableOne$ContTable object do not regress", { expect_equal_to_reference(print(pbcByTrt$ContTable, noSpaces = TRUE, showAllLevels = TRUE, quote = TRUE, printToggle = TRUE), "ref-ContTable_noSpaces_showAllLevels_quote") }) + + +test_that("summary method works without errors", { + + ## Expectations + expect_output(summary(pbcOverall), + "time 418 0 0.0 1918 1104.7 1730 1092.8 2614 41.0 4795 0.47 -0.5") + expect_output(summary(pbcInclNa), " 6 1.4 100.0") + expect_output(summary(pbcByTrt), "hepato 0.20699413") + expect_output(summary(pbcByTrtSex), + "Standardize mean differences") + expect_output(summary(pbcContOnlyByTrtSex), + "### Summary of continuous variables ###") + expect_output(summary(pbcCatOnlyByTrtSex), + "status 0.5770647 0.7964473 0.8748771 0.8309763 0.4375075 0.4621432 0.06043662") + +}) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index 4fe4836..d45188e 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -418,3 +418,20 @@ expect_equal(print(tab1, pDigits = 7, nonnormal = "HI_CHOL")[3,3], pChisq) }) + + +test_that("summary method works without errors", { + + ## Expectations + expect_output(summary(mwOverall), + "n miss p.miss mean sd median p25 p75 min max") + expect_output(summary(mwInclNa), " 0.3 0.1 100.0") + expect_output(summary(mwByE), "Y 0.00099495892 0.00149243839 0.00148861716 0.000003821227") + expect_output(summary(mwByEC1), + "Standardize mean differences") + expect_output(summary(mwContOnlyByEC1), + "Standardize mean differences") + expect_output(summary(mwCatOnlyByEC1), + "Standardize mean differences") + +}) From 3bcb021731c889a38cf747f50ac76a185c6895e9 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 17:10:01 -0400 Subject: [PATCH 147/219] Make summary method to show valid element only; tests include outputs --- R/summary.TableOne.R | 45 +- test-all.txt | 970 +++++++++++++++++++++++- tests/testthat/test-CreateTableOne.R | 6 + tests/testthat/test-svyCreateTableOne.R | 6 + 4 files changed, 1009 insertions(+), 18 deletions(-) diff --git a/R/summary.TableOne.R b/R/summary.TableOne.R index 6dcfed6..44e560e 100644 --- a/R/summary.TableOne.R +++ b/R/summary.TableOne.R @@ -1,12 +1,11 @@ -##' Shows all results in a \code{TableOne} class object +##' Shows all results in a \code{(svy)TableOne} class object ##' -##' This method shows all the data a CatTable class object has. This includes -##' the (optionally stratified) part with summary statistics and p-values from -##' the approximation method test (chisq.test by default) and exact method test -##' (fisher.test by default). +##' This method shows all the data a \code{(svy)TableOne} class object has. This +##' includes the (optionally stratified) part with summary statistics and p-values +##' and/or standardized mean differences. ##' ##' -##' @param object An object that has the \code{CatTable} class to be shown. +##' @param object An object that has the \code{(svy)TableOne} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. ##' @return It will print the results. @@ -46,17 +45,31 @@ ##' @export summary.TableOne <- function(object, digits = 1, ...) { - ## object and ... required to be consistent with generic summary(object, ...) - listCatContTables <- object - ## Continuous - cat("\n ### Summary of continuous variables ###\n\n") - summary(listCatContTables$ContTable, digits = digits) + if (!is.null(object$ContTable)) { + cat("\n ### Summary of continuous variables ###\n\n") + summary(object$ContTable, digits = digits) + } ## Separator - cat("\n=======================================================================================\n") - - ## Categorical - cat("\n ### Summary of categorical variables ### \n\n") - summary(listCatContTables$CatTable, digits = digits) + if ((!is.null(object$ContTable)) & !is.null(object$CatTable)) { + cat("\n=======================================================================================\n") + } + + ## Categorical + if (!is.null(object$CatTable)) { + cat("\n ### Summary of categorical variables ### \n\n") + summary(object$CatTable, digits = digits) + } } + + + + + + + + + + + diff --git a/test-all.txt b/test-all.txt index bdf174c..2a4537f 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1373,7 +1373,611 @@ Column Total | 158 | 154 | 312 | "trig (mean (sd))" "124.14 (71.54)" "125.25 (58.52)" "0.886" "" "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" -....... +. + ### Summary of continuous variables ### + +strata: Overall + n miss p.miss mean sd median p25 p75 min max skew kurt +time 418 0 0.0 1918 1104.7 1730 1092.8 2614 41.0 4795 0.47 -0.5 +age 418 0 0.0 51 10.4 51 42.8 58 26.3 78 0.09 -0.6 +bili 418 0 0.0 3 4.4 1 0.8 3 0.3 28 2.72 8.1 +chol 418 134 32.1 370 231.9 310 249.5 400 120.0 1775 3.41 14.3 +albumin 418 0 0.0 3 0.4 4 3.2 4 2.0 5 -0.47 0.6 +copper 418 108 25.8 98 85.6 73 41.2 123 4.0 588 2.30 7.6 +alk.phos 418 106 25.4 1983 2140.4 1259 871.5 1980 289.0 13862 2.99 9.7 +ast 418 106 25.4 123 56.7 115 80.6 152 26.4 457 1.45 4.3 +trig 418 136 32.5 125 65.1 108 84.2 151 33.0 598 2.52 11.8 +platelet 418 11 2.6 257 98.3 251 188.5 318 62.0 721 0.63 0.9 +protime 418 2 0.5 11 1.0 11 10.0 11 9.0 18 2.22 10.0 + +======================================================================================= + + ### Summary of categorical variables ### + +strata: Overall + var n miss p.miss level freq percent cum.percent + status 418 0 0.0 0 232 55.5 55.5 + 1 25 6.0 61.5 + 2 161 38.5 100.0 + + sex 418 0 0.0 m 44 10.5 10.5 + f 374 89.5 100.0 + + ascites 418 106 25.4 0 288 92.3 92.3 + 1 24 7.7 100.0 + + hepato 418 106 25.4 0 152 48.7 48.7 + 1 160 51.3 100.0 + + spiders 418 106 25.4 0 222 71.2 71.2 + 1 90 28.8 100.0 + + edema 418 0 0.0 0 354 84.7 84.7 + 0.5 44 10.5 95.2 + 1 20 4.8 100.0 + + stage 418 6 1.4 1 21 5.1 5.1 + 2 92 22.3 27.4 + 3 155 37.6 65.0 + 4 144 35.0 100.0 + +. + ### Summary of continuous variables ### + +strata: Overall + n miss p.miss mean sd median p25 p75 min max skew kurt +time 418 0 0.0 1918 1104.7 1730 1092.8 2614 41.0 4795 0.47 -0.5 +age 418 0 0.0 51 10.4 51 42.8 58 26.3 78 0.09 -0.6 +bili 418 0 0.0 3 4.4 1 0.8 3 0.3 28 2.72 8.1 +chol 418 134 32.1 370 231.9 310 249.5 400 120.0 1775 3.41 14.3 +albumin 418 0 0.0 3 0.4 4 3.2 4 2.0 5 -0.47 0.6 +copper 418 108 25.8 98 85.6 73 41.2 123 4.0 588 2.30 7.6 +alk.phos 418 106 25.4 1983 2140.4 1259 871.5 1980 289.0 13862 2.99 9.7 +ast 418 106 25.4 123 56.7 115 80.6 152 26.4 457 1.45 4.3 +trig 418 136 32.5 125 65.1 108 84.2 151 33.0 598 2.52 11.8 +platelet 418 11 2.6 257 98.3 251 188.5 318 62.0 721 0.63 0.9 +protime 418 2 0.5 11 1.0 11 10.0 11 9.0 18 2.22 10.0 + +======================================================================================= + + ### Summary of categorical variables ### + +strata: Overall + var n miss p.miss level freq percent cum.percent + status 418 0 0.0 0 232 55.5 55.5 + 1 25 6.0 61.5 + 2 161 38.5 100.0 + + sex 418 0 0.0 m 44 10.5 10.5 + f 374 89.5 100.0 + + ascites 418 0 0.0 0 288 68.9 68.9 + 1 24 5.7 74.6 + 106 25.4 100.0 + + hepato 418 0 0.0 0 152 36.4 36.4 + 1 160 38.3 74.6 + 106 25.4 100.0 + + spiders 418 0 0.0 0 222 53.1 53.1 + 1 90 21.5 74.6 + 106 25.4 100.0 + + edema 418 0 0.0 0 354 84.7 84.7 + 0.5 44 10.5 95.2 + 1 20 4.8 100.0 + + stage 418 0 0.0 1 21 5.0 5.0 + 2 92 22.0 27.0 + 3 155 37.1 64.1 + 4 144 34.4 98.6 + 6 1.4 100.0 + +. + ### Summary of continuous variables ### + +trt: 1 + n miss p.miss mean sd median p25 p75 min max skew kurt +time 158 0 0.0 2016 1094.1 1895 1231.0 2632 41.0 4556 0.41 -0.4 +age 158 0 0.0 51 11.0 52 43.0 59 26.3 78 0.06 -0.5 +bili 158 0 0.0 3 3.6 1 0.8 3 0.3 20 2.67 7.6 +chol 158 18 11.4 365 209.5 316 247.8 417 127.0 1712 3.83 20.2 +albumin 158 0 0.0 4 0.4 4 3.2 4 2.1 5 -0.40 0.3 +copper 158 1 0.6 98 90.6 73 40.0 121 9.0 588 2.50 8.2 +alk.phos 158 0 0.0 2021 2183.4 1214 840.8 2028 369.0 11552 2.71 7.4 +ast 158 0 0.0 120 54.5 112 76.7 152 26.4 338 1.09 1.6 +trig 158 19 12.0 124 71.5 106 84.5 146 33.0 598 2.95 14.3 +platelet 158 2 1.3 259 100.3 255 189.5 322 62.0 563 0.50 0.2 +protime 158 0 0.0 11 0.9 11 10.0 11 9.0 14 1.10 1.6 +------------------------------------------------------------ +trt: 2 + n miss p.miss mean sd median p25 p75 min max skew kurt +time 154 0 0.0 1997 1155.9 1811 1153.0 2771 51.0 4523 0.4 -0.7 +age 154 0 0.0 49 10.0 48 41.4 56 30.6 75 0.2 -0.5 +bili 154 0 0.0 4 5.3 1 0.7 4 0.3 28 2.7 7.3 +chol 154 10 6.5 374 252.5 304 254.2 377 120.0 1775 3.1 11.1 +albumin 154 0 0.0 4 0.4 4 3.3 4 2.0 4 -0.8 2.0 +copper 154 1 0.6 98 80.5 73 43.0 139 4.0 558 2.0 6.6 +alk.phos 154 0 0.0 1943 2101.7 1283 922.5 1950 289.0 13862 3.3 12.8 +ast 154 0 0.0 125 58.9 117 83.8 152 28.4 457 1.7 6.3 +trig 154 11 7.1 125 58.5 113 84.5 155 44.0 432 1.7 5.5 +platelet 154 2 1.3 265 90.7 260 206.8 322 71.0 487 0.2 -0.3 +protime 154 0 0.0 11 1.1 11 10.0 11 9.2 17 1.9 6.4 + +p-values + pNormal pNonNormal +time 0.88304691 0.82661809 +age 0.01767247 0.01962155 +bili 0.13093942 0.84168460 +chol 0.74799072 0.54433899 +albumin 0.87388074 0.95045176 +copper 0.99915849 0.71745444 +alk.phos 0.74726165 0.81198200 +ast 0.45969842 0.45892358 +trig 0.88604213 0.36980434 +platelet 0.55451136 0.45482564 +protime 0.19714026 0.58802048 + +Standardize mean differences + 1 vs 2 +time 0.0166658751 +age 0.2702619258 +bili 0.1710905651 +chol 0.0382210537 +albumin 0.0180021838 +copper 0.0001200022 +alk.phos 0.0365323630 +ast 0.0837836058 +trig 0.0170615337 +platelet 0.0674763888 +protime 0.1460939117 + +======================================================================================= + + ### Summary of categorical variables ### + +trt: 1 + var n miss p.miss level freq percent cum.percent + status 158 0 0.0 0 83 52.5 52.5 + 1 10 6.3 58.9 + 2 65 41.1 100.0 + + sex 158 0 0.0 m 21 13.3 13.3 + f 137 86.7 100.0 + + ascites 158 0 0.0 0 144 91.1 91.1 + 1 14 8.9 100.0 + + hepato 158 0 0.0 0 85 53.8 53.8 + 1 73 46.2 100.0 + + spiders 158 0 0.0 0 113 71.5 71.5 + 1 45 28.5 100.0 + + edema 158 0 0.0 0 132 83.5 83.5 + 0.5 16 10.1 93.7 + 1 10 6.3 100.0 + + stage 158 0 0.0 1 12 7.6 7.6 + 2 35 22.2 29.7 + 3 56 35.4 65.2 + 4 55 34.8 100.0 + +------------------------------------------------------------ +trt: 2 + var n miss p.miss level freq percent cum.percent + status 154 0 0.0 0 85 55.2 55.2 + 1 9 5.8 61.0 + 2 60 39.0 100.0 + + sex 154 0 0.0 m 15 9.7 9.7 + f 139 90.3 100.0 + + ascites 154 0 0.0 0 144 93.5 93.5 + 1 10 6.5 100.0 + + hepato 154 0 0.0 0 67 43.5 43.5 + 1 87 56.5 100.0 + + spiders 154 0 0.0 0 109 70.8 70.8 + 1 45 29.2 100.0 + + edema 154 0 0.0 0 131 85.1 85.1 + 0.5 13 8.4 93.5 + 1 10 6.5 100.0 + + stage 154 0 0.0 1 4 2.6 2.6 + 2 32 20.8 23.4 + 3 64 41.6 64.9 + 4 54 35.1 100.0 + + +p-values + pApprox pExact +status 0.89350975 0.88422188 +sex 0.42122610 0.37743235 +ascites 0.56728647 0.52558267 +hepato 0.08820884 0.07137522 +spiders 0.98466036 0.90113734 +edema 0.87681949 0.89370131 +stage 0.20129629 0.20455558 + +Standardize mean differences + 1 vs 2 +status 0.05375763 +sex 0.11141161 +ascites 0.08900618 +hepato 0.20699413 +spiders 0.01632844 +edema 0.05811659 +stage 0.24600834 +. + ### Summary of continuous variables ### + +trt: 1 +sex: m + n miss p.miss mean sd median p25 p75 min max skew kurt +time 21 0 0 1793 1244.7 1302 999 2386 140.0 4459 1.04 0.1 +age 21 0 0 56 12.6 56 46 66 33.5 78 -0.20 -0.7 +bili 21 0 0 3 2.1 2 1 4 0.6 7 1.02 -0.1 +chol 21 0 0 403 204.9 376 251 456 168.0 1000 1.33 2.2 +albumin 21 0 0 4 0.4 4 3 4 2.6 4 -0.97 0.3 +copper 21 0 0 175 105.3 158 100 225 25.0 444 1.08 1.0 +alk.phos 21 0 0 2486 2385.3 1664 983 2496 516.0 10165 2.05 4.5 +ast 21 0 0 129 48.7 127 86 158 56.8 222 0.31 -0.9 +trig 21 0 0 146 56.6 142 107 194 55.0 242 0.16 -1.0 +platelet 21 1 5 233 97.4 228 148 314 70.0 394 -0.05 -1.2 +protime 21 0 0 11 0.9 11 10 11 9.7 14 2.11 6.8 +------------------------------------------------------------ +trt: 2 +sex: m + n miss p.miss mean sd median p25 p75 min max skew kurt +time 15 0 0 2156 1428.6 1656 1054 3420 191.0 4427 0.3 -1.4 +age 15 0 0 57 10.1 53 49 66 43.9 75 0.5 -1.3 +bili 15 0 0 3 2.5 2 1 3 0.6 9 1.5 1.4 +chol 15 1 7 301 111.3 259 236 342 151.0 546 0.9 0.4 +albumin 15 0 0 4 0.5 4 3 4 2.3 4 -1.0 1.9 +copper 15 0 0 125 89.2 84 52 198 13.0 281 0.5 -1.1 +alk.phos 15 0 0 1734 2478.1 1070 737 1212 577.0 10397 3.5 12.7 +ast 15 0 0 113 44.4 110 74 129 46.5 188 0.3 -0.8 +trig 15 1 7 115 39.6 108 90 137 49.0 188 0.4 -0.4 +platelet 15 0 0 240 73.9 214 190 294 119.0 360 0.2 -1.0 +protime 15 0 0 11 1.0 11 11 12 10.0 13 0.7 0.2 +------------------------------------------------------------ +trt: 1 +sex: f + n miss p.miss mean sd median p25 p75 min max skew kurt +time 137 0 0.0 2050 1070.2 1945 1293.0 2644 41.0 4556 0.32 -0.4 +age 137 0 0.0 51 10.7 51 42.5 57 26.3 77 0.05 -0.5 +bili 137 0 0.0 3 3.8 1 0.8 3 0.3 20 2.65 7.1 +chol 137 18 13.1 358 210.5 309 247.5 400 127.0 1712 4.28 23.8 +albumin 137 0 0.0 3 0.4 4 3.2 4 2.1 5 -0.33 0.4 +copper 137 1 0.7 86 82.3 67 36.8 105 9.0 588 3.18 13.9 +alk.phos 137 0 0.0 1950 2151.4 1212 823.0 1877 369.0 11552 2.88 8.4 +ast 137 0 0.0 119 55.4 108 74.4 150 26.4 338 1.20 1.9 +trig 137 19 13.9 120 73.4 101 84.0 134 33.0 598 3.28 16.0 +platelet 137 1 0.7 263 100.5 258 194.2 322 62.0 563 0.57 0.3 +protime 137 0 0.0 11 0.8 11 10.0 11 9.0 13 0.92 0.6 +------------------------------------------------------------ +trt: 2 +sex: f + n miss p.miss mean sd median p25 p75 min max skew kurt +time 139 0 0.0 1980 1127.5 1832 1157.0 2717 51.0 4523 0.3 -0.6 +age 139 0 0.0 48 9.5 47 41.3 55 30.6 71 0.2 -0.7 +bili 139 0 0.0 4 5.5 1 0.7 4 0.3 28 2.6 6.5 +chol 139 9 6.5 382 262.3 306 258.0 381 120.0 1775 3.0 10.1 +albumin 139 0 0.0 4 0.4 4 3.3 4 2.0 4 -0.8 2.1 +copper 139 1 0.7 95 79.3 70 42.5 127 4.0 558 2.2 8.3 +alk.phos 139 0 0.0 1966 2066.2 1345 941.0 1992 289.0 13862 3.4 13.6 +ast 139 0 0.0 126 60.3 118 84.5 153 28.4 457 1.8 6.2 +trig 139 10 7.2 126 60.2 113 84.0 157 44.0 432 1.7 5.3 +platelet 139 2 1.4 268 92.2 265 213.0 324 71.0 487 0.2 -0.4 +protime 139 0 0.0 11 1.1 11 9.9 11 9.2 17 2.0 7.2 + +p-values + pNormal pNonNormal +time 0.73004959763 0.55664397971 +age 0.00012863810 0.00065174365 +bili 0.39374304731 0.20495248146 +chol 0.51222227887 0.45787732033 +albumin 0.58539258269 0.40412063286 +copper 0.00006237989 0.00004712924 +alk.phos 0.70638120444 0.18014798221 +ast 0.59828976332 0.50866156390 +trig 0.37010725909 0.05827725951 +platelet 0.36247402287 0.44512771593 +protime 0.13654633001 0.08114382938 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.27083134 0.22071813 0.15677410 0.08450703 0.13729269 +age 0.5214974 0.13353519 0.40993004 0.70700091 0.60864596 0.96133382 +bili 0.1352025 0.11373946 0.04023105 0.18444097 0.04265701 0.24158721 +chol 0.2950579 0.62108339 0.21756422 0.09219212 0.33996564 0.40072828 +albumin 0.1637683 0.28262444 0.30878937 0.26228013 0.01074465 0.05159074 +copper 0.5416574 0.50727571 0.94378898 0.86116098 0.46259003 0.36464167 +alk.phos 0.1633259 0.30907333 0.23603622 0.23332162 0.09290687 0.10128012 +ast 0.1818681 0.34614452 0.18797132 0.04399580 0.12602823 0.25929154 +trig 0.2940632 0.63360898 0.38944815 0.33242327 0.09194315 0.22610097 +platelet 0.2340433 0.08655951 0.30251429 0.37226635 0.25448008 0.33286083 +protime 0.3283721 0.40162254 0.24596092 0.08476002 0.66430044 0.44433997 + 3 vs 4 +time 0.06369595 +age 0.30853876 +bili 0.18855913 +chol 0.09881382 +albumin 0.06658036 +copper 0.11048709 +alk.phos 0.00733728 +ast 0.12777729 +trig 0.09085446 +platelet 0.05557853 +protime 0.12924857 + +======================================================================================= + + ### Summary of categorical variables ### + +trt: 1 +sex: m + var n miss p.miss level freq percent cum.percent + status 21 0 0.0 0 4 19.0 19.0 + 1 3 14.3 33.3 + 2 14 66.7 100.0 + + sex 21 0 0.0 m 21 100.0 100.0 + f 0 0.0 100.0 + + ascites 21 0 0.0 0 20 95.2 95.2 + 1 1 4.8 100.0 + + hepato 21 0 0.0 0 9 42.9 42.9 + 1 12 57.1 100.0 + + spiders 21 0 0.0 0 18 85.7 85.7 + 1 3 14.3 100.0 + + edema 21 0 0.0 0 17 81.0 81.0 + 0.5 3 14.3 95.2 + 1 1 4.8 100.0 + + stage 21 0 0.0 1 2 9.5 9.5 + 2 4 19.0 28.6 + 3 7 33.3 61.9 + 4 8 38.1 100.0 + +------------------------------------------------------------ +trt: 2 +sex: m + var n miss p.miss level freq percent cum.percent + status 15 0 0.0 0 7 46.7 46.7 + 1 0 0.0 46.7 + 2 8 53.3 100.0 + + sex 15 0 0.0 m 15 100.0 100.0 + f 0 0.0 100.0 + + ascites 15 0 0.0 0 13 86.7 86.7 + 1 2 13.3 100.0 + + hepato 15 0 0.0 0 6 40.0 40.0 + 1 9 60.0 100.0 + + spiders 15 0 0.0 0 14 93.3 93.3 + 1 1 6.7 100.0 + + edema 15 0 0.0 0 12 80.0 80.0 + 0.5 1 6.7 86.7 + 1 2 13.3 100.0 + + stage 15 0 0.0 1 1 6.7 6.7 + 2 2 13.3 20.0 + 3 5 33.3 53.3 + 4 7 46.7 100.0 + +------------------------------------------------------------ +trt: 1 +sex: f + var n miss p.miss level freq percent cum.percent + status 137 0 0.0 0 79 57.7 57.7 + 1 7 5.1 62.8 + 2 51 37.2 100.0 + + sex 137 0 0.0 m 0 0.0 0.0 + f 137 100.0 100.0 + + ascites 137 0 0.0 0 124 90.5 90.5 + 1 13 9.5 100.0 + + hepato 137 0 0.0 0 76 55.5 55.5 + 1 61 44.5 100.0 + + spiders 137 0 0.0 0 95 69.3 69.3 + 1 42 30.7 100.0 + + edema 137 0 0.0 0 115 83.9 83.9 + 0.5 13 9.5 93.4 + 1 9 6.6 100.0 + + stage 137 0 0.0 1 10 7.3 7.3 + 2 31 22.6 29.9 + 3 49 35.8 65.7 + 4 47 34.3 100.0 + +------------------------------------------------------------ +trt: 2 +sex: f + var n miss p.miss level freq percent cum.percent + status 139 0 0.0 0 78 56.1 56.1 + 1 9 6.5 62.6 + 2 52 37.4 100.0 + + sex 139 0 0.0 m 0 0.0 0.0 + f 139 100.0 100.0 + + ascites 139 0 0.0 0 131 94.2 94.2 + 1 8 5.8 100.0 + + hepato 139 0 0.0 0 61 43.9 43.9 + 1 78 56.1 100.0 + + spiders 139 0 0.0 0 95 68.3 68.3 + 1 44 31.7 100.0 + + edema 139 0 0.0 0 119 85.6 85.6 + 0.5 12 8.6 94.2 + 1 8 5.8 100.0 + + stage 139 0 0.0 1 3 2.2 2.2 + 2 30 21.6 23.7 + 3 59 42.4 66.2 + 4 47 33.8 100.0 + + +p-values + pApprox pExact +status 3.269881e-02 2.420814e-02 +sex 2.514569e-67 4.934035e-48 +ascites 5.156942e-01 4.354075e-01 +hepato 2.080568e-01 2.048012e-01 +spiders 8.898575e-02 8.569292e-02 +edema 9.058420e-01 8.483322e-01 +stage 6.463005e-01 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +status 0.5770647 0.79644734 0.8748771 0.83097631 0.4375075 0.46214324 +sex 0.0000000 0.00000000 0.0000000 0.00000000 0.0000000 0.00000000 +ascites 0.1755851 0.30219043 0.1845375 0.04452096 0.1211310 0.26007640 +hepato 0.1598214 0.05802589 0.2544151 0.02073917 0.3135916 0.07878788 +spiders 0.4018377 0.25073566 0.3999925 0.42200838 0.6471968 0.66954801 +edema 0.2122338 0.37625250 0.1624118 0.18063879 0.2420277 0.26502087 +stage 0.2773411 0.21945509 0.1333844 0.35632272 0.3000785 0.39205566 + 3 vs 4 +status 0.06043662 +sex 0.00000000 +ascites 0.14105454 +hepato 0.23336861 +spiders 0.02154469 +edema 0.04705137 +stage 0.26275030 +. + ### Summary of continuous variables ### + +trt: 1 +sex: m + n miss p.miss mean sd median p25 p75 min max skew kurt +time 21 0 0 1793 1244.7 1302 999 2386 140 4459 1.0 0.1 +age 21 0 0 56 12.6 56 46 66 33 78 -0.2 -0.7 +protime 21 0 0 11 0.9 11 10 11 10 14 2.1 6.8 +------------------------------------------------------------ +trt: 2 +sex: m + n miss p.miss mean sd median p25 p75 min max skew kurt +time 15 0 0 2156 1429 1656 1054 3420 191 4427 0.3 -1.4 +age 15 0 0 57 10 53 49 66 44 75 0.5 -1.3 +protime 15 0 0 11 1 11 11 12 10 13 0.7 0.2 +------------------------------------------------------------ +trt: 1 +sex: f + n miss p.miss mean sd median p25 p75 min max skew kurt +time 137 0 0 2050 1070.2 1945 1293 2644 41 4556 0.32 -0.4 +age 137 0 0 51 10.7 51 43 57 26 77 0.05 -0.5 +protime 137 0 0 11 0.8 11 10 11 9 13 0.92 0.6 +------------------------------------------------------------ +trt: 2 +sex: f + n miss p.miss mean sd median p25 p75 min max skew kurt +time 139 0 0 1980 1128 1832 1157 2717 51 4523 0.3 -0.6 +age 139 0 0 48 10 47 41 55 31 71 0.2 -0.7 +protime 139 0 0 11 1 11 10 11 9 17 2.0 7.2 + +p-values + pNormal pNonNormal +time 0.7300495976 0.5566439797 +age 0.0001286381 0.0006517437 +protime 0.1365463300 0.0811438294 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 +time 0.1556365 0.2708313 0.2207181 0.15677410 0.08450703 0.1372927 +age 0.5214974 0.1335352 0.4099300 0.70700091 0.60864596 0.9613338 +protime 0.3283721 0.4016225 0.2459609 0.08476002 0.66430044 0.4443400 + 3 vs 4 +time 0.06369595 +age 0.30853876 +protime 0.12924857 +. + ### Summary of categorical variables ### + +trt: 1 +sex: m + var n miss p.miss level freq percent cum.percent + status 21 0 0.0 0 4 19.0 19.0 + 1 3 14.3 33.3 + 2 14 66.7 100.0 + + trt 21 0 0.0 1 21 100.0 100.0 + 2 0 0.0 100.0 + + sex 21 0 0.0 m 21 100.0 100.0 + f 0 0.0 100.0 + +------------------------------------------------------------ +trt: 2 +sex: m + var n miss p.miss level freq percent cum.percent + status 15 0 0.0 0 7 46.7 46.7 + 1 0 0.0 46.7 + 2 8 53.3 100.0 + + trt 15 0 0.0 1 0 0.0 0.0 + 2 15 100.0 100.0 + + sex 15 0 0.0 m 15 100.0 100.0 + f 0 0.0 100.0 + +------------------------------------------------------------ +trt: 1 +sex: f + var n miss p.miss level freq percent cum.percent + status 137 0 0.0 0 79 57.7 57.7 + 1 7 5.1 62.8 + 2 51 37.2 100.0 + + trt 137 0 0.0 1 137 100.0 100.0 + 2 0 0.0 100.0 + + sex 137 0 0.0 m 0 0.0 0.0 + f 137 100.0 100.0 + +------------------------------------------------------------ +trt: 2 +sex: f + var n miss p.miss level freq percent cum.percent + status 139 0 0.0 0 78 56.1 56.1 + 1 9 6.5 62.6 + 2 52 37.4 100.0 + + trt 139 0 0.0 1 0 0.0 0.0 + 2 139 100.0 100.0 + + sex 139 0 0.0 m 0 0.0 0.0 + f 139 100.0 100.0 + + +p-values + pApprox pExact +status 3.269881e-02 2.420814e-02 +trt 2.514569e-67 2.724125e-93 +sex 2.514569e-67 4.934035e-48 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +status 0.5770647 0.7964473 0.8748771 0.8309763 0.4375075 0.4621432 0.06043662 +trt 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000 +sex 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000 +. Unit tests for the modules : ........ Tests for functions for standardized mean differences : ................................................................................... ### Summary of continuous variables ### @@ -2117,7 +2721,369 @@ Column Total | 100 | 100 | 100 | 50 | 50 | (39,59] (59,Inf] RIAGENDR = 2 (%) <0.0000001 -....... +. + ### Summary of continuous variables ### + +: Overall + n miss p.miss mean sd median p25 p75 min max +E 450 0 0 2.0 0.8 2 1 3 1 3 +C 450 0 0 2.1 0.9 2 1 3 1 4 +C2 450 0 0 0.5 0.5 0 0 1 0 1 + +======================================================================================= + + ### Summary of categorical variables ### + +: Overall + var n miss p.miss level freq percent cum.percent + Y 450.0 0.3 0.1 0 272.7 60.6 60.6 + 1 177.0 39.4 100.0 + + C1 450.0 0.0 0.0 0 300.0 66.7 66.7 + 1 150.0 33.3 100.0 + +. + ### Summary of continuous variables ### + +: Overall + n miss p.miss mean sd median p25 p75 min max +E 450 0 0 2.0 0.8 2 1 3 1 3 +C 450 0 0 2.1 0.9 2 1 3 1 4 +C2 450 0 0 0.5 0.5 0 0 1 0 1 + +======================================================================================= + + ### Summary of categorical variables ### + +: Overall + var n miss p.miss level freq percent cum.percent + Y 450.0 0.0 0.0 0 272.7 60.6 60.6 + 1 177.0 39.3 99.9 + 0.3 0.1 100.0 + + C1 450.0 0.0 0.0 0 300.0 66.7 66.7 + 1 150.0 33.3 100.0 + +. + ### Summary of continuous variables ### + +E: 1 + n miss p.miss mean sd median p25 p75 min max +E 150 0 0 1.0 0.0 1 1 1 1 1 +C 150 0 0 2.1 0.9 2 1 3 1 4 +C2 150 0 0 0.5 0.5 0 0 1 0 1 +------------------------------------------------------------ +E: 2 + n miss p.miss mean sd median p25 p75 min max +E 150 0 0 2.0 0.0 2 2 2 2 2 +C 150 0 0 2.1 0.9 2 1 3 1 4 +C2 150 0 0 0.5 0.5 0 0 1 0 1 +------------------------------------------------------------ +E: 3 + n miss p.miss mean sd median p25 p75 min max +E 150 0 0 3.0 0.0 3 3 3 3 3 +C 150 0 0 2.1 0.9 2 1 3 1 4 +C2 150 0 0 0.5 0.5 0 0 1 0 1 + +p-values + pNormal pNonNormal +E 0.0000000 0.0000000 +C 0.9999992 0.9999991 +C2 0.9999993 0.9999993 + +Standardize mean differences + average 1 vs 2 1 vs 3 2 vs 3 +E Inf Inf Inf Inf +C 0.00006823456 0.00009934218 0.00010235224 0.000003009264 +C2 0.00006404022 0.00009606505 0.00007471632 0.000021339301 + +======================================================================================= + + ### Summary of categorical variables ### + +E: 1 + var n miss p.miss level freq percent cum.percent + Y 150.0 0.3 0.2 0 90.7 60.6 60.6 + 1 59.0 39.4 100.0 + + C1 150.0 0.0 0.0 0 100.0 66.7 66.7 + 1 50.0 33.3 100.0 + +------------------------------------------------------------ +E: 2 + var n miss p.miss level freq percent cum.percent + Y 150.0 0.0 0.0 0 91.0 60.7 60.7 + 1 59.0 39.3 100.0 + + C1 150.0 0.0 0.0 0 100.0 66.7 66.7 + 1 50.0 33.3 100.0 + +------------------------------------------------------------ +E: 3 + var n miss p.miss level freq percent cum.percent + Y 150.0 0.0 0.0 0 91.0 60.7 60.7 + 1 59.0 39.3 100.0 + + C1 150.0 0.0 0.0 0 100.0 66.7 66.7 + 1 50.0 33.3 100.0 + + +p-values + pApprox pExact +Y 0.9998243 NA +C1 0.9999998 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 2 vs 3 +Y 0.00099495892 0.00149243839 0.00148861716 0.000003821227 +C1 0.00003770972 0.00004242269 0.00005656458 0.000014141888 +. + ### Summary of continuous variables ### + +E:C1: 1:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 1.0 0.0 1 1 1 1 1 +C 100 0 0 1.6 0.5 2 1 2 1 2 +C2 100 0 0 0.6 0.5 1 0 1 0 1 +------------------------------------------------------------ +E:C1: 2:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 2.0 2e-16 2 2 2 2 2 +C 100 0 0 1.6 5e-01 2 1 2 1 2 +C2 100 0 0 0.6 5e-01 1 0 1 0 1 +------------------------------------------------------------ +E:C1: 3:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 3.0 0.0 3 3 3 3 3 +C 100 0 0 1.6 0.5 2 1 2 1 2 +C2 100 0 0 0.6 0.5 1 0 1 0 1 +------------------------------------------------------------ +E:C1: 1:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 1.0 0.0 1 1 1 1 1 +C 50 0 0 3.2 0.4 3 3 3 3 4 +C2 50 0 0 0.2 0.4 0 0 0 0 1 +------------------------------------------------------------ +E:C1: 2:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 2.0 0.0 2 2 2 2 2 +C 50 0 0 3.2 0.4 3 3 3 3 4 +C2 50 0 0 0.2 0.4 0 0 0 0 1 +------------------------------------------------------------ +E:C1: 3:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 3.0 0.0 3 3 3 3 3 +C 50 0 0 3.2 0.4 3 3 3 3 4 +C2 50 0 0 0.2 0.4 0 0 0 0 1 + +p-values + pNormal pNonNormal +E 0.000000e+00 0.00000e+00 +C 2.518377e-307 0.00000e+00 +C2 1.950910e-37 1.95091e-37 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 +E NaN 6.350292e+15 Inf NaN Inf Inf +C 2.1373647 1.710913e-04 0.000146495 3.5608223 3.5673100 3.5708236 +C2 0.5343248 1.710913e-04 0.000146495 0.8900053 0.8916269 0.8925051 + 2 vs 3 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 +E 6.350292e+15 6.350292e+15 1.4100480 6.350292e+15 Inf Inf +C 2.439672e-05 3.556921e+00 3.5633882 3.566891e+00 3.5525326 3.5589756 +C2 2.439672e-05 8.892636e-01 0.8908805 8.917561e-01 0.8881331 0.8897439 + 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +E NaN Inf Inf Inf +C 3.5624649 0 0 0 +C2 0.8906162 0 0 0 + +======================================================================================= + + ### Summary of categorical variables ### + +E:C1: 1:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.3 0.3 0 77.7 77.9 77.9 + 1 22.0 22.1 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 2:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.0 0.0 0 78.0 78.0 78.0 + 1 22.0 22.0 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 3:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.0 0.0 0 78.0 78.0 78.0 + 1 22.0 22.0 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 1:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + +------------------------------------------------------------ +E:C1: 2:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + +------------------------------------------------------------ +E:C1: 3:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + + +p-values + pApprox pExact +Y 4.540885e-31 NA +C1 4.640660e-128 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 +Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 +C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 + 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +Y 1.218891 1.218891 1.218891 1.218899 1.218899 1.218899 0 0 0 +C1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0 0 0 +. + ### Summary of continuous variables ### + +E:C1: 1:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 1 0.0 1 1 1 1 1 +C 100 0 0 2 0.5 2 1 2 1 2 +------------------------------------------------------------ +E:C1: 2:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 2 2e-16 2 2 2 2 2 +C 100 0 0 2 5e-01 2 1 2 1 2 +------------------------------------------------------------ +E:C1: 3:0 + n miss p.miss mean sd median p25 p75 min max +E 100 0 0 3 0.0 3 3 3 3 3 +C 100 0 0 2 0.5 2 1 2 1 2 +------------------------------------------------------------ +E:C1: 1:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 1 0.0 1 1 1 1 1 +C 50 0 0 3 0.4 3 3 3 3 4 +------------------------------------------------------------ +E:C1: 2:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 2 0.0 2 2 2 2 2 +C 50 0 0 3 0.4 3 3 3 3 4 +------------------------------------------------------------ +E:C1: 3:1 + n miss p.miss mean sd median p25 p75 min max +E 50 0 0 3 0.0 3 3 3 3 3 +C 50 0 0 3 0.4 3 3 3 3 4 + +p-values + pNormal pNonNormal +E 0.000000e+00 0 +C 2.518377e-307 0 + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 +E NaN 6.350292e+15 Inf NaN Inf Inf 6.350292e+15 +C 2.137365 1.710913e-04 0.000146495 3.560822 3.56731 3.570824 2.439672e-05 + 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 +E 6.350292e+15 1.410048 6.350292e+15 Inf Inf NaN Inf Inf +C 3.556921e+00 3.563388 3.566891e+00 3.552533 3.558976 3.562465 0 0 + 5 vs 6 +E Inf +C 0 +. + ### Summary of categorical variables ### + +E:C1: 1:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.3 0.3 0 77.7 77.9 77.9 + 1 22.0 22.1 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 2:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.0 0.0 0 78.0 78.0 78.0 + 1 22.0 22.0 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 3:0 + var n miss p.miss level freq percent cum.percent + Y 100.0 0.0 0.0 0 78.0 78.0 78.0 + 1 22.0 22.0 100.0 + + C1 100.0 0.0 0.0 0 100.0 100.0 100.0 + 1 0.0 0.0 100.0 + +------------------------------------------------------------ +E:C1: 1:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + +------------------------------------------------------------ +E:C1: 2:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + +------------------------------------------------------------ +E:C1: 3:1 + var n miss p.miss level freq percent cum.percent + Y 50.0 0.0 0.0 0 13.0 26.0 26.0 + 1 37.0 74.0 100.0 + + C1 50.0 0.0 0.0 0 0.0 0.0 0.0 + 1 50.0 100.0 100.0 + + +p-values + pApprox pExact +Y 4.540885e-31 NA +C1 4.640660e-128 NA + +Standardize mean differences + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 +Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 +C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 + 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +Y 1.218891 1.218891 1.218891 1.218899 1.218899 1.218899 0 0 0 +C1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0 0 0 +. Unit tests for the survey-related modules : ................................................ DONE diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index 563e63b..c13c060 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -306,14 +306,20 @@ test_that("printing of a TableOne$ContTable object do not regress", { test_that("summary method works without errors", { ## Expectations + summary(pbcOverall) expect_output(summary(pbcOverall), "time 418 0 0.0 1918 1104.7 1730 1092.8 2614 41.0 4795 0.47 -0.5") + summary(pbcInclNa) expect_output(summary(pbcInclNa), " 6 1.4 100.0") + summary(pbcByTrt) expect_output(summary(pbcByTrt), "hepato 0.20699413") + summary(pbcByTrtSex) expect_output(summary(pbcByTrtSex), "Standardize mean differences") + summary(pbcContOnlyByTrtSex) expect_output(summary(pbcContOnlyByTrtSex), "### Summary of continuous variables ###") + summary(pbcCatOnlyByTrtSex) expect_output(summary(pbcCatOnlyByTrtSex), "status 0.5770647 0.7964473 0.8748771 0.8309763 0.4375075 0.4621432 0.06043662") diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index d45188e..e5f0c3a 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -423,14 +423,20 @@ expect_equal(print(tab1, pDigits = 7, nonnormal = "HI_CHOL")[3,3], test_that("summary method works without errors", { ## Expectations + summary(mwOverall) expect_output(summary(mwOverall), "n miss p.miss mean sd median p25 p75 min max") + summary(mwInclNa) expect_output(summary(mwInclNa), " 0.3 0.1 100.0") + summary(mwByE) expect_output(summary(mwByE), "Y 0.00099495892 0.00149243839 0.00148861716 0.000003821227") + summary(mwByEC1) expect_output(summary(mwByEC1), "Standardize mean differences") + summary(mwContOnlyByEC1) expect_output(summary(mwContOnlyByEC1), "Standardize mean differences") + summary(mwCatOnlyByEC1) expect_output(summary(mwCatOnlyByEC1), "Standardize mean differences") From 441a79736fbb271ffe7b5746aa514ea6e0decced Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 18:43:47 -0400 Subject: [PATCH 148/219] Change Makefile to check test files for updates CRAN check was failing because of archive file not in sync with tests --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f74514..9ce335c 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,10 @@ PKG_VERSION=$(shell grep -i ^version: DESCRIPTION | cut -d : -d \ -f 2) ## Define files to check for updates R_FILES := $(wildcard R/*.R) +TST_FILES := $(wildcard tests/testthat/*.R) SRC_FILES := $(wildcard src/*) $(addprefix src/, $(COPY_SRC)) VIG_FILES := $(wildcard vignettes/*) -PKG_FILES := DESCRIPTION NAMESPACE NEWS $(R_FILES) $(SRC_FILES) $(VIG_FILES) +PKG_FILES := DESCRIPTION NAMESPACE NEWS $(R_FILES) $(TST_FILES) $(SRC_FILES) $(VIG_FILES) ## .PHONY to allow non-file targets (file targets should not be here) From 25d0c476cbd96a2851c7a4a7d68a62846f2ca595 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 18:48:17 -0400 Subject: [PATCH 149/219] Simplify summary() unit testing (passing) --- man/summary.TableOne.Rd | 11 +- tableone.Rcheck/tableone-Ex.Rout | 4 +- test-all.txt | 1590 ++++++++--------------- tests/testthat/test-CreateTableOne.R | 10 +- tests/testthat/test-svyCreateTableOne.R | 7 +- 5 files changed, 560 insertions(+), 1062 deletions(-) diff --git a/man/summary.TableOne.Rd b/man/summary.TableOne.Rd index 367620d..962ff5d 100644 --- a/man/summary.TableOne.Rd +++ b/man/summary.TableOne.Rd @@ -2,12 +2,12 @@ % Please edit documentation in R/summary.TableOne.R \name{summary.TableOne} \alias{summary.TableOne} -\title{Shows all results in a \code{TableOne} class object} +\title{Shows all results in a \code{(svy)TableOne} class object} \usage{ \method{summary}{TableOne}(object, digits = 1, ...) } \arguments{ -\item{object}{An object that has the \code{CatTable} class to be shown.} +\item{object}{An object that has the \code{(svy)TableOne} class to be shown.} \item{digits}{Number of digits to print.} @@ -17,10 +17,9 @@ It will print the results. } \description{ -This method shows all the data a CatTable class object has. This includes -the (optionally stratified) part with summary statistics and p-values from -the approximation method test (chisq.test by default) and exact method test -(fisher.test by default). +This method shows all the data a \code{(svy)TableOne} class object has. This +includes the (optionally stratified) part with summary statistics and p-values +and/or standardized mean differences. } \examples{ ## Load diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 66ca54e..9063383 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -3938,7 +3938,7 @@ detaching ‘package:survival’ > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: summary.TableOne -> ### Title: Shows all results in a 'TableOne' class object +> ### Title: Shows all results in a '(svy)TableOne' class object > ### Aliases: summary.TableOne > > ### ** Examples @@ -5792,7 +5792,7 @@ _E_x_a_m_p_l_e_s: > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 8.89 0.258 10.448 0.01 0.012 +Time elapsed: 10.963 0.356 11.657 0.013 0.014 > grDevices::dev.off() null device 1 diff --git a/test-all.txt b/test-all.txt index 2a4537f..fb814bd 100644 --- a/test-all.txt +++ b/test-all.txt @@ -103,129 +103,67 @@ Unit tests for the CreateTableOne function : ................. 4 144 (34.4) NA 6 ( 1.4) . Stratified by trt:sex - 1:m 2:m 1:f - n 21 15 137 - time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) - status (%) - 0 4 (19.0) 7 (46.7) 79 ( 57.7) - 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) - 2 14 (66.7) 8 (53.3) 51 ( 37.2) - age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) - sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) - ascites = 1 (%) 1 ( 4.8) 2 (13.3) 13 ( 9.5) - hepato = 1 (%) 12 (57.1) 9 (60.0) 61 ( 44.5) - spiders = 1 (%) 3 (14.3) 1 ( 6.7) 42 ( 30.7) - edema (%) - 0 17 (81.0) 12 (80.0) 115 ( 83.9) - 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) - 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) - bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) - chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) - copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) - alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) - ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) - trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) - platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) - protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) - stage (%) - 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) - 2 4 (19.0) 2 (13.3) 31 ( 22.6) - 3 7 (33.3) 5 (33.3) 49 ( 35.8) - 4 8 (38.1) 7 (46.7) 47 ( 34.3) - Stratified by trt:sex - 2:f p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - status (%) 0.033 - 0 78 ( 56.1) - 1 9 ( 6.5) - 2 52 ( 37.4) - age (mean (sd)) 47.66 (9.54) <0.001 - sex = f (%) 139 (100.0) <0.001 - ascites = 1 (%) 8 ( 5.8) 0.516 - hepato = 1 (%) 78 ( 56.1) 0.208 - spiders = 1 (%) 44 ( 31.7) 0.089 - edema (%) 0.906 - 0 119 ( 85.6) - 0.5 12 ( 8.6) - 1 8 ( 5.8) - bili (mean (sd)) 3.75 (5.50) 0.394 - chol (mean (sd)) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.53 (0.39) 0.585 - copper (mean (sd)) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 126.30 (60.27) 0.598 - trig (mean (sd)) 126.38 (60.22) 0.370 - platelet (mean (sd)) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.75 (1.15) 0.137 - stage (%) 0.646 - 1 3 ( 2.2) - 2 30 ( 21.6) - 3 59 ( 42.4) - 4 47 ( 33.8) + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 + status (%) 0.033 + 0 4 (19.0) 7 (46.7) 79 ( 57.7) 78 ( 56.1) + 1 3 (14.3) 0 ( 0.0) 7 ( 5.1) 9 ( 6.5) + 2 14 (66.7) 8 (53.3) 51 ( 37.2) 52 ( 37.4) + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 + sex = f (%) 0 ( 0.0) 0 ( 0.0) 137 (100.0) 139 (100.0) <0.001 + ascites = 1 (%) 1 ( 4.8) 2 (13.3) 13 ( 9.5) 8 ( 5.8) 0.516 + hepato = 1 (%) 12 (57.1) 9 (60.0) 61 ( 44.5) 78 ( 56.1) 0.208 + spiders = 1 (%) 3 (14.3) 1 ( 6.7) 42 ( 30.7) 44 ( 31.7) 0.089 + edema (%) 0.906 + 0 17 (81.0) 12 (80.0) 115 ( 83.9) 119 ( 85.6) + 0.5 3 (14.3) 1 ( 6.7) 13 ( 9.5) 12 ( 8.6) + 1 1 ( 4.8) 2 (13.3) 9 ( 6.6) 8 ( 5.8) + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 + stage (%) 0.646 + 1 2 ( 9.5) 1 ( 6.7) 10 ( 7.3) 3 ( 2.2) + 2 4 (19.0) 2 (13.3) 31 ( 22.6) 30 ( 21.6) + 3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4) + 4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8) . Stratified by trt - 1 2 p - n 158 154 - time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 - status (%) 0.89351 - 0 83 (52.532) 85 (55.195) - 1 10 ( 6.329) 9 ( 5.844) - 2 65 (41.139) 60 (38.961) - age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 - sex = f (%) 137 (86.709) 139 (90.260) 0.42123 - ascites = 1 (%) 14 ( 8.861) 10 ( 6.494) 0.56729 - hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 - spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 - edema (%) 0.87682 - 0 132 (83.544) 131 (85.065) - 0.5 16 (10.127) 13 ( 8.442) - 1 10 ( 6.329) 10 ( 6.494) - bili (mean (sd)) 2.8734 (3.6289) 3.6487 (5.2819) 0.13094 - chol (mean (sd)) 365.0143 (209.5439) 373.8819 (252.4846) 0.74799 - albumin (mean (sd)) 3.5163 (0.4433) 3.5238 (0.3958) 0.87388 - copper (mean (sd)) 97.6433 (90.5901) 97.6536 (80.4865) 0.99916 - alk.phos (mean (sd)) 2021.2975 (2183.4358) 1943.0104 (2101.6873) 0.74726 - ast (mean (sd)) 120.2087 (54.5214) 124.9650 (58.9313) 0.45970 - trig (mean (sd)) 124.1367 (71.5391) 125.2517 (58.5211) 0.88604 - platelet (mean (sd)) 258.7500 (100.3247) 265.2039 (90.7294) 0.55451 - protime (mean (sd)) 10.6532 (0.8514) 10.8000 (1.1382) 0.19714 - stage (%) 0.20130 - 1 12 ( 7.595) 4 ( 2.597) - 2 35 (22.152) 32 (20.779) - 3 56 (35.443) 64 (41.558) - 4 55 (34.810) 54 (35.065) - Stratified by trt - test - n - time (mean (sd)) - status (%) - 0 - 1 - 2 - age (mean (sd)) - sex = f (%) - ascites = 1 (%) - hepato = 1 (%) - spiders = 1 (%) - edema (%) - 0 - 0.5 - 1 - bili (mean (sd)) - chol (mean (sd)) - albumin (mean (sd)) - copper (mean (sd)) - alk.phos (mean (sd)) - ast (mean (sd)) - trig (mean (sd)) - platelet (mean (sd)) - protime (mean (sd)) - stage (%) - 1 - 2 - 3 - 4 + 1 2 p test + n 158 154 + time (mean (sd)) 2015.6203 (1094.1233) 1996.8636 (1155.9289) 0.88305 + status (%) 0.89351 + 0 83 (52.532) 85 (55.195) + 1 10 ( 6.329) 9 ( 5.844) + 2 65 (41.139) 60 (38.961) + age (mean (sd)) 51.4191 (11.0072) 48.5825 (9.9578) 0.01767 + sex = f (%) 137 (86.709) 139 (90.260) 0.42123 + ascites = 1 (%) 14 ( 8.861) 10 ( 6.494) 0.56729 + hepato = 1 (%) 73 (46.203) 87 (56.494) 0.08821 + spiders = 1 (%) 45 (28.481) 45 (29.221) 0.98466 + edema (%) 0.87682 + 0 132 (83.544) 131 (85.065) + 0.5 16 (10.127) 13 ( 8.442) + 1 10 ( 6.329) 10 ( 6.494) + bili (mean (sd)) 2.8734 (3.6289) 3.6487 (5.2819) 0.13094 + chol (mean (sd)) 365.0143 (209.5439) 373.8819 (252.4846) 0.74799 + albumin (mean (sd)) 3.5163 (0.4433) 3.5238 (0.3958) 0.87388 + copper (mean (sd)) 97.6433 (90.5901) 97.6536 (80.4865) 0.99916 + alk.phos (mean (sd)) 2021.2975 (2183.4358) 1943.0104 (2101.6873) 0.74726 + ast (mean (sd)) 120.2087 (54.5214) 124.9650 (58.9313) 0.45970 + trig (mean (sd)) 124.1367 (71.5391) 125.2517 (58.5211) 0.88604 + platelet (mean (sd)) 258.7500 (100.3247) 265.2039 (90.7294) 0.55451 + protime (mean (sd)) 10.6532 (0.8514) 10.8000 (1.1382) 0.19714 + stage (%) 0.20130 + 1 12 ( 7.595) 4 ( 2.597) + 2 35 (22.152) 32 (20.779) + 3 56 (35.443) 64 (41.558) + 4 55 (34.810) 54 (35.065) . Stratified by trt 1 2 n 158 154 @@ -258,329 +196,167 @@ Unit tests for the CreateTableOne function : ................. 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) . Stratified by trt - 1 2 - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) - status (%) - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) - sex = f (%) 137 (86.7) 139 (90.3) - ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) - hepato = 1 (%) 73 (46.2) 87 (56.5) - spiders = 1 (%) 45 (28.5) 45 (29.2) - edema (%) - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) - stage (%) - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) - Stratified by trt - p test - n - time (mean (sd)) 0.883 - status (%) 0.884 exact - 0 - 1 - 2 - age (mean (sd)) 0.018 - sex = f (%) 0.421 - ascites = 1 (%) 0.567 - hepato = 1 (%) 0.088 - spiders = 1 (%) 0.985 - edema (%) 0.877 - 0 - 0.5 - 1 - bili (median [IQR]) 0.842 nonnorm - chol (median [IQR]) 0.544 nonnorm - albumin (mean (sd)) 0.874 - copper (median [IQR]) 0.717 nonnorm - alk.phos (median [IQR]) 0.812 nonnorm - ast (mean (sd)) 0.460 - trig (median [IQR]) 0.370 nonnorm - platelet (mean (sd)) 0.555 - protime (mean (sd)) 0.197 - stage (%) 0.205 exact - 1 - 2 - 3 - 4 + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.884 exact + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.205 exact + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) . Stratified by trt - 1 - n 158 - time (mean (sd)) 2015.62 (1094.12) - status (%) - 0 83 (52.5) - 1 10 ( 6.3) - 2 65 (41.1) - age (mean (sd)) 51.42 (11.01) - sex = f (%) 137 (86.7) - ascites = 1 (%) 14 ( 8.9) - hepato = 1 (%) 73 (46.2) - spiders = 1 (%) 45 (28.5) - edema (%) - 0 132 (83.5) - 0.5 16 (10.1) - 1 10 ( 6.3) - bili (median [range]) 1.40 [0.30, 20.00] - chol (median [range]) 315.50 [127.00, 1712.00] - albumin (mean (sd)) 3.52 (0.44) - copper (median [range]) 73.00 [9.00, 588.00] - alk.phos (median [range]) 1214.50 [369.00, 11552.00] - ast (mean (sd)) 120.21 (54.52) - trig (median [range]) 106.00 [33.00, 598.00] - platelet (mean (sd)) 258.75 (100.32) - protime (mean (sd)) 10.65 (0.85) - stage (%) - 1 12 ( 7.6) - 2 35 (22.2) - 3 56 (35.4) - 4 55 (34.8) - Stratified by trt - 2 p test - n 154 - time (mean (sd)) 1996.86 (1155.93) 0.883 - status (%) 0.894 - 0 85 (55.2) - 1 9 ( 5.8) - 2 60 (39.0) - age (mean (sd)) 48.58 (9.96) 0.018 - sex = f (%) 139 (90.3) 0.421 - ascites = 1 (%) 10 ( 6.5) 0.567 - hepato = 1 (%) 87 (56.5) 0.088 - spiders = 1 (%) 45 (29.2) 0.985 - edema (%) 0.877 - 0 131 (85.1) - 0.5 13 ( 8.4) - 1 10 ( 6.5) - bili (median [range]) 1.30 [0.30, 28.00] 0.842 nonnorm - chol (median [range]) 303.50 [120.00, 1775.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.40) 0.874 - copper (median [range]) 73.00 [4.00, 558.00] 0.717 nonnorm - alk.phos (median [range]) 1283.00 [289.00, 13862.40] 0.812 nonnorm - ast (mean (sd)) 124.97 (58.93) 0.460 - trig (median [range]) 113.00 [44.00, 432.00] 0.370 nonnorm - platelet (mean (sd)) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.80 (1.14) 0.197 - stage (%) 0.201 - 1 4 ( 2.6) - 2 32 (20.8) - 3 64 (41.6) - 4 54 (35.1) + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.894 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.201 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) . Stratified by trt - 1 2 - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) - status (%) - 0 83 (52.5) 85 (55.2) - 1 10 (6.3) 9 (5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) - sex = f (%) 137 (86.7) 139 (90.3) - ascites = 1 (%) 14 (8.9) 10 (6.5) - hepato = 1 (%) 73 (46.2) 87 (56.5) - spiders = 1 (%) 45 (28.5) 45 (29.2) - edema (%) - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 (8.4) - 1 10 (6.3) 10 (6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) - stage (%) - 1 12 (7.6) 4 (2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) - Stratified by trt - p test - n - time (mean (sd)) 0.883 - status (%) 0.884 exact - 0 - 1 - 2 - age (mean (sd)) 0.018 - sex = f (%) 0.421 - ascites = 1 (%) 0.567 - hepato = 1 (%) 0.088 - spiders = 1 (%) 0.985 - edema (%) 0.877 - 0 - 0.5 - 1 - bili (median [IQR]) 0.842 nonnorm - chol (median [IQR]) 0.544 nonnorm - albumin (mean (sd)) 0.874 - copper (median [IQR]) 0.717 nonnorm - alk.phos (median [IQR]) 0.812 nonnorm - ast (mean (sd)) 0.460 - trig (median [IQR]) 0.370 nonnorm - platelet (mean (sd)) 0.555 - protime (mean (sd)) 0.197 - stage (%) 0.205 exact - 1 - 2 - 3 - 4 + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0.884 exact + 0 83 (52.5) 85 (55.2) + 1 10 (6.3) 9 (5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex = f (%) 137 (86.7) 139 (90.3) 0.421 + ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 + hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 + spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 + edema (%) 0.877 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 (8.4) + 1 10 (6.3) 10 (6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 0.205 exact + 1 12 (7.6) 4 (2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) . Stratified by trt - level 1 - n 158 - time (mean (sd)) 2015.62 (1094.12) - status (%) 0 83 (52.5) - 1 10 ( 6.3) - 2 65 (41.1) - age (mean (sd)) 51.42 (11.01) - sex (%) m 21 (13.3) - f 137 (86.7) - ascites (%) 0 144 (91.1) - 1 14 ( 8.9) - hepato (%) 0 85 (53.8) - 1 73 (46.2) - spiders (%) 0 113 (71.5) - 1 45 (28.5) - edema (%) 0 132 (83.5) - 0.5 16 (10.1) - 1 10 ( 6.3) - bili (median [IQR]) 1.40 [0.80, 3.20] - chol (median [IQR]) 315.50 [247.75, 417.00] - albumin (mean (sd)) 3.52 (0.44) - copper (median [IQR]) 73.00 [40.00, 121.00] - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] - ast (mean (sd)) 120.21 (54.52) - trig (median [IQR]) 106.00 [84.50, 146.00] - platelet (mean (sd)) 258.75 (100.32) - protime (mean (sd)) 10.65 (0.85) - stage (%) 1 12 ( 7.6) - 2 35 (22.2) - 3 56 (35.4) - 4 55 (34.8) - Stratified by trt - 2 p test - n 154 - time (mean (sd)) 1996.86 (1155.93) 0.883 - status (%) 85 (55.2) 0.884 exact - 9 ( 5.8) - 60 (39.0) - age (mean (sd)) 48.58 (9.96) 0.018 - sex (%) 15 ( 9.7) 0.421 - 139 (90.3) - ascites (%) 144 (93.5) 0.567 - 10 ( 6.5) - hepato (%) 67 (43.5) 0.088 - 87 (56.5) - spiders (%) 109 (70.8) 0.985 - 45 (29.2) - edema (%) 131 (85.1) 0.877 - 13 ( 8.4) - 10 ( 6.5) - bili (median [IQR]) 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 124.97 (58.93) 0.460 - trig (median [IQR]) 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.80 (1.14) 0.197 - stage (%) 4 ( 2.6) 0.205 exact - 32 (20.8) - 64 (41.6) - 54 (35.1) + level 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + status (%) 0 83 (52.5) 85 (55.2) 0.884 exact + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + sex (%) m 21 (13.3) 15 ( 9.7) 0.421 + f 137 (86.7) 139 (90.3) + ascites (%) 0 144 (91.1) 144 (93.5) 0.567 + 1 14 ( 8.9) 10 ( 6.5) + hepato (%) 0 85 (53.8) 67 (43.5) 0.088 + 1 73 (46.2) 87 (56.5) + spiders (%) 0 113 (71.5) 109 (70.8) 0.985 + 1 45 (28.5) 45 (29.2) + edema (%) 0 132 (83.5) 131 (85.1) 0.877 + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 + stage (%) 1 12 ( 7.6) 4 ( 2.6) 0.205 exact + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) . "Stratified by trt" - "" "1" - "n" "158" - "time (mean (sd))" "2015.62 (1094.12)" - "status (%)" "" - " 0" "83 (52.5)" - " 1" "10 (6.3)" - " 2" "65 (41.1)" - "age (mean (sd))" "51.42 (11.01)" - "sex = f (%)" "137 (86.7)" - "ascites = 1 (%)" "14 (8.9)" - "hepato = 1 (%)" "73 (46.2)" - "spiders = 1 (%)" "45 (28.5)" - "edema (%)" "" - " 0" "132 (83.5)" - " 0.5" "16 (10.1)" - " 1" "10 (6.3)" - "bili (median [IQR])" "1.40 [0.80, 3.20]" - "chol (median [IQR])" "315.50 [247.75, 417.00]" - "albumin (mean (sd))" "3.52 (0.44)" - "copper (median [IQR])" "73.00 [40.00, 121.00]" - "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" - "ast (mean (sd))" "120.21 (54.52)" - "trig (median [IQR])" "106.00 [84.50, 146.00]" - "platelet (mean (sd))" "258.75 (100.32)" - "protime (mean (sd))" "10.65 (0.85)" - "stage (%)" "" - " 1" "12 (7.6)" - " 2" "35 (22.2)" - " 3" "56 (35.4)" - " 4" "55 (34.8)" - "Stratified by trt" - "" "2" "p" "test" - "n" "154" "" "" - "time (mean (sd))" "1996.86 (1155.93)" "0.883" "" - "status (%)" "" "0.884" "exact" - " 0" "85 (55.2)" "" "" - " 1" "9 (5.8)" "" "" - " 2" "60 (39.0)" "" "" - "age (mean (sd))" "48.58 (9.96)" "0.018" "" - "sex = f (%)" "139 (90.3)" "0.421" "" - "ascites = 1 (%)" "10 (6.5)" "0.567" "" - "hepato = 1 (%)" "87 (56.5)" "0.088" "" - "spiders = 1 (%)" "45 (29.2)" "0.985" "" - "edema (%)" "" "0.877" "" - " 0" "131 (85.1)" "" "" - " 0.5" "13 (8.4)" "" "" - " 1" "10 (6.5)" "" "" - "bili (median [IQR])" "1.30 [0.72, 3.60]" "0.842" "nonnorm" - "chol (median [IQR])" "303.50 [254.25, 377.00]" "0.544" "nonnorm" - "albumin (mean (sd))" "3.52 (0.40)" "0.874" "" - "copper (median [IQR])" "73.00 [43.00, 139.00]" "0.717" "nonnorm" - "alk.phos (median [IQR])" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" - "ast (mean (sd))" "124.97 (58.93)" "0.460" "" - "trig (median [IQR])" "113.00 [84.50, 155.00]" "0.370" "nonnorm" - "platelet (mean (sd))" "265.20 (90.73)" "0.555" "" - "protime (mean (sd))" "10.80 (1.14)" "0.197" "" - "stage (%)" "" "0.205" "exact" - " 1" "4 (2.6)" "" "" - " 2" "32 (20.8)" "" "" - " 3" "64 (41.6)" "" "" - " 4" "54 (35.1)" "" "" + "" "1" "2" "p" "test" + "n" "158" "154" "" "" + "time (mean (sd))" "2015.62 (1094.12)" "1996.86 (1155.93)" "0.883" "" + "status (%)" "" "" "0.884" "exact" + " 0" "83 (52.5)" "85 (55.2)" "" "" + " 1" "10 (6.3)" "9 (5.8)" "" "" + " 2" "65 (41.1)" "60 (39.0)" "" "" + "age (mean (sd))" "51.42 (11.01)" "48.58 (9.96)" "0.018" "" + "sex = f (%)" "137 (86.7)" "139 (90.3)" "0.421" "" + "ascites = 1 (%)" "14 (8.9)" "10 (6.5)" "0.567" "" + "hepato = 1 (%)" "73 (46.2)" "87 (56.5)" "0.088" "" + "spiders = 1 (%)" "45 (28.5)" "45 (29.2)" "0.985" "" + "edema (%)" "" "" "0.877" "" + " 0" "132 (83.5)" "131 (85.1)" "" "" + " 0.5" "16 (10.1)" "13 (8.4)" "" "" + " 1" "10 (6.3)" "10 (6.5)" "" "" + "bili (median [IQR])" "1.40 [0.80, 3.20]" "1.30 [0.72, 3.60]" "0.842" "nonnorm" + "chol (median [IQR])" "315.50 [247.75, 417.00]" "303.50 [254.25, 377.00]" "0.544" "nonnorm" + "albumin (mean (sd))" "3.52 (0.44)" "3.52 (0.40)" "0.874" "" + "copper (median [IQR])" "73.00 [40.00, 121.00]" "73.00 [43.00, 139.00]" "0.717" "nonnorm" + "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" + "ast (mean (sd))" "120.21 (54.52)" "124.97 (58.93)" "0.460" "" + "trig (median [IQR])" "106.00 [84.50, 146.00]" "113.00 [84.50, 155.00]" "0.370" "nonnorm" + "platelet (mean (sd))" "258.75 (100.32)" "265.20 (90.73)" "0.555" "" + "protime (mean (sd))" "10.65 (0.85)" "10.80 (1.14)" "0.197" "" + "stage (%)" "" "" "0.205" "exact" + " 1" "12 (7.6)" "4 (2.6)" "" "" + " 2" "35 (22.2)" "32 (20.8)" "" "" + " 3" "56 (35.4)" "64 (41.6)" "" "" + " 4" "55 (34.8)" "54 (35.1)" "" "" . Stratified by trt:sex - 1:m 2:m 1:f - n 21 15 137 - time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) - age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) - protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) - Stratified by trt:sex - 2:f p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - age (mean (sd)) 47.66 (9.54) <0.001 - protime (mean (sd)) 10.75 (1.15) 0.137 + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 . Stratified by trt:sex 1:m 2:m 1:f 2:f p test n 21 15 137 139 @@ -681,45 +457,25 @@ Unit tests for the CreateTableOne function : ................. 3 7 (33.3) 5 (33.3) 49 ( 35.8) 59 ( 42.4) 4 8 (38.1) 7 (46.7) 47 ( 34.3) 47 ( 33.8) . Stratified by trt:sex - 1:m 2:m 1:f 2:f - n 21 15 137 139 - status (%) - 0 4 (19.048) 7 (46.667) 79 ( 57.664) 78 ( 56.115) - 1 3 (14.286) 0 ( 0.000) 7 ( 5.109) 9 ( 6.475) - 2 14 (66.667) 8 (53.333) 51 ( 37.226) 52 ( 37.410) - sex = f (%) 0 ( 0.000) 0 ( 0.000) 137 (100.000) 139 (100.000) - ascites = 1 (%) 1 ( 4.762) 2 (13.333) 13 ( 9.489) 8 ( 5.755) - hepato = 1 (%) 12 (57.143) 9 (60.000) 61 ( 44.526) 78 ( 56.115) - spiders = 1 (%) 3 (14.286) 1 ( 6.667) 42 ( 30.657) 44 ( 31.655) - edema (%) - 0 17 (80.952) 12 (80.000) 115 ( 83.942) 119 ( 85.612) - 0.5 3 (14.286) 1 ( 6.667) 13 ( 9.489) 12 ( 8.633) - 1 1 ( 4.762) 2 (13.333) 9 ( 6.569) 8 ( 5.755) - stage (%) - 1 2 ( 9.524) 1 ( 6.667) 10 ( 7.299) 3 ( 2.158) - 2 4 (19.048) 2 (13.333) 31 ( 22.628) 30 ( 21.583) - 3 7 (33.333) 5 (33.333) 49 ( 35.766) 59 ( 42.446) - 4 8 (38.095) 7 (46.667) 47 ( 34.307) 47 ( 33.813) - Stratified by trt:sex - p test - n - status (%) 0.03270 - 0 - 1 - 2 - sex = f (%) <0.00001 - ascites = 1 (%) 0.51569 - hepato = 1 (%) 0.20806 - spiders = 1 (%) 0.08899 - edema (%) 0.90584 - 0 - 0.5 - 1 - stage (%) 0.64630 - 1 - 2 - 3 - 4 + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + status (%) 0.03270 + 0 4 (19.048) 7 (46.667) 79 ( 57.664) 78 ( 56.115) + 1 3 (14.286) 0 ( 0.000) 7 ( 5.109) 9 ( 6.475) + 2 14 (66.667) 8 (53.333) 51 ( 37.226) 52 ( 37.410) + sex = f (%) 0 ( 0.000) 0 ( 0.000) 137 (100.000) 139 (100.000) <0.00001 + ascites = 1 (%) 1 ( 4.762) 2 (13.333) 13 ( 9.489) 8 ( 5.755) 0.51569 + hepato = 1 (%) 12 (57.143) 9 (60.000) 61 ( 44.526) 78 ( 56.115) 0.20806 + spiders = 1 (%) 3 (14.286) 1 ( 6.667) 42 ( 30.657) 44 ( 31.655) 0.08899 + edema (%) 0.90584 + 0 17 (80.952) 12 (80.000) 115 ( 83.942) 119 ( 85.612) + 0.5 3 (14.286) 1 ( 6.667) 13 ( 9.489) 12 ( 8.633) + 1 1 ( 4.762) 2 (13.333) 9 ( 6.569) 8 ( 5.755) + stage (%) 0.64630 + 1 2 ( 9.524) 1 ( 6.667) 10 ( 7.299) 3 ( 2.158) + 2 4 (19.048) 2 (13.333) 31 ( 22.628) 30 ( 21.583) + 3 7 (33.333) 5 (33.333) 49 ( 35.766) 59 ( 42.446) + 4 8 (38.095) 7 (46.667) 47 ( 34.307) 47 ( 33.813) . Stratified by trt:sex 1:m 2:m 1:f 2:f n 21 15 137 139 @@ -1220,33 +976,19 @@ Column Total | 158 | 154 | 312 | platelet (mean (sd)) 257.02 (98.33) protime (mean (sd)) 10.73 (1.02) . Stratified by trt:sex - 1:m 2:m 1:f - n 21 15 137 - time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) - age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) - bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) - chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) - copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) - alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) - ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) - trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) - platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) - protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) - Stratified by trt:sex - 2:f p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - age (mean (sd)) 47.66 (9.54) <0.001 - bili (mean (sd)) 3.75 (5.50) 0.394 - chol (mean (sd)) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.53 (0.39) 0.585 - copper (mean (sd)) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 126.30 (60.27) 0.598 - trig (mean (sd)) 126.38 (60.22) 0.370 - platelet (mean (sd)) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.75 (1.15) 0.137 + 1:m 2:m 1:f 2:f p test + n 21 15 137 139 + time (mean (sd)) 1793.48 (1244.70) 2156.33 (1428.56) 2049.67 (1070.20) 1979.65 (1127.52) 0.730 + age (mean (sd)) 55.57 (12.61) 57.09 (10.07) 50.78 (10.65) 47.66 (9.54) <0.001 + bili (mean (sd)) 2.98 (2.11) 2.72 (2.46) 2.86 (3.81) 3.75 (5.50) 0.394 + chol (mean (sd)) 403.43 (204.95) 301.00 (111.32) 358.24 (210.46) 381.73 (262.26) 0.512 + albumin (mean (sd)) 3.63 (0.43) 3.50 (0.49) 3.50 (0.44) 3.53 (0.39) 0.585 + copper (mean (sd)) 174.90 (105.33) 125.40 (89.18) 85.71 (82.27) 94.64 (79.25) <0.001 + alk.phos (mean (sd)) 2486.16 (2385.32) 1734.45 (2478.07) 1950.04 (2151.35) 1965.52 (2066.15) 0.706 + ast (mean (sd)) 128.71 (48.74) 112.58 (44.38) 118.91 (55.40) 126.30 (60.27) 0.598 + trig (mean (sd)) 145.81 (56.62) 114.86 (39.59) 120.28 (73.41) 126.38 (60.22) 0.370 + platelet (mean (sd)) 232.65 (97.38) 240.13 (73.93) 262.59 (100.53) 267.95 (92.20) 0.362 + protime (mean (sd)) 10.84 (0.94) 11.23 (0.97) 10.62 (0.84) 10.75 (1.15) 0.137 . Stratified by trt 1 2 p test n 158 154 @@ -1276,61 +1018,33 @@ Column Total | 158 | 154 | 312 | platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) . Stratified by trt - 1 2 - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) - Stratified by trt - p test - n - time (mean (sd)) 0.883 - age (mean (sd)) 0.018 - bili (median [IQR]) 0.842 nonnorm - chol (median [IQR]) 0.544 nonnorm - albumin (mean (sd)) 0.874 - copper (median [IQR]) 0.717 nonnorm - alk.phos (median [IQR]) 0.812 nonnorm - ast (mean (sd)) 0.460 - trig (median [IQR]) 0.370 nonnorm - platelet (mean (sd)) 0.555 - protime (mean (sd)) 0.197 + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm + chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm + alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 . Stratified by trt - 1 - n 158 - time (mean (sd)) 2015.62 (1094.12) - age (mean (sd)) 51.42 (11.01) - bili (median [range]) 1.40 [0.30, 20.00] - chol (median [range]) 315.50 [127.00, 1712.00] - albumin (mean (sd)) 3.52 (0.44) - copper (median [range]) 73.00 [9.00, 588.00] - alk.phos (median [range]) 1214.50 [369.00, 11552.00] - ast (mean (sd)) 120.21 (54.52) - trig (median [range]) 106.00 [33.00, 598.00] - platelet (mean (sd)) 258.75 (100.32) - protime (mean (sd)) 10.65 (0.85) - Stratified by trt - 2 p test - n 154 - time (mean (sd)) 1996.86 (1155.93) 0.883 - age (mean (sd)) 48.58 (9.96) 0.018 - bili (median [range]) 1.30 [0.30, 28.00] 0.842 nonnorm - chol (median [range]) 303.50 [120.00, 1775.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.40) 0.874 - copper (median [range]) 73.00 [4.00, 558.00] 0.717 nonnorm - alk.phos (median [range]) 1283.00 [289.00, 13862.40] 0.812 nonnorm - ast (mean (sd)) 124.97 (58.93) 0.460 - trig (median [range]) 113.00 [44.00, 432.00] 0.370 nonnorm - platelet (mean (sd)) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.80 (1.14) 0.197 + 1 2 p test + n 158 154 + time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 + age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 + bili (median [range]) 1.40 [0.30, 20.00] 1.30 [0.30, 28.00] 0.842 nonnorm + chol (median [range]) 315.50 [127.00, 1712.00] 303.50 [120.00, 1775.00] 0.544 nonnorm + albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 + copper (median [range]) 73.00 [9.00, 588.00] 73.00 [4.00, 558.00] 0.717 nonnorm + alk.phos (median [range]) 1214.50 [369.00, 11552.00] 1283.00 [289.00, 13862.40] 0.812 nonnorm + ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 + trig (median [range]) 106.00 [33.00, 598.00] 113.00 [44.00, 432.00] 0.370 nonnorm + platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 + protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 . Stratified by trt 1 2 p test n 158 154 @@ -1489,7 +1203,7 @@ ast 158 0 0.0 120 54.5 112 76.7 152 26.4 338 1.09 1.6 trig 158 19 12.0 124 71.5 106 84.5 146 33.0 598 2.95 14.3 platelet 158 2 1.3 259 100.3 255 189.5 322 62.0 563 0.50 0.2 protime 158 0 0.0 11 0.9 11 10.0 11 9.0 14 1.10 1.6 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 n miss p.miss mean sd median p25 p75 min max skew kurt time 154 0 0.0 1997 1155.9 1811 1153.0 2771 51.0 4523 0.4 -0.7 @@ -1563,7 +1277,7 @@ trt: 1 3 56 35.4 65.2 4 55 34.8 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 var n miss p.miss level freq percent cum.percent status 154 0 0.0 0 85 55.2 55.2 @@ -1628,7 +1342,7 @@ ast 21 0 0 129 48.7 127 86 158 56.8 222 0.31 -0.9 trig 21 0 0 146 56.6 142 107 194 55.0 242 0.16 -1.0 platelet 21 1 5 233 97.4 228 148 314 70.0 394 -0.05 -1.2 protime 21 0 0 11 0.9 11 10 11 9.7 14 2.11 6.8 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: m n miss p.miss mean sd median p25 p75 min max skew kurt @@ -1643,7 +1357,7 @@ ast 15 0 0 113 44.4 110 74 129 46.5 188 0.3 -0.8 trig 15 1 7 115 39.6 108 90 137 49.0 188 0.4 -0.4 platelet 15 0 0 240 73.9 214 190 294 119.0 360 0.2 -1.0 protime 15 0 0 11 1.0 11 11 12 10.0 13 0.7 0.2 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 1 sex: f n miss p.miss mean sd median p25 p75 min max skew kurt @@ -1658,7 +1372,7 @@ ast 137 0 0.0 119 55.4 108 74.4 150 26.4 338 1.20 1.9 trig 137 19 13.9 120 73.4 101 84.0 134 33.0 598 3.28 16.0 platelet 137 1 0.7 263 100.5 258 194.2 322 62.0 563 0.57 0.3 protime 137 0 0.0 11 0.8 11 10.0 11 9.0 13 0.92 0.6 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: f n miss p.miss mean sd median p25 p75 min max skew kurt @@ -1689,30 +1403,18 @@ platelet 0.36247402287 0.44512771593 protime 0.13654633001 0.08114382938 Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -time 0.1556365 0.27083134 0.22071813 0.15677410 0.08450703 0.13729269 -age 0.5214974 0.13353519 0.40993004 0.70700091 0.60864596 0.96133382 -bili 0.1352025 0.11373946 0.04023105 0.18444097 0.04265701 0.24158721 -chol 0.2950579 0.62108339 0.21756422 0.09219212 0.33996564 0.40072828 -albumin 0.1637683 0.28262444 0.30878937 0.26228013 0.01074465 0.05159074 -copper 0.5416574 0.50727571 0.94378898 0.86116098 0.46259003 0.36464167 -alk.phos 0.1633259 0.30907333 0.23603622 0.23332162 0.09290687 0.10128012 -ast 0.1818681 0.34614452 0.18797132 0.04399580 0.12602823 0.25929154 -trig 0.2940632 0.63360898 0.38944815 0.33242327 0.09194315 0.22610097 -platelet 0.2340433 0.08655951 0.30251429 0.37226635 0.25448008 0.33286083 -protime 0.3283721 0.40162254 0.24596092 0.08476002 0.66430044 0.44433997 - 3 vs 4 -time 0.06369595 -age 0.30853876 -bili 0.18855913 -chol 0.09881382 -albumin 0.06658036 -copper 0.11048709 -alk.phos 0.00733728 -ast 0.12777729 -trig 0.09085446 -platelet 0.05557853 -protime 0.12924857 + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +time 0.1556365 0.27083134 0.22071813 0.15677410 0.08450703 0.13729269 0.06369595 +age 0.5214974 0.13353519 0.40993004 0.70700091 0.60864596 0.96133382 0.30853876 +bili 0.1352025 0.11373946 0.04023105 0.18444097 0.04265701 0.24158721 0.18855913 +chol 0.2950579 0.62108339 0.21756422 0.09219212 0.33996564 0.40072828 0.09881382 +albumin 0.1637683 0.28262444 0.30878937 0.26228013 0.01074465 0.05159074 0.06658036 +copper 0.5416574 0.50727571 0.94378898 0.86116098 0.46259003 0.36464167 0.11048709 +alk.phos 0.1633259 0.30907333 0.23603622 0.23332162 0.09290687 0.10128012 0.00733728 +ast 0.1818681 0.34614452 0.18797132 0.04399580 0.12602823 0.25929154 0.12777729 +trig 0.2940632 0.63360898 0.38944815 0.33242327 0.09194315 0.22610097 0.09085446 +platelet 0.2340433 0.08655951 0.30251429 0.37226635 0.25448008 0.33286083 0.05557853 +protime 0.3283721 0.40162254 0.24596092 0.08476002 0.66430044 0.44433997 0.12924857 ======================================================================================= @@ -1746,7 +1448,7 @@ sex: m 3 7 33.3 61.9 4 8 38.1 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: m var n miss p.miss level freq percent cum.percent @@ -1775,7 +1477,7 @@ sex: m 3 5 33.3 53.3 4 7 46.7 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 1 sex: f var n miss p.miss level freq percent cum.percent @@ -1804,7 +1506,7 @@ sex: f 3 49 35.8 65.7 4 47 34.3 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: f var n miss p.miss level freq percent cum.percent @@ -1845,22 +1547,14 @@ edema 9.058420e-01 8.483322e-01 stage 6.463005e-01 NA Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -status 0.5770647 0.79644734 0.8748771 0.83097631 0.4375075 0.46214324 -sex 0.0000000 0.00000000 0.0000000 0.00000000 0.0000000 0.00000000 -ascites 0.1755851 0.30219043 0.1845375 0.04452096 0.1211310 0.26007640 -hepato 0.1598214 0.05802589 0.2544151 0.02073917 0.3135916 0.07878788 -spiders 0.4018377 0.25073566 0.3999925 0.42200838 0.6471968 0.66954801 -edema 0.2122338 0.37625250 0.1624118 0.18063879 0.2420277 0.26502087 -stage 0.2773411 0.21945509 0.1333844 0.35632272 0.3000785 0.39205566 - 3 vs 4 -status 0.06043662 -sex 0.00000000 -ascites 0.14105454 -hepato 0.23336861 -spiders 0.02154469 -edema 0.04705137 -stage 0.26275030 + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +status 0.5770647 0.79644734 0.8748771 0.83097631 0.4375075 0.46214324 0.06043662 +sex 0.0000000 0.00000000 0.0000000 0.00000000 0.0000000 0.00000000 0.00000000 +ascites 0.1755851 0.30219043 0.1845375 0.04452096 0.1211310 0.26007640 0.14105454 +hepato 0.1598214 0.05802589 0.2544151 0.02073917 0.3135916 0.07878788 0.23336861 +spiders 0.4018377 0.25073566 0.3999925 0.42200838 0.6471968 0.66954801 0.02154469 +edema 0.2122338 0.37625250 0.1624118 0.18063879 0.2420277 0.26502087 0.04705137 +stage 0.2773411 0.21945509 0.1333844 0.35632272 0.3000785 0.39205566 0.26275030 . ### Summary of continuous variables ### @@ -1870,21 +1564,21 @@ sex: m time 21 0 0 1793 1244.7 1302 999 2386 140 4459 1.0 0.1 age 21 0 0 56 12.6 56 46 66 33 78 -0.2 -0.7 protime 21 0 0 11 0.9 11 10 11 10 14 2.1 6.8 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: m n miss p.miss mean sd median p25 p75 min max skew kurt time 15 0 0 2156 1429 1656 1054 3420 191 4427 0.3 -1.4 age 15 0 0 57 10 53 49 66 44 75 0.5 -1.3 protime 15 0 0 11 1 11 11 12 10 13 0.7 0.2 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 1 sex: f n miss p.miss mean sd median p25 p75 min max skew kurt time 137 0 0 2050 1070.2 1945 1293 2644 41 4556 0.32 -0.4 age 137 0 0 51 10.7 51 43 57 26 77 0.05 -0.5 protime 137 0 0 11 0.8 11 10 11 9 13 0.92 0.6 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: f n miss p.miss mean sd median p25 p75 min max skew kurt @@ -1899,14 +1593,10 @@ age 0.0001286381 0.0006517437 protime 0.1365463300 0.0811438294 Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -time 0.1556365 0.2708313 0.2207181 0.15677410 0.08450703 0.1372927 -age 0.5214974 0.1335352 0.4099300 0.70700091 0.60864596 0.9613338 -protime 0.3283721 0.4016225 0.2459609 0.08476002 0.66430044 0.4443400 - 3 vs 4 -time 0.06369595 -age 0.30853876 -protime 0.12924857 + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +time 0.1556365 0.2708313 0.2207181 0.15677410 0.08450703 0.1372927 0.06369595 +age 0.5214974 0.1335352 0.4099300 0.70700091 0.60864596 0.9613338 0.30853876 +protime 0.3283721 0.4016225 0.2459609 0.08476002 0.66430044 0.4443400 0.12924857 . ### Summary of categorical variables ### @@ -1923,7 +1613,7 @@ sex: m sex 21 0 0.0 m 21 100.0 100.0 f 0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: m var n miss p.miss level freq percent cum.percent @@ -1937,7 +1627,7 @@ sex: m sex 15 0 0.0 m 15 100.0 100.0 f 0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 1 sex: f var n miss p.miss level freq percent cum.percent @@ -1951,7 +1641,7 @@ sex: f sex 137 0 0.0 m 0 0.0 0.0 f 137 100.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- trt: 2 sex: f var n miss p.miss level freq percent cum.percent @@ -1986,17 +1676,17 @@ HI_CHOL: 0 RIAGENDR: 1 n miss p.miss mean sd median p25 p75 min max skew kurt race 3526 0 0 2 0.9 2 1 2 1 4 0.6 -0.3 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 1 RIAGENDR: 1 n miss p.miss mean sd median p25 p75 min max skew kurt race 363 0 0 2 0.9 2 1 2 1 4 0.8 -0.1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 0 RIAGENDR: 2 n miss p.miss mean sd median p25 p75 min max skew kurt race 3533 0 0 2 0.9 2 1 2 1 4 0.6 -0.4 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 1 RIAGENDR: 2 n miss p.miss mean sd median p25 p75 min max skew kurt @@ -2007,10 +1697,8 @@ p-values race 0.5071597 0.5761282 Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -race 0.04247045 0.03492105 0.0006074061 0.07524267 0.03396878 0.03638678 - 3 vs 4 -race 0.073696 + average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 3 vs 4 +race 0.04247045 0.03492105 0.0006074061 0.07524267 0.03396878 0.03638678 0.073696 ======================================================================================= @@ -2024,7 +1712,7 @@ RIAGENDR: 1 (39,59] 775 22.0 76.3 (59,Inf] 835 23.7 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 1 RIAGENDR: 1 var n miss p.miss level freq percent cum.percent @@ -2033,7 +1721,7 @@ RIAGENDR: 1 (39,59] 173 47.7 74.7 (59,Inf] 92 25.3 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 0 RIAGENDR: 2 var n miss p.miss level freq percent cum.percent @@ -2042,7 +1730,7 @@ RIAGENDR: 2 (39,59] 796 22.5 78.1 (59,Inf] 772 21.9 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- HI_CHOL: 1 RIAGENDR: 2 var n miss p.miss level freq percent cum.percent @@ -2064,23 +1752,14 @@ agecat 0.702331 0.9040822 0.109801 0.985333 0.8536402 0.3838583 0.9772713 n 3526 363 3533 424 race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 ... Stratified by HI_CHOL:RIAGENDR - 0:1 1:1 0:2 1:2 p - n 3526 363 3533 424 - race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 - agecat (%) <0.001 - (0,19] 1119 (31.7) 10 ( 2.8) 1015 (28.7) 6 ( 1.4) - (19,39] 797 (22.6) 88 (24.2) 950 (26.9) 70 (16.5) - (39,59] 775 (22.0) 173 (47.7) 796 (22.5) 167 (39.4) - (59,Inf] 835 (23.7) 92 (25.3) 772 (21.9) 181 (42.7) - Stratified by HI_CHOL:RIAGENDR - test SMD - n - race (mean (sd)) 0.042 - agecat (%) 0.702 - (0,19] - (19,39] - (39,59] - (59,Inf] + 0:1 1:1 0:2 1:2 p test SMD + n 3526 363 3533 424 + race (mean (sd)) 1.98 (0.85) 1.95 (0.90) 1.98 (0.87) 1.92 (0.76) 0.507 0.042 + agecat (%) <0.001 0.702 + (0,19] 1119 (31.7) 10 ( 2.8) 1015 (28.7) 6 ( 1.4) + (19,39] 797 (22.6) 88 (24.2) 950 (26.9) 70 (16.5) + (39,59] 775 (22.0) 173 (47.7) 796 (22.5) 167 (39.4) + (59,Inf] 835 (23.7) 92 (25.3) 772 (21.9) 181 (42.7) . Unit tests for svy* user functions : .......... Stratified by E 1 2 3 p test @@ -2110,37 +1789,29 @@ Unit tests for svy* user functions : .......... Stratified by E C1 = 1 (%) 150.0 (33.3) C2 (mean (sd)) 0.47 (0.50) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 - n 100.01 100.00 100.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) - C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) + 1:0 2:0 3:0 1:1 2:1 3:1 p + n 100.01 100.00 100.00 50.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 Stratified by E:C1 - 2:1 3:1 p test - n 50.00 50.00 - E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 - Y = 1 (%) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 - C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 - C2 (mean (sd)) 0.20 (0.40) 0.20 (0.40) <0.001 + test + n + E (mean (sd)) + C (mean (sd)) + Y = 1 (%) + C1 = 1 (%) + C2 (mean (sd)) . Stratified by E - 1 2 3 - n 150.0120 150.0030 150.0000 - E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) - C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) - Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) - C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) - C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) - Stratified by E - p test - n - E (mean (sd)) <0.00001 - C (mean (sd)) 1.00000 - Y = 1 (%) 0.99982 - C1 = 1 (%) 1.00000 - C2 (mean (sd)) 1.00000 + 1 2 3 p test + n 150.0120 150.0030 150.0000 + E (mean (sd)) 1.0000 (0.0000) 2.0000 (0.0000) 3.0000 (0.0000) <0.00001 + C (mean (sd)) 2.1332 (0.8854) 2.1333 (0.8861) 2.1333 (0.8861) 1.00000 + Y = 1 (%) 59.001 (39.406) 59.001 (39.333) 59.000 (39.333) 0.99982 + C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.00000 + C2 (mean (sd)) 0.4666 (0.4994) 0.4667 (0.4999) 0.4667 (0.4998) 1.00000 . Stratified by E 1 2 3 n 150.01 150.00 150.00 @@ -2150,37 +1821,21 @@ Unit tests for svy* user functions : .......... Stratified by E C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) . Stratified by E - 1 2 3 - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) - Stratified by E - p test - n - E (mean (sd)) <0.001 - C (median [IQR]) 1.000 nonnorm - Y = 1 (%) NA exact - C1 = 1 (%) 1.000 - C2 (mean (sd)) 1.000 + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) NA exact + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E - 1 2 - n 150.01 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) - C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] - Y = 1 (%) 59.0 (39.4) 59.0 (39.3) - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) - Stratified by E - 3 p test - n 150.00 - E (mean (sd)) 3.00 (0.00) <0.001 - C (median [range]) 2.00 [1.00, 4.00] 1.000 nonnorm - Y = 1 (%) 59.0 (39.3) 1.000 - C1 = 1 (%) 50.0 (33.3) 1.000 - C2 (mean (sd)) 0.47 (0.50) 1.000 + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm + Y = 1 (%) 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -2190,61 +1845,33 @@ Unit tests for svy* user functions : .......... Stratified by E C1 = 1 (%) 50.000 (33.331) 50.000 (33.333) 50.000 (33.333) 1.000 C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E - level 1 2 - n 150.01 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] - Y (%) 0 90.7 (60.6) 91.0 (60.7) - 1 59.0 (39.4) 59.0 (39.3) - C1 (%) 0 100.0 (66.7) 100.0 (66.7) - 1 50.0 (33.3) 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) - Stratified by E - 3 p test - n 150.00 - E (mean (sd)) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 1.000 nonnorm - Y (%) 91.0 (60.7) NA exact - 59.0 (39.3) - C1 (%) 100.0 (66.7) 1.000 - 50.0 (33.3) - C2 (mean (sd)) 0.47 (0.50) 1.000 + level 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + Y (%) 0 90.7 (60.6) 91.0 (60.7) 91.0 (60.7) NA exact + 1 59.0 (39.4) 59.0 (39.3) 59.0 (39.3) + C1 (%) 0 100.0 (66.7) 100.0 (66.7) 100.0 (66.7) 1.000 + 1 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . "Stratified by E" - "" "1" "2" - "n" "150.01" "150.00" - "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" - "C (median [IQR])" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" - "Y = 1 (%)" "59.001 (39.406)" "59.001 (39.333)" - "C1 = 1 (%)" "50.000 (33.331)" "50.000 (33.333)" - "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" - "Stratified by E" - "" "3" "p" "test" - "n" "150.00" "" "" - "E (mean (sd))" "3.00 (0.00)" "<0.001" "" - "C (median [IQR])" "2.00 [1.00, 3.00]" "1.000" "nonnorm" - "Y = 1 (%)" "59.000 (39.333)" "NA" "exact" - "C1 = 1 (%)" "50.000 (33.333)" "1.000" "" - "C2 (mean (sd))" "0.47 (0.50)" "1.000" "" + "" "1" "2" "3" "p" "test" + "n" "150.01" "150.00" "150.00" "" "" + "E (mean (sd))" "1.00 (0.00)" "2.00 (0.00)" "3.00 (0.00)" "<0.001" "" + "C (median [IQR])" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "2.00 [1.00, 3.00]" "1.000" "nonnorm" + "Y = 1 (%)" "59.001 (39.406)" "59.001 (39.333)" "59.000 (39.333)" "NA" "exact" + "C1 = 1 (%)" "50.000 (33.331)" "50.000 (33.333)" "50.000 (33.333)" "1.000" "" + "C2 (mean (sd))" "0.47 (0.50)" "0.47 (0.50)" "0.47 (0.50)" "1.000" "" . Stratified by E:C1 - 1:0 2:0 3:0 1:1 - n 100.01 100.00 100.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) - Stratified by E:C1 - 2:1 3:1 p test - n 50.00 50.00 - E (mean (sd)) 2.00 (0.00) 3.00 (0.00) <0.001 - C (mean (sd)) 3.20 (0.40) 3.20 (0.40) <0.001 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.01 100.00 100.00 50.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 . Stratified by E:C1 - 1:0 2:0 3:0 1:1 - n 100.0 100.0 100.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) - Stratified by E:C1 - 2:1 3:1 p test - n 50.0 50.0 - Y = 1 (%) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 - C1 = 1 (%) 50.0 (100.0) 50.0 (100.0) <0.001 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 . Stratified by E 1 2 3 p test n 150.0 150.0 150.0 @@ -2264,40 +1891,25 @@ Unit tests for svy* user functions : .......... Stratified by E NA 0.3 ( 0.1) C1 = 1 (%) 150.0 (33.3) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 - n 100.0 100.0 100.0 50.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) - Stratified by E:C1 - 3:1 p test - n 50.0 - Y = 1 (%) 37.0 ( 74.0) <0.001 - C1 = 1 (%) 50.0 (100.0) <0.001 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 . Stratified by E:C1 - 1:0 2:0 3:0 - n 100.012 100.003 100.000 - Y = 1 (%) 22.001 (22.062) 22.001 (22.000) 22.000 (22.000) - C1 = 1 (%) 0.000 ( 0.000) 0.000 ( 0.000) 0.000 ( 0.000) - Stratified by E:C1 - 1:1 2:1 3:1 p - n 50.000 50.000 50.000 - Y = 1 (%) 37.000 ( 74.000) 37.000 ( 74.000) 37.000 ( 74.000) <0.00001 - C1 = 1 (%) 50.000 (100.000) 50.000 (100.000) 50.000 (100.000) <0.00001 + 1:0 2:0 3:0 1:1 2:1 + n 100.012 100.003 100.000 50.000 50.000 + Y = 1 (%) 22.001 (22.062) 22.001 (22.000) 22.000 (22.000) 37.000 ( 74.000) 37.000 ( 74.000) + C1 = 1 (%) 0.000 ( 0.000) 0.000 ( 0.000) 0.000 ( 0.000) 50.000 (100.000) 50.000 (100.000) Stratified by E:C1 - test - n - Y = 1 (%) - C1 = 1 (%) + 3:1 p test + n 50.000 + Y = 1 (%) 37.000 ( 74.000) <0.00001 + C1 = 1 (%) 50.000 (100.000) <0.00001 . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 - n 100.0 100.0 100.0 50.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) - Stratified by E:C1 - 3:1 - n 50.0 - Y = 1 (%) 37.0 ( 74.0) - C1 = 1 (%) 50.0 (100.0) + 1:0 2:0 3:0 1:1 2:1 3:1 + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) . Stratified by E 1 2 3 p test n 150.012 150.003 150.000 @@ -2331,15 +1943,10 @@ Unit tests for svy* user functions : .......... Stratified by E Y = 1 % (freq) 39.4 (59.0) 39.3 (59.0) 39.3 (59.0) 1.000 C1 = 1 % (freq) 33.3 (50.0) 33.3 (50.0) 33.3 (50.0) 1.000 . Stratified by E - 1 2 - n 150.0 150.0 - Y = 0/1 (%) 90.7/59.0 (60.6/39.4) 91.0/59.0 (60.7/39.3) - C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) - Stratified by E - 3 p test - n 150.0 - Y = 0/1 (%) 91.0/59.0 (60.7/39.3) 1.000 - C1 = 1 (%) 50.0 (33.3) 1.000 + 1 2 3 p test + n 150.0 150.0 150.0 + Y = 0/1 (%) 90.7/59.0 (60.6/39.4) 91.0/59.0 (60.7/39.3) 91.0/59.0 (60.7/39.3) 1.000 + C1 = 1 (%) 50.0 (33.3) 50.0 (33.3) 50.0 (33.3) 1.000 . "Stratified by E" "" "level" "1" "2" "3" "p" "test" "n" "" "150.0" "150.0" "150.0" "" "" @@ -2348,15 +1955,10 @@ Unit tests for svy* user functions : .......... Stratified by E "C1 (%)" "0" "100.0 (66.7)" "100.0 (66.7)" "100.0 (66.7)" "1.000" "" "" "1" "50.0 (33.3)" "50.0 (33.3)" "50.0 (33.3)" "" "" . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 - n 100.0 100.0 100.0 50.0 50.0 - Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) - C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) - Stratified by E:C1 - 3:1 p test - n 50.0 - Y = 1 (%) 37.0 ( 74.0) <0.001 - C1 = 1 (%) 50.0 (100.0) <0.001 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.0 100.0 100.0 50.0 50.0 50.0 + Y = 1 (%) 22.0 (22.1) 22.0 (22.0) 22.0 (22.0) 37.0 ( 74.0) 37.0 ( 74.0) 37.0 ( 74.0) <0.001 + C1 = 1 (%) 0.0 ( 0.0) 0.0 ( 0.0) 0.0 ( 0.0) 50.0 (100.0) 50.0 (100.0) 50.0 (100.0) <0.001 Cell Contents @@ -2440,17 +2042,11 @@ Column Total | 100 | 100 | 100 | 50 | 50 | C (mean (sd)) 2.13 (0.88) C2 (mean (sd)) 0.47 (0.50) . Stratified by E:C1 - 1:0 2:0 3:0 1:1 2:1 - n 100.01 100.00 100.00 50.00 50.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) - C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) - C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) - Stratified by E:C1 - 3:1 p test - n 50.00 - E (mean (sd)) 3.00 (0.00) <0.001 - C (mean (sd)) 3.20 (0.40) <0.001 - C2 (mean (sd)) 0.20 (0.40) <0.001 + 1:0 2:0 3:0 1:1 2:1 3:1 p test + n 100.01 100.00 100.00 50.00 50.00 50.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (mean (sd)) 1.60 (0.49) 1.60 (0.49) 1.60 (0.49) 3.20 (0.40) 3.20 (0.40) 3.20 (0.40) <0.001 + C2 (mean (sd)) 0.60 (0.49) 0.60 (0.49) 0.60 (0.49) 0.20 (0.40) 0.20 (0.40) 0.20 (0.40) <0.001 . Stratified by E 1 2 3 p test n 150.012 150.003 150.000 @@ -2464,29 +2060,17 @@ Column Total | 100 | 100 | 100 | 50 | 50 | C (mean (sd)) 2.13 (0.89) 2.13 (0.89) 2.13 (0.89) C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) . Stratified by E - 1 2 3 p - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 - C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 - Stratified by E - test - n - E (mean (sd)) - C (median [IQR]) nonnorm - C2 (mean (sd)) + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [IQR]) 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 2.00 [1.00, 3.00] 1.000 nonnorm + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E - 1 2 3 - n 150.01 150.00 150.00 - E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) - C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] - C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) - Stratified by E - p test - n - E (mean (sd)) <0.001 - C (median [range]) 1.000 nonnorm - C2 (mean (sd)) 1.000 + 1 2 3 p test + n 150.01 150.00 150.00 + E (mean (sd)) 1.00 (0.00) 2.00 (0.00) 3.00 (0.00) <0.001 + C (median [range]) 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 2.00 [1.00, 4.00] 1.000 nonnorm + C2 (mean (sd)) 0.47 (0.50) 0.47 (0.50) 0.47 (0.50) 1.000 . Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -2572,155 +2156,80 @@ Column Total | 100 | 100 | 100 | 50 | 50 | (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 - Stratified by RIAGENDR - test - n - HI_CHOL (mean (sd)) - race (%) - 1 - 2 - 3 - 4 - agecat (%) - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 - race (%) 0.0416288 - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.0011757 - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 - Stratified by RIAGENDR - test - n - HI_CHOL (mean (sd)) - race (%) - 1 - 2 - 3 - 4 - agecat (%) - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.0092211 + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] - race (%) - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) - Stratified by RIAGENDR - p test - n - HI_CHOL (median [IQR]) 0.0092211 nonnorm - race (%) 0.0416288 - 1 - 2 - 3 - 4 - agecat (%) 0.0011757 - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) <0.0000001 + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . Stratified by RIAGENDR - 1 2 p - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.189 (15.845) 20251367.389 ( 14.303) - 2 89315751.415 (66.187) 92486945.142 ( 65.319) - 3 15045455.461 (11.149) 17967228.319 ( 12.689) - 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) - agecat (%) 0.001 - (0,19] 29299546.109 (21.712) 28150760.544 ( 19.882) - (19,39] 40497613.070 (30.011) 40640361.534 ( 28.702) - (39,59] 41053579.409 (30.423) 42817044.014 ( 30.240) - (59,Inf] 24093815.335 (17.855) 29983725.904 ( 21.176) - RIAGENDR = 2 (%) 0.000 ( 0.000) 141591891.998 (100.000) <0.001 - Stratified by RIAGENDR - test - n - HI_CHOL (mean (sd)) - race (%) - 1 - 2 - 3 - 4 - agecat (%) - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 + race (%) 0.042 + 1 21381884.189 (15.845) 20251367.389 ( 14.303) + 2 89315751.415 (66.187) 92486945.142 ( 65.319) + 3 15045455.461 (11.149) 17967228.319 ( 12.689) + 4 9201462.858 ( 6.819) 10886351.148 ( 7.689) + agecat (%) 0.001 + (0,19] 29299546.109 (21.712) 28150760.544 ( 19.882) + (19,39] 40497613.070 (30.011) 40640361.534 ( 28.702) + (39,59] 41053579.409 (30.423) 42817044.014 ( 30.240) + (59,Inf] 24093815.335 (17.855) 29983725.904 ( 21.176) + RIAGENDR = 2 (%) 0.000 ( 0.000) 141591891.998 (100.000) <0.001 .. Stratified by RIAGENDR - 1 2 - n 134944553.92 141591892.00 - HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] - race (%) - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) - Stratified by RIAGENDR - p test - n - HI_CHOL (median [IQR]) 0.0092211 nonnorm - race (%) 0.0416288 - 1 - 2 - 3 - 4 - agecat (%) 0.0011757 - (0,19] - (19,39] - (39,59] - (59,Inf] - RIAGENDR = 2 (%) <0.0000001 + 1 2 p test + n 134944553.92 141591892.00 + HI_CHOL (median [IQR]) 0.00 [0.00, 0.00] 0.00 [0.00, 0.00] 0.0092211 nonnorm + race (%) 0.0416288 + 1 21381884.2 (15.8) 20251367.4 ( 14.3) + 2 89315751.4 (66.2) 92486945.1 ( 65.3) + 3 15045455.5 (11.1) 17967228.3 ( 12.7) + 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) + agecat (%) 0.0011757 + (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) + (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) + (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) + (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) + RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.0000001 . ### Summary of continuous variables ### @@ -2772,13 +2281,13 @@ E: 1 E 150 0 0 1.0 0.0 1 1 1 1 1 C 150 0 0 2.1 0.9 2 1 3 1 4 C2 150 0 0 0.5 0.5 0 0 1 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E: 2 n miss p.miss mean sd median p25 p75 min max E 150 0 0 2.0 0.0 2 2 2 2 2 C 150 0 0 2.1 0.9 2 1 3 1 4 C2 150 0 0 0.5 0.5 0 0 1 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E: 3 n miss p.miss mean sd median p25 p75 min max E 150 0 0 3.0 0.0 3 3 3 3 3 @@ -2809,7 +2318,7 @@ E: 1 C1 150.0 0.0 0.0 0 100.0 66.7 66.7 1 50.0 33.3 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E: 2 var n miss p.miss level freq percent cum.percent Y 150.0 0.0 0.0 0 91.0 60.7 60.7 @@ -2818,7 +2327,7 @@ E: 2 C1 150.0 0.0 0.0 0 100.0 66.7 66.7 1 50.0 33.3 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E: 3 var n miss p.miss level freq percent cum.percent Y 150.0 0.0 0.0 0 91.0 60.7 60.7 @@ -2845,31 +2354,31 @@ E:C1: 1:0 E 100 0 0 1.0 0.0 1 1 1 1 1 C 100 0 0 1.6 0.5 2 1 2 1 2 C2 100 0 0 0.6 0.5 1 0 1 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:0 n miss p.miss mean sd median p25 p75 min max E 100 0 0 2.0 2e-16 2 2 2 2 2 C 100 0 0 1.6 5e-01 2 1 2 1 2 C2 100 0 0 0.6 5e-01 1 0 1 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:0 n miss p.miss mean sd median p25 p75 min max E 100 0 0 3.0 0.0 3 3 3 3 3 C 100 0 0 1.6 0.5 2 1 2 1 2 C2 100 0 0 0.6 0.5 1 0 1 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 1:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 1.0 0.0 1 1 1 1 1 C 50 0 0 3.2 0.4 3 3 3 3 4 C2 50 0 0 0.2 0.4 0 0 0 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 2.0 0.0 2 2 2 2 2 C 50 0 0 3.2 0.4 3 3 3 3 4 C2 50 0 0 0.2 0.4 0 0 0 0 1 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 3.0 0.0 3 3 3 3 3 @@ -2883,18 +2392,14 @@ C 2.518377e-307 0.00000e+00 C2 1.950910e-37 1.95091e-37 Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 -E NaN 6.350292e+15 Inf NaN Inf Inf -C 2.1373647 1.710913e-04 0.000146495 3.5608223 3.5673100 3.5708236 -C2 0.5343248 1.710913e-04 0.000146495 0.8900053 0.8916269 0.8925051 - 2 vs 3 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 -E 6.350292e+15 6.350292e+15 1.4100480 6.350292e+15 Inf Inf -C 2.439672e-05 3.556921e+00 3.5633882 3.566891e+00 3.5525326 3.5589756 -C2 2.439672e-05 8.892636e-01 0.8908805 8.917561e-01 0.8881331 0.8897439 - 3 vs 6 4 vs 5 4 vs 6 5 vs 6 -E NaN Inf Inf Inf -C 3.5624649 0 0 0 -C2 0.8906162 0 0 0 + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 2 vs 4 2 vs 5 +E NaN 6.350292e+15 Inf NaN Inf Inf 6.350292e+15 6.350292e+15 1.4100480 +C 2.1373647 1.710913e-04 0.000146495 3.5608223 3.5673100 3.5708236 2.439672e-05 3.556921e+00 3.5633882 +C2 0.5343248 1.710913e-04 0.000146495 0.8900053 0.8916269 0.8925051 2.439672e-05 8.892636e-01 0.8908805 + 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +E 6.350292e+15 Inf Inf NaN Inf Inf Inf +C 3.566891e+00 3.5525326 3.5589756 3.5624649 0 0 0 +C2 8.917561e-01 0.8881331 0.8897439 0.8906162 0 0 0 ======================================================================================= @@ -2908,7 +2413,7 @@ E:C1: 1:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:0 var n miss p.miss level freq percent cum.percent Y 100.0 0.0 0.0 0 78.0 78.0 78.0 @@ -2917,7 +2422,7 @@ E:C1: 2:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:0 var n miss p.miss level freq percent cum.percent Y 100.0 0.0 0.0 0 78.0 78.0 78.0 @@ -2926,7 +2431,7 @@ E:C1: 3:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 1:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -2935,7 +2440,7 @@ E:C1: 1:1 C1 50.0 0.0 0.0 0 0.0 0.0 0.0 1 50.0 100.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -2944,7 +2449,7 @@ E:C1: 2:1 C1 50.0 0.0 0.0 0 0.0 0.0 0.0 1 50.0 100.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -2960,12 +2465,12 @@ Y 4.540885e-31 NA C1 4.640660e-128 NA Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 -Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 -C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 - 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 -Y 1.218891 1.218891 1.218891 1.218899 1.218899 1.218899 0 0 0 -C1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0 0 0 + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 2 vs 4 2 vs 5 2 vs 6 3 vs 4 +Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 1.218891 1.218891 1.218891 1.218899 +C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 0.000000 0.000000 0.000000 0.000000 + 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +Y 1.218899 1.218899 0 0 0 +C1 0.000000 0.000000 0 0 0 . ### Summary of continuous variables ### @@ -2973,27 +2478,27 @@ E:C1: 1:0 n miss p.miss mean sd median p25 p75 min max E 100 0 0 1 0.0 1 1 1 1 1 C 100 0 0 2 0.5 2 1 2 1 2 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:0 n miss p.miss mean sd median p25 p75 min max E 100 0 0 2 2e-16 2 2 2 2 2 C 100 0 0 2 5e-01 2 1 2 1 2 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:0 n miss p.miss mean sd median p25 p75 min max E 100 0 0 3 0.0 3 3 3 3 3 C 100 0 0 2 0.5 2 1 2 1 2 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 1:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 1 0.0 1 1 1 1 1 C 50 0 0 3 0.4 3 3 3 3 4 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 2 0.0 2 2 2 2 2 C 50 0 0 3 0.4 3 3 3 3 4 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:1 n miss p.miss mean sd median p25 p75 min max E 50 0 0 3 0.0 3 3 3 3 3 @@ -3005,15 +2510,12 @@ E 0.000000e+00 0 C 2.518377e-307 0 Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 -E NaN 6.350292e+15 Inf NaN Inf Inf 6.350292e+15 -C 2.137365 1.710913e-04 0.000146495 3.560822 3.56731 3.570824 2.439672e-05 - 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 -E 6.350292e+15 1.410048 6.350292e+15 Inf Inf NaN Inf Inf -C 3.556921e+00 3.563388 3.566891e+00 3.552533 3.558976 3.562465 0 0 - 5 vs 6 -E Inf -C 0 + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 2 vs 4 2 vs 5 2 vs 6 +E NaN 6.350292e+15 Inf NaN Inf Inf 6.350292e+15 6.350292e+15 1.410048 6.350292e+15 +C 2.137365 1.710913e-04 0.000146495 3.560822 3.56731 3.570824 2.439672e-05 3.556921e+00 3.563388 3.566891e+00 + 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +E Inf Inf NaN Inf Inf Inf +C 3.552533 3.558976 3.562465 0 0 0 . ### Summary of categorical variables ### @@ -3025,7 +2527,7 @@ E:C1: 1:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:0 var n miss p.miss level freq percent cum.percent Y 100.0 0.0 0.0 0 78.0 78.0 78.0 @@ -3034,7 +2536,7 @@ E:C1: 2:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:0 var n miss p.miss level freq percent cum.percent Y 100.0 0.0 0.0 0 78.0 78.0 78.0 @@ -3043,7 +2545,7 @@ E:C1: 3:0 C1 100.0 0.0 0.0 0 100.0 100.0 100.0 1 0.0 0.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 1:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -3052,7 +2554,7 @@ E:C1: 1:1 C1 50.0 0.0 0.0 0 0.0 0.0 0.0 1 50.0 100.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 2:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -3061,7 +2563,7 @@ E:C1: 2:1 C1 50.0 0.0 0.0 0 0.0 0.0 0.0 1 50.0 100.0 100.0 ------------------------------------------------------------- +--------------------------------------------------------------------------------------- E:C1: 3:1 var n miss p.miss level freq percent cum.percent Y 50.0 0.0 0.0 0 13.0 26.0 26.0 @@ -3077,12 +2579,12 @@ Y 4.540885e-31 NA C1 4.640660e-128 NA Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 -Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 -C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 - 2 vs 4 2 vs 5 2 vs 6 3 vs 4 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 -Y 1.218891 1.218891 1.218891 1.218899 1.218899 1.218899 0 0 0 -C1 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0 0 0 + average 1 vs 2 1 vs 3 1 vs 4 1 vs 5 1 vs 6 2 vs 3 2 vs 4 2 vs 5 2 vs 6 3 vs 4 +Y 0.7311319 0.001480611 0.001486405 1.216879 1.216879 1.216879 0.000005793469 1.218891 1.218891 1.218891 1.218899 +C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 0.000000 0.000000 0.000000 0.000000 + 3 vs 5 3 vs 6 4 vs 5 4 vs 6 5 vs 6 +Y 1.218899 1.218899 0 0 0 +C1 0.000000 0.000000 0 0 0 . Unit tests for the survey-related modules : ................................................ diff --git a/tests/testthat/test-CreateTableOne.R b/tests/testthat/test-CreateTableOne.R index c13c060..88e85f2 100644 --- a/tests/testthat/test-CreateTableOne.R +++ b/tests/testthat/test-CreateTableOne.R @@ -307,12 +307,11 @@ test_that("summary method works without errors", { ## Expectations summary(pbcOverall) - expect_output(summary(pbcOverall), - "time 418 0 0.0 1918 1104.7 1730 1092.8 2614 41.0 4795 0.47 -0.5") + expect_output(summary(pbcOverall), "strata: Overall") summary(pbcInclNa) - expect_output(summary(pbcInclNa), " 6 1.4 100.0") + expect_output(summary(pbcInclNa), "") summary(pbcByTrt) - expect_output(summary(pbcByTrt), "hepato 0.20699413") + expect_output(summary(pbcByTrt), "Standardize mean differences") summary(pbcByTrtSex) expect_output(summary(pbcByTrtSex), "Standardize mean differences") @@ -320,7 +319,6 @@ test_that("summary method works without errors", { expect_output(summary(pbcContOnlyByTrtSex), "### Summary of continuous variables ###") summary(pbcCatOnlyByTrtSex) - expect_output(summary(pbcCatOnlyByTrtSex), - "status 0.5770647 0.7964473 0.8748771 0.8309763 0.4375075 0.4621432 0.06043662") + expect_output(summary(pbcCatOnlyByTrtSex), "3 vs 4") }) diff --git a/tests/testthat/test-svyCreateTableOne.R b/tests/testthat/test-svyCreateTableOne.R index e5f0c3a..7793047 100644 --- a/tests/testthat/test-svyCreateTableOne.R +++ b/tests/testthat/test-svyCreateTableOne.R @@ -424,12 +424,11 @@ test_that("summary method works without errors", { ## Expectations summary(mwOverall) - expect_output(summary(mwOverall), - "n miss p.miss mean sd median p25 p75 min max") + expect_output(summary(mwOverall), "### Summary of categorical variables ### ") summary(mwInclNa) - expect_output(summary(mwInclNa), " 0.3 0.1 100.0") + expect_output(summary(mwInclNa), "") summary(mwByE) - expect_output(summary(mwByE), "Y 0.00099495892 0.00149243839 0.00148861716 0.000003821227") + expect_output(summary(mwByE), "2 vs 3") summary(mwByEC1) expect_output(summary(mwByEC1), "Standardize mean differences") From f40e97ac1e975dbd1fff1d753af05081921b244a Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Fri, 31 Jul 2015 18:52:37 -0400 Subject: [PATCH 150/219] Change file names of internal modules files --- R/{smdModules.R => modules-smd.R} | 0 R/{svyModules.R => modules-svy.R} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename R/{smdModules.R => modules-smd.R} (100%) rename R/{svyModules.R => modules-svy.R} (100%) diff --git a/R/smdModules.R b/R/modules-smd.R similarity index 100% rename from R/smdModules.R rename to R/modules-smd.R diff --git a/R/svyModules.R b/R/modules-svy.R similarity index 100% rename from R/svyModules.R rename to R/modules-svy.R From 9f2dc2f6f2c2f35fe70cd3c004ea5032ce5f4e6e Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:06:48 -0400 Subject: [PATCH 151/219] Correction to constructor documents --- R/CreateCatTable.R | 6 +++--- R/CreateContTable.R | 4 ++-- R/CreateTableOne.R | 11 +++++------ R/svyCreateCatTable.R | 1 + R/svyCreateContTable.R | 5 +---- R/svyCreateTableOne.R | 5 ++--- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index c5dbb49..2cb6e24 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -18,9 +18,9 @@ ##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. ##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, ##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load @@ -63,7 +63,7 @@ ##' ##' ## print now includes p-values which are by default calculated by chisq.test. ##' ## It is formatted at the decimal place specified by the pDigits argument -##' ## (3 by default). It does <0.001 for you. +##' ## (3 by default). It is formatted like <0.001 if very small. ##' catTableBySexTrt ##' ##' ## The exact argument toggles the p-values to the exact test result from diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 7578166..ac1814d 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -20,8 +20,8 @@ ##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) ##' @seealso ##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 769c3a5..81fe506 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -1,4 +1,4 @@ -##' Create an object summarizing both categorical and continuous variables +##' Create an object summarizing both continuous and categorical variables ##' ##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. ##' @@ -18,12 +18,11 @@ ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{TableOne}, which really is a list of three objects. -##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} -##' @return \item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} -##' @return \item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} -##' @return The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +##' @return \item{ContTable}{object of class \code{ContTable}, containing continuous variables only} +##' @return \item{CatTable}{object of class \code{CatTable}, containing categorical variables only} +##' @return \item{MetaData}{list of metadata regarding variables} ##' -##' @author Justin Bohn, Kazuki Yoshida +##' @author Kazuki Yoshida, Justin Bohn ##' @seealso ##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, ##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index bf72bf2..2e2f8b9 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -4,6 +4,7 @@ ##' by one or more startifying variables and performing statistical tests. The ##' object gives a table that is easy to use in medical research papers. See ##' also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. +##' \code{\link{svyCreateTableOne}} should be used as the universal frontend. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index 39a4195..de76504 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -1,9 +1,6 @@ ##' Create an object summarizing continous variables for weighted dataset ##' -##' Create an object summarizing continous variables optionally stratifying by -##' one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. +##' Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. \code{\link{svyCreateTableOne}} should be used as the universal frontend. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 54ee570..3b8728f 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -1,4 +1,4 @@ -##' Create an object summarizing any variables for weighted data +##' Create an object summarizing both continuous and categorical variables for weighted data ##' ##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. ##' @@ -16,10 +16,9 @@ ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{svyTableOne}, which really is a list of three objects. -##' @return \item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} ##' @return \item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} ##' @return \item{CatTable}{ an object of class \code{svyCatTable}, containing categorical variables only} -##' @return The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +##' @return \item{MetaData}{list of metadata regarding variables} ##' ##' @author Kazuki Yoshida ##' @seealso From e3c2cabef143534dcd5e8b7c9ebbd8ec39dffb1d Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:09:36 -0400 Subject: [PATCH 152/219] Update ShowRegTable function to have ciFun argument confint is default can specify confint.default --- R/ShowRegTable.R | 19 +++--- tests/testthat/test-ShowRegTable.R | 96 ++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/test-ShowRegTable.R diff --git a/R/ShowRegTable.R b/R/ShowRegTable.R index b083a60..b334b19 100644 --- a/R/ShowRegTable.R +++ b/R/ShowRegTable.R @@ -9,7 +9,7 @@ ##' @param pDigits Number of digits to print for the p-values. ##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. -##' @param simpleCi Whether to calculate confidence interval by the default normal approximation method. The default is FALSE. If TRUE, the default normal approximation method is used. This may be used when the profile likelihood-based calculation takes too much time. +##' @param ciFun Function used for calculation. \code{confint} is the default. For generalized linear models this gives the profile likelihood-based calculation, which may take too much time for large models. Use \code{confint.default} for simple normal approximation method (+/- 1.96 * standard error). ##' @return A matrix containing what you see is returned invisibly. You can capture it by assignment to an object. ##' @author Kazuki Yoshida ##' @examples @@ -35,11 +35,7 @@ ##' ##' @export ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle = TRUE, - quote = FALSE, simpleCi = FALSE) { - - if (simpleCi) { - confint <- confint.default - } + quote = FALSE, ciFun = confint) { ## Create formats fmt1 <- paste0("%.", digits, "f") @@ -48,7 +44,7 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle ## Obtain necessary data ## The model must have summary and confint methods modelCoef <- coef(model) - modelConfInt <- suppressMessages(confint(model)) + modelConfInt <- suppressMessages(ciFun(model)) modelSummaryMat <- coef(summary(model)) modelP <- modelSummaryMat[,ncol(modelSummaryMat)] @@ -67,11 +63,12 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle pointEstimates <- format(pointEstimates, justify = "right") resString <- sprintf(fmt = paste0("%s", " [", fmt1, ", ", fmt1 ,"]"), - ## resMat[,1], # point estimate + ## point estimate pointEstimates, - resMat[,2], # lower - resMat[,3] # upper - ) + ## lower bound + resMat[,2], + ## upper bound + resMat[,3]) ## Format p-values pString <- sprintf(fmt = fmt2, diff --git a/tests/testthat/test-ShowRegTable.R b/tests/testthat/test-ShowRegTable.R new file mode 100644 index 0000000..7e61a18 --- /dev/null +++ b/tests/testthat/test-ShowRegTable.R @@ -0,0 +1,96 @@ +################################################################################ +### Unit tests for ShowRegTable +## Reference: http://adv-r.had.co.nz/Testing.html +## Created on: 2015-08-01 +## Author: Kazuki Yoshida +################################################################################ + +### Structure +## expectations within tests within context + +### Prepare environment +################################################################################ +library(testthat) +library(survey) +library(survival) + + +### Context (1 for each file) +################################################################################ +context("Unit tests for regression summary function") + +## Load Mayo Clinic Primary Biliary Cirrhosis Data +data(pbc) + +## Cox +coxph1 <- coxph(formula = Surv(time, status == 2) ~ trt + age + albumin + ascites, + data = pbc) +## Logistic +glm1 <- glm(formula = (status == 2) ~ trt + age + albumin + ascites, + family = binomial(link = "logit"), + data = pbc) +## Linear +lm1 <- lm(formula = time ~ trt + age + albumin + ascites, + data = pbc) + +test_that("coxph works", { + + ## For coxph normal approximation is uses + expect_true(all(confint(coxph1) == confint.default(coxph1))) + + ## confint + ShowRegTable(coxph1) + expect_output(ShowRegTable(coxph1), + "[0.72, 1.47]") + + ## contint.default + ShowRegTable(coxph1, ciFun = confint.default) + expect_output(ShowRegTable(coxph1, ciFun = confint.default), + "[0.72, 1.47]") + + ## Show with quote to ease copy and paste + ShowRegTable(coxph1, quote = TRUE) + expect_output(ShowRegTable(coxph1, quote = TRUE), + '[0.72, 1.47]"') + expect_output(ShowRegTable(coxph1, quote = TRUE), + '"[0.72, 1.47]') + +}) + + +test_that("glm works", { + + ## For GLM profile likelihood method and naive approximation differ + expect_true(!all(confint(glm1) == confint.default(glm1))) + + ## confint + ShowRegTable(glm1, digits = 5) + expect_output(ShowRegTable(glm1, digits = 5), + "[0.63994, 1.75622]") + + ## contint.default + ShowRegTable(glm1, ciFun = confint.default, digits = 5) + expect_output(ShowRegTable(glm1, ciFun = confint.default), + "[0.63975, 1.75230]") + +}) + + +test_that("lm works", { + + ## For lm t-distribution based method and naive approximation differ + expect_true(!all(confint(lm1) == confint.default(lm1))) + + ## confint + ShowRegTable(lm1, digits = 5) + expect_output(ShowRegTable(lm1, digits = 5), + "[-275.96185, 175.16874]") + + ## contint.default + ShowRegTable(lm1, ciFun = confint.default, digits = 5) + expect_output(ShowRegTable(lm1, ciFun = confint.default), + "[-275.07261, 174.27950]") + +}) + + From f361fd47965723e72b7b0c714f2f65e0e8f47604 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:10:20 -0400 Subject: [PATCH 153/219] Rename unit test modules --- tests/testthat/{test-smdModules.R => test-modules-smd.R} | 0 tests/testthat/{test-svyModules.R => test-modules-svy.R} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/testthat/{test-smdModules.R => test-modules-smd.R} (100%) rename tests/testthat/{test-svyModules.R => test-modules-svy.R} (100%) diff --git a/tests/testthat/test-smdModules.R b/tests/testthat/test-modules-smd.R similarity index 100% rename from tests/testthat/test-smdModules.R rename to tests/testthat/test-modules-smd.R diff --git a/tests/testthat/test-svyModules.R b/tests/testthat/test-modules-svy.R similarity index 100% rename from tests/testthat/test-svyModules.R rename to tests/testthat/test-modules-svy.R From f74878d0b52603152a67b4e8085b4489874d2962 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:28:51 -0400 Subject: [PATCH 154/219] Update NEWS and DESCRIPTION --- DESCRIPTION | 2 +- NEWS | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f1370ce..f0d3273 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: tableone Type: Package Title: Create "Table 1" to Describe Baseline Characteristics Version: 0.7.0 -Date: 2015-07-30 +Date: 2015-08-01 Author: Kazuki Yoshida, Justin Bohn. Maintainer: Kazuki Yoshida Description: Creates "Table 1", i.e., description of baseline patient diff --git a/NEWS b/NEWS index afc0bc7..97921a1 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,12 @@ -tableone 0.7.0 (2015-07-30) +tableone 0.7.0 (2015-08-01) ---------------------------------------------------------------- NEW FEATURES * Weighted data are now supported via the survey package. - The svydesign() should be used to create a survey design - object, and this object should be used for svyCreateTableOne() - instead of a data frame. Other options are essentially the same. + svydesign() should be used to create a survey design object, + and this object should be used for svyCreateTableOne() instead + of a data frame. Other options are essentially the same. * Standardized mean differences are calculated. print() methods include smd option, which defaults to FALSE for backward @@ -20,13 +20,23 @@ NEW FEATURES * The includeNA option for CreateTableOne() and svyCreateTableOne() make NA's in factors treated as a regular level. +* ShowRegTable() now has ciFun option, which allows use of + the confint.default function if calculation is too slow for + glm results. -MINOR CHANGES +* print.TableOne() aligns the sample size with other summaries. + + +OTHER CHANGES * ShowRegTable() uses coef to refer to coefficients. * Unit tests were extended to cover more functions. +* CreateTableOne() was refactored to avoid redundant calculation. + +* New dependencies: survey and zoo + BUG FIXES From b9ef5f1d05186d899085e7bac7bc31be6beb7453 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:45:04 -0400 Subject: [PATCH 155/219] Update README.md --- README.md | 98 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 07d018a..671496a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,9 @@ tableone (developmental repo) **An R package to create "Table 1", description of baseline characteristics** -This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroup comparisons. The package was inspired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. +Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package. + +tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. tableone in action @@ -19,64 +21,78 @@ A higher quality version is available at YouTube: https://www.youtube.com/watch? tableone code example ------------------------------------------------------------------------------- -In this table, continuous and categorical variables can be ordered however you like. The p-valeus are from exact tests for pre-specified variables. For nonnormal variables, it shows median and IQR instead of mean and SD, and p-values are from nonparametric tests. In this case, the dataset has been transformed so that categorical variables are factors. +In this table, continuous and categorical variables can be placed in any order. The p-valeus are from exact tests for pre-specified variables. For nonnormal variables, it shows median and IQR instead of mean and SD, and p-values are from nonparametric tests. Numerically coded categorical variables can be transformed on the fly with factorVars. SMD stands for standardized mean differences. For weighted data, first created a svydesign object, and use the svyCreateTableOne() function. Most other options remain the same. ``` -> tableOne <- CreateTableOne(vars = vars, strata = "trt", data = pbc) + +> ## Load data +> library(survival); data(pbc) +> # drop ID from variable list +> vars <- names(pbc)[-1] +> ## Create Table 1 stratified by trt (can add more stratifying variables) +> tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, ++ factorVars = c("status","edema","stage")) +> ## Specifying nonnormal variables will show the variables appropriately, +> ## and show nonparametric test p-values. Specify variables in the exact +> ## argument to obtain the exact test p-values. > print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "sex") - - Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0.884 exact - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex = m/f (%) 21/137 (13.3/86.7) 15/139 (9.7/90.3) 0.421 - ascites = 1 (%) 14 (8.9) 10 (6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 0.205 exact - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) ++ exact = c("status","stage"), smd = TRUE) + + + Stratified by trt + 1 2 p test SMD +n 158 154 +time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 0.017 +status (%) 0.884 exact 0.054 + 0 83 (52.5) 85 (55.2) + 1 10 ( 6.3) 9 ( 5.8) + 2 65 (41.1) 60 (39.0) +trt (mean (sd)) 1.00 (0.00) 2.00 (0.00) <0.001 Inf +age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 0.270 +sex = f (%) 137 (86.7) 139 (90.3) 0.421 0.111 +ascites (mean (sd)) 0.09 (0.29) 0.06 (0.25) 0.434 0.089 +hepato (mean (sd)) 0.46 (0.50) 0.56 (0.50) 0.069 0.206 +spiders (mean (sd)) 0.28 (0.45) 0.29 (0.46) 0.886 0.016 +edema (%) 0.877 0.058 + 0 132 (83.5) 131 (85.1) + 0.5 16 (10.1) 13 ( 8.4) + 1 10 ( 6.3) 10 ( 6.5) +bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] 0.842 nonnorm 0.171 +chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] 0.544 nonnorm 0.038 +albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 0.018 +copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] 0.717 nonnorm <0.001 +alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] 0.812 nonnorm 0.037 +ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 0.084 +trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] 0.370 nonnorm 0.017 +platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 0.067 +protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 0.146 +stage (%) 0.205 exact 0.246 + 1 12 ( 7.6) 4 ( 2.6) + 2 35 (22.2) 32 (20.8) + 3 56 (35.4) 64 (41.6) + 4 55 (34.8) 54 (35.1) + ``` Installation ------------------------------------------------------------------------------- -This version of tableone package for R is developmetal, and is not available from the CRAN. You can install it using one of the following way. +This version of tableone package for R is developmetal, and may not be available from the CRAN. You can install it using one of the following way. **Direct installation from github** You first need to install the devtools package to do the following. You can choose from the latest stable version and the latest development version. + ``` + ## Install devtools (if you do not have it already) > install.packages("devtools") -## Load devtools -> library(devtools) ## Install directly from github (develop branch) -> install_github(repo = "kaz-yos/tableone", ref = "develop") +> devtools::install_github(repo = "kaz-yos/tableone", ref = "develop") + ``` -Using devtools requires some preparation, please see the following link for information. +Using devtools may requires some preparation, please see the following link for information. http://www.rstudio.com/projects/devtools/ From 5d76c5647cc1905aeaa64d04a66f144f3428ac31 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 07:55:19 -0400 Subject: [PATCH 156/219] Update Makefile to list test files too --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 9ce335c..9684bf9 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,9 @@ list: @echo "R files:" @echo $(R_FILES) @echo + @echo "Test files:" + @echo $(TST_FILES) + @echo @echo "Source files:" @echo $(SRC_FILES) @echo From f6b2020a9bea48fd6a55c6c1dc5bd0625efbae03 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 08:32:43 -0400 Subject: [PATCH 157/219] Include smd = TRUE in examples --- R/CreateTableOne.R | 2 +- R/print.TableOne.R | 2 +- R/svyCreateTableOne.R | 12 +++++++----- R/tableone-package.R | 12 ++++-------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 81fe506..eda1aa6 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -59,7 +59,7 @@ ##' ## and show nonparametric test p-values. Specify variables in the exact ##' ## argument to obtain the exact test p-values. ##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage")) +##' exact = c("status","stage"), smd = TRUE) ##' ##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 3b0ab22..5f65082 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -56,7 +56,7 @@ ##' ## argument to obtain the exact test p-values. cramVars can be used to ##' ## show both levels for a 2-level categorical variables. ##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "hepato") +##' exact = c("status","stage"), cramVars = "hepato", smd = TRUE) ##' ##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 3b8728f..ed09689 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -37,8 +37,8 @@ ##' nest = TRUE, data = nhanes) ##' ##' ## Create a table object -##' ## factorVars are converted to factors; no need to do this if variables are already factors -##' ## strata will stratify summaries; leave it unspecified, and overview is obtained +##' ## factorVars are converted to factors; no need for variables already factors +##' ## strata will stratify summaries; leave it unspecified for overall summaries ##' tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), ##' strata = "RIAGENDR", data = nhanesSvy, ##' factorVars = c("race","RIAGENDR")) @@ -50,13 +50,15 @@ ##' tab1 ##' ##' ## nonnormal specifies variables to be shown as median [IQR] -##' print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) +##' print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, +##' pDigits = 4, smd = TRUE) ##' ##' ## minMax changes it to median [min, max] -##' print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) +##' print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, +##' catDigits = 2, pDigits = 4, smd = TRUE) ##' ##' ## showAllLevels can be used tow show levels for all categorical variables -##' print(tab1, showAllLevels = TRUE) +##' print(tab1, showAllLevels = TRUE, smd = TRUE) ##' ##' ## To see all printing options ##' ?print.TableOne diff --git a/R/tableone-package.R b/R/tableone-package.R index 2b6c452..9631aef 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -1,6 +1,6 @@ ##' Create "Table 1" to describe baseline characteristics ##' -##' This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroup comparisons. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. +##' Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package. See github for a screencast. tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. ##' ##' @name tableone-package ##' @aliases tableone-package tableone @@ -28,12 +28,8 @@ ##' ##' Maintainer: Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{svyCreateTableOne}}, ##' \code{\link{ShowRegTable}} ##' @examples ##' @@ -71,7 +67,7 @@ ##' ## variables specified in cramVars, both levels are shown. Use minMax ##' ## argument to show median [min, max] for nonnormal variables. ##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "sex") +##' exact = c("status","stage"), cramVars = "sex", smd = TRUE) ##' ##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) From a703a5be98f167a3d4167a1c4625c883f1661210 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 09:06:35 -0400 Subject: [PATCH 158/219] Update tests for ShowRegTable --- cran-check.txt | 13 ++++++++++ test-all.txt | 39 ++++++++++++++++++++++++++++-- tests/testthat/test-ShowRegTable.R | 29 +++++++++------------- 3 files changed, 61 insertions(+), 20 deletions(-) diff --git a/cran-check.txt b/cran-check.txt index d3b965d..b209cc2 100644 --- a/cran-check.txt +++ b/cran-check.txt @@ -1,4 +1,17 @@ Rscript -e "library(methods); library(roxygen2); roxygenize('.')" +R CMD build ../tableone +* checking for file ‘../tableone/DESCRIPTION’ ... OK +* preparing ‘tableone’: +* checking DESCRIPTION meta-information ... OK +* installing the package to build vignettes +* creating vignettes ... OK +* excluding invalid files +Subdirectory 'man' contains invalid file names: + ‘Rd2roxygen.R’ ‘clean_comments.sh’ +* checking for LF line-endings in source and make files +* checking for empty or unneeded directories +Removed empty directory ‘tableone/data’ +* building ‘tableone_0.7.0.tar.gz’ R CMD check --as-cran ./tableone_0.7.0.tar.gz * using log directory ‘/Users/kazuki/Documents/programming/r/tableone/tableone.Rcheck’ * using R version 3.2.1 (2015-06-18) diff --git a/test-all.txt b/test-all.txt index fb814bd..4f5b945 100644 --- a/test-all.txt +++ b/test-all.txt @@ -1668,7 +1668,6 @@ status 0.5770647 0.7964473 0.8748771 0.8309763 0.4375075 0.4621432 0.06043662 trt 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000 sex 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.00000000 . -Unit tests for the modules : ........ Tests for functions for standardized mean differences : ................................................................................... ### Summary of continuous variables ### @@ -1761,6 +1760,43 @@ agecat 0.702331 0.9040822 0.109801 0.985333 0.8536402 0.3838583 0.9772713 (39,59] 775 (22.0) 173 (47.7) 796 (22.5) 167 (39.4) (59,Inf] 835 (23.7) 92 (25.3) 772 (21.9) 181 (42.7) . +Unit tests for the survey-related modules : ................................................ +Unit tests for the modules : ........ +Unit tests for regression summary function : . exp(coef) [confint] p +trt 1.03 [0.72, 1.47] 0.891 +age 1.03 [1.01, 1.05] 0.005 +albumin 0.26 [0.17, 0.41] <0.001 +ascites 2.93 [1.68, 5.11] <0.001 +. exp(coef) [confint] p +trt 1.03 [0.72, 1.47] 0.891 +age 1.03 [1.01, 1.05] 0.005 +albumin 0.26 [0.17, 0.41] <0.001 +ascites 2.93 [1.68, 5.11] <0.001 +.. exp(coef) [confint] p +(Intercept) 4.81558 [0.26099, 93.77267] 0.293 +trt 1.05879 [0.63994, 1.75622] 0.824 +age 1.03850 [1.01306, 1.06547] 0.003 +albumin 0.31078 [0.15316, 0.60752] 0.001 +ascites 19.05020 [3.69390, 349.54310] 0.005 +. exp(coef) [confint] p +(Intercept) 4.81558 [0.25650, 90.40912] 0.293 +trt 1.05879 [0.63975, 1.75230] 0.824 +age 1.03850 [1.01271, 1.06494] 0.003 +albumin 0.31078 [0.15640, 0.61757] 0.001 +ascites 19.05020 [2.44625, 148.35373] 0.005 +.. coef [confint] p +(Intercept) -1194.06334 [-2499.63435, 111.50767] 0.073 +trt -50.39655 [-275.96185, 175.16874] 0.661 +age -2.97371 [-14.01246, 8.06504] 0.596 +albumin 987.37770 [695.98678, 1278.76862] <0.001 +ascites -664.69235 [-1126.85877, -202.52592] 0.005 +. coef [confint] p +(Intercept) -1194.06334 [-2494.48743, 106.36074] 0.073 +trt -50.39655 [-275.07261, 174.27950] 0.661 +age -2.97371 [-13.96894, 8.02152] 0.596 +albumin 987.37770 [697.13553, 1277.61988] <0.001 +ascites -664.69235 [-1125.03679, -204.34791] 0.005 +. Unit tests for svy* user functions : .......... Stratified by E 1 2 3 p test n 150.01 150.00 150.00 @@ -2586,6 +2622,5 @@ C1 0.0000000 0.000000000 0.000000000 0.000000 0.000000 0.000000 0.000000000000 0 Y 1.218899 1.218899 0 0 0 C1 0.000000 0.000000 0 0 0 . -Unit tests for the survey-related modules : ................................................ DONE diff --git a/tests/testthat/test-ShowRegTable.R b/tests/testthat/test-ShowRegTable.R index 7e61a18..433f753 100644 --- a/tests/testthat/test-ShowRegTable.R +++ b/tests/testthat/test-ShowRegTable.R @@ -41,19 +41,12 @@ test_that("coxph works", { ## confint ShowRegTable(coxph1) expect_output(ShowRegTable(coxph1), - "[0.72, 1.47]") + "0.72, 1.47") ## contint.default ShowRegTable(coxph1, ciFun = confint.default) expect_output(ShowRegTable(coxph1, ciFun = confint.default), - "[0.72, 1.47]") - - ## Show with quote to ease copy and paste - ShowRegTable(coxph1, quote = TRUE) - expect_output(ShowRegTable(coxph1, quote = TRUE), - '[0.72, 1.47]"') - expect_output(ShowRegTable(coxph1, quote = TRUE), - '"[0.72, 1.47]') + "0.72, 1.47") }) @@ -66,12 +59,12 @@ test_that("glm works", { ## confint ShowRegTable(glm1, digits = 5) expect_output(ShowRegTable(glm1, digits = 5), - "[0.63994, 1.75622]") + "0.63994, 1.75622") ## contint.default ShowRegTable(glm1, ciFun = confint.default, digits = 5) - expect_output(ShowRegTable(glm1, ciFun = confint.default), - "[0.63975, 1.75230]") + expect_output(ShowRegTable(glm1, ciFun = confint.default, digits = 5), + "0.63975, 1.75230") }) @@ -82,14 +75,14 @@ test_that("lm works", { expect_true(!all(confint(lm1) == confint.default(lm1))) ## confint - ShowRegTable(lm1, digits = 5) - expect_output(ShowRegTable(lm1, digits = 5), - "[-275.96185, 175.16874]") + ShowRegTable(lm1, digits = 5, exp = FALSE) + expect_output(ShowRegTable(lm1, digits = 5, exp = FALSE), + "-275.96185, 175.16874") ## contint.default - ShowRegTable(lm1, ciFun = confint.default, digits = 5) - expect_output(ShowRegTable(lm1, ciFun = confint.default), - "[-275.07261, 174.27950]") + ShowRegTable(lm1, ciFun = confint.default, digits = 5, exp = FALSE) + expect_output(ShowRegTable(lm1, ciFun = confint.default, digits = 5, exp = FALSE), + "-275.07261, 174.27950") }) From 6cc5ff08abd9f8869cfcb6a91265ceb942a5ca72 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 09:18:30 -0400 Subject: [PATCH 159/219] Improve docs of print methods --- R/print.CatTable.R | 12 ++++++------ R/print.ContTable.R | 12 ++++++------ R/print.TableOne.R | 12 ++++++------ R/print.svyCatTable.R | 10 +++++----- R/print.svyContTable.R | 12 ++++++------ 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index 56fddc8..f8e64d3 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -1,10 +1,10 @@ -##' Format and print the \code{CatTable} class objects +##' Format and print \code{CatTable} class objects ##' -##' This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +##' \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. ##' -##' @param x The result of a call to the \code{\link{CreateCatTable}} function. +##' @param x Object returned by \code{\link{CreateCatTable}} function. ##' @param digits Number of digits to print in the table. -##' @param pDigits Number of digits to print for p-values. +##' @param pDigits Number of digits to print for p-values (also used for standardized mean differences). ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. ##' @param missing Whether to show missing data information (not implemented yet, placeholder) ##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown. @@ -13,9 +13,9 @@ ##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency). ##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. ##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. -##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param exact A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test). -##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. +##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. diff --git a/R/print.ContTable.R b/R/print.ContTable.R index e314484..8e44e37 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -1,10 +1,10 @@ -##' Format and print the \code{ContTable} class objects +##' Format and print \code{ContTable} class objects ##' -##' This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +##' \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. ##' -##' @param x The result of a call to the \code{\link{CreateContTable}} function. +##' @param x Object returned by \code{\link{CreateContTable}} function. ##' @param digits Number of digits to print in the table. -##' @param pDigits Number of digits to print for p-values. +##' @param pDigits Number of digits to print for p-values (also used for standardized mean differences). ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. ##' @param missing Whether to show missing data information (not implemented yet, placeholder) ##' @param explain Whether to add explanation to the variable names, i.e., (mean (sd) or median [IQR]) is added to the variable names. @@ -13,8 +13,8 @@ ##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test). ##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. ##' @param insertLevel Whether to add an empty level column to the left of strata. -##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. -##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. +##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 5f65082..3c88a44 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -1,17 +1,17 @@ -##' Format and print the \code{TableOne} class objects +##' Format and print \code{TableOne} class objects ##' -##' This is the \code{print} method for the \code{TableOne} class objects created by \code{\link{CreateTableOne}} function. +##' \code{print} method for the \code{TableOne} class objects created by \code{\link{CreateTableOne}} function. ##' -##' @param x The result of a call to the \code{\link{CreateTableOne}} function. +##' @param x Object returned by \code{\link{CreateTableOne}} function. ##' @param catDigits Number of digits to print for proportions. Default 1. ##' @param contDigits Number of digits to print for continuous variables. Default 2. -##' @param pDigits Number of digits to print for p-values. Default 3. +##' @param pDigits Number of digits to print for p-values (also used for standardized mean differences). Default 3. ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. ##' @param missing Whether to show missing data information (not implemented yet, placeholder) ##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown. ##' @param printToggle Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. -##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. -##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. +##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param noSpaces Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. ##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency). ##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index 316bf05..cebee03 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -1,10 +1,10 @@ -##' Format and print the \code{svyCatTable} class objects +##' Format and print \code{svyCatTable} class objects ##' -##' This is the \code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. +##' \code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. ##' ##' @param x The result of a call to the \code{\link{svyCreateCatTable}} function. ##' @param digits Number of digits to print in the table. -##' @param pDigits Number of digits to print for p-values. +##' @param pDigits Number of digits to print for p-values (also used for standardized mean differences). ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. ##' @param missing Whether to show missing data information (not implemented yet, placeholder) ##' @param explain Whether to add explanation to the variable names, i.e., (\%) is added to the variable names when percentage is shown. @@ -13,9 +13,9 @@ ##' @param format The default is "fp" frequency (percentage). You can also choose from "f" frequency only, "p" percentage only, and "pf" percentage (frequency). ##' @param showAllLevels Whether to show all levels. FALSE by default, i.e., for 2-level categorical variables, only the higher level is shown to avoid redundant information. ##' @param cramVars A character vector to specify the two-level categorical variables, for which both levels should be shown in one row. -##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param exact This option is not available for tables from weighted data. -##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. +##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index bda4439..bfdcf98 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -1,10 +1,10 @@ -##' Format and print the \code{svyContTable} class objects +##' Format and print \code{svyContTable} class objects ##' -##' This is the \code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. +##' \code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. ##' -##' @param x The result of a call to the \code{\link{svyCreateContTable}} function. +##' @param x Object returned by \code{\link{svyCreateContTable}} function. ##' @param digits Number of digits to print in the table. -##' @param pDigits Number of digits to print for p-values. +##' @param pDigits Number of digits to print for p-values (also used for standardized mean differences). ##' @param quote Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily. ##' @param missing Whether to show missing data information (not implemented yet, placeholder) ##' @param explain Whether to add explanation to the variable names, i.e., (mean (sd) or median [IQR]) is added to the variable names. @@ -13,8 +13,8 @@ ##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test). ##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. ##' @param insertLevel Whether to add an empty level column to the left of strata. -##' @param test Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown. -##' @param smd Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. +##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. +##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida From 08b1ac9d88e25fb5c567fc5dc3aec165c33a34a0 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 09:28:22 -0400 Subject: [PATCH 160/219] Update docs for summary methods --- R/summary.CatTable.R | 8 ++++---- R/summary.ContTable.R | 8 ++++---- R/summary.TableOne.R | 14 +++++++------- R/summary.svyCatTable.R | 4 ++-- R/summary.svyContTable.R | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/R/summary.CatTable.R b/R/summary.CatTable.R index b9e3be2..806621b 100644 --- a/R/summary.CatTable.R +++ b/R/summary.CatTable.R @@ -1,16 +1,16 @@ ##' Shows all results in a \code{CatTable} class object ##' -##' This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +##' Shows all data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{CatTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. -##' @return It will print the results. +##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, ##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load diff --git a/R/summary.ContTable.R b/R/summary.ContTable.R index adec7e2..a10f621 100644 --- a/R/summary.ContTable.R +++ b/R/summary.ContTable.R @@ -1,16 +1,16 @@ ##' Shows all results in a \code{ContTable} class object ##' -##' This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +##' Shows all data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{ContTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. -##' @return It will print the results. +##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load diff --git a/R/summary.TableOne.R b/R/summary.TableOne.R index 44e560e..2cbb6f7 100644 --- a/R/summary.TableOne.R +++ b/R/summary.TableOne.R @@ -1,19 +1,19 @@ ##' Shows all results in a \code{(svy)TableOne} class object ##' -##' This method shows all the data a \code{(svy)TableOne} class object has. This -##' includes the (optionally stratified) part with summary statistics and p-values -##' and/or standardized mean differences. +##' Shows all data a \code{(svy)TableOne} class object has. This includes the (optionally stratified) part with summary statistics and p-values and/or standardized mean differences. ##' ##' ##' @param object An object that has the \code{(svy)TableOne} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. -##' @return It will print the results. +##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} +##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}} ##' @examples ##' ##' ## Load diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index 5c9e977..0cec2f3 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -1,11 +1,11 @@ ##' Shows all results in a \code{svyCatTable} class object ##' -##' This method shows all the data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +##' Shows all data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{svyCatTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. -##' @return It will print the results. +##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 926ec8f..2a63687 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -1,16 +1,16 @@ ##' Shows all results in a \code{svyContTable} class object ##' -##' This method shows all the data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +##' Shows all data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{svyContTable} class to be shown. ##' @param digits Number of digits to print. ##' @param ... For compatibility with generic. Ignored. -##' @return It will print the results. +##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, ##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## See the examples for svyCreateTableOne() From ebe48b5d9156706c66eb7830d13307a44409db5f Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 09:47:43 -0400 Subject: [PATCH 161/219] Drop unncessary non-functional code links in docs --- R/CreateCatTable.R | 8 ++++---- R/CreateTableOne.R | 8 ++++---- R/summary.CatTable.R | 2 +- R/summary.ContTable.R | 2 +- R/summary.svyCatTable.R | 2 +- R/summary.svyContTable.R | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 2cb6e24..c0351e4 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -10,10 +10,10 @@ ##' @param data A data frame in which these variables exist. All variables (both vars and strata) must be in this data frame. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. -##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. -##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. -##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{chisq.test}. This is not recommended when some of the cell have small counts like fewer than 5. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{chisq.test}. +##' @param testExact A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. +##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. ##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index eda1aa6..aeb8e7e 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -12,10 +12,10 @@ ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. -##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5. -##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}. -##' @param testExact A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. -##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}. +##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{chisq.test}. This is not recommended when some of the cell have small counts like fewer than 5. +##' @param argsApprox A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{chisq.test}. +##' @param testExact A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. +##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. ##' @return An object of class \code{TableOne}, which really is a list of three objects. ##' @return \item{ContTable}{object of class \code{ContTable}, containing continuous variables only} diff --git a/R/summary.CatTable.R b/R/summary.CatTable.R index 806621b..eae83b7 100644 --- a/R/summary.CatTable.R +++ b/R/summary.CatTable.R @@ -1,6 +1,6 @@ ##' Shows all results in a \code{CatTable} class object ##' -##' Shows all data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default) and standardized mean differences of all possible pairwise contrasts. +##' Shows all data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{chisq.test} by default) and exact method test (\code{fisher.test} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{CatTable} class to be shown. ##' @param digits Number of digits to print. diff --git a/R/summary.ContTable.R b/R/summary.ContTable.R index a10f621..158cdf2 100644 --- a/R/summary.ContTable.R +++ b/R/summary.ContTable.R @@ -1,6 +1,6 @@ ##' Shows all results in a \code{ContTable} class object ##' -##' Shows all data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default) and standardized mean differences of all possible pairwise contrasts. +##' Shows all data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{oneway.test} by default) and nonparametric test (\code{kruskal.test} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{ContTable} class to be shown. ##' @param digits Number of digits to print. diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index 0cec2f3..9e3eabb 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -1,6 +1,6 @@ ##' Shows all results in a \code{svyCatTable} class object ##' -##' Shows all data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default) and standardized mean differences of all possible pairwise contrasts. +##' Shows all data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{chisq.test} by default) and exact method test (\code{fisher.test} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{svyCatTable} class to be shown. ##' @param digits Number of digits to print. diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 2a63687..2ba3f9f 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -1,6 +1,6 @@ ##' Shows all results in a \code{svyContTable} class object ##' -##' Shows all data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default) and standardized mean differences of all possible pairwise contrasts. +##' Shows all data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{regTermTest} with \code{svyglm} by default) and nonparametric test (\code{svyranktest} by default) and standardized mean differences of all possible pairwise contrasts. ##' ##' @param object An object that has the \code{svyContTable} class to be shown. ##' @param digits Number of digits to print. From 43ef0c317e427525ec1986a02986de80dca1c3a3 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 09:59:02 -0400 Subject: [PATCH 162/219] Drop unnecessary details from docs --- R/CreateCatTable.R | 2 +- R/CreateContTable.R | 2 +- R/CreateTableOne.R | 2 +- R/svyCreateTableOne.R | 2 +- R/tableone-package.R | 100 +----------------------------------------- 5 files changed, 5 insertions(+), 103 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index c0351e4..9febe23 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -15,7 +15,7 @@ ##' @param testExact A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. -##' @return An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +##' @return An object of class \code{CatTable}. ##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) ##' @seealso ##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, diff --git a/R/CreateContTable.R b/R/CreateContTable.R index ac1814d..2078d73 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -16,7 +16,7 @@ ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. -##' @return An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +##' @return An object of class \code{ContTable}. ##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) ##' @seealso ##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index aeb8e7e..acf8fa3 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -17,7 +17,7 @@ ##' @param testExact A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice. ##' @param argsExact A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. -##' @return An object of class \code{TableOne}, which really is a list of three objects. +##' @return An object of class \code{TableOne}, which is a list of three objects. ##' @return \item{ContTable}{object of class \code{ContTable}, containing continuous variables only} ##' @return \item{CatTable}{object of class \code{CatTable}, containing categorical variables only} ##' @return \item{MetaData}{list of metadata regarding variables} diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index ed09689..fb94a3e 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -15,7 +15,7 @@ ##' @param testApprox A function used to perform the large sample approximation based tests. The default is \code{svychisq}. ##' @param argsApprox A named list of arguments passed to the function specified in testApprox. ##' @param smd If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used. -##' @return An object of class \code{svyTableOne}, which really is a list of three objects. +##' @return An object of class \code{svyTableOne}, which is a list of three objects. ##' @return \item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} ##' @return \item{CatTable}{ an object of class \code{svyCatTable}, containing categorical variables only} ##' @return \item{MetaData}{list of metadata regarding variables} diff --git a/R/tableone-package.R b/R/tableone-package.R index 9631aef..f6f6851 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -33,104 +33,6 @@ ##' \code{\link{ShowRegTable}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## List numerically coded categorical variables for later conversion. -##' ## Factor variables are automatically handled as categorical variables. -##' factorVars <- c("status","trt","ascites","hepato","spiders","edema","stage") -##' -##' ## Create a variable list -##' dput(names(pbc)) # This shows a character vector-creating syntax. -##' vars <- c("time","status","age","sex","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage") -##' -##' ## Create Table 1 stratified by trt. Use factorVars to convert numerically -##' ## coded categorical variables as factors without changing the dataset. -##' tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, -##' factorVars = factorVars) -##' -##' ## Just typing the object name will invoke the print.TableOne method -##' tableOne -##' -##' ## Specifying nonnormal variables will show the variables appropriately, -##' ## and show nonparametric test p-values. Specify variables in the exact -##' ## argument to obtain the exact test p-values. For two-level categorical -##' ## variables specified in cramVars, both levels are shown. Use minMax -##' ## argument to show median [min, max] for nonnormal variables. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "sex", smd = TRUE) -##' -##' ## Use the summary.TableOne method for detailed summary -##' summary(tableOne) -##' -##' ## See the categorical part only using $ operator -##' tableOne$CatTable -##' summary(tableOne$CatTable) -##' -##' ## See the continuous part only using $ operator -##' tableOne$ContTable -##' summary(tableOne$ContTable) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "sex", quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "sex", quote = TRUE, noSpaces = TRUE) -##' -##' -##' ## Analysis for weighted data -##' -##' ## Load packages -##' library(tableone) -##' library(survey) -##' -##' ## Create a weighted survey design object -##' data(nhanes) -##' nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, -##' nest = TRUE, data = nhanes) -##' -##' ## Create a table object -##' ## factorVars are converted to factors; no need to do this if variables are already factors -##' ## strata will stratify summaries; leave it unspecified, and overview is obtained -##' tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), -##' strata = "RIAGENDR", data = nhanesSvy, -##' factorVars = c("race","RIAGENDR")) -##' -##' ## Detailed output -##' summary(tab1) -##' -##' ## Default formatted printing -##' tab1 -##' -##' ## nonnormal specifies variables to be shown as median [IQR] -##' print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) -##' -##' ## minMax changes it to median [min, max] -##' print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) -##' -##' ## showAllLevels can be used tow show levels for all categorical variables -##' print(tab1, showAllLevels = TRUE) -##' -##' ## To see all printing options -##' ?print.TableOne -##' -##' ## To examine categorical variables only -##' tab1$CatTable -##' -##' ## To examine continuous variables only -##' tab1$ContTable +##' ## See examples for CreateTableOne and svyCreateTableOne ##' NULL From 7e2ccf639c142096ff1645a4c3307b2a9562a774 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:14:19 -0400 Subject: [PATCH 163/219] Include SMD in vignette --- vignettes/introduction.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index 0bf1850..380bf45 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -118,8 +118,10 @@ As you can see in the previous table, when there are two or more groups group co You may be worried about the nonnormal variables and small cell counts in the stage variable. In such a situation, you can use the nonnormal argument like before as well as the exact (test) argument in the print() method. Now kruskal.test() is used for the nonnormal continous variables and fisher.test() is used for categorical variables specified in the exact argument. kruskal.test() is equivalent to wilcox.test() in the two-group case. The column named test is to indicate which p-values were calculated using the non-default tests. +To also show standardized mean differences, use the smd option. + ```{r} -print(tab3, nonnormal = biomarkers, exact = "stage") +print(tab3, nonnormal = biomarkers, exact = "stage", smd = TRUE) ``` ## Exporting From 4aaeed6aa4a3c3e85af8e98e7fe309225a183ebb Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:18:10 -0400 Subject: [PATCH 164/219] Drop unnecessary links to oneway.test --- R/CreateContTable.R | 2 +- R/CreateTableOne.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 2078d73..c44df6f 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -11,7 +11,7 @@ ##' @param funcNames The functions to give the group size, number with missing values, proportion with missing values, mean, standard deviations, median, 25th percentile, 75th percentile, minimum, maximum, skewness (same definition as in SAS), kurtosis (same definition as in SAS). All of them can be seen in the summary method output. The print method uses subset of these. You can choose subset of them or reorder them. They are all configure to omit NA values (\code{na.rm = TRUE}). ##' @param funcAdditional Additional functions can be given as a named list. For example, \code{list(sum = sum)}. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method. -##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. +##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{oneway.test}. This is equivalent of the t-test when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis rank sum test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index acf8fa3..c780f9f 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -8,7 +8,7 @@ ##' @param factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. If omitted, only factors are considered categorical variables. If all categorical variables in the dataset are already factors, this option is not necessary. The variables specified here must also be specified in the \code{vars} argument. ##' @param includeNA If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables. ##' @param test If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. -##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups. +##' @param testNormal A function used to perform the normal assumption based tests. The default is \code{oneway.test}. This is equivalent of the t-test when there are only two groups. ##' @param argsNormal A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups. ##' @param testNonNormal A function used to perform the nonparametric tests. The default is \code{kruskal.test} (Kruskal-Wallis Rank Sum Test). This is equivalent of the wilcox.test (Man-Whitney U test) when there are only two groups. ##' @param argsNonNormal A named list of arguments passed to the function specified in \code{testNonNormal}. The default is \code{list(NULL)}, which is just a placeholder. From ae0d1e259219c7b6f4c6df07aa2cfca38ca0c2de Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:39:04 -0400 Subject: [PATCH 165/219] Simplify seealso for simplicity --- R/CreateCatTable.R | 4 +--- R/CreateContTable.R | 4 +--- R/CreateTableOne.R | 4 +--- R/print.CatTable.R | 4 +--- R/print.ContTable.R | 4 +--- R/print.TableOne.R | 4 +--- R/print.svyCatTable.R | 4 +--- R/print.svyContTable.R | 4 +--- R/summary.CatTable.R | 4 +--- R/summary.ContTable.R | 4 +--- R/summary.svyCatTable.R | 4 +--- R/summary.svyContTable.R | 4 +--- R/svyCreateCatTable.R | 4 +--- R/svyCreateContTable.R | 4 +--- R/svyCreateTableOne.R | 4 +--- R/tableone-package.R | 4 +--- 16 files changed, 16 insertions(+), 48 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 9febe23..63d44cd 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -18,9 +18,7 @@ ##' @return An object of class \code{CatTable}. ##' @author Kazuki Yoshida (based on \code{Deducer::frequencies()}) ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateTableOne}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} ##' @examples ##' ##' ## Load diff --git a/R/CreateContTable.R b/R/CreateContTable.R index c44df6f..9009f54 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -19,9 +19,7 @@ ##' @return An object of class \code{ContTable}. ##' @author Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) ##' @seealso -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateTableOne}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} ##' @examples ##' ##' ## Load diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index c780f9f..404d4cd 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -24,9 +24,7 @@ ##' ##' @author Kazuki Yoshida, Justin Bohn ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +##' \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load diff --git a/R/print.CatTable.R b/R/print.CatTable.R index f8e64d3..cbfffb3 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -21,9 +21,7 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateCatTable}}, \code{\link{summary.CatTable}} ##' @examples ##' ##' ## Load diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 8e44e37..3ce9d50 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -19,9 +19,7 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateContTable}}, \code{\link{summary.ContTable}} ##' @examples ##' ##' ## Load diff --git a/R/print.TableOne.R b/R/print.TableOne.R index 3c88a44..ae00671 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -23,9 +23,7 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida, Justin Bohn ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +##' \code{\link{CreateTableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index cebee03..e698e79 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -21,9 +21,7 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index bfdcf98..99a4fae 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -19,9 +19,7 @@ ##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/summary.CatTable.R b/R/summary.CatTable.R index eae83b7..e9c54ae 100644 --- a/R/summary.CatTable.R +++ b/R/summary.CatTable.R @@ -8,9 +8,7 @@ ##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, ##' @examples ##' ##' ## Load diff --git a/R/summary.ContTable.R b/R/summary.ContTable.R index 158cdf2..b722ae6b 100644 --- a/R/summary.ContTable.R +++ b/R/summary.ContTable.R @@ -8,9 +8,7 @@ ##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}} ##' @examples ##' ##' ## Load diff --git a/R/summary.svyCatTable.R b/R/summary.svyCatTable.R index 9e3eabb..f5bd479 100644 --- a/R/summary.svyCatTable.R +++ b/R/summary.svyCatTable.R @@ -8,9 +8,7 @@ ##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}} ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/summary.svyContTable.R b/R/summary.svyContTable.R index 2ba3f9f..9daf9df 100644 --- a/R/summary.svyContTable.R +++ b/R/summary.svyContTable.R @@ -8,9 +8,7 @@ ##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}} ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 2e2f8b9..1740dd6 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -17,9 +17,7 @@ ##' @return An object of class \code{svyCatTable}. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateTableOne}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index de76504..f871c55 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -14,9 +14,7 @@ ##' @return An object of class \code{svyContTable}. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +##' \code{\link{svyCreateTableOne}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, ##' @examples ##' ##' ## See the examples for svyCreateTableOne() diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index fb94a3e..773330a 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -22,9 +22,7 @@ ##' ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} +##' \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' ##' ## Load packages diff --git a/R/tableone-package.R b/R/tableone-package.R index f6f6851..411f91a 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -28,9 +28,7 @@ ##' ##' Maintainer: Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{svyCreateTableOne}}, -##' \code{\link{ShowRegTable}} +##' \code{\link{CreateTableOne}}, \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, \code{\link{ShowRegTable}} ##' @examples ##' ##' ## See examples for CreateTableOne and svyCreateTableOne From e1790eb5e969e35a1b282c638032285927a15c86 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:39:37 -0400 Subject: [PATCH 166/219] Drop examples from print/summary.TableOne --- R/CreateTableOne.R | 5 +++-- R/print.TableOne.R | 51 +------------------------------------------- R/summary.TableOne.R | 32 ++------------------------- 3 files changed, 6 insertions(+), 82 deletions(-) diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 404d4cd..420eb90 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -55,9 +55,10 @@ ##' ##' ## Specifying nonnormal variables will show the variables appropriately, ##' ## and show nonparametric test p-values. Specify variables in the exact -##' ## argument to obtain the exact test p-values. +##' ## argument to obtain the exact test p-values. cramVars can be used to +##' ## show both levels for a 2-level categorical variables. ##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), smd = TRUE) +##' exact = c("status","stage"), cramVars = "hepato", smd = TRUE) ##' ##' ## Use the summary.TableOne method for detailed summary ##' summary(tableOne) diff --git a/R/print.TableOne.R b/R/print.TableOne.R index ae00671..c153259 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -26,56 +26,7 @@ ##' \code{\link{CreateTableOne}}, \code{\link{summary.TableOne}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Make categorical variables factors -##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -##' -##' ## Create Table 1 stratified by sex and trt -##' tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage"), -##' strata = c("sex","trt"), data = pbc) -##' -##' ## Just typing the object name will invoke the print.TableOne method -##' tableOne -##' -##' ## Specifying nonnormal variables will show the variables appropriately, -##' ## and show nonparametric test p-values. Specify variables in the exact -##' ## argument to obtain the exact test p-values. cramVars can be used to -##' ## show both levels for a 2-level categorical variables. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "hepato", smd = TRUE) -##' -##' ## Use the summary.TableOne method for detailed summary -##' summary(tableOne) -##' -##' ## See the categorical part only using $ operator -##' tableOne$CatTable -##' summary(tableOne$CatTable) -##' -##' ## See the continuous part only using $ operator -##' tableOne$ContTable -##' summary(tableOne$ContTable) -##' -##' ## If your work flow includes copying to Excel and Word when writing manuscripts, -##' ## you may benefit from the quote argument. This will quote everything so that -##' ## Excel does not mess up the cells. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "hepato", quote = TRUE) -##' -##' ## If you want to center-align values in Word, use noSpaces option. -##' print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -##' exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) +##' ## See examples for CreateTableOne and svyCreateTableOne ##' ##' @export print.TableOne <- diff --git a/R/summary.TableOne.R b/R/summary.TableOne.R index 2cbb6f7..678b45c 100644 --- a/R/summary.TableOne.R +++ b/R/summary.TableOne.R @@ -9,38 +9,10 @@ ##' @return None. Results are printed. ##' @author Kazuki Yoshida ##' @seealso -##' \code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -##' \code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -##' \code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} -##' \code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -##' \code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}} +##' \code{\link{CreateTableOne}}, \code{\link{svyCreateCatTable}} ##' @examples ##' -##' ## Load -##' library(tableone) -##' -##' ## Load Mayo Clinic Primary Biliary Cirrhosis Data -##' library(survival) -##' data(pbc) -##' ## Check variables -##' head(pbc) -##' -##' ## Make categorical variables factors -##' varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -##' pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -##' -##' ## Create Table 1 stratified by sex and trt -##' tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -##' "spiders","edema","bili","chol","albumin", -##' "copper","alk.phos","ast","trig","platelet", -##' "protime","stage"), -##' strata = c("sex","trt"), data = pbc) -##' -##' ## Just typing the object name will invoke the print.TableOne method -##' tableOne -##' -##' ## Use the summary.TableOne method for detailed summary -##' summary(tableOne) +##' ## See examples for CreateTableOne and svyCreateTableOne ##' ##' @export summary.TableOne <- function(object, digits = 1, ...) { From 048a10f556f50aeb47e26c4bf46eb04705c0c37b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:47:58 -0400 Subject: [PATCH 167/219] Improve docs for print methods' return objects --- R/print.CatTable.R | 2 +- R/print.ContTable.R | 2 +- R/print.TableOne.R | 2 +- R/print.svyCatTable.R | 2 +- R/print.svyContTable.R | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/print.CatTable.R b/R/print.CatTable.R index cbfffb3..789a9a8 100644 --- a/R/print.CatTable.R +++ b/R/print.CatTable.R @@ -18,7 +18,7 @@ ##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. -##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @return A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{CreateCatTable}}, \code{\link{summary.CatTable}} diff --git a/R/print.ContTable.R b/R/print.ContTable.R index 3ce9d50..c1f0f38 100644 --- a/R/print.ContTable.R +++ b/R/print.ContTable.R @@ -16,7 +16,7 @@ ##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. -##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @return A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{CreateContTable}}, \code{\link{summary.ContTable}} diff --git a/R/print.TableOne.R b/R/print.TableOne.R index c153259..3f887b0 100644 --- a/R/print.TableOne.R +++ b/R/print.TableOne.R @@ -20,7 +20,7 @@ ##' @param nonnormal A character vector to specify the variables for which the p-values should be those of nonparametric tests. By default all p-values are from normal assumption-based tests (oneway.test). ##' @param minMax Whether to use [min,max] instead of [p25,p75] for nonnormal variables. The default is FALSE. ##' @param ... For compatibility with generic. Ignored. -##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @return A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. ##' @author Kazuki Yoshida, Justin Bohn ##' @seealso ##' \code{\link{CreateTableOne}}, \code{\link{summary.TableOne}} diff --git a/R/print.svyCatTable.R b/R/print.svyCatTable.R index e698e79..6b73976 100644 --- a/R/print.svyCatTable.R +++ b/R/print.svyCatTable.R @@ -18,7 +18,7 @@ ##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used. ##' @param CrossTable Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS. ##' @param ... For compatibility with generic. Ignored. -##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @return A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} diff --git a/R/print.svyContTable.R b/R/print.svyContTable.R index 99a4fae..90f4c7b 100644 --- a/R/print.svyContTable.R +++ b/R/print.svyContTable.R @@ -16,7 +16,7 @@ ##' @param test Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown. ##' @param smd Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. ##' @param ... For compatibility with generic. Ignored. -##' @return It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +##' @return A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. ##' @author Kazuki Yoshida ##' @seealso ##' \code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} From 834918beed3b951e5910b757cb15dc3c0ad1a7eb Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 10:59:30 -0400 Subject: [PATCH 168/219] Simplify and improve function descriptions --- R/CreateCatTable.R | 5 +---- R/CreateContTable.R | 5 +---- R/CreateTableOne.R | 2 +- R/svyCreateCatTable.R | 6 +----- R/svyCreateContTable.R | 2 +- R/svyCreateTableOne.R | 2 +- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/R/CreateCatTable.R b/R/CreateCatTable.R index 63d44cd..4b0f83e 100644 --- a/R/CreateCatTable.R +++ b/R/CreateCatTable.R @@ -1,9 +1,6 @@ ##' Create an object summarizing categorical variables ##' -##' Create an object summarizing categorical variables optionally stratifying -##' by one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +##' Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{CreateTableOne}} should be used as the universal frontend for both continuous and categorical data. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/CreateContTable.R b/R/CreateContTable.R index 9009f54..c88783b 100644 --- a/R/CreateContTable.R +++ b/R/CreateContTable.R @@ -1,9 +1,6 @@ ##' Create an object summarizing continous variables ##' -##' Create an object summarizing continous variables optionally stratifying by -##' one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +##' Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{CreateTableOne}} should be used as the universal frontend for both continuous and categorical data. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/CreateTableOne.R b/R/CreateTableOne.R index 420eb90..6066f97 100644 --- a/R/CreateTableOne.R +++ b/R/CreateTableOne.R @@ -1,6 +1,6 @@ ##' Create an object summarizing both continuous and categorical variables ##' -##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +##' Create an object summarizing all baseline variables (both continuous and categorical) optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. ##' ##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the data frame specified in the data argument are used. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/svyCreateCatTable.R b/R/svyCreateCatTable.R index 1740dd6..eae32fe 100644 --- a/R/svyCreateCatTable.R +++ b/R/svyCreateCatTable.R @@ -1,10 +1,6 @@ ##' Create an object summarizing categorical variables for weighted data ##' -##' Create an object summarizing categorical variables optionally stratifying -##' by one or more startifying variables and performing statistical tests. The -##' object gives a table that is easy to use in medical research papers. See -##' also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. -##' \code{\link{svyCreateTableOne}} should be used as the universal frontend. +##' Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{svyCreateTableOne}} should be used as the universal frontend for both continuous and categorical data. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/svyCreateContTable.R b/R/svyCreateContTable.R index f871c55..dfe46d7 100644 --- a/R/svyCreateContTable.R +++ b/R/svyCreateContTable.R @@ -1,6 +1,6 @@ ##' Create an object summarizing continous variables for weighted dataset ##' -##' Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. \code{\link{svyCreateTableOne}} should be used as the universal frontend. +##' Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{svyCreateTableOne}} should be used as the universal frontend for both continuous and categorical data. ##' ##' @param vars Variable(s) to be summarized given as a character vector. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. diff --git a/R/svyCreateTableOne.R b/R/svyCreateTableOne.R index 773330a..0acf592 100644 --- a/R/svyCreateTableOne.R +++ b/R/svyCreateTableOne.R @@ -1,6 +1,6 @@ ##' Create an object summarizing both continuous and categorical variables for weighted data ##' -##' Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +##' Create an object summarizing all baseline variables (both continuous and categorical) optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. ##' ##' @param vars Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used. ##' @param strata Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned. From 6a6cf5fdf6d8db89b35b59d9cace6a50c8171d4b Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 11:11:16 -0400 Subject: [PATCH 169/219] Improve package description --- R/tableone-package.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/tableone-package.R b/R/tableone-package.R index 411f91a..d193dfb 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -1,6 +1,6 @@ ##' Create "Table 1" to describe baseline characteristics ##' -##' Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package. See github for a screencast. tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. +##' Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package. See github for a screencast. tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. Most important functions are \code{\link{CreateTableOne}} and \code{\link{svyCreateTableOne}}. ##' ##' @name tableone-package ##' @aliases tableone-package tableone @@ -8,18 +8,17 @@ ##' @import survey MASS e1071 zoo gmodels ##' @note Special Thanks: ##' -##' Ian Fellows for developing the Deducer package, which this package is based on. +##' Ian Fellows for developing the \code{deducer} package, which this package is based on. ##' -##' Hadley Wickham for packaging advice and for creating tools this package was made with (roxygen2, devtools, testthat). +##' Hadley Wickham for packaging advice and for creating tools this package was made with (\code{roxygen2}, \code{devtools}, \code{testthat}). ##' ##' Yoshinobu Kanda for design advice and for integration into \code{RcmdrPlugin.EZR}. ##' -##' jomuller for a bug report and fix suggestion regarding handling of ordered factors. -##' -##' Raja Sriswan Mamidi for suggestions regarding alignment. +##' jomuller, Raja Sriswan Mamidi, and Atsushi Shiraishi for bug reports and/or feature suggestions. ##' ##' Members of the Facebook Organization of R Users for Medical Statistics in Japan (FORUMS-J) for testing pre-release versions and suggestions. ##' +##' ##' Developmental repository is on github. Your contributions are appreciated. ##' ##' https://github.com/kaz-yos/tableone From 4a24545840289e91ec0da8ddeb6347c679b7f557 Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 15:09:24 -0400 Subject: [PATCH 170/219] Update acknowledgement to include contributors of info regarding SMD --- R/tableone-package.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/tableone-package.R b/R/tableone-package.R index d193dfb..45926d8 100644 --- a/R/tableone-package.R +++ b/R/tableone-package.R @@ -6,7 +6,7 @@ ##' @aliases tableone-package tableone ##' @docType package ##' @import survey MASS e1071 zoo gmodels -##' @note Special Thanks: +##' @note Acknowledgement: ##' ##' Ian Fellows for developing the \code{deducer} package, which this package is based on. ##' @@ -14,6 +14,8 @@ ##' ##' Yoshinobu Kanda for design advice and for integration into \code{RcmdrPlugin.EZR}. ##' +##' H.Tachibana and Hiroki Matsui for inputs regarding standardized mean differences. +##' ##' jomuller, Raja Sriswan Mamidi, and Atsushi Shiraishi for bug reports and/or feature suggestions. ##' ##' Members of the Facebook Organization of R Users for Medical Statistics in Japan (FORUMS-J) for testing pre-release versions and suggestions. From e3747e27b3c120db9abcde06c6543afe44fb61ff Mon Sep 17 00:00:00 2001 From: kaz-yos Date: Sat, 1 Aug 2015 16:45:11 -0400 Subject: [PATCH 171/219] Update manual files and example output --- cran-check.txt | 13 - man/CreateCatTable.Rd | 21 +- man/CreateContTable.Rd | 13 +- man/CreateTableOne.Rd | 35 +- man/ShowRegTable.Rd | 4 +- man/print.CatTable.Rd | 18 +- man/print.ContTable.Rd | 18 +- man/print.TableOne.Rd | 69 +- man/print.svyCatTable.Rd | 16 +- man/print.svyContTable.Rd | 18 +- man/summary.CatTable.Rd | 8 +- man/summary.ContTable.Rd | 8 +- man/summary.TableOne.Rd | 36 +- man/summary.svyCatTable.Rd | 8 +- man/summary.svyContTable.Rd | 8 +- man/svyCreateCatTable.Rd | 9 +- man/svyCreateContTable.Rd | 9 +- man/svyCreateTableOne.Rd | 26 +- man/tableone-package.Rd | 121 +- tableone.Rcheck/tableone-Ex.Rout | 3235 ++++-------------------------- 20 files changed, 530 insertions(+), 3163 deletions(-) diff --git a/cran-check.txt b/cran-check.txt index b209cc2..d3b965d 100644 --- a/cran-check.txt +++ b/cran-check.txt @@ -1,17 +1,4 @@ Rscript -e "library(methods); library(roxygen2); roxygenize('.')" -R CMD build ../tableone -* checking for file ‘../tableone/DESCRIPTION’ ... OK -* preparing ‘tableone’: -* checking DESCRIPTION meta-information ... OK -* installing the package to build vignettes -* creating vignettes ... OK -* excluding invalid files -Subdirectory 'man' contains invalid file names: - ‘Rd2roxygen.R’ ‘clean_comments.sh’ -* checking for LF line-endings in source and make files -* checking for empty or unneeded directories -Removed empty directory ‘tableone/data’ -* building ‘tableone_0.7.0.tar.gz’ R CMD check --as-cran ./tableone_0.7.0.tar.gz * using log directory ‘/Users/kazuki/Documents/programming/r/tableone/tableone.Rcheck’ * using R version 3.2.1 (2015-06-18) diff --git a/man/CreateCatTable.Rd b/man/CreateCatTable.Rd index 2e4651e..411dd2c 100644 --- a/man/CreateCatTable.Rd +++ b/man/CreateCatTable.Rd @@ -20,24 +20,21 @@ CreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that require the large sample approximation and exact tests are performed. Either one of the result can be obtained from the print method.} -\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{chisq.test}. This is not recommended when some of the cell have small counts like fewer than 5.} -\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{chisq.test}.} -\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} +\item{testExact}{A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} -\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} +\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}.} \item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ -An object of class \code{CatTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +An object of class \code{CatTable}. } \description{ -Create an object summarizing categorical variables optionally stratifying -by one or more startifying variables and performing statistical tests. The -object gives a table that is easy to use in medical research papers. See -also \code{\link{print.CatTable}} and \code{\link{summary.CatTable}}. +Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{CreateTableOne}} should be used as the universal frontend for both continuous and categorical data. } \examples{ ## Load @@ -80,7 +77,7 @@ catTableBySexTrt <- CreateCatTable(vars = catVars, ## print now includes p-values which are by default calculated by chisq.test. ## It is formatted at the decimal place specified by the pDigits argument -## (3 by default). It does <0.001 for you. +## (3 by default). It is formatted like <0.001 if very small. catTableBySexTrt ## The exact argument toggles the p-values to the exact test result from @@ -102,8 +99,6 @@ print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) Kazuki Yoshida (based on \code{Deducer::frequencies()}) } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateTableOne}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} } diff --git a/man/CreateContTable.Rd b/man/CreateContTable.Rd index 6409e59..6ceb6a9 100644 --- a/man/CreateContTable.Rd +++ b/man/CreateContTable.Rd @@ -23,7 +23,7 @@ CreateContTable(vars, strata, data, funcNames = c("n", "miss", "p.miss", \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed. Both tests that assume normality and tests that do not are performed. Either one of the result can be obtained from the print method.} -\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} +\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{oneway.test}. This is equivalent of the t-test when there are only two groups.} \item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} @@ -34,13 +34,10 @@ CreateContTable(vars, strata, data, funcNames = c("n", "miss", "p.miss", \item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated.} } \value{ -An object of class \code{ContTable}, which really is a \code{\link{by}} object with additional attributes. Each element of the \code{\link{by}} part is a matrix with rows representing variables, and columns representing summary statistics. +An object of class \code{ContTable}. } \description{ -Create an object summarizing continous variables optionally stratifying by -one or more startifying variables and performing statistical tests. The -object gives a table that is easy to use in medical research papers. See -also \code{\link{print.ContTable}} and \code{\link{summary.ContTable}}. +Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{CreateTableOne}} should be used as the universal frontend for both continuous and categorical data. } \examples{ ## Load @@ -102,8 +99,6 @@ print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRU Kazuki Yoshida (based on \code{Deducer::descriptive.table()}) } \seealso{ -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateTableOne}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} } diff --git a/man/CreateTableOne.Rd b/man/CreateTableOne.Rd index 73c977b..448bacf 100644 --- a/man/CreateTableOne.Rd +++ b/man/CreateTableOne.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/CreateTableOne.R \name{CreateTableOne} \alias{CreateTableOne} -\title{Create an object summarizing both categorical and continuous variables} +\title{Create an object summarizing both continuous and categorical variables} \usage{ CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, test = TRUE, testApprox = chisq.test, argsApprox = list(correct = TRUE), @@ -23,15 +23,15 @@ CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, \item{test}{If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.} -\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{\link{chisq.test}}. This is not recommended when some of the cell have small counts like fewer than 5.} +\item{testApprox}{A function used to perform the large sample approximation based tests. The default is \code{chisq.test}. This is not recommended when some of the cell have small counts like fewer than 5.} -\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{\link{chisq.test}}.} +\item{argsApprox}{A named list of arguments passed to the function specified in testApprox. The default is \code{list(correct = TRUE)}, which turns on the continuity correction for \code{chisq.test}.} -\item{testExact}{A function used to perform the exact tests. The default is fisher.test. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} +\item{testExact}{A function used to perform the exact tests. The default is \code{fisher.test}. If the cells have large numbers, it will fail because of memory limitation. In this situation, the large sample approximation based should suffice.} -\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{\link{fisher.test}}.} +\item{argsExact}{A named list of arguments passed to the function specified in testExact. The default is \code{list(workspace = 2*10^5)}, which specifies the memory space allocated for \code{fisher.test}.} -\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{\link{oneway.test}}. This is equivalent of the t-test when there are only two groups.} +\item{testNormal}{A function used to perform the normal assumption based tests. The default is \code{oneway.test}. This is equivalent of the t-test when there are only two groups.} \item{argsNormal}{A named list of arguments passed to the function specified in \code{testNormal}. The default is \code{list(var.equal = TRUE)}, which makes it the ordinary ANOVA that assumes equal variance across groups.} @@ -42,18 +42,16 @@ CreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, \item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ -An object of class \code{TableOne}, which really is a list of three objects. +An object of class \code{TableOne}, which is a list of three objects. -\item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} +\item{ContTable}{object of class \code{ContTable}, containing continuous variables only} -\item{ContTable}{an object of class \code{ContTable}, containing continuous variables only} +\item{CatTable}{object of class \code{CatTable}, containing categorical variables only} -\item{CatTable}{ an object of class \code{CatTable}, containing categorical variables only} - -The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +\item{MetaData}{list of metadata regarding variables} } \description{ -Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +Create an object summarizing all baseline variables (both continuous and categorical) optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. } \examples{ ## Load @@ -84,9 +82,10 @@ tableOne ## Specifying nonnormal variables will show the variables appropriately, ## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. +## argument to obtain the exact test p-values. cramVars can be used to +## show both levels for a 2-level categorical variables. print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage")) + exact = c("status","stage"), cramVars = "hepato", smd = TRUE) ## Use the summary.TableOne method for detailed summary summary(tableOne) @@ -110,11 +109,9 @@ print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), exact = c("status","stage"), quote = TRUE, noSpaces = TRUE) } \author{ -Justin Bohn, Kazuki Yoshida +Kazuki Yoshida, Justin Bohn } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +\code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/ShowRegTable.Rd b/man/ShowRegTable.Rd index a34720a..cc79a2a 100644 --- a/man/ShowRegTable.Rd +++ b/man/ShowRegTable.Rd @@ -5,7 +5,7 @@ \title{Format regression results in medically decent format} \usage{ ShowRegTable(model, exp = TRUE, digits = 2, pDigits = 3, - printToggle = TRUE, quote = FALSE, simpleCi = FALSE) + printToggle = TRUE, quote = FALSE, ciFun = confint) } \arguments{ \item{model}{Regression model result objects that have the summary and confint methods.} @@ -20,7 +20,7 @@ ShowRegTable(model, exp = TRUE, digits = 2, pDigits = 3, \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} -\item{simpleCi}{Whether to calculate confidence interval by the default normal approximation method. The default is FALSE. If TRUE, the default normal approximation method is used. This may be used when the profile likelihood-based calculation takes too much time.} +\item{ciFun}{Function used for calculation. \code{confint} is the default. For generalized linear models this gives the profile likelihood-based calculation, which may take too much time for large models. Use \code{confint.default} for simple normal approximation method (+/- 1.96 * standard error).} } \value{ A matrix containing what you see is returned invisibly. You can capture it by assignment to an object. diff --git a/man/print.CatTable.Rd b/man/print.CatTable.Rd index d57e4e6..1110aac 100644 --- a/man/print.CatTable.Rd +++ b/man/print.CatTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.CatTable.R \name{print.CatTable} \alias{print.CatTable} -\title{Format and print the \code{CatTable} class objects} +\title{Format and print \code{CatTable} class objects} \usage{ \method{print}{CatTable}(x, digits = 1, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -11,11 +11,11 @@ CrossTable = FALSE, ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{CreateCatTable}} function.} +\item{x}{Object returned by \code{\link{CreateCatTable}} function.} \item{digits}{Number of digits to print in the table.} -\item{pDigits}{Number of digits to print for p-values.} +\item{pDigits}{Number of digits to print for p-values (also used for standardized mean differences).} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} @@ -33,21 +33,21 @@ \item{cramVars}{A character vector to specify the two-level categorical variables, for which both levels should be shown in one row.} -\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{test}{Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} \item{exact}{A character vector to specify the variables for which the p-values should be those of exact tests. By default all p-values are from large sample approximation tests (chisq.test).} -\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} +\item{smd}{Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} \item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} \item{...}{For compatibility with generic. Ignored.} } \value{ -It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. } \description{ -This is the \code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. +\code{print} method for the \code{CatTable} class objects created by \code{\link{CreateCatTable}} function. } \examples{ ## Load @@ -111,8 +111,6 @@ print(catTableBySexTrt, exact = "ascites", quote = TRUE, noSpaces = TRUE) Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateCatTable}}, \code{\link{summary.CatTable}} } diff --git a/man/print.ContTable.Rd b/man/print.ContTable.Rd index 1399cb3..4815fcc 100644 --- a/man/print.ContTable.Rd +++ b/man/print.ContTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.ContTable.R \name{print.ContTable} \alias{print.ContTable} -\title{Format and print the \code{ContTable} class objects} +\title{Format and print \code{ContTable} class objects} \usage{ \method{print}{ContTable}(x, digits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -10,11 +10,11 @@ smd = FALSE, ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{CreateContTable}} function.} +\item{x}{Object returned by \code{\link{CreateContTable}} function.} \item{digits}{Number of digits to print in the table.} -\item{pDigits}{Number of digits to print for p-values.} +\item{pDigits}{Number of digits to print for p-values (also used for standardized mean differences).} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} @@ -32,17 +32,17 @@ \item{insertLevel}{Whether to add an empty level column to the left of strata.} -\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{test}{Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} -\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} +\item{smd}{Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} \item{...}{For compatibility with generic. Ignored.} } \value{ -It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. } \description{ -This is the \code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. +\code{print} method for the \code{ContTable} class objects created by \code{\link{CreateContTable}} function. } \examples{ ## Load @@ -107,8 +107,6 @@ print(contTableBySexTrt, nonnormal = nonNormalVars, quote = TRUE, noSpaces = TRU Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateContTable}}, \code{\link{summary.ContTable}} } diff --git a/man/print.TableOne.Rd b/man/print.TableOne.Rd index 67ccca3..5dd2751 100644 --- a/man/print.TableOne.Rd +++ b/man/print.TableOne.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.TableOne.R \name{print.TableOne} \alias{print.TableOne} -\title{Format and print the \code{TableOne} class objects} +\title{Format and print \code{TableOne} class objects} \usage{ \method{print}{TableOne}(x, catDigits = 1, contDigits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, @@ -11,13 +11,13 @@ nonnormal = NULL, minMax = FALSE, ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{CreateTableOne}} function.} +\item{x}{Object returned by \code{\link{CreateTableOne}} function.} \item{catDigits}{Number of digits to print for proportions. Default 1.} \item{contDigits}{Number of digits to print for continuous variables. Default 2.} -\item{pDigits}{Number of digits to print for p-values. Default 3.} +\item{pDigits}{Number of digits to print for p-values (also used for standardized mean differences). Default 3.} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} @@ -27,9 +27,9 @@ \item{printToggle}{Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned.} -\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{test}{Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} -\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} +\item{smd}{Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} \item{noSpaces}{Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software.} @@ -48,69 +48,18 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. } \description{ -This is the \code{print} method for the \code{TableOne} class objects created by \code{\link{CreateTableOne}} function. +\code{print} method for the \code{TableOne} class objects created by \code{\link{CreateTableOne}} function. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Make categorical variables factors -varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - -## Create Table 1 stratified by sex and trt -tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) - -## Just typing the object name will invoke the print.TableOne method -tableOne - -## Specifying nonnormal variables will show the variables appropriately, -## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. cramVars can be used to -## show both levels for a 2-level categorical variables. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato") - -## Use the summary.TableOne method for detailed summary -summary(tableOne) - -## See the categorical part only using $ operator -tableOne$CatTable -summary(tableOne$CatTable) - -## See the continuous part only using $ operator -tableOne$ContTable -summary(tableOne$ContTable) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) +## See examples for CreateTableOne and svyCreateTableOne } \author{ Kazuki Yoshida, Justin Bohn } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}} +\code{\link{CreateTableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/print.svyCatTable.Rd b/man/print.svyCatTable.Rd index 8d891d6..3bbce4b 100644 --- a/man/print.svyCatTable.Rd +++ b/man/print.svyCatTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.svyCatTable.R \name{print.svyCatTable} \alias{print.svyCatTable} -\title{Format and print the \code{svyCatTable} class objects} +\title{Format and print \code{svyCatTable} class objects} \usage{ \method{print}{svyCatTable}(x, digits = 1, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -15,7 +15,7 @@ \item{digits}{Number of digits to print in the table.} -\item{pDigits}{Number of digits to print for p-values.} +\item{pDigits}{Number of digits to print for p-values (also used for standardized mean differences).} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} @@ -33,21 +33,21 @@ \item{cramVars}{A character vector to specify the two-level categorical variables, for which both levels should be shown in one row.} -\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{test}{Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} \item{exact}{This option is not available for tables from weighted data.} -\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} +\item{smd}{Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown. For categorical variables, Yang and Dalton's definition is used.} \item{CrossTable}{Whether to show the cross table objects held internally using gmodels::CrossTable function. This will give an output similar to the PROC FREQ in SAS.} \item{...}{For compatibility with generic. Ignored.} } \value{ -It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. } \description{ -This is the \code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. +\code{print} method for the \code{svyCatTable} class objects created by \code{\link{svyCreateCatTable}} function. } \examples{ ## See the examples for svyCreateTableOne() @@ -56,8 +56,6 @@ This is the \code{print} method for the \code{svyCatTable} class objects created Kazuki Yoshida } \seealso{ -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} } diff --git a/man/print.svyContTable.Rd b/man/print.svyContTable.Rd index 5b5a82b..7b893a6 100644 --- a/man/print.svyContTable.Rd +++ b/man/print.svyContTable.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/print.svyContTable.R \name{print.svyContTable} \alias{print.svyContTable} -\title{Format and print the \code{svyContTable} class objects} +\title{Format and print \code{svyContTable} class objects} \usage{ \method{print}{svyContTable}(x, digits = 2, pDigits = 3, quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, noSpaces = FALSE, @@ -10,11 +10,11 @@ smd = FALSE, ...) } \arguments{ -\item{x}{The result of a call to the \code{\link{svyCreateContTable}} function.} +\item{x}{Object returned by \code{\link{svyCreateContTable}} function.} \item{digits}{Number of digits to print in the table.} -\item{pDigits}{Number of digits to print for p-values.} +\item{pDigits}{Number of digits to print for p-values (also used for standardized mean differences).} \item{quote}{Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are quoted so that you can copy it to Excel easily.} @@ -32,17 +32,17 @@ \item{insertLevel}{Whether to add an empty level column to the left of strata.} -\item{test}{Whether to show the p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} +\item{test}{Whether to show p-values. TRUE by default. If FALSE, only the numerical summaries are shown.} -\item{smd}{Whether to show the standardized mean difference. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} +\item{smd}{Whether to show standardized mean differences. FALSE by default. If there are more than one contrasts, the average of all possible standardized mean differences is shown.} \item{...}{For compatibility with generic. Ignored.} } \value{ -It is mainly for printing the result. But this function does return a matrix containing what you see in the output invisibly. You can assign it to an object to save it. +A matrix object containing what you see is also invisibly returned. This can be assinged a name and exported via \code{write.csv}. } \description{ -This is the \code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. +\code{print} method for the \code{svyContTable} class objects created by \code{\link{CreateContTable}} function. } \examples{ ## See the examples for svyCreateTableOne() @@ -51,8 +51,6 @@ This is the \code{print} method for the \code{svyContTable} class objects create Kazuki Yoshida } \seealso{ -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{summary.svyCatTable}} } diff --git a/man/summary.CatTable.Rd b/man/summary.CatTable.Rd index a07f7b0..0751e8f 100644 --- a/man/summary.CatTable.Rd +++ b/man/summary.CatTable.Rd @@ -14,10 +14,10 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It will print the results. +None. Results are printed. } \description{ -This method shows all the data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +Shows all data a \code{CatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{chisq.test} by default) and exact method test (\code{fisher.test} by default) and standardized mean differences of all possible pairwise contrasts. } \examples{ ## Load @@ -46,8 +46,6 @@ summary(catTableOverall) Kazuki Yoshida } \seealso{ -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, } diff --git a/man/summary.ContTable.Rd b/man/summary.ContTable.Rd index 2dde221..0543323 100644 --- a/man/summary.ContTable.Rd +++ b/man/summary.ContTable.Rd @@ -14,10 +14,10 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It will print the results. +None. Results are printed. } \description{ -This method shows all the data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +Shows all data a \code{ContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{oneway.test} by default) and nonparametric test (\code{kruskal.test} by default) and standardized mean differences of all possible pairwise contrasts. } \examples{ ## Load @@ -46,8 +46,6 @@ summary(contTableOverall) Kazuki Yoshida } \seealso{ -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{CreateContTable}}, \code{\link{print.ContTable}} } diff --git a/man/summary.TableOne.Rd b/man/summary.TableOne.Rd index 962ff5d..047ba04 100644 --- a/man/summary.TableOne.Rd +++ b/man/summary.TableOne.Rd @@ -14,46 +14,18 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It will print the results. +None. Results are printed. } \description{ -This method shows all the data a \code{(svy)TableOne} class object has. This -includes the (optionally stratified) part with summary statistics and p-values -and/or standardized mean differences. +Shows all data a \code{(svy)TableOne} class object has. This includes the (optionally stratified) part with summary statistics and p-values and/or standardized mean differences. } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## Make categorical variables factors -varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - -## Create Table 1 stratified by sex and trt -tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) - -## Just typing the object name will invoke the print.TableOne method -tableOne - -## Use the summary.TableOne method for detailed summary -summary(tableOne) +## See examples for CreateTableOne and svyCreateTableOne } \author{ Kazuki Yoshida } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}} +\code{\link{CreateTableOne}}, \code{\link{svyCreateCatTable}} } diff --git a/man/summary.svyCatTable.Rd b/man/summary.svyCatTable.Rd index d0892f6..82f124b 100644 --- a/man/summary.svyCatTable.Rd +++ b/man/summary.svyCatTable.Rd @@ -14,10 +14,10 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It will print the results. +None. Results are printed. } \description{ -This method shows all the data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the approximation method test (\code{\link{chisq.test}} by default) and exact method test (\code{\link{fisher.test}} by default). +Shows all data a \code{svyCatTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the approximation method test (\code{chisq.test} by default) and exact method test (\code{fisher.test} by default) and standardized mean differences of all possible pairwise contrasts. } \examples{ ## See the examples for svyCreateTableOne() @@ -26,8 +26,6 @@ This method shows all the data a \code{svyCatTable} class object has. This inclu Kazuki Yoshida } \seealso{ -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}} } diff --git a/man/summary.svyContTable.Rd b/man/summary.svyContTable.Rd index 397156f..24ea0c0 100644 --- a/man/summary.svyContTable.Rd +++ b/man/summary.svyContTable.Rd @@ -14,10 +14,10 @@ \item{...}{For compatibility with generic. Ignored.} } \value{ -It will print the results. +None. Results are printed. } \description{ -This method shows all the data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and , if available, p-values from the normal assupmtion-based test (\code{\link{oneway.test}} by default) and nonparametric test (\code{\link{kruskal.test}} by default). +Shows all data a \code{svyContTable} class object has. This includes the (optionally stratified) part with summary statistics and, if available, p-values from the normal assupmtion-based test (\code{regTermTest} with \code{svyglm} by default) and nonparametric test (\code{svyranktest} by default) and standardized mean differences of all possible pairwise contrasts. } \examples{ ## See the examples for svyCreateTableOne() @@ -26,8 +26,6 @@ This method shows all the data a \code{svyContTable} class object has. This incl Kazuki Yoshida } \seealso{ -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}} } diff --git a/man/svyCreateCatTable.Rd b/man/svyCreateCatTable.Rd index cc1fc40..f7b4eb4 100644 --- a/man/svyCreateCatTable.Rd +++ b/man/svyCreateCatTable.Rd @@ -28,10 +28,7 @@ svyCreateCatTable(vars, strata, data, includeNA = FALSE, test = TRUE, An object of class \code{svyCatTable}. } \description{ -Create an object summarizing categorical variables optionally stratifying -by one or more startifying variables and performing statistical tests. The -object gives a table that is easy to use in medical research papers. See -also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. +Create an object summarizing categorical variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{svyCreateTableOne}} should be used as the universal frontend for both continuous and categorical data. } \examples{ ## See the examples for svyCreateTableOne() @@ -40,8 +37,6 @@ also \code{\link{print.svyCatTable}} and \code{\link{summary.svyCatTable}}. Kazuki Yoshida } \seealso{ -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateTableOne}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, } diff --git a/man/svyCreateContTable.Rd b/man/svyCreateContTable.Rd index 144a082..6537f33 100644 --- a/man/svyCreateContTable.Rd +++ b/man/svyCreateContTable.Rd @@ -31,10 +31,7 @@ svyCreateContTable(vars, strata, data, test = TRUE, An object of class \code{svyContTable}. } \description{ -Create an object summarizing continous variables optionally stratifying by -one or more startifying variables and performing statistical tests. The -object gives a table that is easy to use in medical research papers. See -also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. +Create an object summarizing continous variables optionally stratifying by one or more startifying variables and performing statistical tests. Usually, \code{\link{svyCreateTableOne}} should be used as the universal frontend for both continuous and categorical data. } \examples{ ## See the examples for svyCreateTableOne() @@ -43,8 +40,6 @@ also \code{\link{print.svyContTable}} and \code{\link{summary.svyContTable}}. Kazuki Yoshida } \seealso{ -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}} +\code{\link{svyCreateTableOne}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, } diff --git a/man/svyCreateTableOne.Rd b/man/svyCreateTableOne.Rd index e8f6009..a75dcbd 100644 --- a/man/svyCreateTableOne.Rd +++ b/man/svyCreateTableOne.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/svyCreateTableOne.R \name{svyCreateTableOne} \alias{svyCreateTableOne} -\title{Create an object summarizing any variables for weighted data} +\title{Create an object summarizing both continuous and categorical variables for weighted data} \usage{ svyCreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, test = TRUE, testApprox = svyTestChisq, argsApprox = NULL, @@ -37,18 +37,16 @@ svyCreateTableOne(vars, strata, data, factorVars, includeNA = FALSE, \item{smd}{If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated. For categorical variables, Yang and Dalton's definition is used.} } \value{ -An object of class \code{svyTableOne}, which really is a list of three objects. - -\item{TableOne}{a categorical-continuous mixture data formatted and printed by the \code{\link{print.TableOne}} method} +An object of class \code{svyTableOne}, which is a list of three objects. \item{ContTable}{an object of class \code{svyContTable}, containing continuous variables only} \item{CatTable}{ an object of class \code{svyCatTable}, containing categorical variables only} -The second and third objects can be then be examined with the \code{print} and \code{summary} method, for example, \code{summary(object$CatTable)} to examine the categorical variables in detail. +\item{MetaData}{list of metadata regarding variables} } \description{ -Create an object summarizing all baseline variables optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. See also \code{\link{print.TableOne}} and \code{\link{summary.TableOne}}. +Create an object summarizing all baseline variables (both continuous and categorical) optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers. } \examples{ ## Load packages @@ -61,8 +59,8 @@ nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2Y nest = TRUE, data = nhanes) ## Create a table object -## factorVars are converted to factors; no need to do this if variables are already factors -## strata will stratify summaries; leave it unspecified, and overview is obtained +## factorVars are converted to factors; no need for variables already factors +## strata will stratify summaries; leave it unspecified for overall summaries tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), strata = "RIAGENDR", data = nhanesSvy, factorVars = c("race","RIAGENDR")) @@ -74,13 +72,15 @@ summary(tab1) tab1 ## nonnormal specifies variables to be shown as median [IQR] -print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) +print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, + pDigits = 4, smd = TRUE) ## minMax changes it to median [min, max] -print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) +print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, + catDigits = 2, pDigits = 4, smd = TRUE) ## showAllLevels can be used tow show levels for all categorical variables -print(tab1, showAllLevels = TRUE) +print(tab1, showAllLevels = TRUE, smd = TRUE) ## To see all printing options ?print.TableOne @@ -95,8 +95,6 @@ tab1$ContTable Kazuki Yoshida } \seealso{ -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}} +\code{\link{print.TableOne}}, \code{\link{summary.TableOne}} } diff --git a/man/tableone-package.Rd b/man/tableone-package.Rd index f11d988..563ac24 100644 --- a/man/tableone-package.Rd +++ b/man/tableone-package.Rd @@ -6,127 +6,30 @@ \alias{tableone-package} \title{Create "Table 1" to describe baseline characteristics} \description{ -This package creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. This package provides functions to create such summaries for continuous and categorical variables, optionally with subgroup comparisons. The package was insipired by and based on descriptive statistics functions in Deducer, a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. +Creates "Table 1", i.e., description of baseline patient characteristics, which is essential in every medical research. Supports both continuous and categorical variables, as well as p-values and standardized mean differences. Weighted data are supported via the survey package. See github for a screencast. tableone was inspired by descriptive statistics functions in Deducer , a Java-based GUI package by Ian Fellows. This package does not require GUI or Java, and intended for command-line users. Most important functions are \code{\link{CreateTableOne}} and \code{\link{svyCreateTableOne}}. } \note{ -Special Thanks: +Acknowledgement: -Ian Fellows for developing the Deducer package, which this package is based on. +Ian Fellows for developing the \code{deducer} package, which this package is based on. -Hadley Wickham for packaging advice and for creating tools this package was made with (roxygen2, devtools, testthat). +Hadley Wickham for packaging advice and for creating tools this package was made with (\code{roxygen2}, \code{devtools}, \code{testthat}). Yoshinobu Kanda for design advice and for integration into \code{RcmdrPlugin.EZR}. -jomuller for a bug report and fix suggestion regarding handling of ordered factors. +H.Tachibana and Hiroki Matsui for inputs regarding standardized mean differences. -Raja Sriswan Mamidi for suggestions regarding alignment. +jomuller, Raja Sriswan Mamidi, and Atsushi Shiraishi for bug reports and/or feature suggestions. Members of the Facebook Organization of R Users for Medical Statistics in Japan (FORUMS-J) for testing pre-release versions and suggestions. + Developmental repository is on github. Your contributions are appreciated. https://github.com/kaz-yos/tableone } \examples{ -## Load -library(tableone) - -## Load Mayo Clinic Primary Biliary Cirrhosis Data -library(survival) -data(pbc) -## Check variables -head(pbc) - -## List numerically coded categorical variables for later conversion. -## Factor variables are automatically handled as categorical variables. -factorVars <- c("status","trt","ascites","hepato","spiders","edema","stage") - -## Create a variable list -dput(names(pbc)) # This shows a character vector-creating syntax. -vars <- c("time","status","age","sex","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage") - -## Create Table 1 stratified by trt. Use factorVars to convert numerically -## coded categorical variables as factors without changing the dataset. -tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, - factorVars = factorVars) - -## Just typing the object name will invoke the print.TableOne method -tableOne - -## Specifying nonnormal variables will show the variables appropriately, -## and show nonparametric test p-values. Specify variables in the exact -## argument to obtain the exact test p-values. For two-level categorical -## variables specified in cramVars, both levels are shown. Use minMax -## argument to show median [min, max] for nonnormal variables. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "sex") - -## Use the summary.TableOne method for detailed summary -summary(tableOne) - -## See the categorical part only using $ operator -tableOne$CatTable -summary(tableOne$CatTable) - -## See the continuous part only using $ operator -tableOne$ContTable -summary(tableOne$ContTable) - -## If your work flow includes copying to Excel and Word when writing manuscripts, -## you may benefit from the quote argument. This will quote everything so that -## Excel does not mess up the cells. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "sex", quote = TRUE) - -## If you want to center-align values in Word, use noSpaces option. -print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "sex", quote = TRUE, noSpaces = TRUE) - - -## Analysis for weighted data - -## Load packages -library(tableone) -library(survey) - -## Create a weighted survey design object -data(nhanes) -nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, - nest = TRUE, data = nhanes) - -## Create a table object -## factorVars are converted to factors; no need to do this if variables are already factors -## strata will stratify summaries; leave it unspecified, and overview is obtained -tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), - strata = "RIAGENDR", data = nhanesSvy, - factorVars = c("race","RIAGENDR")) - -## Detailed output -summary(tab1) - -## Default formatted printing -tab1 - -## nonnormal specifies variables to be shown as median [IQR] -print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) - -## minMax changes it to median [min, max] -print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) - -## showAllLevels can be used tow show levels for all categorical variables -print(tab1, showAllLevels = TRUE) - -## To see all printing options -?print.TableOne - -## To examine categorical variables only -tab1$CatTable - -## To examine continuous variables only -tab1$ContTable +## See examples for CreateTableOne and svyCreateTableOne } \author{ Kazuki Yoshida, Justin Bohn @@ -134,12 +37,6 @@ Kazuki Yoshida, Justin Bohn Maintainer: Kazuki Yoshida } \seealso{ -\code{\link{CreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{CreateContTable}}, \code{\link{print.ContTable}}, \code{\link{summary.ContTable}}, -\code{\link{CreateCatTable}}, \code{\link{print.CatTable}}, \code{\link{summary.CatTable}}, -\code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, -\code{\link{svyCreateContTable}}, \code{\link{print.svyContTable}}, \code{\link{summary.svyContTable}}, -\code{\link{svyCreateCatTable}}, \code{\link{print.svyCatTable}}, \code{\link{summary.svyCatTable}}, -\code{\link{ShowRegTable}} +\code{\link{CreateTableOne}}, \code{\link{svyCreateTableOne}}, \code{\link{print.TableOne}}, \code{\link{summary.TableOne}}, \code{\link{ShowRegTable}} } diff --git a/tableone.Rcheck/tableone-Ex.Rout b/tableone.Rcheck/tableone-Ex.Rout index 9063383..8bc3f49 100644 --- a/tableone.Rcheck/tableone-Ex.Rout +++ b/tableone.Rcheck/tableone-Ex.Rout @@ -221,7 +221,7 @@ strata: Overall > > ## print now includes p-values which are by default calculated by chisq.test. > ## It is formatted at the decimal place specified by the pDigits argument -> ## (3 by default). It does <0.001 for you. +> ## (3 by default). It is formatted like <0.001 if very small. > catTableBySexTrt Stratified by sex:trt m:1 f:1 m:2 f:2 p test @@ -981,7 +981,7 @@ detaching ‘package:survival’ > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: CreateTableOne -> ### Title: Create an object summarizing both categorical and continuous +> ### Title: Create an object summarizing both continuous and categorical > ### variables > ### Aliases: CreateTableOne > @@ -1063,9 +1063,10 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", > > ## Specifying nonnormal variables will show the variables appropriately, > ## and show nonparametric test p-values. Specify variables in the exact -> ## argument to obtain the exact test p-values. +> ## argument to obtain the exact test p-values. cramVars can be used to +> ## show both levels for a 2-level categorical variables. > print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage")) ++ exact = c("status","stage"), cramVars = "hepato", smd = TRUE) Stratified by trt 1 2 n 158 154 @@ -1077,7 +1078,7 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", age (mean (sd)) 51.42 (11.01) 48.58 (9.96) sex = f (%) 137 (86.7) 139 (90.3) ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) - hepato = 1 (%) 73 (46.2) 87 (56.5) + hepato = 0/1 (%) 85/73 (53.8/46.2) 67/87 (43.5/56.5) spiders = 1 (%) 45 (28.5) 45 (29.2) edema (%) 0 132 (83.5) 131 (85.1) @@ -1098,36 +1099,36 @@ c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", 3 56 (35.4) 64 (41.6) 4 55 (34.8) 54 (35.1) Stratified by trt - p test - n - time (mean (sd)) 0.883 - status (%) 0.884 exact - 0 - 1 - 2 - age (mean (sd)) 0.018 - sex = f (%) 0.421 - ascites = 1 (%) 0.567 - hepato = 1 (%) 0.088 - spiders = 1 (%) 0.985 - edema (%) 0.877 - 0 - 0.5 - 1 - bili (median [IQR]) 0.842 nonnorm - chol (median [IQR]) 0.544 nonnorm - albumin (mean (sd)) 0.874 - copper (median [IQR]) 0.717 nonnorm - alk.phos (median [IQR]) 0.812 nonnorm - ast (mean (sd)) 0.460 - trig (median [IQR]) 0.370 nonnorm - platelet (mean (sd)) 0.555 - protime (mean (sd)) 0.197 - stage (%) 0.205 exact - 1 - 2 - 3 - 4 + p test SMD + n + time (mean (sd)) 0.883 0.017 + status (%) 0.884 exact 0.054 + 0 + 1 + 2 + age (mean (sd)) 0.018 0.270 + sex = f (%) 0.421 0.111 + ascites = 1 (%) 0.567 0.089 + hepato = 0/1 (%) 0.088 0.207 + spiders = 1 (%) 0.985 0.016 + edema (%) 0.877 0.058 + 0 + 0.5 + 1 + bili (median [IQR]) 0.842 nonnorm 0.171 + chol (median [IQR]) 0.544 nonnorm 0.038 + albumin (mean (sd)) 0.874 0.018 + copper (median [IQR]) 0.717 nonnorm <0.001 + alk.phos (median [IQR]) 0.812 nonnorm 0.037 + ast (mean (sd)) 0.460 0.084 + trig (median [IQR]) 0.370 nonnorm 0.017 + platelet (mean (sd)) 0.555 0.067 + protime (mean (sd)) 0.197 0.146 + stage (%) 0.205 exact 0.246 + 1 + 2 + 3 + 4 > > ## Use the summary.TableOne method for detailed summary > summary(tableOne) @@ -1678,7 +1679,7 @@ detaching ‘package:survival’ > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: print.CatTable -> ### Title: Format and print the 'CatTable' class objects +> ### Title: Format and print 'CatTable' class objects > ### Aliases: print.CatTable > > ### ** Examples @@ -2130,7 +2131,7 @@ detaching ‘package:survival’ > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: print.ContTable -> ### Title: Format and print the 'ContTable' class objects +> ### Title: Format and print 'ContTable' class objects > ### Aliases: print.ContTable > > ### ** Examples @@ -2674,11 +2675,68 @@ detaching ‘package:survival’ > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") > ### Name: print.TableOne -> ### Title: Format and print the 'TableOne' class objects +> ### Title: Format and print 'TableOne' class objects > ### Aliases: print.TableOne > > ### ** Examples > +> ## See examples for CreateTableOne and svyCreateTableOne +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("print.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("print.svyCatTable") +> ### * print.svyCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: print.svyCatTable +> ### Title: Format and print 'svyCatTable' class objects +> ### Aliases: print.svyCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("print.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("print.svyContTable") +> ### * print.svyContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: print.svyContTable +> ### Title: Format and print 'svyContTable' class objects +> ### Aliases: print.svyContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("print.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("summary.CatTable") +> ### * summary.CatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.CatTable +> ### Title: Shows all results in a 'CatTable' class object +> ### Aliases: summary.CatTable +> +> ### ** Examples +> > ## Load > library(tableone) > @@ -2702,2081 +2760,79 @@ detaching ‘package:survival’ 5 3.53 143 671.0 113.15 72 136 10.9 3 6 3.98 50 944.0 93.00 63 NA 11.0 3 > -> ## Make categorical variables factors -> varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -> pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) +> ## Create an overall table for categorical variables +> catVars <- c("status","ascites","hepato","spiders","edema","stage") +> catTableOverall <- CreateCatTable(vars = catVars, data = pbc) > -> ## Create Table 1 stratified by sex and trt -> tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -+ "spiders","edema","bili","chol","albumin", -+ "copper","alk.phos","ast","trig","platelet", -+ "protime","stage"), -+ strata = c("sex","trt"), data = pbc) +> ## Simply typing the object name will invoke the print.CatTable method, +> ## which will show the sample size, frequencies and percentages. +> ## For 2-level variables, only the higher level is shown for simplicity. +> catTableOverall + + Overall + n 418 + status (%) + 0 232 (55.5) + 1 25 ( 6.0) + 2 161 (38.5) + ascites = 1 (%) 24 ( 7.7) + hepato = 1 (%) 160 (51.3) + spiders = 1 (%) 90 (28.8) + edema (%) + 0 354 (84.7) + 0.5 44 (10.5) + 1 20 ( 4.8) + stage (%) + 1 21 ( 5.1) + 2 92 (22.3) + 3 155 (37.6) + 4 144 (35.0) > -> ## Just typing the object name will invoke the print.TableOne method -> tableOne - Stratified by sex:trt - m:1 f:1 m:2 - n 21 137 15 - time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) 2156.33 (1428.56) - status (%) - 0 4 (19.0) 79 (57.7) 7 (46.7) - 1 3 (14.3) 7 ( 5.1) 0 ( 0.0) - 2 14 (66.7) 51 (37.2) 8 (53.3) - age (mean (sd)) 55.57 (12.61) 50.78 (10.65) 57.09 (10.07) - ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) 2 (13.3) - hepato = 1 (%) 12 (57.1) 61 (44.5) 9 (60.0) - spiders = 1 (%) 3 (14.3) 42 (30.7) 1 ( 6.7) - edema (%) - 0 17 (81.0) 115 (83.9) 12 (80.0) - 0.5 3 (14.3) 13 ( 9.5) 1 ( 6.7) - 1 1 ( 4.8) 9 ( 6.6) 2 (13.3) - bili (mean (sd)) 2.98 (2.11) 2.86 (3.81) 2.72 (2.46) - chol (mean (sd)) 403.43 (204.95) 358.24 (210.46) 301.00 (111.32) - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.44) 3.50 (0.49) - copper (mean (sd)) 174.90 (105.33) 85.71 (82.27) 125.40 (89.18) - alk.phos (mean (sd)) 2486.16 (2385.32) 1950.04 (2151.35) 1734.45 (2478.07) - ast (mean (sd)) 128.71 (48.74) 118.91 (55.40) 112.58 (44.38) - trig (mean (sd)) 145.81 (56.62) 120.28 (73.41) 114.86 (39.59) - platelet (mean (sd)) 232.65 (97.38) 262.59 (100.53) 240.13 (73.93) - protime (mean (sd)) 10.84 (0.94) 10.62 (0.84) 11.23 (0.97) - stage (%) - 1 2 ( 9.5) 10 ( 7.3) 1 ( 6.7) - 2 4 (19.0) 31 (22.6) 2 (13.3) - 3 7 (33.3) 49 (35.8) 5 (33.3) - 4 8 (38.1) 47 (34.3) 7 (46.7) - Stratified by sex:trt - f:2 p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - status (%) 0.033 - 0 78 (56.1) - 1 9 ( 6.5) - 2 52 (37.4) - age (mean (sd)) 47.66 (9.54) <0.001 - ascites = 1 (%) 8 ( 5.8) 0.516 - hepato = 1 (%) 78 (56.1) 0.208 - spiders = 1 (%) 44 (31.7) 0.089 - edema (%) 0.906 - 0 119 (85.6) - 0.5 12 ( 8.6) - 1 8 ( 5.8) - bili (mean (sd)) 3.75 (5.50) 0.394 - chol (mean (sd)) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.53 (0.39) 0.585 - copper (mean (sd)) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 126.30 (60.27) 0.598 - trig (mean (sd)) 126.38 (60.22) 0.370 - platelet (mean (sd)) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.75 (1.15) 0.137 - stage (%) 0.646 - 1 3 ( 2.2) - 2 30 (21.6) - 3 59 (42.4) - 4 47 (33.8) +> ## To further examine the variables, use the summary.CatTable method, +> ## which will show more details. +> summary(catTableOverall) +strata: Overall + var n miss p.miss level freq percent cum.percent + status 418 0 0.0 0 232 55.5 55.5 + 1 25 6.0 61.5 + 2 161 38.5 100.0 + + ascites 418 106 25.4 0 288 92.3 92.3 + 1 24 7.7 100.0 + + hepato 418 106 25.4 0 152 48.7 48.7 + 1 160 51.3 100.0 + + spiders 418 106 25.4 0 222 71.2 71.2 + 1 90 28.8 100.0 + + edema 418 0 0.0 0 354 84.7 84.7 + 0.5 44 10.5 95.2 + 1 20 4.8 100.0 + + stage 418 6 1.4 1 21 5.1 5.1 + 2 92 22.3 27.4 + 3 155 37.6 65.0 + 4 144 35.0 100.0 + > -> ## Specifying nonnormal variables will show the variables appropriately, -> ## and show nonparametric test p-values. Specify variables in the exact -> ## argument to obtain the exact test p-values. cramVars can be used to -> ## show both levels for a 2-level categorical variables. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "hepato") - Stratified by sex:trt - m:1 f:1 - n 21 137 - time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) - status (%) - 0 4 (19.0) 79 (57.7) - 1 3 (14.3) 7 ( 5.1) - 2 14 (66.7) 51 (37.2) - age (mean (sd)) 55.57 (12.61) 50.78 (10.65) - ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) - hepato = 0/1 (%) 9/12 (42.9/57.1) 76/61 (55.5/44.5) - spiders = 1 (%) 3 (14.3) 42 (30.7) - edema (%) - 0 17 (81.0) 115 (83.9) - 0.5 3 (14.3) 13 ( 9.5) - 1 1 ( 4.8) 9 ( 6.6) - bili (median [IQR]) 2.30 [1.40, 4.00] 1.30 [0.80, 3.20] - chol (median [IQR]) 376.00 [251.00, 456.00] 309.00 [247.50, 399.50] - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.44) - copper (median [IQR]) 158.00 [100.00, 225.00] 67.00 [36.75, 105.00] - alk.phos (median [IQR]) 1664.00 [983.00, 2496.00] 1212.00 [823.00, 1877.00] - ast (mean (sd)) 128.71 (48.74) 118.91 (55.40) - trig (median [IQR]) 142.00 [107.00, 194.00] 101.00 [84.00, 134.00] - platelet (mean (sd)) 232.65 (97.38) 262.59 (100.53) - protime (mean (sd)) 10.84 (0.94) 10.62 (0.84) - stage (%) - 1 2 ( 9.5) 10 ( 7.3) - 2 4 (19.0) 31 (22.6) - 3 7 (33.3) 49 (35.8) - 4 8 (38.1) 47 (34.3) - Stratified by sex:trt - m:2 f:2 - n 15 139 - time (mean (sd)) 2156.33 (1428.56) 1979.65 (1127.52) - status (%) - 0 7 (46.7) 78 (56.1) - 1 0 ( 0.0) 9 ( 6.5) - 2 8 (53.3) 52 (37.4) - age (mean (sd)) 57.09 (10.07) 47.66 (9.54) - ascites = 1 (%) 2 (13.3) 8 ( 5.8) - hepato = 0/1 (%) 6/9 (40.0/60.0) 61/78 (43.9/56.1) - spiders = 1 (%) 1 ( 6.7) 44 (31.7) - edema (%) - 0 12 (80.0) 119 (85.6) - 0.5 1 ( 6.7) 12 ( 8.6) - 1 2 (13.3) 8 ( 5.8) - bili (median [IQR]) 1.90 [1.10, 2.85] 1.30 [0.70, 3.60] - chol (median [IQR]) 259.00 [235.75, 342.25] 306.50 [258.00, 381.00] - albumin (mean (sd)) 3.50 (0.49) 3.53 (0.39) - copper (median [IQR]) 84.00 [52.50, 198.00] 69.50 [42.50, 127.25] - alk.phos (median [IQR]) 1070.00 [737.00, 1211.50] 1345.00 [941.00, 1992.00] - ast (mean (sd)) 112.58 (44.38) 126.30 (60.27) - trig (median [IQR]) 108.50 [90.25, 137.00] 113.00 [84.00, 157.00] - platelet (mean (sd)) 240.13 (73.93) 267.95 (92.20) - protime (mean (sd)) 11.23 (0.97) 10.75 (1.15) - stage (%) - 1 1 ( 6.7) 3 ( 2.2) - 2 2 (13.3) 30 (21.6) - 3 5 (33.3) 59 (42.4) - 4 7 (46.7) 47 (33.8) - Stratified by sex:trt - p test - n - time (mean (sd)) 0.730 - status (%) 0.024 exact - 0 - 1 - 2 - age (mean (sd)) <0.001 - ascites = 1 (%) 0.516 - hepato = 0/1 (%) 0.208 - spiders = 1 (%) 0.089 - edema (%) 0.906 - 0 - 0.5 - 1 - bili (median [IQR]) 0.205 nonnorm - chol (median [IQR]) 0.458 nonnorm - albumin (mean (sd)) 0.585 - copper (median [IQR]) <0.001 nonnorm - alk.phos (median [IQR]) 0.180 nonnorm - ast (mean (sd)) 0.598 - trig (median [IQR]) 0.058 nonnorm - platelet (mean (sd)) 0.362 - protime (mean (sd)) 0.137 - stage (%) NA exact - 1 - 2 - 3 - 4 > -> ## Use the summary.TableOne method for detailed summary -> summary(tableOne) - - ### Summary of continuous variables ### - -sex: m -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 21 0 0 1793 1e+03 1302 999 2386 140.0 4459 1.04 0.1 -age 21 0 0 56 1e+01 56 46 66 33.5 78 -0.20 -0.7 -bili 21 0 0 3 2e+00 2 1 4 0.6 7 1.02 -0.1 -chol 21 0 0 403 2e+02 376 251 456 168.0 1000 1.33 2.2 -albumin 21 0 0 4 4e-01 4 3 4 2.6 4 -0.97 0.3 -copper 21 0 0 175 1e+02 158 100 225 25.0 444 1.08 1.0 -alk.phos 21 0 0 2486 2e+03 1664 983 2496 516.0 10165 2.05 4.5 -ast 21 0 0 129 5e+01 127 86 158 56.8 222 0.31 -0.9 -trig 21 0 0 146 6e+01 142 107 194 55.0 242 0.16 -1.0 -platelet 21 1 5 233 1e+02 228 148 314 70.0 394 -0.05 -1.2 -protime 21 0 0 11 9e-01 11 10 11 9.7 14 2.11 6.8 ------------------------------------------------------------- -sex: f -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 137 0 0.0 2050 1e+03 1945 1e+03 2644 41.0 4556 0.32 -0.4 -age 137 0 0.0 51 1e+01 51 4e+01 57 26.3 77 0.05 -0.5 -bili 137 0 0.0 3 4e+00 1 8e-01 3 0.3 20 2.65 7.1 -chol 137 18 13.1 358 2e+02 309 2e+02 400 127.0 1712 4.28 23.8 -albumin 137 0 0.0 3 4e-01 4 3e+00 4 2.1 5 -0.33 0.4 -copper 137 1 0.7 86 8e+01 67 4e+01 105 9.0 588 3.18 13.9 -alk.phos 137 0 0.0 1950 2e+03 1212 8e+02 1877 369.0 11552 2.88 8.4 -ast 137 0 0.0 119 6e+01 108 7e+01 150 26.4 338 1.20 1.9 -trig 137 19 13.9 120 7e+01 101 8e+01 134 33.0 598 3.28 16.0 -platelet 137 1 0.7 263 1e+02 258 2e+02 322 62.0 563 0.57 0.3 -protime 137 0 0.0 11 8e-01 11 1e+01 11 9.0 13 0.92 0.6 ------------------------------------------------------------- -sex: m -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 15 0 0 2156 1e+03 1656 1054 3420 191.0 4427 0.3 -1.4 -age 15 0 0 57 1e+01 53 49 66 43.9 75 0.5 -1.3 -bili 15 0 0 3 2e+00 2 1 3 0.6 9 1.5 1.4 -chol 15 1 7 301 1e+02 259 236 342 151.0 546 0.9 0.4 -albumin 15 0 0 4 5e-01 4 3 4 2.3 4 -1.0 1.9 -copper 15 0 0 125 9e+01 84 52 198 13.0 281 0.5 -1.1 -alk.phos 15 0 0 1734 2e+03 1070 737 1212 577.0 10397 3.5 12.7 -ast 15 0 0 113 4e+01 110 74 129 46.5 188 0.3 -0.8 -trig 15 1 7 115 4e+01 108 90 137 49.0 188 0.4 -0.4 -platelet 15 0 0 240 7e+01 214 190 294 119.0 360 0.2 -1.0 -protime 15 0 0 11 1e+00 11 11 12 10.0 13 0.7 0.2 ------------------------------------------------------------- -sex: f -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 139 0 0.0 1980 1e+03 1832 1e+03 2717 51.0 4523 0.3 -0.6 -age 139 0 0.0 48 1e+01 47 4e+01 55 30.6 71 0.2 -0.7 -bili 139 0 0.0 4 5e+00 1 7e-01 4 0.3 28 2.6 6.5 -chol 139 9 6.5 382 3e+02 306 3e+02 381 120.0 1775 3.0 10.1 -albumin 139 0 0.0 4 4e-01 4 3e+00 4 2.0 4 -0.8 2.1 -copper 139 1 0.7 95 8e+01 70 4e+01 127 4.0 558 2.2 8.3 -alk.phos 139 0 0.0 1966 2e+03 1345 9e+02 1992 289.0 13862 3.4 13.6 -ast 139 0 0.0 126 6e+01 118 8e+01 153 28.4 457 1.8 6.2 -trig 139 10 7.2 126 6e+01 113 8e+01 157 44.0 432 1.7 5.3 -platelet 139 2 1.4 268 9e+01 265 2e+02 324 71.0 487 0.2 -0.4 -protime 139 0 0.0 11 1e+00 11 1e+01 11 9.2 17 2.0 7.2 - -p-values - pNormal pNonNormal -time 7.300496e-01 5.566440e-01 -age 1.286381e-04 6.517437e-04 -bili 3.937430e-01 2.049525e-01 -chol 5.122223e-01 4.578773e-01 -albumin 5.853926e-01 4.041206e-01 -copper 6.237989e-05 4.712924e-05 -alk.phos 7.063812e-01 1.801480e-01 -ast 5.982898e-01 5.086616e-01 -trig 3.701073e-01 5.827726e-02 -platelet 3.624740e-01 4.451277e-01 -protime 1.365463e-01 8.114383e-02 - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 -age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 -bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 -chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 -albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 -copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 -alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 -ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 -trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 -platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 -protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 - 3 vs 4 -time 0.13729269 -age 0.96133382 -bili 0.24158721 -chol 0.40072828 -albumin 0.05159074 -copper 0.36464167 -alk.phos 0.10128012 -ast 0.25929154 -trig 0.22610097 -platelet 0.33286083 -protime 0.44433997 - -======================================================================================= +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.CatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() - ### Summary of categorical variables ### +detaching ‘package:survival’ -sex: m -trt: 1 - var n miss p.miss level freq percent cum.percent - status 21 0 0.0 0 4 19.0 19.0 - 1 3 14.3 33.3 - 2 14 66.7 100.0 - - ascites 21 0 0.0 0 20 95.2 95.2 - 1 1 4.8 100.0 - - hepato 21 0 0.0 0 9 42.9 42.9 - 1 12 57.1 100.0 - - spiders 21 0 0.0 0 18 85.7 85.7 - 1 3 14.3 100.0 - - edema 21 0 0.0 0 17 81.0 81.0 - 0.5 3 14.3 95.2 - 1 1 4.8 100.0 - - stage 21 0 0.0 1 2 9.5 9.5 - 2 4 19.0 28.6 - 3 7 33.3 61.9 - 4 8 38.1 100.0 - ------------------------------------------------------------- -sex: f -trt: 1 - var n miss p.miss level freq percent cum.percent - status 137 0 0.0 0 79 57.7 57.7 - 1 7 5.1 62.8 - 2 51 37.2 100.0 - - ascites 137 0 0.0 0 124 90.5 90.5 - 1 13 9.5 100.0 - - hepato 137 0 0.0 0 76 55.5 55.5 - 1 61 44.5 100.0 - - spiders 137 0 0.0 0 95 69.3 69.3 - 1 42 30.7 100.0 - - edema 137 0 0.0 0 115 83.9 83.9 - 0.5 13 9.5 93.4 - 1 9 6.6 100.0 - - stage 137 0 0.0 1 10 7.3 7.3 - 2 31 22.6 29.9 - 3 49 35.8 65.7 - 4 47 34.3 100.0 - ------------------------------------------------------------- -sex: m -trt: 2 - var n miss p.miss level freq percent cum.percent - status 15 0 0.0 0 7 46.7 46.7 - 1 0 0.0 46.7 - 2 8 53.3 100.0 - - ascites 15 0 0.0 0 13 86.7 86.7 - 1 2 13.3 100.0 - - hepato 15 0 0.0 0 6 40.0 40.0 - 1 9 60.0 100.0 - - spiders 15 0 0.0 0 14 93.3 93.3 - 1 1 6.7 100.0 - - edema 15 0 0.0 0 12 80.0 80.0 - 0.5 1 6.7 86.7 - 1 2 13.3 100.0 - - stage 15 0 0.0 1 1 6.7 6.7 - 2 2 13.3 20.0 - 3 5 33.3 53.3 - 4 7 46.7 100.0 - ------------------------------------------------------------- -sex: f -trt: 2 - var n miss p.miss level freq percent cum.percent - status 139 0 0.0 0 78 56.1 56.1 - 1 9 6.5 62.6 - 2 52 37.4 100.0 - - ascites 139 0 0.0 0 131 94.2 94.2 - 1 8 5.8 100.0 - - hepato 139 0 0.0 0 61 43.9 43.9 - 1 78 56.1 100.0 - - spiders 139 0 0.0 0 95 68.3 68.3 - 1 44 31.7 100.0 - - edema 139 0 0.0 0 119 85.6 85.6 - 0.5 12 8.6 94.2 - 1 8 5.8 100.0 - - stage 139 0 0.0 1 3 2.2 2.2 - 2 30 21.6 23.7 - 3 59 42.4 66.2 - 4 47 33.8 100.0 - - -p-values - pApprox pExact -status 0.03269881 0.02420814 -ascites 0.51569424 0.43540746 -hepato 0.20805680 0.20480121 -spiders 0.08898575 0.08569292 -edema 0.90584197 0.84833223 -stage 0.64630048 NA - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 -ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 -hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 -spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 -edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 -stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 - 3 vs 4 -status 0.46214324 -ascites 0.26007640 -hepato 0.07878788 -spiders 0.66954801 -edema 0.26502087 -stage 0.39205566 -> -> ## See the categorical part only using $ operator -> tableOne$CatTable - Stratified by sex:trt - m:1 f:1 m:2 f:2 p test - n 21 137 15 139 - status (%) 0.033 - 0 4 (19.0) 79 (57.7) 7 (46.7) 78 (56.1) - 1 3 (14.3) 7 ( 5.1) 0 ( 0.0) 9 ( 6.5) - 2 14 (66.7) 51 (37.2) 8 (53.3) 52 (37.4) - ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) 2 (13.3) 8 ( 5.8) 0.516 - hepato = 1 (%) 12 (57.1) 61 (44.5) 9 (60.0) 78 (56.1) 0.208 - spiders = 1 (%) 3 (14.3) 42 (30.7) 1 ( 6.7) 44 (31.7) 0.089 - edema (%) 0.906 - 0 17 (81.0) 115 (83.9) 12 (80.0) 119 (85.6) - 0.5 3 (14.3) 13 ( 9.5) 1 ( 6.7) 12 ( 8.6) - 1 1 ( 4.8) 9 ( 6.6) 2 (13.3) 8 ( 5.8) - stage (%) 0.646 - 1 2 ( 9.5) 10 ( 7.3) 1 ( 6.7) 3 ( 2.2) - 2 4 (19.0) 31 (22.6) 2 (13.3) 30 (21.6) - 3 7 (33.3) 49 (35.8) 5 (33.3) 59 (42.4) - 4 8 (38.1) 47 (34.3) 7 (46.7) 47 (33.8) -> summary(tableOne$CatTable) -sex: m -trt: 1 - var n miss p.miss level freq percent cum.percent - status 21 0 0.0 0 4 19.0 19.0 - 1 3 14.3 33.3 - 2 14 66.7 100.0 - - ascites 21 0 0.0 0 20 95.2 95.2 - 1 1 4.8 100.0 - - hepato 21 0 0.0 0 9 42.9 42.9 - 1 12 57.1 100.0 - - spiders 21 0 0.0 0 18 85.7 85.7 - 1 3 14.3 100.0 - - edema 21 0 0.0 0 17 81.0 81.0 - 0.5 3 14.3 95.2 - 1 1 4.8 100.0 - - stage 21 0 0.0 1 2 9.5 9.5 - 2 4 19.0 28.6 - 3 7 33.3 61.9 - 4 8 38.1 100.0 - ------------------------------------------------------------- -sex: f -trt: 1 - var n miss p.miss level freq percent cum.percent - status 137 0 0.0 0 79 57.7 57.7 - 1 7 5.1 62.8 - 2 51 37.2 100.0 - - ascites 137 0 0.0 0 124 90.5 90.5 - 1 13 9.5 100.0 - - hepato 137 0 0.0 0 76 55.5 55.5 - 1 61 44.5 100.0 - - spiders 137 0 0.0 0 95 69.3 69.3 - 1 42 30.7 100.0 - - edema 137 0 0.0 0 115 83.9 83.9 - 0.5 13 9.5 93.4 - 1 9 6.6 100.0 - - stage 137 0 0.0 1 10 7.3 7.3 - 2 31 22.6 29.9 - 3 49 35.8 65.7 - 4 47 34.3 100.0 - ------------------------------------------------------------- -sex: m -trt: 2 - var n miss p.miss level freq percent cum.percent - status 15 0 0.0 0 7 46.7 46.7 - 1 0 0.0 46.7 - 2 8 53.3 100.0 - - ascites 15 0 0.0 0 13 86.7 86.7 - 1 2 13.3 100.0 - - hepato 15 0 0.0 0 6 40.0 40.0 - 1 9 60.0 100.0 - - spiders 15 0 0.0 0 14 93.3 93.3 - 1 1 6.7 100.0 - - edema 15 0 0.0 0 12 80.0 80.0 - 0.5 1 6.7 86.7 - 1 2 13.3 100.0 - - stage 15 0 0.0 1 1 6.7 6.7 - 2 2 13.3 20.0 - 3 5 33.3 53.3 - 4 7 46.7 100.0 - ------------------------------------------------------------- -sex: f -trt: 2 - var n miss p.miss level freq percent cum.percent - status 139 0 0.0 0 78 56.1 56.1 - 1 9 6.5 62.6 - 2 52 37.4 100.0 - - ascites 139 0 0.0 0 131 94.2 94.2 - 1 8 5.8 100.0 - - hepato 139 0 0.0 0 61 43.9 43.9 - 1 78 56.1 100.0 - - spiders 139 0 0.0 0 95 68.3 68.3 - 1 44 31.7 100.0 - - edema 139 0 0.0 0 119 85.6 85.6 - 0.5 12 8.6 94.2 - 1 8 5.8 100.0 - - stage 139 0 0.0 1 3 2.2 2.2 - 2 30 21.6 23.7 - 3 59 42.4 66.2 - 4 47 33.8 100.0 - - -p-values - pApprox pExact -status 0.03269881 0.02420814 -ascites 0.51569424 0.43540746 -hepato 0.20805680 0.20480121 -spiders 0.08898575 0.08569292 -edema 0.90584197 0.84833223 -stage 0.64630048 NA - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 -ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 -hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 -spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 -edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 -stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 - 3 vs 4 -status 0.46214324 -ascites 0.26007640 -hepato 0.07878788 -spiders 0.66954801 -edema 0.26502087 -stage 0.39205566 -> -> ## See the continuous part only using $ operator -> tableOne$ContTable - Stratified by sex:trt - m:1 f:1 m:2 - n 21 137 15 - time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) 2156.33 (1428.56) - age (mean (sd)) 55.57 (12.61) 50.78 (10.65) 57.09 (10.07) - bili (mean (sd)) 2.98 (2.11) 2.86 (3.81) 2.72 (2.46) - chol (mean (sd)) 403.43 (204.95) 358.24 (210.46) 301.00 (111.32) - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.44) 3.50 (0.49) - copper (mean (sd)) 174.90 (105.33) 85.71 (82.27) 125.40 (89.18) - alk.phos (mean (sd)) 2486.16 (2385.32) 1950.04 (2151.35) 1734.45 (2478.07) - ast (mean (sd)) 128.71 (48.74) 118.91 (55.40) 112.58 (44.38) - trig (mean (sd)) 145.81 (56.62) 120.28 (73.41) 114.86 (39.59) - platelet (mean (sd)) 232.65 (97.38) 262.59 (100.53) 240.13 (73.93) - protime (mean (sd)) 10.84 (0.94) 10.62 (0.84) 11.23 (0.97) - Stratified by sex:trt - f:2 p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - age (mean (sd)) 47.66 (9.54) <0.001 - bili (mean (sd)) 3.75 (5.50) 0.394 - chol (mean (sd)) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.53 (0.39) 0.585 - copper (mean (sd)) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 126.30 (60.27) 0.598 - trig (mean (sd)) 126.38 (60.22) 0.370 - platelet (mean (sd)) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.75 (1.15) 0.137 -> summary(tableOne$ContTable) -sex: m -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew -time 21 0 0.0 1793.5 1244.70 1302.0 999.0 2386.0 140.0 4459.0 1.042 -age 21 0 0.0 55.6 12.61 56.0 46.5 65.8 33.5 78.4 -0.200 -bili 21 0 0.0 3.0 2.11 2.3 1.4 4.0 0.6 7.3 1.019 -chol 21 0 0.0 403.4 204.95 376.0 251.0 456.0 168.0 1000.0 1.329 -albumin 21 0 0.0 3.6 0.43 3.8 3.4 3.9 2.6 4.2 -0.966 -copper 21 0 0.0 174.9 105.33 158.0 100.0 225.0 25.0 444.0 1.082 -alk.phos 21 0 0.0 2486.2 2385.32 1664.0 983.0 2496.0 516.0 10165.0 2.051 -ast 21 0 0.0 128.7 48.74 127.0 86.0 158.1 56.8 221.9 0.309 -trig 21 0 0.0 145.8 56.62 142.0 107.0 194.0 55.0 242.0 0.164 -platelet 21 1 4.8 232.7 97.38 227.5 148.2 313.8 70.0 394.0 -0.045 -protime 21 0 0.0 10.8 0.94 10.8 10.3 11.0 9.7 14.1 2.113 - kurt -time 0.10 -age -0.71 -bili -0.12 -chol 2.15 -albumin 0.34 -copper 0.97 -alk.phos 4.49 -ast -0.86 -trig -1.04 -platelet -1.16 -protime 6.84 ------------------------------------------------------------- -sex: f -trt: 1 - n miss p.miss mean sd median p25 p75 min max -time 137 0 0.00 2049.7 1070.20 1945.0 1293.0 2644.0 41.0 4556.0 -age 137 0 0.00 50.8 10.65 51.2 42.5 57.0 26.3 76.7 -bili 137 0 0.00 2.9 3.81 1.3 0.8 3.2 0.3 20.0 -chol 137 18 13.14 358.2 210.46 309.0 247.5 399.5 127.0 1712.0 -albumin 137 0 0.00 3.5 0.44 3.5 3.2 3.8 2.1 4.6 -copper 137 1 0.73 85.7 82.27 67.0 36.8 105.0 9.0 588.0 -alk.phos 137 0 0.00 1950.0 2151.35 1212.0 823.0 1877.0 369.0 11552.0 -ast 137 0 0.00 118.9 55.40 108.5 74.4 150.0 26.4 338.0 -trig 137 19 13.87 120.3 73.41 101.0 84.0 134.0 33.0 598.0 -platelet 137 1 0.73 262.6 100.53 258.5 194.2 322.0 62.0 563.0 -protime 137 0 0.00 10.6 0.84 10.6 10.0 11.0 9.0 13.0 - skew kurt -time 0.318 -0.41 -age 0.045 -0.48 -bili 2.652 7.10 -chol 4.281 23.79 -albumin -0.327 0.42 -copper 3.181 13.92 -alk.phos 2.876 8.39 -ast 1.196 1.91 -trig 3.278 16.03 -platelet 0.565 0.34 -protime 0.916 0.57 ------------------------------------------------------------- -sex: m -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew -time 15 0 0.0 2156.3 1428.56 1656.0 1053.5 3420.0 191.0 4427.0 0.30 -age 15 0 0.0 57.1 10.07 52.8 49.4 65.8 43.9 74.5 0.45 -bili 15 0 0.0 2.7 2.46 1.9 1.1 2.9 0.6 8.6 1.54 -chol 15 1 6.7 301.0 111.32 259.0 235.8 342.2 151.0 546.0 0.91 -albumin 15 0 0.0 3.5 0.49 3.6 3.3 3.8 2.3 4.3 -0.96 -copper 15 0 0.0 125.4 89.18 84.0 52.5 198.0 13.0 281.0 0.50 -alk.phos 15 0 0.0 1734.5 2478.07 1070.0 737.0 1211.5 577.0 10396.8 3.49 -ast 15 0 0.0 112.6 44.38 110.0 74.2 129.4 46.5 188.3 0.32 -trig 15 1 6.7 114.9 39.59 108.5 90.2 137.0 49.0 188.0 0.44 -platelet 15 0 0.0 240.1 73.93 214.0 189.5 294.5 119.0 360.0 0.18 -protime 15 0 0.0 11.2 0.97 11.2 10.6 11.6 10.0 13.2 0.72 - kurt -time -1.39 -age -1.29 -bili 1.43 -chol 0.36 -albumin 1.88 -copper -1.13 -alk.phos 12.68 -ast -0.80 -trig -0.36 -platelet -1.02 -protime 0.18 ------------------------------------------------------------- -sex: f -trt: 2 - n miss p.miss mean sd median p25 p75 min max -time 139 0 0.00 1979.7 1127.52 1832.0 1157.0 2717.0 51.0 4523.0 -age 139 0 0.00 47.7 9.54 47.2 41.3 55.5 30.6 70.6 -bili 139 0 0.00 3.7 5.50 1.3 0.7 3.6 0.3 28.0 -chol 139 9 6.47 381.7 262.26 306.5 258.0 381.0 120.0 1775.0 -albumin 139 0 0.00 3.5 0.39 3.5 3.3 3.8 2.0 4.4 -copper 139 1 0.72 94.6 79.25 69.5 42.5 127.2 4.0 558.0 -alk.phos 139 0 0.00 1965.5 2066.15 1345.0 941.0 1992.0 289.0 13862.4 -ast 139 0 0.00 126.3 60.27 117.8 84.5 152.7 28.4 457.2 -trig 139 10 7.19 126.4 60.22 113.0 84.0 157.0 44.0 432.0 -platelet 139 2 1.44 267.9 92.20 265.0 213.0 324.0 71.0 487.0 -protime 139 0 0.00 10.8 1.15 10.6 9.9 11.2 9.2 17.1 - skew kurt -time 0.34 -0.64 -age 0.16 -0.74 -bili 2.57 6.54 -chol 3.01 10.13 -albumin -0.83 2.06 -copper 2.25 8.30 -alk.phos 3.39 13.57 -ast 1.76 6.24 -trig 1.71 5.27 -platelet 0.21 -0.36 -protime 2.02 7.15 - -p-values - pNormal pNonNormal -time 7.300496e-01 5.566440e-01 -age 1.286381e-04 6.517437e-04 -bili 3.937430e-01 2.049525e-01 -chol 5.122223e-01 4.578773e-01 -albumin 5.853926e-01 4.041206e-01 -copper 6.237989e-05 4.712924e-05 -alk.phos 7.063812e-01 1.801480e-01 -ast 5.982898e-01 5.086616e-01 -trig 3.701073e-01 5.827726e-02 -platelet 3.624740e-01 4.451277e-01 -protime 1.365463e-01 8.114383e-02 - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 -age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 -bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 -chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 -albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 -copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 -alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 -ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 -trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 -platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 -protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 - 3 vs 4 -time 0.13729269 -age 0.96133382 -bili 0.24158721 -chol 0.40072828 -albumin 0.05159074 -copper 0.36464167 -alk.phos 0.10128012 -ast 0.25929154 -trig 0.22610097 -platelet 0.33286083 -protime 0.44433997 -> -> ## If your work flow includes copying to Excel and Word when writing manuscripts, -> ## you may benefit from the quote argument. This will quote everything so that -> ## Excel does not mess up the cells. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "hepato", quote = TRUE) - "Stratified by sex:trt" - "" "m:1" - "n" " 21" - "time (mean (sd))" "1793.48 (1244.70)" - "status (%)" " " - " 0" " 4 (19.0) " - " 1" " 3 (14.3) " - " 2" " 14 (66.7) " - "age (mean (sd))" " 55.57 (12.61)" - "ascites = 1 (%)" " 1 ( 4.8) " - "hepato = 0/1 (%)" " 9/12 (42.9/57.1) " - "spiders = 1 (%)" " 3 (14.3) " - "edema (%)" " " - " 0" " 17 (81.0) " - " 0.5" " 3 (14.3) " - " 1" " 1 ( 4.8) " - "bili (median [IQR])" " 2.30 [1.40, 4.00]" - "chol (median [IQR])" " 376.00 [251.00, 456.00]" - "albumin (mean (sd))" " 3.63 (0.43)" - "copper (median [IQR])" " 158.00 [100.00, 225.00]" - "alk.phos (median [IQR])" "1664.00 [983.00, 2496.00]" - "ast (mean (sd))" " 128.71 (48.74)" - "trig (median [IQR])" " 142.00 [107.00, 194.00]" - "platelet (mean (sd))" " 232.65 (97.38)" - "protime (mean (sd))" " 10.84 (0.94)" - "stage (%)" " " - " 1" " 2 ( 9.5) " - " 2" " 4 (19.0) " - " 3" " 7 (33.3) " - " 4" " 8 (38.1) " - "Stratified by sex:trt" - "" "f:1" - "n" " 137" - "time (mean (sd))" "2049.67 (1070.20)" - "status (%)" " " - " 0" " 79 (57.7) " - " 1" " 7 ( 5.1) " - " 2" " 51 (37.2) " - "age (mean (sd))" " 50.78 (10.65)" - "ascites = 1 (%)" " 13 ( 9.5) " - "hepato = 0/1 (%)" " 76/61 (55.5/44.5) " - "spiders = 1 (%)" " 42 (30.7) " - "edema (%)" " " - " 0" " 115 (83.9) " - " 0.5" " 13 ( 9.5) " - " 1" " 9 ( 6.6) " - "bili (median [IQR])" " 1.30 [0.80, 3.20]" - "chol (median [IQR])" " 309.00 [247.50, 399.50]" - "albumin (mean (sd))" " 3.50 (0.44)" - "copper (median [IQR])" " 67.00 [36.75, 105.00]" - "alk.phos (median [IQR])" "1212.00 [823.00, 1877.00]" - "ast (mean (sd))" " 118.91 (55.40)" - "trig (median [IQR])" " 101.00 [84.00, 134.00]" - "platelet (mean (sd))" " 262.59 (100.53)" - "protime (mean (sd))" " 10.62 (0.84)" - "stage (%)" " " - " 1" " 10 ( 7.3) " - " 2" " 31 (22.6) " - " 3" " 49 (35.8) " - " 4" " 47 (34.3) " - "Stratified by sex:trt" - "" "m:2" - "n" " 15" - "time (mean (sd))" "2156.33 (1428.56)" - "status (%)" " " - " 0" " 7 (46.7) " - " 1" " 0 ( 0.0) " - " 2" " 8 (53.3) " - "age (mean (sd))" " 57.09 (10.07)" - "ascites = 1 (%)" " 2 (13.3) " - "hepato = 0/1 (%)" " 6/9 (40.0/60.0) " - "spiders = 1 (%)" " 1 ( 6.7) " - "edema (%)" " " - " 0" " 12 (80.0) " - " 0.5" " 1 ( 6.7) " - " 1" " 2 (13.3) " - "bili (median [IQR])" " 1.90 [1.10, 2.85]" - "chol (median [IQR])" " 259.00 [235.75, 342.25]" - "albumin (mean (sd))" " 3.50 (0.49)" - "copper (median [IQR])" " 84.00 [52.50, 198.00]" - "alk.phos (median [IQR])" "1070.00 [737.00, 1211.50]" - "ast (mean (sd))" " 112.58 (44.38)" - "trig (median [IQR])" " 108.50 [90.25, 137.00]" - "platelet (mean (sd))" " 240.13 (73.93)" - "protime (mean (sd))" " 11.23 (0.97)" - "stage (%)" " " - " 1" " 1 ( 6.7) " - " 2" " 2 (13.3) " - " 3" " 5 (33.3) " - " 4" " 7 (46.7) " - "Stratified by sex:trt" - "" "f:2" "p" "test" - "n" " 139" "" "" - "time (mean (sd))" "1979.65 (1127.52)" " 0.730" "" - "status (%)" " " " 0.024" "exact" - " 0" " 78 (56.1) " "" "" - " 1" " 9 ( 6.5) " "" "" - " 2" " 52 (37.4) " "" "" - "age (mean (sd))" " 47.66 (9.54)" "<0.001" "" - "ascites = 1 (%)" " 8 ( 5.8) " " 0.516" "" - "hepato = 0/1 (%)" " 61/78 (43.9/56.1) " " 0.208" "" - "spiders = 1 (%)" " 44 (31.7) " " 0.089" "" - "edema (%)" " " " 0.906" "" - " 0" " 119 (85.6) " "" "" - " 0.5" " 12 ( 8.6) " "" "" - " 1" " 8 ( 5.8) " "" "" - "bili (median [IQR])" " 1.30 [0.70, 3.60]" " 0.205" "nonnorm" - "chol (median [IQR])" " 306.50 [258.00, 381.00]" " 0.458" "nonnorm" - "albumin (mean (sd))" " 3.53 (0.39)" " 0.585" "" - "copper (median [IQR])" " 69.50 [42.50, 127.25]" "<0.001" "nonnorm" - "alk.phos (median [IQR])" "1345.00 [941.00, 1992.00]" " 0.180" "nonnorm" - "ast (mean (sd))" " 126.30 (60.27)" " 0.598" "" - "trig (median [IQR])" " 113.00 [84.00, 157.00]" " 0.058" "nonnorm" - "platelet (mean (sd))" " 267.95 (92.20)" " 0.362" "" - "protime (mean (sd))" " 10.75 (1.15)" " 0.137" "" - "stage (%)" " " " NA" "exact" - " 1" " 3 ( 2.2) " "" "" - " 2" " 30 (21.6) " "" "" - " 3" " 59 (42.4) " "" "" - " 4" " 47 (33.8) " "" "" -> -> ## If you want to center-align values in Word, use noSpaces option. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) - "Stratified by sex:trt" - "" "m:1" - "n" "21" - "time (mean (sd))" "1793.48 (1244.70)" - "status (%)" "" - " 0" "4 (19.0)" - " 1" "3 (14.3)" - " 2" "14 (66.7)" - "age (mean (sd))" "55.57 (12.61)" - "ascites = 1 (%)" "1 (4.8)" - "hepato = 0/1 (%)" "9/12 (42.9/57.1)" - "spiders = 1 (%)" "3 (14.3)" - "edema (%)" "" - " 0" "17 (81.0)" - " 0.5" "3 (14.3)" - " 1" "1 (4.8)" - "bili (median [IQR])" "2.30 [1.40, 4.00]" - "chol (median [IQR])" "376.00 [251.00, 456.00]" - "albumin (mean (sd))" "3.63 (0.43)" - "copper (median [IQR])" "158.00 [100.00, 225.00]" - "alk.phos (median [IQR])" "1664.00 [983.00, 2496.00]" - "ast (mean (sd))" "128.71 (48.74)" - "trig (median [IQR])" "142.00 [107.00, 194.00]" - "platelet (mean (sd))" "232.65 (97.38)" - "protime (mean (sd))" "10.84 (0.94)" - "stage (%)" "" - " 1" "2 (9.5)" - " 2" "4 (19.0)" - " 3" "7 (33.3)" - " 4" "8 (38.1)" - "Stratified by sex:trt" - "" "f:1" - "n" "137" - "time (mean (sd))" "2049.67 (1070.20)" - "status (%)" "" - " 0" "79 (57.7)" - " 1" "7 (5.1)" - " 2" "51 (37.2)" - "age (mean (sd))" "50.78 (10.65)" - "ascites = 1 (%)" "13 (9.5)" - "hepato = 0/1 (%)" "76/61 (55.5/44.5)" - "spiders = 1 (%)" "42 (30.7)" - "edema (%)" "" - " 0" "115 (83.9)" - " 0.5" "13 (9.5)" - " 1" "9 (6.6)" - "bili (median [IQR])" "1.30 [0.80, 3.20]" - "chol (median [IQR])" "309.00 [247.50, 399.50]" - "albumin (mean (sd))" "3.50 (0.44)" - "copper (median [IQR])" "67.00 [36.75, 105.00]" - "alk.phos (median [IQR])" "1212.00 [823.00, 1877.00]" - "ast (mean (sd))" "118.91 (55.40)" - "trig (median [IQR])" "101.00 [84.00, 134.00]" - "platelet (mean (sd))" "262.59 (100.53)" - "protime (mean (sd))" "10.62 (0.84)" - "stage (%)" "" - " 1" "10 (7.3)" - " 2" "31 (22.6)" - " 3" "49 (35.8)" - " 4" "47 (34.3)" - "Stratified by sex:trt" - "" "m:2" - "n" "15" - "time (mean (sd))" "2156.33 (1428.56)" - "status (%)" "" - " 0" "7 (46.7)" - " 1" "0 (0.0)" - " 2" "8 (53.3)" - "age (mean (sd))" "57.09 (10.07)" - "ascites = 1 (%)" "2 (13.3)" - "hepato = 0/1 (%)" "6/9 (40.0/60.0)" - "spiders = 1 (%)" "1 (6.7)" - "edema (%)" "" - " 0" "12 (80.0)" - " 0.5" "1 (6.7)" - " 1" "2 (13.3)" - "bili (median [IQR])" "1.90 [1.10, 2.85]" - "chol (median [IQR])" "259.00 [235.75, 342.25]" - "albumin (mean (sd))" "3.50 (0.49)" - "copper (median [IQR])" "84.00 [52.50, 198.00]" - "alk.phos (median [IQR])" "1070.00 [737.00, 1211.50]" - "ast (mean (sd))" "112.58 (44.38)" - "trig (median [IQR])" "108.50 [90.25, 137.00]" - "platelet (mean (sd))" "240.13 (73.93)" - "protime (mean (sd))" "11.23 (0.97)" - "stage (%)" "" - " 1" "1 (6.7)" - " 2" "2 (13.3)" - " 3" "5 (33.3)" - " 4" "7 (46.7)" - "Stratified by sex:trt" - "" "f:2" "p" "test" - "n" "139" "" "" - "time (mean (sd))" "1979.65 (1127.52)" "0.730" "" - "status (%)" "" "0.024" "exact" - " 0" "78 (56.1)" "" "" - " 1" "9 (6.5)" "" "" - " 2" "52 (37.4)" "" "" - "age (mean (sd))" "47.66 (9.54)" "<0.001" "" - "ascites = 1 (%)" "8 (5.8)" "0.516" "" - "hepato = 0/1 (%)" "61/78 (43.9/56.1)" "0.208" "" - "spiders = 1 (%)" "44 (31.7)" "0.089" "" - "edema (%)" "" "0.906" "" - " 0" "119 (85.6)" "" "" - " 0.5" "12 (8.6)" "" "" - " 1" "8 (5.8)" "" "" - "bili (median [IQR])" "1.30 [0.70, 3.60]" "0.205" "nonnorm" - "chol (median [IQR])" "306.50 [258.00, 381.00]" "0.458" "nonnorm" - "albumin (mean (sd))" "3.53 (0.39)" "0.585" "" - "copper (median [IQR])" "69.50 [42.50, 127.25]" "<0.001" "nonnorm" - "alk.phos (median [IQR])" "1345.00 [941.00, 1992.00]" "0.180" "nonnorm" - "ast (mean (sd))" "126.30 (60.27)" "0.598" "" - "trig (median [IQR])" "113.00 [84.00, 157.00]" "0.058" "nonnorm" - "platelet (mean (sd))" "267.95 (92.20)" "0.362" "" - "protime (mean (sd))" "10.75 (1.15)" "0.137" "" - "stage (%)" "" "NA" "exact" - " 1" "3 (2.2)" "" "" - " 2" "30 (21.6)" "" "" - " 3" "59 (42.4)" "" "" - " 4" "47 (33.8)" "" "" -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("print.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() - -detaching ‘package:survival’ - -> nameEx("print.svyCatTable") -> ### * print.svyCatTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: print.svyCatTable -> ### Title: Format and print the 'svyCatTable' class objects -> ### Aliases: print.svyCatTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("print.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("print.svyContTable") -> ### * print.svyContTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: print.svyContTable -> ### Title: Format and print the 'svyContTable' class objects -> ### Aliases: print.svyContTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("print.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("summary.CatTable") -> ### * summary.CatTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: summary.CatTable -> ### Title: Shows all results in a 'CatTable' class object -> ### Aliases: summary.CatTable -> -> ### ** Examples -> -> ## Load -> library(tableone) -> -> ## Load Mayo Clinic Primary Biliary Cirrhosis Data -> library(survival) -> data(pbc) -> ## Check variables -> head(pbc) - id time status trt age sex ascites hepato spiders edema bili chol -1 1 400 2 1 58.76523 f 1 1 1 1.0 14.5 261 -2 2 4500 0 1 56.44627 f 0 1 1 0.0 1.1 302 -3 3 1012 2 1 70.07255 m 0 0 0 0.5 1.4 176 -4 4 1925 2 1 54.74059 f 0 1 1 0.5 1.8 244 -5 5 1504 1 2 38.10541 f 0 1 1 0.0 3.4 279 -6 6 2503 2 2 66.25873 f 0 1 0 0.0 0.8 248 - albumin copper alk.phos ast trig platelet protime stage -1 2.60 156 1718.0 137.95 172 190 12.2 4 -2 4.14 54 7394.8 113.52 88 221 10.6 3 -3 3.48 210 516.0 96.10 55 151 12.0 4 -4 2.54 64 6121.8 60.63 92 183 10.3 4 -5 3.53 143 671.0 113.15 72 136 10.9 3 -6 3.98 50 944.0 93.00 63 NA 11.0 3 -> -> ## Create an overall table for categorical variables -> catVars <- c("status","ascites","hepato","spiders","edema","stage") -> catTableOverall <- CreateCatTable(vars = catVars, data = pbc) -> -> ## Simply typing the object name will invoke the print.CatTable method, -> ## which will show the sample size, frequencies and percentages. -> ## For 2-level variables, only the higher level is shown for simplicity. -> catTableOverall - - Overall - n 418 - status (%) - 0 232 (55.5) - 1 25 ( 6.0) - 2 161 (38.5) - ascites = 1 (%) 24 ( 7.7) - hepato = 1 (%) 160 (51.3) - spiders = 1 (%) 90 (28.8) - edema (%) - 0 354 (84.7) - 0.5 44 (10.5) - 1 20 ( 4.8) - stage (%) - 1 21 ( 5.1) - 2 92 (22.3) - 3 155 (37.6) - 4 144 (35.0) -> -> ## To further examine the variables, use the summary.CatTable method, -> ## which will show more details. -> summary(catTableOverall) -strata: Overall - var n miss p.miss level freq percent cum.percent - status 418 0 0.0 0 232 55.5 55.5 - 1 25 6.0 61.5 - 2 161 38.5 100.0 - - ascites 418 106 25.4 0 288 92.3 92.3 - 1 24 7.7 100.0 - - hepato 418 106 25.4 0 152 48.7 48.7 - 1 160 51.3 100.0 - - spiders 418 106 25.4 0 222 71.2 71.2 - 1 90 28.8 100.0 - - edema 418 0 0.0 0 354 84.7 84.7 - 0.5 44 10.5 95.2 - 1 20 4.8 100.0 - - stage 418 6 1.4 1 21 5.1 5.1 - 2 92 22.3 27.4 - 3 155 37.6 65.0 - 4 144 35.0 100.0 - -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("summary.CatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() - -detaching ‘package:survival’ - -> nameEx("summary.ContTable") -> ### * summary.ContTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: summary.ContTable -> ### Title: Shows all results in a 'ContTable' class object -> ### Aliases: summary.ContTable -> -> ### ** Examples -> -> ## Load -> library(tableone) -> -> ## Load Mayo Clinic Primary Biliary Cirrhosis Data -> library(survival) -> data(pbc) -> ## Check variables -> head(pbc) - id time status trt age sex ascites hepato spiders edema bili chol -1 1 400 2 1 58.76523 f 1 1 1 1.0 14.5 261 -2 2 4500 0 1 56.44627 f 0 1 1 0.0 1.1 302 -3 3 1012 2 1 70.07255 m 0 0 0 0.5 1.4 176 -4 4 1925 2 1 54.74059 f 0 1 1 0.5 1.8 244 -5 5 1504 1 2 38.10541 f 0 1 1 0.0 3.4 279 -6 6 2503 2 2 66.25873 f 0 1 0 0.0 0.8 248 - albumin copper alk.phos ast trig platelet protime stage -1 2.60 156 1718.0 137.95 172 190 12.2 4 -2 4.14 54 7394.8 113.52 88 221 10.6 3 -3 3.48 210 516.0 96.10 55 151 12.0 4 -4 2.54 64 6121.8 60.63 92 183 10.3 4 -5 3.53 143 671.0 113.15 72 136 10.9 3 -6 3.98 50 944.0 93.00 63 NA 11.0 3 -> -> ## Create an overall table for continuous variables -> contVars <- c("time","age","bili","chol","albumin","copper", -+ "alk.phos","ast","trig","platelet","protime") -> contTableOverall <- CreateContTable(vars = contVars, data = pbc) -> -> ## Simply typing the object name will invoke the print.ContTable method, -> ## which will show the sample size, means and standard deviations. -> contTableOverall - - Overall - n 418 - time (mean (sd)) 1917.78 (1104.67) - age (mean (sd)) 50.74 (10.45) - bili (mean (sd)) 3.22 (4.41) - chol (mean (sd)) 369.51 (231.94) - albumin (mean (sd)) 3.50 (0.42) - copper (mean (sd)) 97.65 (85.61) - alk.phos (mean (sd)) 1982.66 (2140.39) - ast (mean (sd)) 122.56 (56.70) - trig (mean (sd)) 124.70 (65.15) - platelet (mean (sd)) 257.02 (98.33) - protime (mean (sd)) 10.73 (1.02) -> -> ## To further examine the variables, use the summary.ContTable method, -> ## which will show more details. -> summary(contTableOverall) -strata: Overall - n miss p.miss mean sd median p25 p75 min max -time 418 0 0.00 1917.8 1104.67 1730.0 1092.8 2613.5 41.0 4795.0 -age 418 0 0.00 50.7 10.45 51.0 42.8 58.2 26.3 78.4 -bili 418 0 0.00 3.2 4.41 1.4 0.8 3.4 0.3 28.0 -chol 418 134 32.06 369.5 231.94 309.5 249.5 400.0 120.0 1775.0 -albumin 418 0 0.00 3.5 0.42 3.5 3.2 3.8 2.0 4.6 -copper 418 108 25.84 97.6 85.61 73.0 41.2 123.0 4.0 588.0 -alk.phos 418 106 25.36 1982.7 2140.39 1259.0 871.5 1980.0 289.0 13862.4 -ast 418 106 25.36 122.6 56.70 114.7 80.6 151.9 26.4 457.2 -trig 418 136 32.54 124.7 65.15 108.0 84.2 151.0 33.0 598.0 -platelet 418 11 2.63 257.0 98.33 251.0 188.5 318.0 62.0 721.0 -protime 418 2 0.48 10.7 1.02 10.6 10.0 11.1 9.0 18.0 - skew kurt -time 0.473 -0.48 -age 0.087 -0.62 -bili 2.718 8.07 -chol 3.409 14.34 -albumin -0.468 0.57 -copper 2.304 7.62 -alk.phos 2.993 9.66 -ast 1.449 4.31 -trig 2.524 11.80 -platelet 0.627 0.86 -protime 2.223 10.04 -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("summary.ContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() - -detaching ‘package:survival’ - -> nameEx("summary.TableOne") -> ### * summary.TableOne -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: summary.TableOne -> ### Title: Shows all results in a '(svy)TableOne' class object -> ### Aliases: summary.TableOne -> -> ### ** Examples -> -> ## Load -> library(tableone) -> -> ## Load Mayo Clinic Primary Biliary Cirrhosis Data -> library(survival) -> data(pbc) -> ## Check variables -> head(pbc) - id time status trt age sex ascites hepato spiders edema bili chol -1 1 400 2 1 58.76523 f 1 1 1 1.0 14.5 261 -2 2 4500 0 1 56.44627 f 0 1 1 0.0 1.1 302 -3 3 1012 2 1 70.07255 m 0 0 0 0.5 1.4 176 -4 4 1925 2 1 54.74059 f 0 1 1 0.5 1.8 244 -5 5 1504 1 2 38.10541 f 0 1 1 0.0 3.4 279 -6 6 2503 2 2 66.25873 f 0 1 0 0.0 0.8 248 - albumin copper alk.phos ast trig platelet protime stage -1 2.60 156 1718.0 137.95 172 190 12.2 4 -2 4.14 54 7394.8 113.52 88 221 10.6 3 -3 3.48 210 516.0 96.10 55 151 12.0 4 -4 2.54 64 6121.8 60.63 92 183 10.3 4 -5 3.53 143 671.0 113.15 72 136 10.9 3 -6 3.98 50 944.0 93.00 63 NA 11.0 3 -> -> ## Make categorical variables factors -> varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") -> pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) -> -> ## Create Table 1 stratified by sex and trt -> tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", -+ "spiders","edema","bili","chol","albumin", -+ "copper","alk.phos","ast","trig","platelet", -+ "protime","stage"), -+ strata = c("sex","trt"), data = pbc) -> -> ## Just typing the object name will invoke the print.TableOne method -> tableOne - Stratified by sex:trt - m:1 f:1 m:2 - n 21 137 15 - time (mean (sd)) 1793.48 (1244.70) 2049.67 (1070.20) 2156.33 (1428.56) - status (%) - 0 4 (19.0) 79 (57.7) 7 (46.7) - 1 3 (14.3) 7 ( 5.1) 0 ( 0.0) - 2 14 (66.7) 51 (37.2) 8 (53.3) - age (mean (sd)) 55.57 (12.61) 50.78 (10.65) 57.09 (10.07) - ascites = 1 (%) 1 ( 4.8) 13 ( 9.5) 2 (13.3) - hepato = 1 (%) 12 (57.1) 61 (44.5) 9 (60.0) - spiders = 1 (%) 3 (14.3) 42 (30.7) 1 ( 6.7) - edema (%) - 0 17 (81.0) 115 (83.9) 12 (80.0) - 0.5 3 (14.3) 13 ( 9.5) 1 ( 6.7) - 1 1 ( 4.8) 9 ( 6.6) 2 (13.3) - bili (mean (sd)) 2.98 (2.11) 2.86 (3.81) 2.72 (2.46) - chol (mean (sd)) 403.43 (204.95) 358.24 (210.46) 301.00 (111.32) - albumin (mean (sd)) 3.63 (0.43) 3.50 (0.44) 3.50 (0.49) - copper (mean (sd)) 174.90 (105.33) 85.71 (82.27) 125.40 (89.18) - alk.phos (mean (sd)) 2486.16 (2385.32) 1950.04 (2151.35) 1734.45 (2478.07) - ast (mean (sd)) 128.71 (48.74) 118.91 (55.40) 112.58 (44.38) - trig (mean (sd)) 145.81 (56.62) 120.28 (73.41) 114.86 (39.59) - platelet (mean (sd)) 232.65 (97.38) 262.59 (100.53) 240.13 (73.93) - protime (mean (sd)) 10.84 (0.94) 10.62 (0.84) 11.23 (0.97) - stage (%) - 1 2 ( 9.5) 10 ( 7.3) 1 ( 6.7) - 2 4 (19.0) 31 (22.6) 2 (13.3) - 3 7 (33.3) 49 (35.8) 5 (33.3) - 4 8 (38.1) 47 (34.3) 7 (46.7) - Stratified by sex:trt - f:2 p test - n 139 - time (mean (sd)) 1979.65 (1127.52) 0.730 - status (%) 0.033 - 0 78 (56.1) - 1 9 ( 6.5) - 2 52 (37.4) - age (mean (sd)) 47.66 (9.54) <0.001 - ascites = 1 (%) 8 ( 5.8) 0.516 - hepato = 1 (%) 78 (56.1) 0.208 - spiders = 1 (%) 44 (31.7) 0.089 - edema (%) 0.906 - 0 119 (85.6) - 0.5 12 ( 8.6) - 1 8 ( 5.8) - bili (mean (sd)) 3.75 (5.50) 0.394 - chol (mean (sd)) 381.73 (262.26) 0.512 - albumin (mean (sd)) 3.53 (0.39) 0.585 - copper (mean (sd)) 94.64 (79.25) <0.001 - alk.phos (mean (sd)) 1965.52 (2066.15) 0.706 - ast (mean (sd)) 126.30 (60.27) 0.598 - trig (mean (sd)) 126.38 (60.22) 0.370 - platelet (mean (sd)) 267.95 (92.20) 0.362 - protime (mean (sd)) 10.75 (1.15) 0.137 - stage (%) 0.646 - 1 3 ( 2.2) - 2 30 (21.6) - 3 59 (42.4) - 4 47 (33.8) -> -> ## Use the summary.TableOne method for detailed summary -> summary(tableOne) - - ### Summary of continuous variables ### - -sex: m -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 21 0 0 1793 1e+03 1302 999 2386 140.0 4459 1.04 0.1 -age 21 0 0 56 1e+01 56 46 66 33.5 78 -0.20 -0.7 -bili 21 0 0 3 2e+00 2 1 4 0.6 7 1.02 -0.1 -chol 21 0 0 403 2e+02 376 251 456 168.0 1000 1.33 2.2 -albumin 21 0 0 4 4e-01 4 3 4 2.6 4 -0.97 0.3 -copper 21 0 0 175 1e+02 158 100 225 25.0 444 1.08 1.0 -alk.phos 21 0 0 2486 2e+03 1664 983 2496 516.0 10165 2.05 4.5 -ast 21 0 0 129 5e+01 127 86 158 56.8 222 0.31 -0.9 -trig 21 0 0 146 6e+01 142 107 194 55.0 242 0.16 -1.0 -platelet 21 1 5 233 1e+02 228 148 314 70.0 394 -0.05 -1.2 -protime 21 0 0 11 9e-01 11 10 11 9.7 14 2.11 6.8 ------------------------------------------------------------- -sex: f -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 137 0 0.0 2050 1e+03 1945 1e+03 2644 41.0 4556 0.32 -0.4 -age 137 0 0.0 51 1e+01 51 4e+01 57 26.3 77 0.05 -0.5 -bili 137 0 0.0 3 4e+00 1 8e-01 3 0.3 20 2.65 7.1 -chol 137 18 13.1 358 2e+02 309 2e+02 400 127.0 1712 4.28 23.8 -albumin 137 0 0.0 3 4e-01 4 3e+00 4 2.1 5 -0.33 0.4 -copper 137 1 0.7 86 8e+01 67 4e+01 105 9.0 588 3.18 13.9 -alk.phos 137 0 0.0 1950 2e+03 1212 8e+02 1877 369.0 11552 2.88 8.4 -ast 137 0 0.0 119 6e+01 108 7e+01 150 26.4 338 1.20 1.9 -trig 137 19 13.9 120 7e+01 101 8e+01 134 33.0 598 3.28 16.0 -platelet 137 1 0.7 263 1e+02 258 2e+02 322 62.0 563 0.57 0.3 -protime 137 0 0.0 11 8e-01 11 1e+01 11 9.0 13 0.92 0.6 ------------------------------------------------------------- -sex: m -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 15 0 0 2156 1e+03 1656 1054 3420 191.0 4427 0.3 -1.4 -age 15 0 0 57 1e+01 53 49 66 43.9 75 0.5 -1.3 -bili 15 0 0 3 2e+00 2 1 3 0.6 9 1.5 1.4 -chol 15 1 7 301 1e+02 259 236 342 151.0 546 0.9 0.4 -albumin 15 0 0 4 5e-01 4 3 4 2.3 4 -1.0 1.9 -copper 15 0 0 125 9e+01 84 52 198 13.0 281 0.5 -1.1 -alk.phos 15 0 0 1734 2e+03 1070 737 1212 577.0 10397 3.5 12.7 -ast 15 0 0 113 4e+01 110 74 129 46.5 188 0.3 -0.8 -trig 15 1 7 115 4e+01 108 90 137 49.0 188 0.4 -0.4 -platelet 15 0 0 240 7e+01 214 190 294 119.0 360 0.2 -1.0 -protime 15 0 0 11 1e+00 11 11 12 10.0 13 0.7 0.2 ------------------------------------------------------------- -sex: f -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 139 0 0.0 1980 1e+03 1832 1e+03 2717 51.0 4523 0.3 -0.6 -age 139 0 0.0 48 1e+01 47 4e+01 55 30.6 71 0.2 -0.7 -bili 139 0 0.0 4 5e+00 1 7e-01 4 0.3 28 2.6 6.5 -chol 139 9 6.5 382 3e+02 306 3e+02 381 120.0 1775 3.0 10.1 -albumin 139 0 0.0 4 4e-01 4 3e+00 4 2.0 4 -0.8 2.1 -copper 139 1 0.7 95 8e+01 70 4e+01 127 4.0 558 2.2 8.3 -alk.phos 139 0 0.0 1966 2e+03 1345 9e+02 1992 289.0 13862 3.4 13.6 -ast 139 0 0.0 126 6e+01 118 8e+01 153 28.4 457 1.8 6.2 -trig 139 10 7.2 126 6e+01 113 8e+01 157 44.0 432 1.7 5.3 -platelet 139 2 1.4 268 9e+01 265 2e+02 324 71.0 487 0.2 -0.4 -protime 139 0 0.0 11 1e+00 11 1e+01 11 9.2 17 2.0 7.2 - -p-values - pNormal pNonNormal -time 7.300496e-01 5.566440e-01 -age 1.286381e-04 6.517437e-04 -bili 3.937430e-01 2.049525e-01 -chol 5.122223e-01 4.578773e-01 -albumin 5.853926e-01 4.041206e-01 -copper 6.237989e-05 4.712924e-05 -alk.phos 7.063812e-01 1.801480e-01 -ast 5.982898e-01 5.086616e-01 -trig 3.701073e-01 5.827726e-02 -platelet 3.624740e-01 4.451277e-01 -protime 1.365463e-01 8.114383e-02 - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -time 0.1556365 0.22071813 0.27083134 0.15677410 0.08450703 0.06369595 -age 0.5214974 0.40993004 0.13353519 0.70700091 0.60864596 0.30853876 -bili 0.1352025 0.04023105 0.11373946 0.18444097 0.04265701 0.18855913 -chol 0.2950579 0.21756422 0.62108339 0.09219212 0.33996564 0.09881382 -albumin 0.1637683 0.30878937 0.28262444 0.26228013 0.01074465 0.06658036 -copper 0.5416574 0.94378898 0.50727571 0.86116098 0.46259003 0.11048709 -alk.phos 0.1633259 0.23603622 0.30907333 0.23332162 0.09290687 0.00733728 -ast 0.1818681 0.18797132 0.34614452 0.04399580 0.12602823 0.12777729 -trig 0.2940632 0.38944815 0.63360898 0.33242327 0.09194315 0.09085446 -platelet 0.2340433 0.30251429 0.08655951 0.37226635 0.25448008 0.05557853 -protime 0.3283721 0.24596092 0.40162254 0.08476002 0.66430044 0.12924857 - 3 vs 4 -time 0.13729269 -age 0.96133382 -bili 0.24158721 -chol 0.40072828 -albumin 0.05159074 -copper 0.36464167 -alk.phos 0.10128012 -ast 0.25929154 -trig 0.22610097 -platelet 0.33286083 -protime 0.44433997 - -======================================================================================= - - ### Summary of categorical variables ### - -sex: m -trt: 1 - var n miss p.miss level freq percent cum.percent - status 21 0 0.0 0 4 19.0 19.0 - 1 3 14.3 33.3 - 2 14 66.7 100.0 - - ascites 21 0 0.0 0 20 95.2 95.2 - 1 1 4.8 100.0 - - hepato 21 0 0.0 0 9 42.9 42.9 - 1 12 57.1 100.0 - - spiders 21 0 0.0 0 18 85.7 85.7 - 1 3 14.3 100.0 - - edema 21 0 0.0 0 17 81.0 81.0 - 0.5 3 14.3 95.2 - 1 1 4.8 100.0 - - stage 21 0 0.0 1 2 9.5 9.5 - 2 4 19.0 28.6 - 3 7 33.3 61.9 - 4 8 38.1 100.0 - ------------------------------------------------------------- -sex: f -trt: 1 - var n miss p.miss level freq percent cum.percent - status 137 0 0.0 0 79 57.7 57.7 - 1 7 5.1 62.8 - 2 51 37.2 100.0 - - ascites 137 0 0.0 0 124 90.5 90.5 - 1 13 9.5 100.0 - - hepato 137 0 0.0 0 76 55.5 55.5 - 1 61 44.5 100.0 - - spiders 137 0 0.0 0 95 69.3 69.3 - 1 42 30.7 100.0 - - edema 137 0 0.0 0 115 83.9 83.9 - 0.5 13 9.5 93.4 - 1 9 6.6 100.0 - - stage 137 0 0.0 1 10 7.3 7.3 - 2 31 22.6 29.9 - 3 49 35.8 65.7 - 4 47 34.3 100.0 - ------------------------------------------------------------- -sex: m -trt: 2 - var n miss p.miss level freq percent cum.percent - status 15 0 0.0 0 7 46.7 46.7 - 1 0 0.0 46.7 - 2 8 53.3 100.0 - - ascites 15 0 0.0 0 13 86.7 86.7 - 1 2 13.3 100.0 - - hepato 15 0 0.0 0 6 40.0 40.0 - 1 9 60.0 100.0 - - spiders 15 0 0.0 0 14 93.3 93.3 - 1 1 6.7 100.0 - - edema 15 0 0.0 0 12 80.0 80.0 - 0.5 1 6.7 86.7 - 1 2 13.3 100.0 - - stage 15 0 0.0 1 1 6.7 6.7 - 2 2 13.3 20.0 - 3 5 33.3 53.3 - 4 7 46.7 100.0 - ------------------------------------------------------------- -sex: f -trt: 2 - var n miss p.miss level freq percent cum.percent - status 139 0 0.0 0 78 56.1 56.1 - 1 9 6.5 62.6 - 2 52 37.4 100.0 - - ascites 139 0 0.0 0 131 94.2 94.2 - 1 8 5.8 100.0 - - hepato 139 0 0.0 0 61 43.9 43.9 - 1 78 56.1 100.0 - - spiders 139 0 0.0 0 95 68.3 68.3 - 1 44 31.7 100.0 - - edema 139 0 0.0 0 119 85.6 85.6 - 0.5 12 8.6 94.2 - 1 8 5.8 100.0 - - stage 139 0 0.0 1 3 2.2 2.2 - 2 30 21.6 23.7 - 3 59 42.4 66.2 - 4 47 33.8 100.0 - - -p-values - pApprox pExact -status 0.03269881 0.02420814 -ascites 0.51569424 0.43540746 -hepato 0.20805680 0.20480121 -spiders 0.08898575 0.08569292 -edema 0.90584197 0.84833223 -stage 0.64630048 NA - -Standardize mean differences - average 1 vs 2 1 vs 3 1 vs 4 2 vs 3 2 vs 4 -status 0.5770647 0.8748771 0.79644734 0.83097631 0.4375075 0.06043662 -ascites 0.1755851 0.1845375 0.30219043 0.04452096 0.1211310 0.14105454 -hepato 0.1598214 0.2544151 0.05802589 0.02073917 0.3135916 0.23336861 -spiders 0.4018377 0.3999925 0.25073566 0.42200838 0.6471968 0.02154469 -edema 0.2122338 0.1624118 0.37625250 0.18063879 0.2420277 0.04705137 -stage 0.2773411 0.1333844 0.21945509 0.35632272 0.3000785 0.26275030 - 3 vs 4 -status 0.46214324 -ascites 0.26007640 -hepato 0.07878788 -spiders 0.66954801 -edema 0.26502087 -stage 0.39205566 -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("summary.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() - -detaching ‘package:survival’ - -> nameEx("summary.svyCatTable") -> ### * summary.svyCatTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: summary.svyCatTable -> ### Title: Shows all results in a 'svyCatTable' class object -> ### Aliases: summary.svyCatTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("summary.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("summary.svyContTable") -> ### * summary.svyContTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: summary.svyContTable -> ### Title: Shows all results in a 'svyContTable' class object -> ### Aliases: summary.svyContTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("summary.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("svyCreateCatTable") -> ### * svyCreateCatTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: svyCreateCatTable -> ### Title: Create an object summarizing categorical variables for weighted -> ### data -> ### Aliases: svyCreateCatTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("svyCreateCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("svyCreateContTable") -> ### * svyCreateContTable -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: svyCreateContTable -> ### Title: Create an object summarizing continous variables for weighted -> ### dataset -> ### Aliases: svyCreateContTable -> -> ### ** Examples -> -> ## See the examples for svyCreateTableOne() -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("svyCreateContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() -> nameEx("svyCreateTableOne") -> ### * svyCreateTableOne -> -> flush(stderr()); flush(stdout()) -> -> base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: svyCreateTableOne -> ### Title: Create an object summarizing any variables for weighted data -> ### Aliases: svyCreateTableOne -> -> ### ** Examples -> -> ## Load packages -> library(tableone) -> library(survey) -Loading required package: grid - -Attaching package: ‘survey’ - -The following object is masked from ‘package:graphics’: - - dotchart - -> -> ## Create a weighted survey design object -> data(nhanes) -> nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR, -+ nest = TRUE, data = nhanes) -> -> ## Create a table object -> ## factorVars are converted to factors; no need to do this if variables are already factors -> ## strata will stratify summaries; leave it unspecified, and overview is obtained -> tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), -+ strata = "RIAGENDR", data = nhanesSvy, -+ factorVars = c("race","RIAGENDR")) -> -> ## Detailed output -> summary(tab1) - - ### Summary of continuous variables ### - -RIAGENDR: 1 - n miss p.miss mean sd median p25 p75 min max -HI_CHOL 1e+08 1e+07 7 0.1 0.3 0 0 0 0 1 ------------------------------------------------------------- -RIAGENDR: 2 - n miss p.miss mean sd median p25 p75 min max -HI_CHOL 1e+08 1e+07 8 0.1 0.3 0 0 0 0 1 - -p-values - pNormal pNonNormal -HI_CHOL 0.009221135 0.009221135 - -Standardize mean differences - 1 vs 2 -HI_CHOL 0.07093003 - -======================================================================================= - - ### Summary of categorical variables ### - -RIAGENDR: 1 - var n miss p.miss level freq percent cum.percent - race 134944553.9 0.0 0.0 1 21381884.2 15.8 15.8 - 2 89315751.4 66.2 82.0 - 3 15045455.5 11.1 93.2 - 4 9201462.9 6.8 100.0 - - agecat 134944553.9 0.0 0.0 (0,19] 29299546.1 21.7 21.7 - (19,39] 40497613.1 30.0 51.7 - (39,59] 41053579.4 30.4 82.1 - (59,Inf] 24093815.3 17.9 100.0 - - RIAGENDR 134944553.9 0.0 0.0 1 134944553.9 100.0 100.0 - 2 0.0 0.0 100.0 - ------------------------------------------------------------- -RIAGENDR: 2 - var n miss p.miss level freq percent cum.percent - race 141591892.0 0.0 0.0 1 20251367.4 14.3 14.3 - 2 92486945.1 65.3 79.6 - 3 17967228.3 12.7 92.3 - 4 10886351.1 7.7 100.0 - - agecat 141591892.0 0.0 0.0 (0,19] 28150760.5 19.9 19.9 - (19,39] 40640361.5 28.7 48.6 - (39,59] 42817044.0 30.2 78.8 - (59,Inf] 29983725.9 21.2 100.0 - - RIAGENDR 141591892.0 0.0 0.0 1 0.0 0.0 0.0 - 2 141591892.0 100.0 100.0 - - -p-values - pApprox pExact -race 4.162884e-02 NA -agecat 1.175703e-03 NA -RIAGENDR 2.688704e-49 NA - -Standardize mean differences - 1 vs 2 -race 0.06878329 -agecat 0.08873652 -RIAGENDR 0.00000000 -> -> ## Default formatted printing -> tab1 - Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 - race (%) 0.042 - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.001 - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 -> -> ## nonnormal specifies variables to be shown as median [IQR] -> print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) - Stratified by RIAGENDR - 1 - n 134944553.923 - HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] - race (%) - 1 21381884.19 (15.84) - 2 89315751.41 (66.19) - 3 15045455.46 (11.15) - 4 9201462.86 ( 6.82) - agecat (%) - (0,19] 29299546.11 (21.71) - (19,39] 40497613.07 (30.01) - (39,59] 41053579.41 (30.42) - (59,Inf] 24093815.33 (17.85) - RIAGENDR = 2 (%) 0.00 ( 0.00) - Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 ( 14.30) - 2 92486945.14 ( 65.32) - 3 17967228.32 ( 12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 ( 19.88) - (19,39] 40640361.53 ( 28.70) - (39,59] 42817044.01 ( 30.24) - (59,Inf] 29983725.90 ( 21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 -> -> ## minMax changes it to median [min, max] -> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) - Stratified by RIAGENDR - 1 - n 134944553.923 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] - race (%) - 1 21381884.19 (15.84) - 2 89315751.41 (66.19) - 3 15045455.46 (11.15) - 4 9201462.86 ( 6.82) - agecat (%) - (0,19] 29299546.11 (21.71) - (19,39] 40497613.07 (30.01) - (39,59] 41053579.41 (30.42) - (59,Inf] 24093815.33 (17.85) - RIAGENDR = 2 (%) 0.00 ( 0.00) - Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 ( 14.30) - 2 92486945.14 ( 65.32) - 3 17967228.32 ( 12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 ( 19.88) - (19,39] 40640361.53 ( 28.70) - (39,59] 42817044.01 ( 30.24) - (59,Inf] 29983725.90 ( 21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 -> -> ## showAllLevels can be used tow show levels for all categorical variables -> print(tab1, showAllLevels = TRUE) - Stratified by RIAGENDR - level 1 2 - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) - race (%) 1 21381884.2 ( 15.8) 20251367.4 ( 14.3) - 2 89315751.4 ( 66.2) 92486945.1 ( 65.3) - 3 15045455.5 ( 11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) (0,19] 29299546.1 ( 21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 ( 30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 ( 30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 ( 17.9) 29983725.9 ( 21.2) - RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) - 2 0.0 ( 0.0) 141591892.0 (100.0) - Stratified by RIAGENDR - p test - n - HI_CHOL (mean (sd)) 0.009 - race (%) 0.042 - - - - agecat (%) 0.001 - - - - RIAGENDR (%) <0.001 - -> -> ## To see all printing options -> ?print.TableOne -print.TableOne package:tableone R Documentation - -_F_o_r_m_a_t _a_n_d _p_r_i_n_t _t_h_e '_T_a_b_l_e_O_n_e' _c_l_a_s_s _o_b_j_e_c_t_s - -_D_e_s_c_r_i_p_t_i_o_n: - - This is the ‘print’ method for the ‘TableOne’ class objects - created by ‘CreateTableOne’ function. - -_U_s_a_g_e: - - ## S3 method for class 'TableOne' - print(x, catDigits = 1, contDigits = 2, pDigits = 3, - quote = FALSE, missing = FALSE, explain = TRUE, printToggle = TRUE, - test = TRUE, smd = FALSE, noSpaces = FALSE, format = c("fp", "f", "p", - "pf")[1], showAllLevels = FALSE, cramVars = NULL, exact = NULL, - nonnormal = NULL, minMax = FALSE, ...) - -_A_r_g_u_m_e_n_t_s: - - x: The result of a call to the ‘CreateTableOne’ function. - -catDigits: Number of digits to print for proportions. Default 1. - -contDigits: Number of digits to print for continuous variables. Default - 2. - - pDigits: Number of digits to print for p-values. Default 3. - - quote: Whether to show everything in quotes. The default is FALSE. - If TRUE, everything including the row and column names are - quoted so that you can copy it to Excel easily. - - missing: Whether to show missing data information (not implemented - yet, placeholder) - - explain: Whether to add explanation to the variable names, i.e., (%) - is added to the variable names when percentage is shown. - -printToggle: Whether to print the output. If FLASE, no output is - created, and a matrix is invisibly returned. - - test: Whether to show the p-values. TRUE by default. If FALSE, only - the numerical summaries are shown. - - smd: Whether to show the standardized mean difference. If there - are more than one contrasts, the average of all possible - standardized mean differences is shown. For categorical - variables, Yang and Dalton's definition is used. - -noSpaces: Whether to remove spaces added for alignment. Use this option - if you prefer to align numbers yourself in other software. - - format: The default is "fp" frequency (percentage). You can also - choose from "f" frequency only, "p" percentage only, and "pf" - percentage (frequency). - -showAllLevels: Whether to show all levels. FALSE by default, i.e., for - 2-level categorical variables, only the higher level is shown - to avoid redundant information. - -cramVars: A character vector to specify the two-level categorical - variables, for which both levels should be shown in one row. - - exact: A character vector to specify the variables for which the - p-values should be those of exact tests. By default all - p-values are from large sample approximation tests - (chisq.test). - -nonnormal: A character vector to specify the variables for which the - p-values should be those of nonparametric tests. By default - all p-values are from normal assumption-based tests - (oneway.test). - - minMax: Whether to use [min,max] instead of [p25,p75] for nonnormal - variables. The default is FALSE. - - ...: For compatibility with generic. Ignored. - -_V_a_l_u_e: - - It is mainly for printing the result. But this function does - return a matrix containing what you see in the output invisibly. - You can assign it to an object to save it. - -_A_u_t_h_o_r(_s): - - Kazuki Yoshida, Justin Bohn - -_S_e_e _A_l_s_o: - - ‘CreateTableOne’, ‘print.TableOne’, ‘summary.TableOne’, - ‘CreateCatTable’, ‘print.CatTable’, ‘summary.CatTable’, - ‘CreateContTable’, ‘print.ContTable’, ‘summary.ContTable’ - -_E_x_a_m_p_l_e_s: - - ## Load - library(tableone) - - ## Load Mayo Clinic Primary Biliary Cirrhosis Data - library(survival) - data(pbc) - ## Check variables - head(pbc) - - ## Make categorical variables factors - varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") - pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - - ## Create Table 1 stratified by sex and trt - tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) - - ## Just typing the object name will invoke the print.TableOne method - tableOne - - ## Specifying nonnormal variables will show the variables appropriately, - ## and show nonparametric test p-values. Specify variables in the exact - ## argument to obtain the exact test p-values. cramVars can be used to - ## show both levels for a 2-level categorical variables. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato") - - ## Use the summary.TableOne method for detailed summary - summary(tableOne) - - ## See the categorical part only using $ operator - tableOne$CatTable - summary(tableOne$CatTable) - - ## See the continuous part only using $ operator - tableOne$ContTable - summary(tableOne$ContTable) - - ## If your work flow includes copying to Excel and Word when writing manuscripts, - ## you may benefit from the quote argument. This will quote everything so that - ## Excel does not mess up the cells. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE) - - ## If you want to center-align values in Word, use noSpaces option. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) - - -> -> ## To examine categorical variables only -> tab1$CatTable - Stratified by RIAGENDR - 1 2 p test - n 134944553.9 141591892.0 - race (%) 0.042 - 1 21381884.2 (15.8) 20251367.4 ( 14.3) - 2 89315751.4 (66.2) 92486945.1 ( 65.3) - 3 15045455.5 (11.1) 17967228.3 ( 12.7) - 4 9201462.9 ( 6.8) 10886351.1 ( 7.7) - agecat (%) 0.001 - (0,19] 29299546.1 (21.7) 28150760.5 ( 19.9) - (19,39] 40497613.1 (30.0) 40640361.5 ( 28.7) - (39,59] 41053579.4 (30.4) 42817044.0 ( 30.2) - (59,Inf] 24093815.3 (17.9) 29983725.9 ( 21.2) - RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 -> -> ## To examine continuous variables only -> tab1$ContTable - Stratified by RIAGENDR - 1 2 p test - n 134944553.92 141591892.00 - HI_CHOL (mean (sd)) 0.10 (0.30) 0.12 (0.33) 0.009 -> -> -> -> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") -> base::cat("svyCreateTableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") -> cleanEx() - -detaching ‘package:survey’, ‘package:grid’ - -> nameEx("tableone-package") -> ### * tableone-package +> nameEx("summary.ContTable") +> ### * summary.ContTable > > flush(stderr()); flush(stdout()) > > base::assign(".ptime", proc.time(), pos = "CheckExEnv") -> ### Name: tableone-package -> ### Title: Create "Table 1" to describe baseline characteristics -> ### Aliases: tableone tableone-package +> ### Name: summary.ContTable +> ### Title: Shows all results in a 'ContTable' class object +> ### Aliases: summary.ContTable > > ### ** Examples > @@ -4791,614 +2847,187 @@ detaching ‘package:survey’, ‘package:grid’ id time status trt age sex ascites hepato spiders edema bili chol 1 1 400 2 1 58.76523 f 1 1 1 1.0 14.5 261 2 2 4500 0 1 56.44627 f 0 1 1 0.0 1.1 302 -3 3 1012 2 1 70.07255 m 0 0 0 0.5 1.4 176 -4 4 1925 2 1 54.74059 f 0 1 1 0.5 1.8 244 -5 5 1504 1 2 38.10541 f 0 1 1 0.0 3.4 279 -6 6 2503 2 2 66.25873 f 0 1 0 0.0 0.8 248 - albumin copper alk.phos ast trig platelet protime stage -1 2.60 156 1718.0 137.95 172 190 12.2 4 -2 4.14 54 7394.8 113.52 88 221 10.6 3 -3 3.48 210 516.0 96.10 55 151 12.0 4 -4 2.54 64 6121.8 60.63 92 183 10.3 4 -5 3.53 143 671.0 113.15 72 136 10.9 3 -6 3.98 50 944.0 93.00 63 NA 11.0 3 -> -> ## List numerically coded categorical variables for later conversion. -> ## Factor variables are automatically handled as categorical variables. -> factorVars <- c("status","trt","ascites","hepato","spiders","edema","stage") -> -> ## Create a variable list -> dput(names(pbc)) # This shows a character vector-creating syntax. -c("id", "time", "status", "trt", "age", "sex", "ascites", "hepato", -"spiders", "edema", "bili", "chol", "albumin", "copper", "alk.phos", -"ast", "trig", "platelet", "protime", "stage") -> vars <- c("time","status","age","sex","ascites","hepato", -+ "spiders","edema","bili","chol","albumin", -+ "copper","alk.phos","ast","trig","platelet", -+ "protime","stage") -> -> ## Create Table 1 stratified by trt. Use factorVars to convert numerically -> ## coded categorical variables as factors without changing the dataset. -> tableOne <- CreateTableOne(vars = vars, strata = c("trt"), data = pbc, -+ factorVars = factorVars) -> -> ## Just typing the object name will invoke the print.TableOne method -> tableOne - Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - status (%) 0.894 - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 - chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 - alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 - stage (%) 0.201 - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) -> -> ## Specifying nonnormal variables will show the variables appropriately, -> ## and show nonparametric test p-values. Specify variables in the exact -> ## argument to obtain the exact test p-values. For two-level categorical -> ## variables specified in cramVars, both levels are shown. Use minMax -> ## argument to show median [min, max] for nonnormal variables. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "sex") - Stratified by trt - 1 2 - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) - status (%) - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) - sex = m/f (%) 21/137 (13.3/86.7) 15/139 (9.7/90.3) - ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) - hepato = 1 (%) 73 (46.2) 87 (56.5) - spiders = 1 (%) 45 (28.5) 45 (29.2) - edema (%) - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - bili (median [IQR]) 1.40 [0.80, 3.20] 1.30 [0.72, 3.60] - chol (median [IQR]) 315.50 [247.75, 417.00] 303.50 [254.25, 377.00] - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) - copper (median [IQR]) 73.00 [40.00, 121.00] 73.00 [43.00, 139.00] - alk.phos (median [IQR]) 1214.50 [840.75, 2028.00] 1283.00 [922.50, 1949.75] - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) - trig (median [IQR]) 106.00 [84.50, 146.00] 113.00 [84.50, 155.00] - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) - stage (%) - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) - Stratified by trt - p test - n - time (mean (sd)) 0.883 - status (%) 0.884 exact - 0 - 1 - 2 - age (mean (sd)) 0.018 - sex = m/f (%) 0.421 - ascites = 1 (%) 0.567 - hepato = 1 (%) 0.088 - spiders = 1 (%) 0.985 - edema (%) 0.877 - 0 - 0.5 - 1 - bili (median [IQR]) 0.842 nonnorm - chol (median [IQR]) 0.544 nonnorm - albumin (mean (sd)) 0.874 - copper (median [IQR]) 0.717 nonnorm - alk.phos (median [IQR]) 0.812 nonnorm - ast (mean (sd)) 0.460 - trig (median [IQR]) 0.370 nonnorm - platelet (mean (sd)) 0.555 - protime (mean (sd)) 0.197 - stage (%) 0.205 exact - 1 - 2 - 3 - 4 -> -> ## Use the summary.TableOne method for detailed summary -> summary(tableOne) - - ### Summary of continuous variables ### - -trt: 1 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 158 0 0.0 2016 1e+03 1895 1e+03 2632 41.0 4556 0.41 -0.4 -age 158 0 0.0 51 1e+01 52 4e+01 59 26.3 78 0.06 -0.5 -bili 158 0 0.0 3 4e+00 1 8e-01 3 0.3 20 2.67 7.6 -chol 158 18 11.4 365 2e+02 316 2e+02 417 127.0 1712 3.83 20.2 -albumin 158 0 0.0 4 4e-01 4 3e+00 4 2.1 5 -0.40 0.3 -copper 158 1 0.6 98 9e+01 73 4e+01 121 9.0 588 2.50 8.2 -alk.phos 158 0 0.0 2021 2e+03 1214 8e+02 2028 369.0 11552 2.71 7.4 -ast 158 0 0.0 120 5e+01 112 8e+01 152 26.4 338 1.09 1.6 -trig 158 19 12.0 124 7e+01 106 8e+01 146 33.0 598 2.95 14.3 -platelet 158 2 1.3 259 1e+02 255 2e+02 322 62.0 563 0.50 0.2 -protime 158 0 0.0 11 9e-01 11 1e+01 11 9.0 14 1.10 1.6 ------------------------------------------------------------- -trt: 2 - n miss p.miss mean sd median p25 p75 min max skew kurt -time 154 0 0.0 1997 1e+03 1811 1e+03 2771 51.0 4523 0.4 -0.7 -age 154 0 0.0 49 1e+01 48 4e+01 56 30.6 75 0.2 -0.5 -bili 154 0 0.0 4 5e+00 1 7e-01 4 0.3 28 2.7 7.3 -chol 154 10 6.5 374 3e+02 304 3e+02 377 120.0 1775 3.1 11.1 -albumin 154 0 0.0 4 4e-01 4 3e+00 4 2.0 4 -0.8 2.0 -copper 154 1 0.6 98 8e+01 73 4e+01 139 4.0 558 2.0 6.6 -alk.phos 154 0 0.0 1943 2e+03 1283 9e+02 1950 289.0 13862 3.3 12.8 -ast 154 0 0.0 125 6e+01 117 8e+01 152 28.4 457 1.7 6.3 -trig 154 11 7.1 125 6e+01 113 8e+01 155 44.0 432 1.7 5.5 -platelet 154 2 1.3 265 9e+01 260 2e+02 322 71.0 487 0.2 -0.3 -protime 154 0 0.0 11 1e+00 11 1e+01 11 9.2 17 1.9 6.4 - -p-values - pNormal pNonNormal -time 0.88304691 0.82661809 -age 0.01767247 0.01962155 -bili 0.13093942 0.84168460 -chol 0.74799072 0.54433899 -albumin 0.87388074 0.95045176 -copper 0.99915849 0.71745444 -alk.phos 0.74726165 0.81198200 -ast 0.45969842 0.45892358 -trig 0.88604213 0.36980434 -platelet 0.55451136 0.45482564 -protime 0.19714026 0.58802048 - -Standardize mean differences - 1 vs 2 -time 0.0166658751 -age 0.2702619258 -bili 0.1710905651 -chol 0.0382210537 -albumin 0.0180021838 -copper 0.0001200022 -alk.phos 0.0365323630 -ast 0.0837836058 -trig 0.0170615337 -platelet 0.0674763888 -protime 0.1460939117 - -======================================================================================= - - ### Summary of categorical variables ### - -trt: 1 - var n miss p.miss level freq percent cum.percent - status 158 0 0.0 0 83 52.5 52.5 - 1 10 6.3 58.9 - 2 65 41.1 100.0 - - sex 158 0 0.0 m 21 13.3 13.3 - f 137 86.7 100.0 - - ascites 158 0 0.0 0 144 91.1 91.1 - 1 14 8.9 100.0 - - hepato 158 0 0.0 0 85 53.8 53.8 - 1 73 46.2 100.0 - - spiders 158 0 0.0 0 113 71.5 71.5 - 1 45 28.5 100.0 - - edema 158 0 0.0 0 132 83.5 83.5 - 0.5 16 10.1 93.7 - 1 10 6.3 100.0 - - stage 158 0 0.0 1 12 7.6 7.6 - 2 35 22.2 29.7 - 3 56 35.4 65.2 - 4 55 34.8 100.0 - ------------------------------------------------------------- -trt: 2 - var n miss p.miss level freq percent cum.percent - status 154 0 0.0 0 85 55.2 55.2 - 1 9 5.8 61.0 - 2 60 39.0 100.0 - - sex 154 0 0.0 m 15 9.7 9.7 - f 139 90.3 100.0 - - ascites 154 0 0.0 0 144 93.5 93.5 - 1 10 6.5 100.0 - - hepato 154 0 0.0 0 67 43.5 43.5 - 1 87 56.5 100.0 - - spiders 154 0 0.0 0 109 70.8 70.8 - 1 45 29.2 100.0 - - edema 154 0 0.0 0 131 85.1 85.1 - 0.5 13 8.4 93.5 - 1 10 6.5 100.0 - - stage 154 0 0.0 1 4 2.6 2.6 - 2 32 20.8 23.4 - 3 64 41.6 64.9 - 4 54 35.1 100.0 - - -p-values - pApprox pExact -status 0.89350975 0.88422188 -sex 0.42122610 0.37743235 -ascites 0.56728647 0.52558267 -hepato 0.08820884 0.07137522 -spiders 0.98466036 0.90113734 -edema 0.87681949 0.89370131 -stage 0.20129629 0.20455558 - -Standardize mean differences - 1 vs 2 -status 0.05375763 -sex 0.11141161 -ascites 0.08900618 -hepato 0.20699413 -spiders 0.01632844 -edema 0.05811659 -stage 0.24600834 +3 3 1012 2 1 70.07255 m 0 0 0 0.5 1.4 176 +4 4 1925 2 1 54.74059 f 0 1 1 0.5 1.8 244 +5 5 1504 1 2 38.10541 f 0 1 1 0.0 3.4 279 +6 6 2503 2 2 66.25873 f 0 1 0 0.0 0.8 248 + albumin copper alk.phos ast trig platelet protime stage +1 2.60 156 1718.0 137.95 172 190 12.2 4 +2 4.14 54 7394.8 113.52 88 221 10.6 3 +3 3.48 210 516.0 96.10 55 151 12.0 4 +4 2.54 64 6121.8 60.63 92 183 10.3 4 +5 3.53 143 671.0 113.15 72 136 10.9 3 +6 3.98 50 944.0 93.00 63 NA 11.0 3 > -> ## See the categorical part only using $ operator -> tableOne$CatTable - Stratified by trt - 1 2 p test - n 158 154 - status (%) 0.894 - 0 83 (52.5) 85 (55.2) - 1 10 ( 6.3) 9 ( 5.8) - 2 65 (41.1) 60 (39.0) - sex = f (%) 137 (86.7) 139 (90.3) 0.421 - ascites = 1 (%) 14 ( 8.9) 10 ( 6.5) 0.567 - hepato = 1 (%) 73 (46.2) 87 (56.5) 0.088 - spiders = 1 (%) 45 (28.5) 45 (29.2) 0.985 - edema (%) 0.877 - 0 132 (83.5) 131 (85.1) - 0.5 16 (10.1) 13 ( 8.4) - 1 10 ( 6.3) 10 ( 6.5) - stage (%) 0.201 - 1 12 ( 7.6) 4 ( 2.6) - 2 35 (22.2) 32 (20.8) - 3 56 (35.4) 64 (41.6) - 4 55 (34.8) 54 (35.1) -> summary(tableOne$CatTable) -trt: 1 - var n miss p.miss level freq percent cum.percent - status 158 0 0.0 0 83 52.5 52.5 - 1 10 6.3 58.9 - 2 65 41.1 100.0 - - sex 158 0 0.0 m 21 13.3 13.3 - f 137 86.7 100.0 - - ascites 158 0 0.0 0 144 91.1 91.1 - 1 14 8.9 100.0 - - hepato 158 0 0.0 0 85 53.8 53.8 - 1 73 46.2 100.0 - - spiders 158 0 0.0 0 113 71.5 71.5 - 1 45 28.5 100.0 - - edema 158 0 0.0 0 132 83.5 83.5 - 0.5 16 10.1 93.7 - 1 10 6.3 100.0 - - stage 158 0 0.0 1 12 7.6 7.6 - 2 35 22.2 29.7 - 3 56 35.4 65.2 - 4 55 34.8 100.0 - ------------------------------------------------------------- -trt: 2 - var n miss p.miss level freq percent cum.percent - status 154 0 0.0 0 85 55.2 55.2 - 1 9 5.8 61.0 - 2 60 39.0 100.0 - - sex 154 0 0.0 m 15 9.7 9.7 - f 139 90.3 100.0 - - ascites 154 0 0.0 0 144 93.5 93.5 - 1 10 6.5 100.0 - - hepato 154 0 0.0 0 67 43.5 43.5 - 1 87 56.5 100.0 - - spiders 154 0 0.0 0 109 70.8 70.8 - 1 45 29.2 100.0 - - edema 154 0 0.0 0 131 85.1 85.1 - 0.5 13 8.4 93.5 - 1 10 6.5 100.0 - - stage 154 0 0.0 1 4 2.6 2.6 - 2 32 20.8 23.4 - 3 64 41.6 64.9 - 4 54 35.1 100.0 - - -p-values - pApprox pExact -status 0.89350975 0.88422188 -sex 0.42122610 0.37743235 -ascites 0.56728647 0.52558267 -hepato 0.08820884 0.07137522 -spiders 0.98466036 0.90113734 -edema 0.87681949 0.89370131 -stage 0.20129629 0.20455558 - -Standardize mean differences - 1 vs 2 -status 0.05375763 -sex 0.11141161 -ascites 0.08900618 -hepato 0.20699413 -spiders 0.01632844 -edema 0.05811659 -stage 0.24600834 +> ## Create an overall table for continuous variables +> contVars <- c("time","age","bili","chol","albumin","copper", ++ "alk.phos","ast","trig","platelet","protime") +> contTableOverall <- CreateContTable(vars = contVars, data = pbc) > -> ## See the continuous part only using $ operator -> tableOne$ContTable - Stratified by trt - 1 2 p test - n 158 154 - time (mean (sd)) 2015.62 (1094.12) 1996.86 (1155.93) 0.883 - age (mean (sd)) 51.42 (11.01) 48.58 (9.96) 0.018 - bili (mean (sd)) 2.87 (3.63) 3.65 (5.28) 0.131 - chol (mean (sd)) 365.01 (209.54) 373.88 (252.48) 0.748 - albumin (mean (sd)) 3.52 (0.44) 3.52 (0.40) 0.874 - copper (mean (sd)) 97.64 (90.59) 97.65 (80.49) 0.999 - alk.phos (mean (sd)) 2021.30 (2183.44) 1943.01 (2101.69) 0.747 - ast (mean (sd)) 120.21 (54.52) 124.97 (58.93) 0.460 - trig (mean (sd)) 124.14 (71.54) 125.25 (58.52) 0.886 - platelet (mean (sd)) 258.75 (100.32) 265.20 (90.73) 0.555 - protime (mean (sd)) 10.65 (0.85) 10.80 (1.14) 0.197 -> summary(tableOne$ContTable) -trt: 1 +> ## Simply typing the object name will invoke the print.ContTable method, +> ## which will show the sample size, means and standard deviations. +> contTableOverall + + Overall + n 418 + time (mean (sd)) 1917.78 (1104.67) + age (mean (sd)) 50.74 (10.45) + bili (mean (sd)) 3.22 (4.41) + chol (mean (sd)) 369.51 (231.94) + albumin (mean (sd)) 3.50 (0.42) + copper (mean (sd)) 97.65 (85.61) + alk.phos (mean (sd)) 1982.66 (2140.39) + ast (mean (sd)) 122.56 (56.70) + trig (mean (sd)) 124.70 (65.15) + platelet (mean (sd)) 257.02 (98.33) + protime (mean (sd)) 10.73 (1.02) +> +> ## To further examine the variables, use the summary.ContTable method, +> ## which will show more details. +> summary(contTableOverall) +strata: Overall n miss p.miss mean sd median p25 p75 min max -time 158 0 0.00 2015.6 1094.12 1895.0 1231.0 2632.5 41.0 4556.0 -age 158 0 0.00 51.4 11.01 51.9 43.0 58.9 26.3 78.4 -bili 158 0 0.00 2.9 3.63 1.4 0.8 3.2 0.3 20.0 -chol 158 18 11.39 365.0 209.54 315.5 247.8 417.0 127.0 1712.0 -albumin 158 0 0.00 3.5 0.44 3.6 3.2 3.8 2.1 4.6 -copper 158 1 0.63 97.6 90.59 73.0 40.0 121.0 9.0 588.0 -alk.phos 158 0 0.00 2021.3 2183.44 1214.5 840.8 2028.0 369.0 11552.0 -ast 158 0 0.00 120.2 54.52 111.6 76.7 151.5 26.4 338.0 -trig 158 19 12.03 124.1 71.54 106.0 84.5 146.0 33.0 598.0 -platelet 158 2 1.27 258.8 100.32 255.0 189.5 322.0 62.0 563.0 -protime 158 0 0.00 10.7 0.85 10.6 10.0 11.0 9.0 14.1 +time 418 0 0.00 1917.8 1104.67 1730.0 1092.8 2613.5 41.0 4795.0 +age 418 0 0.00 50.7 10.45 51.0 42.8 58.2 26.3 78.4 +bili 418 0 0.00 3.2 4.41 1.4 0.8 3.4 0.3 28.0 +chol 418 134 32.06 369.5 231.94 309.5 249.5 400.0 120.0 1775.0 +albumin 418 0 0.00 3.5 0.42 3.5 3.2 3.8 2.0 4.6 +copper 418 108 25.84 97.6 85.61 73.0 41.2 123.0 4.0 588.0 +alk.phos 418 106 25.36 1982.7 2140.39 1259.0 871.5 1980.0 289.0 13862.4 +ast 418 106 25.36 122.6 56.70 114.7 80.6 151.9 26.4 457.2 +trig 418 136 32.54 124.7 65.15 108.0 84.2 151.0 33.0 598.0 +platelet 418 11 2.63 257.0 98.33 251.0 188.5 318.0 62.0 721.0 +protime 418 2 0.48 10.7 1.02 10.6 10.0 11.1 9.0 18.0 skew kurt -time 0.412 -0.44 -age 0.056 -0.53 -bili 2.675 7.61 -chol 3.831 20.21 -albumin -0.395 0.30 -copper 2.503 8.21 -alk.phos 2.707 7.36 -ast 1.095 1.60 -trig 2.947 14.29 -platelet 0.498 0.25 -protime 1.103 1.62 ------------------------------------------------------------- -trt: 2 - n miss p.miss mean sd median p25 p75 min max -time 154 0 0.00 1996.9 1155.9 1811.0 1153.00 2771.2 51.0 4523.0 -age 154 0 0.00 48.6 10.0 48.1 41.43 55.8 30.6 74.5 -bili 154 0 0.00 3.6 5.3 1.3 0.72 3.6 0.3 28.0 -chol 154 10 6.49 373.9 252.5 303.5 254.25 377.0 120.0 1775.0 -albumin 154 0 0.00 3.5 0.4 3.5 3.34 3.8 2.0 4.4 -copper 154 1 0.65 97.7 80.5 73.0 43.00 139.0 4.0 558.0 -alk.phos 154 0 0.00 1943.0 2101.7 1283.0 922.50 1949.8 289.0 13862.4 -ast 154 0 0.00 125.0 58.9 117.4 83.78 151.9 28.4 457.2 -trig 154 11 7.14 125.3 58.5 113.0 84.50 155.0 44.0 432.0 -platelet 154 2 1.30 265.2 90.7 259.5 206.75 322.5 71.0 487.0 -protime 154 0 0.00 10.8 1.1 10.6 10.00 11.4 9.2 17.1 - skew kurt -time 0.35 -0.72 -age 0.24 -0.53 -bili 2.67 7.27 -chol 3.12 11.14 -albumin -0.85 1.96 -copper 2.01 6.65 -alk.phos 3.35 12.81 -ast 1.73 6.31 -trig 1.72 5.51 -platelet 0.23 -0.35 -protime 1.87 6.39 - -p-values - pNormal pNonNormal -time 0.88304691 0.82661809 -age 0.01767247 0.01962155 -bili 0.13093942 0.84168460 -chol 0.74799072 0.54433899 -albumin 0.87388074 0.95045176 -copper 0.99915849 0.71745444 -alk.phos 0.74726165 0.81198200 -ast 0.45969842 0.45892358 -trig 0.88604213 0.36980434 -platelet 0.55451136 0.45482564 -protime 0.19714026 0.58802048 +time 0.473 -0.48 +age 0.087 -0.62 +bili 2.718 8.07 +chol 3.409 14.34 +albumin -0.468 0.57 +copper 2.304 7.62 +alk.phos 2.993 9.66 +ast 1.449 4.31 +trig 2.524 11.80 +platelet 0.627 0.86 +protime 2.223 10.04 +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.ContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() -Standardize mean differences - 1 vs 2 -time 0.0166658751 -age 0.2702619258 -bili 0.1710905651 -chol 0.0382210537 -albumin 0.0180021838 -copper 0.0001200022 -alk.phos 0.0365323630 -ast 0.0837836058 -trig 0.0170615337 -platelet 0.0674763888 -protime 0.1460939117 +detaching ‘package:survival’ + +> nameEx("summary.TableOne") +> ### * summary.TableOne +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.TableOne +> ### Title: Shows all results in a '(svy)TableOne' class object +> ### Aliases: summary.TableOne +> +> ### ** Examples +> +> ## See examples for CreateTableOne and svyCreateTableOne +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.TableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("summary.svyCatTable") +> ### * summary.svyCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.svyCatTable +> ### Title: Shows all results in a 'svyCatTable' class object +> ### Aliases: summary.svyCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.svyCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("summary.svyContTable") +> ### * summary.svyContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: summary.svyContTable +> ### Title: Shows all results in a 'svyContTable' class object +> ### Aliases: summary.svyContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("summary.svyContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateCatTable") +> ### * svyCreateCatTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateCatTable +> ### Title: Create an object summarizing categorical variables for weighted +> ### data +> ### Aliases: svyCreateCatTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() > -> ## If your work flow includes copying to Excel and Word when writing manuscripts, -> ## you may benefit from the quote argument. This will quote everything so that -> ## Excel does not mess up the cells. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "sex", quote = TRUE) - "Stratified by trt" - "" "1" - "n" " 158" - "time (mean (sd))" "2015.62 (1094.12)" - "status (%)" " " - " 0" " 83 (52.5) " - " 1" " 10 ( 6.3) " - " 2" " 65 (41.1) " - "age (mean (sd))" " 51.42 (11.01)" - "sex = m/f (%)" " 21/137 (13.3/86.7) " - "ascites = 1 (%)" " 14 ( 8.9) " - "hepato = 1 (%)" " 73 (46.2) " - "spiders = 1 (%)" " 45 (28.5) " - "edema (%)" " " - " 0" " 132 (83.5) " - " 0.5" " 16 (10.1) " - " 1" " 10 ( 6.3) " - "bili (median [IQR])" " 1.40 [0.80, 3.20]" - "chol (median [IQR])" " 315.50 [247.75, 417.00]" - "albumin (mean (sd))" " 3.52 (0.44)" - "copper (median [IQR])" " 73.00 [40.00, 121.00]" - "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" - "ast (mean (sd))" " 120.21 (54.52)" - "trig (median [IQR])" " 106.00 [84.50, 146.00]" - "platelet (mean (sd))" " 258.75 (100.32)" - "protime (mean (sd))" " 10.65 (0.85)" - "stage (%)" " " - " 1" " 12 ( 7.6) " - " 2" " 35 (22.2) " - " 3" " 56 (35.4) " - " 4" " 55 (34.8) " - "Stratified by trt" - "" "2" "p" "test" - "n" " 154" "" "" - "time (mean (sd))" "1996.86 (1155.93)" " 0.883" "" - "status (%)" " " " 0.884" "exact" - " 0" " 85 (55.2) " "" "" - " 1" " 9 ( 5.8) " "" "" - " 2" " 60 (39.0) " "" "" - "age (mean (sd))" " 48.58 (9.96)" " 0.018" "" - "sex = m/f (%)" " 15/139 (9.7/90.3) " " 0.421" "" - "ascites = 1 (%)" " 10 ( 6.5) " " 0.567" "" - "hepato = 1 (%)" " 87 (56.5) " " 0.088" "" - "spiders = 1 (%)" " 45 (29.2) " " 0.985" "" - "edema (%)" " " " 0.877" "" - " 0" " 131 (85.1) " "" "" - " 0.5" " 13 ( 8.4) " "" "" - " 1" " 10 ( 6.5) " "" "" - "bili (median [IQR])" " 1.30 [0.72, 3.60]" " 0.842" "nonnorm" - "chol (median [IQR])" " 303.50 [254.25, 377.00]" " 0.544" "nonnorm" - "albumin (mean (sd))" " 3.52 (0.40)" " 0.874" "" - "copper (median [IQR])" " 73.00 [43.00, 139.00]" " 0.717" "nonnorm" - "alk.phos (median [IQR])" "1283.00 [922.50, 1949.75]" " 0.812" "nonnorm" - "ast (mean (sd))" " 124.97 (58.93)" " 0.460" "" - "trig (median [IQR])" " 113.00 [84.50, 155.00]" " 0.370" "nonnorm" - "platelet (mean (sd))" " 265.20 (90.73)" " 0.555" "" - "protime (mean (sd))" " 10.80 (1.14)" " 0.197" "" - "stage (%)" " " " 0.205" "exact" - " 1" " 4 ( 2.6) " "" "" - " 2" " 32 (20.8) " "" "" - " 3" " 64 (41.6) " "" "" - " 4" " 54 (35.1) " "" "" > -> ## If you want to center-align values in Word, use noSpaces option. -> print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), -+ exact = c("status","stage"), cramVars = "sex", quote = TRUE, noSpaces = TRUE) - "Stratified by trt" - "" "1" - "n" "158" - "time (mean (sd))" "2015.62 (1094.12)" - "status (%)" "" - " 0" "83 (52.5)" - " 1" "10 (6.3)" - " 2" "65 (41.1)" - "age (mean (sd))" "51.42 (11.01)" - "sex = m/f (%)" "21/137 (13.3/86.7)" - "ascites = 1 (%)" "14 (8.9)" - "hepato = 1 (%)" "73 (46.2)" - "spiders = 1 (%)" "45 (28.5)" - "edema (%)" "" - " 0" "132 (83.5)" - " 0.5" "16 (10.1)" - " 1" "10 (6.3)" - "bili (median [IQR])" "1.40 [0.80, 3.20]" - "chol (median [IQR])" "315.50 [247.75, 417.00]" - "albumin (mean (sd))" "3.52 (0.44)" - "copper (median [IQR])" "73.00 [40.00, 121.00]" - "alk.phos (median [IQR])" "1214.50 [840.75, 2028.00]" - "ast (mean (sd))" "120.21 (54.52)" - "trig (median [IQR])" "106.00 [84.50, 146.00]" - "platelet (mean (sd))" "258.75 (100.32)" - "protime (mean (sd))" "10.65 (0.85)" - "stage (%)" "" - " 1" "12 (7.6)" - " 2" "35 (22.2)" - " 3" "56 (35.4)" - " 4" "55 (34.8)" - "Stratified by trt" - "" "2" "p" "test" - "n" "154" "" "" - "time (mean (sd))" "1996.86 (1155.93)" "0.883" "" - "status (%)" "" "0.884" "exact" - " 0" "85 (55.2)" "" "" - " 1" "9 (5.8)" "" "" - " 2" "60 (39.0)" "" "" - "age (mean (sd))" "48.58 (9.96)" "0.018" "" - "sex = m/f (%)" "15/139 (9.7/90.3)" "0.421" "" - "ascites = 1 (%)" "10 (6.5)" "0.567" "" - "hepato = 1 (%)" "87 (56.5)" "0.088" "" - "spiders = 1 (%)" "45 (29.2)" "0.985" "" - "edema (%)" "" "0.877" "" - " 0" "131 (85.1)" "" "" - " 0.5" "13 (8.4)" "" "" - " 1" "10 (6.5)" "" "" - "bili (median [IQR])" "1.30 [0.72, 3.60]" "0.842" "nonnorm" - "chol (median [IQR])" "303.50 [254.25, 377.00]" "0.544" "nonnorm" - "albumin (mean (sd))" "3.52 (0.40)" "0.874" "" - "copper (median [IQR])" "73.00 [43.00, 139.00]" "0.717" "nonnorm" - "alk.phos (median [IQR])" "1283.00 [922.50, 1949.75]" "0.812" "nonnorm" - "ast (mean (sd))" "124.97 (58.93)" "0.460" "" - "trig (median [IQR])" "113.00 [84.50, 155.00]" "0.370" "nonnorm" - "platelet (mean (sd))" "265.20 (90.73)" "0.555" "" - "protime (mean (sd))" "10.80 (1.14)" "0.197" "" - "stage (%)" "" "0.205" "exact" - " 1" "4 (2.6)" "" "" - " 2" "32 (20.8)" "" "" - " 3" "64 (41.6)" "" "" - " 4" "54 (35.1)" "" "" > +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateCatTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateContTable") +> ### * svyCreateContTable +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateContTable +> ### Title: Create an object summarizing continous variables for weighted +> ### dataset +> ### Aliases: svyCreateContTable +> +> ### ** Examples +> +> ## See the examples for svyCreateTableOne() +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateContTable", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() +> nameEx("svyCreateTableOne") +> ### * svyCreateTableOne +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: svyCreateTableOne +> ### Title: Create an object summarizing both continuous and categorical +> ### variables for weighted data +> ### Aliases: svyCreateTableOne > -> ## Analysis for weighted data +> ### ** Examples > > ## Load packages > library(tableone) @@ -5418,8 +3047,8 @@ The following object is masked from ‘package:graphics’: + nest = TRUE, data = nhanes) > > ## Create a table object -> ## factorVars are converted to factors; no need to do this if variables are already factors -> ## strata will stratify summaries; leave it unspecified, and overview is obtained +> ## factorVars are converted to factors; no need for variables already factors +> ## strata will stratify summaries; leave it unspecified for overall summaries > tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"), + strata = "RIAGENDR", data = nhanesSvy, + factorVars = c("race","RIAGENDR")) @@ -5512,7 +3141,8 @@ RIAGENDR 0.00000000 RIAGENDR = 2 (%) 0.0 ( 0.0) 141591892.0 (100.0) <0.001 > > ## nonnormal specifies variables to be shown as median [IQR] -> print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, pDigits = 4) +> print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2, ++ pDigits = 4, smd = TRUE) Stratified by RIAGENDR 1 n 134944553.923 @@ -5529,23 +3159,24 @@ RIAGENDR 0.00000000 (59,Inf] 24093815.33 (17.85) RIAGENDR = 2 (%) 0.00 ( 0.00) Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 ( 14.30) - 2 92486945.14 ( 65.32) - 3 17967228.32 ( 12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 ( 19.88) - (19,39] 40640361.53 ( 28.70) - (39,59] 42817044.01 ( 30.24) - (59,Inf] 29983725.90 ( 21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 + 2 p test SMD + n 141591891.998 + HI_CHOL (median [IQR]) 0.000 [0.000, 0.000] 0.0092 nonnorm 0.0709 + race (%) 0.0416 0.0688 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 0.0887 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 <0.0001 > > ## minMax changes it to median [min, max] -> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, catDigits = 2, pDigits = 4) +> print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3, ++ catDigits = 2, pDigits = 4, smd = TRUE) Stratified by RIAGENDR 1 n 134944553.923 @@ -5562,23 +3193,23 @@ RIAGENDR 0.00000000 (59,Inf] 24093815.33 (17.85) RIAGENDR = 2 (%) 0.00 ( 0.00) Stratified by RIAGENDR - 2 p test - n 141591891.998 - HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm - race (%) 0.0416 - 1 20251367.39 ( 14.30) - 2 92486945.14 ( 65.32) - 3 17967228.32 ( 12.69) - 4 10886351.15 ( 7.69) - agecat (%) 0.0012 - (0,19] 28150760.54 ( 19.88) - (19,39] 40640361.53 ( 28.70) - (39,59] 42817044.01 ( 30.24) - (59,Inf] 29983725.90 ( 21.18) - RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 + 2 p test SMD + n 141591891.998 + HI_CHOL (median [range]) 0.000 [0.000, 1.000] 0.0092 nonnorm 0.0709 + race (%) 0.0416 0.0688 + 1 20251367.39 ( 14.30) + 2 92486945.14 ( 65.32) + 3 17967228.32 ( 12.69) + 4 10886351.15 ( 7.69) + agecat (%) 0.0012 0.0887 + (0,19] 28150760.54 ( 19.88) + (19,39] 40640361.53 ( 28.70) + (39,59] 42817044.01 ( 30.24) + (59,Inf] 29983725.90 ( 21.18) + RIAGENDR = 2 (%) 141591892.00 (100.00) <0.0001 <0.0001 > > ## showAllLevels can be used tow show levels for all categorical variables -> print(tab1, showAllLevels = TRUE) +> print(tab1, showAllLevels = TRUE, smd = TRUE) Stratified by RIAGENDR level 1 2 n 134944553.92 141591892.00 @@ -5594,30 +3225,30 @@ RIAGENDR 0.00000000 RIAGENDR (%) 1 134944553.9 (100.0) 0.0 ( 0.0) 2 0.0 ( 0.0) 141591892.0 (100.0) Stratified by RIAGENDR - p test - n - HI_CHOL (mean (sd)) 0.009 - race (%) 0.042 - - - - agecat (%) 0.001 - - - - RIAGENDR (%) <0.001 - + p test SMD + n + HI_CHOL (mean (sd)) 0.009 0.071 + race (%) 0.042 0.069 + + + + agecat (%) 0.001 0.089 + + + + RIAGENDR (%) <0.001 <0.001 + > > ## To see all printing options > ?print.TableOne print.TableOne package:tableone R Documentation -_F_o_r_m_a_t _a_n_d _p_r_i_n_t _t_h_e '_T_a_b_l_e_O_n_e' _c_l_a_s_s _o_b_j_e_c_t_s +_F_o_r_m_a_t _a_n_d _p_r_i_n_t '_T_a_b_l_e_O_n_e' _c_l_a_s_s _o_b_j_e_c_t_s _D_e_s_c_r_i_p_t_i_o_n: - This is the ‘print’ method for the ‘TableOne’ class objects - created by ‘CreateTableOne’ function. + ‘print’ method for the ‘TableOne’ class objects created by + ‘CreateTableOne’ function. _U_s_a_g_e: @@ -5630,14 +3261,15 @@ _U_s_a_g_e: _A_r_g_u_m_e_n_t_s: - x: The result of a call to the ‘CreateTableOne’ function. + x: Object returned by ‘CreateTableOne’ function. catDigits: Number of digits to print for proportions. Default 1. contDigits: Number of digits to print for continuous variables. Default 2. - pDigits: Number of digits to print for p-values. Default 3. + pDigits: Number of digits to print for p-values (also used for + standardized mean differences). Default 3. quote: Whether to show everything in quotes. The default is FALSE. If TRUE, everything including the row and column names are @@ -5652,13 +3284,13 @@ contDigits: Number of digits to print for continuous variables. Default printToggle: Whether to print the output. If FLASE, no output is created, and a matrix is invisibly returned. - test: Whether to show the p-values. TRUE by default. If FALSE, only - the numerical summaries are shown. + test: Whether to show p-values. TRUE by default. If FALSE, only the + numerical summaries are shown. - smd: Whether to show the standardized mean difference. If there - are more than one contrasts, the average of all possible - standardized mean differences is shown. For categorical - variables, Yang and Dalton's definition is used. + smd: Whether to show standardized mean differences. FALSE by + default. If there are more than one contrasts, the average of + all possible standardized mean differences is shown. For + categorical variables, Yang and Dalton's definition is used. noSpaces: Whether to remove spaces added for alignment. Use this option if you prefer to align numbers yourself in other software. @@ -5691,9 +3323,9 @@ nonnormal: A character vector to specify the variables for which the _V_a_l_u_e: - It is mainly for printing the result. But this function does - return a matrix containing what you see in the output invisibly. - You can assign it to an object to save it. + A matrix object containing what you see is also invisibly + returned. This can be assinged a name and exported via + ‘write.csv’. _A_u_t_h_o_r(_s): @@ -5701,62 +3333,11 @@ _A_u_t_h_o_r(_s): _S_e_e _A_l_s_o: - ‘CreateTableOne’, ‘print.TableOne’, ‘summary.TableOne’, - ‘CreateCatTable’, ‘print.CatTable’, ‘summary.CatTable’, - ‘CreateContTable’, ‘print.ContTable’, ‘summary.ContTable’ + ‘CreateTableOne’, ‘summary.TableOne’ _E_x_a_m_p_l_e_s: - ## Load - library(tableone) - - ## Load Mayo Clinic Primary Biliary Cirrhosis Data - library(survival) - data(pbc) - ## Check variables - head(pbc) - - ## Make categorical variables factors - varsToFactor <- c("status","trt","ascites","hepato","spiders","edema","stage") - pbc[varsToFactor] <- lapply(pbc[varsToFactor], factor) - - ## Create Table 1 stratified by sex and trt - tableOne <- CreateTableOne(vars = c("time","status","age","ascites","hepato", - "spiders","edema","bili","chol","albumin", - "copper","alk.phos","ast","trig","platelet", - "protime","stage"), - strata = c("sex","trt"), data = pbc) - - ## Just typing the object name will invoke the print.TableOne method - tableOne - - ## Specifying nonnormal variables will show the variables appropriately, - ## and show nonparametric test p-values. Specify variables in the exact - ## argument to obtain the exact test p-values. cramVars can be used to - ## show both levels for a 2-level categorical variables. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato") - - ## Use the summary.TableOne method for detailed summary - summary(tableOne) - - ## See the categorical part only using $ operator - tableOne$CatTable - summary(tableOne$CatTable) - - ## See the continuous part only using $ operator - tableOne$ContTable - summary(tableOne$ContTable) - - ## If your work flow includes copying to Excel and Word when writing manuscripts, - ## you may benefit from the quote argument. This will quote everything so that - ## Excel does not mess up the cells. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE) - - ## If you want to center-align values in Word, use noSpaces option. - print(tableOne, nonnormal = c("bili","chol","copper","alk.phos","trig"), - exact = c("status","stage"), cramVars = "hepato", quote = TRUE, noSpaces = TRUE) + ## See examples for CreateTableOne and svyCreateTableOne > @@ -5787,12 +3368,34 @@ _E_x_a_m_p_l_e_s: > > > base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") +> base::cat("svyCreateTableOne", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") +> cleanEx() + +detaching ‘package:survey’, ‘package:grid’ + +> nameEx("tableone-package") +> ### * tableone-package +> +> flush(stderr()); flush(stdout()) +> +> base::assign(".ptime", proc.time(), pos = "CheckExEnv") +> ### Name: tableone-package +> ### Title: Create "Table 1" to describe baseline characteristics +> ### Aliases: tableone tableone-package +> +> ### ** Examples +> +> ## See examples for CreateTableOne and svyCreateTableOne +> +> +> +> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") > base::cat("tableone-package", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t") > ### *