Package 'hpolcc'

Title: Hierarchical Air Pollution Model
Description: Fits hierarchical functional case-crossover models for air pollution health effects, with hierarchical structures and case-crossover designs built on the adlaplace Laplace approximation framework.
Authors: Patrick Brown [aut, cre, cph]
Maintainer: Patrick Brown <[email protected]>
License: MPL-2.0
Version: 0.5.2
Built: 2026-07-17 23:39:34 UTC
Source: https://github.com/eborgnine/adlaplace

Help Index


Dirichlet-multinomial case-crossover response term

Description

Dirichlet-multinomial case-crossover response term

Usage

dirichlet_multinom(x, by, init = 0.001, lower = 0, upper = Inf, parscale = 1)

Arguments

x

Outcome variable name.

by

Character vector of stratification variables (e.g. c("year", "month", "dow")).

init

Initial value for overdispersion sd.

lower

Lower bound for sd.

upper

Upper bound for sd.

parscale

Parameter scale for optimization.

Value

A dirichlet_multinom object.


Dirichlet-multinomial response term

Description

Model term for the case-crossover Dirichlet-multinomial log density registered as dirichlet_multinomial.

Usage

## S4 method for signature 'dirichlet_multinom'
elgm_matrix(term, data)

## S4 method for signature 'dirichlet_multinom'
design(term, data)

## S4 method for signature 'dirichlet_multinom'
precision(term, data)

## S4 method for signature 'dirichlet_multinom'
theta_info(term)

## S4 method for signature 'dirichlet_multinom'
beta_info(term, data)

## S4 method for signature 'dirichlet_multinom'
random_info(term, data)

Arguments

term

A dirichlet_multinom term object.

data

Analysis-ready data frame.

Value

Sparse ngCMatrix mapping observations to strata columns.

Functions

  • elgm_matrix(dirichlet_multinom): Case-crossover stratum map for AD shards.

  • design(dirichlet_multinom): Design method (not used).

  • precision(dirichlet_multinom): Precision method (not used).

  • theta_info(dirichlet_multinom): Theta info for overdispersion sd.

  • beta_info(dirichlet_multinom): Beta info method (not used).

  • random_info(dirichlet_multinom): Random info method (not used).

Slots

by

Character vector of stratification variables for the case-crossover design.

Slots (inherited from model)

ad_fun

Character scalar "dirichlet_multinomial".

ad_kind

Character scalar "observations".

package

Character scalar "hpolcc".


Build observation-shard ad_fun_ptr in this package's shared library.

Description

Build observation-shard ad_fun_ptr in this package's shared library.

Usage

get_ad_fun_raw_obs(model, config, name)

Arguments

model

ad_data S4 object.

config

Model configuration list.

name

Observation density name (e.g. "dirichlet_multinomial").

Value

External pointer of class ad_fun_ptr.


Build parameters-shard ad_fun_ptr in this package's shared library.

Description

Build parameters-shard ad_fun_ptr in this package's shared library.

Usage

get_ad_fun_raw_parameters(model, config, name)

Arguments

model

ad_data S4 object.

config

Model configuration list.

name

Parameters density name (e.g. "dirichlet_multinomial_extra").

Value

External pointer of class ad_fun_ptr.


Fit Hierarchical Non-Linear Models

Description

Fits a hierarchical case-crossover model with a dirichlet_multinom response term, using adlaplace automatic differentiation and Laplace approximation.

Usage

hnlm(
  formula,
  data,
  config = list(transform_theta = TRUE),
  control = list(maxit = 1000, trace = 3, REPORT = 1),
  control_inner = list(report.level = 0),
  for_dev = FALSE,
  ...
)

Arguments

formula

Model formula with a dirichlet_multinom(...) response on the LHS.

data

Data frame containing variables referenced in formula.

config

Configuration list passed to adlaplace. Common entries:

transform_theta

If TRUE (default), optimize log-scale hyperparameters.

num_threads

OpenMP threads for inner optimization and derivative evaluation (default 1L).

num_shards

Target number of observation shards for parallel evaluation (default 1000L).

num_sim

Number of conditional simulation draws from adlaplaceHgp::cond_sim_iwp (default 500).

verbose

Verbosity level; values above 1 enable extra adlaplace logging.

control

Control list passed to outer optim.

control_inner

Control list passed to inner optimization.

for_dev

If TRUE, return intermediate objects for development.

...

Unused.

Value

When for_dev = TRUE, a development bundle of class c("hnlm_dev", "hnlm"). Otherwise a fitted object of class hnlm with primary slots coefficients, log_lik, optim, converged, extra (Laplace output), hessian, info, optional sample, and call (fit metadata including config, terms, and the original match.call).


Remove Holidays from Data

Description

This function removes holidays from a dataset based on the specified type.

Usage

remove_holidays(data, type = "rm_all")

Arguments

data

A data frame containing a 'date' column.

type

A character string specifying the type of holiday removal. Options are "rm_none", "rm_all".

Value

A data frame with holidays removed according to the specified type.


Summary method for hnlm fits

Description

Returns coefficients$parameters from the fit, including mle and se (when the outer Hessian was available at fit time).

Usage

## S3 method for class 'hnlm'
summary(object, ...)

## S3 method for class 'summary.hnlm'
print(x, digits = max(3L, getOption("digits") - 3L), ...)

Arguments

object

A fitted hnlm object.

...

Not used.

x

A summary.hnlm object.

digits

Number of significant digits to print.

Value

An object of class summary.hnlm with the parameters table, variance matrix, log-likelihood, and convergence flag.


Variance-covariance matrix of outer parameters

Description

Inverse of the outer Hessian from profile likelihood optimization (hessian$outer). Falls back to a Moore-Penrose inverse with a warning if the Hessian is singular.

Usage

## S3 method for class 'hnlm'
vcov(object, ...)

Arguments

object

A fitted hnlm object.

...

Not used.

Value

Variance-covariance matrix on the optimization scale of optim$par.