Skip to main content

Analysing costs

From costs per person to an excess cost with a confidence interval: skewed costs with zeros, censoring, price year and discounting

Register-based cost analysis in R: the estimand, excess cost against a comparison group, two-part and GLM models for skewed costs with zeros, censored costs, bootstrap, price indices and discounting.
Last modified

December 4, 2026

Use this page when your outcome is a cost: healthcare costs, lost earnings or both, summed per person over follow-up. It covers the analysis side: what to estimate, how to describe costs, which models fit them, how to handle censoring and uncertainty, and how to bring costs to one price year.

You start from an analysis dataset with one row per person: the summed cost in DKK (Danish kroner) over follow-up, follow-up time, exposure and covariates. Healthcare costs shows how to build the cost column from the registers. Each year’s costs are brought to one price year and discounted before they are summed per person (Prices, Discounting), so read those two sections before you build it. The other columns come from Assemble and prepare the dataset. You end with mean costs per group and an excess cost with a confidence interval.

Looking for where costs per person come from in the registers? That is on Healthcare costs.

WarningStructural guidance, not verified code

The code on this page shows the shape of each step. It has not been run on register data. Check the column names against your own dataset, and the choices against your analysis plan.

Variable names in the examples are generic. Replace them with your own. The models use glm() from base R and dplyr for data handling.

Start from the estimand

Decide what number you want before you choose a model.

  • Mean cost per person over a fixed horizon, for example the five years after the index date. A person who dies contributes the costs up to death and nothing after.
  • Mean cost per person-year: the summed costs divided by the summed person-years at risk, in the same way as a rate (see Rates and rate ratios (Poisson)).
  • Total cost or excess cost. The total cost is what the exposed group costs. The excess cost (also called attributable or incremental cost) is the difference between the mean cost of the exposed and the mean cost of comparable unexposed people. Excess cost needs a comparison group.

The comparison group is built in the same way as for any other outcome:

Report the mean, not only the median. In a skewed distribution the median is lower than the mean, and it cannot be multiplied up to a total. Barber and Thompson write that analysis of costs “needs to focus on arithmetic mean costs, since these will reflect the total cost of treating all patients with the disease” (Barber & Thompson 2000). Mihaylova et al. make the same point for policy makers (Mihaylova et al. 2011). Medians and quartiles are still useful to describe the distribution.

Prices: bring all costs to one price year

A cost from 2012 is in 2012 prices, and a cost from 2024 in 2024 prices. Before you sum or compare across years, convert every cost to one price year with a price index. For DRG prices, year t below is the tariff year, not the year of the activity: a 2019 contact priced in the 2021 tariff file is already in 2021 prices (Healthcare costs). Converting it from 2019 would add two years of price growth that is not there.

cost in price year B = cost in year t × index(B) / index(t)

Two Danish indices:

  • The consumer price index from DST (Statistics Denmark). Annual averages are in StatBank table PRIS8 (from 1900), and the monthly index in PRIS01. Older papers cite table PRIS111, which DST no longer updates: its last month is December 2025.
  • The Danish Regions’ price and wage development for health care, the row “Sundheds-PL ekskl. medicintilskud (sygesikring)” in the Regions’ yearly note on price and wage regulation. It is published as a yearly percentage change. Each year’s note gives the final figure for the year before and estimates for the current year and the next (Pris- og lønreguleringen 2025-27, June 2026). To use it as an index, chain the yearly changes.

DRG (Diagnosis Related Groups) tariffs are computed each year (see Healthcare costs), so hospital costs priced with tariffs from several years need the same conversion.

Discounting

Discounting converts costs that fall in later years to their value in a start year. It is a separate step from the price index: first bring costs to one price year, then discount.

The Danish Ministry of Finance recommends a real discount rate of 3.5% a year for years 0-35, 2.5% for years 36-70 and 1.5% after year 70 (Vejledning i samfundsøkonomiske konsekvensvurderinger, June 2023, section 4.7, table 4.1). The rate in force is kept in the Ministry’s key figures catalogue, which in June 2026 gives the same rates (Nøgletalskatalog, June 2026). Until January 2021 the rates were 4%, 3% and 2% (Vejledning 2023, preface). The guidance says the rate will be adjusted in the catalogue when the Ministry’s assumptions about the real interest rate change for good.

