Skip to main content

Gamma Regression: What Makes a Hospital Stay Expensive?

Gamma regression with a log link in R, on the cost of 4,100 hospital stays for heart failure in one county of New York State (SPARCS 2021): positive, skewed outcomes with a constant coefficient of variation, cost ratios, the deviance and the dispersion, gamma against least squares on dollars and on logs with smearing, the modified Park test for the variance, robust standard errors, residuals, predicted costs and APA reporting.

The question: the same illness, very different bills

Heart failure is one of the most common reasons for a hospital stay. Some stays cost 5,000 dollars, some 100,000. What makes them expensive: how ill the patient is, the age, or the hospital?

Costs are always positive and skewed: most are moderate and a few are enormous. And they have a third property, which is the key to this page: the higher the average, the larger the spread. Severe cases cost more on average, and their costs also vary more. Ordinary regression assumes the same spread everywhere, and adds dollars where the effects are really percentages.

Gamma regression is a generalized linear model (McCullagh & Nelder, 1989) made for such outcomes. The mean is modeled on a log scale, so effects are ratios (“1.4 times as expensive”), and the standard deviation grows in proportion to the mean.

Code
library(ggplot2)
library(sandwich)   # vcovHC(): robust standard errors
library(lmtest)     # coeftest(), coefci()

# number formats for the text
f0   <- function(x) formatC(x, format = "f", digits = 0, big.mark = ",")
f1   <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2   <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3   <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
num  <- function(x) trimws(format(x, big.mark = ","))
pct  <- function(x, d = 0) paste0(formatC(100 * x, format = "f", digits = d), "%")

1. The data

New York State publishes every hospital stay, without names, in the SPARCS data. They are free, and the portal answers queries, so we ask only for what we need: the stays for heart failure (diagnosis group 194) in the hospitals of Suffolk County in 2021.

Code
query <- paste0(
  "https://health.data.ny.gov/resource/tg3i-cinn.csv?",
  "$select=facility_name,age_group,gender,length_of_stay,apr_severity_of_illness,total_costs",
  "&$where=apr_drg_code='194' and hospital_county='Suffolk'",
  "&$order=facility_name,total_costs&$limit=10000"
)
raw <- read.csv(URLencode(query))
stays <- subset(raw, total_costs > 0 & age_group %in% c("30 to 49", "50 to 69", "70 or Older") &
                     apr_severity_of_illness %in% c("Minor", "Moderate", "Major", "Extreme"))
stays <- with(stays, data.frame(
  cost     = total_costs,
  severity = factor(apr_severity_of_illness, levels = c("Minor", "Moderate", "Major", "Extreme")),
  age      = factor(age_group, levels = c("30 to 49", "50 to 69", "70 or Older")),
  male     = as.integer(gender == "M"),
  days     = suppressWarnings(as.numeric(length_of_stay)),
  hospital = facility_name))
small <- names(which(table(stays$hospital) < 100)) # hospitals with few stays go together
stays$hospital <- factor(ifelse(stays$hospital %in% small, "Other", stays$hospital))
stays$hospital <- relevel(stays$hospital, ref = names(which.max(table(stays$hospital))))
nrow(stays)
[1] 4134
Code
summary(stays$cost)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   1254    7662   11907   16336   19089  489976 

There are 4,134 stays in 11 hospitals (those with fewer than 100 stays are put together). cost is the hospital’s estimate of what the stay cost, not the price on the bill. severity is how ill the patient was for a patient with this diagnosis, in four classes assigned by a standard algorithm from the diagnoses.


2. Look at the data

Code
pa <- ggplot(stays, aes(pmin(cost, 80000) / 1000)) +
  geom_histogram(binwidth = 2, boundary = 0, fill = "#2a78d6", colour = "white", linewidth = 0.1) +
  labs(title = "Cost of a stay (80 = 80 or more)", x = "thousand dollars", y = "stays") + theme_bw()
