-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Function for realising state as pres/abs
- Loading branch information
1 parent
53bebaf
commit 006f3f2
Showing
14 changed files
with
203 additions
and
71 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
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,27 @@ | ||
#' Realizes the state_target into binary from the continuous probability values | ||
#' | ||
#' @param sim_obj a SimulationObject | ||
#' @return A SimulationObject with a binary state_target | ||
#' @examples | ||
#' \dontrun{ | ||
#' sim_state_target_binary(sim_obj) | ||
#' } | ||
sim_state_target_realise_binomial <- function(sim_obj) { | ||
state_target <- sim_obj@state_target | ||
binary_state_target <- state_target | ||
|
||
for (i in 1:dim(sim_obj@state_target)[3]){ | ||
# Get the probability values from the state target | ||
prob_values <- terra::values(state_target[[i]]) | ||
|
||
# Simulate binary values from the binomial distribution based on the probability values | ||
binary_values <- rbinom(length(prob_values), 1, prob_values) | ||
|
||
terra::values(binary_state_target[[i]]) <- binary_values | ||
} | ||
|
||
# Update the SimulationObject with the binary state_target | ||
sim_obj@state_target_realised <- binary_state_target | ||
|
||
sim_obj | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.