| Title: | Calculates Alpha for a Stable Population |
|---|---|
| Description: | Provides tools to calculate the alpha parameter of the Weibull distribution, given beta and the age-specific fertility of a species, so that the population remains stable and stationary. Methods are inspired by "Survival profiles from linear models versus Weibull models: Estimating stable and stationary population structures for Pleistocene large mammals" (Martín-González et al. 2019) <doi:10.1016/j.jasrep.2019.03.031>. |
| Authors: | David Palacios-Morales [aut, cre]
|
| Maintainer: | David Palacios-Morales <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.3.9000 |
| Built: | 2026-05-22 09:19:30 UTC |
| Source: | https://github.com/d4v1d-d0/stablepopulation |
uniroot: Finds the Difference Between Births and 1This function calculates the difference between the number of births, as calculated with the given values
of alpha, beta, and fertility_rates, and the target value of 1.
alpha_objective(alpha, beta, fertility_rates)alpha_objective(alpha, beta, fertility_rates)
alpha |
A numeric value representing the alpha parameter. |
beta |
A numeric value representing the beta parameter. |
fertility_rates |
A numeric vector containing the fertility rates. |
Typically used as the objective function in root-finding algorithms such as uniroot, to determine the value of alpha that results in exactly one birth.
This function depends on calculate_population, which must be available in your package namespace.
A numeric value giving the difference between the number of births (as calculated) and 1.
# Basic usage alpha_objective(0.5, 1.2, c(0.2, 0.3, 0.5, 0.4)) # Example with uniroot: fertility_rates <- c(0.2, 0.3, 0.5, 0.4) beta <- 1.2 res <- uniroot( alpha_objective, interval = c(0.000001, 100), beta = beta, fertility_rates = fertility_rates ) res$root# Basic usage alpha_objective(0.5, 1.2, c(0.2, 0.3, 0.5, 0.4)) # Example with uniroot: fertility_rates <- c(0.2, 0.3, 0.5, 0.4) beta <- 1.2 res <- uniroot( alpha_objective, interval = c(0.000001, 100), beta = beta, fertility_rates = fertility_rates ) res$root
This function calculates the population for each age group and the number of births.
calculate_population(alpha, beta, fertility_rates)calculate_population(alpha, beta, fertility_rates)
alpha |
A numeric value representing the scale parameter ( |
beta |
A numeric value representing the shape parameter ( |
fertility_rates |
A vector of fertility rates for each age group. |
A list with the following elements:
A numeric vector giving the population size for each age group.
A numeric value giving the total number of births.
calculate_population(0.5, 1.2, c(0.2, 0.3, 0.5, 0.4))calculate_population(0.5, 1.2, c(0.2, 0.3, 0.5, 0.4))
This function finds the value of alpha using the uniroot method for a given beta and a vector
of fertility rates. If the function values at the interval ends do not have opposite signs,
it returns the closest value to 0.
find_alphas(beta, fertility_rates, tol = 1e-22)find_alphas(beta, fertility_rates, tol = 1e-22)
beta |
A numeric value representing the beta parameter of Weibull distribution. |
fertility_rates |
A numeric vector containing the fertility rates. |
tol |
A numeric value representing the tolerance for the |
A numeric value giving the estimated value of alpha, either found by uniroot or selected as the endpoint closest to zero if the root is not bracketed.
find_alphas(1.2, c(0.2, 0.3, 0.5, 0.4))find_alphas(1.2, c(0.2, 0.3, 0.5, 0.4))
This function reads fertility-rate data () from a multi-sheet Excel
file, performs a sweep of values, computes for each
the corresponding that satisfies ,
and exports all predicted Weibull survival profiles () to a single
Excel workbook with one worksheet per input sheet.
run_analysis( input_file = NULL, output_file = NULL, beta_values = seq(0.05, 3, by = 0.05), tol = 1e-12 )run_analysis( input_file = NULL, output_file = NULL, beta_values = seq(0.05, 3, by = 0.05), tol = 1e-12 )
input_file |
Optional path to the input Excel workbook. The workbook must contain one or more sheets, with ages in the first column and fertility rates in the second column. The first row is treated as a header row. |
output_file |
Optional path to the output Excel workbook. If omitted, the
file |
beta_values |
Numeric vector of |
tol |
Numeric tolerance passed to |
If input_file is not supplied, the function first looks for the bundled
example file via system.file("extdata", "Input_Data.xlsx", package =
"StablePopulation"). If that is not available, it falls back to the package
source tree and looks for inst/extdata/Input_Data.xlsx.
The output workbook contains one sheet per input sheet. In each output sheet:
the first row contains the evaluated values,
the second row contains the corresponding values,
the third row contains the numerical check of ,
the remaining rows contain the predicted Weibull survival profiles
() for each age.
Invisibly returns the full path to the output workbook.
find_alphas(), calculate_population(), readxl::read_excel(),
openxlsx::writeData()
This function calculates the survival rate to reach a specific age using the Weibull function.
weibull_survival(alpha, beta, age)weibull_survival(alpha, beta, age)
alpha |
A numeric value representing the scale parameter of the Weibull distribution. |
beta |
A numeric value representing the shape parameter of the Weibull distribution. |
age |
A numeric value representing the age. |
A numeric value giving the survival rate (probability) for reaching the given age.
weibull_survival(1.5, 0.8, 10)weibull_survival(1.5, 0.8, 10)