| Title: | Demographic projections of religious groups |
|---|---|
| Description: | Measuringreligiouschange is a package developed by the Center for Advanced Studies of Population and Religion (CASPAR) for a joint project with the Pew Research Center as part of the Pew-Templeton Global Religious Futures project. The software package can generate religious group population projections at the global, regional and national level resulting from initial age-sex composition of populations, demographic processes (fertility, mortality and migration) and religious processes (transmission of religion between generations and religious switching). The package is a flexible tool that can be used to numerically reproduce the projections presented in the Pew Research Center report “The Future of World Religions: Population Growth Projections, 2020-2070”, generate other projection variants based on the included input data, or create projections from user-supplied input data and adjustments to demographic and religious processes. This package may be most useful for users with training in demographic analysis and some experience using and programming in R. For inquiries, please contact: [email protected]. |
| Authors: | Michał Bożek [aut, cre], Krzysztof Kiecoń [aut], Marcin Stonawski [aut] |
| Maintainer: | Michał Bożek <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.2 |
| Built: | 2026-11-18 15:53:23 UTC |
| Source: | https://github.com/CASPAR-PL/measuringreligiouschange |
List of eleven datasets used for projections. The default dataset in the MRC projection framework. Includes data for 201 countries and 7 religious groups over the period 2020–2100.
[data_asfr]. Dataset containing age specific fertility rates
[data_fertility_differentials]. Dataset containing fertility differentials
[data_migration_destination]. Dataset containing migrants destination data
[data_migration_rates]. Dataset containing outmigration rates
[data_births_ratio]. Dataset containing fractions of boys at birth
[data_population]. Dataset containing population size data
[data_structure]. Dataset containing religion structure of populations data
[data_survivability]. Dataset containing survival rates
[data_switching]. Dataset containing religion switching rates
[info_variants]. Dataset containing variants settings
[data_regions]. Dataset containing regional codes and names.
base_data_listbase_data_list
list of data frames
Other base_data:
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
length(base_data_list) # 11 datasetslength(base_data_list) # 11 datasets
Function for creating unresolved projection-objects
base_object_generator( object_name, steps = 10, light_migration = TRUE, light_switching = TRUE, post_switch = FALSE )base_object_generator( object_name, steps = 10, light_migration = TRUE, light_switching = TRUE, post_switch = FALSE )
object_name |
Character; name of the projection scenario — required |
steps |
Numeric; number of 5-year projection periods to simulate (default 10) |
light_migration |
Logical; if TRUE, migration output is stored in abbreviated form to reduce memory usage. Recommended when running multiple projections (default TRUE) |
light_switching |
Logical; if TRUE, switching output is stored in abbreviated form to reduce memory usage. Recommended when running multiple projections (default TRUE) |
post_switch |
Logical; controls how religious switching is tracked across periods. If FALSE (default), individuals who have switched religion remain in the general population and may switch again in subsequent steps. If TRUE, those who have switched are moved into separate post-switch columns and excluded from further switching. Forwarded to both 'create_country_list()' and 'create_projection_object()'. |
A single projection object
test_object_generator for a lightweight 3-country 1-step variant,
project to run the returned object,
save_csv_all and save_plots_all to export results.
vignette("conducting-projections") for the full projection workflow.
Main_1 <- base_object_generator(object_name = "SC1", steps = 10, light_migration = TRUE, light_switching = TRUE )Main_1 <- base_object_generator(object_name = "SC1", steps = 10, light_migration = TRUE, light_switching = TRUE )
Object representing demographic and model-specific information for a single country used in the MRC projection framework.
Each country object contains demographic inputs and parameters that define fertility, mortality, migration, and religious switching dynamics, as well as country-specific settings used for scenario projections.
Country_object stores initial and projected data, specific options and results of the MRC projection for each country.
yearNumeric; current projection year, advances by 5 at each step
periodCharacter; current five-year period label used in previous_* output tables (e.g. "2020-2025")
nameCharacter; name of the country
codeNumeric; ISO 3166-1 country code
regionCharacter; name of the region to which the country belongs
structure_dataList; population structure matrices indexed by year label. Before 'project()' is called, contains only the starting period
mortality_ratesMatrix; age- and sex-specific survival rates for each projection period (rows = sex-age groups, cols = periods)
age_specific_fertility_ratesMatrix; total population ASFRs for each projection period (rows = periods, cols = age groups)
fertility_differentialsList; religion-specific fertility differential matrices indexed by period label (values are ratios relative to total ASFR)
sex_ratioNumeric vector; fraction of boys at birth for each projection period
switching_matrices_listList; decomposed switching probability matrices, one per origin religion
outmigration_ratesList; outmigration rate matrices by period (rows = sex-age groups, cols = religions)
destination_matrixMatrix; share of emigrants directed to each destination country, by sex and religion (rows = sex-religion combos, cols = destination country codes)
start_fertility_groupNumeric; index of the first age group included in fertility calculations (default 3, corresponding to 10-14)
combined_fertility_factorizationLogical; if TRUE (default), a single global factor is applied across all fertile age groups; if FALSE, each age group's fertility births are normalised independently to match the total ASFR for that age group
previous_mortalitydata.table; mortality output. Columns: Country, Country_code, Period, Sex (integer 1/2), Age_group, Structure, Region, then one column per religion
previous_fertilitydata.table; fertility (births) output. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total, then one column per religion
previous_asfrdata.table; age-specific fertility rate output. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total (realised rate: births / exposure), then one column per religion; rows with Mother_age_group == "TFR" contain period totals. Religion columns of individual structures hold the applied rates and are reported even without exposure; Total and the "total" structure hold realised rates and are 0 where exposure is 0 (except *_post_switch columns, which show the mean applied rate)
previous_fertility_exposuredata.table; women-population exposure used in ASFR calculation. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total, then one column per religion
old_fertility_factorsMatrix; scaling factors applied to births to reconcile religion-specific fertility with total ASFR; one row per age group, one column per period
previous_switchingdata.table; switching output. Columns: Country, Country_code, Period, Origin_religion, Region (light mode) or additionally Sex, Age_group, Structure (full mode), then one column per destination religion
previous_immigrationdata.table; immigration output. Columns: Destination, Country_code, Period, Structure, Origin, Region (light mode) or additionally Sex, Age_group (full mode), then one column per religion
previous_emigrationdata.table; emigration output. Columns: Origin, Country_code, Period, Structure, Destination, Region (light mode) or additionally Sex, Age_group (full mode), then one column per religion
migration_listList; internal buffer accumulating immigration flows during a projection step
emigration_listList; internal buffer accumulating emigration flows during a projection step
migrant_sumMatrix; running total of emigrant counts by religion used to balance destination shares within a step
tempList; internal scratch space used during projection calculations; not intended for direct access
projection_ownerCharacter; name of the Projection_object that has claimed this country object. Empty string ('""') if unclaimed. Prevents the same country list from being reused across multiple projections
## Not run: obj <- test_object_generator(object_name = "example") # Access a country object by its c-prefixed ISO key co <- obj$country_object_list[["c840"]] co$name # "USA" co$code # 840 dim(co$structure_data[[1]]) # 40 x 7 ## End(Not run)## Not run: obj <- test_object_generator(object_name = "example") # Access a country object by its c-prefixed ISO key co <- obj$country_object_list[["c840"]] co$name # "USA" co$code # 840 dim(co$structure_data[[1]]) # 40 x 7 ## End(Not run)
Function for creating a country objects list
create_country_list( start_year = 2020, start_fertility_group = 3, switching_pattern = list(c(1/3, 1/3, 1/3), c(1/3, 1/3, 1/3)), data_list = base_data_list, progress_bar = TRUE, post_switch = FALSE, on_country_mismatch = c("error", "rescale", "ignore") )create_country_list( start_year = 2020, start_fertility_group = 3, switching_pattern = list(c(1/3, 1/3, 1/3), c(1/3, 1/3, 1/3)), data_list = base_data_list, progress_bar = TRUE, post_switch = FALSE, on_country_mismatch = c("error", "rescale", "ignore") )
start_year |
Numeric; starting year of the projection (default 2020). |
start_fertility_group |
Numeric; index of the youngest age group for which fertility is applied. Default 3, corresponding to the 10-14 age group. |
switching_pattern |
List of two numeric vectors; specifies for each switching cohort the distribution of religious switching across sub-periods. The first switchable age group is 15-19. Default 'list(c(1/3, 1/3, 1/3), c(1/3, 1/3, 1/3))', distributing switching uniformly across 15-19, 20-24 and 25-29. |
data_list |
List; named list of data frames containing pre-loaded projection input data (default [base_data_list]). |
progress_bar |
Logical; whether to show a progress bar and ETA during loading (default TRUE). |
post_switch |
Logical; controls how religious switching is tracked across periods. If FALSE (default), individuals who have switched religion remain in the general population and may switch again in subsequent steps. If TRUE, those who have switched are moved into separate post-switch columns and excluded from further switching. Forwarded to internal country object creation. |
on_country_mismatch |
Character; how to handle a mismatch between the number of countries in the migration destination matrix and 'info_variants'. One of '"error"', '"rescale"' (renormalise destination rows to sum to 1), or '"ignore"'. In interactive sessions without an explicit value the user is prompted. |
List of country objects, each containing demographic and model-specific data used in the MRC projection framework. Each element of the list represents a single country.
create_projection_object to assemble a projection from this list,
variants_loader to validate the assembled object,
project to run the projection.
vignette("conducting-projections") for a complete worked example.
vignette("inner-workings") for the internal data-loading pipeline.
test_cl <- create_country_list( start_year = 2025, start_fertility_group = 4, switching_pattern = list( c(1 / 3, 1 / 3, 1 / 3), c(1 / 3, 1 / 3, 1 / 3) ), data_list = base_data_list, progress_bar = FALSE, post_switch = FALSE, on_country_mismatch = "error" )test_cl <- create_country_list( start_year = 2025, start_fertility_group = 4, switching_pattern = list( c(1 / 3, 1 / 3, 1 / 3), c(1 / 3, 1 / 3, 1 / 3) ), data_list = base_data_list, progress_bar = FALSE, post_switch = FALSE, on_country_mismatch = "error" )
Function for creating a projection object used in the MRC projection model. Users can specify several parameters controlling the projection setup, inclusion of migration and switching processes, and assumptions regarding fertility differentials.
create_projection_object( name, country_object_list, region_object_list, steps = 10, migration = TRUE, switching = TRUE, switching_type = 1, no_diff = FALSE, post_switch = FALSE, light_migration = TRUE, light_switching = TRUE )create_projection_object( name, country_object_list, region_object_list, steps = 10, migration = TRUE, switching = TRUE, switching_type = 1, no_diff = FALSE, post_switch = FALSE, light_migration = TRUE, light_switching = TRUE )
name |
Character; name of the projection scenario - required. |
country_object_list |
List; country objects created by 'create_country_list()'. If omitted or not a list, 'create_country_list(post_switch = post_switch)' is called automatically. The same list cannot be reused across multiple projections (no default - auto-created if missing). |
region_object_list |
List; region objects created by 'create_region_list()'. If omitted or not a list, 'create_region_list()' is called automatically. Modify only if you are fully familiar with the internal structure of the package (no default - auto-created if missing). |
steps |
Numeric; number of 5-year projection periods to simulate (default 10). |
migration |
Logical; whether migration (emigration and immigration) is included in the projection (default TRUE). |
switching |
Logical; whether religious switching is included in the projection (default TRUE). |
switching_type |
Numeric; sequence of switching relative to demographic processes. Available options: 1 - The population is divided into two groups. For the first group, switching rates are applied at the beginning of the period (before demographic processes); for the second group, switching occurs at the end of the period (after demographic processes). 2 - Switching is applied entirely at the beginning of the period, before demographic processes. (Default = 1). |
no_diff |
Logical; if TRUE, fertility differentials by religion are ignored and all religions use the total ASFR (default FALSE - differentials are applied). |
post_switch |
Logical; controls how religious switching is tracked across periods. If FALSE (default), individuals who have switched religion remain in the general population and may switch again in subsequent steps. If TRUE, those who have switched are moved into separate post-switch columns and excluded from further switching. Also forwarded to 'create_country_list()' when called automatically. |
light_migration |
Logical; if TRUE, migration output is stored in abbreviated form to reduce memory usage. Recommended when running multiple projections (default TRUE). |
light_switching |
Logical; if TRUE, switching output is stored in abbreviated form to reduce memory usage. Recommended when running multiple projections (default TRUE). |
A single projection object
create_country_list to create the required country list,
variants_loader to validate this object before projecting,
project to run the projection,
save_csv_all and save_plots_all to export results.
vignette("conducting-projections") for a full walkthrough.
test_po <- create_projection_object(name = "test", steps = 5)test_po <- create_projection_object(name = "test", steps = 5)
Function for creating a list of Region_objects from a region-mapping data frame.
In most workflows this is called automatically by create_projection_object;
call it directly only when you need to customise the region list before assembling
a projection.
create_region_list(region_data = base_data_list[[11]])create_region_list(region_data = base_data_list[[11]])
region_data |
Data frame; mapping region names to region identifiers.
See |
List of Region_objects, one per row in region_data.
create_projection_object which calls this automatically,
base_data_list for the default region mapping data.
create_region_list(region_data = base_data_list[[11]])create_region_list(region_data = base_data_list[[11]])
Data frame containing age-specific fertility rates (ASFR) for 201 countries, used in the MRC projections. Data cover the period 2020–2100.
Unit is children born per 1000 women per 5 years.
ASFR values are based on data from the United Nations 'World Population Prospects 2024 Revision' (medium variant), recalculated into 5-year periods.
Country_code. Code of country [standard ISO 3166-1] (numeric)
Period. Period for which the data is presented (character)
10-14. ASFR for 10-14 age groups (numeric)
15-19. ASFR for 15-19 age groups (numeric)
20-24. ASFR for 20-24 age groups (numeric)
25-29. ASFR for 25-29 age groups (numeric)
30-34. ASFR for 30-34 age groups (numeric)
35-39. ASFR for 35-39 age groups (numeric)
40-44. ASFR for 40-44 age groups (numeric)
45-49. ASFR for 45-49 age groups (numeric)
50-54. ASFR for 50-54 age groups (numeric)
Data frame with 3216 rows and 11 variables
United Nations, Department of Economic and Social Affairs, Population Division (2024). World Population Prospects 2024, Online Edition (Rev. 1). Available at: https://population.un.org/wpp/
Other base_data:
base_data_list,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_asfr)head(base_data_list$data_asfr)
Data frame containing the fractions of male births for 201 countries, used in the MRC projection models. Data cover the period 2020–2100. Fractions were derived from sex ratio at birth data published in the United Nations 'World Population Prospects 2024 Revision' (medium variant), recalculated into 5-year periods.
Country_code. Code of country [standard ISO 3166-1] (numeric)
2020-2025. fractions of boys at birth for 2020-2025 period (numeric)
2025-2030. fractions of boys at birth for 2025-2030 period (numeric)
2030-2035. fractions of boys at birth for 2030-2035 period (numeric)
2035-2040. fractions of boys at birth for 2035-2040 period (numeric)
2040-2045. fractions of boys at birth for 2040-2045 period (numeric)
2045-2050. fractions of boys at birth for 2045-2050 period (numeric)
2050-2055. fractions of boys at birth for 2050-2055 period (numeric)
2055-2060. fractions of boys at birth for 2055-2060 period (numeric)
2060-2065. fractions of boys at birth for 2060-2065 period (numeric)
2065-2070. fractions of boys at birth for 2065-2070 period (numeric)
2070-2075. fractions of boys at birth for 2070-2075 period (numeric)
2075-2080. fractions of boys at birth for 2075-2080 period (numeric)
2080-2085. fractions of boys at birth for 2080-2085 period (numeric)
2085-2090. fractions of boys at birth for 2085-2090 period (numeric)
2090-2095. fractions of boys at birth for 2090-2095 period (numeric)
2095-2100. fractions of boys at birth for 2095-2100 period (numeric)
Data frame with 201 rows and 17 variables
United Nations, Department of Economic and Social Affairs, Population Division (2024). World Population Prospects 2024, Online Edition (Rev. 1). Available at: https://population.un.org/wpp/
Other base_data:
base_data_list,
data_asfr,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_births_ratio)head(base_data_list$data_births_ratio)
Data frame containing fertility differentials by religion for 201 countries, used in the MRC projection models.
The differentials represent the ratio of the age-specific fertility rate (ASFR) for a particular religion to the ASFR for the total population. Ratios were calculated in the MRC project based on data from censuses, registers, and surveys.
ASFR values for the total population were derived from the United Nations 'World Population Prospects 2024 Revision'.
Country_code. Code of country [standard ISO 3166-1] (numeric)
Age_group. Name of age group (character)
Christians. Fertility differentials for Christians (numeric)
Muslims. Fertility differentials for Muslims (numeric)
Unaffiliated. Fertility differentials for Unaffiliated (numeric)
Buddhists. Fertility differentials for Buddhists (numeric)
Hindus. Fertility differentials for Hindus (numeric)
Jews. Fertility differentials for Jews (numeric)
Other_Religions. Fertility differentials for Other Religionists (numeric)
Data frame with 1809 rows and 9 variables
Pew-CASPAR Measuring Religious Change Project
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_fertility_differentials)head(base_data_list$data_fertility_differentials)
Data frame containing data on emigrant destinations by religion and sex for 201 countries, used in the MRC projection models.
The dataset contains fractions of emigrants moving to each destination country. Fractions were calculated based on two sources: Guy Abel's bilateral international migration flow estimates (Version 8) and the study "The Religious Composition of the World’s Migrants" by Pew Research Center.
Country_code. Code of country of origin [standard ISO 3166-1] (numeric)
Sex. Name of sex [1=males, 2=females] (numeric)
Religion. Name of religion (character)
201 variables with names representing Country_code of migrants’ destination. Fraction of migrants (numeric)
Data frame with 2814 rows and 204 variables
Pew-CASPAR Measuring Religious Change Project; Kramer, S., & Tong, Y. (2024). The religious composition of the world’s migrants. Pew Research Center; Abel, G. J. (2025). Bilateral international migration flow estimates for 200 countries (Version 8). Retrieved from https://guyabel.com/publication/bilateral-migration-flow-sex/
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_migration_destination[, 1:6])head(base_data_list$data_migration_destination[, 1:6])
Data frame containing emigration (out-migration) rates by age, sex, and religion for 201 countries, used in the MRC projection models.
Rates were calculated based on two sources: Guy Abel's bilateral international migration flow estimates (Version 8) and the study "The Religious Composition of the World’s Migrants" by Pew Research Center.
Year. Year of beginning of a period for which the data is presented (numeric)
Sex. Name of sex [1=males, 2=females] (numeric)
Age_group. Names of age groups (character)
Country_code. Code of country of origin [standard ISO 3166-1] (numeric)
Christians. Emigration rates for Christians (numeric)
Muslims. Emigration rates for Muslims (numeric)
Unaffiliated. Emigration rates for Unaffiliated (numeric)
Buddhists. Emigration rates for Buddhists (numeric)
Hindus. Emigration rates for Hindus (numeric)
Jews. Emigration rates for Jews (numeric)
Other_Religions. Emigration rates for Other Religionists (numeric)
Data frame with 8040 rows and 11 variables
Pew-CASPAR Measuring Religious Change Project; Kramer, S., & Tong, Y. (2024). The religious composition of the world’s migrants. Pew Research Center; Abel, G. J. (2025). Bilateral international migration flow estimates for 200 countries (Version 8). Retrieved from https://guyabel.com/publication/bilateral-migration-flow-sex/
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_migration_rates)head(base_data_list$data_migration_rates)
Data frame containing population size by age and sex for 201 countries, used in the MRC projections. The dataset corresponds to the year 2020. Population counts come from estimates published in the United Nations 'World Population Prospects 2024 Revision'
Population is in thousands.
Sex. Name of sex [1=males, 2=females] (numeric)
Country_code. Code of country [standard ISO 3166-1] (numeric)
20 variables representing each five-year age group used in projection from 0-4 to 95+. Population size (numeric)
Data frame with 402 rows and 22 variables
United Nations, Department of Economic and Social Affairs, Population Division (2024). World Population Prospects 2024, Online Edition (Rev. 1). Available at: https://population.un.org/wpp/
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_regions,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_population)head(base_data_list$data_population)
Data frame containing the names and codes of geographic regions used in the MRC projection models. Each row defines one region to which countries can be assigned.
Name. Full name of the region (character)
Region. Short region code used internally as an identifier (character)
Data frame with 6 rows and 2 variables
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_structure,
data_survivability,
data_switching,
info_variants
head(base_data_list[[11]])head(base_data_list[[11]])
Data frame containing the religious composition of specific age and sex groups in the population of 201 countries, used in the MRC projections The dataset corresponds to the year 2020.
The values represent the proportion of a particular religious group within a specific age group (5-year intervals) and sex, relative to the total population of that age group and sex. Shares were calculated in the MRC project based on data from censuses, registers, and surveys.
Country_code. Code of country [standard ISO 3166-1] (numeric)
Age_group. Name of age group (character)
Sex. Name of sex [1=males, 2=females] (numeric)
Christians. Share of Christians in a specific age and sex group (numeric)
Muslims. Share of Muslims in a specific age and sex group (numeric)
Unaffiliated. Share of Unaffiliated in a specific age and sex group (numeric)
Buddhists. Share of Buddhists in a specific age and sex group (numeric)
Hindus. Share of Hindus in a specific age and sex group (numeric)
Jews. Share of Jews in a specific age and sex group (numeric)
Other_Religions. Share of Other Religionists in a specific age and sex group (numeric)
Data frame with 8040 rows and 10 variables
Pew-CASPAR Measuring Religious Change Project
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_survivability,
data_switching,
info_variants
head(base_data_list$data_structure)head(base_data_list$data_structure)
Data frame containing survival rates by age and sex for 201 countries, used in the MRC projection models. Dataset covers the period 2020–2100. Survival rates (Sx) come from the abridged life tables from the United Nations 'World Population Prospects 2024 Revision' (medium variant), recalculated into 5-year periods.
Country_code. Code of country [standard ISO 3166-1] (numeric)
Sex. Name of sex [1=males, 2=females] (numeric)
Age. Number of age_group (from 0 (age 0) to 20 (age 95+)) (numeric)
Age_name. Age representing lower limit of age group (e.g. 10 for age group 10-14) (numeric)
2020-2025. Survival rates for 2020-2025 period (numeric)
2025-2030. Survival rates for 2025-2030 period (numeric)
2030-2035. Survival rates for 2030-2035 period (numeric)
2035-2040. Survival rates for 2035-2040 period (numeric)
2040-2045. Survival rates for 2040-2045 period (numeric)
2045-2050. Survival rates for 2045-2050 period (numeric)
2050-2055. Survival rates for 2050-2055 period (numeric)
2055-2060. Survival rates for 2055-2060 period (numeric)
2060-2065. Survival rates for 2060-2065 period (numeric)
2065-2070. Survival rates for 2065-2070 period (numeric)
2070-2075. Survival rates for 2070-2075 period (numeric)
2075-2080. Survival rates for 2075-2080 period (numeric)
2080-2085. Survival rates for 2080-2085 period (numeric)
2085-2090. Survival rates for 2085-2090 period (numeric)
2090-2095. Survival rates for 2090-2095 period (numeric)
2095-2100. Survival rates for 2095-2100 period (numeric)
Data frame with 8442 rows and 20 variables
United Nations, Department of Economic and Social Affairs, Population Division (2024). World Population Prospects 2024, Online Edition (Rev. 1). Available at: https://population.un.org/wpp/
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_switching,
info_variants
head(base_data_list$data_survivability)head(base_data_list$data_survivability)
Data frame containing the religious composition of cohorts after the “switching period” of a specific religion, for 201 countries, used in the MRC projection models.
The switching period is the age range during which individuals in a cohort may change their religion. It is defined by the user in the MRC projection model. For example, if the switching period is defined as ages 15–30 for religion group A, the dataset shows the religious composition of the same cohort at ages 30–34 that had religion A at ages 10–14.
The compositions were calculated in the MRC project based on survey data containing retrospective questions on religious affiliation.
Country_code. Code of country [standard ISO 3166-1] (numeric)
Religion. Name of religion before switching period (character)
Sex. Name of sex [1=males, 2=females] (numeric)
Christians. Share of Christians after switching period (numeric)
Muslims. Share of Muslims after switching period (numeric)
Unaffiliated. Share of Unaffiliated after switching period (numeric)
Buddhists. Share of Buddhists after switching period (numeric)
Hindus. Share of Hindus after switching period (numeric)
Jews. Share of Jews after switching period (numeric)
Other_Religions. Share of Other Religions after switching period (numeric)
Data frame with 2814 rows and 10 variables
Pew-CASPAR Measuring Religious Change Project
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
info_variants
head(base_data_list$data_switching)head(base_data_list$data_switching)
Data frame containing scenario variant settings that can be applied in the MRC projection models. Users can modify assumptions related to fertility and migration for each country without altering the input data.
Fertility. Users can adjust the level of the total fertility rate (TFR) for each country by specifying a multiplier of the input TFR in the column 'percentage_fertility' (predefined level = 1).
Optional bounds can be set for the modified TFR using: • 'bottom_fertility_cap': minimum allowed TFR (predefined = NA) • 'upper_fertility_cap': maximum allowed TFR (predefined = NA) If the adjusted TFR falls outside these limits, it is replaced with the nearest boundary value.
A constant TFR change across the entire projection period can be applied by setting 'flat_fertility' (predefined = 0). This will not change fertility profile.
Users can also specify convergence of religion-specific TFRs toward the country-level TFR by setting the number of periods to full convergence in 'convergence_steps' (predefined = 16, meaning convergence finishing in 2100).
Migration. Users can modify the level of out-migration rates for each country by specifying a multiplier of the input migration data in the column 'percentage_migration' (predefined level = 1).
Country. Name of country (character)
Country_code. Code of country [standard ISO 3166-1] (numeric)
Region_name. Name of the country region (character)
percentage_fertility. Fraction by which the fertility should be modified (numeric)
flat_fertility. Number by which the fertility should be modified (numeric)
bottom_fertility_cap. Min value of modified fertility (numeric)
upper_fertility_cap. Max value of modified fertility (numeric)
percentage_migration. Fraction by which the migration should be modified (numeric)
convergence_steps. Number of steps after which a full fertility convergence should be done (numeric) Numbers other than natural may lead to unexpected errors.
fertility_factorization. Settings for equalising fertility after calculating fertility differentials. 1 equalise all age groups together, 2 equalise each age group separately. Using setting 1 may result in inconsistent ASFRs if fertility differentials are of different magnitude between age groups. (numeric)
Data frame with 201 rows and 10 variables
Other base_data:
base_data_list,
data_asfr,
data_births_ratio,
data_fertility_differentials,
data_migration_destination,
data_migration_rates,
data_population,
data_regions,
data_structure,
data_survivability,
data_switching
head(base_data_list$info_variants)head(base_data_list$info_variants)
Main method for a projection object. It is used to run the MRC projection - multi-state projection of population by age, sex and religious affiliation. Calling this method executes the MRC projection using parameters stored in the projection_object and input data stored in country_object_list.
The method performs the full projection workflow according to the settings contained in projection_object (e.g. number of steps, inclusion of migration and switching, switching sequence, fertility differentials). Input data for all countries must be supplied via country_object_list prior to running.
project(projection_object, progress_bar = TRUE, save_totals = TRUE)project(projection_object, progress_bar = TRUE, save_totals = TRUE)
projection_object |
Projection_object; an unresolved projection object to run. |
progress_bar |
Logical; whether to show a progress bar and ETA during the projection (default TRUE). |
save_totals |
Logical; whether to compute and store region and global totals after projection (default TRUE). |
Progress bar and time of execution, modifies projection object
create_country_list, create_projection_object,
variants_loader to set up a projection before calling this function.
save_csv_all and save_plots_all to export results afterwards.
vignette("conducting-projections") for a full walkthrough.
vignette("inner-workings") for the internal projection algorithm.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: p_object <- create_projection_object(name = "test") p_object$project() p_object <- create_projection_object(name = "test") project(projection_object = p_object) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: p_object <- create_projection_object(name = "test") p_object$project() p_object <- create_projection_object(name = "test") project(projection_object = p_object) ## End(Not run)
Object containing technical information as well as demographic and model-specific information for all countries included in projection.
A single object contains all the necessary information and functions needed for calculating the projection allowing user to easily perform calculations and visualize the results
Projection_object stores initial and projected data, specific options and results of the MRC projection for each country
projection_nameCharacter; name of the projection scenario, used as the default output folder name
region_object_listList; Region_objects, one per region defined in 'data_regions'
country_object_listList; Country_objects, one per country, created by 'create_country_list()'
stepsNumeric; number of 5-year projection periods to simulate
migrationLogical; whether migration (emigration and immigration) is included in the projection
switchingLogical; whether religious switching is included in the projection
switching_typeNumeric; sequence of switching relative to demographic processes. 1 = split (pre/post demographic); 2 = all switching before demographic processes
no_diffLogical; if TRUE, fertility differentials by religion are ignored and all religions use the total ASFR
post_switchLogical; if FALSE (default), individuals who have switched religion remain in the general population and may switch again in subsequent steps; if TRUE, those who have switched are moved into separate post-switch columns and excluded from further switching
resolvedLogical; TRUE once 'project()' has been called successfully; prevents re-projection of the same object
region_totalsLogical; whether region-level aggregated totals are computed and stored after projection
global_totalsLogical; whether global totals are computed and stored after projection
light_migrationLogical; if TRUE, migration output is stored in abbreviated form to reduce memory usage
light_switchingLogical; if TRUE, switching output is stored in abbreviated form to reduce memory usage
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") obj$projection_name # "example" obj$steps # 1 obj$resolved # FALSE (before project()) project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) obj$resolved # TRUE length(obj$country_object_list) # 3 ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") obj$projection_name # "example" obj$steps # 1 obj$resolved # FALSE (before project()) project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) obj$resolved # TRUE length(obj$country_object_list) # 3 ## End(Not run)
Object representing demographic and model-specific information for a single region.
Each region object contains information fields as well as calculated results of countries projections aggregated to respective regions allowing user to easily perform calculations and visualize the results on projection results for regions.
Region_object stores results of projection aggregated to regions.
nameCharacter; name of the region e.g. "North America"
regionCharacter; region code identifying which countries belong to this region e.g. "NOAM"
structure_dataList; aggregated population structure matrices indexed by year label, summed across all countries in the region
previous_mortalitydata.table; aggregated mortality output for the region. Columns: Country, Country_code, Period, Sex (integer 1/2), Age_group, Structure, Region, then one column per religion
previous_fertilitydata.table; aggregated fertility (births) output for the region. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total, then one column per religion
previous_asfrdata.table; aggregated age-specific fertility rate output for the region. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total, then one column per religion; rows with Mother_age_group == "TFR" contain period totals
previous_fertility_exposuredata.table; aggregated women-population exposure for the region. Columns: Country, Country_code, Period, Mother_age_group, Structure, Region, Total, then one column per religion
previous_switchingdata.table; aggregated switching output for the region. Columns: Country, Country_code, Period, Origin_religion, Structure, Region (light mode) or additionally Sex, Age_group (full mode), then one column per destination religion
previous_immigrationdata.table; aggregated immigration output for the region. Columns: Destination, Country_code, Period, Structure, Origin, Region (light mode) or additionally Sex, Age_group (full mode), then one column per religion
previous_emigrationdata.table; aggregated emigration output for the region. Columns: Origin, Country_code, Period, Structure, Destination, Region (light mode) or additionally Sex, Age_group (full mode), then one column per religion
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = TRUE) # Access a region object by name reg <- obj$region_object_list[["NOAM"]] reg$name # "NOAM" length(reg$structure_data) # one entry per projection period ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = TRUE) # Access a region object by name reg <- obj$region_object_list[["NOAM"]] reg$name # "NOAM" length(reg$structure_data) # one entry per projection period ## End(Not run)
Method for exporting all projection results to a set of .csv files. Each type of output data (e.g., population, fertility, mortality, migration, switching) is written to a separate file.
The export process can take up to an hour to complete, depending on dataset size—particularly for projections that include religious switching and migration, which generate large output files.
If switching or migration is disabled in the projection settings, the corresponding .csv files are skipped automatically.
save_csv_all( projection_object, objects = list("countries", "regions"), filenames_vector = c("projection_structure_data.csv", "projection_births_data.csv", "projection_asfr_data.csv", "projection_fertility_exposure_data.csv", "projection_fertility_differentials.csv", "projection_deaths_data.csv", "projection_emigration_data.csv", "projection_immigration_data.csv", "projection_switching_matrices.csv", "projection_switchers_data.csv"), folder, demographic_files = TRUE, switching_files, migration_files, order_by_name = FALSE, progress_bar = TRUE )save_csv_all( projection_object, objects = list("countries", "regions"), filenames_vector = c("projection_structure_data.csv", "projection_births_data.csv", "projection_asfr_data.csv", "projection_fertility_exposure_data.csv", "projection_fertility_differentials.csv", "projection_deaths_data.csv", "projection_emigration_data.csv", "projection_immigration_data.csv", "projection_switching_matrices.csv", "projection_switchers_data.csv"), folder, demographic_files = TRUE, switching_files, migration_files, order_by_name = FALSE, progress_bar = TRUE )
projection_object |
Projection_object; a resolved (already projected) projection object. |
objects |
Character vector specifying which objects to export: '"countries"', '"regions"', or both. Default exports both where applicable — regions omit switching matrices and fertility differentials (character). |
filenames_vector |
Character vector of length 10 containing output file names, in order: structure data, births, ASFRs, fertility exposure, fertility differentials, deaths, emigration, immigration, switching matrices, switchers (character vector). |
folder |
Name of folder in which results should be saved. Defaults to projection_object's name (character). |
demographic_files |
Logical; if TRUE, saves structure data, fertility data, mortality data, ASFRs and women population data used in fertility calculations (default TRUE). |
switching_files |
Logical; if TRUE, saves switching matrices and switching data. Defaults to the projection's switching setting. Will error if TRUE when no switching was calculated. |
migration_files |
Logical; if TRUE, saves migration data. Defaults to the projection's migration setting (logical). |
order_by_name |
Logical; if TRUE, countries are ordered alphabetically by name. If FALSE, countries are ordered by ISO 3166-1 code (default FALSE). |
progress_bar |
Logical; whether to show a progress bar and ETA (default TRUE). |
Progress bar and time of execution.
project to run the projection before exporting.
save_plots_all to export visualisations instead of raw data.
vignette("exporting-results") for a column-by-column description of
every output file including example rows.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: p_object <- create_projection_object(name = "test") p_object$project() p_object$save_csv_all() p_object <- create_projection_object(name = "test") project(projection_object = p_object) save_csv_all(projection_object = p_object) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: p_object <- create_projection_object(name = "test") p_object$project() p_object$save_csv_all() p_object <- create_projection_object(name = "test") project(projection_object = p_object) save_csv_all(projection_object = p_object) ## End(Not run)
Method for generating and saving plots of MRC projection results for all countries. Outputs can be saved either as: (a) a single combined PDF file containing all countries, or (b) separate PDF files for each country.
save_plots_all( projection_object, single_file = FALSE, order_by_name = FALSE, show_post_switch = TRUE, folder, demographic_plots = TRUE, switching_plots, migration_plots, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40"), plot_switching_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )save_plots_all( projection_object, single_file = FALSE, order_by_name = FALSE, show_post_switch = TRUE, folder, demographic_plots = TRUE, switching_plots, migration_plots, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40"), plot_switching_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )
projection_object |
Projection_object; a resolved projection object containing completed results to visualize. |
single_file |
Logical; if TRUE, saves all country plots into a single .pdf file (default FALSE). |
order_by_name |
Logical; if TRUE, countries are ordered alphabetically by name; if FALSE, ordered by ISO 3166-1 code (default FALSE). |
show_post_switch |
Logical; if FALSE, combines post-switch and non-switch populations into a single category in the plots (default TRUE). |
folder |
Character; name of the folder in which results should be saved. Defaults to projection_object's name. |
demographic_plots |
Logical; if FALSE, skips creation of fertility and mortality plots (default TRUE). |
switching_plots |
Logical; if FALSE, skips creation of switching plots. Defaults to the projection's switching status. |
migration_plots |
Logical; if FALSE, skips creation of migration plots. Defaults to the projection's migration status. |
plot_colors |
Character vector; colors used for each religion in the plots (default: 7-color palette). |
plot_switching_colors |
Character vector; colors used for post-switch religious groups in the plots (default: 14-color palette). |
progress_bar |
Logical; whether to show a progress bar and ETA (default TRUE). |
Called for its side effects. Saves country plots as PDF file(s) to 'folder' and prints a completion message.
save_plots_regions_all for region-level plots,
save_plots_comparative_all to compare two scenarios side by side.
vignette("visualising-projections") for a complete guide to all plot
variants and the demographic_plots, migration_plots, and
switching_plots flags.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) save_plots_all(projection_object = obj, folder = tempdir(), progress_bar = FALSE) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) save_plots_all(projection_object = obj, folder = tempdir(), progress_bar = FALSE) ## End(Not run)
Function for generating and saving side-by-side comparative plots of MRC projection results for all countries across two or more scenarios. Outputs can be saved either as a single combined PDF file or as separate PDF files per country.
save_plots_comparative_all( projection_objects, single_file = TRUE, folder = "comparative", demographic_plots = TRUE, switching_plots, migration_plots, show_post_switch = TRUE, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )save_plots_comparative_all( projection_objects, single_file = TRUE, folder = "comparative", demographic_plots = TRUE, switching_plots, migration_plots, show_post_switch = TRUE, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )
projection_objects |
List; resolved projection objects to compare against each other |
single_file |
Logical; if TRUE, saves all country plots into a single .pdf file (default TRUE) |
folder |
Character; name of folder in which plots should be saved (default "comparative") |
demographic_plots |
Logical; if FALSE, skips creation of fertility and mortality plots (default TRUE) |
switching_plots |
Logical; if FALSE, skips creation of switching plots. Defaults to the first projection object's switching status |
migration_plots |
Logical; if FALSE, skips creation of migration plots. Defaults to the first projection object's migration status |
show_post_switch |
Logical; if TRUE, post-switch populations are visualized separately. Forced to FALSE if any projection has post_switch disabled. The per-religion population plots always show the full religion (base plus post-switch) (default TRUE) |
plot_colors |
Character vector; colors used for each religion in the plots (recommended to leave unchanged unless the number of religions has changed) |
progress_bar |
Logical; whether to show a progress bar during saving (default TRUE) |
Called for its side effects. Saves comparative country plots as PDF file(s) to 'folder' and prints a completion message.
save_plots_all for single-scenario country plots.
save_plots_comparative_regions_all for the region-level equivalent.
vignette("visualising-projections") for a guide to all comparative
plot types and how the content flags map to type numbers.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: projection_dsm <- create_projection_object(name = "dsm", switching = TRUE) projection_dm <- create_projection_object(name = "dm", switching = FALSE) project(projection_object = projection_dsm) project(projection_object = projection_dm) save_plots_comparative_all( projection_objects = list(projection_dsm, projection_dm), folder = tempdir(), progress_bar = FALSE ) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: projection_dsm <- create_projection_object(name = "dsm", switching = TRUE) projection_dm <- create_projection_object(name = "dm", switching = FALSE) project(projection_object = projection_dsm) project(projection_object = projection_dm) save_plots_comparative_all( projection_objects = list(projection_dsm, projection_dm), folder = tempdir(), progress_bar = FALSE ) ## End(Not run)
Function for generating and saving side-by-side comparative plots of MRC projection results for all regions across two or more scenarios. Outputs can be saved either as a single combined PDF file or as separate PDF files per region.
save_plots_comparative_regions_all( projection_objects, single_file = TRUE, folder = "comparative", demographic_plots = TRUE, switching_plots, migration_plots, show_post_switch = TRUE, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )save_plots_comparative_regions_all( projection_objects, single_file = TRUE, folder = "comparative", demographic_plots = TRUE, switching_plots, migration_plots, show_post_switch = TRUE, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )
projection_objects |
List of resolved projection objects (list) |
single_file |
Logical; if TRUE, saves all region plots into a single .pdf file (default TRUE) |
folder |
Name of folder in which plots should be saved (character) |
demographic_plots |
Logical; if FALSE, skips creation of fertility and mortality plots (default TRUE) |
switching_plots |
Logical; if FALSE, skips creation of switching plots. Defaults to projection_object's switching status (logical) |
migration_plots |
Logical; if FALSE, skips creation of migration plots. Defaults to projection_object's migration status (logical) |
show_post_switch |
Logical; if TRUE, post-switch populations are visualized separately. Forced to FALSE if any projection has post_switch disabled. The per-religion population plots always show the full religion (base plus post-switch) (default TRUE) |
plot_colors |
Character vector defining the colors used for each religion in the plots (recommended to leave unchanged unless the number of religions has changed) |
progress_bar |
Logical; whether to show a progress bar during saving (default TRUE) |
Called for its side effects. Saves comparative region plots as PDF file(s) to 'folder' and prints a completion message.
save_plots_regions_all for single-scenario region plots.
save_plots_comparative_all for the country-level equivalent.
vignette("visualising-projections") for a guide to all comparative
plot types and how the content flags map to type numbers.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj1 <- test_object_generator(object_name = "sc1") obj2 <- test_object_generator(object_name = "sc2", no_diff = TRUE) project(projection_object = obj1, progress_bar = FALSE, save_totals = TRUE) project(projection_object = obj2, progress_bar = FALSE, save_totals = TRUE) save_plots_comparative_regions_all( projection_objects = list(obj1, obj2), folder = tempdir(), progress_bar = FALSE ) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj1 <- test_object_generator(object_name = "sc1") obj2 <- test_object_generator(object_name = "sc2", no_diff = TRUE) project(projection_object = obj1, progress_bar = FALSE, save_totals = TRUE) project(projection_object = obj2, progress_bar = FALSE, save_totals = TRUE) save_plots_comparative_regions_all( projection_objects = list(obj1, obj2), folder = tempdir(), progress_bar = FALSE ) ## End(Not run)
Method for generating and saving plots of MRC projection results for all regions. Outputs can be saved either as: (a) a single combined PDF file containing all regions, or (b) separate PDF files for each region.
save_plots_regions_all( projection_object, single_file = FALSE, order_by_name = FALSE, show_post_switch = TRUE, folder, demographic_plots = TRUE, switching_plots, migration_plots, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40"), plot_switching_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )save_plots_regions_all( projection_object, single_file = FALSE, order_by_name = FALSE, show_post_switch = TRUE, folder, demographic_plots = TRUE, switching_plots, migration_plots, plot_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40"), plot_switching_colors = c("blue3", "green4", "red3", "yellow3", "orange3", "purple3", "grey40", "darkblue", "darkgreen", "red4", "yellow4", "orange4", "purple4", "grey30"), progress_bar = TRUE )
projection_object |
Projection_object; a resolved projection object containing completed results to visualize. |
single_file |
Logical; if TRUE, saves all region plots into a single .pdf file (default FALSE). |
order_by_name |
Logical; if TRUE, regions are ordered alphabetically by name; if FALSE, by code (default FALSE). |
show_post_switch |
Logical; if FALSE, combines post-switch and non-switch populations into a single category in the plots (default TRUE). |
folder |
Character; name of the folder in which results should be saved. Defaults to projection_object's name. |
demographic_plots |
Logical; if FALSE, skips creation of fertility and mortality plots (default TRUE). |
switching_plots |
Logical; if FALSE, skips creation of switching plots. Defaults to the projection's switching status. |
migration_plots |
Logical; if FALSE, skips creation of migration plots. Defaults to the projection's migration status. |
plot_colors |
Character vector; colors used for each religion in the plots (default: 7-color palette). |
plot_switching_colors |
Character vector; colors used for post-switch religious groups in the plots (default: 14-color palette). |
progress_bar |
Logical; whether to show a progress bar and ETA (default TRUE). |
Called for its side effects. Saves region plots as PDF file(s) to 'folder' and prints a completion message.
save_plots_all for country-level plots,
save_plots_comparative_all to compare scenarios.
vignette("visualising-projections") for a complete guide including
which variants each flag controls.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = TRUE) save_plots_regions_all(projection_object = obj, folder = tempdir(), progress_bar = FALSE) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "example") project(projection_object = obj, progress_bar = FALSE, save_totals = TRUE) save_plots_regions_all(projection_object = obj, folder = tempdir(), progress_bar = FALSE) ## End(Not run)
Function for creating unresolved projection-objects limited to Poland (616), United Kingdom (826) and United States (840) with a single projection step
test_object_generator( object_name, post_switch = FALSE, migration = TRUE, switching = TRUE, switching_type = 1L, light_migration = TRUE, light_switching = TRUE, no_diff = FALSE, progress_bar = FALSE )test_object_generator( object_name, post_switch = FALSE, migration = TRUE, switching = TRUE, switching_type = 1L, light_migration = TRUE, light_switching = TRUE, no_diff = FALSE, progress_bar = FALSE )
object_name |
Character; name of the projection scenario — required |
post_switch |
Logical; controls how religious switching is tracked across periods. If FALSE (default), individuals who have switched religion remain in the general population and may switch again in subsequent steps. If TRUE, those who have switched are moved into separate post-switch columns and excluded from further switching. Forwarded to both 'create_country_list()' and 'create_projection_object()'. |
migration |
Logical; if TRUE, migration (emigration and immigration) is included in the projection (default TRUE) |
switching |
Logical; if TRUE, religious switching is included in the projection (default TRUE) |
switching_type |
Numeric; switching sequence type passed to 'create_projection_object()' (default 1) |
light_migration |
Logical; if TRUE, migration output is stored in abbreviated form to reduce memory usage (default TRUE) |
light_switching |
Logical; if TRUE, switching output is stored in abbreviated form to reduce memory usage (default TRUE) |
no_diff |
Logical; if TRUE, fertility differentials are ignored and all religions use the total ASFR (default FALSE) |
progress_bar |
Logical; if TRUE, shows a progress bar during country loading (default FALSE) |
A single projection object
base_object_generator for a full 201-country projection,
project to run the returned object,
save_csv_all and save_plots_all to export results.
vignette("conducting-projections") for the full projection workflow.
# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "my_test") project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) ## End(Not run)# Running a full projection is time-consuming. # Wrapped in dontrun to avoid executing during documentation build. ## Not run: obj <- test_object_generator(object_name = "my_test") project(projection_object = obj, progress_bar = FALSE, save_totals = FALSE) ## End(Not run)
Applies per-country variant settings (e.g. fertility convergence, migration
adjustments) from info_variants to the country objects stored
inside a projection object. Must be called after
create_projection_object and before project.
Calling it a second time on the same object is blocked unless force = TRUE.
variants_loader( projection_object, country_info = base_data_list[[10]], force = FALSE )variants_loader( projection_object, country_info = base_data_list[[10]], force = FALSE )
projection_object |
Projection_object; an unresolved projection object whose country objects will be modified by variant settings |
country_info |
Data frame; variant settings for each country, typically 'base_data_list$info_variants' (default 'base_data_list[[10]]') |
force |
Logical, if TRUE loads a variant even if a variant has been already loaded. (default FALSE) |
The input projection_object with modified country_object_list.
info_variants for a description of the variant settings table,
create_projection_object to create the object passed here,
project to run the projection after loading a variant.
vignette("conducting-projections") for a full walkthrough.
p_object <- create_projection_object(name = "test") p_object <- variants_loader(projection_object = p_object)p_object <- create_projection_object(name = "test") p_object <- variants_loader(projection_object = p_object)