spread <- do.call(
  rbind,
  lapply(split(stays$cost, stays$severity), function(v) {
    data.frame(n = length(v), mean = mean(v), sd = sd(v), cv = sd(v) / mean(v))
  })
)
cell <- aggregate(cost ~ severity + hospital, data = stays, FUN = function(v) {
  c(mean = mean(v), sd = sd(v), n = length(v))
})
cell <- data.frame(
  severity = cell$severity,
  mean = cell$cost[, "mean"],
  sd = cell$cost[, "sd"],
  n = cell$cost[, "n"]
)
cell <- subset(cell, n >= 20)
pb <- ggplot(cell, aes(mean / 1000, sd / 1000, colour = severity)) +
  geom_abline(slope = mean(spread$cv), linetype = "dashed", colour = "grey50") +
  geom_point(aes(size = n)) +
  scale_size_area(max_size = 5, guide = "none") +
  scale_colour_viridis_d(end = 0.9, name = NULL) +
  labs(
    title = "Mean and standard deviation in each hospital and severity class",
    x = "mean (thousand dollars)",
    y = "SD (thousand dollars)"
  ) +
  theme_bw() +
  theme(legend.position = "bottom")
patchwork::wrap_plots(pa, pb, ncol = 1, heights = c(1, 1.3))

Plot: 2. Look at the data

Code
round(spread, 2)
            n     mean       sd   cv
Minor     259  7702.23  4399.91 0.57
Moderate 1306 11323.59  7573.72 0.67
Major    1841 16632.37 13294.14 0.80
Extreme   728 27651.23 29775.09 1.08

The SD grows with the mean, about in proportion. The ratio of the two, the coefficient of variation (CV), is 0.57 for minor and 1.08 for extreme cases. The mean goes from 7,702 to 27,651 dollars.


3. The model step by step, with formulas

Step 1: the gamma distribution

A gamma variable is positive and skewed to the right. We write it with its mean \(\mu\) and a shape \(\nu\):

\[E(y) = \mu, \qquad \text{Var}(y) = \frac{\mu^2}{\nu} = \phi\,\mu^2, \qquad \phi = \frac{1}{\nu}\]

The variance is proportional to the square of the mean, so the SD is proportional to the mean, and the CV is \(\sqrt\phi\) for everybody. With \(\nu = 1\) it is the exponential distribution, and with a large \(\nu\) it looks like a normal one.

Code
grid <- seq(0.1, 60, by = 0.1)
shapes <- do.call(
  rbind,
  lapply(c(1, 2, 5, 20), function(nu) {
    data.frame(
      y = grid,
      d = dgamma(grid, shape = nu, scale = 20 / nu),
      shape = paste0("ν = ", nu, ", CV = ", f2(1 / sqrt(nu)))
    )
  })
)
shapes$shape <- factor(shapes$shape, levels = unique(shapes$shape))
ggplot(shapes, aes(y, d, colour = shape)) +
  geom_line(linewidth = 0.9) +
  scale_colour_viridis_d(end = 0.9, name = NULL) +
  labs(title = "Gamma distributions with a mean of 20", x = "y", y = "density") +
  theme_bw() +
  theme(legend.position = "bottom")

Gamma shapes – Step 1: the gamma distribution

Step 3: this is not the same as a regression of log(cost)

Least squares on \(\log y\) models \(E(\log y)\). Gamma regression models \(\log E(y)\). The first compares typical (geometric mean) costs, the second compares mean costs. If the spread differs between groups the two can disagree. For budgets one needs the mean.

Step 4: the estimates

The \(\beta\)’s do not depend on \(\phi\). They solve

\[\sum_i \frac{y_i - \mu_i}{\mu_i}\, x_i = 0\]

The relative errors \((y - \mu)/\mu\) are balanced against each predictor. A 10% error counts the same for a cheap and for an expensive stay. All that the estimates need is that the mean model is right. The variance assumption decides only their precision and standard errors.

