This works even when a function is passed multiple times (e.g., when used
-inside an optim
call).
-See https://stackoverflow.com/a/46740314/10886760
diff --git a/CODE_OF_CONDUCT.html b/CODE_OF_CONDUCT.html deleted file mode 100644 index 59609b0e..00000000 --- a/CODE_OF_CONDUCT.html +++ /dev/null @@ -1,95 +0,0 @@ - -
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
-We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
-Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
-Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
-Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
-This Code of Conduct is adapted from the Contributor Covenant (http://contributor-covenant.org), version 1.0.0, available at http://contributor-covenant.org/version/1/0/0/
-This returns 10
likelihood values (because nsim_obs = 10
), which can be
averaged to come up with an overall likelihood estimate.
To find out about the usage of the chain_ll()
function, you can run ?chain_ll
diff --git a/articles/introduction.html b/articles/introduction.html
deleted file mode 100644
index b3be186f..00000000
--- a/articles/introduction.html
+++ /dev/null
@@ -1,187 +0,0 @@
-
-
-
vignettes/introduction.Rmd
- introduction.Rmd
bpmodels is an R
package to simulate and analyse the size and length of branching processes with a given offspring distribution. These can be used, for example, to analyse the distribution of chain sizes or length of infectious disease outbreaks.
To load the package, use
-At the heart of the package are the chains_ll()
and chains_sim()
functions.
The chains_ll()
function calculates the log-likelihood of a distribution of chain sizes or lengths given an offspring distribution and its associated parameters.
If we have observed a distribution of chains of sizes \(1, 1, 4, 7\), we can calculate the log-likelihood of this observed chain by assuming the offspring per generation is Poisson distributed with a mean number of 0.5.
-To do this, we run
-The first argument of chain_ll()
is the size (or length) distribution to analyse. The second argument (called offspring
) specifies the offspring distribution. This is given as a function used to generate random offspring. It can be any probability distribution implemented in R
, that is, one that has a corresponding function for generating random numbers beginning with the letter r
. In the case of the example above, since random Poisson numbers are generated in R
using a function called rpois()
, the string to pass to the offspring
argument is "pois"
.
The third argument (called stat
) determines whether to analyse chain sizes ("size"
, the default if this argument is not specified) or lengths ("length"
). Lastly, any named arguments not recognised by chain_ll()
are interpreted as parameters of the corresponding probability distribution, here lambda = 0.5
as the mean of the Poisson distribution (see the R
help page for the Poisson distribution for more information).
To find out about usage of the chains_ll()
function, you can use the R
help file
-?chains_ll
To simulate a branching process, we use the chain_sim()
function. This function follows the same syntax as chain_ll()
, that is:
-chain_sim(n = 5, "pois", "size", lambda = 0.5)
-#> [1] 2 1 1 1 5
If the probability distribution of chain sizes or lengths has an analytical solution, this will be used (size distribution: Poisson and negative binomial; length distribution: Poisson and geometric).
-If an analytical solution does not exist, simulations are used to approximate this probability distributions (using a linear approximation to the cumulative distribution for unobserved sizes/lengths). The argument nsim_offspring
is used to specify the number of simulations to be used for this approximation.
For example, to get offspring drawn from a binomial distribution with probability prob = 0.5
, we run
-chain_ll(chain_sizes, "binom", "size", size = 1, prob = 0.5, nsim_offspring = 100)
-#> [1] -8.477588
If observations are imperfect, the chain_ll()
function has an obs_prob
argument that can be used to determine the likelihood. In that case, true chain sizes or lengths are simulated repeatedly (the number of times given by the nsim_obs
argument), and the likelihood calculated for each of these simulations.
For example, if the probability of observing each case is \(30%\), we use
-This returns nsim_obs = 10
likelihood values which can be averaged to come up with an overall likelihood estimate.
This works even when a function is passed multiple times (e.g., when used
-inside an optim
call).
-See https://stackoverflow.com/a/46740314/10886760