Skip to content

Commit

Permalink
style: reformat docs
Browse files Browse the repository at this point in the history
  • Loading branch information
niekdt committed Sep 22, 2023
1 parent 8fb323d commit 821d65b
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 42 deletions.
32 changes: 22 additions & 10 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#' @name latrend-data
#' @title Longitudinal dataset representation
#' @description The [latrend estimation functions][latrend-estimation] expect univariate longitudinal data that can be represented in a `data.frame` with one row per trajectory observation:
#' @description The [latrend estimation functions][latrend-estimation] expect univariate
#' longitudinal data that can be represented in a `data.frame` with one row per trajectory observation:
#' * Trajectory identifier: `numeric`, `character`, or `factor`
#' * Observation time: `numeric`
#' * Observation value: `numeric`
#'
#' In principle, any type of longitudinal data structure is supported, given that it can be transformed to the required `data.frame` format using the generic [trajectories] function.
#' In principle, any type of longitudinal data structure is supported,
#' given that it can be transformed to the required `data.frame` format using the generic [trajectories] function.
#' Support can be added by implementing the [trajectories] function for the respective signature.
#' This means that users can implement their own data adapters as needed.
#'
Expand Down Expand Up @@ -52,9 +54,12 @@ NULL
#' @name PAP.adh
#' @title Weekly Mean PAP Therapy Usage of OSA Patients in the First 3 Months
#' @description
#' A simulated longitudinal dataset comprising 301 patients with obstructive sleep apnea (OSA) during their first 91 days (13 weeks) of PAP therapy.
#' The longitudinal patterns were inspired by the adherence patterns reported by Yi et al. (2022), interpolated to weekly hours of usage.
#' @format A `data.frame` comprising longitudinal data of 500 patients, each having 26 observations over a period of 1 year.
#' A simulated longitudinal dataset comprising 301 patients with obstructive sleep apnea (OSA)
#' during their first 91 days (13 weeks) of PAP therapy.
#' The longitudinal patterns were inspired by the adherence patterns reported by Yi et al. (2022),
#' interpolated to weekly hours of usage.
#' @format A `data.frame` comprising longitudinal data of 500 patients, each having 26 observations
#' over a period of 1 year.
#' Each row represents a patient observation interval (two weeks), with columns:
#' \describe{
#' \item{Patient}{`integer`: The patient identifier, where each level represents a simulated patient.}
Expand Down Expand Up @@ -87,11 +92,13 @@ NULL
#' @name PAP.adh1y
#' @title Biweekly Mean PAP Therapy Adherence of OSA Patients over 1 Year
#' @description
#' A simulated longitudinal dataset comprising 500 patients with obstructive sleep apnea (OSA) during their first year on CPAP therapy.
#' A simulated longitudinal dataset comprising 500 patients with obstructive sleep apnea (OSA)
#' during their first year on CPAP therapy.
#' The dataset contains the patient usage hours, averaged over 2-week periods.
#'
#' The daily usage data underlying the downsampled dataset was simulated based on 7 different adherence patterns.
#' The defined adherence patterns were inspired by the adherence patterns identified by Aloia et al. (2008), with slight adjustments
#' The defined adherence patterns were inspired by the adherence patterns identified by Aloia et al. (2008),
#' with slight adjustments
#' @format A `data.frame` comprising longitudinal data of 500 patients, each having 26 observations over a period of 1 year.
#' Each row represents a patient observation interval (two weeks), with columns:
#' \describe{
Expand All @@ -105,7 +112,8 @@ NULL
#'
#' @note This dataset is only intended for demonstration purposes.
#' While the data format will remain the same, the data content is subject to change in future versions.
#' @source This dataset was generated based on the cluster-specific descriptive statistics table provided in Aloia et al. (2008),
#' @source This dataset was generated based on the cluster-specific descriptive statistics table
#' provided in Aloia et al. (2008),
#' with some adjustments made in order to improve cluster separation for demonstration purposes.
#'
#' \insertRef{aloia2008time}{latrend}
Expand Down Expand Up @@ -134,7 +142,8 @@ NULL
#' @param random Random effects formula.
#' @param cluster Cluster effects formula.
#' @param id Name of the strata.
#' @param data Data with covariates to use for generation. Stratified data may be specified by adding a grouping column.
#' @param data Data with covariates to use for generation. Stratified data may be specified by
#' adding a grouping column.
#' @param clusterNames A `character` vector denoting the names of the generated clusters.
#' @param fixedCoefs Coefficients matrix for the fixed effects.
#' @param clusterCoefs Coefficients matrix for the cluster effects.
Expand Down Expand Up @@ -229,7 +238,10 @@ generateLongData = function(
)
assert_that(ncol(clusterCoefs) == nClus)
Xc = model.matrix(cluster, alldata)
assert_that(ncol(Xc) == nrow(clusterCoefs), msg = 'Missing or too many coefficients specified for cluster effects.')
assert_that(
ncol(Xc) == nrow(clusterCoefs),
msg = 'Missing or too many coefficients specified for cluster effects.'
)
alldata[, Mu.class := rowSums(Xc * t(clusterCoefs)[Class, ])]

