├── .Rbuildignore ├── .gitattributes ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── CODE_OF_CONDUCT.html ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.html ├── CONTRIBUTING.md ├── DESCRIPTION ├── LICENSE ├── LICENSE-text.html ├── NAMESPACE ├── NEWS.md ├── R ├── AGEINT.R ├── AGESEX.R ├── CENSUR.R ├── DemoTools-package.R ├── GRPOPYB.R ├── IRDID.R ├── LIFIT.R ├── MAV.R ├── OGIVE.R ├── OPAG.R ├── SPENCER.R ├── ZELNIK.R ├── ZIGZAG.R ├── basepop.R ├── check_heaping.R ├── data.R ├── extra_mortality.R ├── graduate.R ├── interp_coh.R ├── interp_lc_lim.R ├── interp_lc_lim_group.R ├── log_quad_augm.R ├── lt_abridged.R ├── lt_id.R ├── lt_model_lq.R ├── lt_regroup_age.R ├── lt_rule.R ├── lt_single.R ├── lt_single_qx.R ├── mig_beta.R ├── mig_rc.R ├── mig_resid.R ├── mig_un_fam.R ├── nAx.R ├── smooth_age_5.R ├── splitOscillate.R ├── utils-pipe.R ├── utils.R ├── utilsAge.R └── utils_downloads.R ├── README.md ├── _pkgdown.yml ├── authors.html ├── codecov.yml ├── data-raw └── examples_migresid.R ├── data ├── ages_asfr_five.rda ├── ages_asfr_single.rda ├── ages_five.rda ├── ages_single.rda ├── asfr_mat_five.rda ├── asfr_mat_single.rda ├── dth5_zigzag.rda ├── e0_swe.rda ├── fitted_logquad_b.rda ├── fitted_logquad_f.rda ├── fitted_logquad_m.rda ├── mA_swe.rda ├── mig_un_families.rda ├── mig_un_params.rda ├── pop1m_ind.rda ├── pop1m_pasex.rda ├── pop1m_rus2002.rda ├── pop1m_rus2010.rda ├── pop5_mat.rda ├── pop5m_pasex.rda ├── popA_earlier.rda ├── popA_later.rda ├── pop_f_mat_five.rda ├── pop_f_mat_single.rda ├── pop_m_mat_five.rda ├── pop_m_mat_single.rda ├── sr_f_mat_five.rda ├── sr_f_mat_single.rda ├── sr_m_mat_five.rda ├── sr_m_mat_single.rda ├── srb_vec_five.rda └── srb_vec_single.rda ├── dev ├── .gitignore ├── ADJAGE.R ├── AGEINT.R ├── AGESEX.R ├── AGESMTH.R ├── BASEPOP.R ├── Bachi.R ├── Beers.R ├── BeersMSplit.R ├── BeersOInterpol.R ├── CENSUR.R ├── CoaleLi.R ├── Data │ ├── .gitignore │ └── ModelLTcoefs.R ├── FunctionInventory.csv ├── GRPOPYB.R ├── IRDID.R ├── LIFIT.R ├── LTPOPDTH.R ├── LTidentities.R ├── LTrulesofthumb.R ├── LTsingle.R ├── Myers.R ├── Noumbissi.R ├── OPAG.R ├── OPAG_refactor.R ├── ReadIn.R ├── Spoorenberg.R ├── Sprague.R ├── SpragueOscillate.R ├── SpragueSplit.R ├── T95RL.R ├── Whipple.R ├── ZIGZAG.R ├── aomegaMortalityLaws.R ├── arriaga_tidy.R ├── brassNotes.R ├── build.R ├── build_tests.R ├── data-define-reusable.R ├── default.R ├── ediev.R ├── graduate.R ├── greville.mortpak.R ├── hex.R ├── ik-startup-lines-rebiuld-DT.R ├── ik-startup-lines.R ├── ik-wrap-hmd-train-wilmoth-objects.R ├── lt_model_cd.R ├── lt_model_lq-dev.R ├── mig_resid_sa.R ├── mig_resid_singleTest.R ├── nAx.R ├── ogive.R ├── sawtooth.R ├── splitHomogenize.R └── utils.R ├── docs ├── 404.html ├── CODE_OF_CONDUCT.html ├── CONTRIBUTING.html ├── LICENSE-text.html ├── apple-touch-icon-120x120.png ├── apple-touch-icon-152x152.png ├── apple-touch-icon-180x180.png ├── apple-touch-icon-60x60.png ├── apple-touch-icon-76x76.png ├── apple-touch-icon.png ├── articles │ ├── Age-heaping_quality_with_Demotools.html │ ├── Age-heaping_quality_with_Demotools_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ └── unnamed-chunk-9-1.png │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.9 │ │ │ └── header-attrs.js │ ├── case_study_1.html │ ├── case_study_1_files │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.9 │ │ │ └── header-attrs.js │ ├── graduation_with_demotools.html │ ├── graduation_with_demotools_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-3-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ ├── unnamed-chunk-5-1.png │ │ │ ├── unnamed-chunk-6-1.png │ │ │ └── unnamed-chunk-7-1.png │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.9 │ │ │ └── header-attrs.js │ ├── index.html │ ├── lifetables_with_demotools.html │ ├── lifetables_with_demotools_files │ │ ├── crosstalk-1.1.0.1 │ │ │ ├── css │ │ │ │ └── crosstalk.css │ │ │ └── js │ │ │ │ ├── crosstalk.js │ │ │ │ ├── crosstalk.js.map │ │ │ │ ├── crosstalk.min.js │ │ │ │ └── crosstalk.min.js.map │ │ ├── crosstalk-1.1.1 │ │ │ ├── css │ │ │ │ └── crosstalk.css │ │ │ └── js │ │ │ │ ├── crosstalk.js │ │ │ │ ├── crosstalk.js.map │ │ │ │ ├── crosstalk.min.js │ │ │ │ └── crosstalk.min.js.map │ │ ├── datatables-binding-0.15 │ │ │ └── datatables.js │ │ ├── datatables-binding-0.16 │ │ │ └── datatables.js │ │ ├── datatables-binding-0.17 │ │ │ └── datatables.js │ │ ├── datatables-binding-0.18 │ │ │ └── datatables.js │ │ ├── datatables-css-0.0.0 │ │ │ └── datatables-crosstalk.css │ │ ├── dt-core-1.10.20 │ │ │ ├── css │ │ │ │ ├── jquery.dataTables.extra.css │ │ │ │ └── jquery.dataTables.min.css │ │ │ └── js │ │ │ │ └── jquery.dataTables.min.js │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.9 │ │ │ └── header-attrs.js │ │ ├── htmlwidgets-1.5.1 │ │ │ └── htmlwidgets.js │ │ ├── htmlwidgets-1.5.2 │ │ │ └── htmlwidgets.js │ │ ├── htmlwidgets-1.5.3 │ │ │ └── htmlwidgets.js │ │ ├── jquery-1.12.4 │ │ │ ├── LICENSE.txt │ │ │ └── jquery.min.js │ │ └── jquery-3.5.1 │ │ │ ├── jquery-AUTHORS.txt │ │ │ ├── jquery.js │ │ │ ├── jquery.min.js │ │ │ └── jquery.min.map │ ├── migration_with_demotools.html │ ├── migration_with_demotools_files │ │ ├── figure-html │ │ │ ├── unnamed-chunk-1-1.png │ │ │ ├── unnamed-chunk-2-1.png │ │ │ ├── unnamed-chunk-4-1.png │ │ │ └── unnamed-chunk-7-1.png │ │ ├── header-attrs-2.10 │ │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ │ └── header-attrs.js │ │ └── header-attrs-2.9 │ │ │ └── header-attrs.js │ ├── smoothing_with_demotools.html │ └── smoothing_with_demotools_files │ │ ├── figure-html │ │ ├── unnamed-chunk-1-1.png │ │ ├── unnamed-chunk-2-1.png │ │ ├── unnamed-chunk-3-1.png │ │ ├── unnamed-chunk-4-1.png │ │ ├── unnamed-chunk-5-1.png │ │ ├── unnamed-chunk-6-1.png │ │ ├── unnamed-chunk-7-1.png │ │ ├── unnamed-chunk-8-1.png │ │ └── unnamed-chunk-9-1.png │ │ ├── header-attrs-2.10 │ │ └── header-attrs.js │ │ ├── header-attrs-2.8 │ │ └── header-attrs.js │ │ └── header-attrs-2.9 │ │ └── header-attrs.js ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── index.html ├── link.svg ├── logo.png ├── news │ └── index.html ├── package-logo.png ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml ├── reference │ ├── ADM.html │ ├── AGEN.html │ ├── Bachi.html │ ├── CoaleLi.html │ ├── DemoTools-package.html │ ├── DemoTools-renamed.html │ ├── ID.html │ ├── IRD.html │ ├── Jdanov.html │ ├── KannistoHeap.html │ ├── LTabr.html │ ├── Lx2Tx.html │ ├── Lxlx2Sx.html │ ├── M04_2_D0.html │ ├── M04_2_M0.html │ ├── Myers.html │ ├── Noumbissi.html │ ├── OPAG.html │ ├── OPAG_fit_stable_standard.html │ ├── OPAG_nLx_warp_r.html │ ├── OPAG_r_min.html │ ├── OPAG_simple.html │ ├── RDM.html │ ├── Rplot001.png │ ├── Spoorenberg.html │ ├── T9R5L.html │ ├── Whipple.html │ ├── adjustAge.html │ ├── age2ageN.html │ ├── age2int.html │ ├── ageRatioScore.html │ ├── ageSexAccuracy.html │ ├── ageSexAccuracyDasGupta.html │ ├── age_abridge_force.html │ ├── ages_asfr_five.html │ ├── ages_asfr_single.html │ ├── ages_five.html │ ├── ages_single.html │ ├── agesmth.html │ ├── agesmth1.html │ ├── aomegaMortalityLaws.html │ ├── arriaga_smth.html │ ├── asfr_mat_five.html │ ├── asfr_mat_single.html │ ├── avg_adj.html │ ├── ax.greville.mortpak.html │ ├── axPAS.html │ ├── axUN.html │ ├── basepop.html │ ├── basepop_five.html │ ├── beers.html │ ├── beersExpand.html │ ├── birthCohorts.html │ ├── calcAgeAbr.html │ ├── calcAgeN.html │ ├── carrier_farrag_smth.html │ ├── census_cohort_adjust.html │ ├── check_heaping_bachi.html │ ├── check_heaping_coale_li.html │ ├── check_heaping_jdanov.html │ ├── check_heaping_kannisto.html │ ├── check_heaping_myers.html │ ├── check_heaping_noumbissi.html │ ├── check_heaping_roughness.html │ ├── check_heaping_sawtooth.html │ ├── check_heaping_spoorenberg.html │ ├── check_heaping_whipple.html │ ├── coef.extra_mortality.html │ ├── dec.date.html │ ├── downloadAsfr.html │ ├── downloadSRB.html │ ├── downloadnLx.html │ ├── dth5_zigzag.html │ ├── e0_swe.html │ ├── extra_mortality-1.png │ ├── extra_mortality.html │ ├── fetch_wpp_births.html │ ├── find.my.case.html │ ├── find_my_case.html │ ├── fitted_logquad_b.html │ ├── fitted_logquad_f.html │ ├── fitted_logquad_m.html │ ├── five_year_roughness.html │ ├── getModelLifeTable.html │ ├── geta0CD.html │ ├── geta1_4CD.html │ ├── grabill.html │ ├── grabillExpand.html │ ├── graduate.html │ ├── graduate_beers.html │ ├── graduate_beers_expand.html │ ├── graduate_beers_johnson.html │ ├── graduate_grabill.html │ ├── graduate_grabill_expand.html │ ├── graduate_mono.html │ ├── graduate_mono_closeout.html │ ├── graduate_pclm-1.png │ ├── graduate_pclm.html │ ├── graduate_sprague.html │ ├── graduate_sprague_expand.html │ ├── graduate_uniform.html │ ├── groupAges.html │ ├── groupOAG.html │ ├── heapify-1.png │ ├── heapify.html │ ├── index.html │ ├── inferAgeIntAbr.html │ ├── int2age.html │ ├── int2ageN.html │ ├── interp.html │ ├── interp_coh.html │ ├── interp_coh_bare.html │ ├── interp_lc_lim.html │ ├── interp_lc_lim_abk_m.html │ ├── interp_lc_lim_estimate.html │ ├── interp_lc_lim_group.html │ ├── interp_lc_lim_kt_min.html │ ├── interpolatePop.html │ ├── is_LeapYear.html │ ├── is_abridged.html │ ├── is_age_coherent.html │ ├── is_age_redundant.html │ ├── is_age_sequential.html │ ├── is_single.html │ ├── johnsonAdjust.html │ ├── kkn_smth.html │ ├── loess_smth1.html │ ├── lt_a_closeout.html │ ├── lt_a_pas.html │ ├── lt_a_un.html │ ├── lt_abridged.html │ ├── lt_abridged2single.html │ ├── lt_ambiguous.html │ ├── lt_ax_closeout.html │ ├── lt_id_L_T.html │ ├── lt_id_Ll_S.html │ ├── lt_id_d_l.html │ ├── lt_id_d_q.html │ ├── lt_id_l_d.html │ ├── lt_id_l_q.html │ ├── lt_id_lda_L.html │ ├── lt_id_m_q.html │ ├── lt_id_ma_q.html │ ├── lt_id_ma_q_robust.html │ ├── lt_id_morq_a.html │ ├── lt_id_morq_a_greville.html │ ├── lt_id_q_l.html │ ├── lt_id_qa_m.html │ ├── lt_id_qm_a.html │ ├── lt_model_lq.html │ ├── lt_rule_1a0.html │ ├── lt_rule_1a0_ak.html │ ├── lt_rule_1a0_cd.html │ ├── lt_rule_4a1_cd.html │ ├── lt_rule_4m0_D0.html │ ├── lt_rule_4m0_m0.html │ ├── lt_rule_ak.html │ ├── lt_rule_ak_m0_a0.html │ ├── lt_rule_ak_q0_a0.html │ ├── lt_rule_m_extrapolate-1.png │ ├── lt_rule_m_extrapolate.html │ ├── lt_single2abridged.html │ ├── lt_single_mx.html │ ├── lt_single_qx.html │ ├── lt_single_simple.html │ ├── lt_smooth_ambiguous.html │ ├── lthat.logquad.html │ ├── lx2dx.html │ ├── lxdxax2Lx.html │ ├── mA_swe.html │ ├── ma.html │ ├── mav.html │ ├── mav_smth.html │ ├── maxA2abridged.html │ ├── mig_beta.html │ ├── mig_calculate_rc-1.png │ ├── mig_calculate_rc.html │ ├── mig_estimate_rc-1.png │ ├── mig_estimate_rc.html │ ├── mig_resid.html │ ├── mig_resid_stock.html │ ├── mig_un_fam.html │ ├── mig_un_families.html │ ├── mig_un_params.html │ ├── monoCloseout.html │ ├── mx2qx.html │ ├── mxax2qx.html │ ├── mxax2qx_Backstop.html │ ├── mxorqx2ax.html │ ├── names2age.html │ ├── pipe.html │ ├── poly_smth1.html │ ├── pop1m_ind.html │ ├── pop1m_pasex.html │ ├── pop1m_rus2002.html │ ├── pop1m_rus2010.html │ ├── pop5_mat.html │ ├── pop5m_pasex.html │ ├── popA_earlier.html │ ├── popA_later.html │ ├── pop_f_mat_five.html │ ├── pop_f_mat_single.html │ ├── pop_m_mat_five.html │ ├── pop_m_mat_single.html │ ├── print.extra_mortality.html │ ├── qx2lx.html │ ├── qxax2mx.html │ ├── qxmx2ax.html │ ├── ratx.html │ ├── rescale.vector.html │ ├── rescaleAgeGroups.html │ ├── rescale_vector.html │ ├── rlog.html │ ├── sexRatioScore.html │ ├── shift.vector.html │ ├── shift_census_ages_to_cohorts.html │ ├── simplify.text.html │ ├── single2abridged.html │ ├── smooth_age_5.html │ ├── smooth_age_5_arriaga.html │ ├── smooth_age_5_cf.html │ ├── smooth_age_5_feeney.html │ ├── smooth_age_5_kkn.html │ ├── smooth_age_5_mav.html │ ├── smooth_age_5_strong.html │ ├── smooth_age_5_un.html │ ├── smooth_age_5_zigzag.html │ ├── smooth_age_5_zigzag_inner.html │ ├── smooth_age_5_zigzag_min.html │ ├── smooth_age_5_zigzag_p.html │ ├── spencer.html │ ├── splitMono.html │ ├── splitOscillate.html │ ├── splitUniform.html │ ├── sprague.html │ ├── spragueExpand.html │ ├── sr_f_mat_five.html │ ├── sr_f_mat_single.html │ ├── sr_m_mat_five.html │ ├── sr_m_mat_single.html │ ├── srb_vec_five.html │ ├── srb_vec_single.html │ ├── strong_smth.html │ ├── surv10.html │ ├── surv5.html │ ├── survN.html │ ├── survRatioError.html │ ├── united_nations_smth.html │ ├── ypart.html │ ├── zelnik.html │ ├── zero_pref_sawtooth.html │ ├── zigzag.html │ ├── zigzag_min.html │ ├── zigzag_p.html │ └── zigzag_smth.html └── sitemap.xml ├── index.html ├── inst └── REFERENCES.bib ├── logo.png ├── man ├── ADM.Rd ├── AGEN.Rd ├── DemoTools-package.Rd ├── HMD_old_logquad.Rd ├── ID.Rd ├── IRD.Rd ├── OPAG.Rd ├── OPAG_fit_stable_standard.Rd ├── OPAG_nLx_warp_r.Rd ├── OPAG_r_min.Rd ├── OPAG_simple.Rd ├── RDM.Rd ├── age2ageN.Rd ├── age2int.Rd ├── ageRatioScore.Rd ├── ageSexAccuracy.Rd ├── ageSexAccuracyDasGupta.Rd ├── age_abridge_force.Rd ├── ages_asfr_five.Rd ├── ages_asfr_single.Rd ├── ages_five.Rd ├── ages_single.Rd ├── agesmth1.Rd ├── asfr_mat_five.Rd ├── asfr_mat_single.Rd ├── avg_adj.Rd ├── basepop_five.Rd ├── birthCohorts.Rd ├── calcAgeAbr.Rd ├── calcAgeN.Rd ├── check_heaping_bachi.Rd ├── check_heaping_coale_li.Rd ├── check_heaping_jdanov.Rd ├── check_heaping_kannisto.Rd ├── check_heaping_myers.Rd ├── check_heaping_noumbissi.Rd ├── check_heaping_roughness.Rd ├── check_heaping_sawtooth.Rd ├── check_heaping_spoorenberg.Rd ├── check_heaping_whipple.Rd ├── dec.date.Rd ├── downloadAsfr.Rd ├── downloadSRB.Rd ├── downloadnLx.Rd ├── dth5_zigzag.Rd ├── e0_swe.Rd ├── fetch_wpp_births.Rd ├── find_my_case.Rd ├── fitted_logquad_b.Rd ├── fitted_logquad_f.Rd ├── fitted_logquad_m.Rd ├── getModelLifeTable.Rd ├── graduate.Rd ├── graduate_beers.Rd ├── graduate_beers_expand.Rd ├── graduate_beers_johnson.Rd ├── graduate_grabill.Rd ├── graduate_grabill_expand.Rd ├── graduate_mono.Rd ├── graduate_mono_closeout.Rd ├── graduate_pclm.Rd ├── graduate_sprague.Rd ├── graduate_sprague_expand.Rd ├── graduate_uniform.Rd ├── groupAges.Rd ├── groupOAG.Rd ├── heapify.Rd ├── inferAgeIntAbr.Rd ├── int2age.Rd ├── int2ageN.Rd ├── interp.Rd ├── interp_coh.Rd ├── interp_lc_lim.Rd ├── interp_lc_lim_abk_m.Rd ├── interp_lc_lim_estimate.Rd ├── interp_lc_lim_group.Rd ├── interp_lc_lim_kt_min.Rd ├── interpolatePop.Rd ├── is_abridged.Rd ├── is_age_coherent.Rd ├── is_age_redundant.Rd ├── is_age_sequential.Rd ├── is_single.Rd ├── loess_smth1.Rd ├── logquad_augmented.Rd ├── lt_a_closeout.Rd ├── lt_a_pas.Rd ├── lt_a_un.Rd ├── lt_abridged.Rd ├── lt_abridged2single.Rd ├── lt_ambiguous.Rd ├── lt_id_L_T.Rd ├── lt_id_Ll_S.Rd ├── lt_id_d_l.Rd ├── lt_id_d_q.Rd ├── lt_id_l_d.Rd ├── lt_id_l_q.Rd ├── lt_id_lda_L.Rd ├── lt_id_ma_q.Rd ├── lt_id_morq_a.Rd ├── lt_id_morq_a_greville.Rd ├── lt_id_q_l.Rd ├── lt_id_qa_m.Rd ├── lt_id_qm_a.Rd ├── lt_model_lq.Rd ├── lt_rule_1a0.Rd ├── lt_rule_1a0_ak.Rd ├── lt_rule_1a0_cd.Rd ├── lt_rule_4a1_cd.Rd ├── lt_rule_4m0_D0.Rd ├── lt_rule_4m0_m0.Rd ├── lt_rule_ak_m0_a0.Rd ├── lt_rule_ak_q0_a0.Rd ├── lt_rule_m_extrapolate.Rd ├── lt_single2abridged.Rd ├── lt_single_mx.Rd ├── lt_single_qx.Rd ├── lt_smooth_ambiguous.Rd ├── lthat.logquad.Rd ├── mA_swe.Rd ├── ma.Rd ├── mav.Rd ├── maxA2abridged.Rd ├── mig_beta.Rd ├── mig_calculate_rc.Rd ├── mig_estimate_rc.Rd ├── mig_resid.Rd ├── mig_un_fam.Rd ├── mig_un_families.Rd ├── mig_un_params.Rd ├── names2age.Rd ├── pipe.Rd ├── poly_smth1.Rd ├── pop1m_ind.Rd ├── pop1m_pasex.Rd ├── pop1m_rus2002.Rd ├── pop1m_rus2010.Rd ├── pop5_mat.Rd ├── pop5m_pasex.Rd ├── popA_earlier.Rd ├── popA_later.Rd ├── pop_f_mat_five.Rd ├── pop_f_mat_single.Rd ├── pop_m_mat_five.Rd ├── pop_m_mat_single.Rd ├── ratx.Rd ├── rescaleAgeGroups.Rd ├── rescale_vector.Rd ├── rlog.Rd ├── sexRatioScore.Rd ├── shift.vector.Rd ├── shift_census_ages_to_cohorts.Rd ├── simplify.text.Rd ├── single2abridged.Rd ├── smooth_age_5.Rd ├── smooth_age_5_arriaga.Rd ├── smooth_age_5_cf.Rd ├── smooth_age_5_feeney.Rd ├── smooth_age_5_kkn.Rd ├── smooth_age_5_mav.Rd ├── smooth_age_5_strong.Rd ├── smooth_age_5_un.Rd ├── smooth_age_5_zigzag.Rd ├── smooth_age_5_zigzag_inner.Rd ├── smooth_age_5_zigzag_min.Rd ├── smooth_age_5_zigzag_p.Rd ├── spencer.Rd ├── splitOscillate.Rd ├── sr_f_mat_five.Rd ├── sr_f_mat_single.Rd ├── sr_m_mat_five.Rd ├── sr_m_mat_single.Rd ├── srb_vec_five.Rd ├── srb_vec_single.Rd ├── surv10.Rd ├── surv5.Rd ├── survN.Rd ├── survRatioError.Rd └── zelnik.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── testthat.R └── testthat │ ├── test-AGEHEAP.R │ ├── test-AGESEX.R │ ├── test-CENSUR.R │ ├── test-IRDID.R │ ├── test-OPAG.R │ ├── test-basepop.R │ ├── test-fn_name_check_message.R │ ├── test-graduate.R │ ├── test-interp_coh.R │ ├── test-lt_abridged.R │ ├── test-lt_model_lq.R │ ├── test-mig_beta.R │ ├── test-mig_resid.R │ ├── test-smooth_age_5.R │ ├── test-spencer.R │ ├── test-utils.R │ ├── test-utilsage.R │ ├── test-zelnik.R │ ├── test-zigzag.R │ ├── test_AGEINT.R │ ├── test_interp_lc_lim.R │ └── test_mig_un_fam.R ├── version_lookup.R ├── version_lookup.csv └── vignettes ├── .gitignore ├── Age-heaping_quality_with_Demotools.Rmd ├── REFERENCES.bib ├── case_study_1.Rmd ├── graduation_with_demotools.Rmd ├── lifetables_with_demotools.Rmd ├── migration_with_demotools.Rmd └── smoothing_with_demotools.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^Meta$ 2 | ^doc$ 3 | ^.project* 4 | ^.gitignore* 5 | dev 6 | devdata 7 | ^appveyor\.yml$ 8 | ^\.travis\.yml$ 9 | ^codecov\.yml$ 10 | ^.*\.Rproj$ 11 | ^\.Rproj\.user$ 12 | ^CODE_OF_CONDUCT\.md$ 13 | ^CONTRIBUTING\.md$ 14 | ^docs$ 15 | ^_pkgdown\.yml$ 16 | ^pkgdown$ 17 | CODE_OF_CONDUCT.html 18 | CONTRIBUTING.html 19 | LICENSE-text.html 20 | authors.html 21 | index.html 22 | logo.png 23 | DemoToolsHexTests 24 | Spreadsheets 25 | ^\.ccache$ 26 | ^\.github$ 27 | ^tic\.R$ 28 | rcppExports.cpp 29 | stanExports_* 30 | ^data-raw$ 31 | version_lookup.R 32 | version_lookup.csv 33 | .gitsum 34 | Presentations 35 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | data/* binary 3 | src/* text=lf 4 | R/* text=lf 5 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Meta 2 | doc 3 | /.settings/ 4 | /.project 5 | /devdata/ 6 | *.Rhistory 7 | /inst/REFERENCES.bib.bak 8 | .Rproj.user 9 | *.Rproj 10 | # History files 11 | .Rhistory 12 | .Rapp.history 13 | .DS_Store 14 | inst/doc 15 | DemoToolsHexTests 16 | Spreadsheets 17 | *.cc 18 | *.cpp 19 | *.h 20 | *.o 21 | *.so 22 | .gitsum 23 | .RData 24 | /doc/ 25 | /Meta/ 26 | Presentations 27 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: DemoTools 2 | Type: Package 3 | Title: Standardize, Evaluate, and Adjust Demographic Data 4 | Version: 01.13.83 5 | Date: 2024-12-06 6 | Authors@R: c( 7 | person("Tim", "Riffe", role = c("aut", "cre"), 8 | email = "tim.riffe@gmail.com", comment = c(ORCID = "0000-0002-2673-4622")), 9 | person("José Manuel", "Aburto", role = "aut", comment = c(ORCID = "0000-0002-2926-6879")), 10 | person("Ilya", "Kashnitsky", role = "aut", comment = c(ORCID = "0000-0003-1835-8687")), 11 | person("Monica", "Alexander", role = "aut", comment = c(ORCID = "0000-0002-8135-3435")), 12 | person("Marius D.", "Pascariu", role = "aut", comment = c(ORCID = "0000-0002-2568-6489")), 13 | person("Sara", "Hertog", role = "aut"), 14 | person("Sean", "Fennell", role = "aut"), 15 | person("Peter", "Johnson", role = "ctb"), 16 | person("Jorge", "Cimentada", role = "ctb", comment = c(ORCID = "0000-0001-5594-1156")), 17 | person("Juan", "Galeano", role = "ctb", comment = c(ORCID = "0000-0002-3682-1797")), 18 | person("Derek", "Burk", role = "ctb"), 19 | person("Greg", "Freedman Ellis", role = "ctb")) 20 | Description: A collection of classic demographic methods used to evaluate, adjust, and standardize demographic data. 21 | License: file LICENSE 22 | LazyLoad: yes 23 | LazyData: true 24 | Roxygen: list(markdown = TRUE) 25 | RoxygenNote: 7.3.1 26 | Depends: 27 | R (>= 3.6), 28 | Rcpp (>= 0.12.0), 29 | Suggests: 30 | covr, 31 | testthat (>= 2.1.0), 32 | knitr, 33 | rmarkdown, 34 | markdown, 35 | DT, 36 | ggplot2 37 | RdMacros: Rdpack 38 | Imports: 39 | data.table (>= 1.13.6), 40 | demogR, 41 | DemoToolsData (>= 0.1.5), 42 | dplyr, 43 | fertestr (>= 0.10.00), 44 | lubridate, 45 | magrittr, 46 | MortalityLaws (>= 1.7.0), 47 | Rdpack, 48 | rlang, 49 | rstan (>= 2.18.1), 50 | tibble, 51 | tidybayes, 52 | ungroup (>= 1.4.2) 53 | BugReports: https://github.com/timriffe/DemoTools/issues 54 | Remotes: 55 | github::timriffe/fertestr, 56 | github::timriffe/DemoToolsData, 57 | github::timriffe/MortalityLaws 58 | Encoding: UTF-8 59 | VignetteBuilder: knitr 60 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # Changes in this update 2 | 3 | ## 2018-08-15 4 | 5 | - NEWS.md file added. When a first release comes out, major functionality 6 | and features will be listed here at that time. 7 | 8 | ## 2019-11-28 9 | 10 | - new function mig_calculate_rc() added 11 | - several function names harmonized, see ?DemoTools-renamed 12 | - graduate_sprague() and other graduation functions no longer support matrix inputs 13 | 14 | ## 2023-12-29 15 | - minor fixes to pass checks 16 | 17 | -------------------------------------------------------------------------------- /R/DemoTools-package.R: -------------------------------------------------------------------------------- 1 | 2 | # DemoTools: Standardize, Evaluate, and Adjust Demographic Data 3 | # "_PACKAGE" imports the details from DESCRIPTION 4 | 5 | #' @import demogR Rdpack 6 | #' @import Rcpp 7 | #' @importFrom MortalityLaws MortalityLaw 8 | #' @importFrom stats coef predict 9 | #' @importFrom Rdpack reprompt 10 | #' @name DemoTools-package 11 | #' @docType package 12 | "_PACKAGE" 13 | NULL 14 | 15 | # examples forthcoming 16 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | -------------------------------------------------------------------------------- /data/ages_asfr_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/ages_asfr_five.rda -------------------------------------------------------------------------------- /data/ages_asfr_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/ages_asfr_single.rda -------------------------------------------------------------------------------- /data/ages_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/ages_five.rda -------------------------------------------------------------------------------- /data/ages_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/ages_single.rda -------------------------------------------------------------------------------- /data/asfr_mat_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/asfr_mat_five.rda -------------------------------------------------------------------------------- /data/asfr_mat_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/asfr_mat_single.rda -------------------------------------------------------------------------------- /data/dth5_zigzag.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/dth5_zigzag.rda -------------------------------------------------------------------------------- /data/e0_swe.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/e0_swe.rda -------------------------------------------------------------------------------- /data/fitted_logquad_b.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/fitted_logquad_b.rda -------------------------------------------------------------------------------- /data/fitted_logquad_f.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/fitted_logquad_f.rda -------------------------------------------------------------------------------- /data/fitted_logquad_m.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/fitted_logquad_m.rda -------------------------------------------------------------------------------- /data/mA_swe.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/mA_swe.rda -------------------------------------------------------------------------------- /data/mig_un_families.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/mig_un_families.rda -------------------------------------------------------------------------------- /data/mig_un_params.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/mig_un_params.rda -------------------------------------------------------------------------------- /data/pop1m_ind.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop1m_ind.rda -------------------------------------------------------------------------------- /data/pop1m_pasex.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop1m_pasex.rda -------------------------------------------------------------------------------- /data/pop1m_rus2002.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop1m_rus2002.rda -------------------------------------------------------------------------------- /data/pop1m_rus2010.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop1m_rus2010.rda -------------------------------------------------------------------------------- /data/pop5_mat.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop5_mat.rda -------------------------------------------------------------------------------- /data/pop5m_pasex.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop5m_pasex.rda -------------------------------------------------------------------------------- /data/popA_earlier.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/popA_earlier.rda -------------------------------------------------------------------------------- /data/popA_later.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/popA_later.rda -------------------------------------------------------------------------------- /data/pop_f_mat_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop_f_mat_five.rda -------------------------------------------------------------------------------- /data/pop_f_mat_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop_f_mat_single.rda -------------------------------------------------------------------------------- /data/pop_m_mat_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop_m_mat_five.rda -------------------------------------------------------------------------------- /data/pop_m_mat_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/pop_m_mat_single.rda -------------------------------------------------------------------------------- /data/sr_f_mat_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/sr_f_mat_five.rda -------------------------------------------------------------------------------- /data/sr_f_mat_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/sr_f_mat_single.rda -------------------------------------------------------------------------------- /data/sr_m_mat_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/sr_m_mat_five.rda -------------------------------------------------------------------------------- /data/sr_m_mat_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/sr_m_mat_single.rda -------------------------------------------------------------------------------- /data/srb_vec_five.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/srb_vec_five.rda -------------------------------------------------------------------------------- /data/srb_vec_single.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/data/srb_vec_single.rda -------------------------------------------------------------------------------- /dev/.gitignore: -------------------------------------------------------------------------------- 1 | /test.R 2 | /Prof/ 3 | /Deprecated/ 4 | transitivitytests.R 5 | scratch.R 6 | junk.R 7 | testLT.R 8 | lx2.RData 9 | -------------------------------------------------------------------------------- /dev/ADJAGE.R: -------------------------------------------------------------------------------- 1 | # Author: sean 2 | ############################################################################### 3 | # 4 | #Males <- c(423, 1654, 1523, 1475, 1482, 1356, 1321, 1298, 1121, 1023, 974, 968, 859, 824, 756, 723, 652, 622) 5 | #Females <- c(401, 1608, 1498, 1450, 1465, 1345, 1338, 1295, 1156, 1098, 1036, 987, 867, 882, 755, 746, 823, 875) 6 | #DesiredTotalMale <- 23657 7 | #DesiredTotalFemale <- 24764 8 | 9 | #' proportionally adjust a population age distribution to a new total. 10 | #' @description The adjustment factor for each age is the ratio of the desired population total divided by the initial population total. This adjustment factor is used to adjust each age group to the new total. 11 | #' This comes from the PAS spreadsheet called ADJAGE. 12 | 13 | #' @param Value numeric. A vector of demographic population counts. 14 | #' @param DesiredTotal integer. An integer giving the desired total population. 15 | 16 | #' @details The age group structure of the output is the same as that of the input. This function does not adjust for unknown age groups. 17 | 18 | #' @return a vector of the adjusted population. 19 | #' 20 | #' @export 21 | #' 22 | #' @examples 23 | #' Males <- c(423, 1654, 1523, 1475, 1482, 1356, 1321, 1298, 1121, 1023, 974, 968, 859, 824, 756, 723, 652, 622) 24 | #' Females <- c(401, 1608, 1498, 1450, 1465, 1345, 1338, 1295, 1156, 1098, 1036, 987, 867, 882, 755, 746, 823, 875) 25 | #' DesiredTotalMale <- 23657 26 | #' DesiredTotalFemale <- 24764 27 | #' adjustAge(Males, DesiredTotalMale) 28 | #' adjustAge(Females, DesiredTotalFemale) 29 | #' adjustAge(Males+Females, DesiredTotalMale+DesiredTotalFemale) 30 | 31 | adjustAge <- function(Value, DesiredTotal){ 32 | 33 | valueSum <- sum(Value) 34 | 35 | adjustFactor <- DesiredTotal/valueSum 36 | 37 | adjustValues <- round(Value*adjustFactor) 38 | 39 | return(adjustValues) 40 | } -------------------------------------------------------------------------------- /dev/BASEPOP.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: tim 3 | ############################################################################### 4 | 5 | # PAS BASEPOP spreadsheet. 6 | 7 | # census date 8 | ReferenceDate <- 1986.21 9 | 10 | 11 | date1 <- 1977.31 12 | date2 <- 1986.50 13 | Lx1 <- c(87732, 304435, 361064) 14 | Lx2 <- c(88451, 310605, 370362) 15 | 16 | # from spreadsheet E64-E66 17 | result1test <- c(88389, 310075, 369563) 18 | result2test <- c(88233, 308732, 367539) 19 | result3test <- c(87842, 305375, 362480) 20 | result1 <- interpolatePop( 21 | Pop1 = Lx1, 22 | Pop2 = Lx2, 23 | Date1 = date1, 24 | Date2 = date2, 25 | DesiredDate = ReferenceDate - .5, 26 | method = "linear") 27 | result2 <- interpolatePop( 28 | Pop1 = Lx1, 29 | Pop2 = Lx2, 30 | Date1 = date1, 31 | Date2 = date2, 32 | DesiredDate = ReferenceDate - 2.5, 33 | method = "linear") 34 | result3 <- interpolatePop( 35 | Pop1 = Lx1, 36 | Pop2 = Lx2, 37 | Date1 = date1, 38 | Date2 = date2, 39 | DesiredDate = ReferenceDate - 7.5, 40 | method = "linear") 41 | stopifnot(all((round(result1) - result1test) == 0)) 42 | stopifnot(all((round(result2) - result2test) == 0)) 43 | stopifnot(all((round(result2) - result2test) == 0)) 44 | 45 | # but can it extrapolate if necessary? 46 | # this will work just the same for asfr. Would like to allow for arbitrary number of 47 | # input Lx vectors. Also ideally in varying shape and size. can do 2d linear approx: 48 | # first over age to get matching ages, then over time to get desired ref points. 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /dev/Data/.gitignore: -------------------------------------------------------------------------------- 1 | /IND_Pop2015B1_1.7.csv 2 | fitted_logquad_b.rda 3 | fitted_logquad_f.rda 4 | fitted_logquad_m.rda 5 | -------------------------------------------------------------------------------- /dev/ReadIn.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: tim 3 | ############################################################################### 4 | 5 | setwd("/home/tim/workspace/DemoTools") 6 | 7 | #D1 <- read.csv("data/Deaths_1x1.csv") 8 | D5 <- read.csv("data/Deaths_5x1.csv") 9 | 10 | dim(D5) 11 | unique(D1$AgeSpan) 12 | unique(D5$AgeSpan) 13 | head(D5[D5$TimeLabel == 1817 & D5$IndicatorID == 195 & D5$SexID == 1, ]) 14 | 15 | D1 <- D5[D5$TimeLabel == 1820 & D5$IndicatorID == 195 & D5$SexID == 1 & D5$SubGroupTypeID == 2, ] 16 | D1 <- D1[order(D1$AgeStart), ] 17 | 18 | # D1$DataValue is the value column, deaths or population... 19 | # AgeStart is the lower bound of the Age group 20 | # AgeSpan is the interval of the age group (-1 is open) 21 | 22 | getYear <- function(X){ 23 | # TimeLabel ought to be integer, and this should be the year, 24 | # but not necessarily so. It is contained in the TimeStart column, 25 | # which ought to be coercible to Date class, but which is coded 26 | # with an ambiguous date. The strategy is therefore to take 27 | # TimeMid and subtract half of TimeDuration. 28 | # This will not yield an integer if data aren't annualized 29 | 30 | X$Year <- X$TimeMid - X$TimeDuration / 2 31 | X 32 | } 33 | #D1 <- getYear(D1) 34 | #head(D1) 35 | 36 | 37 | # get an example 38 | 39 | -------------------------------------------------------------------------------- /dev/Spoorenberg.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: tim 3 | ############################################################################### 4 | 5 | #' Spoorenbergs total modified Whipple index 6 | 7 | #' @description This index consists in calculating the Noumbissi index, Wi, for each 8 | #' terminal digit, then taking the sum of the absolute deviations of these from unity. 9 | 10 | #' @param Value a vector of demographic counts by single age 11 | #' @param Age a vector of ages corresponding to the lower integer bound of the counts 12 | #' @param ageMin the lowest age included in calcs. Default 20 13 | #' @param ageMax the upper age bound used for calcs. Default 65 14 | #' @return the index value 15 | #' 16 | #' @details \code{ageMin} and \code{ageMax} are applied to numerator ages, not denominators. 17 | #' Denominators are always 5-year age groups centered on the digit in question, 18 | #' and these therefore stretch into ages a bit higher or lower than the numerator ages. 19 | #' 20 | #' @export 21 | 22 | Spoorenberg <- function(Value, Age, ageMin = 20, ageMax = 65){ 23 | 24 | digits <- 0:9 25 | Wi <- sapply(digits, 26 | Noumbissi, 27 | Value = Value, 28 | Age = Age, 29 | ageMin = ageMin, 30 | ageMax = ageMax) 31 | Wtot <- sum(abs(1 - Wi)) 32 | return(Wtot) 33 | } 34 | -------------------------------------------------------------------------------- /dev/aomegaMortalityLaws.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: tim 3 | ############################################################################### 4 | 5 | 6 | #' Life expectancy in the open age group. 7 | #' 8 | #' @description Get an estimate of life expectancy in the open age group. 9 | #' @details This method estimates life expectancy in the open age group by fitting one of several potential old-age parametric mortality models, extrapolating rates to age 130, then backing out the implied remaining life expectancy in the open age group. 10 | #' @inheritParams extra_mortality 11 | #' @return life expectancy in the open age group 12 | #' @references 13 | #' \insertRef{mortpak1988}{DemoTools} 14 | #' @export 15 | #' @examples 16 | #' nMx <- c(0.12846,0.02477,0.00603,0.0034, 17 | #' 0.00417,0.00513,0.00581,0.00645,0.00725, 18 | #' 0.00813,0.00913,0.01199,0.01647, 19 | #' 0.0256,0.04047,0.06624,0.10638,0.19611) 20 | #' Age <- c(0,1,seq(5,80,by=5)) 21 | #' 22 | #' 23 | #' aomegaMortalityLaws(nMx,Age,"Kannisto") 24 | #' aomegaMortalityLaws(nMx,Age,"Kannisto_Makeham") 25 | #' aomegaMortalityLaws(nMx,Age,"Makeham") 26 | #' aomegaMortalityLaws(nMx,Age,"Gompertz") 27 | #' aomegaMortalityLaws(nMx,Age,"GGompertz") 28 | #' aomegaMortalityLaws(nMx,Age,extrapLaw="Beard") 29 | #' aomegaMortalityLaws(nMx,Age,"Beard_Makeham") 30 | #' aomegaMortalityLaws(nMx,Age,"Quadratic") 31 | 32 | aomegaMortalityLaws <- function( 33 | mx, 34 | Age, 35 | law = c("kannisto", 36 | "kannisto_makeham", 37 | "gompertz", 38 | "ggompertz", 39 | "makeham", 40 | "beard", 41 | "beard_makeham", 42 | "quadratic")[1], 43 | extrapFrom = max(Age), 44 | extrapFit = Age[Age >= 60], 45 | ...){ 46 | 47 | extrapLaw <- tolower(extrapLaw) 48 | OA <- max(Age) 49 | x_extr <- seq(OA, 130, by = .1) 50 | 51 | Mxnew <- extra_mortality( 52 | mx = nMx, 53 | x = Age, 54 | x_fit = extrapFit, 55 | x_extr = x_extr, 56 | law = extrapLaw, 57 | ...) 58 | 59 | mx <- Mxnew$values[names2age(nMxext)>=OA] 60 | 61 | # acceptable approximation for small intervals 62 | lx <- c(1, exp(-cumsum(mx / 10)),0) 63 | # divide by 10 (interval) and 2 (avg), so 20. 64 | sum(shift.vector(lx, -1) + lx) / 20 65 | 66 | } 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /dev/brassNotes.R: -------------------------------------------------------------------------------- 1 | # Author: tim 2 | ############################################################################### 3 | 4 | # ----------------------------------------------------- 5 | # 6 | blogit <- function(lx){ 7 | lx <- lx/lx[1] 8 | Yx <- log((1-lx)/lx)/2 9 | Yx 10 | } 11 | bexpit <- function(Yx){ 12 | 1 / (1+exp(2*Yx)) 13 | } 14 | 15 | HMD <- local(get(load("/home/tim/git/DistributionTTD/DistributionTTD/Data/HMDresults.Rdata"))) 16 | head(HMD) 17 | 18 | lxs <- HMD$lx[HMD$CNTRY == "SWE" & HMD$Year == 2000 & HMD$Sex == "f"]/1e5 19 | 20 | lxi <- HMD$lx[HMD$CNTRY == "JPN" & HMD$Year == 2010 & HMD$Sex == "f"]/1e5 21 | 22 | Yxs <- blogit(lxs)[-1] 23 | Yxi <- blogit(lxi)[-1] 24 | 25 | plot(Yxs,Yxi) 26 | 27 | abline(lm(Yxi~Yxs)) 28 | mod <- lm(Yxi~Yxs) 29 | 30 | lxa <- c(1,bexpit(predict(mod,data.frame(Yxs=Yxs)))) 31 | 32 | a <- 0:110 33 | plot(a,lxs,type='l') 34 | lines(a, lxi,col="red") 35 | lines(a, lxa, col = "blue",lty=2) 36 | 37 | brass_adjust <- function(lx_in, age_in, lx_standard, age_standard=0:110){ 38 | 39 | stopifnot(all(age_in %in% age_standard)) 40 | 41 | # make ages match- no need for AgeInt if working only with lx... 42 | ind <- age_standard %in% age_in 43 | lxs <- lx_standard[ind] 44 | 45 | # assuming first values 1, turning to Inf 46 | Yxs <- blogit(lxs)[-1] 47 | Yxi <- blogit(lx_in)[-1] 48 | 49 | mod <- lm(Yxi~Yxs) 50 | 51 | # predict again for each age of the standard 52 | Yxi_out <- predict(mod,data.frame(Yxs=Yxs)) 53 | lx_out <- c(1,bexpit(Yxi_out)) 54 | 55 | lx_out 56 | } 57 | 58 | plot(Yxs,Yxi) 59 | abline(v=0);abline(h=0) 60 | abline(a=0,b=1) 61 | abline(lm(Yxi~Yxs)) 62 | 63 | -------------------------------------------------------------------------------- /dev/ik-startup-lines-rebiuld-DT.R: -------------------------------------------------------------------------------- 1 | # Author: IK 2 | # Date: 2018-10-12 3 | # Sturtup lines to work on package development 4 | ################################################################################ 5 | 6 | rstudioapi::restartSession() 7 | library(magrittr) 8 | library(devtools) 9 | library(testthat) 10 | # rebuild the latest version of DemoTools 11 | install_github("timriffe/DemoTools") 12 | library(DemoTools) 13 | -------------------------------------------------------------------------------- /dev/ik-startup-lines.R: -------------------------------------------------------------------------------- 1 | # Author: IK 2 | # Date: 2018-10-12 3 | # Sturtup lines to work on package development 4 | ################################################################################ 5 | 6 | library(tidyverse) 7 | library(magrittr) 8 | library(devtools) 9 | library(testthat) 10 | library(DemoTools) 11 | -------------------------------------------------------------------------------- /dev/lt_model_cd.R: -------------------------------------------------------------------------------- 1 | #=============================================================================== 2 | # Wrap model life tables methods -- Coale Demeny 3 | # Ilya Kashnitsky, ilya.kashnitsky@gmail.com 4 | #=============================================================================== 5 | 6 | 7 | 8 | # Coale Demeny ------------------------------------------------------------ 9 | 10 | lt_model_cd 11 | -------------------------------------------------------------------------------- /docs/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /docs/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /docs/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/articles/Age-heaping_quality_with_Demotools_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/Age-heaping_quality_with_Demotools_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/Age-heaping_quality_with_Demotools_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/Age-heaping_quality_with_Demotools_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/Age-heaping_quality_with_Demotools_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Age-heaping_quality_with_Demotools_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/Age-heaping_quality_with_Demotools_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/case_study_1_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/case_study_1_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/case_study_1_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/graduation_with_demotools_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/graduation_with_demotools_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/crosstalk-1.1.0.1/css/crosstalk.css: -------------------------------------------------------------------------------- 1 | /* Adjust margins outwards, so column contents line up with the edges of the 2 | parent of container-fluid. */ 3 | .container-fluid.crosstalk-bscols { 4 | margin-left: -30px; 5 | margin-right: -30px; 6 | white-space: normal; 7 | } 8 | 9 | /* But don't adjust the margins outwards if we're directly under the body, 10 | i.e. we were the top-level of something at the console. */ 11 | body > .container-fluid.crosstalk-bscols { 12 | margin-left: auto; 13 | margin-right: auto; 14 | } 15 | 16 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 17 | display: inline-block; 18 | padding-right: 12px; 19 | vertical-align: top; 20 | } 21 | 22 | @media only screen and (max-width:480px) { 23 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 24 | display: block; 25 | padding-right: inherit; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/crosstalk-1.1.1/css/crosstalk.css: -------------------------------------------------------------------------------- 1 | /* Adjust margins outwards, so column contents line up with the edges of the 2 | parent of container-fluid. */ 3 | .container-fluid.crosstalk-bscols { 4 | margin-left: -30px; 5 | margin-right: -30px; 6 | white-space: normal; 7 | } 8 | 9 | /* But don't adjust the margins outwards if we're directly under the body, 10 | i.e. we were the top-level of something at the console. */ 11 | body > .container-fluid.crosstalk-bscols { 12 | margin-left: auto; 13 | margin-right: auto; 14 | } 15 | 16 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 17 | display: inline-block; 18 | padding-right: 12px; 19 | vertical-align: top; 20 | } 21 | 22 | @media only screen and (max-width:480px) { 23 | .crosstalk-input-checkboxgroup .crosstalk-options-group .crosstalk-options-column { 24 | display: block; 25 | padding-right: inherit; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/datatables-css-0.0.0/datatables-crosstalk.css: -------------------------------------------------------------------------------- 1 | .dt-crosstalk-fade { 2 | opacity: 0.2; 3 | } 4 | 5 | html body div.DTS div.dataTables_scrollBody { 6 | background: none; 7 | } 8 | 9 | 10 | /* 11 | Fix https://github.com/rstudio/DT/issues/563 12 | If the `table.display` is set to "block" (e.g., pkgdown), the browser will display 13 | datatable objects strangely. The search panel and the page buttons will still be 14 | in full-width but the table body will be "compact" and shorter. 15 | In therory, having this attributes will affect `dom="t"` 16 | with `display: block` users. But in reality, there should be no one. 17 | We may remove the below lines in the future if the upstream agree to have this there. 18 | See https://github.com/DataTables/DataTablesSrc/issues/160 19 | */ 20 | 21 | table.dataTable { 22 | display: table; 23 | } 24 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/dt-core-1.10.20/css/jquery.dataTables.extra.css: -------------------------------------------------------------------------------- 1 | /* Selected rows/cells */ 2 | table.dataTable tr.selected td, table.dataTable td.selected { 3 | background-color: #b0bed9 !important; 4 | } 5 | /* In case of scrollX/Y or FixedHeader */ 6 | .dataTables_scrollBody .dataTables_sizing { 7 | visibility: hidden; 8 | } 9 | 10 | /* The datatables' theme CSS file doesn't define 11 | the color but with white background. It leads to an issue that 12 | when the HTML's body color is set to 'white', the user can't 13 | see the text since the background is white. One case happens in the 14 | RStudio's IDE when inline viewing the DT table inside an Rmd file, 15 | if the IDE theme is set to "Cobalt". 16 | 17 | See https://github.com/rstudio/DT/issues/447 for more info 18 | 19 | This fixes should have little side-effects because all the other elements 20 | of the default theme use the #333 font color. 21 | 22 | TODO: The upstream may use relative colors for both the table background 23 | and the color. It means the table can display well without this patch 24 | then. At that time, we need to remove the below CSS attributes. 25 | */ 26 | div.datatables { 27 | color: #333; 28 | } 29 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/lifetables_with_demotools_files/jquery-1.12.4/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2005, 2014 jQuery Foundation and other contributors, 2 | https://jquery.org/ 3 | 4 | This software consists of voluntary contributions made by many 5 | individuals. For exact contribution history, see the revision history 6 | available at https://github.com/jquery/jquery 7 | 8 | The following license applies to all parts of this software except as 9 | documented below: 10 | 11 | ==== 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining 14 | a copy of this software and associated documentation files (the 15 | "Software"), to deal in the Software without restriction, including 16 | without limitation the rights to use, copy, modify, merge, publish, 17 | distribute, sublicense, and/or sell copies of the Software, and to 18 | permit persons to whom the Software is furnished to do so, subject to 19 | the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be 22 | included in all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 | 32 | ==== 33 | 34 | All files located in the node_modules and external directories are 35 | externally maintained libraries used by this software which have their 36 | own licenses; we recommend you read them, as their terms may differ from 37 | the terms above. 38 | -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/migration_with_demotools_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/migration_with_demotools_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-1-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/articles/smoothing_with_demotools_files/figure-html/unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/header-attrs-2.10/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/header-attrs-2.8/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/articles/smoothing_with_demotools_files/header-attrs-2.9/header-attrs.js: -------------------------------------------------------------------------------- 1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to 2 | // be compatible with the behavior of Pandoc < 2.8). 3 | document.addEventListener('DOMContentLoaded', function(e) { 4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); 5 | var i, h, a; 6 | for (i = 0; i < hs.length; i++) { 7 | h = hs[i]; 8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 9 | a = h.attributes; 10 | while (a.length > 0) h.removeAttribute(a[0].name); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/favicon-16x16.png -------------------------------------------------------------------------------- /docs/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/favicon-32x32.png -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/favicon.ico -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/logo.png -------------------------------------------------------------------------------- /docs/package-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/package-logo.png -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.11.4 2 | pkgdown: 1.6.1 3 | pkgdown_sha: ~ 4 | articles: 5 | Age-heaping_quality_with_Demotools: Age-heaping_quality_with_Demotools.html 6 | case_study_1: case_study_1.html 7 | graduation_with_demotools: graduation_with_demotools.html 8 | lifetables_with_demotools: lifetables_with_demotools.html 9 | migration_with_demotools: migration_with_demotools.html 10 | smoothing_with_demotools: smoothing_with_demotools.html 11 | last_built: 2022-01-17T19:50Z 12 | urls: 13 | reference: https://timriffe.github.io/DemoTools//reference 14 | article: https://timriffe.github.io/DemoTools//articles 15 | 16 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/extra_mortality-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/extra_mortality-1.png -------------------------------------------------------------------------------- /docs/reference/graduate_pclm-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/graduate_pclm-1.png -------------------------------------------------------------------------------- /docs/reference/heapify-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/heapify-1.png -------------------------------------------------------------------------------- /docs/reference/lt_rule_m_extrapolate-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/lt_rule_m_extrapolate-1.png -------------------------------------------------------------------------------- /docs/reference/mig_calculate_rc-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/mig_calculate_rc-1.png -------------------------------------------------------------------------------- /docs/reference/mig_estimate_rc-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/docs/reference/mig_estimate_rc-1.png -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/logo.png -------------------------------------------------------------------------------- /man/AGEN.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{AGEN} 4 | \alias{AGEN} 5 | \title{Trim two age vectors to matching N-year age groups.} 6 | \usage{ 7 | AGEN( 8 | Age1, 9 | Age2, 10 | N = 5, 11 | consecutive = TRUE, 12 | ageMin = 0, 13 | ageMax = max(c(Age1, Age2)) 14 | ) 15 | } 16 | \arguments{ 17 | \item{Age1}{integer. Vector of first age groups (lower bounds).} 18 | 19 | \item{Age2}{integer. Vector of second age groups (lower bounds).} 20 | 21 | \item{N}{integer. Target age group interval (just one number).} 22 | 23 | \item{consecutive}{logical. Whether or not to throw error if resulting age groups not consecutive. Default \code{TRUE}.} 24 | 25 | \item{ageMin}{integer. Optional lower age bound for output.} 26 | 27 | \item{ageMax}{integer. Optional upper age bound for output.} 28 | } 29 | \value{ 30 | Integer vector of the N-year age groups present in both \code{Age1} and \code{Age2}. 31 | } 32 | \description{ 33 | Determining which N-year (e.g. 5-year) age groups two vectors have in common 34 | is helpful for matching vector lengths, and questions of alignment. Used as a utility throughout. 35 | } 36 | \examples{ 37 | Age1 <- seq(0, 100, by = 5) 38 | Age2 <- 0:80 39 | AGEN(Age1, Age2, N = 5) 40 | AGEN(Age1, Age2, N = 5, ageMax = 70) 41 | } 42 | -------------------------------------------------------------------------------- /man/DemoTools-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DemoTools-package.R 3 | \docType{package} 4 | \name{DemoTools-package} 5 | \alias{DemoTools} 6 | \alias{DemoTools-package} 7 | \title{DemoTools: Standardize, Evaluate, and Adjust Demographic Data} 8 | \description{ 9 | A collection of classic demographic methods used to evaluate, adjust, and standardize demographic data. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item Report bugs at \url{https://github.com/timriffe/DemoTools/issues} 15 | } 16 | 17 | } 18 | \author{ 19 | \strong{Maintainer}: Tim Riffe \email{tim.riffe@gmail.com} (\href{https://orcid.org/0000-0002-2673-4622}{ORCID}) 20 | 21 | Authors: 22 | \itemize{ 23 | \item José Manuel Aburto (\href{https://orcid.org/0000-0002-2926-6879}{ORCID}) 24 | \item Ilya Kashnitsky (\href{https://orcid.org/0000-0003-1835-8687}{ORCID}) 25 | \item Monica Alexander (\href{https://orcid.org/0000-0002-8135-3435}{ORCID}) 26 | \item Marius D. Pascariu (\href{https://orcid.org/0000-0002-2568-6489}{ORCID}) 27 | \item Sara Hertog 28 | \item Sean Fennell 29 | } 30 | 31 | Other contributors: 32 | \itemize{ 33 | \item Peter Johnson [contributor] 34 | \item Jorge Cimentada (\href{https://orcid.org/0000-0001-5594-1156}{ORCID}) [contributor] 35 | \item Juan Galeano (\href{https://orcid.org/0000-0002-3682-1797}{ORCID}) [contributor] 36 | \item Derek Burk [contributor] 37 | \item Greg Freedman Ellis [contributor] 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/ID.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/IRDID.R 3 | \name{ID} 4 | \alias{ID} 5 | \title{Index of dissimilarity} 6 | \usage{ 7 | ID(pop1, pop2) 8 | } 9 | \arguments{ 10 | \item{pop1}{numeric. Vector of counts from population 1.} 11 | 12 | \item{pop2}{numeric. Vector of counts from population 2.} 13 | } 14 | \value{ 15 | The value of the index ranging from 0 to infinity.. 16 | } 17 | \description{ 18 | Calculate the index of dissimilarity between two population structures. A returned 19 | value of zero means that the two population have identical structure. A value of 100 means 20 | that the populations have no overlap at all (not likely for populations structured only by age). 21 | This is a simple measure of distribution overlap on the absolute scale. 22 | } 23 | \details{ 24 | Input populations are assumed to be ordered in the same way prior to calling the function. 25 | It is only checked that the vectors are of the same length. The input arguments could indeed be populations structured on multiple 26 | variables (more than just age), as long as they are ordered in the same way. 27 | } 28 | \examples{ 29 | pop1 <- c(7.38,14.16,14.79,17.36,15.11,10.14,8.50,7.28,5.28) 30 | pop2 <- c(6.48,12.27,15.25,15.10,14.66,10.80,8.95,9.28,7.21) 31 | ID(pop1, pop2) # 5.5 reproduces table 7.20 of Siegel & Swanson (2004) 32 | ID(pop1, pop1) # identical = 0 33 | ID(pop1, pop2 * 2) # scale invariant 34 | pop3 <- pop4 <- pop1 35 | pop3[1:5] <- 0 36 | pop4[6:length(pop4)] <- 0 37 | ID(pop3, pop4) # no overlap = 100. 38 | } 39 | \references{ 40 | \insertRef{siegel2004methods}{DemoTools} 41 | } 42 | -------------------------------------------------------------------------------- /man/IRD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/IRDID.R 3 | \name{IRD} 4 | \alias{IRD} 5 | \title{Index of relative difference.} 6 | \usage{ 7 | IRD(pop1, pop2, log = FALSE) 8 | } 9 | \arguments{ 10 | \item{pop1}{numeric. Vector of counts from population 1.} 11 | 12 | \item{pop2}{numeric. Vector of counts from population 2.} 13 | 14 | \item{log}{logical. Default \code{FALSE}. Shall we take the mean of the natural log of ratios?} 15 | } 16 | \value{ 17 | The value of the index ranging from 0 to infinity. 18 | } 19 | \description{ 20 | Calculate the relative percent difference between two population structures. A returned value of zero means that the two population have identical structure. 21 | } 22 | \details{ 23 | Input populations are assumed to be ordered in the same way prior to calling the function. It is only checked that the vectors are of the same length. The input arguments could indeed be populations structured on multiple variables (more than just age), as long as they are ordered in the same way. It is advised to lower the open age group for this method because each age has the same weight. Ages where one population has a zero count and the other does not are thrown out. 24 | 25 | If \code{log = TRUE} then we return a simple mean of the absolute of the log of the element-wise ratios between \code{pop1} and \code{pop2}. In this case it doesn't matter which vector is which. This result is also on a percent scale, and the max is greater than 100. 26 | } 27 | \examples{ 28 | pop1 <- c(7.38,14.16,14.79,17.36,15.11,10.14,8.50,7.28,5.28) 29 | pop2 <- c(6.48,12.27,15.25,15.10,14.66,10.80,8.95,9.28,7.21) 30 | IRD(pop1, pop2) # 6.7 reproduces table 7.20 of Siegel & Swanson (2004) 31 | IRD(pop1,pop1) # identical pops = 0 32 | IRD(pop1, pop1 * 2) # only structure matters 33 | pop3 <- pop1 34 | pop3[1:7] <- 0 35 | IRD(pop1, pop3) # theoretical max > 100 36 | } 37 | -------------------------------------------------------------------------------- /man/OPAG_nLx_warp_r.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/OPAG.R 3 | \name{OPAG_nLx_warp_r} 4 | \alias{OPAG_nLx_warp_r} 5 | \title{Warps a given stationary population into a stable population} 6 | \usage{ 7 | OPAG_nLx_warp_r(Lx1, Age_Lx1, r) 8 | } 9 | \arguments{ 10 | \item{Lx1}{numeric vector of stationary population age structure in arbitrary integer age groups} 11 | 12 | \item{Age_Lx1}{integer vector of lower bounds of age groups of \code{nLx}} 13 | 14 | \item{r}{stable growth rate} 15 | } 16 | \value{ 17 | numeric vector of the transformed \code{nLx}. Note, this vector sums to \code{1}. 18 | } 19 | \description{ 20 | We take \code{nLx} as indicative of a stationary population age structure, 21 | then subject the population structure to long-term growth by a constant rate, \code{r}. 22 | } 23 | \details{ 24 | \code{Lx1} could be any population structure of any scale, as long as you're comfortable 25 | assuming it's stationary and can be warped into stable. For the oldest ages, this is probably 26 | quite often an acceptable and useful approximation. The transformation is applied at the single-age scale, even if the input \code{nLx} is in wider (e.g. abridged) age groups. When needed, we reduce to single ages using (default) \code{graduate_uniform()}, then apply the transformation, then group back. This is innocuous if \code{nLx} is given in single ages. You may want to change \code{method} to \code{"mono"} or \code{"pclm"}. 27 | } 28 | \examples{ 29 | Lx <- downloadnLx(NULL, "Spain","female",1971) 30 | Age <- names2age(Lx) 31 | r <- .01 32 | ai <- age2int(Age) 33 | \dontrun{ 34 | plot(Age, Lx/sum(Lx) / ai, type = 's',ylim = c(0,0.015)) 35 | lines(Age,OPAG_nLx_warp_r(Lx,Age,0.005)/ai,type='s',col = "red") 36 | lines(Age,OPAG_nLx_warp_r(Lx,Age,-0.005)/ai,type='s',col = "blue") 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /man/OPAG_r_min.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/OPAG.R 3 | \name{OPAG_r_min} 4 | \alias{OPAG_r_min} 5 | \title{calculates residual for optimizing growth rate r for OPAG family} 6 | \usage{ 7 | OPAG_r_min(r, Age_fit, Pop_fit, AgeInt_fit, Lx1, Age_Lx1) 8 | } 9 | \arguments{ 10 | \item{r}{given stable growth rate} 11 | 12 | \item{Age_fit}{integer vector of lower bounds for age groups of \code{Pop_fit}} 13 | 14 | \item{Pop_fit}{numeric vector of at least two population counts to use for fitting} 15 | 16 | \item{AgeInt_fit}{integer vector of widths of age groups of \code{Pop_fit}} 17 | 18 | \item{Lx1}{numeric vector of stable population standard by single ages} 19 | 20 | \item{Age_Lx1}{integer vector of lower bounds for age groups of \code{Lx1}} 21 | } 22 | \value{ 23 | numeric. A residual that you're presumably trying to minimize. 24 | } 25 | \description{ 26 | For a given set of age groups to fit against, and a given stable growth rate, $r$, 27 | what is the error implied given the current $r$ and stationary standard? 28 | } 29 | \details{ 30 | This is a utility function for \code{OPAG()}, which needs to optimize $r$ for a 31 | given population vector and stationary standard. 32 | } 33 | \examples{ 34 | # Make up some population data to fit to: 35 | Pop_fit <- c(85000,37000) 36 | Age_fit <- c(70,80) 37 | AgeInt_fit <- c(10,10) 38 | nLx <- downloadnLx(NULL, "Spain","female",1971) 39 | # graduate(nLx, Age_nLx, method = method, constrain = TRUE) 40 | Ageab <- names2age(nLx) 41 | Lx1 <- graduate(c(nLx), Ageab, method = "mono", constrain = TRUE) 42 | Age_Lx1 <- 0:100 43 | r <- .01 44 | 45 | OPAG_r_min(r, 46 | Pop_fit = Pop_fit, 47 | Age_fit = Age_fit, 48 | AgeInt_fit = AgeInt_fit, 49 | Lx1 = Lx1, 50 | Age_Lx1 = Age_Lx1) 51 | 52 | (r_opt <- optimize(OPAG_r_min, 53 | Pop_fit = Pop_fit, 54 | Age_fit = Age_fit, 55 | AgeInt_fit = AgeInt_fit, 56 | Lx1 = Lx1, 57 | Age_Lx1 = Age_Lx1, 58 | interval = c(-0.05,.05))$min) 59 | 60 | } 61 | -------------------------------------------------------------------------------- /man/age2ageN.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{age2ageN} 4 | \alias{age2ageN} 5 | \title{repeat age lower bounds once for each single age} 6 | \usage{ 7 | age2ageN(Age, AgeInt = NULL, OAG = FALSE) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of lower age bounds.} 11 | 12 | \item{AgeInt}{integer vector of age group widths.} 13 | 14 | \item{OAG}{logical. Whether or not the final age group open. Default \code{FALSE}. See details} 15 | } 16 | \value{ 17 | integer vector of elements of \code{Age} repeated once for each implied single age. 18 | } 19 | \description{ 20 | This is a frequent grouping situation. For a given vector of lower age bounds, repeat each value N times, where N is the width of the corresponding age interval. Age intervals are in this case calculated from the original Age vector. 21 | } 22 | \details{ 23 | If \code{OAG = TRUE} then the last value is not repeated, otherwise the final age interval is assumed to be the same width as the penultimate. Here intervals do not need to be of uniform width. 24 | } 25 | \examples{ 26 | age1 <- seq(0,100,by=5) 27 | (ageN1 <- age2ageN(age1, OAG = FALSE)) 28 | (ageN2 <- age2ageN(age1, OAG = TRUE)) 29 | } 30 | -------------------------------------------------------------------------------- /man/age2int.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{age2int} 4 | \alias{age2int} 5 | \title{Infer age class intervals from lower age bounds.} 6 | \usage{ 7 | age2int(Age, OAG = TRUE, OAvalue = NA) 8 | } 9 | \arguments{ 10 | \item{Age}{integer or numeric. Vector of lower age group bounds .} 11 | 12 | \item{OAG}{logical. Whether or not the final age group is open. Default \code{TRUE}.} 13 | 14 | \item{OAvalue}{numeric or integer. The value to use for the final age interval if \code{OAG = TRUE}. Default \code{NA}.} 15 | } 16 | \value{ 17 | Age interval vector, of same length as \code{Age}. 18 | } 19 | \description{ 20 | Determine age class intervals based on a vector of age class lower bounds. 21 | } 22 | \details{ 23 | If the final age group is open, it is given a value of \code{NA} by default, or else a user-determined value. 24 | If the final age group is closed, it is assumed to be equal to the next-lower interval. If the final age interval is 25 | known and not equal to the next lowest interval, specify \code{OAG = TRUE} and assign its value to \code{OAvalue}. 26 | } 27 | \examples{ 28 | # single age examples: 29 | Age <- 0:100 30 | age2int(Age, OAG = TRUE, OAvalue = NA) 31 | age2int(Age, OAG = TRUE, OAvalue = Inf) 32 | age2int(Age, OAG = FALSE) 33 | 34 | # and for abridged ages: 35 | AgeA <- c(0,1,seq(5,85,by=5)) 36 | age2int(AgeA, OAG = TRUE, OAvalue = NA) 37 | age2int(AgeA, OAG = TRUE, OAvalue = Inf) 38 | age2int(AgeA, OAG = FALSE) 39 | } 40 | -------------------------------------------------------------------------------- /man/ageSexAccuracyDasGupta.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AGESEX.R 3 | \name{ageSexAccuracyDasGupta} 4 | \alias{ageSexAccuracyDasGupta} 5 | \title{Calculate Das Gupta's (1995) age sex accuracy index} 6 | \usage{ 7 | ageSexAccuracyDasGupta( 8 | Males, 9 | Females, 10 | Age, 11 | ageMin = 0, 12 | ageMax = max(Age), 13 | OAG = TRUE 14 | ) 15 | } 16 | \arguments{ 17 | \item{Males}{numeric. A vector of demographic counts in 5-year age groups for males.} 18 | 19 | \item{Females}{numeric. A vector of demographic counts in 5-year age groups for females.} 20 | 21 | \item{Age}{numeric. A vector of ages corresponding to the lower integer bound of the counts.} 22 | 23 | \item{ageMin}{integer. The lowest age included in calculations. Default 0.} 24 | 25 | \item{ageMax}{integer. The upper age bound used for calculations. Default \code{max(Age)}.} 26 | 27 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 28 | } 29 | \description{ 30 | Given population counts in 5-year age groups for males and females, follow Das Gupta's steps 31 | to calculate a composite index of the quality of the age and sex structure for a given population. 32 | } 33 | \details{ 34 | It is assumed that the terminal age group is open, in which case it is ignored. 35 | Set \code{OAG = FALSE} if the top age is indeed a closed interval that you want included in calculations. 36 | If \code{ageMax == max(Age)} and \code{OAG} is \code{TRUE}, then \code{ageMax} gets decremented one age class. 37 | } 38 | \examples{ 39 | # data from table for South West Africa (1946) given in reference 40 | Males <- c(2365, 2320, 1859, 1554, 1758, 1534, 1404, 1324, 41 | 1118, 872, 795, 745, 743, 574) 42 | Females <- c(2244, 2248, 1773, 1594, 1616, 1510, 1478, 1320, 43 | 1085, 858, 768, 726, 533, 282) 44 | Age <- seq(0, 65, by = 5) 45 | ageSexAccuracyDasGupta(Males, Females, Age) 46 | # this method is not on the same scale as the others, so don't directly compare. 47 | ageSexAccuracy(Males, Females, Age, method = "das gupta") 48 | } 49 | \references{ 50 | \insertRef{dasgupta1955}{DemoTools} 51 | } 52 | -------------------------------------------------------------------------------- /man/age_abridge_force.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{age_abridge_force} 4 | \alias{age_abridge_force} 5 | \title{force a (count) vector to abridged ages} 6 | \usage{ 7 | age_abridge_force(Value, Age) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{Age}{integer vector, lower bounds of age groups} 13 | } 14 | \description{ 15 | This is a robustness utility, in place to avoid annoying hang-ups in \code{LTAbr()}. If data are given in non-standard ages, they are forced to standard abridged ages on the fly. Really this should happen prior to calling \code{lt_abridged()} 16 | } 17 | \details{ 18 | This should be able to group up and group down as needed. \code{graduate_mono()} is used below the hood. \code{pclm()} or \code{graduate_uniform()} out to be flexible enough to do the same. 19 | } 20 | \examples{ 21 | V1 <- pop1m_ind 22 | Age <- c(0,1,3,seq(5,100,5)) 23 | AgeInt <- c(1,2,2,rep(5,19),1) 24 | Value <- tapply(V1,rep(Age,times=AgeInt), sum) 25 | 26 | is_abridged(Age) 27 | age_abridge_force(Value, Age) 28 | } 29 | \seealso{ 30 | graduate_mono_closeout, lt_abridged 31 | } 32 | -------------------------------------------------------------------------------- /man/ages_asfr_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ages_asfr_five} 5 | \alias{ages_asfr_five} 6 | \title{Ages between 15 and 45 in five year age groups} 7 | \format{ 8 | A vector of length 7 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | ages_asfr_five 15 | } 16 | \description{ 17 | Ages between 15 and 45 in five year age groups for unknown 18 | country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/ages_asfr_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ages_asfr_single} 5 | \alias{ages_asfr_single} 6 | \title{Single ages between 15 and 49} 7 | \format{ 8 | A vector of length 36 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | ages_asfr_single 15 | } 16 | \description{ 17 | Single ages between 15 and 49 for Sweden 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/ages_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ages_five} 5 | \alias{ages_five} 6 | \title{Ages between 0 and 100 abridged in five year age groups} 7 | \format{ 8 | A vector of length 21 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | ages_five 15 | } 16 | \description{ 17 | Ages between 0 and 100 abridged in five year age groups for unknown 18 | country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/ages_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{ages_single} 5 | \alias{ages_single} 6 | \title{Single ages between 0 and 100} 7 | \format{ 8 | A vector of length 101 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | ages_single 15 | } 16 | \description{ 17 | Single ages between 0 and 100 for Sweden, 1999-2019. 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/asfr_mat_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{asfr_mat_five} 5 | \alias{asfr_mat_five} 6 | \title{Age-specific fertility rates for age groups 15 to 45 between 1950 and 2045} 7 | \format{ 8 | A matrix of dimensions 7 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | asfr_mat_five 15 | } 16 | \description{ 17 | Age-specific fertility rates for age groups 15 to 45 between 1950 and 2045 18 | for unknown country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/asfr_mat_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{asfr_mat_single} 5 | \alias{asfr_mat_single} 6 | \title{Age-specific fertility rates for single ages 15 to 49 between 1999 and 2018} 7 | \format{ 8 | A matrix of dimensions 35 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | asfr_mat_single 15 | } 16 | \description{ 17 | Age-specific fertility rates for single ages 15 to 49 between 1999 and 2018 18 | for Sweden 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/avg_adj.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{avg_adj} 4 | \alias{avg_adj} 5 | \title{calculate average of vector elements adjacent to and excluding the index element} 6 | \usage{ 7 | avg_adj(x) 8 | } 9 | \arguments{ 10 | \item{x}{numeric vector} 11 | } 12 | \value{ 13 | numeric vector the same length as \code{x}. 14 | } 15 | \description{ 16 | Calculate average of vector elements adjacent to and excluding the index element. For example, the second element of the result is the average of the first and third elements of the input vector \code{x}. Used by \code{smooth_age_5_zigzag_inner()}, and possibly useful elsewhere. 17 | } 18 | \details{ 19 | Tails are given a value of \code{NA}. 20 | } 21 | \examples{ 22 | x <- 1:10 23 | all(avg_adj(x) == x, na.rm = TRUE) 24 | } 25 | -------------------------------------------------------------------------------- /man/calcAgeAbr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{calcAgeAbr} 4 | \alias{calcAgeAbr} 5 | \title{Calculate which abridged age group single ages belong to.} 6 | \usage{ 7 | calcAgeAbr(Age) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of single ages (lower bound).} 11 | } 12 | \value{ 13 | An integer vector of \code{length(Age)} indicating the abridged age group that each single age belongs to. 14 | } 15 | \description{ 16 | Assign single ages to 5-year abridged age groups. That means that age 0 is kept as a single age, 17 | ages 1-4 are grouped together as abridged age 1, and thereafter 5-year age groups are used. 18 | } 19 | \details{ 20 | In the case that the single \code{Age} vector starts at some age higher than 4, 21 | this is just the same as \code{calcAgeN(Age,5,0)}. 22 | } 23 | \examples{ 24 | Age <- 0:70 25 | calcAgeAbr(Age) 26 | calcAgeN(Age,5,0) 27 | } 28 | -------------------------------------------------------------------------------- /man/calcAgeN.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{calcAgeN} 4 | \alias{calcAgeN} 5 | \title{Calculate which large age group single ages belong to.} 6 | \usage{ 7 | calcAgeN(Age, N = 5, shiftdown = 0) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of single ages (lower bound).} 11 | 12 | \item{N}{integer. Desired width of resulting age groups.} 13 | 14 | \item{shiftdown}{integer. Move the grouping down by one or more single ages. Optional argument.} 15 | } 16 | \value{ 17 | An integer vector of \code{length(Age)} indicating the age group that each single age belongs to. 18 | } 19 | \description{ 20 | Assign single ages to age groups of equal and arbitrary width, and also optionally shifted. 21 | } 22 | \details{ 23 | If you shift the groupings, then the first age groups may have a negative lower bound 24 | (for example of -5). These counts would be discarded for the oscillatory version of Sprague smoothing, 25 | for example, but they are preserved in this function. The important thing to know is that if you shift 26 | the groups, the first and last groups won't be N years wide. For example if \code{shiftdown} is 1, 27 | the first age group is 4-ages wide. 28 | } 29 | \examples{ 30 | Age <- 0:100 31 | calcAgeN(Age) 32 | calcAgeN(Age, N = 4) 33 | calcAgeN(Age, N = 3) 34 | calcAgeN(Age, shiftdown = 1) 35 | calcAgeN(Age, shiftdown = 2) 36 | # can be used to group abridged into equal 5-year intervals 37 | AgeAbr <- c(0,1,5,10,15,20) 38 | calcAgeN(AgeAbr) 39 | } 40 | -------------------------------------------------------------------------------- /man/check_heaping_coale_li.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_heaping.R 3 | \name{check_heaping_coale_li} 4 | \alias{check_heaping_coale_li} 5 | \title{Coale-Li age heaping index} 6 | \usage{ 7 | check_heaping_coale_li( 8 | Value, 9 | Age, 10 | ageMin = 60, 11 | ageMax = max(Age), 12 | terms = 5, 13 | digit = 0 14 | ) 15 | } 16 | \arguments{ 17 | \item{Value}{numeric. A vector of demographic counts by single age.} 18 | 19 | \item{Age}{numeric. A vector of ages corresponding to the lower integer bound of the counts.} 20 | 21 | \item{ageMin}{integer. The lowest age included in calculations. Default 25.} 22 | 23 | \item{ageMax}{integer. The upper age bound used for calculations. Default 65.} 24 | 25 | \item{terms}{integer. Length of the (centered) moving average be. Default 5.} 26 | 27 | \item{digit}{integer. Any digit 0-9. Default 0.} 28 | } 29 | \value{ 30 | The value of the index. 31 | } 32 | \description{ 33 | This implementation is based largely on the sparse verbal description given in 34 | Coale and Li (1991): calculate a two-stage 5-term moving average as a reference pattern, then 35 | take ratios with respect to this. Ratios for a given terminal digit can then be averaged to produce 36 | an index. This procedure was used in that paper for ages 65-100 for mortality rates. 37 | It is probably better suited to rates than counts, but that is not a hard rule. 38 | } 39 | \details{ 40 | \code{digit} could also be a vector of digits, but the more digits one includes (excepting 0 and 5) the closer the index will get to 1. 41 | It is therefore recommended for single digits, or else \code{c(0,5)}. 42 | \code{ageMax} is an inclusive upper bound, treated as interval. 43 | If you want ages 20 to 89, then give \code{ageMin = 20} and \code{ageMax = 89}, not 90. By default all available ages greater than or equal to \code{ageMin} are used. 44 | } 45 | \examples{ 46 | Age <- 0:99 47 | check_heaping_coale_li(pop1m_pasex, Age, 65, 95, 5, 0) # 3.7 48 | check_heaping_coale_li(pop1m_pasex, Age, 65, 95, 5, 5) # 3.5 almost just as high 49 | } 50 | \references{ 51 | \insertRef{coale1991effect}{DemoTools} 52 | } 53 | -------------------------------------------------------------------------------- /man/check_heaping_jdanov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_heaping.R 3 | \name{check_heaping_jdanov} 4 | \alias{check_heaping_jdanov} 5 | \title{Calculate Jdanov's old-age heaping index} 6 | \usage{ 7 | check_heaping_jdanov(Value, Age, Agei = seq(95, 105, by = 5)) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. A vector of demographic counts by single age.} 11 | 12 | \item{Age}{integer. A vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{Agei}{integer. A vector of ages to put in the numerator, default \code{c(95,100,105)}.} 15 | } 16 | \value{ 17 | The value of the index. 18 | } 19 | \description{ 20 | This is a slightly more flexible implementation of Jdanov's formula, with defaults set to match his parameters. The numerator is the sum of (death counts) in ages 95, 100, and 105. The denominator consists in the sum of the 5-year age groups centered around each of the numerator ages. It probably only makes sense to use this with the default values, however. Used with a single age in the numerator, it is almost the same as \code{Noumbissi()}, except here we pick out particular ages, whereas Noumbissi picks out terminal digits. 21 | } 22 | \examples{ 23 | Value <-c(8904, 592, 354, 299, 292, 249, 222, 216, 181, 169, 151, 167, 24 | 170, 196, 249, 290, 425, 574, 671, 724, 675, 754, 738, 695, 597, 25 | 498, 522, 479, 482, 478, 558, 582, 620, 606, 676, 768, 862, 952, 26 | 1078, 1215, 1215, 1357, 1470, 1605, 1723, 1782, 1922, 2066, 2364, 27 | 2561, 2476, 1674, 1664, 1616, 1808, 3080, 3871, 4166, 4374, 4707, 28 | 5324, 5678, 6256, 6382, 6823, 7061, 7344, 8149, 8439, 8308, 8482, 29 | 8413, 8157, 7945, 7503, 7164, 7289, 7016, 6753, 6906, 6797, 6624, 30 | 6416, 5811, 5359, 4824, 4277, 3728, 3136, 2524, 2109, 1657, 1235, 31 | 924, 667, 465, 287, 189, 125, 99, 80, 24, 10, 7, 3, 1, 0, 1, 32 | 1, 0, 0) 33 | Age <- 0:110 34 | check_heaping_jdanov(Value, Age, Agei = c(95,100,105)) 35 | } 36 | \references{ 37 | \insertRef{jdanov2008beyond}{DemoTools} 38 | } 39 | -------------------------------------------------------------------------------- /man/check_heaping_kannisto.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_heaping.R 3 | \name{check_heaping_kannisto} 4 | \alias{check_heaping_kannisto} 5 | \title{Kannisto's age heaping index} 6 | \usage{ 7 | check_heaping_kannisto(Value, Age, Agei = 90, pow = "exp") 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. A vector of demographic counts or rates by single age.} 11 | 12 | \item{Age}{integer. A vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{Agei}{integer. The age on which the index is centered.} 15 | 16 | \item{pow}{either \code{"exp"} (default) or a power such as 2. See details} 17 | } 18 | \value{ 19 | The value of the index. 20 | } 21 | \description{ 22 | This age heaping index is used for particular old ages, such as 90, 95, 100, 105, and so forth. 23 | } 24 | \details{ 25 | The index looks down two ages and up two ages, so the data must accommodate that range. The denominator is a mean of the counts in the surrounding 5 single ages. The kind of mean can be controlled with the \code{pow} argument. By default, this takes the antilog of the arithmetic mean of the natural log of the five denominator counts. That will fail if one of the counts is equal to 0. In such cases, another power, such as 2 or 10 or 100 may be used, which is more robust to 0s. The higher the power, the closer the result will resemble the default output. If \code{pow=="exp"} but a 0 is detected among the denominator ages, then \code{pow} is assigned a value of 1000. \code{pow=1} would imply an arithmetic mean in the denominator. 26 | } 27 | \examples{ 28 | Age <- 0:99 29 | check_heaping_kannisto(pop1m_pasex, Age, 90) 30 | check_heaping_kannisto(pop1m_pasex, Age, 95) 31 | check_heaping_kannisto(pop1m_pasex, Age, 95, pow = 2) # geometric mean in denom 32 | check_heaping_kannisto(pop1m_pasex, Age, 95, pow = 1000) # similar, but robust to 0s 33 | check_heaping_kannisto(pop1m_pasex, Age, 95, pow = 1) # arithmetic mean in denom 34 | pop1m_pasex[Age==95] / mean(pop1m_pasex[Age >= 93 & Age <= 97]) 35 | } 36 | \references{ 37 | \insertRef{kannisto1999assessing}{DemoTools} 38 | } 39 | -------------------------------------------------------------------------------- /man/check_heaping_spoorenberg.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/check_heaping.R 3 | \name{check_heaping_spoorenberg} 4 | \alias{check_heaping_spoorenberg} 5 | \title{Spoorenberg's total modified Whipple index} 6 | \usage{ 7 | check_heaping_spoorenberg(Value, Age, ageMin = 20, ageMax = 64) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. A vector of demographic counts by single age.} 11 | 12 | \item{Age}{numeric. A vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{ageMin}{integer. The lowest age included in calculations. Default 25.} 15 | 16 | \item{ageMax}{integer. The upper age bound used for calculations. Default 65.} 17 | } 18 | \value{ 19 | The value of the index. 20 | } 21 | \description{ 22 | Using the digit-specific modified Whipple's index, this index summarizes 23 | all age preference and avoidance effects by taking the sum of the absolute differences between digit-specific Whipple's index and 1 (counting all differences as positive). 24 | } 25 | \details{ 26 | \code{ageMin} and \code{ageMax} are applied to numerator ages, not denominators. Denominators are always 5-year age groups centered on the digit in question, and these therefore stretch into ages a bit higher or lower than the numerator ages. \code{ageMax} is an inclusive upper bound, treated as interval. If you want ages 20 to 64, then give \code{ageMin = 20} and \code{ageMax = 64}, not 65. 27 | } 28 | \examples{ 29 | Age <- 0:99 30 | check_heaping_spoorenberg(pop1m_pasex, Age) 31 | } 32 | \references{ 33 | \insertRef{spoorenberg2007quality}{DemoTools} 34 | } 35 | -------------------------------------------------------------------------------- /man/dec.date.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{dec.date} 4 | \alias{dec.date} 5 | \title{Convert date to decimal year fraction.} 6 | \usage{ 7 | dec.date(date) 8 | } 9 | \arguments{ 10 | \item{date}{Either a \code{Date} class object or an unambiguous character string in the format \code{"YYYY-MM-DD"}.} 11 | } 12 | \value{ 13 | Numeric expression of the date, year plus the fraction of the year passed as of the date. 14 | } 15 | \description{ 16 | Convert a character or date class to decimal, taking into account leap years. 17 | } 18 | \details{ 19 | This makes use of the \code{lubridate::decimal_date} to compute the proportion of the year that has passed. If the date is numeric, it is returned as such. If it is \code{"character"}, we try to coerce to date through \code{lubridate::ymd}, ergo, it is best to specify a character string in an unambiguous \code{"YYYY-MM-DD"} format. If \code{date} is given in a \code{"Date"} class it is dealt with accordingly. 20 | } 21 | -------------------------------------------------------------------------------- /man/downloadAsfr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_downloads.R 3 | \name{downloadAsfr} 4 | \alias{downloadAsfr} 5 | \title{Extract ASFR estimates from WPP2019. Mainly an util function for other ones.} 6 | \usage{ 7 | downloadAsfr(Asfrmat, location = NULL, AsfrDatesIn, method = "linear") 8 | } 9 | \arguments{ 10 | \item{Asfrmat}{numeric.} 11 | 12 | \item{location}{vector. UN Pop Div \code{LocName} or \code{LocID}} 13 | 14 | \item{AsfrDatesIn}{numeric. Vector of decimal dates.} 15 | 16 | \item{method}{character. Could be \code{"linear"}, \code{"exponential"}, or \code{"power"}} 17 | } 18 | \value{ 19 | numeric matrix interpolated asfr 20 | } 21 | \description{ 22 | We extract \code{ASFRx} from \code{wpp2019}, interpolated to exact dates. Different methods available. 23 | A vector of countries can handle, but with an unique sex. Row names are not indicative of countries. 24 | } 25 | \examples{ 26 | # Total fertility ratio calculated from ASFRx downloaded from WPP19. 27 | # See `downloadnLx` for analogous examples on multiple countries or using codes instead of names. 28 | ASFR_Arg <- downloadAsfr(Asfrmat = NULL, location = "Argentina", AsfrDatesIn = 1950:2025) 29 | \dontrun{ 30 | plot(1950:2025, as.numeric(colSums(ASFR_Arg))*5, xlab = "Year", ylab="TFR", ylim=c(1.5,4), t="l") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /man/downloadSRB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_downloads.R 3 | \name{downloadSRB} 4 | \alias{downloadSRB} 5 | \title{Extract SRB estimates from WPP2019} 6 | \usage{ 7 | downloadSRB(SRB, location, DatesOut, verbose = TRUE) 8 | } 9 | \arguments{ 10 | \item{SRB}{sex ratio at birth. Either \code{NULL}, a scalar to assume constant, or a vector of length 3, assumed.} 11 | 12 | \item{location}{UN Pop Div \code{LocName} or \code{LocID}} 13 | 14 | \item{DatesOut}{numeric vector of three decimal dates produced by \code{basepop_ive()}} 15 | 16 | \item{verbose}{logical, shall we send optional messages to the console?} 17 | } 18 | \value{ 19 | numeric vector with three SRB estimates 20 | } 21 | \description{ 22 | We use the \code{WPP2019_births} dataset from \code{DemoToolsData} for the sex ratio at birth. Births from WPP 2019 were graduates to single year totals. 23 | } 24 | -------------------------------------------------------------------------------- /man/dth5_zigzag.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{dth5_zigzag} 5 | \alias{dth5_zigzag} 6 | \title{Deaths by 5 year age groups} 7 | \format{ 8 | A numeric vector of length 20 9 | } 10 | \source{ 11 | The data comes from 12 | \url{http://demographer.com/white-papers/2013-removing-zigzag-from-age-data/} 13 | } 14 | \usage{ 15 | dth5_zigzag 16 | } 17 | \description{ 18 | Deaths by 5 year age groups in South Africa 1997, from Feeney Zigzag 2013 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/e0_swe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{e0_swe} 5 | \alias{e0_swe} 6 | \title{Swedish life expectancy at birth} 7 | \format{ 8 | A data frame with: 9 | \describe{ 10 | \item{Date}{Reference time.} 11 | \item{Sex}{Male \code{m} and female \code{m}.} 12 | \item{e0}{Life expectancy at birth.} 13 | } 14 | } 15 | \source{ 16 | Human Mortality Database. Retrieved 2021-20-01, from \url{https://mortality.org} 17 | } 18 | \usage{ 19 | e0_swe 20 | } 21 | \description{ 22 | Life expectancy at birth by sex in tidy format for dates from 1960-07-01 to 2015-07-01 by 5 calendar years. 23 | } 24 | \keyword{datasets} 25 | -------------------------------------------------------------------------------- /man/fetch_wpp_births.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_downloads.R 3 | \name{fetch_wpp_births} 4 | \alias{fetch_wpp_births} 5 | \title{extract births from wpp2019} 6 | \usage{ 7 | fetch_wpp_births(births, yrs_births, location, sex, verbose) 8 | } 9 | \arguments{ 10 | \item{births}{\code{NULL} or else a vector of births to simply return} 11 | 12 | \item{yrs_births}{vector of years to extract} 13 | 14 | \item{location}{UN Pop Dov \code{LocName} or \code{LocID}} 15 | 16 | \item{sex}{\code{"male"}, \code{"female"}, or \code{"both"}} 17 | 18 | \item{verbose}{logical, shall we send optional messages to the console?} 19 | } 20 | \value{ 21 | vector of births 22 | } 23 | \description{ 24 | extract births from wpp2019 25 | } 26 | -------------------------------------------------------------------------------- /man/find_my_case.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_model_lq.R 3 | \name{find_my_case} 4 | \alias{find_my_case} 5 | \title{Function that determines the case/problem we have to solve 6 | It also performs some checks} 7 | \usage{ 8 | find_my_case(par_ind) 9 | } 10 | \arguments{ 11 | \item{par_ind}{logical vector of length 5} 12 | } 13 | \description{ 14 | Function that determines the case/problem we have to solve 15 | It also performs some checks 16 | } 17 | \details{ 18 | \code{par_ind} should consist in logicals in the following order: \code{q0_5}, \code{q0_1}, \code{q15_45}, \code{q15_35}, \code{e0}. This is faithfully constructed in calling functions as required. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/fitted_logquad_b.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fitted_logquad_b} 5 | \alias{fitted_logquad_b} 6 | \title{LogQuad model for BOTH SEX fitted for all HMD life tables} 7 | \format{ 8 | List of 6: 9 | \describe{ 10 | \item{input}{List of parameters passed to \code{MortalityEstimate::wilmoth}.} 11 | \item{call}{R code call line used for fitting.} 12 | \item{coefficients}{Dataframe with 24 rows and 4 variables -- parameters \code{ax}, \code{bx}, \code{cx}, \code{vx} for each age group.} 13 | \item{k}{\code{k} fitting parameter of the LogQuag model, a vector of 968 values.} 14 | \item{fitted.values}{Fitted death rates, a matrix 968x24.} 15 | \item{model.info}{Model formula.} 16 | } 17 | } 18 | \source{ 19 | Human Mortality Database. Retrieved 2019-11-28, from \url{https://mortality.org} 20 | } 21 | \usage{ 22 | fitted_logquad_b 23 | } 24 | \description{ 25 | LogQuad model fitted using \code{MortalityEstimate::wilmoth} for all BOTH SEX period life tables present in Human Mortality Database (\url{https://mortality.org}) in December 2019 (968 life tables). Object of class \code{wilmoth}. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/fitted_logquad_f.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fitted_logquad_f} 5 | \alias{fitted_logquad_f} 6 | \title{LogQuad model for FEMALES fitted for all HMD life tables} 7 | \format{ 8 | List of 6: 9 | \describe{ 10 | \item{input}{List of parameters passed to \code{MortalityEstimate::wilmoth}.} 11 | \item{call}{R code call line used for fitting.} 12 | \item{coefficients}{Dataframe with 24 rows and 4 variables -- parameters \code{ax}, \code{bx}, \code{cx}, \code{vx} for each age group.} 13 | \item{k}{\code{k} fitting parameter of the LogQuag model, a vector of 968 values.} 14 | \item{fitted.values}{Fitted death rates, a matrix 968x24.} 15 | \item{model.info}{Model formula.} 16 | } 17 | } 18 | \source{ 19 | Human Mortality Database. Retrieved 2019-11-28, from \url{https://mortality.org} 20 | } 21 | \usage{ 22 | fitted_logquad_f 23 | } 24 | \description{ 25 | LogQuad model fitted using \code{MortalityEstimate::wilmoth} for all FEMALE period life tables present in Human Mortality Database (\url{https://mortality.org}) in December 2019 (968 life tables). Object of class \code{wilmoth}. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/fitted_logquad_m.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fitted_logquad_m} 5 | \alias{fitted_logquad_m} 6 | \title{LogQuad model for MALES fitted for all HMD life tables} 7 | \format{ 8 | List of 6: 9 | \describe{ 10 | \item{input}{List of parameters passed to \code{MortalityEstimate::wilmoth}.} 11 | \item{call}{R code call line used for fitting.} 12 | \item{coefficients}{Dataframe with 24 rows and 4 variables -- parameters \code{ax}, \code{bx}, \code{cx}, \code{vx} for each age group.} 13 | \item{k}{\code{k} fitting parameter of the LogQuag model, a vector of 968 values.} 14 | \item{fitted.values}{Fitted death rates, a matrix 968x24.} 15 | \item{model.info}{Model formula.} 16 | } 17 | } 18 | \source{ 19 | Human Mortality Database. Retrieved 2019-11-28, from \url{https://mortality.org} 20 | } 21 | \usage{ 22 | fitted_logquad_m 23 | } 24 | \description{ 25 | LogQuad model fitted using \code{MortalityEstimate::wilmoth} for all MALE period life tables present in Human Mortality Database (\url{https://mortality.org}) in December 2019 (968 life tables). Object of class \code{wilmoth}. 26 | } 27 | \keyword{datasets} 28 | -------------------------------------------------------------------------------- /man/getModelLifeTable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{getModelLifeTable} 4 | \alias{getModelLifeTable} 5 | \title{Wrapper to provide a single location to reference all model life tables.} 6 | \usage{ 7 | getModelLifeTable(ModelName, Sex) 8 | } 9 | \arguments{ 10 | \item{ModelName}{string naming the life table to return. Can be "coale-demeny west".} 11 | 12 | \item{Sex}{string indicating which sex should be returned. Can be either "m" or "f".} 13 | } 14 | \value{ 15 | list of life tables 16 | } 17 | \description{ 18 | Still in the works. 19 | } 20 | \details{ 21 | More model families can easily be added. 22 | } 23 | -------------------------------------------------------------------------------- /man/graduate_beers_expand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_beers_expand} 4 | \alias{graduate_beers_expand} 5 | \title{Create the Beers ordinary or modified coefficient matrix} 6 | \usage{ 7 | graduate_beers_expand(Value, OAG = FALSE, method = "Mod") 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{OAG}{logical, default = \code{TRUE} is the final age group open?} 13 | 14 | \item{method}{character. Valid values are \code{"mod"} or \code{"ord"}. Default \code{"mod"}.} 15 | } 16 | \description{ 17 | The resulting coefficient matrix is based on the number of rows in \code{Value} 18 | which must be in 5-year age groups (not abridged). The final row may be an open 19 | or closed age group, as indicated by the \code{OAG} argument. 20 | } 21 | \details{ 22 | The \code{Value} vector is a placeholder in this case. This function is 23 | a utility called by the Beers family of functions, where it is most convenient to just pass 24 | in the same matrix being used in those calculations to determine the layout of the coefficient matrix. 25 | } 26 | \examples{ 27 | coefsOA <- graduate_beers_expand(pop5_mat, OAG = TRUE, method = "mod") 28 | coefsclosed <- graduate_beers_expand(pop5_mat, OAG = FALSE, method = "mod") 29 | dim(graduate_beers_expand(pop5_mat, TRUE)) 30 | dim(graduate_beers_expand(pop5_mat, FALSE)) 31 | coefso <- graduate_beers_expand(pop5_mat, OAG = TRUE, method = "ord") 32 | 33 | # how to use (under the hood in beers() 34 | 35 | } 36 | \references{ 37 | \insertRef{beers1945modified}{DemoTools} 38 | \insertRef{siegel2004methods}{DemoTools} 39 | } 40 | -------------------------------------------------------------------------------- /man/graduate_beers_johnson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_beers_johnson} 4 | \alias{graduate_beers_johnson} 5 | \title{Adjust ages under 10 using a modification of Beers} 6 | \usage{ 7 | graduate_beers_johnson(Age0, pop5, pop1) 8 | } 9 | \arguments{ 10 | \item{Age0}{numeric. An estimate of age 0.} 11 | 12 | \item{pop5}{numeric. Matrix of age-period population counts in 5-year age groups.} 13 | 14 | \item{pop1}{numeric. Matrix of age-period population using Beers ordinary (or some other) method.} 15 | } 16 | \value{ 17 | A matrix of single age population estimates. 18 | } 19 | \description{ 20 | Assuming we have an external estimate of age 0, this method 21 | refits to the ordinary Beers single age results, remaining constrained to the 22 | original 5-year age groups and smoothly blending into ages greater than 10. 23 | } 24 | \details{ 25 | This has not been tested using \code{pop1} as generated from other methods, such as 26 | the Beers modified, Sprague, or Grabill methods. Called internally by \code{beers()}. 27 | } 28 | \references{ 29 | \insertRef{stover2008spectrum}{DemoTools} 30 | } 31 | -------------------------------------------------------------------------------- /man/graduate_grabill.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_grabill} 4 | \alias{graduate_grabill} 5 | \title{The basic Grabill age-splitting method} 6 | \usage{ 7 | graduate_grabill(Value, Age, AgeInt, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{Age}{integer vector, lower bounds of age groups} 13 | 14 | \item{AgeInt}{integer vector, age interval widths} 15 | 16 | \item{OAG}{logical, default = \code{TRUE} is the final age group open?} 17 | } 18 | \value{ 19 | numeric vector in single ages. 20 | } 21 | \description{ 22 | This method uses Grabill's redistribution of middle ages and blends into 23 | Sprague estimated single-age population counts for the first and final ten ages. Open age groups are preserved, as are annual totals. 24 | } 25 | \details{ 26 | Dimension labeling is necessary. There must be at least six age groups (including the open group). One year of data will work as well, as long as it's given as a single-column matrix. Data may be given in either single or grouped ages. If the highest age does not end in a 0 or 5, and \code{OAG == TRUE}, then the open age will be grouped down to the next highest age ending in 0 or 5. If the highest age does not end in a 0 or 5, and \code{OAG == FALSE}, then results extend to single ages covering the entire 5-year age group. 27 | } 28 | \examples{ 29 | a5 <- as.integer(rownames(pop5_mat)) 30 | p5 <- pop5_mat[,1] 31 | p1g <- graduate_grabill(Value = p5, Age = a5, OAG = TRUE) 32 | sum(p1g) - sum(p5) 33 | p1s <- graduate_sprague(p5, Age = a5, OAG = TRUE) 34 | \dontrun{ 35 | plot(seq(0,100,by=5),p5[,1]/5,type = "s", col = "gray", xlab = "Age", ylab = "Count") 36 | lines(0:100, p1g, col = "red", lwd = 2) 37 | lines(0:100, p1s, col = "blue", lty = 2, lwd =2) 38 | legend("topright", 39 | lty = c(1,1,2), 40 | col = c("gray","red","blue"), 41 | lwd = c(1,2,1), 42 | legend = c("grouped","Grabill", "Sprague")) 43 | } 44 | 45 | # also works for single ages: 46 | grab1 <- graduate_grabill(Value = pop1m_ind, Age = 0:100) 47 | \dontrun{ 48 | plot(0:100, pop1m_ind) 49 | lines(0:100, grab1) 50 | } 51 | } 52 | \references{ 53 | \insertRef{shryock1973methods}{DemoTools} 54 | } 55 | -------------------------------------------------------------------------------- /man/graduate_grabill_expand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_grabill_expand} 4 | \alias{graduate_grabill_expand} 5 | \title{Create the Grabill coefficient matrix.} 6 | \usage{ 7 | graduate_grabill_expand(Value, Age, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{Age}{integer vector, lower bounds of age groups} 13 | 14 | \item{OAG}{logical, default = \code{TRUE} is the final age group open?} 15 | } 16 | \description{ 17 | The resulting coefficient matrix is based on the number of rows in \code{popmat} where we assume that each row of data is a 5-year age group and the final row is an open age group to be preserved as such. 18 | } 19 | \details{ 20 | The \code{Value} vector is really just a placeholder in this case. This function is a utility called by the Grabill family of functions, where it is most convenient to just pass in the same matrix being used in those calculations to determine the layout of the coefficient matrix. Note that these coefficients do not constrain population counts to their year totals. This function is called by \code{grabill()}, which ensures matching marginals by 1) blending boundary ages into the Sprague estimated population, and 2) a second constraint on the middle age groups to enforce matching sums. 21 | } 22 | \examples{ 23 | a5 <- as.integer(rownames(pop5_mat)) 24 | graduate_grabill_expand(pop5_mat[,1], Age = a5, OAG = TRUE) 25 | graduate_grabill_expand(pop5_mat[,1], Age = a5, OAG = FALSE) 26 | } 27 | \references{ 28 | \insertRef{shryock1973methods}{DemoTools} 29 | } 30 | -------------------------------------------------------------------------------- /man/graduate_sprague_expand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_sprague_expand} 4 | \alias{graduate_sprague_expand} 5 | \title{Create the Sprague coefficient matrix.} 6 | \usage{ 7 | graduate_sprague_expand(Value, Age, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{Age}{integer vector, lower bounds of age groups} 13 | 14 | \item{OAG}{logical, default = \code{TRUE} is the final age group open?} 15 | } 16 | \description{ 17 | The resulting coefficient matrix is based on the number of rows in \code{popmat} where is assumed that each row of data is a 5-year age group. The final row may be an open or closed age group, as indicated by the \code{OAG} argument. 18 | } 19 | \details{ 20 | The \code{popmat} matrix is really just a placeholder in this case. This function is a utility called by the Sprague family of functions, where it is most convenient to just pass in the same matrix being used in those calculations to determine the layout of the coefficient matrix. 21 | } 22 | \examples{ 23 | a5 <- as.integer(rownames(pop5_mat)) 24 | coefsOA <- graduate_sprague_expand(pop5_mat[,1], Age = a5, OAG = TRUE) 25 | coefsclosed <- graduate_sprague_expand(pop5_mat[,1], Age = a5, OAG = FALSE) 26 | dim(coefsOA) 27 | dim(coefsclosed) 28 | } 29 | \references{ 30 | \insertRef{sprague1880explanation}{DemoTools} 31 | \insertRef{shryock1973methods}{DemoTools} 32 | \insertRef{siegel2004methods}{DemoTools} 33 | } 34 | -------------------------------------------------------------------------------- /man/graduate_uniform.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/graduate.R 3 | \name{graduate_uniform} 4 | \alias{graduate_uniform} 5 | \title{Convert arbitrary age groupings into single years of age.} 6 | \usage{ 7 | graduate_uniform(Value, Age, AgeInt, OAG = TRUE, OAvalue = 1) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector, presumably counts in grouped ages} 11 | 12 | \item{Age}{integer vector, lower bounds of age groups} 13 | 14 | \item{AgeInt}{integer vector, age interval widths} 15 | 16 | \item{OAG}{logical, default = \code{TRUE} is the final age group open?} 17 | 18 | \item{OAvalue}{Desired width of open age group. See details.} 19 | } 20 | \value{ 21 | Numeric vector of counts for single year age groups. 22 | } 23 | \description{ 24 | Uniformly splits aggregate counts in age groups into single year age groups. 25 | } 26 | \details{ 27 | Assumes that the population is uniformly distributed across each age interval, and that initial age intervals are integers greater than or equal to 1. If \code{AgeInt} is given, its final value is used as the interval for the final age group. If \code{AgeInt} is missing, then \code{Age} must be given, and the open age group is by default preserved \code{OAvalue} rather than split. To instead split the final age group into, e.g., a 5-year age class, either give \code{AgeInt}, \emph{or} give \code{Age}, \code{OAG = TRUE}, and \code{OAvalue = 5}. \code{Age} be any age range, it does not need to start at 0. 28 | } 29 | \examples{ 30 | MalePop <- c(9544406,7471790,11590109,11881844,11872503,12968350, 31 | 11993151,10033918,14312222,8111523,15311047,6861510,13305117,7454575, 32 | 9015381,10325432,9055588,5519173) 33 | Ages <- seq(0, 85, by = 5) 34 | graduate_uniform(MalePop, Age = Ages) 35 | } 36 | -------------------------------------------------------------------------------- /man/groupAges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{groupAges} 4 | \alias{groupAges} 5 | \title{Group single ages into equal age groups of arbitrary width} 6 | \usage{ 7 | groupAges( 8 | Value, 9 | Age = 1:length(Value) - 1, 10 | N = 5, 11 | shiftdown = 0, 12 | AgeN, 13 | OAnew = max(Age) 14 | ) 15 | } 16 | \arguments{ 17 | \item{Value}{numeric. Vector of single age counts.} 18 | 19 | \item{Age}{integer. Vector of lower bounds of single age groups.} 20 | 21 | \item{N}{integer. The desired width of resulting age groups. Default 5.} 22 | 23 | \item{shiftdown}{integer. Optionally shift age groupings down by single ages. Default 0.} 24 | 25 | \item{AgeN}{integer vector, otherwise calculated using \code{calcAgeN()}. Optional argument.} 26 | 27 | \item{OAnew}{integer. Value of lower bound of new open age group.} 28 | } 29 | \value{ 30 | Vector of counts in N-year age groups. 31 | } 32 | \description{ 33 | This can be useful to check constrained sums, or as an intermediate step for smoothing. 34 | } 35 | \details{ 36 | If you shift the groupings, then the first age groups may have a negative lower bound 37 | (for example of -5). These counts would be discarded for the oscillatory version of Sprague smoothing, 38 | for example, but they are preserved in this function. The important thing to know is that if you shift 39 | the groups, the first and last groups will not be N years wide. For example if \code{shiftdown} is 1, the first age group is 4-ages wide. The ages themselves are not returned, 40 | but they are the name attribute of the output count vector. Note this will also correctly group abridged ages 41 | into equal 5-year age groups if the \code{Age} argument is explicitly given. \code{OAnew} (optional) must be less than or equal to \code{max(Age)} to have any effect. 42 | } 43 | \examples{ 44 | Age <- 0:100 45 | groupAges(pop1m_ind, N = 5) 46 | groupAges(pop1m_ind, N = 5, shiftdown = 1) 47 | groupAges(pop1m_ind, N = 5, shiftdown = 2) 48 | groupAges(pop1m_ind, N = 5, shiftdown = 3) 49 | groupAges(pop1m_ind, N = 5, shiftdown = 4) 50 | groupAges(pop1m_ind, N = 5, OAnew = 80) 51 | } 52 | -------------------------------------------------------------------------------- /man/groupOAG.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{groupOAG} 4 | \alias{groupOAG} 5 | \title{Group down to a new open age class.} 6 | \usage{ 7 | groupOAG(Value, Age, OAnew) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. Vector of counts.} 11 | 12 | \item{Age}{integer. Vector of age classes.} 13 | 14 | \item{OAnew}{The desired open age group.} 15 | } 16 | \value{ 17 | Value vector potentially of reduced length up to OAG. 18 | } 19 | \description{ 20 | This simple utility lowers the open age group. It only returns the input value vector, not the age vector. 21 | } 22 | -------------------------------------------------------------------------------- /man/inferAgeIntAbr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{inferAgeIntAbr} 4 | \alias{inferAgeIntAbr} 5 | \title{Infer abridged age groups widths.} 6 | \usage{ 7 | inferAgeIntAbr(Age, vec, OAG = FALSE, OAvalue = NA) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of lower bound of each age group.} 11 | 12 | \item{vec}{Any vector, presumably a count, rate, or similar.} 13 | 14 | \item{OAG}{logical. Whether or not the final age group open. Default \code{FALSE}.} 15 | 16 | \item{OAvalue}{numeric or integer. The value to use for the final age interval if \code{OAG = TRUE}. Default \code{NA}.} 17 | } 18 | \value{ 19 | An integer vector of \code{length(vec)} indicating the width of the abridged age group that each 20 | vector element corresponds to. 21 | } 22 | \description{ 23 | This function is an auxiliary used by top level functions where it is 24 | guaranteed that age groups are standard abridged age groups. If \code{Age} is specified, 25 | this will work as well for other age groupings. 26 | } 27 | \details{ 28 | If based solely on the length of a vector, this will give erroneous results if ages 29 | are anything other than standard abridged ages groups. If the final age group is open, the 30 | interval width is defined as \code{NA}. \code{Inf} or \code{-1} would have 31 | also been a good choice, but we went with \code{NA}. 32 | } 33 | \examples{ 34 | vec <- runif(20) 35 | inferAgeIntAbr(vec = vec) 36 | inferAgeIntAbr(vec = vec, OAG = TRUE) 37 | inferAgeIntAbr(Age = 0:100, OAG = TRUE) 38 | } 39 | -------------------------------------------------------------------------------- /man/int2age.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{int2age} 4 | \alias{int2age} 5 | \title{Infer lower age bounds from age class intervals.} 6 | \usage{ 7 | int2age(AgeInt, ageMin = 0) 8 | } 9 | \arguments{ 10 | \item{AgeInt}{integer or numeric. Vector of age intervals.} 11 | 12 | \item{ageMin}{integer. The lowest age, default 0.} 13 | } 14 | \value{ 15 | Age vector of same length as \code{AgeInt}. 16 | } 17 | \description{ 18 | Determine lower bounds of age classes based on a vector of age intervals and a starting age. 19 | } 20 | \examples{ 21 | AgeInt <- c(1,4,rep(5,17)) 22 | int2age(AgeInt) 23 | } 24 | -------------------------------------------------------------------------------- /man/int2ageN.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{int2ageN} 4 | \alias{int2ageN} 5 | \title{repeat age lower bounds once for each single age} 6 | \usage{ 7 | int2ageN(AgeInt, OAG) 8 | } 9 | \arguments{ 10 | \item{AgeInt}{integer or numeric. Vector of age intervals.} 11 | 12 | \item{OAG}{logical. Whether or not the final age group open. Default \code{FALSE}. See details} 13 | } 14 | \value{ 15 | integer vector of elements of \code{Age} repeated once for each implied single age. 16 | } 17 | \description{ 18 | This is a frequent grouping situation. For a given vector of lower age bounds, as implied by \code{AgeInt}, repeat each value N times, where N is the width of the corresponding age interval. Age intervals are in this case given, and age lower bound values are calculated from \code{AgeInt} vector. 19 | } 20 | \details{ 21 | If \code{OAG == TRUE} then the last value is given just once, irrespective of the final value of \code{AgeInt}, otherwise the final age interval is repeated \code{AgeInt[length(AgeInt)]} times. Here intervals do not need to be of uniform width. 22 | } 23 | \examples{ 24 | int5 <- rep(5,21) 25 | (ageN1 <- int2ageN(int5, OAG = FALSE)) 26 | (ageN2 <- int2ageN(int5, OAG = TRUE)) 27 | } 28 | -------------------------------------------------------------------------------- /man/interp_lc_lim_abk_m.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interp_lc_lim.R 3 | \name{interp_lc_lim_abk_m} 4 | \alias{interp_lc_lim_abk_m} 5 | \title{wrapper fun for \code{"interp_lc_lim_estimate"} function} 6 | \usage{ 7 | interp_lc_lim_abk_m(k, ax, bx) 8 | } 9 | \arguments{ 10 | \item{k}{numeric. k parameter from LC model.} 11 | 12 | \item{ax}{numeric. Vector (same length of age) of parameters from LC model.} 13 | 14 | \item{bx}{numeric. Vector (same length of age) of parameters from LC model.} 15 | } 16 | \description{ 17 | wrapper fun to estimate rates from LC parameters 18 | } 19 | -------------------------------------------------------------------------------- /man/interp_lc_lim_estimate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interp_lc_lim.R 3 | \name{interp_lc_lim_estimate} 4 | \alias{interp_lc_lim_estimate} 5 | \title{Estimate LC with limited data parameters} 6 | \usage{ 7 | interp_lc_lim_estimate(M, dates_in, dates_out, SVD = F) 8 | } 9 | \arguments{ 10 | \item{M}{numeric. Matrix with many rows as ages and columns as \code{dates_in}.} 11 | 12 | \item{dates_in}{numeric. Vector of dates with input rates.} 13 | 14 | \item{dates_out}{numeric. Vector of dates for estimate a set of rates.} 15 | 16 | \item{SVD}{logical. Use Singular Value Decomposition for estimate \code{b} and \code{k} or Maximum Likelihood Estimation. Default \code{FALSE} for Maximum Likelihood Estimation.} 17 | } 18 | \description{ 19 | Estimate LC with limited data from a matrix of rates (age by dates). 20 | } 21 | \details{ 22 | SVD for \code{ax} and \code{bx.} Fit a simple linear model for \code{k} and interpolate/extrapolate for objective dates. 23 | } 24 | \references{ 25 | \insertRef{Li2004}{DemoTools} 26 | } 27 | -------------------------------------------------------------------------------- /man/interp_lc_lim_kt_min.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interp_lc_lim.R 3 | \name{interp_lc_lim_kt_min} 4 | \alias{interp_lc_lim_kt_min} 5 | \title{Optimize k} 6 | \usage{ 7 | interp_lc_lim_kt_min(k, ax, bx, age, sex, e0_target, ...) 8 | } 9 | \arguments{ 10 | \item{k}{numeric. k parameter from LC model.} 11 | 12 | \item{ax}{numeric. Vector (same length of age) of parameters from LC model.} 13 | 14 | \item{bx}{numeric. Vector (same length of age) of parameters from LC model.} 15 | 16 | \item{age}{numeric.} 17 | 18 | \item{sex}{numeric.} 19 | 20 | \item{e0_target}{numeric.} 21 | 22 | \item{...}{Other arguments to be passed on to the \code{\link[DemoTools]{lt_abridged}} function.} 23 | } 24 | \description{ 25 | Optimize estimated k from LC with limited data model, 26 | for fitting given e_0 at same dates 27 | } 28 | \details{ 29 | Given LC parameters at some date, change a bit k for replicate already know e_0 values. 30 | This is useful to give some sort of flexibility, and not follow strictly linear model implied in LC model, 31 | but taking advantage of estimated structure (ax) and change by age (bx) for some trustable period. 32 | } 33 | -------------------------------------------------------------------------------- /man/is_abridged.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{is_abridged} 4 | \alias{is_abridged} 5 | \title{Detect if a vector of lower age bounds is plausibly of abridged ages.} 6 | \usage{ 7 | is_abridged(Age) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of lower age bounds.} 11 | } 12 | \value{ 13 | Logical \code{TRUE} if abridged, \code{FALSE} otherwise. 14 | } 15 | \description{ 16 | A logical utility that checks if a given vector is of the lower bounds of abridged age groups or not. 17 | } 18 | \examples{ 19 | # as expected, TRUE 20 | is_abridged(c(0,1,5,10,15,20,25)) 21 | # standard 5, not abridged, FALSE 22 | is_abridged(c(0,5,10,15,20,25)) 23 | # plausible, TRUE 24 | is_abridged(c(1,5,10,15,20,25)) 25 | # plausible, TRUE 26 | is_abridged(c(5,10,15,20,25)) 27 | # 10 year age group not abridged, FALSE 28 | is_abridged(c(0,1,5,10,15,25)) 29 | } 30 | -------------------------------------------------------------------------------- /man/is_age_coherent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{is_age_coherent} 4 | \alias{is_age_coherent} 5 | \title{check for coherence within Age and between Age and AgeInt} 6 | \usage{ 7 | is_age_coherent(Age, AgeInt, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Age}{integer vector of single ages (lower bound)} 11 | 12 | \item{AgeInt}{integer vector. Age interval widths} 13 | 14 | \item{OAG}{logical (default \code{TRUE}). Is the final age group open?} 15 | } 16 | \value{ 17 | logical. \code{TRUE} if the arguments are considered consistent. 18 | } 19 | \description{ 20 | A few checks are carried out to test if \code{Age} is internally consistent, that \code{OAG} is consistent with \code{AgeInt}, and that \code{Age} and \code{AgeInt} are consistent with one another. For \code{Age} to be internally consistent, we cannot have redundant values, and values must be sequential. 21 | } 22 | \details{ 23 | If \code{OAG} is \code{TRUE} then \code{AgeInt} must be coded as \code{NA}. If \code{Age} is not sorted then we sort both \code{Age} and \code{AgeInt}, assuming that they are in matched order. This isn't incoherence in itself, but a message is returned to the console. 24 | } 25 | \examples{ 26 | Age <- 0:99 27 | AgeInt <- rep(1, 100) 28 | # closed, sequential, non-redundant ages, any easy yes: 29 | is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = FALSE) # TRUE 30 | 31 | # incorrectly coded OAG 32 | is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # FALSE 33 | 34 | # correctly coded OAG 35 | AgeInt[100] <- NA 36 | is_age_coherent(Age = Age, AgeInt = AgeInt, OAG = TRUE) # TRUE 37 | 38 | # correct unordered, but this isn't incoherence per se. 39 | # watch out though! 40 | aaoo <- order(sample(Age, 100, replace = FALSE)) 41 | is_age_coherent(Age[aaoo], AgeInt = AgeInt[aaoo], OAG = TRUE) # TRUE 42 | 43 | # check redundancy 44 | AgeRed <- c(0:100,70) 45 | AgeInt <- c(rep(1, 100), NA, NA) 46 | ao <- order(AgeRed) 47 | AgeRed <- AgeRed[ao] 48 | AgeIntRed <- AgeInt[ao] 49 | is_age_coherent(AgeRed, AgeInt, TRUE) # FALSE 50 | } 51 | -------------------------------------------------------------------------------- /man/is_age_redundant.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{is_age_redundant} 4 | \alias{is_age_redundant} 5 | \title{check for redundant age specification} 6 | \usage{ 7 | is_age_redundant(Age, AgeInt) 8 | } 9 | \arguments{ 10 | \item{Age}{integer vector of single ages (lower bound)} 11 | 12 | \item{AgeInt}{integer vector. Age interval widths} 13 | } 14 | \value{ 15 | logical. Are there repeated values in the \code{Age} vector? 16 | } 17 | \description{ 18 | Ages are considered redundant if values for the underlying single ages are repeated. This might occur if there is an extra open age group below the final open age group. For example we have single ages 0 to 84, with an open age group of 85+, but the data also contain an open age group of 70+, leading to age 70 appearing twice. This will also detect 19 | } 20 | \details{ 21 | Missing \code{AgeInt} are conservatively imputed with 20, which will most often trigger \code{FALSE} and thereby flag for further inspection. 22 | } 23 | \examples{ 24 | Age <- c(0:100,70) 25 | AgeInt <- c(rep(1,100),NA,NA) 26 | # it doesn't matter if Age is sequential for this check 27 | is_age_redundant(Age, AgeInt) 28 | } 29 | -------------------------------------------------------------------------------- /man/is_age_sequential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{is_age_sequential} 4 | \alias{is_age_sequential} 5 | \title{is \code{Age} sorted sequentially?} 6 | \usage{ 7 | is_age_sequential(Age) 8 | } 9 | \arguments{ 10 | \item{Age}{integer vector of single ages (lower bound)} 11 | } 12 | \value{ 13 | logical. Is the \code{Age} vector sorted sequentially? 14 | } 15 | \description{ 16 | Check if \code{Age} is sorted sequentially. 17 | } 18 | \details{ 19 | This does not check for redundancy. 20 | } 21 | -------------------------------------------------------------------------------- /man/is_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{is_single} 4 | \alias{is_single} 5 | \title{Logical checking of whether age classes appear single.} 6 | \usage{ 7 | is_single(Age) 8 | } 9 | \arguments{ 10 | \item{Age}{integer. Vector of age classes.} 11 | } 12 | \value{ 13 | logical. \code{TRUE} if detected as single ages, \code{FALSE} otherwise. 14 | } 15 | \description{ 16 | Check whether a vector of ages consists in single ages. This 17 | makes sense sometimes when age intervals are not explicitly given. 18 | } 19 | \details{ 20 | In cases where ages are indeed single, but repeated, this will still return \code{FALSE}. 21 | Therefore make sure that the age vector given refers to a single year of a single population. 22 | } 23 | \examples{ 24 | Age <- 0:99 25 | Age2 <- c(0:10,0:10) 26 | Age3 <- seq(0,80,by=5) 27 | Age4 <- seq(0,10,by=.5) 28 | is_single(Age) # TRUE 29 | is_single(Age2) # FALSE repeated, can't tell. 30 | is_single(Age3) # FALSE not single ages 31 | is_single(Age4) # FALSE not single ages 32 | } 33 | -------------------------------------------------------------------------------- /man/loess_smth1.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/OGIVE.R 3 | \name{loess_smth1} 4 | \alias{loess_smth1} 5 | \title{Wrapper to LOESS using demographic data.} 6 | \usage{ 7 | loess_smth1(Value, Age, OAG = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of counts in single, abridged, or 5-year age groups.} 11 | 12 | \item{Age}{integer vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | 16 | \item{...}{optional arguments passed to \code{stats::loess()}} 17 | } 18 | \description{ 19 | LOESS (locally weighted smoothing) helps to smooth data over age, preserving the open age group if necessary. This is a simple wrapper to \code{stats::loess()} but using standard demographic arguments. 20 | It is a popular tool to create a smooth line through a timeplot or scatter plot. 21 | } 22 | \details{ 23 | The total sum of \code{Value} is preserved in the output. One can control smoothness using the \code{spar} argument of \code{stats::loess()}. See \code{\link[stats]{loess}} for more details. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | Age <- 0:99 28 | plot(Age,pop1m_pasex) 29 | lines(Age, loess_smth1(pop1m_pasex, Age, FALSE)) 30 | } 31 | } 32 | \seealso{ 33 | \code{\link[stats]{loess}} 34 | } 35 | -------------------------------------------------------------------------------- /man/logquad_augmented.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/log_quad_augm.R 3 | \name{logquad_augmented} 4 | \alias{logquad_augmented} 5 | \title{Augmented logquad} 6 | \usage{ 7 | logquad_augmented(coeffs, k, q0_5, q60_15, Sex = "b", Age, ...) 8 | } 9 | \arguments{ 10 | \item{coeffs}{data.frame. Columns \code{a(x)}, \code{b(x)}, \code{c(x)} and \code{v(x)} from fitted logquad model. See \code{fitted_logquad_b}.} 11 | 12 | \item{k}{numeric. Adult mortality related value from log-quad estimatation based on one or two input parameters. See \code{lt_model_lq}.} 13 | 14 | \item{q0_5}{numeric. Probability of death from born to age 5.} 15 | 16 | \item{q60_15}{numeric. Probability of death from age 60 to age 75.} 17 | 18 | \item{Sex}{character. Either male \code{"m"}, female \code{"f"}, or both \code{"b"}.} 19 | 20 | \item{Age}{integer. Abridged lower bound ages. Same length than rows in \code{coeffs}.} 21 | 22 | \item{...}{Other arguments to be passed on to the \code{lt_abridged} function.} 23 | } 24 | \value{ 25 | life table as in \code{lt_abridged} function. 26 | } 27 | \description{ 28 | Adjust rates in oldest ages that comes from a HMD model, using an external estimate of 15q60 (Li, 2014). As an example see\code{\link[DemoTools]{HMD_old_logquad}}. 29 | } 30 | \details{ 31 | Parameter \code{a(x)} is augmented based on an external estimate of 15q60. 32 | } 33 | \references{ 34 | See \href{https://www.un.org/development/desa/pd/content/estimating-life-tables-developing-countries}{Li (2014)}. 35 | } 36 | -------------------------------------------------------------------------------- /man/lt_ambiguous.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_regroup_age.R 3 | \name{lt_ambiguous} 4 | \alias{lt_ambiguous} 5 | \title{calculate an abridged or single age lifetable from abridged or single age data} 6 | \usage{ 7 | lt_ambiguous( 8 | nMx_or_nqx_or_lx = NULL, 9 | type = "m", 10 | Age = NULL, 11 | Sex = NULL, 12 | Single = FALSE, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{nMx_or_nqx_or_lx}{numeric vector of either \code{nMx}, \code{nqx}, or \code{lx}} 18 | 19 | \item{type}{character, which variable is \code{x}?, either \code{"m"}, \code{"q"}, or \code{"l"}. Default \code{"m"}} 20 | 21 | \item{Age}{integer vector of the lower age bounds of \code{x}} 22 | 23 | \item{Sex}{character, \code{"m"}, \code{"f"}, or \code{"b"}.} 24 | 25 | \item{Single}{logical, do we want output in single ages?} 26 | 27 | \item{...}{optional arguments passed to \code{lt_abridged()} or \verb{lt_single*()}} 28 | } 29 | \description{ 30 | This is a wrapper around the other lifetable utilities. We start with either \code{nMx}, \code{nqx}, or \code{lx} in single or abridged ages, and returns a full lifetable in either single or abridged ages. All optional arguments of \code{lt_abridged()} or \verb{lt_single*()} can be passed in, for instance the \code{nax} assumptions or the extrapolation arguments. 31 | } 32 | -------------------------------------------------------------------------------- /man/lt_id_L_T.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_L_T} 4 | \alias{lt_id_L_T} 5 | \title{Derive lifetable total person years left to live from exposure.} 6 | \usage{ 7 | lt_id_L_T(Lx) 8 | } 9 | \arguments{ 10 | \item{Lx}{numeric. Vector of lifetable exposure.} 11 | } 12 | \value{ 13 | Tx total years left to live above age x. 14 | } 15 | \description{ 16 | A lifetable identity. Tx is interpreted as the total years 17 | left to live above age x in the life table stationary population. 18 | } 19 | \details{ 20 | No \code{NA} or other error checking here. This is taken as the numerator in the classic lifetable method 21 | of calculation of life expectancy. 22 | } 23 | \references{ 24 | \insertRef{preston2000demography}{DemoTools} 25 | } 26 | -------------------------------------------------------------------------------- /man/lt_id_Ll_S.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_Ll_S} 4 | \alias{lt_id_Ll_S} 5 | \title{Calculate survivor ratios} 6 | \usage{ 7 | lt_id_Ll_S(nLx, lx = NULL, Age, AgeInt = NULL, N = 5) 8 | } 9 | \arguments{ 10 | \item{nLx}{numeric vector of lifetable exposure.} 11 | 12 | \item{lx}{numeric vector of lifetable survivors from same lifetable than \code{nLx}. Infered radix from nLx in case is \code{NULL}.} 13 | 14 | \item{Age}{integer vector of starting ages.} 15 | 16 | \item{AgeInt}{integer vector of age intervals.} 17 | 18 | \item{N}{integer, the age width for survivor ratios, either 5 or 1. Default 5.} 19 | } 20 | \description{ 21 | An extra lifetable column for use in projections, which require uniform time steps both both age and period. Intervals are either single age or five-year ages. Input vectors are assumed to come from either single or standard abridged ages. Note that the ages of the output Sx are the ages the population would be after the N-year projection. 22 | } 23 | \details{ 24 | This function does not account for \code{nLx} having been pre-binned into uniform 5-year age widths, which will throw an error. Just leave them in abridged ages instead. Note that in the case of abridged ages, the interpretation for the first and second value don't follow the original abridged age intervals: the first value in the probability of surviving from birth into ages 0-4 in the first five years, and the second value is the probability of surviving from 0-4 to 5-9. This represents a slight misalignment with the rest of the lifetable, user beware. 25 | } 26 | -------------------------------------------------------------------------------- /man/lt_id_d_l.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_d_l} 4 | \alias{lt_id_d_l} 5 | \title{Derive survivorship from lifetable deaths} 6 | \usage{ 7 | lt_id_d_l(ndx, radix = sum(ndx)) 8 | } 9 | \arguments{ 10 | \item{ndx}{numeric. Vector of age-specific lifetable deaths.} 11 | 12 | \item{radix}{numeric.} 13 | } 14 | \value{ 15 | lx vector of lifetable survivorship 16 | } 17 | \description{ 18 | This lifetable identity is the same no matter what kind of lifetable is required. You can find it in any demography textbook. 19 | } 20 | \details{ 21 | The vector returned is the same length as \code{dx} and it sums to the lifetable radix. If the radix is one then this is the discrete deaths distribution. 22 | } 23 | \references{ 24 | \insertRef{preston2000demography}{DemoTools} 25 | } 26 | -------------------------------------------------------------------------------- /man/lt_id_d_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_d_q} 4 | \alias{lt_id_d_q} 5 | \title{Derive death probabilities from lifetable deaths} 6 | \usage{ 7 | lt_id_d_q(ndx) 8 | } 9 | \arguments{ 10 | \item{ndx}{numeric. Vector of age-specific lifetable survivorship.} 11 | } 12 | \value{ 13 | nqx vector of lifetable death probabilities. 14 | } 15 | \description{ 16 | This lifetable identity is the same no matter what kind of lifetable is required. You can find it in any demography textbook. 17 | } 18 | \details{ 19 | The vector returned is the same length as \code{dx}. 20 | } 21 | \references{ 22 | \insertRef{preston2000demography}{DemoTools} 23 | } 24 | -------------------------------------------------------------------------------- /man/lt_id_l_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_l_d} 4 | \alias{lt_id_l_d} 5 | \title{Derive lifetable deaths from survivorship.} 6 | \usage{ 7 | lt_id_l_d(lx) 8 | } 9 | \arguments{ 10 | \item{lx}{numeric. Vector of age-specific lifetable survivorship.} 11 | } 12 | \value{ 13 | ndx vector of lifetable deaths. 14 | } 15 | \description{ 16 | This lifetable identity is the same no matter what kind of lifetable is required. 17 | You can find it in any demography textbook. 18 | } 19 | \details{ 20 | The vector returned is the same length as \code{lx} and it sums to the lifetable radix. 21 | If the radix is one then this is the discrete deaths distribution. 22 | } 23 | \references{ 24 | \insertRef{preston2000demography}{DemoTools} 25 | } 26 | -------------------------------------------------------------------------------- /man/lt_id_l_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_l_q} 4 | \alias{lt_id_l_q} 5 | \title{Derive lifetable death probabilities from survivorship.} 6 | \usage{ 7 | lt_id_l_q(lx) 8 | } 9 | \arguments{ 10 | \item{lx}{numeric. Vector of age-specific lifetable survivorship.} 11 | } 12 | \value{ 13 | \code{qx} values of age-specific mortality rates. The last value is always 1.0 14 | } 15 | \description{ 16 | This lifetable identity is the same no matter what kind of lifetable is required. 17 | You can find it in any demography textbook. 18 | } 19 | \details{ 20 | The vector returned is the same length as \code{lx}. 21 | } 22 | \references{ 23 | \insertRef{preston2000demography}{DemoTools} 24 | } 25 | -------------------------------------------------------------------------------- /man/lt_id_lda_L.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_lda_L} 4 | \alias{lt_id_lda_L} 5 | \title{Derive lifetable exposure from lx, ndx and nax.} 6 | \usage{ 7 | lt_id_lda_L(lx, ndx, nax, AgeInt) 8 | } 9 | \arguments{ 10 | \item{lx}{numeric. Vector of age-specific lifetable survivorship.} 11 | 12 | \item{ndx}{numeric. Vector of lifetable deaths, summing to radix of \code{lx}.} 13 | 14 | \item{nax}{numeric. Vector of average time spent in interval by those dying in interval.} 15 | 16 | \item{AgeInt}{integer. Vector of age class widths.} 17 | } 18 | \value{ 19 | nLx numeric vector of lifetable exposure. 20 | } 21 | \description{ 22 | This is a common approximation of lifetable exposure: 23 | All persons surviving to the end of the interval time the interval width, plus all those that died 24 | in the interval multiplied by their average time spent in the interval. 25 | } 26 | \details{ 27 | There is no checking of equal vector lengths at this time. 28 | } 29 | \references{ 30 | \insertRef{preston2000demography}{DemoTools} 31 | } 32 | -------------------------------------------------------------------------------- /man/lt_id_ma_q.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_ma_q} 4 | \alias{lt_id_ma_q} 5 | \title{Calculate conditional death probabilities from nMx and nax} 6 | \usage{ 7 | lt_id_ma_q(nMx, nax, AgeInt, closeout = TRUE, IMR) 8 | } 9 | \arguments{ 10 | \item{nMx}{numeric. Vector of mortality rates in abridged age classes.} 11 | 12 | \item{nax}{numeric. Average time spent in age interval of those that die in the interval.} 13 | 14 | \item{AgeInt}{integer. Vector of age class widths. Default \code{inferAgeIntAbr(Age = Age)}.} 15 | 16 | \item{closeout}{logical. Set final age to 1 if TRUE. Identity otherwise. Default \code{TRUE}.} 17 | 18 | \item{IMR}{numeric. Optional q0 to impute, in case available separately.} 19 | } 20 | \description{ 21 | Sometimes a given age interval, death rate, and a(x) imply a death probability that is greater than 1. In this case either the interval needs to be extended or a(x) decreased. This especially arises with mid interval a(x) has been assumed in five-year age groups. This backstop reduces a(x) by assuming a constant death rate over the single ages within the interval, assuming mid interval a(x) for each single age, producing nq(x) by identity from the (5) single ages. 22 | } 23 | \details{ 24 | nMx equal to 2 will imply nqx of 1 by this formula. Implied nqx greater than 1 after this procedure are returned as 1. This is not vectorized! 25 | } 26 | \examples{ 27 | # implies a qx > 1 28 | mx <- .65 29 | AgeInt <- 5 30 | ax <- 2.5 31 | # this is a problematic case 32 | (AgeInt * mx) / (1 + (AgeInt - ax) * mx) 33 | # here a workable value 34 | (lt_id_ma_q(mx, ax, AgeInt, closeout = FALSE)) 35 | #' # still less than 1 36 | lt_id_ma_q(1.99, ax, AgeInt, closeout = FALSE) < 1 37 | # unity 38 | (lt_id_ma_q(2, ax, AgeInt, closeout = FALSE)) 39 | # qx imputed as 1 40 | (lt_id_ma_q(2.1, ax, AgeInt, closeout = FALSE)) 41 | } 42 | -------------------------------------------------------------------------------- /man/lt_id_q_l.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_q_l} 4 | \alias{lt_id_q_l} 5 | \title{Derive lifetable survivorship (lx) from death probabilities.} 6 | \usage{ 7 | lt_id_q_l(nqx, radix = 1e+05) 8 | } 9 | \arguments{ 10 | \item{nqx}{numeric. Vector of age specific death probabilities.} 11 | 12 | \item{radix}{numeric. The lifetable starting population. Default 100000.} 13 | } 14 | \value{ 15 | lx vector of lifetable survivorship. 16 | } 17 | \description{ 18 | This lifetable identity is the same no matter what kind of lifetable is required. 19 | You can find it in any demography textbook. 20 | } 21 | \details{ 22 | #' @export 23 | #' @rdname lt_id_ma_q 24 | mxax2qx <- lt_id_ma_q 25 | 26 | set \code{radix = 1} for the probability of surviving until age x. The vector returned is 27 | the same length as \code{nqx}, thereby throwing out the final value of qx, which is usually set to 1. 28 | } 29 | \references{ 30 | \insertRef{preston2000demography}{DemoTools} 31 | } 32 | -------------------------------------------------------------------------------- /man/lt_id_qa_m.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_qa_m} 4 | \alias{lt_id_qa_m} 5 | \title{Derive nMx from nqx and nax.} 6 | \usage{ 7 | lt_id_qa_m(nqx, nax, AgeInt) 8 | } 9 | \arguments{ 10 | \item{nqx}{numeric. Vector of age specific death probabilities.} 11 | 12 | \item{nax}{numeric. Vector of average time spent in interval by those dying in interval.} 13 | 14 | \item{AgeInt}{integer. Vector of age class widths.} 15 | } 16 | \value{ 17 | nMx vector of age specific death rates derived via identity. 18 | } 19 | \description{ 20 | This is the standard identity to derive nMx from nax and nqx. 21 | } 22 | \references{ 23 | \insertRef{preston2000demography}{DemoTools} 24 | } 25 | -------------------------------------------------------------------------------- /man/lt_id_qm_a.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_id.R 3 | \name{lt_id_qm_a} 4 | \alias{lt_id_qm_a} 5 | \title{Derive nax from nqx and nMx.} 6 | \usage{ 7 | lt_id_qm_a(nqx, nMx, AgeInt) 8 | } 9 | \arguments{ 10 | \item{nqx}{numeric. Vector of age specific death probabilities.} 11 | 12 | \item{nMx}{numeric. Vector of age-specific death rates.} 13 | 14 | \item{AgeInt}{integer. Vector of age class widths.} 15 | } 16 | \value{ 17 | nax numeric vector of average time spent in interval by those dying in interval via identity. 18 | } 19 | \description{ 20 | This is the standard identity to derive nax from nqx and nMx. 21 | } 22 | \references{ 23 | \insertRef{preston2000demography}{DemoTools} 24 | } 25 | -------------------------------------------------------------------------------- /man/lt_rule_1a0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_rule.R 3 | \name{lt_rule_1a0} 4 | \alias{lt_rule_1a0} 5 | \title{calculate a0 in different ways} 6 | \usage{ 7 | lt_rule_1a0( 8 | rule = "ak", 9 | M0 = NULL, 10 | q0 = NULL, 11 | Sex = "m", 12 | IMR = NA, 13 | region = "w", 14 | SRB = 1.05 15 | ) 16 | } 17 | \arguments{ 18 | \item{rule}{character. Either \code{"ak"} (Andreev-Kingkade) or \code{"cd"} (Coale-Demeny).} 19 | 20 | \item{M0}{numeric. Event exposure infant mortality rate.} 21 | 22 | \item{q0}{a value or vector of values of m0, the death risk in the first year of life.} 23 | 24 | \item{Sex}{character, either \code{"m"}, \code{"f"}, or \code{"b"}} 25 | 26 | \item{IMR}{numeric. Optional. {\ifelse{html}{\out{q0}}{\eqn{q_0}}}, the death probability in first year of life, in case available separately.} 27 | 28 | \item{region}{character. \code{"n"}, \code{"e"}, \code{"s"} or \code{"w"} for North, East, South, or West.} 29 | 30 | \item{SRB}{the sex ratio at birth (boys / girls), default 1.05} 31 | } 32 | \value{ 33 | a0, the estimated average age at death of those dying in the first year of life, either a single value or a vector of values. 34 | } 35 | \description{ 36 | This function wraps the Coale-Demeny and Andreev-Kingkade approximations for \code{a0}, which can come from \code{M0}, \code{q0}, or \code{IMR.} 37 | } 38 | \details{ 39 | If sex is given as both, \code{"b"}, then we calculate the male and female results separately, then weight them together using SRB. This is bad in theory, but the leverage is trivial, and it's better than using male or female coefs for the total population. 40 | 41 | Neither Coale-Demeny nor Andreev-Kingkade have explicit a0 rules for both-sexes combined. There's not a good way to arrive at a both-sex a0 estimate without increasing data requirements (you'd need data from each sex, which are not always available). It's more convenient to blend sex-specific a0 estimates based on something. Here we use SRB to do this, for no other reason than it has an easy well-known default value. This is bad because it assumes no sex differences in infant mortality, but this choice has a trivial impact on results. 42 | } 43 | -------------------------------------------------------------------------------- /man/lt_rule_1a0_ak.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_rule.R 3 | \name{lt_rule_1a0_ak} 4 | \alias{lt_rule_1a0_ak} 5 | \title{Andreev-Kingkade approximation for a0} 6 | \usage{ 7 | lt_rule_1a0_ak(M0 = NULL, q0 = NULL, Sex) 8 | } 9 | \arguments{ 10 | \item{M0}{a value or vector of values of `1m0``, the death risk in the first year of life.} 11 | 12 | \item{q0}{a value or vector of values of `1q0``, the death probability in the first year of life, sometimes approximated with IMR.} 13 | 14 | \item{Sex}{either \code{"m"} or \code{"f"}} 15 | } 16 | \value{ 17 | a0, the estimated average age at death of those dying in the first year of life, either a single value or a vector of values. 18 | } 19 | \description{ 20 | This function wraps the two approximations for a0 based on either q0 (IMR) or m0. 21 | } 22 | -------------------------------------------------------------------------------- /man/lt_rule_ak_m0_a0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_rule.R 3 | \name{lt_rule_ak_m0_a0} 4 | \alias{lt_rule_ak_m0_a0} 5 | \title{estimates a0 using the Andreev-Kingkade rule of thumb starting with an event exposure rate} 6 | \usage{ 7 | lt_rule_ak_m0_a0(M0, Sex) 8 | } 9 | \arguments{ 10 | \item{M0}{a value or vector of values of m0, the death risk in the first year of life.} 11 | 12 | \item{Sex}{either "m" or "f"} 13 | } 14 | \value{ 15 | a0, the estimated average age at death of those dying in the first year of life, either a single value or a vector of values. 16 | } 17 | \description{ 18 | These formulas and cutpoints are based on a supplementary analysis from Andreev & Kingkade. The original formulation was in terms of IMR. There is also an analytic path to convert M0 to q0 and then use the original q0 cutpoints. Code ported from HMD code base. 19 | } 20 | -------------------------------------------------------------------------------- /man/lt_rule_ak_q0_a0.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_rule.R 3 | \name{lt_rule_ak_q0_a0} 4 | \alias{lt_rule_ak_q0_a0} 5 | \title{estimates a0 using the Andreev-Kingkade rule of thumb starting with IMR} 6 | \usage{ 7 | lt_rule_ak_q0_a0(q0, Sex) 8 | } 9 | \arguments{ 10 | \item{q0}{a value or vector of values of q0, the death probability in the first year of life.} 11 | 12 | \item{Sex}{either "m" or "f"} 13 | } 14 | \value{ 15 | a0, the estimated average age at death of those dying in the first year of life, either a single value or a vector of a_0 values. 16 | } 17 | \description{ 18 | \code{AKq02a0} Andreev Kingkade a0 method. This version has a 3-part segmented linear model, based on cut points in q0. Code ported from HMDLifeTables. 19 | } 20 | -------------------------------------------------------------------------------- /man/lt_single2abridged.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_regroup_age.R 3 | \name{lt_single2abridged} 4 | \alias{lt_single2abridged} 5 | \title{calculate an abridged life table that is consistent with a life table by single year of age} 6 | \usage{ 7 | lt_single2abridged(lx, nLx, ex, Age = 1:length(lx) - 1, ...) 8 | } 9 | \arguments{ 10 | \item{lx}{numeric. Vector of lifetable survivorship at single ages.} 11 | 12 | \item{nLx}{numeric. Vector of lifetable exposure at single ages.} 13 | 14 | \item{ex}{numeric. Vector of Age-specific remaining life expectancy at single ages.} 15 | 16 | \item{Age}{integer. Lower bounds of single ages.} 17 | 18 | \item{...}{optional args, not currently used.} 19 | } 20 | \value{ 21 | Abridged lifetable in \code{data.frame} with columns 22 | \code{Age} integer. Lower bound of abridged age class 23 | \code{AgeInt} integer. Age class widths. 24 | \code{nMx} numeric. Age-specific central death rates. 25 | \code{nAx} numeric. Average time spent in interval by those deceased in interval. 26 | \code{nqx} numeric. Age-specific conditional death probabilities. 27 | \code{lx} numeric. Lifetable survivorship 28 | \code{ndx} numeric. Lifetable deaths distribution. 29 | \code{nLx} numeric. Lifetable exposure. 30 | \code{Sx} numeric. Survivor ratios in uniform 5-year age groups. 31 | \code{Tx} numeric. Lifetable total years left to live above age x. 32 | \code{ex} numeric. Age-specific remaining life expectancy. 33 | } 34 | \description{ 35 | Computes abridged life table columns based on the lx, nLx , and ex values from 36 | a single year life table, in accordance with step 2.2 of the Human Life Table Protocol 37 | https://www.lifetable.de/methodology.pdf. Output abridged life table has same open age group 38 | as input single age life table 39 | } 40 | \details{ 41 | Similar to \code{lt_abridged()} details, forthcoming 42 | } 43 | -------------------------------------------------------------------------------- /man/lt_smooth_ambiguous.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interp_lc_lim.R 3 | \name{lt_smooth_ambiguous} 4 | \alias{lt_smooth_ambiguous} 5 | \title{Smooth and apply lt_ambiguous} 6 | \usage{ 7 | lt_smooth_ambiguous(input, ...) 8 | } 9 | \arguments{ 10 | \item{input}{data.frame. with cols: Date, Sex, Age, nMx (opt), nqx (opt), lx (opt)} 11 | 12 | \item{...}{Other arguments to be passed on to the \code{\link[DemoTools]{lt_abridged}} function.} 13 | } 14 | \description{ 15 | Considering different mortality input for each sex/year data, 16 | smooth older ages with makeham or kannisto in case no law was specified, 17 | and return a data.frame with standard LT. 18 | } 19 | \details{ 20 | Makeham is chosen if last age is less than 90. Else Kannisto. 21 | } 22 | -------------------------------------------------------------------------------- /man/lthat.logquad.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lt_model_lq.R 3 | \name{lthat.logquad} 4 | \alias{lthat.logquad} 5 | \title{Estimated life table using the log-quadratic model} 6 | \usage{ 7 | lthat.logquad( 8 | coefs, 9 | x, 10 | q0_5, 11 | k, 12 | radix, 13 | axmethod = "pas", 14 | a0rule = "ak", 15 | Sex = "m", 16 | IMR = NA, 17 | region = "w", 18 | mod = TRUE, 19 | SRB = 1.05 20 | ) 21 | } 22 | \arguments{ 23 | \item{coefs}{Estimated coefficients} 24 | 25 | \item{q0_5}{5q0. The probability that a new-born will die during the 26 | subsequent 5 years;} 27 | 28 | \item{radix}{Life table radix. Default: 10^5;} 29 | 30 | \item{axmethod}{character. Either \code{"pas"} or \code{"un"}.} 31 | 32 | \item{a0rule}{character. Either \code{"ak"} (default) or \code{"cd"}.} 33 | 34 | \item{Sex}{Choose the sex of the population. This choice defines the use 35 | of a corresponding Log-Quadratic (\code{wilmoth}) 36 | model fitted for the whole Human Mortality Database (as of Dec 2019, 37 | there are 968 life tables for each sex). 38 | The following options are available: \itemize{ 39 | \item{\code{"b"}} -- Both sex; 40 | \item{\code{"f"}} -- Females; 41 | \item{\code{"m"}} -- Males. 42 | }} 43 | 44 | \item{IMR}{numeric. Infant mortality rate \ifelse{html}{\out{q0}}{\eqn{q_0}}, in case available and \code{nqx} is not specified. Default \code{NA}.} 45 | 46 | \item{region}{character. North, East, South, or West: \code{"n"}, \code{"e"}, \code{"s"}, \code{"w"}. Default \code{"w"}.} 47 | 48 | \item{mod}{logical. If \code{"un"} specified for \code{axmethod}, whether or not to use Nan Li's modification for ages 5-14. Default \code{TRUE}.} 49 | 50 | \item{SRB}{the sex ratio at birth (boys / girls), default 1.05} 51 | } 52 | \description{ 53 | Estimated life table using the log-quadratic model 54 | } 55 | \keyword{internal} 56 | -------------------------------------------------------------------------------- /man/mA_swe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mA_swe} 5 | \alias{mA_swe} 6 | \title{Swedish abridged mortality rates} 7 | \format{ 8 | A data frame with: 9 | \describe{ 10 | \item{Date}{Reference time for the rates estimate.} 11 | \item{Age}{Inferior age for abridged groups. Careful: last age 100 is not an OAG} 12 | \item{Sex}{Male \code{m} and female \code{m}.} 13 | \item{nMx}{Mortality rates.} 14 | } 15 | } 16 | \source{ 17 | Human Mortality Database. Retrieved 2021-20-01, from \url{https://mortality.org} 18 | } 19 | \usage{ 20 | mA_swe 21 | } 22 | \description{ 23 | Mortality rates in tidy format for each sex in dates 1990-07-01, 2000-07-01, 2010-07-01 24 | } 25 | \keyword{datasets} 26 | -------------------------------------------------------------------------------- /man/ma.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{ma} 4 | \alias{ma} 5 | \title{A simple centered moving average function.} 6 | \usage{ 7 | ma(x, n = 5) 8 | } 9 | \arguments{ 10 | \item{x}{numeric. Vector to produce a moving average of.} 11 | 12 | \item{n}{integer. The width of the moving average. Default 5 time steps.} 13 | } 14 | \value{ 15 | Numeric vector of same length as \code{x}. 16 | } 17 | \description{ 18 | This function is defined based on a code chunk found \href{https://stackoverflow.com/questions/743812/calculating-moving-average}{here}. 19 | This is a centered moving average of arbitrary width. 20 | } 21 | \details{ 22 | \code{NA} values 23 | are used as padding on the left and right to make the returned vector of equal length. 24 | } 25 | \examples{ 26 | x <- runif(100) 27 | xx <- cumsum(x) 28 | \dontrun{ 29 | plot(x) 30 | lines(ma(x)) 31 | lines(ma(x),9) 32 | } 33 | # some de facto unit tests: 34 | x <- 1:10 35 | d2 <- ma(x,2) - x 36 | d3 <- ma(x,3) - x 37 | d4 <- ma(x,4) - x 38 | d5 <- ma(x,5) - x 39 | # pop <- sample.int(10, 5, replace = T) 40 | # all should give same for linear data. 41 | stopifnot(all(abs(d2) < 1e-10, na.rm = TRUE)) 42 | stopifnot(all(abs(d3) < 1e-10, na.rm = TRUE)) 43 | stopifnot(all(abs(d4) < 1e-10, na.rm = TRUE)) 44 | stopifnot(all(abs(d5) < 1e-10, na.rm = TRUE)) 45 | } 46 | -------------------------------------------------------------------------------- /man/maxA2abridged.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{maxA2abridged} 4 | \alias{maxA2abridged} 5 | \title{Determine abridged ages up to a given maximum age group.} 6 | \usage{ 7 | maxA2abridged(ageMax = 80) 8 | } 9 | \arguments{ 10 | \item{ageMax}{integer. Default 80.} 11 | } 12 | \value{ 13 | integer. Vector of ages, e.g. \code{c(0,1,5,10,15,...)}. 14 | } 15 | \description{ 16 | Produce standard abridged age groups (lower bounds) up to a specified maximum age group. 17 | } 18 | \details{ 19 | If the highest age group is not evenly divisible by 5 then age classes only go up to its 5-year lower bound. 20 | } 21 | \examples{ 22 | maxA2abridged(80) 23 | all(maxA2abridged(100) == maxA2abridged(102)) 24 | } 25 | -------------------------------------------------------------------------------- /man/mig_calculate_rc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mig_rc.R 3 | \name{mig_calculate_rc} 4 | \alias{mig_calculate_rc} 5 | \title{Calculate Rogers-Castro migration age schedule} 6 | \usage{ 7 | mig_calculate_rc(ages, pars) 8 | } 9 | \arguments{ 10 | \item{ages}{numeric. A vector of ages for migration rates to be calculated.} 11 | 12 | \item{pars}{numeric. A named list of parameters. See below for details.} 13 | } 14 | \description{ 15 | Given a set of ages and parameters, calculate the migration age schedule based on the Rogers and Castro formula. 16 | Choose between a 7,9,11 or 13 parameter model. 17 | } 18 | \details{ 19 | In the full 13 parameter model, the migration rate at age x, \eqn{m(x)} is defined as 20 | \deqn{m(x) = a1*exp(-1*alpha1*x) + a2*exp(-1*alpha2*(x - mu2) - exp(-1*lambda2*(x - mu2))) + a3*exp(-1*alpha3*(x - mu3) - exp(-1*lambda3*(x - mu3))) + a4*exp(lambda4*x) + c} 21 | 22 | The first, second, third and fourth pieces of the equation represent pre-working age, working age, retirement and post-retirement age patterns, respectively. 23 | Models with less parameters gradually remove terms at the older ages. Parameters in each family are: 24 | \itemize{ 25 | \item pre-working age: a1, alpha1 26 | \item working age: a2, alpha2, mu2, lambda2 27 | \item retirement: a3, alpha3, mu3, lambda3 28 | \item post retirement: a4, lambda4 29 | } 30 | 31 | For a specific family to be included, values for all parameters in that family must be specified. 32 | } 33 | \examples{ 34 | \dontrun{ 35 | pars <- c(a1= 0.09, alpha1= 0.1, a2= 0.2, 36 | alpha2= 0.1, mu2= 21, lambda2= 0.39, a3= 0.001, 37 | alpha3= 1, mu3= 67, lambda3= 0.6, c= 0.01) 38 | ages <- 0:75 39 | mx <- mig_calculate_rc(ages = ages, pars = pars) 40 | plot(ages, mx, type = 'l') 41 | } 42 | } 43 | \references{ 44 | \insertRef{rogers1981model}{DemoTools} 45 | } 46 | -------------------------------------------------------------------------------- /man/mig_un_fam.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mig_un_fam.R 3 | \name{mig_un_fam} 4 | \alias{mig_un_fam} 5 | \title{Net migration by age for an UN family} 6 | \usage{ 7 | mig_un_fam(NM, family, Single = TRUE, OAnew = 100) 8 | } 9 | \arguments{ 10 | \item{NM}{numeric. Total net migration to distribute between ages and sex.} 11 | 12 | \item{family}{character. Could be "Family", "Female Labor", "Male Labor".} 13 | 14 | \item{Single}{logical. Results by simple age. Default \code{TRUE}. 15 | Typically from pre-working age and working age parts of in Roger-Castro formula.} 16 | 17 | \item{OAnew}{The age from which to group all ages into an open ended age group. 18 | By default it is set to 100, so it groups all ages up to 120, which is the 19 | maximum age.} 20 | } 21 | \value{ 22 | List with 23 | \itemize{ 24 | \item \code{params_RC} \code{data.frame}. Roger-Castro parameters in a \code{data.frame}. Same as \code{mig_un_params} data. 25 | \item \code{net_migr} \code{data.frame}. Net migrants by age and sex for the chosen family. 26 | } 27 | } 28 | \description{ 29 | Given a total net migration, 30 | calculate the net migration age schedule based on the Rogers and Castro formula for UN families. 31 | } 32 | \examples{ 33 | # 10000 net migrants, comparing two possible families 34 | nm1 <- mig_un_fam(NM = 10000, family = "Male Labor", OAnew = 100) 35 | nm2 <- mig_un_fam(NM = 10000, family = "Family", OAnew = 100) 36 | # See the female profile in for these models: 37 | \dontrun{ 38 | plot(nm1$net_migr$age[nm1$net_migr$sex=="Female"], 39 | nm1$net_migr$nm[nm1$net_migr$sex=="Female"], 40 | xlab="Age",ylab="nm",ylim=c(0,300)) 41 | points(nm2$net_migr$age[nm2$net_migr$sex=="Female"], 42 | nm2$net_migr$nm[nm2$net_migr$sex=="Female"], col=2) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /man/mig_un_families.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mig_un_families} 5 | \alias{mig_un_families} 6 | \title{Proportion of net migrants by age and sex for considered migration profiles} 7 | \format{ 8 | A data frame with: 9 | \describe{ 10 | \item{family}{Types Family, Male Labor or Female Labor.} 11 | \item{sex}{Male and Female.} 12 | \item{mig_sign}{Inmigration or Emigration.} 13 | \item{age}{Simple ages from 0 to 80 (OAG).} 14 | \item{prop}{Proportion of net migrants due to that sex and age.} 15 | } 16 | } 17 | \source{ 18 | UN spreadsheet "UNPD_Migration Age Profiles.xlsx" 19 | } 20 | \usage{ 21 | mig_un_families 22 | } 23 | \description{ 24 | Roger-Castro estimated proportion of total net migrants using parameters from \code{mig_un_params} data. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/mig_un_params.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{mig_un_params} 5 | \alias{mig_un_params} 6 | \title{Parameters for considered migration profiles} 7 | \format{ 8 | A data frame with: 9 | \describe{ 10 | \item{family}{Types Family, Male Labor or Female Labor.} 11 | \item{sex}{Male and Female.} 12 | \item{mig_sign}{Inmigration or Emigration.} 13 | \item{param}{Parameters from Roger-Castro.} 14 | \item{median}{median of posterior distribution using Monte Carlo Markov Chains in \code{mig_estimate_rc}.} 15 | } 16 | } 17 | \source{ 18 | UN spreadsheet "UNPD_Migration Age Profiles.xlsx" 19 | } 20 | \usage{ 21 | mig_un_params 22 | } 23 | \description{ 24 | Roger-Castro estimated parameters using \code{mig_estimate_rc} for Pre Working Age and Working Age profiles of migration. 25 | } 26 | \keyword{datasets} 27 | -------------------------------------------------------------------------------- /man/names2age.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilsAge.R 3 | \name{names2age} 4 | \alias{names2age} 5 | \title{detect ages from names of vector(s)} 6 | \usage{ 7 | names2age(...) 8 | } 9 | \arguments{ 10 | \item{...}{one or more vectors of any class, which has/have a names attribute.} 11 | } 12 | \value{ 13 | integer vector of ages (presumably). 14 | } 15 | \description{ 16 | Often as a shorthand we pull lower age bounds from the names of a vector. This modulates that action, and allows for giving several vectors to check for names. 17 | } 18 | \details{ 19 | If more than one vector is given, names are pulled from the first available named vector. All vectors must be of the same length. If no names are available on any vector, then \code{NA}s are returned. This clearly won't work if the names on the vector are of something else. 20 | } 21 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling \code{rhs(lhs)}. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/pop1m_ind.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop1m_ind} 5 | \alias{pop1m_ind} 6 | \title{Indian male population 1971} 7 | \format{ 8 | A numeric vector of length 101 9 | } 10 | \source{ 11 | REGISTRAR GENERAL & CENSUS COMMISSIONER, INDIA, 1976, 12 | Census of India 1971, Series 1, India, Social and Cultural Tables, 13 | Part II-C(ii), New Delhi 14 | } 15 | \usage{ 16 | pop1m_ind 17 | } 18 | \description{ 19 | Indian male population 1971 20 | } 21 | \keyword{datasets} 22 | -------------------------------------------------------------------------------- /man/pop1m_pasex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop1m_pasex} 5 | \alias{pop1m_pasex} 6 | \title{Male population by 1 year age groups} 7 | \format{ 8 | A numeric vector of length 100 9 | } 10 | \source{ 11 | The data comes from 12 | \url{https://URL} 13 | } 14 | \usage{ 15 | pop1m_pasex 16 | } 17 | \description{ 18 | Male population by 1 year age groups from PASEX SINGAGE 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop1m_rus2002.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop1m_rus2002} 5 | \alias{pop1m_rus2002} 6 | \title{Russian census 2002 male population by 1 year age groups} 7 | \format{ 8 | A numeric vector of length 101 9 | } 10 | \source{ 11 | The data comes from 12 | \url{http://www.demoscope.ru/weekly/ssp/rus2002_01.php} 13 | } 14 | \usage{ 15 | pop1m_rus2002 16 | } 17 | \description{ 18 | Male population by 1 year age groups from Russian census help on 2002-10-16 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop1m_rus2010.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop1m_rus2010} 5 | \alias{pop1m_rus2010} 6 | \title{Russian census 2010 male population by 1 year age groups} 7 | \format{ 8 | A numeric vector of length 101 9 | } 10 | \source{ 11 | The data comes from 12 | \url{http://www.demoscope.ru/weekly/ssp/rus_age1_10.php} 13 | } 14 | \usage{ 15 | pop1m_rus2010 16 | } 17 | \description{ 18 | Male population by 1 year age groups from Russian census help on 2010-10-25 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop5_mat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop5_mat} 5 | \alias{pop5_mat} 6 | \title{Matrix of population over 5 years} 7 | \format{ 8 | A matrix of 21 rows and 5 columns 9 | } 10 | \source{ 11 | The data comes from 12 | \url{https://URL} 13 | } 14 | \usage{ 15 | pop5_mat 16 | } 17 | \description{ 18 | Matrix of population over 5 years, 5 year age groups, some population 1950-1954 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop5m_pasex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop5m_pasex} 5 | \alias{pop5m_pasex} 6 | \title{Male population by 5 year age groups} 7 | \format{ 8 | A numeric vector of length 17 9 | } 10 | \source{ 11 | The data comes from 12 | \url{https://URL} 13 | } 14 | \usage{ 15 | pop5m_pasex 16 | } 17 | \description{ 18 | Male population by 5 year age groups from PASEX AGESMTH 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/popA_earlier.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{popA_earlier} 5 | \alias{popA_earlier} 6 | \title{Abridged population from PAS AGEINT -- earlier} 7 | \format{ 8 | A numeric vector of length 18 9 | } 10 | \source{ 11 | The data comes from 12 | \url{http://} 13 | } 14 | \usage{ 15 | popA_earlier 16 | } 17 | \description{ 18 | Abridged population from PAS AGEINT -- earlier, 1980 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/popA_later.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{popA_later} 5 | \alias{popA_later} 6 | \title{Abridged population from PAS AGEINT -- later} 7 | \format{ 8 | A numeric vector of length 18 9 | } 10 | \source{ 11 | The data comes from 12 | \url{http://} 13 | } 14 | \usage{ 15 | popA_later 16 | } 17 | \description{ 18 | Abridged population from PAS AGEINT -- later, 1990 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop_f_mat_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop_f_mat_five} 5 | \alias{pop_f_mat_five} 6 | \title{Population matrix for females five year age groups between 1950 and 2050} 7 | \format{ 8 | A matrix of dimensions 21 x 21 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | pop_f_mat_five 15 | } 16 | \description{ 17 | Population matrix for females five year age groups between 1950 and 2050 for 18 | unknown country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop_f_mat_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop_f_mat_single} 5 | \alias{pop_f_mat_single} 6 | \title{Population matrix for females single ages between 1999 and 2019} 7 | \format{ 8 | A matrix of dimensions 101 x 21 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | pop_f_mat_single 15 | } 16 | \description{ 17 | Population matrix for females single ages between 1999 and 2019 for 18 | Sweden 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop_m_mat_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop_m_mat_five} 5 | \alias{pop_m_mat_five} 6 | \title{Population matrix for males five year age groups between 1950 and 2050} 7 | \format{ 8 | A matrix of dimensions 21 x 21 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | pop_m_mat_five 15 | } 16 | \description{ 17 | Population matrix for males five year age groups between 1950 and 2050 for 18 | unknown country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/pop_m_mat_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{pop_m_mat_single} 5 | \alias{pop_m_mat_single} 6 | \title{Population matrix for males single ages between 1999 and 2019} 7 | \format{ 8 | A matrix of dimensions 101 x 21 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | pop_m_mat_single 15 | } 16 | \description{ 17 | Population matrix for males single ages between 1999 and 2019 for 18 | Sweden 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/ratx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{ratx} 4 | \alias{ratx} 5 | \title{Take consecutive ratios of a vector.} 6 | \usage{ 7 | ratx(fx, k = 1) 8 | } 9 | \arguments{ 10 | \item{fx}{numeric. Vector of \code{length > k}.} 11 | 12 | \item{k}{integer. The size of the lag in elements of \code{fx}.} 13 | } 14 | \description{ 15 | This can be used, for example to take survival ratios. 16 | } 17 | \details{ 18 | Behavior similar to \code{diff()}, in that returned vector is \code{k} elements 19 | shorter than the given vector \code{fx}. 20 | } 21 | \examples{ 22 | fx <- 1:10 23 | ratx(fx) 24 | ratx(fx,-1) 25 | ratx(fx,0) 26 | } 27 | -------------------------------------------------------------------------------- /man/rescale_vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{rescale_vector} 4 | \alias{rescale_vector} 5 | \title{Rescale a vector proportionally to a new sum.} 6 | \usage{ 7 | rescale_vector(x, scale = 1) 8 | } 9 | \arguments{ 10 | \item{x}{numeric vector.} 11 | 12 | \item{scale}{numeric. Value the vector should sum to. Default 1.} 13 | } 14 | \value{ 15 | The vector rescaled. 16 | } 17 | \description{ 18 | Function used to rescale a vector to a given value. This is a frequently needed operation. 19 | } 20 | \details{ 21 | For a distribution, use \code{scale = 1}. For percentages, use \code{scale = 100}, etc. 22 | } 23 | \examples{ 24 | x <- runif(10) 25 | sum(x) 26 | xx <- rescale_vector(x,100) 27 | sum(xx) 28 | } 29 | -------------------------------------------------------------------------------- /man/rlog.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{rlog} 4 | \alias{rlog} 5 | \title{Logging that does not cause jams.} 6 | \usage{ 7 | rlog(x, base = exp(1)) 8 | } 9 | \arguments{ 10 | \item{x}{numeric or complex vector.} 11 | 12 | \item{base}{positive or complex number. The base with respect to which 13 | logarithms are computed. Defaults to \code{e=exp(1)}.} 14 | } 15 | \description{ 16 | Zeros happen. Logging zeros leads to errors in downstream code. 17 | For the sake of robustness, we replace zeros with a small positive number to be 18 | able to continue with calculations. 19 | } 20 | \details{ 21 | Use judiciously, since errors are good too. 22 | } 23 | -------------------------------------------------------------------------------- /man/sexRatioScore.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AGESEX.R 3 | \name{sexRatioScore} 4 | \alias{sexRatioScore} 5 | \title{Calculate the PAS sex ratio score} 6 | \usage{ 7 | sexRatioScore(Males, Females, Age, ageMin = 0, ageMax = max(Age), OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Males}{numeric. A vector of demographic counts in 5-year age groups for males.} 11 | 12 | \item{Females}{numeric. A vector of demographic counts in 5-year age groups for females.} 13 | 14 | \item{Age}{numeric. A vector of ages corresponding to the lower integer bound of the counts.} 15 | 16 | \item{ageMin}{integer. The lowest age included in calculations. Default 0.} 17 | 18 | \item{ageMax}{integer. The upper age bound used for calculations. Default \code{max(Age)}.} 19 | 20 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 21 | } 22 | \value{ 23 | The value of the index. 24 | } 25 | \description{ 26 | A single ratio is defined as males per 100 females. 27 | Taking the first difference of the ratios over age would give 0s 28 | if the ratio were constant. The average absolute difference over 29 | age defines the index. This comes from the PAS spreadsheet called AGESEX. 30 | } 31 | \details{ 32 | Age groups must be of equal intervals. Five year age groups are assumed. 33 | It is also assumed that the final age group is open, unless \code{ageMax < max(Age)}. 34 | } 35 | \examples{ 36 | Males <- c(4677000,4135000,3825000,3647000,3247000,2802000,2409000,2212000, 37 | 1786000,1505000,1390000,984000,745000,537000,346000,335000) 38 | Females <- c(4544000,4042000,3735000,3647000,3309000,2793000,2353000,2112000, 39 | 1691000,1409000,1241000,887000,697000,525000,348000,366000) 40 | Age <- seq(0, 75, by = 5) 41 | sexRatioScore(Males, Females, Age) # 2.2, matches PAS 42 | } 43 | \references{ 44 | \insertRef{accuracyun1952}{DemoTools} 45 | \insertRef{PAS}{DemoTools} 46 | } 47 | -------------------------------------------------------------------------------- /man/shift.vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{shift.vector} 4 | \alias{shift.vector} 5 | \title{Shift a vector left or right.} 6 | \usage{ 7 | shift.vector(x, shift = 0, fill = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{vector.} 11 | 12 | \item{shift}{integer. Value \code{< length(x)}. Default 0.} 13 | 14 | \item{fill}{Values to fill newly created positions, e.g. \code{FALSE}, \code{NA}, or \code{0}.} 15 | } 16 | \value{ 17 | The vector x, shifted left or right. 18 | } 19 | \description{ 20 | Simple function to move the elements of a vector to earlier or 21 | later positions depending on the value of \code{shift}. Auxiliary to other functions, 22 | rather multipurpose. 23 | } 24 | \details{ 25 | Nothing fancy here. This is used for example in \code{Noumbissi()} to match denominator ranges to numerator positions using logical vectors. 26 | } 27 | -------------------------------------------------------------------------------- /man/shift_census_ages_to_cohorts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/interp_coh.R 3 | \name{shift_census_ages_to_cohorts} 4 | \alias{shift_census_ages_to_cohorts} 5 | \title{shift census populations to match single year cohorts} 6 | \usage{ 7 | shift_census_ages_to_cohorts( 8 | pop, 9 | age, 10 | date, 11 | censusYearOpt = "frac", 12 | OAG = TRUE 13 | ) 14 | } 15 | \arguments{ 16 | \item{pop}{numeric vector. Population counts in age groups, presumably from a census with an exact reference date.} 17 | 18 | \item{age}{integer vector. Lower bound of single age groups} 19 | 20 | \item{date}{Either a \code{Date} class object or an unambiguous character string in the format \code{"YYYY-MM-DD"}.} 21 | 22 | \item{censusYearOpt}{character or \code{NA}. Options include: 23 | \itemize{ 24 | \item \code{"frac"} keep the partial cohort observed in the year of the census. 25 | \item \code{"drop"} remove the partial cohort from the census year (and trim other outputs to match) 26 | \item \code{"extrap"} inflate the partial cohort from the census year. Specifically we keep it the same as the input age 0. 27 | \item \code{NA} return \code{NA} for the census year cohort size. 28 | }} 29 | 30 | \item{OAG}{logical. Is the highest age group an open age? If \code{TRUE}} 31 | } 32 | \description{ 33 | Matches the (single) ages of a census to single cohorts. For use in intercensal interpolations. Ages are potentially blended to match single cohort line assuming that the population in each age is uniformly distributed over the age group. 34 | } 35 | \examples{ 36 | pop <- seq(10000,100,length.out = 101) 37 | age <- 0:100 38 | d1 <- "2020-01-01" 39 | d2 <- "2020-07-01" 40 | d3 <- "2020-12-21" 41 | 42 | shift_census_ages_to_cohorts(pop, age, d1) 43 | shift_census_ages_to_cohorts(pop, age, d2) 44 | shift_census_ages_to_cohorts(pop, age, d3) 45 | shift_census_ages_to_cohorts(pop, age, 2020.5) 46 | } 47 | -------------------------------------------------------------------------------- /man/simplify.text.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{simplify.text} 4 | \alias{simplify.text} 5 | \title{convert strings to concatenation of lower case alphabet} 6 | \usage{ 7 | simplify.text(string) 8 | } 9 | \arguments{ 10 | \item{string}{character string} 11 | } 12 | \value{ 13 | character string 14 | } 15 | \description{ 16 | all characters are converteusd to lower case, and all non-alphabet characters are removed. This is useful for reducing checks on names of user-specified strings, like \code{method} arguments. For example, \code{"Carrier-Farrag"}, \code{"Carrier Farrag"}, or \code{"carrier_farrag"} all get converted to \code{"carrierfarrag"}. 17 | } 18 | \examples{ 19 | simplify.text(c("carrier_farrag","CarrierFarrag","Carrier-Farrag")) 20 | } 21 | -------------------------------------------------------------------------------- /man/smooth_age_5_arriaga.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_arriaga} 4 | \alias{smooth_age_5_arriaga} 5 | \title{E. Arriaga's method of population count smoothing} 6 | \usage{ 7 | smooth_age_5_arriaga(Value, Age, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of counts in single, abridged, or 5-year age groups.} 11 | 12 | \item{Age}{numeric vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | } 16 | \value{ 17 | numeric vector of smoothed counts in 5-year age groups. 18 | } 19 | \description{ 20 | Smooth population counts in 5-year age groups. 21 | } 22 | \details{ 23 | The open age group is aggregated down to be evenly divisible by 10. 24 | This method accounts for the youngest and oldest age groups. Age classes must be cleanly groupable to 5-year age groups. 10-year age groups are constrained to sum to their original totals. 25 | } 26 | \examples{ 27 | Ages <- seq(0, 80, by = 5) 28 | AMales <- smooth_age_5_arriaga(Value = pop5m_pasex, Age = Ages, OAG = TRUE) 29 | # PAS spreadsheet result: 30 | Atest <- c(662761, 495126, 345744, 287629, 285919, 261018, 237469, 203277, 31 | 161733, 126960, 88586, 67496, 54587, 41257, 28790, 17189, 34729) 32 | all(round(AMales) - Atest == 0, na.rm = TRUE) 33 | \dontrun{ 34 | plot(Ages, pop5m_pasex) 35 | lines(as.integer(names(AMales)),AMales) 36 | } 37 | } 38 | \references{ 39 | \insertRef{arriaga1994population}{DemoTools} 40 | \insertRef{arriaga1968new}{DemoTools} 41 | } 42 | -------------------------------------------------------------------------------- /man/smooth_age_5_cf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_cf} 4 | \alias{smooth_age_5_cf} 5 | \title{The Carrier-Farrag method of population count smoothing} 6 | \usage{ 7 | smooth_age_5_cf(Value, Age, OAG = TRUE, start_on = 0) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of counts in single, abridged, or 5-year age groups.} 11 | 12 | \item{Age}{numeric vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | 16 | \item{start_on}{integer. Either 0 or 5. Do we constrain decades starting on the 0s or 5s?} 17 | } 18 | \value{ 19 | numeric vector of smoothed counts in 5-year age groups. 20 | } 21 | \description{ 22 | Smooth population counts in 5-year age groups. 23 | } 24 | \details{ 25 | This method does not account for ages < 10 nor for the 10 year age interval prior to the open age group. These are returned imputed with \code{NA}. Age classes must be cleanly groupable to 5-year age groups. Smoothed counts are constrained to sum to original totals in 10-year age groups. 26 | } 27 | \examples{ 28 | # from PASEX AGESMTH 29 | Ages <- seq(0, 80, by = 5) 30 | KKNtest <- c(NA,NA,354871,278502,285508,261429,236513 , 31 | 204233,162138,126555,90094,65988,54803,41041,NA,NA,NA) 32 | 33 | CFmales <- smooth_age_5_cf(pop5m_pasex, Ages, TRUE) 34 | CFtest <- c(NA,NA,346290,287083,285855,261082,237937, 35 | 202809,162973,125720,88730,67352,55187,40657,NA,NA,NA) 36 | all(round(CFmales) - CFtest == 0, na.rm = TRUE) 37 | \dontrun{ 38 | plot(Ages, pop5m_pasex) 39 | lines(as.integer(names(CFmales)),CFmales) 40 | } 41 | } 42 | \references{ 43 | \insertRef{carrier1959reduction}{DemoTools} 44 | \insertRef{PAS}{DemoTools} 45 | } 46 | -------------------------------------------------------------------------------- /man/smooth_age_5_feeney.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_feeney} 4 | \alias{smooth_age_5_feeney} 5 | \title{Feeney'S formula on 9 years to correct for heaping on multiples of 5.} 6 | \usage{ 7 | smooth_age_5_feeney(Value, Age, maxit = 200, OAG = FALSE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. A vector of demographic counts in single age groups.} 11 | 12 | \item{Age}{numeric or character. A vector with ages in single years.} 13 | 14 | \item{maxit}{integer. Maximum number of iterations.} 15 | 16 | \item{OAG}{logical. Is the final age group open? Default \code{FALSE}.} 17 | } 18 | \value{ 19 | a vector of adjusted counts in 5-year age groups 20 | } 21 | \description{ 22 | Fenney's technique for correcting age distributions for heaping on multiples of five. 23 | } 24 | \details{ 25 | \code{Value} can be given in single or 5-year age groups. 26 | } 27 | \examples{ 28 | # data from feeney1979, Table 1, page 12: Population of Indonesia, 22 provinces, 29 | # by single year of age: Census of 24 September 1971. 30 | Pop <- c(2337,3873,3882,3952,4056,3685,3687,3683,3611,3175, 31 | 3457,2379,3023,2375,2316,2586,2014,2123,2584,1475, 32 | 3006,1299,1236,1052,992,3550,1334,1314,1337,942, 33 | 3951,1128,1108,727,610,3919,1221,868,979,637, 34 | 3409,887,687,533,313,2488,677,426,524,333, 35 | 2259,551,363,290,226,1153,379,217,223,152, 36 | 1500,319,175,143,89,670,149,96,97,69, 37 | 696,170,60,38,23,745) 38 | Ages <- c(0:75) 39 | result <- smooth_age_5_feeney(Pop, Ages, OAG = TRUE) 40 | A5 <- names2age(result) 41 | V5 <- groupAges(Pop,Ages) 42 | \dontrun{ 43 | plot(Ages, Pop, type= 'l') 44 | segments(A5, 45 | result/5, 46 | A5+5, 47 | result/5, 48 | col = "red") 49 | segments(A5, 50 | V5/5, 51 | A5+5, 52 | V5/5, 53 | col = "blue") 54 | legend("topright",col=c("black","blue","red"), 55 | lty=c(1,1,1), 56 | legend=c("recorded 1","recorded 5","corrected 5")) 57 | } 58 | } 59 | \references{ 60 | \insertRef{feeney1979}{DemoTools} 61 | } 62 | -------------------------------------------------------------------------------- /man/smooth_age_5_kkn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_kkn} 4 | \alias{smooth_age_5_kkn} 5 | \title{Karup-King-Newton method of population count smoothing} 6 | \usage{ 7 | smooth_age_5_kkn(Value, Age, OAG = TRUE, start_on = 0) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of counts in single, abridged, or 5-year age groups.} 11 | 12 | \item{Age}{numeric vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | 16 | \item{start_on}{integer. Either 0 or 5. Do we constrain decades starting on the 0s or 5s?} 17 | } 18 | \value{ 19 | numeric vector of smoothed counts in 5-year age groups. 20 | } 21 | \description{ 22 | Smooth population counts in 5-year age groups. 23 | } 24 | \details{ 25 | This method does not account for ages < 10 nor for the 10 year age interval prior to the open age group. These are returned imputed with \code{NA}. Age classes must be cleanly groupable to 5-year age groups. Smoothed counts are constrained to sum to original totals in 10-year age groups. 26 | } 27 | \examples{ 28 | Ages <- seq(0, 80, by = 5) 29 | KKNtest <- c(NA,NA,354871,278502,285508,261429,236513 , 30 | 204233,162138,126555,90094,65988,54803,41041,NA,NA,NA) 31 | 32 | KKNmales <- smooth_age_5_kkn(pop5m_pasex, Ages, TRUE) 33 | all(round(KKNmales) - KKNtest == 0, na.rm = TRUE) 34 | \dontrun{ 35 | plot(Ages, pop5m_pasex) 36 | lines(as.integer(names(KKNmales)),KKNmales) 37 | } 38 | } 39 | \references{ 40 | \insertRef{carrier1959reduction}{DemoTools} 41 | } 42 | -------------------------------------------------------------------------------- /man/smooth_age_5_mav.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_mav} 4 | \alias{smooth_age_5_mav} 5 | \title{Smooth in 5-year age groups using a moving average} 6 | \usage{ 7 | smooth_age_5_mav(Value, Age, OAG = TRUE, n = 3, tails = FALSE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of (presumably) counts in 5-year age groups.} 11 | 12 | \item{Age}{integer vector of age group lower bounds.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | 16 | \item{n}{integer. The width of the moving average. Default 3 intervals (x-5 to x+9).} 17 | 18 | \item{tails}{logical. If tails is \code{FALSE}, both tails are left untouched. 19 | Otherwise, the tails are filled out using a cascade method.} 20 | } 21 | \value{ 22 | numeric vector of smoothed counts in 5-year age groups. 23 | } 24 | \description{ 25 | Smooth data in 5-year age groups. 26 | } 27 | \details{ 28 | This function calls \code{smooth_age_5_zigzag_inner()}, but prepares data in a way consistent with other methods called by \code{smooth_age_5()}. It is probably preferable to call \code{zigzag()} from the top level, or else call this method from \code{agesmth()} for more control over tail imputations. 29 | 30 | If tails is set to \code{FALSE}, this function calls \code{mav()}, which itself relies on the more general \code{ma()}. We lose the lowest and highest ages with this method, unless \code{n=1}, in which case data is returned in the original 5-year age groups. The total population count is not constrained to sum to the original total. 31 | 32 | If tails is \code{TRUE}, the same results are expected but the tails are 33 | filled in using a cascading method. 34 | } 35 | \examples{ 36 | Age <- c(0,1,seq(5,90,by=5)) 37 | # defaults 38 | ns <- sapply(1:5,smooth_age_5_mav,Value=dth5_zigzag,Age=Age,OAG=TRUE) 39 | cols <- paste0(gray(seq(.8,0,length=5)),"A0") 40 | lwds <- seq(4,1,length=5) 41 | \dontrun{ 42 | plot(Age, dth5_zigzag,pch=16) 43 | matplot(as.integer(rownames(ns)),ns,type='l', 44 | col = cols, 45 | lty = 1, 46 | add = TRUE, 47 | lwd = lwds) 48 | legend("topright", col = cols, lty = 1, lwd = lwds, legend = paste("n =",1:5)) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /man/smooth_age_5_un.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/smooth_age_5.R 3 | \name{smooth_age_5_un} 4 | \alias{smooth_age_5_un} 5 | \title{The old United Nations method of population count smoothing} 6 | \usage{ 7 | smooth_age_5_un(Value, Age, OAG = TRUE) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of counts in single, abridged, or 5-year age groups.} 11 | 12 | \item{Age}{numeric vector of ages corresponding to the lower integer bound of the counts.} 13 | 14 | \item{OAG}{logical. Whether or not the top age group is open. Default \code{TRUE}.} 15 | } 16 | \value{ 17 | numeric vector of smoothed counts in 5-year age groups. 18 | } 19 | \description{ 20 | Smooth population counts in 5-year age groups. 21 | } 22 | \details{ 23 | The open age group is aggregated down to be evenly divisible by 10. This method accounts for the youngest and oldest age groups. Age classes must be cleanly groupable to 5-year age groups. Counts are not constrained in 10-year age groups, except 10-year young and old tails, which are unaffected. 24 | } 25 | \examples{ 26 | Ages <- seq(0, 80, by = 5) 27 | un_test <- c(NA,NA,364491,279123,268724,272228,243638,200923,162752,126304, 28 | 91662,67432,54677,38833,NA,NA,NA) 29 | un_result <- smooth_age_5_un(pop5m_pasex, Ages, TRUE) 30 | all(round(un_result) - un_test == 0, na.rm = TRUE) 31 | \dontrun{ 32 | plot(Ages, pop5m_pasex) 33 | lines(as.integer(names(un_result)),un_result) 34 | } 35 | } 36 | \references{ 37 | \insertRef{carrier1959reduction}{DemoTools} 38 | \insertRef{arriaga1994population}{DemoTools} 39 | } 40 | -------------------------------------------------------------------------------- /man/smooth_age_5_zigzag_min.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ZIGZAG.R 3 | \name{smooth_age_5_zigzag_min} 4 | \alias{smooth_age_5_zigzag_min} 5 | \title{Objective function to minimize Feeney's zigzag method residual} 6 | \usage{ 7 | smooth_age_5_zigzag_min(Value, Age, ageMin = 40, ageMax = 80, p) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric vector of (presumably) counts in 5-year age groups.} 11 | 12 | \item{Age}{integer vector of age group lower bounds.} 13 | 14 | \item{ageMin}{integer. Lower age bound to adjust values.} 15 | 16 | \item{ageMax}{integer. Upper age bound to adjust values.} 17 | 18 | \item{p}{numeric vector of adjustment parameters.} 19 | } 20 | \value{ 21 | positive residual to minimize. 22 | } 23 | \description{ 24 | This function is auxiliary to \code{smooth_age_5_zigzag_inner()}, see \code{?smooth_age_5_zigzag_inner} for a description. 25 | } 26 | \details{ 27 | This function is not intended to be used at the top level, but just in case, make sure that \code{ageMax = ageMin + 10 * length(p)}. Age groups \code{ >= ageMin} AND \code{ <= ageMin} must be in 5-year age groups. This function does no checks. 28 | } 29 | \examples{ 30 | Age <- c(0,1,seq(5,90,by=5)) 31 | smooth_age_5_zigzag_min(dth5_zigzag,Age,ageMin=40,ageMax = 80,p=rep(.05,4)) 32 | # it's used like this in zigzag() 33 | (p <- optim( 34 | rep(.05,4), 35 | smooth_age_5_zigzag_min, 36 | Value = dth5_zigzag, 37 | Age = Age, 38 | ageMin = 40, 39 | ageMax = 80)$par) 40 | Smoothed <- smooth_age_5_zigzag_p(dth5_zigzag,Age,40,80,p) 41 | # de facto unit test: 42 | # check result using results frozen in Feeney spreadsheet 43 | # after fixing probable cell range 'error' 44 | p.feeney <- c(0.0235802695087692,0.0724286618207911, 45 | 0.0242327829742267,0.0883411499065237) 46 | ans <- 106.1147411629 47 | stopifnot(abs(smooth_age_5_zigzag_min(dth5_zigzag, Age, 40,80,p.feeney) - ans) < 1e-6) 48 | } 49 | \references{ 50 | Feeney, G. 2013 "Removing "Zigzag" from Age Data," http://demographer.com/white-papers/2013-removing-zigzag-from-age-data/ 51 | } 52 | -------------------------------------------------------------------------------- /man/smooth_age_5_zigzag_p.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ZIGZAG.R 3 | \name{smooth_age_5_zigzag_p} 4 | \alias{smooth_age_5_zigzag_p} 5 | \title{Smooth population counts using Feeney's zigzag method and smoothing parameters.} 6 | \usage{ 7 | smooth_age_5_zigzag_p( 8 | Value, 9 | Age, 10 | ageMin = 40, 11 | ageMax = 80, 12 | p = rep(0.05, floor((ageMax - ageMin)/10)) 13 | ) 14 | } 15 | \arguments{ 16 | \item{Value}{numeric vector of (presumably) counts in 5-year age groups.} 17 | 18 | \item{Age}{integer vector of age group lower bounds.} 19 | 20 | \item{ageMin}{integer. Lower age bound to adjust values.} 21 | 22 | \item{ageMax}{integer. Upper age bound to adjust values.} 23 | 24 | \item{p}{numeric vector of adjustment parameters.} 25 | } 26 | \value{ 27 | numeric vector of smoothed population counts. 28 | } 29 | \description{ 30 | This function is auxiliary to \code{zigzag()}, see \code{?zigzag} for a description. 31 | } 32 | \details{ 33 | This function is not intended to be used at the top level, but just in case, make sure that \code{ageMax = ageMin + 10 * length(p)}. Age groups \code{ >= ageMin} AND \code{ <= ageMin} must be in 5-year age groups. This function does no checks. 34 | } 35 | \examples{ 36 | Age <- c(0,1,seq(5,90,by=5)) 37 | smooth_age_5_zigzag_min(dth5_zigzag,Age,ageMin=40,ageMax = 80,p=rep(.05,4)) 38 | # it's used like this in smooth_age_5_zigzag_inner() 39 | (p <- optim( 40 | rep(.05,4), 41 | smooth_age_5_zigzag_min, 42 | Value = dth5_zigzag, 43 | Age = Age, 44 | ageMin = 40, 45 | ageMax = 80)$par) 46 | Smoothed <- smooth_age_5_zigzag_p(dth5_zigzag,Age,40,80,p) 47 | } 48 | \references{ 49 | Feeney, G. 2013 "Removing "Zigzag" from Age Data," http://demographer.com/white-papers/2013-removing-zigzag-from-age-data/ 50 | } 51 | -------------------------------------------------------------------------------- /man/spencer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SPENCER.R 3 | \name{spencer} 4 | \alias{spencer} 5 | \title{Smoothing of an age structure by single years using Spencer's formula.} 6 | \usage{ 7 | spencer(Value, Age) 8 | } 9 | \arguments{ 10 | \item{Value}{numeric. A vector of demographic counts in single age groups.} 11 | 12 | \item{Age}{numeric or character. A vector with ages in single years.} 13 | } 14 | \value{ 15 | A named vector with the smoothed age structure. 16 | } 17 | \description{ 18 | Spencer's method is used to adjust distributions by year of age based on cumulative series. 19 | } 20 | \details{ 21 | Single year age groups are assumed. 22 | } 23 | \examples{ 24 | # data from GDA1981IREDA, Table 15 and 16, page 375-376: Ghana (1970 Males + Females), 25 | # population between 10 and 40 years by single age. 26 | Pop <-c(286487,282182,319718,345610,329133,324683,330555,269536,271593,253798, 27 | 242297,165755,233159,185812,175647,187138,160864,128099,178568,123386, 28 | 194999,113372,139088,106190,127482,178375,123286,95637,151514,82614, 29 | 239243,74788,112354,61746,72366,144828,92563,53924,94635,52351,178832) 30 | Age <-c(0:40) 31 | sp_smoothed <- spencer(Value =Pop,Age=Age) 32 | \dontrun{ 33 | plot(Age,Pop, col = "red", xlab = "Age", ylab = "Population",type ='l') 34 | lines(Age,spencer(Pop,Age), col = "blue") 35 | legend("topright", 36 | lty =1, 37 | col = c("red","blue"), 38 | legend = c("Original","Spencer")) 39 | } 40 | # on the fly unit test: 41 | Tab16answer <- c(rep(NA,10),233847,216876,201938,189873,179734,171529,164280,158214, 42 | 152477,147735,143099,139301,135930,133889,132458,132495, 43 | 132660,132894,131463,128560,123150,116725,109180,102386, 44 | 96394,92586,89962,88681,86812,84209,79819) 45 | stopifnot(all(na.omit(abs(sp_smoothed - Tab16answer) < 0.5))) 46 | } 47 | \references{ 48 | \insertRef{GDA1981IREDA}{DemoTools} 49 | Roger et al (1981, pp. 373-377). 50 | } 51 | -------------------------------------------------------------------------------- /man/sr_f_mat_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{sr_f_mat_five} 5 | \alias{sr_f_mat_five} 6 | \title{Survival rates matrix for females five year age groups between 1950 and 2045} 7 | \format{ 8 | A matrix of dimensions 21 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | sr_f_mat_five 15 | } 16 | \description{ 17 | Survival rates matrix for females five year age groups between 1950 and 2045 18 | for unknown country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/sr_f_mat_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{sr_f_mat_single} 5 | \alias{sr_f_mat_single} 6 | \title{Survival rates matrix for females single ages between 1999 and 2019} 7 | \format{ 8 | A matrix of dimensions 101 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | sr_f_mat_single 15 | } 16 | \description{ 17 | Survival rates matrix for females single ages between 1999 and 2019 for 18 | Sweden 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/sr_m_mat_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{sr_m_mat_five} 5 | \alias{sr_m_mat_five} 6 | \title{Survival rates matrix for males five year age groups between 1950 and 2045} 7 | \format{ 8 | A matrix of dimensions 21 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | sr_m_mat_five 15 | } 16 | \description{ 17 | Survival rates matrix for males five year age groups between 1950 and 2045 18 | for unknown country 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/sr_m_mat_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{sr_m_mat_single} 5 | \alias{sr_m_mat_single} 6 | \title{Survival rates matrix for males single ages between 1999 and 2019} 7 | \format{ 8 | A matrix of dimensions 101 x 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | sr_m_mat_single 15 | } 16 | \description{ 17 | Survival rates matrix for males single ages between 1999 and 2019 for 18 | Sweden 19 | } 20 | \keyword{datasets} 21 | -------------------------------------------------------------------------------- /man/srb_vec_five.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{srb_vec_five} 5 | \alias{srb_vec_five} 6 | \title{Sex ratio at birth between 1950 and 2045} 7 | \format{ 8 | A vector of length 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | srb_vec_five 15 | } 16 | \description{ 17 | Sex ratio at birth between 1950 and 2045 for unknown country 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/srb_vec_single.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{srb_vec_single} 5 | \alias{srb_vec_single} 6 | \title{Sex ratio at birth between 1999 and 2019} 7 | \format{ 8 | A vector of length 20 9 | } 10 | \source{ 11 | Migration residual PAS spreadsheet 12 | } 13 | \usage{ 14 | srb_vec_single 15 | } 16 | \description{ 17 | Sex ratio at birth between 1999 and 2019 for Sweden 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/surv10.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CENSUR.R 3 | \name{surv10} 4 | \alias{surv10} 5 | \title{Estimate survival curve from censuses spaced 10 years apart.} 6 | \usage{ 7 | surv10(pop1, pop2) 8 | } 9 | \arguments{ 10 | \item{pop1}{numeric. Vector of population counts in 5-year age groups of census 1.} 11 | 12 | \item{pop2}{numeric. Vector of population counts in 5-year age groups of census 2.} 13 | } 14 | \value{ 15 | Survival function lx as a numeric vector with radix 1. 16 | } 17 | \description{ 18 | This function reproduces calculations through column H of \code{CENSUR~1.XLS} by Griff Feeney. Censuses are assumed to be spaced 10 years apart and population counts for both censuses in 5-year age groups. The staggered ratio of these approximates lifetable function npx =1-nqx, i.e. probability of surviving between age x and age x+n. The cumulative product of this approximates the survival function lx. 19 | } 20 | \details{ 21 | Checking for census spacing of 10 years must happen prior to this function. 22 | Also, we assume the open age group has already been trimmed off. 23 | } 24 | \examples{ 25 | # 1960 vs 1970 pops 26 | pop1 <- c(3831870,4502304,5397061,4630775,4193184,4114704,3770907,3274822, 27 | 2744786,2559755,2160716,1839025,1494043,1133409,870238,577972,313781) 28 | pop2 <- c(4292503,3988292,3852101,4492096,5347327,4571868,4190340,4085338, 29 | 3674127,3198934,2648360,2382691,1970485,1584699,1172155,736258,408191) 30 | surv10(pop1,pop2) 31 | } 32 | -------------------------------------------------------------------------------- /man/surv5.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CENSUR.R 3 | \name{surv5} 4 | \alias{surv5} 5 | \title{Estimate survival curve from censuses spaced 5 years apart.} 6 | \usage{ 7 | surv5(pop1, pop2) 8 | } 9 | \arguments{ 10 | \item{pop1}{numeric. Vector of population counts in 5-year age groups of census 1.} 11 | 12 | \item{pop2}{numeric. Vector of population counts in 5-year age groups of census 2.} 13 | } 14 | \value{ 15 | Survival function lx as a numeric vector with radix 1. 16 | } 17 | \description{ 18 | This function reproduces calculations of \code{CENSUR~3.XLS} by Griff Feeney. Censuses are assumed to be spaced 5 years apart and population counts for both censuses in 5-year age groups. The staggered ratio of these approximates lifetable function npx =1-nqx, i.e. probability of surviving between age x and age x+n. The cumulative product of this approximates the survival function lx. 19 | } 20 | \details{ 21 | Checking for census spacing of 5 years must happen prior to this function. Also, we assume the open age group has already been trimmed off. 22 | } 23 | \examples{ 24 | # 1965 vs 1970 pops 25 | pop1 <- c(3983902,3854281,4513237,5373547,4572392,4206801,4110076,3751030, 26 | 3231736,2697217,2485095,2071540,1719370,1343444,955567,644043,341170) 27 | pop2 <- c(4292503,3988292,3852101,4492096,5347327,4571868,4190340,4085338, 28 | 3674127,3198934,2648360,2382691,1970485,1584699,1172155,736258,408191) 29 | surv5(pop1,pop2) 30 | \dontrun{ 31 | plot(seq(0,80,5),surv5(pop1,pop2), t ='l', col='red', 32 | ylim = c(0,1), 33 | ylab = 'Survival function', xlab = 'Age') 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timriffe/DemoTools/47c25a0dd4ad995d1df1a9e8a1b2e797264330bb/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | shhh <- function(expr){ 2 | capture.output(x <- suppressPackageStartupMessages( 3 | suppressMessages(suppressWarnings(expr)))) 4 | invisible(x) 5 | } 6 | 7 | 8 | shhh(library(testthat)) 9 | shhh(library(DemoTools)) 10 | shhh(library(magrittr)) 11 | shhh(library(dplyr)) 12 | test_check("DemoTools") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-AGEHEAP.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: ilya 3 | ############################################################################### 4 | context("test-ageheap") 5 | 6 | # PASEX spreadsheet SINGAGE 7 | 8 | test_that("check_heaping_whipple replicates SINGAGE males", { 9 | 10 | Age <- 0:99 11 | 12 | # test 13 | expect_equal( 14 | check_heaping_whipple( 15 | Value = pop1m_pasex, 16 | Age = Age, 17 | ageMin = 25, 18 | ageMax = 60, 19 | digit = c(0, 5) 20 | ), 21 | 2.34, 22 | tolerance = .01 23 | ) 24 | 25 | }) 26 | test_that("is_single() applied only to tested age range",{ 27 | 28 | # should induce perfect equality also 29 | df <- data.frame( 30 | age = c(0:90, 100), 31 | count = 10 32 | ) 33 | 34 | expect_equal(check_heaping_whipple(df$count, df$age, ageMin = 25, ageMax = 65),1) 35 | expect_equal(check_heaping_myers(df$count, df$age, ageMin = 25, ageMax = 65),0) 36 | expect_equal(check_heaping_bachi(df$count, df$age, ageMin = 25, ageMax = 65),0) 37 | expect_equal(check_heaping_coale_li(df$count, df$age, ageMin = 60, ageMax = 89),1) 38 | expect_equal(check_heaping_noumbissi(df$count, df$age, ageMin = 25, ageMax = 65),1) 39 | expect_equal(check_heaping_spoorenberg(df$count, df$age, ageMin = 25, ageMax = 65),0) 40 | 41 | # should induce errors 42 | # no longer throw errors because these are lowered where necessary 43 | # expect_error(check_heaping_whipple(df$count, df$age, ageMin = 25, ageMax = 100)) 44 | # expect_error(check_heaping_myers(df$count, df$age, ageMin = 25, ageMax = 100)) 45 | # expect_error(check_heaping_bachi(df$count, df$age, ageMin = 25, ageMax = 100)) 46 | # expect_error(check_heaping_coale_li(df$count, df$age, ageMin = 60, ageMax = 100)) 47 | # expect_error(check_heaping_noumbissi(df$count, df$age, ageMin = 25, ageMax = 100)) 48 | # expect_error(check_heaping_spoorenberg(df$count, df$age, ageMin = 25, ageMax = 100)) 49 | }) -------------------------------------------------------------------------------- /tests/testthat/test-IRDID.R: -------------------------------------------------------------------------------- 1 | 2 | # Author: tim 3 | ############################################################################### 4 | context("test-irdid") 5 | 6 | # Table 7.20 in Siegel and Swanson (2004). Make sure cited in IRDID.R 7 | # under @references tag (using \insertRef{bibtextag}{DemoTools} 8 | 9 | 10 | # create sample data 11 | # (creating in the test env. enables to reuse the objects in every test_that) 12 | pop1 <- c(7.38, 14.16, 14.79, 17.36, 15.11, 10.14, 8.50, 7.28, 5.28) 13 | pop2 <- c(6.48, 12.27, 15.25, 15.10, 14.66, 10.80, 8.95, 9.28, 7.21) 14 | 15 | test_that("ID and IRD reproduce source examples", { 16 | # this is a set of expectations that are checked. The numbers 17 | # 5.5 and 6.7 are pulled from the book example. 18 | expect_equal(ID(pop1, pop2), 5.5, tolerance = 0.01) 19 | expect_equal(IRD(pop1, pop2), 6.7, tolerance = 0.01) 20 | }) 21 | 22 | test_that("ID and IRD scale invariant", { 23 | expect_equal(ID(pop1, pop2), ID(pop1, pop2 * 2)) 24 | expect_equal(IRD(pop1, pop2), IRD(pop1, pop2 * 2)) 25 | }) 26 | 27 | test_that("ID and IRD identical", { 28 | expect_equal(ID(pop1, pop1), 0) 29 | expect_equal(IRD(pop1, pop1), 0) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-spencer.R: -------------------------------------------------------------------------------- 1 | # Author: ilya 2 | ############################################################################### 3 | context("test-spencer") 4 | 5 | 6 | test_that("spencer works", { 7 | # data from GDA1981IREDA, Table 15 and 16, page 375-376: 8 | # Ghana (1970 Males + Females), 9 | # population between 10 and 40 years by single age. 10 | Pop <-c(286487, 282182, 319718, 345610, 329133, 324683, 330555, 269536, 11 | 271593, 253798, 242297, 165755, 233159, 185812, 175647, 187138, 12 | 160864, 128099, 178568, 123386, 194999, 113372, 139088, 106190, 13 | 127482, 178375, 123286, 95637, 151514, 82614, 239243, 74788, 14 | 112354, 61746, 72366, 144828, 92563, 53924, 94635, 52351, 178832) 15 | 16 | Age <-c(0:40) 17 | 18 | sp_smoothed <- spencer(Value = Pop, Age = Age) 19 | 20 | Tab16answer <- c( 21 | rep(NA, 10), 22 | 233847, 216876, 201938, 189873, 179734, 171529, 164280, 158214, 23 | 152477, 147735, 143099, 139301, 135930, 133889, 132458, 132495, 24 | 132660, 132894, 131463, 128560, 123150, 116725, 109180, 102386, 25 | 96394, 92586, 89962, 88681, 86812, 84209, 79819 26 | ) 27 | 28 | expect_equivalent( # unlike equal, equivalent ignores attributes 29 | na.omit(sp_smoothed), 30 | Tab16answer[!is.na(sp_smoothed)], 31 | tolerance = .5 32 | ) 33 | }) 34 | -------------------------------------------------------------------------------- /tests/testthat/test-zigzag.R: -------------------------------------------------------------------------------- 1 | # Author: ilya 2 | ############################################################################### 3 | context("test-zigzag") 4 | 5 | # Feeney, G. 2013 "Removing "Zigzag" from Age Data," http://demographer.com/white-papers/2013-removing-zigzag-from-age-data/ 6 | 7 | test_that("smooth_age_5_zigzag works",{ 8 | 9 | Age <- c(0, 1, seq(5, 90, by = 5)) 10 | 11 | # check result using results frozen in Feeney spreadsheet 12 | # after fixing probable cell range 'error' 13 | p.feeney <- c(0.0235802695087692, 0.0724286618207911, 14 | 0.0242327829742267, 0.0883411499065237) 15 | 16 | ans <- 106.1147411629 17 | 18 | 19 | expect_equal( 20 | smooth_age_5_zigzag_min(dth5_zigzag, Age, 40,80,p.feeney), 21 | ans, 22 | tolerance = 1e-6 23 | ) 24 | }) 25 | 26 | -------------------------------------------------------------------------------- /tests/testthat/test_AGEINT.R: -------------------------------------------------------------------------------- 1 | # test for basic interpolation function `interp` 2 | 3 | context("test-AGEINT") 4 | 5 | test_that("basic interpolation function",{ 6 | 7 | # Toy example: two ages, two dates, expected result by eye 8 | popmatr <- matrix(1:2,2,2,byrow = T) 9 | dates <- dec.date(c(2000.5,2010.5)) 10 | 11 | # interp 12 | expect_true( 13 | all( 1.5 == 14 | interp(popmat = popmatr, 15 | datesIn = dates, 16 | datesOut = dec.date(2005.5)) 17 | ) 18 | ) 19 | # extrap 20 | expect_true( 21 | all( 2.5 == 22 | interp(popmat = popmatr, 23 | datesIn = dates, 24 | datesOut = dec.date(2015.5), extrap = T) 25 | ) 26 | ) 27 | # constant inputs 28 | expect_true( 29 | all( 1 == 30 | interp(popmat = matrix(1,2,2,byrow = T), 31 | datesIn = dates, 32 | datesOut = dec.date(2005.5)), 33 | 1 == 34 | interp(popmat = matrix(1,2,2,byrow = T), 35 | datesIn = dates, 36 | datesOut = dec.date(2015.5), extrap = T) 37 | ) 38 | ) 39 | 40 | # you set an output date beyond observed range, but without extrap=T, receive NA 41 | # this is an interp function by default, so the argument to change the deafult behaviour 42 | # must be explicit 43 | expect_true( 44 | all( 45 | is.na( 46 | interp(popmat = popmatr, 47 | datesIn = dates, 48 | datesOut = dec.date(2015.5)) 49 | ) 50 | ) 51 | ) 52 | 53 | # no negative values 54 | expect_true( 55 | all(interp(popmat = popmatr, 56 | datesIn = dates, 57 | datesOut = dec.date(1900.5), 58 | extrap = T)>=0 59 | ) 60 | ) 61 | expect_output(interp(popmat = popmatr, 62 | datesIn = dates, 63 | datesOut = dec.date(1900.5), 64 | extrap = T), 65 | regexp = "Negative values have been replaced with 0s") 66 | }) 67 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | smoothing_with_demotools.html 2 | Age-heaping_quality_with_Demotools.R 3 | Age-heaping_quality_with_Demotools.html 4 | graduation_with_demotools.R 5 | graduation_with_demotools.html 6 | smoothing_with_demotools.R 7 | *.html 8 | *.R 9 | -------------------------------------------------------------------------------- /vignettes/case_study_1.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "DemoTools: A case study" 3 | author: "Jose Manuel Aburto, Ilya Kashnitsky, Monica Alexander, Jorge Cimentada, Tim Riffe" 4 | date: "`r Sys.Date()`" 5 | output: rmarkdown::html_vignette 6 | bibliography: REFERENCES.bib 7 | vignette: > 8 | %\VignetteIndexEntry{DemoTools: A case study} 9 | %\VignetteEngine{knitr::rmarkdown} 10 | %\VignetteEncoding{UTF-8} 11 | header-includes: 12 | - \usepackage{amsmath} 13 | - \usepackage{amssymb} 14 | --- 15 | 16 | 17 | ```{r setup, include = FALSE} 18 | knitr::opts_chunk$set( 19 | collapse = TRUE, 20 | comment = "#>" 21 | ) 22 | ``` 23 | 24 | ## Intro 25 | Here the idea is use API to read in death count and pop count data, evaluate them, adjust them, get to single ages, and make a single age lifetable. Or Abridged lifetable. Or both and compare. Show different closeout options too. 26 | 27 | ## 28 | 29 | --------------------------------------------------------------------------------