Code
X <- model.matrix(~ severity + age + male + hospital, data = stays); y <- stays$cost
beta <- c(log(mean(y)), rep(0, ncol(X) - 1))
for (it in 1:30) {
  # Fisher scoring: regress the relative error on X, and step
  mu <- exp(drop(X %*% beta))
  step <- solve(crossprod(X), crossprod(X, (y - mu) / mu))
  beta <- beta + drop(step)
  if (max(abs(step)) < 1e-10) break
}
fit <- glm(cost ~ severity + age + male + hospital, family = Gamma(link = "log"), data = stays)
c(iterations = it, largest_difference = max(abs(beta - coef(fit))))
        iterations largest_difference 
      1.000000e+01       6.421003e-06 

With the log link, Fisher scoring is nothing but a repeated ordinary regression of the relative errors.


4. Fitting the model and reading the output

Code
sm <- summary(fit)
round(sm$coefficients[1:7, ], 3)                                  # the hospitals are in section 5
                 Estimate Std. Error t value Pr(>|t|)
(Intercept)         9.423      0.078 120.731    0.000
severityModerate    0.353      0.047   7.437    0.000
severityMajor       0.744      0.046  16.008    0.000
severityExtreme     1.266      0.051  24.900    0.000
age50 to 69         0.043      0.065   0.663    0.507
age70 or Older     -0.042      0.062  -0.674    0.501
male                0.008      0.022   0.358    0.720
Code
c(
  dispersion = sm$dispersion,
  CV = sqrt(sm$dispersion),
  null_deviance = fit$null.deviance,
  deviance = fit$deviance,
  df = fit$df.residual
)
   dispersion            CV null_deviance      deviance            df 
    0.4840869     0.6957636  2321.2327072  1472.4790577  4117.0000000 
Code
V <- vcovHC(fit, type = "HC0") # sandwich: valid when the variance is not mu^2
robust <- coeftest(fit, vcov = V)
ci     <- exp(coefci(fit, vcov. = V))
ratio  <- exp(coef(fit))
key <- c(
  "severityModerate", "severityMajor", "severityExtreme", "age50 to 69", "age70 or Older", "male"
)
round(
  cbind(
    ratio = ratio[key],
    low = ci[key, 1],
    high = ci[key, 2],
    SE_usual = sm$coefficients[key, 2],
    SE_robust = robust[key, 2]
  ),
  3
)
                 ratio   low  high SE_usual SE_robust
severityModerate 1.423 1.327 1.526    0.047     0.036
severityMajor    2.105 1.962 2.258    0.046     0.036
severityExtreme  3.546 3.234 3.889    0.051     0.047
age50 to 69      1.044 0.923 1.182    0.065     0.063
age70 or Older   0.959 0.856 1.074    0.062     0.058
male             1.008 0.964 1.053    0.022     0.022
  • (Intercept): \(e^{9.42}\) = 12,366 dollars, the mean cost of the reference case: minor severity, 30 to 49 years, a woman, at the largest hospital.
  • Severity: extreme cases cost 3.55 times as much as minor ones, 95% CI [3.23, 3.89], in patients of the same age and sex and at the same hospital.
  • Age and sex matter little once severity is known: people of 70 or more cost 0.96 times as much as those of 30 to 49, [0.86, 1.07], men 1.01 times as much as women.
  • Dispersion = 0.48 estimates \(\phi\), so the CV around the mean is \(\sqrt{0.48}\) = 0.70.
  • Deviance: the model explains 37% of the null deviance. Unlike a binomial deviance for grouped data, the residual deviance is not a test of fit, because \(\phi\) is estimated.

Testing whole factors

Because the dispersion is estimated, use F tests, not \(\chi^2\) tests:

Code
drops <- drop1(fit, test = "F")
drops
Single term deletions

Model:
cost ~ severity + age + male + hospital
         Df Deviance   AIC  F value    Pr(>F)    
<none>        1472.5 85632                       
severity  3   1981.7 86678 474.5818 < 2.2e-16 ***
age       2   1477.3 85638   6.7745  0.001155 ** 
male      1   1472.5 85631   0.1742  0.676390    
hospital 10   1803.5 86296  92.5536 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Age as a whole is significant, p = .001, although neither age group differs clearly from the youngest: the oldest patients cost 8% less than those of 50 to 69. With 4,134 stays, small differences are significant.


5. The hospitals

Code
hosp <- grep("^hospital", names(coef(fit)), value = TRUE)
hosp_data <- data.frame(
  hospital = sub("^hospital", "", hosp),
  ratio = ratio[hosp],
  low = ci[hosp, 1],
  high = ci[hosp, 2]
)
hosp_data$short <- sub(" of Port Jefferson New York Inc", "", hosp_data$hospital)
hosp_data$short <- factor(hosp_data$short, levels = hosp_data$short[order(hosp_data$ratio)])

ggplot(hosp_data, aes(ratio, short)) +
  geom_vline(xintercept = 1, linetype = "dashed", colour = "grey50") +
  geom_pointrange(aes(xmin = low, xmax = high), colour = "#2a78d6", linewidth = 0.8) +
  scale_x_log10(breaks = c(0.4, 0.5, 0.6, 0.8, 1)) +
  labs(title = "Cost of a stay compared with the largest hospital",
       subtitle = paste0("Reference: ", levels(stays$hospital)[1], ". Same severity, age and sex"),
       x = "ratio of mean costs (log scale)", y = NULL) +
  theme_bw() + theme(plot.title.position = "plot")

5. The hospitals

Among patients of the same severity class, age group and sex, the mean cost at the other hospitals is 0.42 to 0.81 times that of the university hospital, which is the reference. A difference in cost is not a difference in efficiency: the classes are coarse, a university hospital gets the complicated cases within each class, and the costs are estimated from each hospital’s own accounts.


6. Gamma against the alternatives

Code
ols     <- lm(cost ~ severity + age + male + hospital, data = stays)
logs    <- lm(log(cost) ~ severity + age + male + hospital, data = stays)
smear <- mean(exp(resid(logs))) # one smearing factor for all
smear_s <- tapply(exp(resid(logs)), stays$severity, mean) # one for each severity class
pred <- data.frame(
  severity = stays$severity,
  observed = stays$cost,
  gamma = fitted(fit),
  OLS = fitted(ols),
  logs_naive = exp(fitted(logs)),
  logs_smeared = exp(fitted(logs)) * smear,
  logs_smeared_by_severity = exp(fitted(logs)) * smear_s[as.character(stays$severity)]
)
means <- aggregate(. ~ severity, data = pred, FUN = mean)
print(cbind(severity = as.character(means$severity), round(means[, -1])), row.names = FALSE)
 severity observed gamma   OLS logs_naive logs_smeared logs_smeared_by_severity
    Minor     7702  7846  7702       6937         8304                     7816
 Moderate    11324 11454 11324       9912        11865                    11418
    Major    16632 16468 16632      13743        16451                    16441
  Extreme    27651 27565 27651      21131        25296                    27578
Code
smear_s
   Minor Moderate    Major  Extreme 
1.126782 1.151922 1.196333 1.305117 
  • Gamma comes close to the mean of each severity class, without any correction: the differences are at most 1.9%. (They are not exactly zero, because the model balances the relative errors of step 4, not the errors in dollars.)
  • Exponentiating the predictions of the log model gives costs that are too low everywhere (21,131 instead of 27,651 for extreme cases).
  • One smearing factor repairs the average, and not the classes: the spread of the logs grows with severity, so the factor should be 1.13 for minor and 1.31 for extreme cases. The log model would need a model for the spread as well.
  • OLS on dollars gets the class means right. But it adds the same number of dollars for a hospital to a minor and to an extreme case.

Which variance? The modified Park test

Is the variance proportional to \(\mu^2\), as the gamma assumes? Regress the log of the squared residuals on the log of the mean, with a gamma GLM (Manning & Mullahy, 2001). The slope is the power of the mean: 0 for the normal, 1 for Poisson-like, 2 for the gamma, 3 for the inverse Gaussian.