In the Ministry’s worked example the value in year 0 is not discounted. For horizons under 35 years each later year is divided by 1.035 once more:

library(dplyr) # mutate

# costs_by_year: one row per person and year of follow-up
# year_since_start: 0 for the first year of follow-up, 1 for the next, ...
costs_by_year <- costs_by_year %>%
  mutate(cost_discounted = cost_real / 1.035^year_since_start) # cost_real: cost in one price year
# then sum cost_discounted per person to get the cost over the horizon

Describe the costs first

Look at the distribution before you fit anything. Cost data are non-negative, usually strongly skewed to the right, often have many zeros (people with no contact in the period) and can have heavy tails (Mihaylova et al. 2011).

Per group, report the number of people, person-years, the share with zero cost, the mean with its standard deviation, the median and quartiles, and the total by cost domain (hospital, primary care, medication).

library(dplyr) # group_by, summarise

# df: one row per person, with cost (DKK over the horizon), followup_years,
# exposure (0/1) and covariates. Read it once; the later code uses it too
df <- readRDS("path/to/cost_analysis.rds")

df %>%
  group_by(exposure) %>%
  summarise(
    n = n(),
    person_years = sum(followup_years),
    share_zero = mean(cost == 0),     # share of people with no cost at all
    mean_cost = mean(cost),
    sd_cost = sd(cost),
    median_cost = median(cost),
    q1 = quantile(cost, 0.25),
    q3 = quantile(cost, 0.75),
    total_cost = sum(cost)
  )

The very large values are part of the mean you want to estimate, so removing or capping them changes what the mean describes. A maximum is one person’s value, and a median or percentile in a small group can be too, so check them against the export rules before they leave DST (see Output control and export).

Choosing a model

For the crude comparison in a large cohort you need no model. Mihaylova et al. recommend simple methods “in large samples where the near-normality of sample means is assured” (Mihaylova et al. 2011), such as a difference in means with a normal-based confidence interval, and Barber and Thompson recommend the bootstrap as a check (Barber & Thompson 2000).

When you adjust or standardise and many people have no cost, the two-part model below is the default: it handles both the zeros and the skew. It is not the only valid choice. In a large cohort, linear regression on the raw costs also estimates the mean, and Mihaylova et al. note that it is unclear what share of zeros makes a two-part model worth it (Mihaylova et al. 2011). The two fold-outs after it explain how to choose the GLM (generalised linear model) family for its second part, and why taking the log of the costs is not the way round the skewness.

Two-part model for costs with many zeros

When many people have no cost, a two-part model fits the zeros and the positive costs separately (Belotti et al. 2015):

  1. A logistic regression for the probability of any cost.
  2. A GLM with a log link for the cost among those with any cost. The sketch uses the gamma family, where the standard deviation grows in proportion to the mean. Manning and Mullahy write that in their experience “many health care expenditure and use data” have this property (Manning & Mullahy 2001). To check it in your own data, see Choosing the family.

The mean cost is the product of the two parts: E(cost | x) = Pr(cost > 0 | x) × E(cost | cost > 0, x) (Belotti et al. 2015). In the review by Mihaylova et al., two-part models “seem to outperform other methods when excess zeros are present” (Mihaylova et al. 2011).

The sketch fits both parts and standardises: it predicts each person’s mean cost as exposed and as unexposed, and the excess cost is the difference of the two averages. exposure is 0/1 here. If it is a factor, set the levels in mutate() instead.

library(dplyr) # filter, mutate

# df from "Describe the costs first" above: one row per person

excess_cost <- function(d) {
  part1 <- glm(I(cost > 0) ~ exposure + age + sex,     # part 1: Pr(any cost)
               data = d, family = binomial)
  part2 <- glm(cost ~ exposure + age + sex,             # part 2: mean cost among those with any cost
               data = filter(d, cost > 0), family = Gamma(link = "log"))

  mean_cost_if <- function(e) {
    d_e <- mutate(d, exposure = e)                      # everyone exposed (1) or everyone unexposed (0)
    predict(part1, d_e, type = "response") *            # Pr(cost > 0) ...
      predict(part2, d_e, type = "response")            # ... times E(cost | cost > 0)
  }

  mean(mean_cost_if(1)) - mean(mean_cost_if(0))         # excess mean cost per person, DKK
}

