Skip to content

Commit

Permalink
Merge branch 'release/0.8.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kaz-yos committed Jun 16, 2017
2 parents 4238221 + aa27a08 commit a91c08c
Show file tree
Hide file tree
Showing 58 changed files with 1,468 additions and 485 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cran-comment.md

## Avoid Makefile, testing-related files, and archives
Makefile
revdep
revdep_check.txt
tableone.Rcheck
.*.tar.gz
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.Rhistory
*.tar.gz
*.Rcheck
revdep
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Sample .travis.yml for R projects
# .travis.yml for Travis CI
# https://docs.travis-ci.com/user/languages/r
# https://github.com/craigcitro/r-travis/wiki/Porting-to-native-R-support-in-Travis

language: r
r:
- oldrel
- release
- devel
cache: packages
# helpful when preparing your package for submission to CRAN
warnings_are_errors: true
sudo: required
# No need for sudo as R is natively supported now.
sudo: false

env:
global:
Expand Down
15 changes: 9 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: tableone
Type: Package
Title: Create "Table 1" to Describe Baseline Characteristics
Version: 0.7.3
Date: 2015-11-10
Version: 0.8.0
Date: 2017-06-15
Author: Kazuki Yoshida, Justin Bohn.
Maintainer: Kazuki Yoshida <[email protected]>
Description: Creates "Table 1", i.e., description of baseline patient
Expand All @@ -19,7 +19,8 @@ Imports:
MASS,
e1071,
zoo,
gmodels
gmodels,
nlme
Suggests:
survival,
testthat,
Expand All @@ -28,7 +29,9 @@ Suggests:
Matching,
reshape2,
ggplot2,
knitr
rmarkdown,
geepack,
lme4
URL: https://github.com/kaz-yos/tableone
VignetteBuilder: knitr
RoxygenNote: 5.0.0
VignetteBuilder: rmarkdown
RoxygenNote: 6.0.1
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ PKG_FILES := DESCRIPTION NAMESPACE NEWS $(R_FILES) $(TST_FILES) $(SRC_FILES) $(V
### Define targets

## test just runs testthat scripts. No dependencies.
test:
Rscript -e "devtools::test()" | tee test-all.txt
test: NAMESPACE
Rscript -e "options(width = 120); devtools::test()" | tee test-all.txt

## build_win always build regardless of file update status
## Links to results e-mailed (no useful output locally)
Expand All @@ -45,29 +45,30 @@ build: $(PKG_NAME)_$(PKG_VERSION).tar.gz
## (file target) The *.tar.gz file depends on package files including NAMESPACE,
## and build *.tar.gz file from these.
$(PKG_NAME)_$(PKG_VERSION).tar.gz: $(PKG_FILES)
R CMD build ../${PKG_NAME}
cp -a ${VIG_FILES} inst/doc/
Rscript -e "devtools::build(pkg = '.', path = '.', manual = TRUE)"

## (file target) NAMESPACE depends on *.R files, and excecute roxygen2 on these.
## methods::is() is not automatically loaded by roxygen2 version 4
NAMESPACE: $(R_FILES)
Rscript -e "library(methods); library(roxygen2); roxygenize('.')"
Rscript -e "devtools::document('.')"

## check requires the *.tar.gz file, and execute strict tests on it.
check: $(PKG_NAME)_$(PKG_VERSION).tar.gz
R CMD check --as-cran ./$(PKG_NAME)_$(PKG_VERSION).tar.gz | tee cran-check.txt
Rscript -e "options(width = 120); devtools::check(pkg = '.', check_dir = '.', manual = TRUE)" | tee cran-check.txt

## revdep requires the *.tar.gz file, and execute strict tests on it.
revdep: $(PKG_NAME)_$(PKG_VERSION).tar.gz
Rscript -e "devtools::revdep_check()" | tee revdep_check.txt
Rscript -e "options(width = 120); devtools::revdep_check()" | tee revdep_check.txt

## install requires the *.tar.gz file, and execute installation using it.
install: $(PKG_NAME)_$(PKG_VERSION).tar.gz
R CMD install ./$(PKG_NAME)_$(PKG_VERSION).tar.gz
Rscript -e "devtools::install('.')"


## clean has no dependency, and execute removal of make output files.
clean:
-rm -f $(PKG_NAME)_*.tar.gz
-rm -f $(PKG_NAME)_$(PKG_VERSION).tar.gz
-rm -r -f $(PKG_NAME).Rcheck
-rm -r -f man/*.Rd
-rm -r -f NAMESPACE
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ importFrom(stats,fisher.test)
importFrom(stats,kruskal.test)
importFrom(stats,median)
importFrom(stats,oneway.test)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stats,var)
importFrom(stats,vcov)
importFrom(stats,xtabs)
importFrom(utils,combn)
importFrom(utils,tail)
55 changes: 55 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@
tableone 0.8.0 (2017-06-15)
----------------------------------------------------------------

NEW FEATURES

* The "missing" option for the print methods was implemented. If
TRUE, a column called "Missing" is added as the rightmost column
of the formatted table. This represents percentage of missing
observation in each variable. Please note this is the percentage
with respect to the unweighted raw observations even in weighted
tables.

* The "padColnames" option was added the print.TableOne method. If
TRUE, the column names of the formatted table become space-padded
to center them.


tableone 0.7.6 (2016-07-12)
----------------------------------------------------------------

BUG FIXES

* The explanation for the "factorVars" argument for the functions
CreateTableOne and svyCreateTableOne were changed for clarity.
When factor variables are included in the argument, they are
releveled to exlude empty levels. This was not clearly documented
in the previous documentation. Thanks @eribul.

* svyrep.design objects (survey design objects with replicate weights)
are allowed for the data argument in svyTableOne. This is considered
experimental. Thanks @przemo.


tableone 0.7.5 (2016-04-10)
----------------------------------------------------------------

BUG FIXES

* ShowRegTable() now correctly supports models fit with geepack,
nlme, and lme4.


tableone 0.7.4 (2016-03-31)
----------------------------------------------------------------

NEW FEATURE

* Define SMD := 0 when the numerator is 0 even if the denominator
is also 0. This is more intuitive because a constant compared
across two groups will give an SMD of 0 rather than NaN (0/0).
For example, if two groups being compared both only have one
gender (all female or all male), then SMD for the gender
variable is defined as 0.


tableone 0.7.3 (2015-11-10)
----------------------------------------------------------------

Expand Down
7 changes: 6 additions & 1 deletion R/CreateCatTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function(vars, # character vector of variable n
## Abort if no variables exist at this point
ModuleStopIfNoVarsLeft(vars)

## Get the missing percentage for each variable (no strata).
## This has to happen before includeNA is used.
percentMissing <- ModulePercentMissing(data[vars])

## Extract necessary variables (unused variables are not included in dat)
dat <- data[c(vars)]

Expand Down Expand Up @@ -199,7 +203,8 @@ function(vars, # character vector of variable n
attributes(result) <- c(attributes(result),
list(pValues = pValues),
list(xtabs = listXtabs),
list(smd = smds))
list(smd = smds),
list(percentMissing = percentMissing))

## Return
return(result)
Expand Down
6 changes: 5 additions & 1 deletion R/CreateContTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ function(vars, # character vector of variable
## Abort if no variables exist at this point
ModuleStopIfNoVarsLeft(vars)

## Get the missing percentage for each variable (no strata).
percentMissing <- ModulePercentMissing(data[vars])

## Extract necessary variables
dat <- data[c(vars)]

Expand Down Expand Up @@ -249,7 +252,8 @@ function(vars, # character vector of variable
## Give additional attributes
attributes(result) <- c(attributes(result),
list(pValues = pValues),
list(smd = smds))
list(smd = smds),
list(percentMissing = percentMissing))

## Return
return(result)
Expand Down
9 changes: 7 additions & 2 deletions R/CreateTableOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##' @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 factorVars Numerically coded variables that should be handled as categorical variables given as a character vector. Do not include factors, unless you need to relevel them by removing empty levels. If omitted, only factors are considered categorical variables. 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{oneway.test}. This is equivalent of the t-test when there are only two groups.
Expand Down Expand Up @@ -141,6 +141,9 @@ function(vars, # character vector of variab
test <- ModuleReturnFalseIfNoStrata(strata, test)
smd <- ModuleReturnFalseIfNoStrata(strata, smd)

## Get the missing percentage for each variable (no strata).
percentMissing <- ModulePercentMissing(data[vars])

## Get the classes of the variables
varClasses <- lapply(data[vars], class)

Expand Down Expand Up @@ -238,7 +241,9 @@ function(vars, # character vector of variab
logiFactors = logiFactors,
## names of vars of each type
varFactors = varFactors,
varNumerics = varNumerics))
varNumerics = varNumerics,
## Missing data percentage for each variable (no strata).
percentMissing = percentMissing))

## Give a class
class(TableOneObject) <- "TableOne"
Expand Down
39 changes: 33 additions & 6 deletions R/ShowRegTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,39 @@ ShowRegTable <- function(model, exp = TRUE, digits = 2, pDigits = 3, printToggle
fmt1 <- paste0("%.", digits, "f")
fmt2 <- paste0("%.", pDigits, "f")

## Obtain necessary data
## The model must have summary and confint methods
modelCoef <- coef(model)
modelConfInt <- suppressMessages(ciFun(model))
modelSummaryMat <- coef(summary(model))
modelP <- modelSummaryMat[,ncol(modelSummaryMat)]
## Extract coefficients
if (any(class(model) %in% c("lme"))) {
## nlme needs special handling
## Use column 2 because it is the point estimate
modelCoef <- nlme::intervals(model)[[1]][, 2]
} else if (any(class(model) %in% c("lmerMod","glmerMod"))) {
## (g)lmer gives confint for other extra parameters
modelCoef <- coef(summary(model))[,1]
} else {
modelCoef <- coef(model)
}

## Extract confidence intervals
if (any(class(model) %in% c("lme"))) {
## nlme needs special handling
## Drop column 2 because it is the point estimate
modelConfInt <- nlme::intervals(model)[[1]][, -2]
} else if (any(class(model) %in% c("lmerMod","glmerMod"))) {
## (g)lmer gives confint for other extra parameters
modelConfInt <- tail(suppressMessages(ciFun(model)), length(modelCoef))
} else {
modelConfInt <- suppressMessages(ciFun(model))
}

## P-value extraction
if (any(class(model) %in% c("gls", "lme"))) {
## nlme needs special handling
modelSummaryMat <- summary(model)$tTable
} else {
modelSummaryMat <- coef(summary(model))
}
## Extract p value from
modelP <- modelSummaryMat[,ncol(modelSummaryMat)]

## Create the result matrix with beta and two columns of confidence interval
resMat <- cbind(beta = modelCoef,
Expand Down
27 changes: 27 additions & 0 deletions R/modules-ShowRegTable.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/local/bin/Rscript

################################################################################
### Modules to support ShowRegTable()
##
## Created on: 2016-03-19
## Author: Kazuki Yoshida
################################################################################

### geepack support

## cov.unscaled
## the unscaled (dispersion = 1) estimated covariance matrix of the estimated coefficients.
## cov.scaled (This is appropriate.)
## ditto, scaled by dispersion.
vcov.geeglm <- function(object, ...) {
summary(object)$cov.scaled
}

confint.geeglm <- function(fit, level = 0.95) {
coefs <- coef(fit)
ses <- sqrt(diag(vcov(fit)))
q <- qnorm(p = 1 - level, lower.tail = FALSE)

data.frame(lower = coefs - q * ses,
upper = coefs + q * ses)
}
10 changes: 10 additions & 0 deletions R/modules-constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,13 @@ ModuleApproxExactTests <- function(result, strata, dat, strataVarName,
## Return both xtabs and p value df
list(pValues = pValues, xtabs = listXtabs)
}


###
### Module for marginal missing percentage handling
################################################################################

## Returns a vector of missing percentage given data frame
ModulePercentMissing <- function(data) {
unlist(lapply(data, function(x) {sum(is.na(x)) / length(x) * 100}))
}
Loading

0 comments on commit a91c08c

Please sign in to comment.