From 8d3b268522632156609b0df6c30b5fe43b1b8dff Mon Sep 17 00:00:00 2001 From: Fonti Kar Date: Wed, 3 Apr 2024 13:17:51 +1100 Subject: [PATCH] Moved unique code back to make_constant.R --- .../fixtures/constant/make_constant.R | 23 +++++++++++++++++++ tests/testthat/helper.R | 22 ------------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/testthat/fixtures/constant/make_constant.R b/tests/testthat/fixtures/constant/make_constant.R index db48e6e..1ffe8cf 100644 --- a/tests/testthat/fixtures/constant/make_constant.R +++ b/tests/testthat/fixtures/constant/make_constant.R @@ -1,3 +1,26 @@ +#Generates data for constant growth model testing +#Differential equation governing dynamics. +DE <- function(y, pars){ + return(pars[1]) +} + +#Normally distributed error +add_error_process <- function(y, sigma_e=0.001){ + return(y + rnorm(length(y), mean=0, sd=sigma_e)) +} + +#Function to generate distribution of DE parameters +DE_par_generation <- function(n_ind, pars=list(mean=0, sd=1)){ + par_sample <- data.frame(beta=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) + return(par_sample) +} + +#Generate initial conditions +initial_condition_generation <- function(n_ind, pars=list(mean=2, sd=1)){ + y_0_sample <- data.frame(y_0=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) + return(y_0_sample) +} + #Set required values model_name <- "constant" n_ind <- 3 #Number of individuals for multi-individual data. Single individual takes the first. diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index d93b4bb..e4399d8 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -1,25 +1,3 @@ -#Generates data for constant growth model testing -#Differential equation governing dynamics. -DE <- function(y, pars){ - return(pars[1]) -} - -#Normally distributed error -add_error_process <- function(y, sigma_e=0.001){ - return(y + rnorm(length(y), mean=0, sd=sigma_e)) -} - -#Function to generate distribution of DE parameters -DE_par_generation <- function(n_ind, pars=list(mean=0, sd=1)){ - par_sample <- data.frame(beta=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) - return(par_sample) -} - -#Generate initial conditions -initial_condition_generation <- function(n_ind, pars=list(mean=2, sd=1)){ - y_0_sample <- data.frame(y_0=exp(rnorm(n_ind, mean = pars[[1]], sd=pars[[2]]))) - return(y_0_sample) -} #General functions for data generation