Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
99c8049
depend forcats
IvanWilli Nov 4, 2022
9b8c0db
Merge pull request #10 from IvanWilli/updates
IvanWilli Nov 4, 2022
76df243
fix no pi or N case
IvanWilli Nov 19, 2022
5ad8a47
Merge pull request #1 from IvanWilli/main
alburezg Jan 4, 2023
f9bb9e5
Added labels to plot_diagram
alburezg Jan 4, 2023
75c1bc3
increased y-limit of igraph
alburezg Jan 4, 2023
1e247e5
Merge pull request #14 from alburezg/main
IvanWilli Jan 11, 2023
bcbdcef
adding 2sex model + vignette
IvanWilli Jan 24, 2023
972d5c1
general 2sexkin
IvanWilli Jan 27, 2023
47ade30
document 2sex
IvanWilli Jan 29, 2023
9deb29b
pre load cran
IvanWilli Feb 4, 2023
4595bb9
Merge branch 'main' into updates
IvanWilli Feb 4, 2023
38ed1ea
Merge pull request #15 from IvanWilli/updates
IvanWilli Feb 4, 2023
1a14b1c
when pi added in 2sex variant
IvanWilli Feb 8, 2023
b489170
fix vector sex_kin
IvanWilli Feb 10, 2023
2dcf899
dtplyr conflict
IvanWilli Feb 10, 2023
323128b
age_kin correction
IvanWilli Feb 15, 2023
f8b84fd
Merge pull request #19 from IvanWilli/updates
IvanWilli Feb 15, 2023
135129a
pivot_longer specify values_to
IvanWilli Mar 10, 2023
1fe0dfd
pi for 2 sex fix
IvanWilli Mar 16, 2023
c80c9d5
variant no pi fix
IvanWilli Apr 27, 2023
6eb6449
pi_N_null_flag
IvanWilli Apr 28, 2023
f45a1c0
preparing cran
IvanWilli May 19, 2023
89ace42
reassign deaths
IvanWilli May 24, 2023
8fc1ec8
fix reassign d
IvanWilli May 24, 2023
222e021
preparing for cran
IvanWilli May 24, 2023
7f288e3
version
IvanWilli May 24, 2023
ec457d7
Increment version number to 1.0.2
IvanWilli May 24, 2023
377ff94
fixing cran feedback
IvanWilli May 26, 2023
3660c05
updated citations
alburezg May 26, 2023
414a3da
removed extra ref file
alburezg May 26, 2023
1d81eec
fixing cran, adding biblio
IvanWilli May 26, 2023
b3f5387
Increment version number to 1.0.3
IvanWilli May 26, 2023
f54cd02
preapare cran
IvanWilli Jun 4, 2023
db6ae98
updated readme after cran release
alburezg Jun 9, 2023
2e90b91
start building time invariant for 2 sex by cause of death
Feb 6, 2024
6cdccb5
created functions for cod
Feb 13, 2024
725e173
script to compare functions with/without cod
Feb 20, 2024
29ecf60
add description in top of scripts
Feb 21, 2024
fe64c82
issues pending
IvanWilli Mar 8, 2024
87994e1
Merge pull request #29 from benjisamschlu/cod_ben
IvanWilli Mar 18, 2024
afede1c
Merge pull request #30 from IvanWilli/cod
IvanWilli Mar 18, 2024
bd626f2
adding cod and vignette
IvanWilli Mar 18, 2024
85830e4
updated vignette COD
alburezg Sep 17, 2024
1202f19
Merge pull request #32 from alburezg/main
IvanWilli Sep 18, 2024
5784565
Update README.md
IvanWilli Sep 24, 2024
ae5e0dc
commiting files to my fork
Oct 24, 2024
9aec5b4
removing function documentation -- optional
Oct 24, 2024
8dd7ad7
using tictoc in DESC
Oct 24, 2024
7d633aa
removing n_inc
Oct 24, 2024
fef1248
re-naming data (to show we use list)
Oct 24, 2024
9c71361
updating vignette
Oct 24, 2024
95607fd
updating vignette
Oct 24, 2024
1bc314d
testthat file -- we don't need to pre-load data now
Oct 24, 2024
4abf7e4
updating vignette
Oct 24, 2024
74039f5
Working on vignette
Oct 25, 2024
dce01e5
vignette
Oct 25, 2024
48eeaa2
vignette
Oct 25, 2024
02f702d
vignette
Oct 25, 2024
16aeb25
vignette
Oct 25, 2024
4a3ebf1
vignette
Oct 25, 2024
590b087
testing rda files
Oct 25, 2024
6998f19
rda
Oct 25, 2024
04c88a0
Setting data files as rda for pre-loading
Oct 26, 2024
4dd7229
removing old RDS extensions
Oct 26, 2024
62aaa1a
Merge pull request #35 from ButterickJoe/main
IvanWilli Nov 12, 2024
3c59fbd
include multi_stage 2 sex time var
IvanWilli Nov 13, 2024
6025af2
clean multi_state_variant + fix issues
IvanWilli Jan 8, 2025
a860fba
fixing age-year increments
ButterickJoe Feb 21, 2025
4ce6324
fixing age-year increments
ButterickJoe Feb 21, 2025
3b2e90a
age year
ButterickJoe Feb 21, 2025
f96f8a5
fixing time and age inc
ButterickJoe Feb 21, 2025
7e98a86
removing old
ButterickJoe Feb 21, 2025
738cda7
fixing
ButterickJoe Feb 21, 2025
3313af7
Merge branch 'main' into main
IvanWilli Feb 26, 2025
7d2c4f9
Merge pull request #43 from ButterickJoe/main
IvanWilli Feb 26, 2025
3025030
home
IvanWilli Apr 23, 2025
52ea6ba
home git
IvanWilli Apr 23, 2025
81933c4
Revert "Updating function to allow user to select output years with t…
IvanWilli Apr 24, 2025
ca0752e
Merge pull request #44 from IvanWilli/revert-43-main
IvanWilli Apr 24, 2025
a289975
web
IvanWilli Apr 24, 2025
5a0c571
remove devtools from vignettes
IvanWilli Apr 24, 2025
555138f
devtools inlcuding, removing library(DemoKin)
IvanWilli Apr 24, 2025
566a5cf
add pkgdown
IvanWilli Apr 24, 2025
8e53ca5
prepare using demokin-web
IvanWilli Apr 24, 2025
ff59d89
fuera reads
IvanWilli Apr 24, 2025
56eaf10
remove readr
IvanWilli Apr 24, 2025
9d8347a
readme
IvanWilli Apr 24, 2025
0f80df5
navbar custom
IvanWilli Apr 25, 2025
b52577d
custom ref
IvanWilli Apr 25, 2025
ef487a4
custom readme
IvanWilli Apr 25, 2025
8e5f694
add ctbs
IvanWilli Apr 30, 2025
b861994
corr authors/colabs
IvanWilli May 14, 2025
a5a428a
auth corr
IvanWilli May 14, 2025
600c877
add coll
IvanWilli May 16, 2025
d168692
papers
IvanWilli May 22, 2025
f2eb387
papers
IvanWilli May 22, 2025
2e382fb
Add files via upload
ButterickJoe Jun 3, 2025
932f26e
Update kin_multi_stage_time_variant_2sex.R
ButterickJoe Jun 3, 2025
7481930
Delete kin_multi_stage_time_variant_2sex.R
ButterickJoe Jun 3, 2025
810a27d
Merge pull request #45 from ButterickJoe/main
IvanWilli Jun 4, 2025
e28ef28
show plot readme
IvanWilli Jun 5, 2025
a0edaa1
Merge branch 'main' of https://github.com/IvanWilli/DemoKin
IvanWilli Jun 5, 2025
9267590
improve plot readme
IvanWilli Jun 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
^\.Rproj\.user$
^README\.Rmd$
^LICENSE\.md$
^cran-comments\.md$
^CRAN-SUBMISSION$
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
release:
types: [published]
workflow_dispatch:

name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
folder: docs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ diego.txt
.m
.mat
.csv
docs
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.3
Date: 2023-06-04 13:27:38 UTC
SHA: f54cd023b2e6bb2de1e74d1d0c89c13828149c44
30 changes: 21 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
Package: DemoKin
Title: Demokin
Description: Estimate population kin counts and its distribution by type and age
Version: 1.0.0
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.
Version: 1.0.3
Authors@R: c(
person("Iván", "Williams", email = "act.ivanwilliams@gmail.com", role = "cre"),
person("Iván", "Williams", email = "act.ivanwilliams@gmail.com", role = c("aut", "cre")),
person("Diego", "Alburez-Gutierrez", email = "alburezgutierrez@demogr.mpg.de", role = "aut"),
person("Xi", "Song", email = "xisong@sas.upenn.edu", role = "ctb"))
person("Xi", "Song", email = "xisong@sas.upenn.edu", role = "ctb"),
person("Hal", "Caswell", email = "caswell@demogr.mpg.de", role = "ctb"),
person("Benjamin", "Schlüter", email = "benjamin.schluter@utoronto.ca", role = "ctb"),
person("Joe", "Butterick", email = "J.Butterick@soton.ac.uk", role = "ctb"),
person("Sha", "Jiang", email = "jiang@demogr.mpg.de", role = "ctb"))
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
ggplot2,
pkgdown
VignetteBuilder: knitr
Imports:
dplyr,
tidyr,
purrr,
HMDHFDplus,
progress,
matrixcalc,
Matrix,
MASS,
stats,
igraph,
magrittr,
lifecycle
data.table,
lifecycle,
tictoc,
reshape2
URL: https://github.com/IvanWilli/DemoKin,
https://ivanwilli.github.io/DemoKin/
BugReports: https://github.com/IvanWilli/DemoKin/issues
Depends:
R (>= 2.10)
Expand Down
12 changes: 10 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(demokin_codes)
export(get_HMDHFD)
export(kin)
export(kin2sex)
export(kin_multi_stage)
export(kin_multi_stage_time_variant_2sex)
export(kin_time_invariant)
export(kin_time_invariant_2sex)
export(kin_time_invariant_2sex_cod)
export(kin_time_variant)
export(kin_time_variant_2sex)
export(kin_time_variant_2sex_cod)
export(output_period_cohort_combination)
export(plot_diagram)
export(rename_kin)
export(timevarying_kin)
export(timevarying_kin_2sex)
export(timevarying_kin_2sex_cod)
importFrom(magrittr,"%>%")
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# DemoKin 1.0.3