excess_cost(df)

The standardised means are averages over everyone in df, so the excess cost is for the whole cohort. To get it for the exposed only, average over the exposed rows. The function returns a single number, so the confidence interval comes from the bootstrap below.

The sketch assumes that everyone is followed to the end of the horizon or to death. If some people emigrate or your data end before the horizon, their summed cost is too low and the excess cost is biased. Use the methods under Censored costs, or choose a horizon that everyone can be followed for. Liu et al. 2019 show how to split an effect on the mean cost into its effect on the probability of any cost and on the cost among users.

A generalised linear model with a log link models the mean cost on the DKK scale directly: the predicted mean is exp(xβ), with no smearing factor. exp() of a coefficient is a ratio of mean costs among people with any cost, because part 2 only models them. A difference in DKK comes from standardisation, as in the two-part model above.

The variance function (the GLM family) says how the variance grows with the mean. The estimate of the mean is usually robust to a wrong variance function, but the precision is not (Mihaylova et al. 2011). Manning and Mullahy write the variance as a power of the mean, var(y | x) proportional to E(y | x)^λ, and propose a Park-type test to estimate λ: regress the log of the squared raw-scale residual on the log of the predicted mean, and read off the slope (Manning & Mullahy 2001, who call it a modified Park test).

Slope λ near Variance family = in glm()
0 constant gaussian(link = "log")
1 proportional to the mean quasipoisson(link = "log")
2 mean squared Gamma(link = "log")
3 mean cubed inverse.gaussian(link = "log")
library(dplyr) # filter

pos <- filter(df, cost > 0)                          # people with any cost
fit <- glm(cost ~ exposure + age + sex, data = pos,
           family = Gamma(link = "log"))             # a first GLM with log link

res <- residuals(fit, type = "response")             # raw-scale residual: cost minus predicted mean
park <- lm(log(res^2) ~ log(fitted(fit)))            # log squared residual on log predicted mean
coef(park)[2]                                        # the slope: an estimate of lambda

Manning and Mullahy start from the residuals of a first GLM. If the residuals on the log scale are heavy-tailed (a coefficient of kurtosis above 3), they suggest linear regression on log cost instead. If not, the Park test picks the family. In their simulations the test was less informative when the data were heavy-tailed. When the family is picked this way, they recommend robust or bootstrapped standard errors, because the estimated variance function may still be wrong (Manning & Mullahy 2001).

Taking the log of the cost and fitting lm() gives coefficients on the log scale, and exp() of a predicted log cost is not the mean cost. Getting back to DKK needs a retransformation. Duan’s smearing factor does this when the log-scale error has constant variance. When the variance differs with the covariates, as it often does, the simple retransformation is biased, and a correct one is cumbersome (Manning & Mullahy 2001; Manning et al. 2005). The log is also undefined at zero, and adding a constant to the zeros is not recommended (Mihaylova et al. 2011).

Censored costs

For mean cost per person over a fixed horizon, death ends the costs: it is not censoring. Emigration and the end of your data are censoring, because the costs after that date are unknown. The dates of death and emigration are under Outcomes.

A plain average of the observed costs is then biased. The usual remedy is to weight: each person followed to the horizon or to death counts with the inverse of the probability of staying uncensored that long (Bang & Tsiatis 2000). It is the same idea as IPCW (inverse probability of censoring weighting) in IP weighting, with a weight that depends on each person’s follow-up time.

The weighting assumes that censoring happens completely at random. Bang and Tsiatis call this “a reasonable assumption at least in relation to administrative censoring” (Bang & Tsiatis 2000), which in register data is the end of your data. Emigration need not be at random, so compare how many emigrate in each group.

The average of the observed costs, over everyone or over the uncensored cases only, “can be severely biased, and the standard survival analysis techniques are not applicable” (Lin et al. 1997). Kaplan-Meier with cost in place of time fails because the cost accumulated up to censoring is not independent of the cost up to death (Wijeysundera et al. 2012). Two estimators were developed for this:

  • Lin et al. 1997 split follow-up into intervals, take the mean cost in each interval among those alive at its start, and weight it by the Kaplan-Meier probability of being alive at the start. The estimator is consistent if censoring happens at the interval boundaries, and the authors find the bias small when it does not (Lin et al. 1997).
  • Bang & Tsiatis 2000 weight each person with complete follow-up by the inverse of the probability of remaining uncensored, which allows censoring at any time (Bang & Tsiatis 2000). The partitioned version also uses the costs a censored person had in the periods before censoring. It needs cost per period, which register data give (Wijeysundera et al. 2012).

