-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finalised the testing structure for models with single and multiple individuals, using the constant growth model as the test case. - Generating a dataset to be loaded with the model in the fixtures. - Running the chosen model on the first individual in the simulated data and test that the parameter estimate converges to a reasonable value (with 0.1 of the true value) - Running the chosen model on multiple individuals and tests whether the output samples are of the right size for the number of chains, iterations, and parameters. * Notation (#5) * Updated notation and function structure in the multi individual constant model file for consistency. Updated rmot_run, rmot_models to reflect the changes. * Removed old constant stan file and cleared out references to it in stanmodels.R, rmot.rmd. * Updated ignore to exclude compiled binaries. * Cleared out .o and .so files. * Added develop branch as a trigger for PR --------- Co-authored-by: Fonti Kar <[email protected]> * Added single ind const model, updated rmot_models, rmot_run, rmot vignette. Need to do test files yet. * Updated the single individual constant model stan file and the testing code. * Added some comments to the model testing script. * Expending tests: testing run * Reorganise if statements * Rename file to linear * Added unit testing of model output for linear data. * Re-added testing structure. * Found problem with unit testing for const model outputs: object y_single/y_multi in global environment not being seen within rmot_assign_data function. * Added internal testing data so no data is created within test_that() functions, y_single and y_multi are not evaluated globally #1 * Added internal testing data so no data is created within test_that() functions, y_single and y_multi are not evaluated globally #1 * Skip snapshots on CI * Updated snaps * Removed snaps as a testing framework and using expect_equal #1 * Removed skip_on_ci #1 * Updating roxygen version and package doc * Updated code to generate testing data * Moved helper code in generating fake data, removed internal testing data * Updated rmot_assign and tests passing I think * Completed testing workflow * Added filepath to saving rds and updated TO DO in assign_data * Set tolerance * Updated version for checkout * Added constant data generation and tests based on model output summary for single and multiple individuals. Tests all complete dynamically and when run in the testing console. * Init comit for constant branch * Tess helper funcs * Regenerate test data using stan seed method * using rstan::extract instead of summary * Added constant as trigger * Moved unique code back to make_constant.R * Changed test data generation and single- and multi-individual testing structures for constant model. * Fixed linear regression model testing. * Resolving issues raised in pull request review: changed the set-up of the constant model and removed reference to the constant branch from R-CMD-checn.yaml. --------- Co-authored-by: Fonti Kar <[email protected]> Co-authored-by: Daniel Falster <[email protected]>
- Loading branch information
1 parent
467c95e
commit 9365267
Showing
32 changed files
with
1,555 additions
and
418 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 |
---|---|---|
|
@@ -6,3 +6,6 @@ | |
^LICENSE\.md$ | ||
^\.github$ | ||
^codecov\.yml$ | ||
^data-raw$ | ||
^tests/testthat/_snaps/$ | ||
|
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
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,96 @@ | ||
//Constant DE - Single species | ||
functions{ | ||
//DE function | ||
real DE(real beta){ | ||
return beta; | ||
} | ||
|
||
real size_step(real y, real beta, real time){ | ||
return y + DE(beta) * time; | ||
} | ||
} | ||
|
||
// Data structure | ||
data { | ||
int n_obs; | ||
int n_ind; | ||
real y_obs[n_obs]; | ||
int obs_index[n_obs]; | ||
real time[n_obs]; | ||
int ind_id[n_obs]; | ||
real y_0_obs[n_ind]; | ||
} | ||
|
||
// The parameters accepted by the model. | ||
parameters { | ||
//Individual level | ||
real<lower=0> ind_y_0[n_ind]; | ||
real<lower=0> ind_beta[n_ind]; | ||
|
||
real species_beta_mu; | ||
real<lower=0> species_beta_sigma; | ||
|
||
//Global level | ||
real<lower=0> global_error_sigma; | ||
} | ||
|
||
// The model to be estimated. | ||
model { | ||
real y_hat[n_obs]; | ||
|
||
for(i in 1:n_obs){ | ||
//Fits the first size | ||
if(obs_index[i]==1){ | ||
y_hat[i] = ind_y_0[ind_id[i]]; | ||
} | ||
|
||
// Estimate next size | ||
if(i < n_obs){ | ||
if(ind_id[i+1]==ind_id[i]){ | ||
y_hat[i+1] = size_step(y_hat[i], ind_beta[ind_id[i]], (time[i+1]-time[i])); | ||
} | ||
} | ||
} | ||
|
||
//Likelihood | ||
y_obs ~ normal(y_hat, global_error_sigma); | ||
|
||
//Priors | ||
//Individual level | ||
ind_y_0 ~ normal(y_0_obs, global_error_sigma); | ||
ind_beta ~ lognormal(species_beta_mu, | ||
species_beta_sigma); | ||
|
||
//Species level | ||
species_beta_mu ~ normal(0.1, 1); | ||
species_beta_sigma ~cauchy(0.1, 1); | ||
|
||
//Global level | ||
global_error_sigma ~cauchy(0.1, 1); | ||
} | ||
|
||
// The output | ||
generated quantities { | ||
real y_hat[n_obs]; | ||
real Delta_hat[n_obs]; | ||
|
||
for(i in 1:n_obs){ | ||
|
||
//Fits the first size | ||
if(obs_index[i]==1){ | ||
y_hat[i] = ind_y_0[ind_id[i]]; | ||
} | ||
|
||
// Estimate next size | ||
if(i < n_obs){ | ||
if(ind_id[i+1]==ind_id[i]){ | ||
y_hat[i+1] = size_step(y_hat[i], ind_beta[ind_id[i]], (time[i+1]-time[i])); | ||
Delta_hat[i] = y_hat[i+1] - y_hat[i]; | ||
} else { | ||
Delta_hat[i] = DE(ind_beta[ind_id[i]]) * (time[i]-time[i-1]); | ||
} | ||
} else { | ||
Delta_hat[i] = DE(ind_beta[ind_id[i]]) * (time[i]-time[i-1]); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.