Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factored the stan code for longitudinal generated quantities #289

Merged
merged 7 commits into from
Mar 25, 2024

Conversation

gowerc
Copy link
Collaborator

@gowerc gowerc commented Mar 22, 2024

Addresses part 1 of #288

In this PR I factor out the looping code into the base longitudinal model stan file. This means each individual model doesn't have to concern itself about how patients are subset meaning less chance of issues in the future when we update this mechanism.

We then introduce a new interface that the longitudinal models have to conform to which is that they must create a function with signature:

row_vector lm_predict_individual_patient(vector time, row_vector long_gq_parameters)

They also must define a matrix long_gq_parameters which has 1 row per patient and as many columns as required for the model in question. As an example for the SF model this is defined as:

    matrix[Nind, 3] long_gq_parameters;
    long_gq_parameters[, 1] = lm_gsf_psi_bsld;
    long_gq_parameters[, 2] = lm_gsf_psi_ks;
    long_gq_parameters[, 3] = lm_gsf_psi_kg;

I also added a new unit test to show that patient subsetting works as expected and that the correct values are reconstructed per each sample per patient.

@gowerc gowerc marked this pull request as ready for review March 22, 2024 16:14
Copy link
Contributor

github-actions bot commented Mar 22, 2024

Unit Tests Summary

  1 files   40 suites   5m 30s ⏱️
121 tests  90 ✅ 31 💤 0 ❌
850 runs  819 ✅ 31 💤 0 ❌

Results for commit f5a0403.

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Mar 22, 2024

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
LongitudinalQuantiles 💚 $44.63$ $-2.71$ $+1$ $0$ $0$ $0$
SurvivalLoglogistic 💚 $30.77$ $-1.25$ $0$ $0$ $0$ $0$
compile 💚 $16.20$ $-2.40$ $0$ $0$ $0$ $0$
stan_functions 💚 $50.10$ $-2.92$ $0$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
LongitudinalQuantiles 👶 $+0.92$ LongitudinalQuantities_correctly_subsets_patients_and_rebuilds_correct_value_for_each_sample
LongitudinalQuantiles 💚 $37.26$ $-3.73$ Test_that_LongitudinalQuantities_works_as_expected
SurvivalLoglogistic 💚 $30.59$ $-1.24$ SurvivalLogLogistic_can_recover_known_values
compile 💚 $16.20$ $-2.40$ compileStanModel_doesn_t_error_if_the_directory_doesn_t_exist
stan_functions 💚 $17.79$ $-2.52$ GSF_SLD_function_works_as_expected

Results for commit 835c5b9

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Mar 22, 2024

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  --------------------------------
R/brier_score.R                     166       0  100.00%
R/DataJoint.R                        76       2  97.37%   264, 270
R/DataLongitudinal.R                119       1  99.16%   245
R/DataSubject.R                      69       1  98.55%   124
R/DataSurvival.R                     77       0  100.00%
R/defaults.R                         10       6  40.00%   18-57, 84
R/generics.R                         23       1  95.65%   49
R/JointModel.R                      122       8  93.44%   142-144, 194, 198, 240, 286, 292
R/JointModelSamples.R                55       0  100.00%
R/Link.R                             55       4  92.73%   159-162
R/LinkComponent.R                    47       5  89.36%   100, 118, 132-149
R/LongitudinalGSF.R                  64       0  100.00%
R/LongitudinalModel.R                37      12  67.57%   71-86
R/LongitudinalQuantities.R           85       0  100.00%
R/LongitudinalRandomSlope.R          27       0  100.00%
R/LongitudinalSteinFojo.R            57       8  85.96%   113-135
R/Parameter.R                        14       0  100.00%
R/ParameterList.R                    42       1  97.62%   184
R/Prior.R                           236       8  96.61%   480, 576, 588-606
R/Quantities.R                      105       0  100.00%
R/settings.R                         12      12  0.00%    55-69
R/SimGroup.R                          5       0  100.00%
R/SimJointData.R                     72       1  98.61%   103
R/SimLongitudinal.R                   5       2  60.00%   22, 40
R/SimLongitudinalGSF.R               51       0  100.00%
R/SimLongitudinalRandomSlope.R       42       0  100.00%
R/SimLongitudinalSteinFojo.R         48       0  100.00%
R/SimSurvival.R                     104       0  100.00%
R/StanModel.R                        15       0  100.00%
R/StanModule.R                      179       6  96.65%   199-200, 242, 253, 390, 418
R/SurvivalExponential.R              10       0  100.00%
R/SurvivalLoglogistic.R              11       0  100.00%
R/SurvivalModel.R                    19       0  100.00%
R/SurvivalQuantities.R              155       6  96.13%   178-183
R/SurvivalWeibullPH.R                11       0  100.00%
R/utilities.R                       145       1  99.31%   13
R/zzz.R                               2       2  0.00%    3-12
TOTAL                              2372      87  96.33%

Diff against main

Filename                      Stmts    Miss  Cover
--------------------------  -------  ------  -------
R/LongitudinalModel.R            +2       0  +1.85%
R/LongitudinalQuantities.R        0      -8  +9.41%
R/StanModule.R                   +2       0  +0.04%
TOTAL                            +4      -8  +0.34%

Results for commit: f5a0403

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

R/LongitudinalModel.R Outdated Show resolved Hide resolved
tests/testthat/test-LongitudinalQuantiles.R Outdated Show resolved Hide resolved
@gowerc gowerc merged commit 1db0fc4 into main Mar 25, 2024
19 checks passed
@gowerc gowerc deleted the feature/harmonise_long_gq branch March 25, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants