Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to DemoKin up to uploading to CRAN #1

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
^\.Rproj\.user$
^README\.Rmd$
^LICENSE\.md$
^cran-comments\.md$
^CRAN-SUBMISSION$
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
19 changes: 12 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
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 = "[email protected]", role = "cre"),
person("Diego", "Alburez-Gutierrez", email = "[email protected]", role = "aut"),
person("Xi", "Song", email = "[email protected]", role = "ctb"))
person("Xi", "Song", email = "[email protected]", role = "ctb"),
person("Caswell", "Hal", email = "[email protected]", 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
VignetteBuilder: knitr
Imports:
dplyr,
tidyr,
purrr,
HMDHFDplus,
progress,
matrixcalc,
Matrix,
MASS,
stats,
igraph,
magrittr,
data.table,
lifecycle
URL: https://github.com/IvanWilli/DemoKin
BugReports: https://github.com/IvanWilli/DemoKin/issues
Depends:
R (>= 2.10)
Expand Down
11 changes: 9 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# 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_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)
}
31 changes: 31 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,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"
125 changes: 0 additions & 125 deletions R/get_HMDHFD.R

This file was deleted.

Loading