Title: Calculates Alpha for a Stable Population
Version: 1.0.3
Date: 2025-07-24
Author: David Palacios-Morales ORCID iD [aut, cre], Guillermo Rodríguez-Gómez ORCID iD [aut], Jesús A. Martín-González ORCID iD [aut]
Maintainer: David Palacios-Morales <dpmorales@ubu.es>
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>.
License: GPL-3
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (≥ 3.5.0)
Imports: readxl, openxlsx, stats
NeedsCompilation: no
Packaged: 2025-07-24 15:02:36 UTC; dpala
Repository: CRAN
Date/Publication: 2025-07-25 16:30:09 UTC

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))

Find Root Directory of StablePopulation

Description

This internal function searches for the root directory of the StablePopulation project by looking for a folder named StablePopulation in the current or parent directories. It is used internally to locate project-specific files.

Usage

find_stablepopulations_root()

Value

A character string with the full path to the StablePopulation directory if found. If not found, an error is raised.


Run Analysis on Excel Data and Export Results

Description

This function reads fertility rate data and Beta value from an Excel file, processes it, and exports the results to a new Excel file for the species, including population matrices and calculated alpha/beta values.

Usage

run_analysis()

Details

The function relies on functions from the readxl and openxlsx packages to handle Excel files.

The following external functions are used:

Please refer to the documentation of those packages for more details.

Value

No return value. Called for side effects (reading data, writing Excel files, and printing messages).

See Also

excel_sheets, read_excel, createWorkbook, addWorksheet, writeData, saveWorkbook


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)