| Type: | Package |
| Title: | Reproducible Assessment of Disability Course in Multiple Sclerosis |
| Version: | 1.0.0 |
| Description: | Analyse disability course in multiple sclerosis (MS) from longitudinal data. The package provides a flexible framework for identifying disability events under user-specified criteria, allowing adaptation to different study designs and endpoints. Tools are included to facilitate transparent and reproducible reporting of the settings used in the analysis. For an introduction to the package and illustrative applications, see Montobbio et al. (2024) <doi:10.1177/13524585241243157>. |
| Encoding: | UTF-8 |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| Imports: | stats, dplyr, rlang |
| Depends: | R (≥ 4.1.0) |
| VignetteBuilder: | knitr |
| Suggests: | knitr, rmarkdown, xfun, DT |
| License: | MIT + file LICENSE |
| NeedsCompilation: | no |
| Packaged: | 2026-06-18 13:56:40 UTC; nmontobbio |
| Author: | Noemi Montobbio |
| Maintainer: | Noemi Montobbio <noemi.montobbio@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-06-23 16:00:02 UTC |
Assess multiple sclerosis disability course from longitudinal data.
Description
Detect and characterise confirmed disability worsening (CDW) or improvement (CDI) events of an outcome measure (EDSS, NHPT, T25FW, or SDMT; or any custom outcome) based on repeated assessments through time (and on the dates of acute episodes, if any). The events are detected sequentially by scanning the outcome values in chronological order. Several qualitative and quantitative options are given as arguments that can be set by the user and reported as a complement to the results to ensure reproducibility.
Usage
MSprog(
data,
subj_col,
value_col,
date_col,
outcome,
relapse = NULL,
rsubj_col = NULL,
rdate_col = NULL,
renddate_col = NULL,
subjects = NULL,
delta_fun = NULL,
worsening = NULL,
event = c("firstCDW", "firstCDI", "multiple", "firstPIRA", "firstRAW", "first"),
RAW_PIRA = FALSE,
baseline = c("fixed", "roving", "roving_impr", "roving_wors"),
proceed_from = c("firstconf", "event"),
sub_threshold_rebl = c("none", "change", "improvement", "worsening"),
bl_geq = FALSE,
relapse_rebl = FALSE,
skip_local_extrema = c("none", "strict", "all"),
validconf_col = NULL,
conf_days = 12 * 7,
conf_tol_days = c(7, 2 * 365.25),
require_sust_days = 0,
check_intermediate = TRUE,
relapse_to_bl = 30,
relapse_to_event = 0,
relapse_to_conf = 30,
relapse_assoc = 90,
relapse_indep = NULL,
impute_last_visit = 0,
date_format = NULL,
include_dates = FALSE,
include_values = FALSE,
include_stable = TRUE,
verbose = 1
)
Arguments
data |
Data frame containing longitudinal data, including: subject IDs, outcome values, visit dates. |
subj_col |
Name of data column with subject IDs. |
value_col |
Name of data column with outcome values. |
date_col |
Name of data column with visit dates. |
outcome |
Specifies the outcome type. Must be one of the following:
When it's not set to |
relapse |
Optional data frame containing longitudinal data, including subject IDs and relapse onset dates. |
rsubj_col |
Name of subject ID column in the |
rdate_col |
Name of relapse onset date column in the |
renddate_col |
Name of relapse end date column in the |
subjects |
Subset of subjects (a vector or list of IDs). If none is specified, all subjects listed in |
delta_fun |
Custom function specifying the minimum clinically meaningful
change in the outcome measure from the provided reference value.
The function provided must take a numeric value (reference score) as input,
and return a numeric value corresponding to the minimum shift from baseline, see example below.
If |
worsening |
The direction of worsening ( The given value is only used when |
event |
Character string specifying which events to detect. Must be one of the following.
|
RAW_PIRA |
If |
baseline |
Specifies the baseline scheme. Must be one of the following.
|
proceed_from |
After detecting a confirmed disability event, continue searching:
If
|
sub_threshold_rebl |
This argument is only used if
See |
bl_geq |
This argument is only used if relapse-based re-baseline is enabled ( |
relapse_rebl |
If |
skip_local_extrema |
This argument is only used if the baseline is moved. It controls re-baseline behaviour in the presence of local minima or maxima. A visit
Local maxima are defined similarly. A visit
Strict local maxima are defined similarly. When
|
validconf_col |
Name of data column, if any, specifying which visits can
( |
conf_days |
Period before confirmation (days). Can be a single value, or
vector of any length if considering multiple windows.
If |
conf_tol_days |
Tolerance window for confirmation visit (days).
Can be an integer (equal lower and upper tolerance)
or vector of length 2 (different lower and upper tolerance).
The right end of the interval (upper tolerance) may be set to |
require_sust_days |
Minimum number of days over which a confirmed change must be sustained
(i.e., confirmed at all visits occurring in the specified period) to be retained as an event.
Events sustained for the remainder of the follow-up period are always retained regardless of follow-up duration.
If (Warning: if |
check_intermediate |
If If set to |
relapse_to_bl |
Minimum distance (days) from the onset of a relapse for a visit to be used as baseline. Can be an integer (minimum distance from last relapse onset) or vector of length 2 (minimum distance from last relapse onset, minimum distance from next relapse onset). Note that setting the distance to zero means keeping the baseline where it is regardless of surrounding relapses. If relapse end dates are available ( If the designated baseline does not satisfy this constraint, the baseline is moved to the next available visit. |
relapse_to_event |
Minimum distance (days) from the onset of a relapse for an event to be considered as such. Can be an integer (minimum distance from last relapse onset) or vector of length 2 (minimum distance from last relapse onset, minimum distance from next relapse onset). Note that setting the distance to zero means retaining the event regardless of surrounding relapses. If relapse end dates are available ( |
relapse_to_conf |
Minimum distance (days) from the onset of a relapse for a visit to be an eligible confirmation visit. Can be an integer (minimum distance from last relapse onset) or vector of length 2 (minimum distance from last relapse onset, minimum distance from next relapse onset). Note that setting the distance to zero means using any visit for confirmation regardless of surrounding relapses. If relapse end dates are available ( |
relapse_assoc |
Maximum distance (days) from the onset of a relapse for a CDW event to be classified as RAW.
Can be an integer (maximum distance from last relapse onset) or vector of length 2
(maximum distance from last relapse onset, maximum distance from next relapse onset).
If relapse end dates are available ( |
relapse_indep |
Specifies relapse-free intervals for PIRA definition.
Must be a named list
The auxiliary function |
impute_last_visit |
Imputation probability for worsening events occurring
at the last available visit (i.e., with no confirmation).
Unconfirmed worsening events occurring at the last visit are never imputed if |
date_format |
Format of dates in the
If not specified, function |
include_dates |
If
|
include_values |
If
|
include_stable |
If |
verbose |
One of:
|
Value
An object of class MSprogOutput with the following attributes:
event_count: a data frame containing event counts for each subject (and the event sequence in case of multiple events).results: a data frame with extended info on each event for all subjects.settings: a list containing all the arguments used to compute the output.unconfirmed: a data frame with info on unconfirmed events (initial change from baseline, but no confirmation) for all subjects.
For a detailed description of output data frames, see ?MSprogOutput.
References
[1] Müller J, Cagol A, Lorscheider J, Tsagkas C, Benkert P, Yaldizli Ö, et al.
Harmonizing definitions for progression independent of relapse activity in multiple sclerosis: A systematic review.
JAMA Neurol. 2023;80:1232–45.
[2] Kappos L, Wolinsky JS, Giovannoni G, Arnold DL, Wang Q, Bernasconi C, et al.
Contribution of relapse-independent progression vs relapse-associated worsening to overall confirmed disability
accumulation in typical relapsing multiple sclerosis in a pooled analysis of 2 randomized clinical trials.
JAMA Neurol. 2020;77:1132–40.
Examples
# 1. EDSS course
output <- MSprog(toydata_visits, subj_col="id", value_col="EDSS", date_col="date", outcome="edss",
relapse=toydata_relapses, conf_days=12*7, conf_tol_days=30,
event="multiple", baseline="roving", verbose=1)
print(output$results) # extended info on each event for all subjects
print(output$event_count) # event counts for each subject
# 2. SDMT course
output <- MSprog(toydata_visits, subj_col="id", value_col="SDMT", date_col="date", outcome="sdmt",
relapse=toydata_relapses, conf_days=12*7, conf_tol_days=30,
event="multiple", baseline="roving", verbose=1)
print(output$results) # extended info on each event for all subjects
print(output$event_count) # event counts for each subject
# 3. SDMT course, with a custom delta function
my_sdmt_delta <- function(reference_value) {min(c(reference_value/10, 3))}
output <- MSprog(toydata_visits, subj_col="id", value_col="SDMT", date_col="date", outcome="sdmt",
delta_fun=my_sdmt_delta,
relapse=toydata_relapses, conf_days=12*7, conf_tol_days=30,
event="multiple", baseline="roving", verbose=1)
print(output$results) # extended info on each event for all subjects
print(output$event_count) # event counts for each subject
Objects of class "MSprogOutput"
Description
Objects of class "MSprogOutput" are returned by MSprog(). They contain
the results of event detection and associated metadata.
Structure
Objects of class "MSprogOutput" are lists with the following elements:
event_countA data frame containing event counts for each subject (and the event sequence in case of multiple events).
resultsA data frame with extended info on each event for all subjects.
settingsA list containing all the arguments used to compute the output.
unconfirmedA data frame with info on unconfirmed events (initial change from baseline, but no confirmation) for all subjects.
event_count data frame
- event_sequence
Sequence of detected events (if any), in chronological order (only displayed in multiple-event setting).
- CDI
Count of confirmed disability improvement (CDI) events.
- CDW
Count of confirmed disability worsening (CDW) events.
- RAW
Count of relapse-associated worsening (RAW) events.
- PIRA
Count of progression independent of relapse activity (PIRA) events.
Note: depending on computation settings, some of the above columns may not be
included in the data frame (e.g., no CDI column if event='firstCDW' in MSprog()).
results data frame
<subj_col>Subject ID.
- nevent
Cumulative count of events for the subject.
- event_type
Type of event (CDI or CDW).
- CDW_type
Type of CDW (PIRA, RAW, undefined).
- total_fu
Total length of follow-up period in days.
- time2event
Number of days from start of follow-up to event onset.
- bl2event
Number of days from baseline to event onset.
- date
Date of event onset.
- value
Outcome value at event onset.
- bl_date
Date of baseline for the event.
- bl_value
Outcome value at baseline.
- last_delta_date
Date of last visit before event onset at a clinically meaningful score distance from it.
- last_delta_value
Last outcome value before event onset at a clinically meaningful score distance from it.
- conf
<conf_days>_date Date of
<conf_days>-day confirmation visit for the event.- conf
<conf_days>_value Outcome value at
<conf_days>-day confirmation visit.- PIRA_conf
<conf_days>_date When relevant, date of
<conf_days>-day confirmation visit for PIRA (could be different from CDW confirmation visit if the PIRA definition includes confirmation-related constraints on relapses).- PIRA_conf
<conf_days>_value When relevant, outcome value at
<conf_days>-day confirmation visit for PIRA (could be different from CDW confirmation visit if the PIRA definition includes confirmation-related constraints on relapses).- sust_days
Number of days for which the event was sustained.
- sust_last
Whether the event was sustained up to the end of follow-up.
Note: some of the columns may not be included, depending on computation settings
(e.g., no date columns if include_dates=F in MSprog()).
unconfirmed data frame
<subj_col>Subject ID.
- date
Date of initial outcome change.
- value
Outcome value at initial outcome change.
- bl_date
Date of baseline.
- bl_value
Outcome value at baseline.
- closest_rel_before
Distance in days from the last relapse before the outcome change (if any).
- closest_rel_after
Distance in days from the next relapse after the outcome change (if any).
Note: in first-event scenarios (e.g., event='firstCDW'), the event search stops as soon as
the first confirmed event is found – in this case, the unconfirmed data frame only reports
unconfirmed outcome changes occurring before detecting a confirmed event.
Default minimum clinically meaningful shift for different scales.
Description
Compute the minimum clinically meaningful score change as a function of the reference value for some widely used scales (EDSS, NHPT, T25FW, or SDMT), according to the most established rule for each of these outcomes.
Usage
compute_delta(baseline, outcome = "edss")
Arguments
baseline |
Outcome value at baseline. |
outcome |
One of:
|
Details
Default thresholds are meant to apply to all versions of each test (e.g., dominant or non-dominant hand for NHPT, best time or mean of two trials, etc.).
Value
Minimum clinically meaningful change from the provided baseline value. Specifically:
EDSS: 1.5 if
baseline=0, 1 if 0<baseline<=5.0, 0.5 ifbaseline>5.0NHPT and T25FW: 20
%ofbaselineSDMT: either 4 points or 20
%ofbaseline.
Examples
compute_delta(4.5) # default outcome is "edss"
compute_delta(55, outcome="sdmt")
Compare value to reference.
Description
Check if an outcome value determines a valid worsening, or improvement, or change, from a given reference value.
Usage
is_event(
x,
baseline,
type,
outcome = "edss",
worsening = NULL,
delta_fun = NULL,
sub_threshold = FALSE
)
Arguments
x |
Outcome value to test. |
baseline |
Outcome value at baseline. |
type |
One of:
|
outcome |
One of:
Outcome type determines the direction of worsening (see |
worsening |
The direction of worsening ( |
delta_fun |
Custom function specifying the minimum clinically meaningful
change in the outcome measure from the provided reference value.
The function provided must take a numeric value (reference score) as input,
and return a numeric value corresponding to the minimum relevant shift from baseline, see example below.
If |
sub_threshold |
If |
Value
A boolean value specifying if a valid event was found.
Examples
is_event(x=4.5, baseline=4, type="wors", outcome="edss")
is_event(x=50, baseline=57, type="wors", outcome="sdmt")
is_event(x=3, baseline=3.5, type="impr", outcome="edss", sub_threshold=TRUE)
Textual description of criteria used to assess disability course.
Description
print method for class "MSprogOutput".
Usage
## S3 method for class 'MSprogOutput'
print(x, ...)
Arguments
x |
An object of class |
... |
Optional arguments for |
Details
The method prints out (1) the package version, (2) a full list of function arguments, and (3) a short paragraph describing the full set of criteria used to obtain the output.
Value
Invisibly returns x.
Examples
output <- MSprog(toydata_visits, "id", "EDSS", "date", "edss",
relapse=toydata_relapses, conf_days=7*12, conf_tol_days=30,
event="multiple", baseline="roving", verbose=2)
print(output) # textual description of parameters used to obtain output
Define relapse-free intervals for PIRA definition.
Description
Organise the given interval bounds into a named list to be given as argument
relapse_indep to function MSprog().
The relapse-free intervals may be anchored to (any subset of) the following
three data-driven checkpoints.
"prec": a visit preceding the event: can be (i) the current baseline, (ii) the last visit before event onset, or (iii) the last visit before event onset with a clinically meaningful score difference from it (i.e., for an outcomexwith "higher score" = "worse", the last visitisuch thatx[event] - x[i] >= delta_fun(x[i]), and same for the confirmation visit)."event": the disability worsening event onset."conf": an eligible confirmation visit.
Usage
relapse_indep_from_bounds(
p0 = 0,
p1 = 0,
e0 = 0,
e1 = 0,
c0 = 0,
c1 = 0,
prec_type = "baseline",
use_end_dates = F
)
Arguments
p0 |
Days before preceding visit ( |
p1 |
Days after preceding visit ( |
e0 |
Days before event onset ( |
e1 |
Days after event onset ( |
c0 |
Days before confirmation ( |
c1 |
Days after confirmation ( |
prec_type |
Which visit to use as "preceding visit". Must be one of:
|
use_end_dates |
If |
Details
If both ends of an interval are 0 (e.g., if both p0=0 and p1=0), the checkpoint is ignored.
To merge two intervals together, set both the right end of the first interval and the left end of the
second interval to NULL (e.g., "between baseline and event onset": p1=NULL and e0=NULL).
Here are some examples:
No relapses from 90dd before to 30dd after the event, and from 90dd before to 30dd after confirmation [1]:
relapse_indep_from_bounds(e0=90,e1=30,c0=90,c1=30).No relapses between baseline and confirmation (high-specificity definition from [1]):
relapse_indep_from_bounds(p0=0,p1=NULL,e0=NULL,e1=NULL,c0=NULL,c1=0).No relapses from baseline to 30dd after the event, and within confirmation+-30dd [2]:
relapse_indep_from_bounds(p0=0,p1=NULL,e0=NULL,e1=30,c0=30,c1=30).
Value
A named list to be given as argument relapse_indep to function MSprog().
References
[1] Müller J, Cagol A, Lorscheider J, Tsagkas C, Benkert P, Yaldizli Ö, et al.
Harmonizing definitions for progression independent of relapse activity in multiple sclerosis: A systematic review.
JAMA Neurol. 2023;80:1232–45.
[2] Kappos L, Wolinsky JS, Giovannoni G, Arnold DL, Wang Q, Bernasconi C, et al.
Contribution of relapse-independent progression vs relapse-associated worsening to overall confirmed disability
accumulation in typical relapsing multiple sclerosis in a pooled analysis of 2 randomized clinical trials.
JAMA Neurol. 2020;77:1132–40.
Synthetic Relapse Data
Description
Artificially generated relapse onset dates for some example patients in toydata_visits to illustrate the use of the package.
Usage
data(toydata_relapses)
Format
An object of class data.frame, with columns:
- id
Subject IDs.
- date
Relapse onset dates.
References
This data set was artificially created for the msprog package.
Examples
data(toydata_relapses)
head(toydata_relapses)
Synthetic Longitudinal EDSS and SDMT Data
Description
Artificially generated toy data set including Extended Disability Status Scale (EDSS) and Symbol Digit Modalities Test (SDMT) scores in a small cohort of example patients to illustrate the use of the package.
Usage
data(toydata_visits)
Format
An object of class data.frame, with columns:
- id
Subject IDs.
- date
Visit dates.
- EDSS
Synthetic EDSS scores (values between 0 and 10).
- SDMT
Synthetic SDMT scores (values between 0 and 110).
References
This data set was artificially created for the msprog package.
Examples
head(toydata_visits)
Time to disability milestone.
Description
Scan the visits in chronological order to detect the first outcome value reaching or exceeding a specified disability milestone (e.g., EDSS>=6), with confirmation.
Usage
value_milestone(
data,
milestone,
subj_col,
value_col,
date_col,
outcome,
worsening = NULL,
relapse = NULL,
rsubj_col = NULL,
rdate_col = NULL,
validconf_col = NULL,
conf_days = 12 * 7,
conf_tol_days = c(7, 2 * 365.25),
require_sust_days = 0,
relapse_to_event = 0,
relapse_to_conf = 30,
impute_last_visit = 0,
date_format = NULL,
verbose = 0
)
Arguments
data |
Data frame containing longitudinal data, including: subject IDs, outcome values, visit dates. |
milestone |
Disability milestone (outcome value to check data against). |
subj_col |
Name of data column with subject IDs. |
value_col |
Name of data column with outcome values. |
date_col |
Name of data column with visit dates. |
outcome |
Specifies the outcome type. Must be one of the following:
When it's not set to |
worsening |
The direction of worsening ( |
relapse |
Optional data frame containing longitudinal data, including subject IDs and relapse onset dates. |
rsubj_col |
Name of subject ID column in the |
rdate_col |
Name of date column in the |
validconf_col |
Name of data column, if any, specifying which visits can
( |
conf_days |
Period before confirmation (days). Can be a single value, or
vector of any length if considering multiple windows.
If |
conf_tol_days |
Tolerance window for confirmation visit (days); can be
an integer (equal lower and upper tolerance)
or vector of length 2 (different lower and upper tolerance).
The right end of the interval can be set to |
require_sust_days |
Minimum number of days over which the milestone must be sustained
(i.e., confirmed at all visits occurring in the specified period).
If the milestone is sustained for the remainder of the follow-up period, it is considered reached regardless of follow-up duration.
If |
relapse_to_event |
Minimum distance (days) from the onset of a relapse for the milestone to be considered reached. Can be an integer (minimum distance from last relapse onset) or vector of length 2 (minimum distance from last relapse onset, minimum distance from next relapse onset). Note that setting the distance to zero means retaining the event regardless of surrounding relapses. |
relapse_to_conf |
Minimum distance (days) from the onset of a relapse for a visit to be a valid confirmation visit. Can be an integer (minimum distance from last relapse onset) or vector of length 2 (minimum distance from last relapse onset, minimum distance from next relapse onset). Note that setting the distance to zero means using any visit for confirmation regardless of surrounding relapses. |
impute_last_visit |
Imputation probability when the milestone is reached
at the last available visit (i.e., with no confirmation).
Unconfirmed values exceeding the milestone at the last visit are never imputed
if |
date_format |
Format of dates in the
If not specified, function |
verbose |
One of:
|
Details
"Reaching or exceeding" means either value>=milestone or value<=milestone, depending on the direction of worsening (see arguments
outcomeandworsening).An event is only considered "observed" if confirmed, i.e., if all values up to the confirmation visit reach or exceed the milestone.
Value
A data frame containing the following columns:
-
<date_col>: the date of first reaching or exceeding the milestone with confirmation (or last date of follow-up if milestone is not reached or not confirmed). -
<value_col: the first value reaching or exceeding the milestone with confirmation, if present, otherwise no value. -
"time2event": the time taken to reach or exceed the milestone (or total follow-up length if milestone is not reached or not confirmed). -
"observed": whether the milestone was reached with confirmation (1) or not (0).