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

Changed extract_estimates argument order so the output from run() can… #53

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/hmde_extract_estimates.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' Extract samples and return measurement, individual, and population-level estimates
#'
#' @param model model name character string
#' @param fit fitted model Stan fit
#' @param input_measurement_data data used to fit the model with ind_id, y_obs, time, obs_index tibble
#'
Expand All @@ -9,8 +8,7 @@
#' @import dplyr
#' @importFrom stats quantile

hmde_extract_estimates <- function(model = NULL,
fit = NULL,
hmde_extract_estimates <- function(fit = NULL,
input_measurement_data = NULL){
#Check for fit
if(is.null(fit)){
Expand All @@ -21,9 +19,11 @@ hmde_extract_estimates <- function(model = NULL,
stop("Fit not S4 stanfit type.")
}

model <- fit@model_name
#Check for model
if(!model %in% hmde_model_names()){
stop("Model name not recognised. Run hmde_model_names() to see available models.")
stop(paste0("Model name not recognised: ", model,
" Run hmde_model_names() to see available models."))
}

#Check for input measurement data
Expand All @@ -33,7 +33,7 @@ hmde_extract_estimates <- function(model = NULL,
}
}

estimate_list <- list()
estimate_list <- list(model_name = model)
par_names <- hmde_model_pars(model)

if(grepl("multi", model)){ #Get n_ind for multi-individual
Expand Down
4 changes: 2 additions & 2 deletions inst/stan/affine_single_ind.stan
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ data {
real time[n_obs];
real y_bar;
int int_method;
real prior_means[2]; #vector of means for beta parameter priors
real prior_sds[2]; #Vector of SDs for beta parameter priors
real prior_means[2]; //vector of means for beta parameter priors
real prior_sds[2]; //Vector of SDs for beta parameter priors
}

// The parameters accepted by the model.
Expand Down
4 changes: 1 addition & 3 deletions man/hmde_extract_estimates.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions tests/testthat/test-hmde_extract_estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ test_that("Execution and output: extract_estimates function", {
)

suppressWarnings(
constant_single_fit <- hmde_model("constant_single_ind") |>
output <- hmde_model("constant_single_ind") |>
hmde_assign_data(data = data) |>
hmde_run(chains = 1, iter = 20, cores = 1,
verbose = FALSE, show_messages = FALSE)
verbose = FALSE, show_messages = FALSE) |>
hmde_extract_estimates(input_measurement_data = data)
)

output <- hmde_extract_estimates(model = "constant_single_ind",
fit = constant_single_fit,
input_measurement_data = data)

expect_named(output)

expect_visible(output)
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-hmde_plot_de_pieces.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ test_that("Execution and output: plot_de_pieces function", {
verbose = FALSE, show_messages = FALSE)
)

output <- hmde_extract_estimates(model = "constant_multi_ind",
fit = multi_ind_trout,
output <- hmde_extract_estimates(fit = multi_ind_trout,
input_measurement_data = Trout_Size_Data)

plot <- hmde_plot_de_pieces(model = "constant_multi_ind",
Expand All @@ -33,8 +32,7 @@ test_that("Execution and output: bad input", {
verbose = FALSE, show_messages = FALSE)
)

output <- hmde_extract_estimates(model = "constant_multi_ind",
fit = multi_ind_trout,
output <- hmde_extract_estimates(fit = multi_ind_trout,
input_measurement_data = Trout_Size_Data)

expect_error(
Expand Down
3 changes: 1 addition & 2 deletions vignettes/canham.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ tree_canham_fit <- hmde_model("canham_multi_ind") |>
hmde_assign_data(data = Tree_Size_Data) |>
hmde_run(chains = 4, cores = 4, iter = 2000)

tree_canham_estimates <- hmde_extract_estimates(model = "canham_multi_ind",
fit = tree_canham_fit,
tree_canham_estimates <- hmde_extract_estimates(fit = tree_canham_fit,
input_measurement_data = Tree_Size_Data)

#saveRDS(tree_canham_fit, "tree_canham_fit.rds")
Expand Down
2 changes: 1 addition & 1 deletion vignettes/constant-growth.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ trout_constant_fit <- hmde_model("constant_multi_ind") |>
Once the model has finished running, we can extract the model estimates and have a look at the distribution of estimated sizes, estimated growth increments, and annualised growth rates at the level of sizes over time.

```{r}
trout_constant_estimates <- hmde_extract_estimates(model = "constant_multi_ind",
trout_constant_estimates <- hmde_extract_estimates(
fit = trout_constant_fit,
input_measurement_data = Trout_Size_Data)
```
Expand Down
3 changes: 1 addition & 2 deletions vignettes/here_be_dragons.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ for(i in 1:runs){
)

#Extract parameter estimates
ests <- hmde_extract_estimates(model = "affine_single_ind",
fit = fit,
ests <- hmde_extract_estimates(fit = fit,
input_measurement_data = obs_data_frame)

temp <- tibble(
Expand Down
3 changes: 1 addition & 2 deletions vignettes/hmde_for_mathematicians.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ canham_multi_ind_fit <- hmde_model("canham_multi_ind") |>
hmde_assign_data(data = Tree_Size_Data) |>
hmde_run(chains = 1, cores = 1, iter = 1000)

Tree_Size_Ests <- hmde_extract_estimates(model = "canham_multi_ind",
fit = canham_multi_ind_fit,
Tree_Size_Ests <- hmde_extract_estimates(fit = canham_multi_ind_fit,
input_measurement_data = Tree_Size_Data)
```

Expand Down
3 changes: 1 addition & 2 deletions vignettes/von-bertalanffy.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ lizard_vb_fit <- hmde_model("vb_multi_ind") |>
hmde_assign_data(data = Lizard_Size_Data) |>
hmde_run(chains = 4, cores = 1, iter = 2000)

lizard_estimates <- hmde_extract_estimates(model = "vb_multi_ind",
fit = lizard_vb_fit,
lizard_estimates <- hmde_extract_estimates(fit = lizard_vb_fit,
input_measurement_data = Lizard_Size_Data)
```

Expand Down
Loading