Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnovik committed Jun 13, 2024
0 parents commit 87b0a58
Show file tree
Hide file tree
Showing 113 changed files with 10,186 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
^\_config\.yml$
^\.github$
^CONTRIBUTING\.md$
^NEWS\.md$
^_pkgdown\.yml$
pkgdown/
.DS_Store
.Rhistory
.gitignore
^codecov\.yml$
vignettes/models-survival-check.Rmd
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
96 changes: 96 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# This workflow file is from https://github.com/stan-dev/cmdstanr/blob/master/.github/workflows
# under the BSD 3-Clause License: https://github.com/stan-dev/cmdstanr/blob/master/LICENSE.md.
#
# BSD 3-Clause License
# Copyright (c) 2019, Stan Developers and their Assignees
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

on:
push:
branches:
- main
- develop

name: check

jobs:
check:
if: "! contains(github.event.head_commit.message, '[ci skip]')"
runs-on: ${{ matrix.config.os }}

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

strategy:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: 'release', rtools: '42'}
- {os: ubuntu-latest, r: 'release', rtools: ''}


env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
NOT_CRAN: true

steps:
- name: cmdstan env vars
run: |
echo "CMDSTAN_PATH=${HOME}/.cmdstan" >> $GITHUB_ENV
shell: bash

- uses: actions/checkout@v3

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y libglpk-dev libglpk40 libcurl4-openssl-dev openmpi-bin openmpi-common libopenmpi-dev || true
- uses: r-lib/actions/[email protected]
with:
r-version: ${{ matrix.config.r }}
rtools-version: ${{ matrix.config.rtools }}

- uses: r-lib/actions/[email protected]

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

