Package 'StablePopulation'

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] , Guillermo Rodríguez-Gómez [aut] , Jesús A. Martín-González [aut]
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

Help Index


Objective Function for uniroot: Finds the Difference Between Births and 1

Description

This 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.

Usage

alpha_objective(alpha, beta, fertility_rates)

Arguments

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.

Details

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.

Value

A numeric value giving the difference between the number of births (as calculated) and 1.

See Also

uniroot

Examples

# 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

Calculates the population for each age group

Description

This function calculates the population for each age group and the number of births.

Usage

calculate_population(alpha, beta, fertility_rates)

Arguments

alpha

A numeric value representing the scale parameter (α\alpha) of the Weibull distribution. Note: In this context, alpha controls the horizontal scaling of the survival curve.

beta

A numeric value representing the shape parameter (β\beta) of the Weibull distribution. Note: Beta controls the shape of the survival curve (e.g., aging or failure rate).

fertility_rates

A vector of fertility rates for each age group.

Value

A list with the following elements:

population

A numeric vector giving the population size for each age group.

births

A numeric value giving the total number of births.

Examples

calculate_population(0.5, 1.2, c(0.2, 0.3, 0.5, 0.4))

Function to find the value of alpha

Description

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.

Usage

find_alphas(beta, fertility_rates, tol = 1e-22)

Arguments

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 uniroot method. Default is 1e-22.

Value

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.

Examples

find_alphas(1.2, c(0.2, 0.3, 0.5, 0.4))

Run a beta sweep on Excel fertility data and export the predicted profiles

Description

This function reads fertility-rate data (mxm_x) from a multi-sheet Excel file, performs a sweep of β\beta values, computes for each β\beta the corresponding α\alpha that satisfies R0=lxmx=1R_0 = \sum l_x m_x = 1, and exports all predicted Weibull survival profiles (lxl_x) to a single Excel workbook with one worksheet per input sheet.

Usage

run_analysis(
  input_file = NULL,
  output_file = NULL,
  beta_values = seq(0.05, 3, by = 0.05),
  tol = 1e-12
)

Arguments

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 Output_Profiles.xlsx is written in the same directory as input_file.

beta_values

Numeric vector of β\beta values to evaluate. By default the function uses seq(0.05, 3.00, by = 0.05).

tol

Numeric tolerance passed to find_alphas(). Default: 1e-12.

Details

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 β\beta values,

  • the second row contains the corresponding α\alpha values,

  • the third row contains the numerical check of R0R_0,

  • the remaining rows contain the predicted Weibull survival profiles (lxl_x) for each age.

Value

Invisibly returns the full path to the output workbook.

See Also

find_alphas(), calculate_population(), readxl::read_excel(), openxlsx::writeData()


Weibull function for the survival rate

Description

This function calculates the survival rate to reach a specific age using the Weibull function.

Usage

weibull_survival(alpha, beta, age)

Arguments

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.

Value

A numeric value giving the survival rate (probability) for reaching the given age.

Examples

weibull_survival(1.5, 0.8, 10)