# DemoKin 1.0.2

# DemoKin 1.0.1

# DemoKin 1.0.0

* Added a `NEWS.md` file to track changes to the package.
* Change stable/non-stable references to time varying/non-varying rates.
* Add multi-state process.

# DemoKin 1.0.1
* Submitted to CRAN
* Death counts are placed in the age where Focal experience the death.
* Aggregated kin types are allowed (`s` for older and younger sisters, for example).
60 changes: 14 additions & 46 deletions R/aux_funs.R
Original file line number Diff line number Diff line change
@@ -1,49 +1,17 @@

#' print kin codes
#' @description Print kin codes and labels
#' @export
demokin_codes <- function(){
codes <- c("coa", "cya", "d", "gd", "ggd", "ggm", "gm", "m", "nos", "nys", "oa", "ya", "os", "ys")
caswell_codes <- c("t", "v", "a", "b", "c", "h", "g", "d", "p", "q", "r", "s", "m", "n")
labels <- c("Cousins from older aunt", "Cousins from younger aunt", "Daughter", "Grand-daughter", "Great-grand-daughter", "Great-grandmother", "Grandmother", "Mother", "Nieces from older sister", "Nieces from younger sister", "Aunt older than mother", "Aunt younger than mother", "Older sister", "Younger sister")
data.frame(DemoKin = codes, Caswell = caswell_codes, Label = labels, row.names = NULL)
}