- name: Install cmdstan
run: |
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
cmdstanr::install_cmdstan(cores = 2)
shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.Rproj.user
*.Rhistory
*.RData
*.Ruserdata
*.DS_Store
*.exe
*.so
*.o
*.dll
docs/
*.html
*_cache/
*_files/
.Rproj.user
inst/doc
39 changes: 39 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Package: sfgp
Type: Package
Title: Additive semiparametric modeling
Version: 0.3.0
Author: Juho Timonen.
Maintainer: Juho Timonen <[email protected]>
Description: Additive semiparametric regression modeling with joint longitudinal
and time-to-event models.
The additive components of the longitudinal part can be for example
Stein-Fojo or approximate Gaussian process functions.
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Depends:
R (>= 3.5.0)
SystemRequirements: CmdStan >= 2.33.0
Remotes:
stan-dev/cmdstanr,
Imports:
methods,
cmdstanr (>= 0.4.0),
checkmate (>= 2.0.0),
posterior (>= 1.1.0),
R6 (>= 2.4.0),
ggplot2 (>= 3.3.5),
ggdist (>= 3.3.1),
processx (>= 3.5.2),
stringr (>= 1.5.0),
ggpubr (>= 0.6.0),
dplyr (>= 1.1.4),
magrittr(>= 2.0.3)
Suggests:
covr,
knitr,
rmarkdown,
testthat (>= 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
License: file LICENSE
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2024, Generable

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 changes: 35 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by roxygen2: do not edit by hand

S3method("+",FunctionDraws)
S3method("-",FunctionDraws)
export("%>%")
export(FunctionDraws)
export(JointModel)
export(JointModelFit)
export(StanModelFit)
export(TSModel)
export(TSModelFit)
export(TTEModel)
export(TermList)
export(WeibullHazard)
export(add_sff_input)
export(create_jm_grid)
export(example)
export(example2)
export(extend_df)
export(extend_df2)
export(new_draws)
export(plot_metric)
export(predict_new_subjects)
export(prior_sigma_informed)
export(sample_subjects)
export(sfsim)
export(stancode_ts)
export(term_to_code)
export(trajectory_metrics)
export(treatment_effect)
import(ggplot2)
import(stats)
importFrom(R6,R6Class)
importFrom(magrittr,"%>%")
importFrom(posterior,as_draws_rvars)
80 changes: 80 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# MAIN DOCUMENTATION PAGE -------------------------------------------------

#' The 'sfgp' package.
#'
#' @description SF+GP modeling using 'Stan'.
#' @author Juho Timonen (first.last at iki.fi)
#' @keywords tumor GP Stan Bayesian
#'
#' @section Getting started:
#' See the following \code{R6} classes.
#' \itemize{
#' \item \code{\link{TSModel}}: Main model class.
#' \item \code{\link{TSModelFit}}: Fit class.
#' \item \code{\link{JointModel}}: Main model class.
#' \item \code{\link{JointModelFit}}: Fit class.
#' \item \code{\link{TermList}}: Class describing model terms.
#' \item \code{\link{FunctionDraws}}: Class to hold fitted function
#' distributions.
#' }
#'
#' @section Data:
#' The data that you wish to analyze with 'sfgp' should be in an \R
#' \code{data.frame} where columns correspond to measured variables and rows
#' correspond to observations. Categorical variables should be \code{factor}s
#' and continuous ones should be \code{numeric}.
#'
#' @name sfgp-package
#' @aliases sfgp
#' @import ggplot2 stats
#' @importFrom R6 R6Class
#' @importFrom posterior as_draws_rvars
#'
#'
"_PACKAGE"


#' Run an example
#'
#' @description Fits a model to simple simulated data.
#' @export
#' @param num_bf Number of basis functions.
#' @param scale_bf Basis function domain scale.
#' @param formula The model formula.
#' @param ... Other arguments to the \code{$fit()} method of
#' \code{\link{TSModel}}.
#' @return An \code{\link{TSModelFit}} object.
example <- function(num_bf = 32, scale_bf = 1.5, formula = "y ~ gp(x)",
...) {
form <- stats::as.formula(formula)
m <- TSModel$new(form)
xx <- seq(1, 10, by = 0.15)
ff <- 20 + 5 * sin(xx) + 2 * sin(5 * xx) + xx
yy <- ff + stats::rnorm(n = length(xx), mean = 0, sd = 1)
a <- data.frame(x = xx, y = yy)
tc1 <- list(num_bf = num_bf, scale_bf = scale_bf)
tc <- list(f_gp_x = tc1)
m$fit(data = a, term_confs = tc, ...)
}

#' Run an example
#'
#' @description Fits a model to \code{testdata}.
#' @export
#' @param num_bf Number of basis functions.
#' @param scale_bf Basis function domain scale.
#' @param formula The model formula.
#' @param ... Other arguments to the \code{$fit()} method of
#' \code{\link{TSModel}}.
#' @return An \code{\link{TSModelFit}} object.
example2 <- function(num_bf = 24, scale_bf = 1.5,
formula = "y ~ gp(time) + gp(time,arm) + gp(time,id)",
...) {
form <- stats::as.formula(formula)
dat <- testdata
m <- TSModel$new(form)
dat <- add_sff_input(dat, m)
tc1 <- list(num_bf = num_bf, scale_bf = scale_bf)
tc <- list(gp_x = tc1)
m$fit(data = dat, term_confs = tc, ...)
}
25 changes: 25 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' Simulated longitudinal test data
#'
#'
#' @format
#' A data frame with 176 rows and 7 columns:
#' \describe{
#' \item{id}{Subject id, factor}
#' \item{arm}{Trial arm, factor}
#' \item{sex}{Sex, factor}
#' \item{time}{Measurement time, numeric}
#' \item{weight}{Weight, numeric}
#' \item{y}{Response variable, numeric}
#' \item{f_true}{True signal}
#' }
#' @family built-in datasets
"testdata"

#' Simulated joint longitudinal and time-to-event test data
#'
#'
#' @format
#' A list of two data frames \code{lon} (longitudinal data) and
#' \code{tte} (time-to-event data). Generated using \code{simjm}.
#' @family built-in datasets
"example_data_jm"
Loading

0 comments on commit 87b0a58

Please sign in to comment.