Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests and CI #15

Merged
merged 14 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^codecov\.yml$
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
10 changes: 8 additions & 2 deletions DESCRIPTION
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Author: Eric Zhang Chen
Maintainer: Eric Zhang Chen <chvlyl@gmail.com>
Description: A zero-inflated beta random effect model for longitudinal
microbiome data.
License: GPL-2
License: file LICENSE
LazyData: TRUE
RoxygenNote: 5.0.1
RoxygenNote: 7.2.3
Encoding: UTF-8
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
Depends:
R (>= 2.10)
Empty file modified LICENSE
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions NAMESPACE
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

export(simulate_zero_inflated_beta_random_effect_data)
export(zibr)
importFrom(stats,nlminb)
importFrom(stats,pchisq)
importFrom(stats,rbeta)
importFrom(stats,rbinom)
importFrom(stats,rnorm)
3 changes: 1 addition & 2 deletions R/data.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#' a longitudinal human microbiome study
#'
#' @docType data
#' @usage data(ibd.data)
#' @keywords datasets
#'
#' @format A data frame with 236 rows and 5 variables:
Expand All @@ -17,4 +16,4 @@
#' ...
#' }
#' @references Lewis and Chen et al. (2016) Cell Host & Microbe 18 (4), 489-500
"ibd.data"
"ibd"
1 change: 1 addition & 0 deletions R/fit_beta_regression_random_effect.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cal_beta_loglik = function(para,Z.aug,Y,subject.n,time.n,


#######################################
#' @importFrom stats nlminb pchisq
fit_beta_random_effect = function(Z=Z,Y=Y,
subject.ind=subject.ind,time.ind=time.ind,
quad.n=30,verbose=FALSE){
Expand Down
1 change: 1 addition & 0 deletions R/fit_logistic_regression_random_effect.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cal_logistic_loglik = function(para,X.aug,Y,subject.n,time.n,
### system.time(rs4 <- colSums(aperm(b, c(2,1,3))))

#######################################
#' @importFrom stats nlminb pchisq
fit_logistic_random_effect = function(X=X,Y=Y,
subject.ind=subject.ind,time.ind=time.ind,
quad.n=30,verbose=FALSE){
Expand Down
1 change: 1 addition & 0 deletions R/fit_zero_inflated_beta_regression_random_effect.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ cal_zibeta_loglik = function(para,
#######################################

#######################################
#' @importFrom stats nlminb pchisq
fit_zero_inflated_beta_random_effect = function(X=X,Z=Z,Y=Y,
subject.ind=subject.ind,time.ind=time.ind,
component.wise.test = TRUE,
Expand Down
Empty file modified R/generate_gaussian_quad_points.R
100644 → 100755
Empty file.
7 changes: 4 additions & 3 deletions R/simulate_beta_data.R
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @importFrom stats rnorm rbeta
simulate_beta_random_effect_data = function(subject.n=50, time.n=5, v=2,
beta=as.matrix(c(-0.5,-0.5,0.5)),
Z=NA, s2=1, sim.seed=100){
Expand All @@ -13,7 +14,7 @@ simulate_beta_random_effect_data = function(subject.n=50, time.n=5, v=2,
Z <- as.matrix(Z)
colnames(Z) <- paste('var',seq(1,ncol(Z)),sep='')
}

set.seed(sim.seed*5000+1)
c <- as.matrix(rnorm(subject.n,mean=0,sd=s2))
c.rep <- as.matrix(as.vector(matrix(c,nrow=time.n,ncol=length(c),byrow=TRUE)))
Expand All @@ -32,7 +33,7 @@ simulate_beta_random_effect_data = function(subject.n=50, time.n=5, v=2,
set.seed(sim.seed*5000+4)
Y <- rbeta(subject.n*time.n, shape1 = u*v, shape2=(1-u)*v)
if(any(Y>1-10^(-6))){Y[Y>1-10^(-6)] <- 1-10^(-6)}

#### For test purpose
#### betareg can not fit random effect model
#### so set the s2 to a small value (small random effect)
Expand All @@ -48,7 +49,7 @@ simulate_beta_random_effect_data = function(subject.n=50, time.n=5, v=2,
#
#fit_beta_random_effect(Z=Z,Y=Y,subject.ind=subject.ind,time.ind=time.ind,
# quad.n=30,verbose=FALSE)

return(list(Y=Y,Z=Z,c=c,u=u,v=v,beta=beta,s2=s2,
subject.ind=subject.ind,time.ind=time.ind))
}
1 change: 1 addition & 0 deletions R/simulate_logistic_data.R
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @importFrom stats rnorm rbinom
simulate_logistic_data = function(){
#########################
#########################
Expand Down
1 change: 1 addition & 0 deletions R/simulate_zero_inflated_beta_data.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @return s2 the stardard deviation of random effect in beta component
#' @return subject.ind the IDs for each subject
#' @return time.ind time points
#' @importFrom stats rnorm rbinom rbeta
#' @export
#' @examples
#' \dontrun{
Expand Down
2 changes: 1 addition & 1 deletion R/zibr.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ zibr = function(logistic.cov=logistic.cov,
#### if the colnames are the same, jointly test the two component
if (identical(colnames(logistic.cov),colnames(beta.cov))){
joint.test <- TRUE
}
}
else{
joint.test <- FALSE
}
Expand Down
15 changes: 10 additions & 5 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ZIBR (Zero-Inflated Beta Random Effect model)

<!-- badges: start -->
[![R-CMD-check](https://github.com/PennChopMicrobiomeProgram/ZIBR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/PennChopMicrobiomeProgram/ZIBR/actions/workflows/R-CMD-check.yaml)
[![codecov](https://codecov.io/gh/PennChopMicrobiomeProgram/ZIBR/graph/badge.svg?token=6A7MIF2IPE)](https://codecov.io/gh/PennChopMicrobiomeProgram/ZIBR)
<!-- badges: end -->

## Introduction
The longitudinal microbiome compositional data are highly skewed, bounded in [0,1), and often sparse with many zeros. In addition, the observations from repeated measures are correlated. We propose a two-part zero-inflated Beta regression model with random effects (ZIBR) for testing the association between microbial abundance and clinical covariates for longitudinal microbiome data. The model includes a logistic component to model presence/absence of the microbe in samples and a Beta component to model non-zero microbial abundance and each component includes a random effect to take into account the correlation among repeated measurements on the same subject.

Expand Down Expand Up @@ -81,7 +86,7 @@ zibr.fit
#### Real data
Let's try anohter example on the real data. I will use a dataset from a longitudinal human microbiome study containing the bacterial abundance and clinical information from [Lewis and Chen et al.](http://www.cell.com/cell-host-microbe/references/S1931-3128(15)00377-7). I only include the abundance from one genus.

Type ```ibd.data```.
Type ```ibd```.
```r
Sample Subject Time Treatment Abundance
1 5001-01 5001 1 0 0.000000e+00
Expand Down Expand Up @@ -116,10 +121,10 @@ The current model can not handle missing data. That is, each subject must have t
We can run the zibr function to the real data. Here, I'm interested in comparing the two treatments and use treatment as the only covariate in both logistic and beta component. Depending on the scientific questions you are interested in, you can also include time and treament-time interaction in the covariates.

```r
zibr.fit <- zibr(logistic.cov = data.frame(Treatment=ibd.data$Treatment),
beta.cov = data.frame(Treatment=ibd.data$Treatment),
Y = ibd.data$Abundance, subject.ind = ibd.data$Subject,
time.ind = ibd.data$Time)
zibr.fit <- zibr(logistic.cov = data.frame(Treatment=ibd$Treatment),
beta.cov = data.frame(Treatment=ibd$Treatment),
Y = ibd$Abundance, subject.ind = ibd$Subject,
time.ind = ibd$Time)
zibr.fit
```

Expand Down
43 changes: 22 additions & 21 deletions ZIBR.Rproj
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace,vignette
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
Binary file added data/ibd.rda
Binary file not shown.
Binary file removed data/realdata.RData
Binary file not shown.
13 changes: 7 additions & 6 deletions man/ibd.data.Rd → man/ibd.Rd
100644 → 100755

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

16 changes: 12 additions & 4 deletions man/simulate_zero_inflated_beta_random_effect_data.Rd
100644 → 100755

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

Loading