-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from adibender/issue-129
Issue 129
- Loading branch information
Showing
29 changed files
with
684 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ vignettes/*_files | |
*.dropbox.attr | ||
|
||
docs/* | ||
pkgdown/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: pammtools | ||
Title: Piece-Wise Exponential Additive Mixed Modeling Tools for Survival Analysis | ||
Version: 0.1.18 | ||
Version: 0.2.0 | ||
Date: 2020-01-30 | ||
Authors@R: c( | ||
person("Andreas", "Bender", , "[email protected]", role = c("aut", "cre"), comment=c(ORCID = "0000-0001-5628-8611")), | ||
|
@@ -20,15 +20,15 @@ Imports: | |
checkmate, | ||
magrittr, | ||
rlang, | ||
tidyr (>= 0.8.3), | ||
tidyr (>= 1.0.0), | ||
ggplot2, | ||
dplyr (>= 0.7.0), | ||
purrr (>= 0.2.3), | ||
tibble, | ||
msm, | ||
lazyeval, | ||
Formula, | ||
mvtnorm | ||
mvtnorm, | ||
pec | ||
Suggests: | ||
RColorBrewer, | ||
scam, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#' Transform crps object to data.frame | ||
#' | ||
#' A\code{as.data.frame} S3 method for objects of class \code{\link[pec]{crps}}. | ||
#' | ||
#' @inheritParams base::as.data.frame | ||
#' @param x An object of class \code{crps}. See \code{\link[pec]{crps}}. | ||
#' @importFrom tidyr pivot_longer | ||
#' | ||
#' @export | ||
as.data.frame.crps <- function(x, row.names = NULL, optional = FALSE, ...) { | ||
|
||
m <- matrix(x, nrow = dim(x)[1], ncol = dim(x)[2]) | ||
colnames(m) <- attr(x, "dimnames")[[2]] | ||
|
||
m <- as.data.frame(m) | ||
m$method <- attr(x, "dimnames")[[1]] | ||
|
||
m <- m %>% | ||
pivot_longer(cols = -.data$method, values_to = "IBS") %>% | ||
dplyr::rename(time = .data$name) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
unpam <- function(pamm) { | ||
class(pamm) <- class(pamm)[-1] | ||
pamm | ||
} | ||
repam <- function(x) { | ||
class(x) <- c("pamm", class(x)) | ||
x | ||
} | ||
|
||
append_ped_attr <- function(pamm, ped) { | ||
|
||
attr_ped <- ped_attr(ped) | ||
pamm[["attr_ped"]] <- attr_ped | ||
|
||
pamm | ||
|
||
} | ||
|
||
|
||
#' Fit a piece-wise exponential additive model | ||
#' | ||
#' A thin wrapper around \code{\link[mgcv]{gam}}, however, some arguments are | ||
#' prespecified: | ||
#' \code{family=poisson()}, \code{offset=data$offset} and \code{method="REML"}. | ||
#' The first two can not be overriden. The \code{method} argument | ||
#' can be specified as usual, but defaults to \code{GCV.cp} in \code{\link[mgcv]{gam}}. | ||
#' | ||
#' @inheritParams mgcv::gam | ||
#' @param ... Further arguments passed to \code{engine}. | ||
#' @param trafo_args A named list. If data is not in PED format, \code{as_ped} | ||
#' will be called internally with arguments provided in \code{trafo_args}. | ||
#' @param engine Character name of the function that will be called to fit the | ||
#' model. The intended entries are either \code{"gam"} or \code{"bam"} | ||
#' (both from package \code{mgcv}). | ||
#' @import mgcv | ||
#' @importFrom stats poisson | ||
#' @rdname pamm | ||
#' @seealso \code{\link[mgcv]{gam}} | ||
#' @examples | ||
#' ped <- tumor %>% | ||
#' as_ped(Surv(days, status) ~ complications, cut = seq(0, 3000, by = 50)) | ||
#' pam <- pamm(ped_status ~ s(tend) + complications, data = ped) | ||
#' summary(pam) | ||
#' ## Alternatively | ||
#' pamm( | ||
#' ped_status ~ s(tend) + complications, | ||
#' data = tumor, | ||
#' trafo_args = list(formula = Surv(days, status)~complications)) | ||
#' @export | ||
pamm <- function( | ||
formula, | ||
data = list(), | ||
method = "REML", | ||
..., | ||
trafo_args = NULL, | ||
engine = "gam") { | ||
|
||
dots <- list(...) | ||
dots$formula <- formula | ||
dots$family <- poisson() | ||
if (!is.null(trafo_args)) { | ||
trafo_args$data <- data | ||
data <- do.call(split_data, trafo_args) | ||
} | ||
dots$data <- data | ||
dots$offset <- data$offset | ||
|
||
pamm_fit <- do.call(engine, dots) | ||
class(pamm_fit) <- c("pamm", class(pamm_fit)) | ||
pamm_fit <- append_ped_attr(pamm_fit, data) | ||
pamm_fit[["trafo_args"]] <- attr(data, "trafo_args") | ||
|
||
pamm_fit | ||
|
||
} | ||
|
||
|
||
#' Check if object is of class pamm | ||
#' | ||
#' @param x Any R object. | ||
#' @rdname pamm | ||
#' @keywords internal | ||
#' @export | ||
is.pamm <- function(x) inherits(x, "pamm") | ||
|
||
|
||
#' @rdname pamm | ||
#' @keywords internal | ||
#' @export | ||
print.pamm <- function(x, ...) { | ||
|
||
print(unpam(x), ...) | ||
|
||
} | ||
|
||
#' @rdname pamm | ||
#' @param object An object of class \code{pamm} as returned by \code{\link{pamm}}. | ||
#' @keywords internal | ||
#' @export | ||
summary.pamm <- function(object, ...) { | ||
|
||
summary(unpam(object), ...) | ||
|
||
} | ||
|
||
#' @rdname pamm | ||
#' @keywords internal | ||
#' @export | ||
plot.pamm <- function(x, ...) { | ||
|
||
plot(unpam(x), ...) | ||
|
||
} |
Oops, something went wrong.