Code
park <- glm(
  (stays$cost - fitted(fit))^2 ~ log(fitted(fit)),
  family = Gamma("log"),
  control = list(maxit = 100)
)
park_slope <- coef(park)[[2]]; park_se <- sqrt(vcovHC(park, type = "HC0")[2, 2])
c(power = park_slope, SE = park_se)
    power        SE 
2.7501910 0.2545951 
Code
invg <- glm(
  cost ~ severity + age + male + hospital,
  family = inverse.gaussian("log"),
  data = stays,
  start = coef(fit)
)
aic_log <- AIC(logs) + 2 * sum(log(stays$cost)) # on the scale of dollars, to compare
c(gamma = AIC(fit), inverse_gaussian = AIC(invg), log_normal = aic_log, normal = AIC(ols))
           gamma inverse_gaussian       log_normal           normal 
        85632.45         85337.78         85270.93         91361.59 

The power is 2.75 (robust SE 0.25): larger than 2, towards the 3 of the inverse Gaussian. The AIC agrees: the log-normal and the inverse Gaussian describe the distribution of the costs better than the gamma, and the normal distribution is hopeless. So the gamma is not the true distribution of these costs. Does it matter for the ratios?

Code
weights_check <- cbind(
  gamma = exp(coef(fit))[key],
  inverse_gaussian = exp(coef(invg))[key],
  poisson_type = exp(coef(glm(
    cost ~ severity + age + male + hospital,
    family = quasipoisson("log"),
    data = stays
  )))[key],
  logs = exp(coef(logs))[key]
)
round(weights_check, 2)
                 gamma inverse_gaussian poisson_type logs
severityModerate  1.42             1.41         1.43 1.40
severityMajor     2.10             2.05         2.17 1.99
severityExtreme   3.55             3.49         3.64 3.07
age50 to 69       1.04             1.03         1.02 1.01
age70 or Older    0.96             0.98         0.90 0.99
male              1.01             1.01         1.01 1.00

Hardly. The three models for the mean agree on the ratios to within a few percent, because they share the same model for the mean and differ only in how much weight the expensive stays get. The log model, which compares geometric means, gives a smaller ratio for extreme severity (3.07). This is the practical lesson: choose the link and the mean model with care, use robust standard errors, and do not worry too much about the exact variance.


7. Checking the model

Code
chk <- data.frame(mu = fitted(fit), dev = rstandard(fit, type = "deviance"))
chk$q <- qqnorm(chk$dev, plot.it = FALSE)$x
pa <- ggplot(chk, aes(mu / 1000, dev)) +
  geom_hline(yintercept = 0, colour = "grey60") +
  geom_point(alpha = 0.15, size = 0.8) +
  geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "#eb6834") +
  labs(
    title = "Deviance residuals against the fitted mean",
    x = "fitted mean (thousand dollars)",
    y = "residual"
  ) +
  theme_bw()
pb <- ggplot(chk, aes(q, dev)) +
  geom_abline(colour = "grey60") +
  geom_point(colour = "#2a78d6", alpha = 0.4, size = 0.9) +
  labs(title = "Normal Q-Q plot of the deviance residuals", x = "normal quantile", y = "residual") +
  theme_bw()
patchwork::wrap_plots(pa, pb, ncol = 1)

Residuals – 7. Checking the model

Code
tenth <- cut(fitted(fit), quantile(fitted(fit), 0:10 / 10), include.lowest = TRUE, labels = 1:10)
cal <- data.frame(
  predicted = tapply(fitted(fit), tenth, mean),
  observed = tapply(stays$cost, tenth, mean)
)
cal$ratio <- cal$observed / cal$predicted
round(cal, 2)
   predicted observed ratio
