Title: | Estimate Population Kin Distribution |
---|---|
Description: | Estimate population kin counts and its distribution by type, age and sex. The package implements one-sex and two-sex framework for studying living-death availability, with time varying rates or not, and multi-stage model. |
Authors: | Iván Williams [cre], Diego Alburez-Gutierrez [aut], Xi Song [ctb], Caswell Hal [ctb] |
Maintainer: | Iván Williams <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.3 |
Built: | 2024-11-13 12:27:46 UTC |
Source: | https://github.com/ivanwilli/demokin |
Title time invariant two-sex multi-state kin projections
all_kin_dy( Uf, Um, Ff, Fm, alpha, na, ns, Parity, sex_Focal, Initial_stage_Focal )
all_kin_dy( Uf, Um, Ff, Fm, alpha, na, ns, Parity, sex_Focal, Initial_stage_Focal )
Uf |
matrix (block structured). transfers female individuals across stages and advances their age (conditional on survial) |
Um |
matrix (block structured). transfers male individuals across stages and advances their age (conditional on survial) |
Ff |
matrix (block structured). accounts for female reproduction, and assigns newborns into given age*stage |
Fm |
matrix (block structured). accounts for male reproduction; assigns newborns into age-class, and stage |
alpha |
scalar. birth ratio (male:female) |
na |
scalar. number of ages. |
ns |
scalar. number of stages. |
Parity |
logical. If true then we omit mothers of parity 0, and re-scale the mother's age*stage of parenting |
sex_Focal |
logical. Female or Male |
Initial_stage_Focal |
numeric. Any natural number 1,2,3,4,... |
a list of matrices. Each list entry represents a particular kin. Each kin is chacacterised by a matrix of dimension: nrow = 2* na * ns (2-sex age-stage structured) and ncol = na (Focal's age) yielding the age*stage distribution of kin for each age of Focal
Title time-variant two-sex multi-state kin projections
all_kin_dy_TV( Uf, Um, Ff, Fm, alpha, na, ns, Parity, sex_Focal, Initial_stage_Focal, previous_kin_Focal, prev_kin_children, prev_kin_grandchildren, prev_kin_greatgrandchildren, prev_kin_parents, prev_kin_grand_parents, prev_kin_great_grand_parents, prev_kin_older_sibs, prev_kin_younger_sibs, prev_kin_older_niece_nephew, prev_kin_younger_niece_nephew, prev_kin_older_aunts_uncles, prev_kin_younger_aunts_uncles, prev_kin_older_cousins, prev_kin_younger_cousins, previous_population_age_stage_structure )
all_kin_dy_TV( Uf, Um, Ff, Fm, alpha, na, ns, Parity, sex_Focal, Initial_stage_Focal, previous_kin_Focal, prev_kin_children, prev_kin_grandchildren, prev_kin_greatgrandchildren, prev_kin_parents, prev_kin_grand_parents, prev_kin_great_grand_parents, prev_kin_older_sibs, prev_kin_younger_sibs, prev_kin_older_niece_nephew, prev_kin_younger_niece_nephew, prev_kin_older_aunts_uncles, prev_kin_younger_aunts_uncles, prev_kin_older_cousins, prev_kin_younger_cousins, previous_population_age_stage_structure )
Uf |
matrix (block structured). transfers female individuals across stages and advances their age (conditional on survial) |
Um |
matrix (block structured). transfers male individuals across stages and advances their age (conditional on survial) |
Ff |
matrix (block structured). accounts for female reproduction, and assigns newborns into given age*stage |
Fm |
matrix (block structured). accounts for male reproduction; assigns newborns into age-class, and stage |
alpha |
scalar. birth ratio (male:female) |
na |
scalar. number of ages. |
ns |
scalar. number of stages. |
Parity |
logical. If true then we omit mothers of parity 0, and re-scale the mother's age*stage of parenting |
sex_Focal |
logical. Female or Male |
Initial_stage_Focal |
numeric. Any natural number 1,2,3,4,... |
previous_kin_Focal |
matrix. last years kinship output. |
prev_kin_children |
matrix. last years kinship output. |
prev_kin_grandchildren |
matrix. last years kinship output. |
prev_kin_greatgrandchildren |
matrix. last years kinship output. |
prev_kin_parents |
matrix. last years kinship output. |
prev_kin_grand_parents |
matrix. last years kinship output. |
prev_kin_older_sibs |
matrix. last years kinship output. |
prev_kin_younger_sibs |
matrix. last years kinship output. |
prev_kin_older_niece_nephew |
matrix. last years kinship output. |
prev_kin_younger_niece_nephew |
matrix. last years kinship output. |
prev_kin_older_aunts_uncles |
matrix. last years kinship output. |
prev_kin_younger_aunts_uncles |
matrix. last years kinship output. |
prev_kin_older_cousins |
matrix. last years kinship output. |
prev_kin_younger_cousins |
matrix. last years kinship output. |
previous_population_age_stage_structure |
vector. The transient "population structure" (age*stage distributed) |
a list of matrices. Each list entry represents a particular kin. Each kin is chacacterised by a matrix of dimension: nrow = 2* na * ns (2-sex age-stage structured) and ncol = na (Focal's age) yielding the age*stage distribution of kin for each age of Focal
Title Accumulated kin by each age of Focal, for each time period, and cohort of birth
create_cumsum_df( kin_matrix_lists, kin_names, years, start_year, na, ns, specific_kin )
create_cumsum_df( kin_matrix_lists, kin_names, years, start_year, na, ns, specific_kin )
kin_matrix_lists |
list of lists of kin matrices: list( list(X_focal), list(X_parents), ... ). Outer list is length 14 = number of kin. Inner lists have lenght = timescale so list(X_focal) = list(X_focalyear1,X_focalyear2,...,X_focalyearlast) |
kin_names |
list of characters. Corresponding to above lists: list("F","m",....) |
years |
vector. The timescale on which we implement the kinship model. |
start_year |
. First year of varying vital rates (e.g., if years = 1990:2000 then start_year = 1990) |
na |
numeric. Number of ages. |
ns |
numeric. Number of stages. |
specific_kin |
character. names of kin we wish to analyse, e.g., list("os","ys"). If null returns all 14. |
A data frame which gives for each age of Focal at each year in the timescale, Focal's experienced number kin demarcated by stages (summed over all ages)
Title joint age*stage distributions of kin by each age of Focal, for each time period, and cohort of birth
create_full_dists_df( kin_matrix_lists, kin_names, years, start_year, na, ns, specific_kin )
create_full_dists_df( kin_matrix_lists, kin_names, years, start_year, na, ns, specific_kin )
kin_matrix_lists |
list of lists of kin matrices: list( list(X_focal), list(X_parents), ... ). Outer list is length 14 = number of kin. Inner lists have lenght = timescale so list(X_focal) = list(X_focalyear1,X_focalyear2,...,X_focalyearlast) |
kin_names |
list of characters. Corresponding to above lists: list("F","m",....) |
years |
vector. The timescale on which we implement the kinship model. |
start_year |
. First year of varying vital rates (e.g., if years = 1990:2000 then start_year = 1990) |
na |
numeric. Number of ages. |
ns |
numeric. Number of stages. |
specific_kin |
character. names of kin we wish to analyse, e.g., list("os","ys"). If null returns all 14. |
A data frame which gives for each age of Focal at each year in the timescale, the full age*stage dist of kin
DemoKin codes, Caswell (2020) codes, and useful labels.
demokin_codes
demokin_codes
A data.frame with codes and labels for distinction between kin types.
Historic and projected fertility ratios from Sweden used in Caswell (2021)
f_caswell_2021
f_caswell_2021
A matrix f with years as cols and ages as rows.
Caswell (2019)
Fertility for France (2012) by sex in Caswell (2022).
fra_asfr_sex
fra_asfr_sex
A data.frame with age specific fertility rates by age and sex.
Caswell (2022)
Survival probability for France (2012) by sex in Caswell (2022).
fra_surv_sex
fra_surv_sex
A data.frame with survival probabilities by age and sex.
Caswell (2022)
Implementation of Goodman-Keyfitz-Pullum equations in a matrix framework. This produce a matrilineal (or patrilineal) kin count distribution by kin and age.
kin( p = NULL, f = NULL, time_invariant = TRUE, pi = NULL, n = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, output_age_focal = NULL, birth_female = 1/2.04, summary_kin = TRUE )
kin( p = NULL, f = NULL, time_invariant = TRUE, pi = NULL, n = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, output_age_focal = NULL, birth_female = 1/2.04, summary_kin = TRUE )
p |
numeric. A vector (atomic) or matrix with probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
f |
numeric. Same as |
time_invariant |
logical. Constant assumption for a given |
pi |
numeric. Same as |
n |
numeric. Only for |
output_cohort |
integer. Vector of year cohorts for returning results. Should be within input data years range. |
output_period |
integer. Vector of period years for returning results. Should be within input data years range. |
output_kin |
character. kin types to return: "m" for mother, "d" for daughter,... |
output_age_focal |
integer. Vector of ages to select (and make faster the run). |
birth_female |
numeric. Female portion at birth. This multiplies |
summary_kin |
logical. Whether or not include |
See Caswell (2019) and Caswell (2021) for details on formulas. One sex only (female by default).
A list with:
kin_full a data frame with year, cohort, Focal´s age, related ages and type of kin (for example d
is daughter,
oa
is older aunts, etc.), including living and dead kin at that age.
kin_summary a data frame with Focal´s age, related ages and type of kin, with indicators obtained processing kin_full
,
grouping by cohort or period (depending on the given arguments):
count_living
: count of living kin at actual age of Focal
mean_age
: mean age of each type of living kin.
sd_age
: standard deviation of age of each type of living kin.
count_death
: count of dead kin at specific age of Focal.
count_cum_death
: cumulated count of dead kin until specific age of Focal.
mean_age_lost
: mean age where Focal lost her relative.
# Kin expected matrilineal count for a Swedish female based on 2015 rates. swe_surv_2015 <- swe_px[,"2015"] swe_asfr_2015 <- swe_asfr[,"2015"] # Run kinship models swe_2015 <- kin(p = swe_surv_2015, f = swe_asfr_2015) head(swe_2015$kin_summary)
# Kin expected matrilineal count for a Swedish female based on 2015 rates. swe_surv_2015 <- swe_px[,"2015"] swe_asfr_2015 <- swe_asfr[,"2015"] # Run kinship models swe_2015 <- kin(p = swe_surv_2015, f = swe_asfr_2015) head(swe_2015$kin_summary)
Implementation of age-stage kin estimates (multi-state) by Caswell (2020). Stages are implied in length of input lists.
kin_multi_stage( U = NULL, f = NULL, D = NULL, H = NULL, birth_female = 1/2.04, output_kin = NULL, parity = FALSE, list_output = FALSE )
kin_multi_stage( U = NULL, f = NULL, D = NULL, H = NULL, birth_female = 1/2.04, output_kin = NULL, parity = FALSE, list_output = FALSE )
U |
list. age elements with column-stochastic transition matrix with dimension for the state space, conditional on survival. |
f |
matrix. state-specific fertility (age in rows and states in columns). Is accepted also a list with for each age-class. |
D |
matrix. survival probabilities by state (age in rows and states in columns). Is accepted also a list for each state with survival matrices. |
H |
matrix. assigns the offspring of individuals in some stage to the appropriate age class (age in rows and states in columns). Is accepted also a list with a matrix for each state. |
birth_female |
numeric. Female portion at birth. |
output_kin |
character. kin to return. For example "m" for mother, "d" for daughter. See the |
parity |
logical. parity states imply age distribution of mothers re-scaled to not have parity 0 when Focal born. Default |
list_output |
logical. Results as a list. Default |
A data frame with focal´s age, related ages and type of kin
(for example d
is daughter, oa
is older aunts, etc.), living and death kin counts, and specific stage. If list_output = TRUE
then this is a list with elements as kin types.
Implementation of combined formal demographic models: Caswell II,III,IV.
kin_multi_stage_time_variant_2sex( U_list_females = NULL, U_list_males = NULL, F_list_females = NULL, F_list_males = NULL, T_list_females = NULL, T_list_males = NULL, H_list = NULL, birth_female = 0.49, parity = FALSE, output_kin = FALSE, summary_kin = TRUE, sex_Focal = "Female", initial_stage_Focal = NULL, output_years )
kin_multi_stage_time_variant_2sex( U_list_females = NULL, U_list_males = NULL, F_list_females = NULL, F_list_males = NULL, T_list_females = NULL, T_list_males = NULL, H_list = NULL, birth_female = 0.49, parity = FALSE, output_kin = FALSE, summary_kin = TRUE, sex_Focal = "Female", initial_stage_Focal = NULL, output_years )
U_list_females |
list with matrix entries: period-specific female survival probabilities. Age in rows and states in columns. |
U_list_males |
list with matrix entries: period-specific male survival probabilities. Age in rows and states in columns. |
F_list_females |
list with matrix with elements: period-specific female fertility (age in rows and states in columns). |
F_list_males |
list with matrix entries: period-specific male fertility (age in rows and states in columns). |
T_list_females |
list of lists with matrix entries: each outer list entry is period-specific, and composed of a list of stochastic matrices which describe age-specific female probabilities of transferring stage |
T_list_males |
list of lists with matrix entries: each outer list entry is period-specific, and composed of a list of stochastic matrices which describe age-specific male probabilities of transferring stage |
H_list |
list with matrix entries: redistribution of newborns across each stage to a specific age-class |
birth_female |
numeric. birth ratio of females to males in population |
parity |
logical. parity states imply age distribution of mothers re-scaled to not have parity 0 when Focal born. Default |
output_kin |
vector. A vector of particular kin one wishes to obtain results for, e.g., c("m","d","oa"). Default is all kin types. |
summary_kin |
logical. Results as a data frame of accumulated kin by age of Focal if TRUE, and kin by their age*stage distribution by age of Focal if FALSE. |
sex_Focal |
character. Female or Male as the user requests. |
initial_stage_Focal |
Numeric in Natural number set 1,2,...,. The stage which Focal is born into (e.g., 1 for parity 0) |
output_years |
vector. The times at which we wish to count kin: start year = output_years1, and end year = output_yearslength. |
A data frame with focal age, kin age, kin stage, kin sex, year, cohort, and expected number of kin given these restrictions.
Output for Slovakia 1990 in Caswell (2020).
kin_svk1990_caswell2020
kin_svk1990_caswell2020
A list with specific kin types age-stage matrix
Caswell (2021)
Mtrix implementation of Goodman-Keyfitz-Pullum equations adapted by Caswell (2019).
kin_time_invariant( p = NULL, f = NULL, birth_female = 1/2.04, pi = NULL, output_kin = NULL, list_output = FALSE )
kin_time_invariant( p = NULL, f = NULL, birth_female = 1/2.04, pi = NULL, output_kin = NULL, list_output = FALSE )
p |
numeric. A vector of survival probabilities with same length as ages. |
f |
numeric. A vector of age-specific fertility rates with same length as ages. |
birth_female |
numeric. Female portion at birth. |
pi |
numeric. For using some specific non-stable age distribution of childbearing (same length as ages). Default |
output_kin |
character. kin to return. For example "m" for mother, "d" for daughter. See |
list_output |
logical. Results as a list with |
A data frame with focal´s age, related ages and type of kin
(for example d
is daughter, oa
is older aunts, etc.), alive and death. If list_output = TRUE
then this is a list.
Two-sex matrix framework for kin count estimates.This produces kin counts grouped by kin, age and sex of each relatives at each Focal´s age. For example, male cousins from aunts and uncles from different sibling's parents are grouped in one male count of cousins.
kin_time_invariant_2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, output_kin = NULL, list_output = FALSE )
kin_time_invariant_2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, output_kin = NULL, list_output = FALSE )
pf |
numeric. A vector of survival probabilities for females with same length as ages. |
pm |
numeric. A vector of survival probabilities for males with same length as ages. |
ff |
numeric. A vector of age-specific fertility rates for females with same length as ages. |
fm |
numeric. A vector of age-specific fertility rates for males with same length as ages. |
sex_focal |
character. "f" for female or "m" for male. |
birth_female |
numeric. Female portion at birth. |
pif |
numeric. For using some specific non-stable age distribution of childbearing for mothers (same length as ages). Default |
pim |
numeric. For using some specific non-stable age distribution of childbearing for fathers (same length as ages). Default |
output_kin |
character. kin to return, considering matrilineal names. For example "m" for parents, "d" for children, etc. See the |
list_output |
logical. Results as a list with |
See Caswell (2022) for details on formulas.
A data frame with focal´s age, related ages and type of kin
(for example d
is children, oa
is older aunts/uncles, etc.), sex, alive and death. If list_output = TRUE
then this is a list.
Two-sex matrix framework for kin count and death estimates.This produces kin counts grouped by kin, age and sex of each relatives at each Focal´s age. For example, male cousins from aunts and uncles from different sibling's parents are grouped in one male count of cousins. This also produces kin deaths grouped by kin, age, sex of each relatives at each Focal´s age, and cause of death.
kin_time_invariant_2sex_cod( pf = NULL, pm = NULL, ff = NULL, fm = NULL, Hf = NULL, Hm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, output_kin = NULL, list_output = FALSE )
kin_time_invariant_2sex_cod( pf = NULL, pm = NULL, ff = NULL, fm = NULL, Hf = NULL, Hm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, output_kin = NULL, list_output = FALSE )
pf |
numeric. A vector of survival probabilities for females with same length as ages. |
pm |
numeric. A vector of survival probabilities for males with same length as ages. |
ff |
numeric. A vector of age-specific fertility rates for females with same length as ages. |
fm |
numeric. A vector of age-specific fertility rates for males with same length as ages. |
Hf |
numeric. A matrix with cause-specific hazards for females with rows as causes and columns as ages, being the name of each col the age. |
Hm |
numeric. A matrix with cause-specific hazards for males with rows as causes and columns as ages, being the name of each col the age. |
sex_focal |
character. "f" for female or "m" for male. |
birth_female |
numeric. Female portion at birth. |
pif |
numeric. For using some specific non-stable age distribution of childbearing for mothers (same length as ages). Default |
pim |
numeric. For using some specific non-stable age distribution of childbearing for fathers (same length as ages). Default |
output_kin |
character. kin to return, considering matrilineal names. For example "m" for parents, "d" for children, etc. See the |
list_output |
logical. Results as a list with |
See Caswell (2022) for details on formulas.
A data frame with focal´s age, related ages and type of kin
(for example d
is children, oa
is older aunts/uncles, etc.), sex, alive and death. If list_output = TRUE
then this is a list.
Matrix implementation of time variant Goodman-Keyfitz-Pullum equations in a matrix framework.
kin_time_variant( p = NULL, f = NULL, pi = NULL, n = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, birth_female = 1/2.04, list_output = FALSE )
kin_time_variant( p = NULL, f = NULL, pi = NULL, n = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, birth_female = 1/2.04, list_output = FALSE )
p |
numeric. A matrix of survival ratios with rows as ages and columns as years. Column names must be equal interval. |
f |
numeric. A matrix of age-specific fertility rates with rows as ages and columns as years. Coincident with |
pi |
numeric. A matrix with distribution of childbearing with rows as ages and columns as years. Coincident with |
n |
numeric. A matrix of population with rows as ages and columns as years. Coincident with |
output_cohort |
integer. Year of birth of focal to return as output. Could be a vector. Should be within input data years range. |
output_period |
integer. Year for which to return kinship structure. Could be a vector. Should be within input data years range. |
output_kin |
character. kin to return as output: "m" for mother, "d" for daughter,... See |
birth_female |
numeric. Female portion at birth. |
list_output |
logical. Results as a list with years elements (as a result of |
See Caswell (2021) for details on formulas.
A data frame of population kinship structure, with Focal's cohort, focal´s age, period year, type of relatives
(for example d
is daughter, oa
is older aunts, etc.), living and death kin counts, and age of (living or time deceased) relatives. If list_output = TRUE
then this is a list.
Two-sex matrix framework for kin count estimates with varying rates. This produces kin counts grouped by kin, age and sex of each relatives at each Focal´s age. For example, male cousins from aunts and uncles from different sibling's parents are grouped in one male count of cousins.
kin_time_variant_2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, list_output = FALSE )
kin_time_variant_2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, list_output = FALSE )
pf |
numeric. A vector (atomic) or matrix with probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
pm |
numeric. A vector (atomic) or matrix with probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
ff |
numeric. Same as pf but for fertility rates. |
fm |
numeric. Same as pm but for fertility rates. |
sex_focal |
character. "f" for female or "m" for male. |
birth_female |
numeric. Female portion at birth. This multiplies |
pif |
numeric. For using some specific age distribution of childbearing for mothers (same length as ages). Default |
pim |
numeric. For using some specific age distribution of childbearing for fathers (same length as ages). Default |
nf |
numeric. Same as pf but for population distribution (counts or |
nm |
numeric. Same as pm but for population distribution (counts or |
output_cohort |
integer. Vector of year cohorts for returning results. Should be within input data years range. |
output_period |
integer. Vector of period years for returning results. Should be within input data years range. |
output_kin |
character. kin types to return: "m" for mother, "d" for daughter,... |
list_output |
logical. Results as a list with years elements (as a result of |
See Caswell (2022) for details on formulas.
A data.frame with year, cohort, Focal´s age, related ages, sex and type of kin (for example d
is daughter, oa
is older aunts, etc.), including living and dead kin at that age and sex.
Two-sex matrix framework for kin count estimates with varying rates. This produces kin counts grouped by kin, age and sex of each relatives at each Focal´s age. For example, male cousins from aunts and uncles from different sibling's parents are grouped in one male count of cousins. This also produces kin deaths grouped by kin, age, sex of each relatives at each Focal´s age, and cause of death.
kin_time_variant_2sex_cod( pf = NULL, pm = NULL, ff = NULL, fm = NULL, Hf = NULL, Hm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, list_output = FALSE )
kin_time_variant_2sex_cod( pf = NULL, pm = NULL, ff = NULL, fm = NULL, Hf = NULL, Hm = NULL, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, list_output = FALSE )
pf |
numeric. A vector (atomic) or matrix with probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
pm |
numeric. A vector (atomic) or matrix with probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
ff |
numeric. Same as pf but for fertility rates. |
fm |
numeric. Same as pm but for fertility rates. |
Hf |
numeric. A list where each list element (being the name of each list element the year) contains a matrix with cause-specific hazards for females with rows as causes and columns as ages, being the name of each col the age. |
Hm |
numeric. A list where each list element (being the name of each list element the year) contains a matrix with cause-specific hazards for males with rows as causes and columns as ages, being the name of each col the age. |
sex_focal |
character. "f" for female or "m" for male. |
birth_female |
numeric. Female portion at birth. This multiplies |
pif |
numeric. For using some specific age distribution of childbearing for mothers (same length as ages). Default |
pim |
numeric. For using some specific age distribution of childbearing for fathers (same length as ages). Default |
nf |
numeric. Same as pf but for population distribution (counts or |
nm |
numeric. Same as pm but for population distribution (counts or |
output_cohort |
integer. Vector of year cohorts for returning results. Should be within input data years range. |
output_period |
integer. Vector of period years for returning results. Should be within input data years range. |
output_kin |
character. kin types to return: "m" for mother, "d" for daughter,... |
list_output |
logical. Results as a list with years elements (as a result of |
See Caswell (2022) for details on formulas.
A data.frame with year, cohort, Focal´s age, related ages, sex and type of kin (for example d
is daughter, oa
is older aunts, etc.), including living and dead kin at that age and sex.
Implementation of two-sex matrix kinship model. This produces kin counts grouped by kin, age and sex of
each relatives at each Focal´s age. For example, male cousins from aunts and uncles from different sibling's parents
are grouped in one male count of cousins. Note that the output labels relative following female notation: the label m
refers to either mothers or fathers, and column sex_kin
determine the sex of the relative.
kin2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, time_invariant = TRUE, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, Hf = NULL, Hm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, output_age_focal = NULL, summary_kin = TRUE )
kin2sex( pf = NULL, pm = NULL, ff = NULL, fm = NULL, time_invariant = TRUE, sex_focal = "f", birth_female = 1/2.04, pif = NULL, pim = NULL, nf = NULL, nm = NULL, Hf = NULL, Hm = NULL, output_cohort = NULL, output_period = NULL, output_kin = NULL, output_age_focal = NULL, summary_kin = TRUE )
pf |
numeric. A vector (atomic) or matrix with female probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
pm |
numeric. A vector (atomic) or matrix with male probabilities (or survival ratios, or transition between age class in a more general perspective) with rows as ages (and columns as years in case of matrix, being the name of each col the year). |
ff |
numeric. Same as |
fm |
numeric. Same as |
time_invariant |
logical. Constant assumption for a given |
sex_focal |
character. "f" for female or "m" for male. |
birth_female |
numeric. Female portion at birth. This multiplies |
pif |
numeric. For using some specific age distribution of childbearing for mothers (same length as ages). Default |
pim |
numeric. For using some specific age distribution of childbearing for fathers (same length as ages). Default |
nf |
numeric. Only for |
nm |
numeric. Only for |
Hf |
numeric. A list where each list element (being the name of each list element the year) contains a matrix with cause-specific hazards for females with rows as causes and columns as ages, being the name of each col the age. |
Hm |
numeric. A list where each list element (being the name of each list element the year) contains a matrix with cause-specific hazards for males with rows as causes and columns as ages, being the name of each col the age. |
output_cohort |
integer. Vector of year cohorts for returning results. Should be within input data years range. |
output_period |
integer. Vector of period years for returning results. Should be within input data years range. |
output_kin |
character. kin types to return: "m" for mother, "d" for daughter,... |
output_age_focal |
integer. Vector of ages to select (and make faster the run). |
summary_kin |
logical. Whether or not include |
See Caswell (2022) for details on formulas.
A list with:
kin_full a data frame with year, cohort, Focal´s age, related ages and type of kin (for example d
could be daughter or son depending sex_kin
,
oa
is older aunts or uncles also depending sex_kin
value, etc.), including living and dead kin at that age.
kin_summary a data frame with Focal´s age, related ages, sex and type of kin, with indicators obtained processing kin_full
, grouping by cohort or period (depending on the given arguments):
count_living
: count of living kin at actual age of Focal
mean_age
: mean age of each type of living kin.
sd_age
: standard deviation of age of each type of living kin.
count_death
: count of dead kin at specific age of Focal.
count_cum_death
: cumulated count of dead kin until specific age of Focal.
mean_age_lost
: mean age where Focal lost her relative.
# Kin expected count by relative sex for a French female based on 2012 rates. fra_fert_f <- fra_asfr_sex[,"ff"] fra_fert_m <- fra_asfr_sex[,"fm"] fra_surv_f <- fra_surv_sex[,"pf"] fra_surv_m <- fra_surv_sex[,"pm"] fra_2012 <- kin2sex(fra_surv_f, fra_surv_m, fra_fert_f, fra_fert_m) head(fra_2012$kin_summary)
# Kin expected count by relative sex for a French female based on 2012 rates. fra_fert_f <- fra_asfr_sex[,"ff"] fra_fert_m <- fra_asfr_sex[,"fm"] fra_surv_f <- fra_surv_sex[,"pf"] fra_surv_m <- fra_surv_sex[,"pm"] fra_2012 <- kin2sex(fra_surv_f, fra_surv_m, fra_fert_f, fra_fert_m) head(fra_2012$kin_summary)
define APC combination to return in kin
and kin2sex
.
output_period_cohort_combination( output_cohort = NULL, output_period = NULL, age = NULL, years_data = NULL )
output_period_cohort_combination( output_cohort = NULL, output_period = NULL, age = NULL, years_data = NULL )
output_cohort |
integer. A vector with selected calendar years. |
output_period |
integer. A vector with selected cohort years. |
age |
integer. A vector with ages from the kinship network to be filtered. |
years_data |
integer. A vector with years from the time-varying kinship network to be filtered. |
Because returning all period and cohort data from a huge time-series would be hard memory consuming,
this function is an auxiliary one to deal with selection from inputs output_cohort
and output_period
.
data.frame with years and ages to filter in kin
and kin_2sex
functions.
Historic and projected mother´s age distribution of childbearing from Sweden used in Caswell (2021)
pi_caswell_2021
pi_caswell_2021
A matrix pi with years as cols and ages as rows.
Caswell (2019)
Mixing distributions for the time-invariant multi-state 2-sex model: Non-parity case
pi_mix(Uf, Um, Ff, Fm, alpha, na, ns)
pi_mix(Uf, Um, Ff, Fm, alpha, na, ns)
Uf |
matrix. Block-structured matrix which transfers females over stage and advances their age |
Um |
matrix. Block-structured matrix which transfers males over stage and advances their age |
Ff |
matrix. Block-structured matrix which counts reproduction by females and assigns newborns an age and stage |
Fm |
matrix. Block-structured matrix which counts reproduction by males and assigns newborns an age and stage |
alpha |
scalar. Birth ratio male:female |
na |
scalar. Number of age-classes |
ns |
scalar. Number of stages |
list (of vectors). list[1] = full agestagesex distribution list[2] = female agestage distribution normalised list[3] = male agestage distribution normalised list[4] = female marginal age distribution normalised list[5] = male marginal age distribution normalised
Mixing distributions for the time-invariant multi-state 2-sex model: Parity-specific case
pi_mix_parity(Uf, Um, Ff, Fm, alpha, na, ns)
pi_mix_parity(Uf, Um, Ff, Fm, alpha, na, ns)
Uf |
matrix. Block-structured matrix which transfers females over stage and advances their age |
Um |
matrix. Block-structured matrix which transfers males over stage and advances their age |
Ff |
matrix. Block-structured matrix which counts reproduction by females and assigns newborns an age and stage |
Fm |
matrix. Block-structured matrix which counts reproduction by males and assigns newborns an age and stage |
alpha |
scalar. Birth ratio male:female |
na |
scalar. Number of age-classes |
ns |
scalar. Number of stages |
list (of vectors). list[1] = full agestagesex distribution list[2] = female agestage distribution normalised list[3] = male agestage distribution normalised list[4] = female marginal age distribution normalised list[5] = male marginal age distribution normalised
Mixing distributions for the time-variant multi-state 2-sex model: Non-parity case
pi_mix_TV(Ff, Fm, alpha, na, ns, previous_age_stage_dist)
pi_mix_TV(Ff, Fm, alpha, na, ns, previous_age_stage_dist)
Ff |
matrix. Block-structured matrix which counts reproduction by females and assigns newborns an age and stage |
Fm |
matrix. Block-structured matrix which counts reproduction by males and assigns newborns an age and stage |
alpha |
scalar. Birth ratio male:female |
na |
scalar. Number of age-classes |
ns |
scalar. Number of stages |
previous_age_stage_dist |
vector. Last years population structure (agestagesex full distribution) |
list (of vectors). list[1] = full agestagesex distribution list[2] = female agestage distribution normalised list[3] = male agestage distribution normalised list[4] = female marginal age distribution normalised list[5] = male marginal age distribution normalised
Mixing distributions for the time-variant multi-state 2-sex model: Parity-specific case
pi_mix_TV_parity(Ff, Fm, alpha, na, ns, previous_age_stage_dist)
pi_mix_TV_parity(Ff, Fm, alpha, na, ns, previous_age_stage_dist)
Ff |
matrix. Block-structured matrix which counts reproduction by females and assigns newborns an age and stage |
Fm |
matrix. Block-structured matrix which counts reproduction by males and assigns newborns an age and stage |
alpha |
scalar. Birth ratio male:female |
na |
scalar. Number of age-classes |
ns |
scalar. Number of stages |
previous_age_stage_dist |
vector. Last years population structure (agestagesex full distribution) |
Uf |
matrix. Block-structured matrix which transfers females over stage and advances their age |
Um |
matrix. Block-structured matrix which transfers males over stage and advances their age |
list (of vectors). list[1] = full agestagesex distribution list[2] = female agestage distribution normalised list[3] = male agestage distribution normalised list[4] = female marginal age distribution normalised list[5] = male marginal age distribution normalised
Draws a Keyfitz-style kinship diagram given a kinship object created by the kin
function. Displays expected kin counts for a Focal aged 'a'.
plot_diagram(kin_total, rounding = 3)
plot_diagram(kin_total, rounding = 3)
kin_total |
data.frame. values in column |
rounding |
numeric. Number of decimals to show in diagram. |
A Keyfitz-style kinship plot.
Add kin labels depending the sex
rename_kin(df, sex = "f")
rename_kin(df, sex = "f")
df |
data.frame. A data frame with variable |
sex |
character. "f" for female, "m" for male or "2sex" for both sex naming. |
See table demokin_codes
to know label options.
Add a column with kin labels in the input data frame.
Female Slovakian fertility rates by parity stage in 1990 (Caswell, 2021)
svk_fxs
svk_fxs
A matrix of fx with stages as cols and ages as rows.
Caswell (2021)
Age where assign offspring of individuals in each partity stage (Caswell, 2021). All to zero age in this case.
svk_Hxs
svk_Hxs
A matrix of ones in ages where assign offspring individuals, with stages as cols and ages as rows.
Caswell (2021)
Female Slovakian survival probabilities by parity stage in 1990 (Caswell, 2021)
svk_pxs
svk_pxs
A matrix of px with stages as cols and ages as rows.
Caswell (2021)
Probability of transition among parity stage for Slovakia in 1990, for each age, conditional on survival (Caswell, 2021).
svk_Uxs
svk_Uxs
A list of column-stochastic matrix with probabilities of transition among parity stage, for each age, conditional on survival.
Caswell (2021)
Swedish age-specific fertility rates from 1900 to 2015
swe_asfr
swe_asfr
A matrix with years as cols and ages (0 to 100 as OAG) as rows.
HMD/HFD
Female swedish population from 1900 to 2015
swe_pop
swe_pop
A matrix with years as cols and ages (0 to 100 as OAG) as rows.
HMD/HFD
Female swedish survival probabilities from 1900 to 2015
swe_px
swe_px
A matrix with years as cols and ages (0 to 100 as OAG) as rows.
HMD/HFD
Female swedish survival ratios from 1900 to 2015
swe_Sx
swe_Sx
A matrix with years as cols and ages (0 to 100 as OAG) as rows.
HMD/HFD
one time projection kin. internal function.
timevarying_kin(Ut, ft, pit, ages, pkin)
timevarying_kin(Ut, ft, pit, ages, pkin)
Ut |
numeric. A matrix of survival probabilities (or ratios). |
ft |
numeric. A matrix of age-specific fertility rates. |
pit |
numeric. A matrix with distribution of childbearing. |
ages |
numeric. |
pkin |
numeric. A list with kin count distribution in previous year. |
A list of 14 types of kin matrices (kin age by Focal age) projected one time interval.
one time projection kin. internal function.
timevarying_kin_2sex(Ut, Ft, Ft_star, pit, sex_focal, ages, pkin)
timevarying_kin_2sex(Ut, Ft, Ft_star, pit, sex_focal, ages, pkin)
Ut |
numeric. A matrix of survival probabilities (or ratios). |
Ft |
numeric. A matrix of age-specific fertility rates. |
Ft_star |
numeric. Ft but for female fertility. |
pit |
numeric. A matrix with distribution of childbearing. |
sex_focal |
character. "f" for female or "m" for male. |
ages |
numeric. |
pkin |
numeric. A list with kin count distribution in previous year. |
A list of 14 types of kin matrices (kin age by Focal age, blocked for two sex) projected one time interval.
one time projection kin. internal function.
timevarying_kin_2sex_cod(Ut, Ft, Ft_star, pit, sex_focal, ages, pkin)
timevarying_kin_2sex_cod(Ut, Ft, Ft_star, pit, sex_focal, ages, pkin)
Ut |
numeric. A matrix of survival probabilities (or ratios). |
Ft |
numeric. A matrix of age-specific fertility rates. |
Ft_star |
numeric. Ft but for female fertility. |
pit |
numeric. A matrix with distribution of childbearing. |
sex_focal |
character. "f" for female or "m" for male. |
ages |
numeric. |
pkin |
numeric. A list with kin count distribution in previous year. |
A list of 14 types of kin matrices (kin age by Focal age, blocked for two sex) projected one time interval.
Historic and projected survival ratios from Sweden used in Caswell (2021)
U_caswell_2021
U_caswell_2021
A matrix U with years as cols and ages as rows.
Caswell (2019)