## Random effects
Expand Down
31 changes: 22 additions & 9 deletions R/matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
#' @export
#' @name trajectoryAssignments
#' @aliases trajectoryAssignments,matrix-method
#' @details In case `object` is a `matrix`: the posterior probability `matrix`, with the \eqn{k}th column containing the observation- or trajectory-specific probability for cluster \eqn{k}.
#' @param clusterNames Optional `character vector` with the cluster names. If `clusterNames = NULL`, [make.clusterNames()] is used.
setMethod('trajectoryAssignments', 'matrix', function(object, strategy = which.max, clusterNames = colnames(object), ...) {
#' @details In case `object` is a `matrix`: the posterior probability `matrix`,
#' with the \eqn{k}th column containing the observation- or trajectory-specific probability for cluster \eqn{k}.
#' @param clusterNames Optional `character vector` with the cluster names.
#' If `clusterNames = NULL`, [make.clusterNames()] is used.
setMethod('trajectoryAssignments', 'matrix', function(
object,
strategy = which.max,
clusterNames = colnames(object),
...
) {
assert_that(is_valid_postprob(object))

nTraj = nrow(object)
Expand Down Expand Up @@ -48,7 +55,8 @@ setMethod('trajectoryAssignments', 'matrix', function(object, strategy = which.m
#' @param time The time column name.
#' @param response The response column name.
#' @param ids A `vector` specifying the id names. Should match the number of rows of `data`.
#' @param times A `numeric` `vector` specifying the times of the measurements. Should match the number of columns of `data`.
#' @param times A `numeric` `vector` specifying the times of the measurements.
#' Should match the number of columns of `data`.
#' @param as.data.table Whether to return the result as a `data.table`, or a `data.frame` otherwise.
#' @return A `data.table` or `data.frame` containing the repeated measures.
#' @seealso [tsmatrix]
Expand Down Expand Up @@ -97,7 +105,8 @@ tsframe = function(
if (all(!is.finite(times))) {
times = seq_along(times)
warning(
'supplied "times" argument failed to parse to numeric values; falling back to times = seq_along(times) instead.'
'supplied "times" argument failed to parse to numeric values;
falling back to times = seq_along(times) instead.'
)
} else {
stop('some time values are non-finite (possible failed to parse to numeric?)')
Expand All @@ -119,14 +128,17 @@ tsframe = function(
}

#' @rdname tsframe
#' @note The `meltRepeatedMeasures()` function is deprecated and will be removed in a future version, please use `tsframe()` instead.
#' @note The `meltRepeatedMeasures()` function is deprecated and will be removed in a future version,
#' please use `tsframe()` instead.
meltRepeatedMeasures = tsframe

#' @export
#' @title Convert a longitudinal data.frame to a matrix
#' @description Converts a longitudinal `data.frame` comprising trajectories with an equal number of observations, measured at identical moments in time, to a `matrix`. Each row of the matrix represents a trajectory.
#' @description Converts a longitudinal `data.frame` comprising trajectories with an equal number of observations,
#' measured at identical moments in time, to a `matrix`. Each row of the matrix represents a trajectory.
#' @inheritParams tsframe
#' @param fill A `scalar` value. If `FALSE`, an error is thrown when time series observations are missing in the data frame.
#' @param fill A `scalar` value.
#' If `FALSE`, an error is thrown when time series observations are missing in the data frame.
#' Otherwise, the value used for representing missing observations.
#' @return A `matrix` with a trajectory per row.
#' @seealso [tsframe]
Expand Down Expand Up @@ -180,5 +192,6 @@ tsmatrix = function(
}

#' @rdname tsmatrix
#' @note The `dcastRepeatedMeasures()` function is deprecated and will be removed in a future version. Please use `tsmatrix()` instead.
#' @note The `dcastRepeatedMeasures()` function is deprecated and will be removed in a future version.
#' Please use `tsmatrix()` instead.
dcastRepeatedMeasures = tsmatrix
12 changes: 8 additions & 4 deletions R/trajectories.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ setMethod('trajectories', 'call', function(object, ..., envir) {
#' @param cluster The cluster assignment column
#' @param center A function for aggregating multiple points at the same point in time
#' @param trajectories Whether to additionally plot the original trajectories (`TRUE`),
#' or to show the expected interval (standard deviation, standard error, range, or percentile range) of the observations at the respective moment in time.
#' or to show the expected interval (standard deviation, standard error, range, or percentile range)
#' of the observations at the respective moment in time.
#'
#' Note that visualizing the expected intervals is currently only supported for time-aligned trajectories, as the interval is computed at each unique moment in time.
#' Note that visualizing the expected intervals is currently only supported for time-aligned trajectories,
#' as the interval is computed at each unique moment in time.
#' By default (`FALSE`), no information on the underlying trajectories is shown.
#' @param facet Whether to facet by cluster. This is done by default when `trajectories` is enabled.
#' @param id Id column. Only needed when `trajectories = TRUE`.
Expand Down Expand Up @@ -209,7 +211,8 @@ setMethod('plotClusterTrajectories', 'data.frame', function(object,
#' @aliases plotTrajectories,data.frame-method
#' @inheritParams trajectories
#' @param response Response variable `character` name or a `call`.
#' @param cluster Cluster variable name. If unspecified, trajectories are not grouped. Alternatively, cluster is a vector indicating cluster membership per id.
#' @param cluster Cluster variable name. If unspecified, trajectories are not grouped.
#' Alternatively, cluster is a vector indicating cluster membership per id.
#' @param facet Whether to facet by cluster.
#' @seealso [trajectories] [plotFittedTrajectories] [plotClusterTrajectories]
#' @examples
Expand Down Expand Up @@ -269,7 +272,8 @@ setMethod('plotTrajectories', 'data.frame',
response = names(dfNum)[which.max(counts)]
message(
sprintf(
'Automatically selected "%s" as the response variable. To override this, specify the "response" argument.',
'Automatically selected "%s" as the response variable.
To override this, specify the "response" argument.',
response
)
)
Expand Down
9 changes: 6 additions & 3 deletions man/PAP.adh.Rd

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

9 changes: 6 additions & 3 deletions man/PAP.adh1y.Rd

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

3 changes: 2 additions & 1 deletion man/generateLongData.Rd

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

6 changes: 4 additions & 2 deletions man/latrend-data.Rd

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

6 changes: 4 additions & 2 deletions man/plotClusterTrajectories.Rd

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

3 changes: 2 additions & 1 deletion man/plotTrajectories.Rd

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

6 changes: 4 additions & 2 deletions man/trajectoryAssignments.Rd

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

6 changes: 4 additions & 2 deletions man/tsframe.Rd

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

Loading

0 comments on commit 821d65b

Please sign in to comment.