#' rename kin
#' @description Rename kin labels depending consolidate some types
#' @export
rename_kin <- function(df, consolidate_column = "no"){

stopifnot("Argument 'consolidate_column' should be 'no' or a valid column name" = consolidate_column %in% c("no", colnames(df)))

if(consolidate_column == "no"){

relatives <- c("Cousins from older aunt", "Cousins from younger aunt", "Daughter", "Grand-daughter", "Great-grand-daughter", "Great-grandmother", "Grandmother", "Mother", "Nieces from older sister", "Nieces from younger sister", "Aunt older than mother", "Aunt younger than mother", "Older sister", "Younger sister")
names(relatives) <- c("coa", "cya", "d", "gd", "ggd", "ggm", "gm", "m", "nos", "nys", "oa", "ya", "os", "ys")

} else {

# Combine kin types irrespective of whether they come from older
# or younger sibling lines
consolidate_vec <- c("c", "c", "d", "gd", "ggd", "ggm", "gm", "m", "n", "n", "a", "a", "s", "s")
names(consolidate_vec) <- c("coa", "cya", "d", "gd", "ggd", "ggm", "gm", "m", "nos", "nys", "oa", "ya", "os", "ys")

# Rename kin types from codes to actual words
relatives <- c("Cousins", "Daughter", "Grand-daughter", "Great-grand-daughter", "Great-grandmother", "Grandmother", "Mother", "Nieces", "Aunt", "Sister")
names(relatives) <- unique(consolidate_vec)

df <- as.data.frame(df)
df$count <- df[ , consolidate_column]

df <-
df %>%
dplyr::mutate(kin = consolidate_vec[kin]) %>%
dplyr::group_by(age_focal, kin) %>%
dplyr::summarise(count = sum(count)) %>%
dplyr::ungroup()


}
df$kin <- relatives[df$kin]
df
#' @description Add kin labels depending the sex
#' @details See table `demokin_codes` to know label options.
#' @param df data.frame. A data frame with variable `kin` with `DemoKin` codes to be labelled.
#' @param sex character. "f" for female, "m" for male or "2sex" for both sex naming.
#' @return Add a column with kin labels in the input data frame.
#' @export
rename_kin <- function(df, sex = "f"){
if(!"kin" %in% names(df)) stop("Input df needs a column named kin.")
if(sex == "f") demokin_codes_sex <- DemoKin::demokin_codes[,c("DemoKin", "Labels_female")]
if(sex == "m") demokin_codes_sex <- DemoKin::demokin_codes[,c("DemoKin", "Labels_male")]
if(sex == "2sex") demokin_codes_sex <- DemoKin::demokin_codes[,c("DemoKin", "Labels_2sex")]
colnames(demokin_codes_sex) <- c("kin", "kin_label")
df %>%
dplyr::left_join(demokin_codes_sex)
}
129 changes: 127 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,99 @@
#' Female swedish survival ratios from 1900 to 2015
#'
#' Singapore: List of matrices that redistribute newborns to age-class 1 and "no education" category
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"H_mat_edu"

#' Singapore: Lists of transition matrices showing probabilities of moving between education states. Females
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"T_mat_fem_edu"

#' Singapore: Lists of transition matrices showing probabilities of moving between education states. Males
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"T_mat_male_edu"

#' Singapore: Lists of matrices containing fertility rates by age and education. Females
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"F_mat_fem_edu"

#' Singapore: Lists of matrices containing fertility rates by age and education. Males
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"F_mat_male_edu"

#' Singapore: Lists of matrices containing survival probabilities by age (rows) and education (columns) from 2020-2090. Females
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"U_mat_fem_edu"

#' Singapore: Lists of matrices containing survival probabilities by age (rows) and education (columns) from 2020-2090. Males
#' @docType data
#' @format
#' The data is aggregated into 5-year age groups and 5-year time intervals
#' @source
#' Wittgenstein Center
"U_mat_male_edu"

#' UK female fertility from 1965 to 2022
#' @docType data
#' @format
#' list of age by stage matrices, entries give female fert. List starting 1965 ending 2022.
#' @source
#' HFD and ONS
"Female_parity_fert_list_UK"

#' UK female parity transitions from 1965 to 2022
#' @docType data
#' @format
#' list of age by stage matrices, entries give female parity transitions. List starting 1965 ending 2022.
#' @source
#' HFD and ONS
"Parity_transfers_by_age_list_UK"

#' UK female parity mortality from 1965 to 2022
#' @docType data
#' @format
#' list of age by stage matrices, entries give female parity mortality List starting 1965 ending 2022.
#' @source
#' HFD and ONS
"Female_parity_mortality_list_UK"

#' UK male parity mortality from 1965 to 2022
#' @docType data
#' @format
#' list of age by stage matrices, entries give male parity mortality List starting 1965 ending 2022.
#' @source
#' HFD and ONS
"Male_parity_mortality_list_UK"

#' UK parity assign parity at birth
#' @docType data
#' @format
#' list of matrices which redistributes newborns to age-class 1 and parity 0. No time-variation.
#' @source
#' None
"Redistribution_by_parity_list_UK"

#' Female swedish survival ratios from 1900 to 2015
#' @docType data
#' @format
Expand Down Expand Up @@ -127,3 +221,34 @@
#' @source
#' Caswell (2021)
"kin_svk1990_caswell2020"

#' Fertility for France (2012) by sex in Caswell (2022).
#'
#' Fertility for France (2012) by sex in Caswell (2022).
#' @docType data
#' @format
#' A data.frame with age specific fertility rates by age and sex.
#'
#' @source
#' Caswell (2022)
"fra_asfr_sex"

#' Survival probability for France (2012) by sex in Caswell (2022).
#'
#' Survival probability for France (2012) by sex in Caswell (2022).
#' @docType data
#' @format
#' A data.frame with survival probabilities by age and sex.
#'
#' @source
#' Caswell (2022)
"fra_surv_sex"

#' DemoKin codes, Caswell (2020) codes, and useful labels.
#'
#' DemoKin codes, Caswell (2020) codes, and useful labels.
#' @docType data
#' @format
#' A data.frame with codes and labels for distinction between kin types.

"demokin_codes"
Loading