Skip to content

Commit

Permalink
Merge pull request #248 from adibender/issue-247
Browse files Browse the repository at this point in the history
Issue 247
  • Loading branch information
adibender authored Jan 29, 2025
2 parents 170e59c + 82c2266 commit 5fab415
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 62 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: pammtools
Title: Piece-Wise Exponential Additive Mixed Modeling Tools for Survival Analysis
Version: 0.5.93
Date: 2024-02-24
Version: 0.6.01
Date: 2025-01-29
Authors@R: c(
person("Andreas", "Bender", , "[email protected]", role = c("aut", "cre"), comment=c(ORCID = "0000-0001-5628-8611")),
person("Fabian", "Scheipl", , "[email protected]", role = c("aut"), comment = c(ORCID = "0000-0001-8172-3603")),
Expand All @@ -16,7 +16,7 @@ Description: The Piece-wise exponential (Additive Mixed) Model
including data simulation, transformation and other functions for data
preprocessing and model post-processing as well as visualization.
Depends:
R (>= 3.5.0)
R (>= 4.1.0)
Imports:
mgcv,
survival (>= 2.39-5),
Expand Down Expand Up @@ -45,6 +45,6 @@ License: MIT + file LICENSE
LazyData: true
URL: https://adibender.github.io/pammtools/
BugReports: https://github.com/adibender/pammtools/issues
RoxygenNote: 7.1.2
RoxygenNote: 7.3.2
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
14 changes: 12 additions & 2 deletions R/add-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,31 @@ add_term <- function(

}

#' Create design matrix from a suitable object
#'
#' @keywords internal
#' @param object A suitable object from which a design matrix can be generated.
#' Often a model object.
make_X <- function(object, ...) {

UseMethod("make_X", object)

}

#' @rdname make_X
#' @inherit make_X
#' @param newdata A data frame from which design matrix will be constructed
make_X.default <- function(object, newdata, ...) {

X <- model.matrix(object$formula[-2], data = newdata, ...)
model.matrix(object$formula[-2], data = newdata, ...)

}

#' @inherit make_X.default
#' @rdname make_X
make_X.gam <- function(object, newdata, ...) {

X <- predict.gam(object, newdata = newdata, type = "lpmatrix", ...)
predict.gam(object, newdata = newdata, type = "lpmatrix", ...)

}

Expand Down
2 changes: 2 additions & 0 deletions R/get-cut-points.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ get_cut.default <- function(
}


#' @rdname get_cut
#' @inherit get_cut
get_cut.list <- function (
data,
formula,
Expand Down
4 changes: 2 additions & 2 deletions R/ggplot-extensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#' @seealso
#' \code{\link[ggplot2]{geom_ribbon}} \code{geom_stepribbon}
#' inherits from \code{geom_ribbon}.
#' @inheritParams ggplot2:::geom_ribbon
#' @inheritParams ggplot2:::geom_step
#' @examples
#' library(ggplot2)
#' huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
Expand All @@ -23,6 +21,8 @@
#' geom_line(aes(y = level))
#' @rdname geom_stepribbon
#' @importFrom ggplot2 layer GeomRibbon
#' @inheritParams ggplot2::geom_step
#' @inheritParams ggplot2::geom_ribbon
#' @export
geom_stepribbon <- function(
mapping = NULL,
Expand Down
13 changes: 6 additions & 7 deletions R/interval-information.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ int_info.default <- function(
if (is.unsorted(x)) {
x <- sort(x)
}
if (min(x != 0)) {
if (min(x) != 0) {
x <- c(0, x)
}

intlen <- diff(x)
tstart <- x[-length(x)]
tend <- tstart + intlen
tend <- x[-1]

tdf <- data.frame(
tstart = tstart,
tend = tend,
intlen = intlen) %>%
intlen = tend - tstart) %>%
mutate(
intmid = tstart + intlen / 2,
interval = paste0("(", tstart, ",", tend, "]"),
intmid = .data$tstart + .data$intlen / 2,
interval = paste0("(", .data$tstart, ",", .data$tend, "]"),
interval = factor(.data$interval, levels = unique(.data$interval))
)

Expand Down Expand Up @@ -155,7 +154,7 @@ get_intervals.default <- function(
int_df <- int_info(x)
int <- findInterval(
x = times,
vec = sort(union(int_df$tstart, int_df$tend)),
vec = c(int_df$tstart[1], int_df$tend),
left.open = left.open,
rightmost.closed = rightmost.closed)

Expand Down
4 changes: 2 additions & 2 deletions R/pammtools.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
#'
#' Bender, Andreas, and Fabian Scheipl. 2018.
#' “pammtools: Piece-Wise Exponential Additive Mixed Modeling Tools.”
#' ArXiv:1806.01042 [Stat], June. https://arxiv.org/abs/1806.01042.
NULL
#' ArXiv:1806.01042 Stat, June. https://arxiv.org/abs/1806.01042.
"_PACKAGE"
NULL
14 changes: 9 additions & 5 deletions R/warnings.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ warn_about_new_time_points <- function(object, newdata, ...) {

}


#' @inherit warn_about_new_time_points
#' @keywords internal
warn_about_new_time_points.glm <- function(object, newdata, time_var, ...) {

is_pam <- inherits(object, "gam")

if(is_pam & is.null(object$model)){
if (is_pam && is.null(object$model)) {
return(invisible())
}

original_intervals <- if (is_pam) {
unique(model.frame(object)[[time_var]])
} else levels(model.frame(object)[[time_var]])
} else {
levels(model.frame(object)[[time_var]])
}
prediction_intervals <- if (is_pam) {
unique(newdata[[time_var]])
} else levels(factor(newdata[[time_var]]))
} else {
levels(factor(newdata[[time_var]]))
}
new_ints <- which(!(prediction_intervals %in% original_intervals))
n_out <- pmin(10, length(new_ints))
if (length(new_ints)) {
message <- paste0(
"Time points/intervals in new data not equivalent to time points/intervals during model fit.",
Expand Down
4 changes: 0 additions & 4 deletions man/dplyr_verbs.Rd

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

63 changes: 51 additions & 12 deletions man/geom_hazard.Rd

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

63 changes: 51 additions & 12 deletions man/geom_stepribbon.Rd

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

11 changes: 11 additions & 0 deletions man/get_cut.Rd

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

7 changes: 0 additions & 7 deletions man/get_term.Rd

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

24 changes: 24 additions & 0 deletions man/make_X.Rd

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

Loading

0 comments on commit 5fab415

Please sign in to comment.