Skip to contents

Installation

Install mongolstats and the released mongolmaps from CRAN:

install.packages(c("mongolstats", "mongolmaps"))

Your First Analysis: Infant Mortality

This walk-through uses the infant mortality rate (IMR), a key indicator of population health and health system performance. It covers the full workflow: find a table, check its structure, fetch data, calculate rates, and map them.

Step 1: Load Packages

library(mongolstats)
library(mongolmaps)
library(dplyr)
library(ggplot2)

# Set language to English for readable output
# Checked teaching helpers are shipped with the package and can be inspected.
source(system.file("examples", "analysis-helpers.R", package = "mongolstats"), local = TRUE)
source(system.file("examples", "plot-style.R", package = "mongolstats"), local = TRUE)

Step 2: Find the Right Table

Search the catalogue by keyword:

mortality_tables <- nso_search("infant mortality")
mortality_tables |>
  distinct(tbl_id, tbl_eng_nm)
#> # A tibble: 8 × 2
#>   tbl_id            tbl_eng_nm                                                  
#>   <chr>             <chr>                                                       
#> 1 DT_NSO_2100_014V1 NUMBER OF INFANT MORTALITY, aimags and the Capital and by m…
#> 2 DT_NSO_2100_014V2 NUMBER OF INFANT MORTALITY, by soum and discrict, and by ye…
#> 3 DT_NSO_2100_014V4 INFANT MORTALITY, by sex, by soum, and by year              
#> 4 DT_NSO_2100_014V5 INFANT MORTALITY RATE, per 1000 live births, by sex, by sou…
#> 5 DT_NSO_2100_015V1 INFANT MORTALITY RATE, per 1000 live births, aimags and the…
#> 6 DT_NSO_2100_015V2 INFANT MORTALITY, per 1000 live births, by soum, and by year
#> 7 DT_NSO_2100_015V2 INFANT MORTALITY, per 1000 live births, by year             
#> 8 DT_NSO_2800_019V1 INFANT MORTALITY RATE PER 1000 LIVE BIRTHS

NSO publishes both rates (per 1,000 live births) and the counts behind them (infant deaths). We start with the monthly rate table, DT_NSO_2100_015V1, and later use the counts to compare aimags.

Step 3: Explore Table Metadata

Before fetching data, check which dimensions the table has:

# View table structure
meta <- nso_table_meta("DT_NSO_2100_015V1")
meta
#> # A tibble: 2 × 5
#>   dim    code  is_time n_values codes             
#>   <chr>  <chr> <lgl>      <int> <list>            
#> 1 Region Бүс   FALSE         28 <tibble [28 × 3]> 
#> 2 Month  Сар   TRUE         128 <tibble [128 × 3]>

# Periods oldest first, with their dates. Month labels are "YYYY-MM"; the
# codes count back from the latest month ("0"), so select periods by label.
months <- nso_table_periods("DT_NSO_2100_015V1")
head(months)
#> # A tibble: 6 × 4
#>   code  label   date       frequency
#>   <chr> <chr>   <date>     <chr>    
#> 1 13    2016-01 2016-01-01 month    
#> 2 14    2016-02 2016-02-01 month    
#> 3 15    2016-03 2016-03-01 month    
#> 4 16    2016-04 2016-04-01 month    
#> 5 17    2016-05 2016-05-01 month    
#> 6 18    2016-06 2016-06-01 month
range(months$label)
#> [1] "2016-01" "2026-08"

Step 4: Fetch Data

Get the national rate for every month NSO publishes:

imr_national <- nso_data(
  tbl_id = "DT_NSO_2100_015V1",
  selections = list(
    Region = "0", # national total
    Month = months$label
  ),
  labels = "en" # add English label columns
)

# The Month column holds labels such as "2024-03", which keep their meaning
# when NSO publishes a new month
imr_national |>
  arrange(Month) |>
  head(10)
