Skip to content

Commit

Permalink
Moved unique code back to make_constant.R
Browse files Browse the repository at this point in the history
  • Loading branch information
fontikar committed Apr 3, 2024
1 parent ffaab78 commit 8d3b268
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
23 changes: 23 additions & 0 deletions tests/testthat/fixtures/constant/make_constant.R
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
22 changes: 0 additions & 22 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 8d3b268

Please sign in to comment.