Wijeysundera et al. give a worked example for readers without an advanced statistical background, cite simulations in which the simple weighted estimator became unstable with more than 50% censoring, and describe phase-based costing as an alternative when censoring is heavy (Wijeysundera et al. 2012).

With mean cost per person-year, a person who emigrates contributes the costs and the person-years observed before the date, as with a rate.

Uncertainty: bootstrap

The non-parametric bootstrap gives a confidence interval for a difference in mean costs without assuming normality (Barber & Thompson 2000). For a model-based estimate such as the two-part model above, repeat the whole procedure in each bootstrap sample: both models and the standardisation, and the weights too if you weighted.

Resample the unit that the rows depend on:

  • The person, when a person has several rows (one per year, or matched more than once). This is the same reason as for clustered standard errors.
  • The matched set, in a matched cohort. For propensity-score matched pairs, resampling the pairs gave standard errors closer to the true sampling variation than redoing the matching in each bootstrap sample, in simulations (Austin & Small 2014).
library(dplyr) # inner_join

set.seed(2026)
ids <- unique(df$pnr)                                    # matched sets: use match_id here and in by = below

boot <- replicate(1000, {
  draw <- data.frame(pnr = sample(ids, replace = TRUE))  # draw persons, not rows
  d_b <- inner_join(draw, df, by = "pnr",
                    relationship = "many-to-many")       # all rows of each drawn person, once per draw
  excess_cost(d_b)                                       # the function from the two-part model above
})

quantile(boot, c(0.025, 0.975))                          # percentile 95% interval

Each replicate refits both models on the whole cohort, so time a few replicates before you start a thousand. The percentile interval is the simplest. Barber and Thompson preferred the bootstrap-t and the bias-corrected and accelerated (BCa) intervals (Barber & Thompson 2000).

Productivity costs

A societal cost study can add lost production to healthcare costs. Two methods value it differently. The human capital method “counts any hour not worked as an hour lost”. The friction cost method “only counts as lost those hours not worked until another employee takes over the patient’s work”, and the two can give widely different results (van den Hout 2010; the friction cost method is from Koopmanschap et al. 1995).

Registers at DST that carry the inputs:

  • IND (Indkomst), yearly from 1980, holds personal income. LOENMV_13 is wage income (“Lønindkomst i alt”), valid from 1987, and includes pay during sickness and parental leave. ERHVERVSINDK_13 is wage income plus fees (HONNY) plus net income from self-employment (DST, IND variable list; DST, LOENMV_13; DST, ERHVERVSINDK_13).
  • AKM (the labour classification module) gives the main labour-market status per year (see Employment - AKM).
  • DREAM, a database of public benefit spells, gives the type of benefit week by week for each person who received one, such as sickness benefit or unemployment benefit (DREAM vejledning, version 51).

FAIK (family income), used in this guide for SEPLINE’s (the national guideline on socioeconomic position in register research) income measure, is household-equivalised disposable income (FAIK), not a person’s earnings.

None of these registers records time spent caring for a relative. Informal care needs survey data, and its value depends heavily on the valuation method (for dementia in Denmark, see Jakobsen et al. 2011).

What to report

Each choice on this page changes the number, so a reader needs all of them to interpret the estimate and compare it with other studies:

  • The estimand: per person or per person-year, horizon, total or excess, and the comparison group.
  • The cost domains included and the source of each unit cost (see Healthcare costs).
  • How zeros, very large values, death and censoring were handled.
  • The model: family and link, how you chose them, and the result with another family.
  • The uncertainty method and the unit you resampled.
  • The price year and the price index, and the discount rate with year 0.
  • Mean costs per group in DKK, the excess cost with its confidence interval, and the share with zero cost.

For a guide to how cost-of-illness studies are read and judged, see Larg & Moss 2011.

TipRead more
Back to top