#> # A tibble: 10 × 5
#>    Region Month   value Region_en Month_en
#>    <chr>  <chr>   <dbl> <chr>     <chr>   
#>  1 0      2016-01    12 Total     2016-01 
#>  2 0      2016-02    13 Total     2016-02 
#>  3 0      2016-03    14 Total     2016-03 
#>  4 0      2016-04    15 Total     2016-04 
#>  5 0      2016-05    15 Total     2016-05 
#>  6 0      2016-06    14 Total     2016-06 
#>  7 0      2016-07    14 Total     2016-07 
#>  8 0      2016-08    15 Total     2016-08 
#>  9 0      2016-09    12 Total     2016-09 
#> 10 0      2016-10    12 Total     2016-10

NSO rounds these monthly rates to whole numbers, which is coarse for a measure that sits around 10 to 20 per 1,000.

Step 5: Visualize the Trend

imr_national |>
  mutate(date = nso_period_date(Month)) |> # "YYYY-MM" to Date
  ggplot(aes(x = date, y = value)) +
  geom_line(color = "#183442", linewidth = 1, alpha = 0.3) + # dim raw data so trend stands out
  geom_point(color = "#C2623D", size = 2, shape = 21, fill = "white", stroke = 1, alpha = 0.6) +
  # Descriptive smooth only: no model-based uncertainty ribbon
  geom_smooth(
    method = "loess", formula = y ~ x, se = FALSE,
    color = "#167D8D", fill = "#167D8D", alpha = 0.2, linewidth = 1.5
  ) +
  scale_x_date(date_breaks = "1 year", date_labels = "%Y") +
  scale_y_continuous(limits = c(0, NA)) +
  labs(
    title = "Infant Mortality Rate in Mongolia (Monthly)",
    subtitle = "Deaths under age 1 per 1,000 live births, national",
    x = NULL,
    y = "IMR (per 1,000)",
    caption = "Source: NSO Mongolia, DT_NSO_2100_015V1"
  ) +
  theme(
    panel.grid.minor = element_blank(),
    panel.grid.major.x = element_blank() # vertical gridlines clutter time series
  )

Line plot of Mongolia's monthly infant mortality rate since 2016, with a LOESS smoother showing the overall direction

The smooth is an exploratory summary of rounded monthly rates. It does not account for different numbers of births or dependence between neighbouring months.

Regional Comparison

To compare aimags over a year, do not average the 12 monthly rates. A mean of monthly rates gives a month with few births the same weight as a busy month, and NSO’s rounding makes small aimags’ monthly rates jump between values. Instead, add up the infant deaths and the live births for the year, then divide:

IMR=infant deaths in the yearlive births in the year×1,000\text{IMR} = \frac{\text{infant deaths in the year}}{\text{live births in the year}} \times 1{,}000

This conventional same-period vital-statistics IMR is not a linked birth-cohort probability: infant deaths can include children born in the preceding year. The counts come from two monthly tables: infant deaths (DT_NSO_2100_014V1) and live births (DT_NSO_2100_018V5).

# Expected independent units: national total, 21 aimags and capital code 5.
aimag_codes <- setdiff(mn_aimags()$nso_code, "511")
units <- c("0", aimag_codes, "5")
death_source <- analysis_fetch_counts("DT_NSO_2100_014V1", units)
birth_source <- analysis_fetch_counts("DT_NSO_2100_018V5", units)

# A year must have every calendar month in both tables for all expected units.
# Unresolved observations are retained as missing, never assumed to be zero.
latest_year <- analysis_latest(analysis_common_years(death_source$annual, birth_source$annual))
infant_deaths <- filter(death_source$annual, year == latest_year)
live_births <- filter(birth_source$annual, year == latest_year)
imr_regional <- analysis_pair(
  select(infant_deaths, Region, Region_en, deaths = count, missing_deaths = n_missing),
  select(live_births, Region, births = count, missing_births = n_missing),
  by = "Region"
) |>
  mutate(
    Region_en = trimws(Region_en),
    level = case_when(Region == "0" ~ "National", Region == "5" ~ "Capital", .default = "Aimag")
  )
imr_regional <- bind_cols(imr_regional, analysis_poisson(imr_regional$deaths, imr_regional$births)) |>
  rename(imr = rate)