1    7383.23  7665.60  1.04
2    9116.18  9316.09  1.02
3   10716.19 10561.33  0.99
4   12180.00 11730.18  0.96
5   13493.20 12810.30  0.95
6   15411.10 15427.16  1.00
7   17579.59 17194.05  0.98
8   20833.31 21218.81  1.02
9   25014.60 25661.84  1.03
10  32834.72 33418.23  1.02
Code
worst <- order(-cooks.distance(fit))[1:3]
stays[worst, c("cost", "severity", "age", "days")]
          cost severity         age days
1211 489976.48  Extreme    50 to 69   62
3203  91777.08    Major 70 or Older   29
3215  32800.88    Major 70 or Older   10

Deviance residuals of a good gamma model are roughly normal. Ours have a heavier right tail: some stays are far more expensive than even a gamma distribution allows. The mean is right, which the calibration shows: in tenths of the predicted cost, the ratio of observed to predicted is between 0.95 and 1.04. The most influential stays are listed; the most expensive cost 489,976 dollars. Without the top ten, the ratio for extreme severity changes to

Code
top10 <- order(-stays$cost)[1:10]
exp(coef(update(fit, data = stays[-top10, ]))[["severityExtreme"]])
[1] 3.354952

from 3.55.


8. Predicted costs

Code
new <- expand.grid(
  severity = levels(stays$severity),
  age = "70 or Older",
  male = 0,
  hospital = levels(stays$hospital)[1:2]
)
eta <- predict(fit, new, type = "link")
Xn <- model.matrix(delete.response(terms(fit)), new, xlev = fit$xlevels)
se  <- sqrt(rowSums((Xn %*% V) * Xn))
new$cost <- exp(eta); new$low <- exp(eta - 1.96 * se); new$high <- exp(eta + 1.96 * se)
print(
  cbind(new[, c("severity", "hospital")], round(new[, c("cost", "low", "high")])),
  row.names = FALSE
)
 severity                               hospital  cost   low  high
    Minor        Stony Brook University Hospital 11857 10944 12846
 Moderate        Stony Brook University Hospital 16875 15939 17865
    Major        Stony Brook University Hospital 24953 23572 26415
  Extreme        Stony Brook University Hospital 42045 38745 45625
    Minor Good Samaritan Hospital Medical Center  5767  5305  6270
 Moderate Good Samaritan Hospital Medical Center  8208  7715  8733
    Major Good Samaritan Hospital Medical Center 12138 11401 12922
  Extreme Good Samaritan Hospital Medical Center 20452 18831 22212

The rows are for women of 70 or older at two of the hospitals. The intervals are for the mean cost of such patients. For one patient the range is much wider: with a CV of 0.70, a gamma distribution with a mean of 20,000 dollars has 95% of its values between 2,546 and 55,043.


9. Things to keep in mind

  • Positive outcomes only. A gamma variable is never zero. With real zeros, use a two-part model or Tweedie regression.
  • Log link, unless you have a reason. Ratios are easy to explain.
  • Robust standard errors cost nothing and protect against a wrong variance. Here the usual and the robust ones are similar for most terms.
  • Do not adjust for what lies between. The length of the stay is the main way in which severity costs money. With days in the model, the coefficient of severity would be the cost of severity at the same length of stay, which is another question.
  • Clusters. Patients of one hospital are alike. We gave each hospital its own level. For many hospitals, a mixed model (lme4::glmer with a gamma family, or glmmTMB).
  • Durations, sizes, amounts of rain on wet days, reaction times are other typical gamma outcomes.
  • Gamma or log-normal? For large samples and a question about means, the gamma GLM. For prediction intervals of single cases, the distribution that fits best.
  • Not a causal model. Patients are not assigned to hospitals at random.

10. Reporting the results in APA style

A report (APA 7th edition) needs the distribution and link, the reference categories, ratios with intervals, the kind of standard errors, and a check of the variance assumption. The numbers come from the R objects:

Code
apa_table <- data.frame(
  Predictor = c(
    "Severity: moderate", "Severity: major", "Severity: extreme", "Age 50–69", "Age 70 or older",
    "Male"
  ),
  b = f2(coef(fit)[key]),
  SE = f3(robust[key, 2]),
  z = f2(robust[key, 3]),
  p = sapply(robust[key, 4], function(p) sub("^= ", "", pval(p))),
  ratio = paste0(f2(ratio[key]), " [", f2(ci[key, 1]), ", ", f2(ci[key, 2]), "]")
)
F_sev <- drops["severity", ]; F_hosp <- drops["hospital", ]

Method (data analysis):

The costs of 4,134 hospital stays for heart failure in Suffolk County, New York, in 2021 (New York State Department of Health, 2023) were positive and right-skewed (M = 16,336, Mdn = 11,907, SD = 17,004 dollars). We used a generalized linear model with a gamma distribution and a log link, with severity of illness (reference: minor), age group (reference: 30–49), sex and hospital as predictors. Exponentiated coefficients are ratios of mean costs. Standard errors are heteroscedasticity-robust. The variance function was examined with the modified Park test (Manning & Mullahy, 2001). Analyses were conducted in R (Version 4.6.2; R Core Team, 2026).

Results:

Costs increased with severity, F(3, 4,117) = 474.6, p < .001: stays with extreme severity cost 3.55 times as much as those with minor severity, 95% CI [3.23, 3.89] (Table 1). Costs also differed between hospitals, F(10, 4,117) = 92.6, p < .001. Age had a small effect, F(2, 4,117) = 6.8, p = .001, and sex none, F(1, 4,117) = 0.2, p = .676. The model explained 37% of the deviance. The variance increased with the mean to the power 2.75, somewhat more than the 2 of the gamma distribution; models with other variance functions gave nearly the same ratios.

Table 1

Gamma Regression of the Cost of a Hospital Stay for Heart Failure

Predictor b SE z p Cost ratio [95% CI]
Severity: moderate 0.35 0.036 9.91 < .001 1.42 [1.33, 1.53]
Severity: major 0.74 0.036 20.78 < .001 2.10 [1.96, 2.26]
Severity: extreme 1.27 0.047 26.90 < .001 3.55 [3.23, 3.89]
Age 50–69 0.04 0.063 0.69 .493 1.04 [0.92, 1.18]
Age 70 or older -0.04 0.058 -0.72 .469 0.96 [0.86, 1.07]
Male 0.01 0.022 0.35 .726 1.01 [0.96, 1.05]

Note. N = 4,134. Log link, robust standard errors. Also adjusted for hospital (11 levels). Dispersion = 0.48.

Points to remember:

  • Name the distribution and the link.
  • Report ratios of means, with intervals, and the reference categories.
  • Say how you checked the variance, and that the standard errors are robust.
  • Give predicted means in the original unit.

11. Summary

When A positive, skewed outcome whose SD grows with the mean: costs, durations, sizes
The model \(\log E(y) = x^\top\beta\), \(\text{Var}(y) = \phi\,\mu^2\)
How (R) glm(y ~ x, family = Gamma(link = "log"))
Reading it \(e^{\beta}\): ratio of means
Dispersion \(\phi\); the CV is \(\sqrt\phi\)
Tests F tests (drop1(fit, test = "F")), robust standard errors
Against log(y) \(\log E(y)\), not \(E(\log y)\): no smearing needed
Checks Modified Park test, deviance residuals, calibration by tenths
Related pages Two-part models, generalized linear models, weighted least squares

References

Manning, W. G., & Mullahy, J. (2001). Estimating log models: To transform or not to transform? Journal of Health Economics, 20(4), 461–494. https://doi.org/10.1016/S0167-6296(01)00086-8

McCullagh, P., & Nelder, J. A. (1989). Generalized linear models (2nd ed.). Chapman & Hall.

New York State Department of Health. (2023). Hospital inpatient discharges (SPARCS de-identified): 2021 [Data set]. Health Data NY. https://health.data.ny.gov/d/tg3i-cinn