fit_normal: Fit normal outcome model in TMB

View source: R/fit_normal.R

fit_normalR Documentation

Fit normal outcome model in TMB

Description

Fit normal outcome model in TMB. Currently can only fit a space-only model at a single time point. Linear predictor includes a single intercept and a BYM2 sptial random effect, and an IID cluster-level random effect is included if unit-level data is input (otherwise, no cluster-level random effect). Can fit benchmarked models, unbenchmarked models, or both. Simultaneous benchmarking is performed via a second likelihood for the national level estimate. Produces posterior samples for fitted values, hyperparameters, random effects, and fixed effects.

Usage

fit_normal(
  df,
  cluster = NA,
  y = "y",
  region = "admin1",
  SE_i,
  hiv_adj = NA,
  natl = NULL,
  natl_sd = NULL,
  pop_weights = NULL,
  Q_struct_space = NULL,
  intercept_pri = c(0, 31.62278),
  nsamp = 1000,
  benched = "unbenched",
  expit_outcome = NULL
)

Arguments

df

a dataframe containing normal outcome data, and the following columns:

  • cluster: cluster ID

  • y: normally distributed outcome

  • region: area

cluster

the column in binom_df corresponding to cluster id. If data is area-level then cluster should be set to NA. By default, cluster will be set to NA.

y

the column in binom_df corresponding to the outcome

region

the column in binom_df corresponding to region/area. Must be numeric and start from 1.

SE_i

a vector of fixed standard errors for use in the normal likelihood. Length of SE_i must be equal to the number of regions.

hiv_adj

An optional log offset in time to include in the linear predictor. Defaults to no log offset.

natl

a vector of national level estimates, arranged in order of time

natl_sd

a vector of standard deviations for national level estimates, arranged in order of time

pop_weights

a vector of population weights for use in the benchmarking constraint. Must sum to one at each time point, and be in order arrange(region)

Q_struct_space

An ICAR precision matrix. Should be unscaled, as scaling will happen internally.

intercept_pri

Prior specification for the intercept. Defaults to c(0, 31.62278), corresponding to the default prior for the intercept in INLA, with mean 0 and precision 0.001. Must be a vector of length 2, with specificaiton c(mean, sd) for a Normal distribution. Currently only an option for unbenchmarked models.

nsamp

Number of posterior samples to take from joint posterior. Defaults to 1000

benched

A string, either "benched", "unbenched", or "both", determining whether to fit a benchmarked model, and unbenchmarked model, or both. Defaults to "unbenched".

expit_outcome

A boolean for whether or not the normally distributed outcome needs to be expit-ed in order to be on the same scale as national estimates. This parameter will only affect benchmarked models. If TRUE, linear predictors will be expit-ed before being multiplied by population weights in the benchmarking constraint. This parameter must be specified by the user if benched = "benched".

Value

A list containing:

  • fitted_mat: a matrix of posterior samples of fitted values in order arrange(region, time)

  • re_list: a list contaning matrices of posterior samples for each random effect term

  • param_list: a list containing matrices of posterior samples for fixed effects and hyperparameters

  • runtime: the time it took to fit the model in TMB and get samples from the joint posterior

If benched = "both", a list of two will be returned containing the above list for both benchmarked and unbenchmarked models.

Author(s)

Taylor Okonek


taylorokonek/stbench documentation built on Jan. 7, 2025, 11:13 p.m.