national_imr <- imr_regional$imr[imr_regional$Region == "0"]
stopifnot(length(national_imr) == 1L, is.finite(national_imr))
imr_units <- filter(imr_regional, Region != "0")
stopifnot(nrow(imr_units) == 22L)
imr_units |>
  transmute(
    area = Region_en, deaths, births, imr,
    interval = if_else(is.finite(imr), sprintf("%.1f to %.1f", lower, upper), "Insufficient data")
  ) |>
  knitr::kable(
    col.names = c("Area", "Infant deaths", "Live births", "IMR per 1,000", "95% CI"),
    digits = c(0, 0, 0, 1, 0), format.args = list(big.mark = ",")
  )
Area Infant deaths Live births IMR per 1,000 95% CI
Dornod 8 1,251 6.4 2.8 to 12.6
Sukhbaatar 8 814 9.8 4.2 to 19.4
Khentii 10 980 10.2 4.9 to 18.8
Tuv 12 666 18.0 9.3 to 31.5
Govisumber 3 287 10.5 2.2 to 30.5
Selenge 11 991 11.1 5.5 to 19.9
Dornogovi 13 862 15.1 8.0 to 25.8
Darkhan-Uul 18 1,800 10.0 5.9 to 15.8
Umnugovi 15 1,113 13.5 7.5 to 22.2
Dundgovi 4 514 7.8 2.1 to 19.9
Orkhon 15 1,936 7.7 4.3 to 12.8
Uvurkhangai 28 1,609 17.4 11.6 to 25.2
Bulgan 7 460 15.2 6.1 to 31.4
Bayankhongor 8 1,268 6.3 2.7 to 12.4
Arkhangai 16 999 16.0 9.2 to 26.0
Khuvsgul 32 1,764 18.1 12.4 to 25.6
Zavkhan 9 830 10.8 5.0 to 20.6
Govi-Altai 11 813 13.5 6.8 to 24.2
Bayan-Ulgii 41 2,449 16.7 12.0 to 22.7
Khovd 18 1,694 10.6 6.3 to 16.8
Uvs 28 1,366 20.5 13.6 to 29.6
Ulaanbaatar 423 29,671 14.3 12.9 to 15.7

In 2025, the national recorded IMR was 13.6 per 1,000 live births. 0 areas have insufficient observations for an annual estimate. The source objects retain raw observations, symbols and provenance for inspection.

Visualize Regional Differences

imr_units |>
  filter(is.finite(imr)) |>
  mutate(Region_en = forcats::fct_reorder(Region_en, imr)) |> # order by rate, not alphabet
  ggplot(aes(x = imr, y = Region_en)) +
  geom_vline(xintercept = national_imr, linetype = "dashed", color = "grey50") +
  geom_errorbar(aes(xmin = lower, xmax = upper), width = 0.3, color = "grey60", orientation = "y") +
  geom_point(aes(color = level), size = 2.5) +
  scale_color_manual(values = c(Aimag = "#167D8D", Capital = "#C2623D"), name = NULL) +
  labs(
    title = paste0("Infant Mortality by Aimag, ", latest_year),
    subtitle = "Per 1,000 live births, with exact 95% CIs; dashed line = national rate",
    x = "Deaths per 1,000 live births",
    y = NULL,
    caption = "Source: NSO Mongolia, DT_NSO_2100_014V1 and DT_NSO_2100_018V5"
  ) +
  theme(
    panel.grid.major.y = element_blank(),
    panel.grid.minor = element_blank(),
    legend.position = "top"
  )

Dot plot of infant mortality rates by aimag and Ulaanbaatar over the selected common calendar period, with 95% confidence intervals and a dashed line at the national rate

The intervals describe Poisson count variation conditional on the recorded counts and birth denominator. They do not include under-registration, revisions or geographic mismatch. Crossing the estimated national line is a descriptive comparison, not an independent two-sample test: the national total includes each aimag. If births or deaths are assigned by place of occurrence rather than residence, referral patterns can distort area comparisons; confirm the definitions of these specific source tables before interpreting differences.

Adding Geographic Context

mongolmaps provides boundaries that carry NSO codes, so the Region column joins without matching names.

# mn_join() takes Ulaanbaatar's figures from region code "5" when the
# capital's own code "511" is empty, as it is in this table
imr_map <- imr_units |>
  mn_join(by = "Region", level = "aimag")
stopifnot(nrow(imr_map) == 22L, !anyDuplicated(imr_map$nso_code))

mn_map(
  imr_map,
  fill = imr,
  title = paste0("Infant Mortality Rate, ", latest_year)
) +
  labs(subtitle = "Infant deaths per 1,000 live births. Data: NSO Mongolia", fill = "IMR\n(per 1,000)") +
  guides(fill = guide_colourbar(barwidth = grid::unit(85, "mm"), barheight = grid::unit(3, "mm"))) +
  analysis_map_theme()

Choropleth map of infant mortality rates across Mongolia's aimags and Ulaanbaatar over the selected common calendar period

Grey areas have insufficient data. The map shows point estimates only. Read it with the confidence intervals above: in small aimags, a few more or fewer infant deaths can move the colour a long way.

Key Functions Summary

Function Purpose Example
nso_search() Find tables by keyword nso_search("mortality")
nso_table_meta() Get table dimensions nso_table_meta("DT_NSO_...")
nso_dim_values() List dimension values nso_dim_values(tbl, "Region")
nso_table_periods() Check time coverage nso_table_periods(tbl)
nso_latest_periods() Latest periods, for selections list(Year = nso_latest_periods(tbl, n = 5))
nso_data() Fetch data nso_data(tbl, selections, labels)
nso_period_date() Period labels to dates nso_period_date(data$Month)
mongolmaps::mn_join() Join NSO data to boundaries by code mn_join(data, by = "Region", level = "aimag")
mongolmaps::mn_map() Quick map of joined data mn_map(joined, fill = value)

Best Practices

  1. Use codes in scripts, labels for display: Selections accept codes or labels, but codes such as region codes are more stable. labels = "en" adds readable label columns alongside the codes. Periods are the exception: NSO numbers them from the latest ("0"), so mongolstats always returns them as labels, and you should select them by label or with nso_latest_periods().
  2. Check metadata first: Use nso_table_meta() and nso_dim_values() to see dimensions and codes before fetching.
  3. Separate the levels: Region columns mix the national total ("0"), regions ("1"–"4"), the capital ("5"), and aimags. Filter to one level before summing or ranking, or you will count deaths twice.
  4. Build rates from counts: Add up numerators and denominators over the period, then divide. Do not average monthly rates.
  5. Show uncertainty: Small populations give unstable rates. Report confidence intervals, or pool several years.
  6. Join by code: Use mongolmaps::mn_join() on the Region code column rather than matching names.

Common Workflows

Time Series Analysis

  1. Search for table → Check periods → Fetch months or years → Plot trend

Regional Comparison

  1. Fetch numerator and denominator counts → Sum over the period → Calculate rates and confidence intervals → Compare with the national rate

Spatial Epidemiology

  1. Calculate rates by aimag → mn_join() by Region code → mn_map()

Next Steps

Quick Reference: Common Health Tables

Indicator Table ID Measure Detail
Infant mortality rate DT_NSO_2100_015V1 Rate per 1,000 live births Aimag, month
Infant deaths DT_NSO_2100_014V1 Count Aimag, month
Live births DT_NSO_2100_018V5 Count Aimag, month
Under-5 mortality rate DT_NSO_2100_030V2 Rate per 1,000 live births Aimag, month
Maternal deaths DT_NSO_2100_002V2 Count Aimag, month
Deaths by leading cause DT_NSO_2100_027V1 Count Soum, year
Cancer incidence DT_NSO_2100_012V1 Rate per 10,000 population Cancer type, year
Communicable disease cases (incl. tuberculosis) DT_NSO_2100_035V1 Count Disease, month
Communicable disease cases DT_NSO_2100_020V2 Count Disease, soum, year
Mid-year population DT_NSO_0300_002V1 Count Aimag, year