mod_norm: Specify a Normal Model

View source: R/bage_mod-constructors.R

mod_normR Documentation

Specify a Normal Model

Description

Specify a model where the outcome is drawn from a normal distribution.

Usage

mod_norm(formula, data, weights)

Arguments

formula

An R formula, specifying the outcome and predictors.

data

A data frame containing outcome, predictor, and, optionally, weights variables.

weights

Name of the weights variable, a 1, or a formula. See below for details.

Details

The model is hierarchical. The means in the normal distribution are described by a prior model formed from dimensions such as age, sex, and time. The terms for these dimension themselves have models, as described in priors. These priors all have defaults, which depend on the type of term (eg an intercept, an age main effect, or an age-time interaction.)

Value

An object of class bage_mod_norm.

Scaling of outcome and weights

Internally, mod_norm() scales the outcome variable to have mean 0 and standard deviation 1, and scales the weights to have mean 1. This scaling allows mod_norm() to use the same menu of priors as mod_pois() and mod_binom().

augment() always returns values on the original scale, rather than the transformed scale.

components() by default returns values on the transformed scale. But if original_scale is TRUE, it returns some types of values on the original scale. See components() for details.

Specifying weights

The weights argument can take three forms:

  • the name of a variable in data, with or without quote marks, eg "wt" or wt;

  • the number 1, in which no weights are used; or

  • a formula, which is evaluated with data as its environment (see below for example).

Mathematical details

The likelihood is

y_i \sim \text{N}(\gamma_i, w_i^{-1} \sigma^2)

where

  • subscript i identifies some combination of the classifying variables, such as age, sex, and time,

  • y_i is the value of the outcome variable,

  • w_i is a weight.

In some applications, w_i is set to 1 for all i.

Internally, bage works with standardized versions of \gamma_i and \sigma^2:

\mu_i = (\gamma_i - \bar{y}) / s

\xi^2 = \sigma^2 / (\bar{w} s^2)

where

\bar{y} = \sum_{i=1}^n y_i / n

s = \sqrt{\sum_{i=1}^n (y_i - \bar{y})^2 / (n-1)}

\bar{w} = \sum_{i=1}^n w_i / n

Mean parameter \mu_i is modelled as the sum of terms formed from classifying variables and covariates,

\mu_i = \sum_{m=0}^{M} \beta_{j_i^m}^{(m)}

where

  • \beta^{0} is an intercept;

  • \beta^{(m)}, m = 1, \dots, M, is a main effect or interaction; and

  • j_i^m is the element of \beta^{(m)} associated with cell i,

The \beta^{(m)} are given priors, as described in priors.

\xi has an exponential prior with mean 1. Non-default values for the mean can be specified with set_disp().

The model for \mu_i can also include covariates, as described in set_covariates().

See Also

  • mod_pois() Specify Poisson model

  • mod_binom() Specify binomial model

  • set_prior() Specify non-default prior for term

  • set_disp() Specify non-default prior for standard deviation

  • fit() Fit a model

  • augment() Extract values for means, together with original data

  • components() Extract values for hyper-parameters

  • forecast() Forecast parameters and outcomes

  • report_sim() Check model using a simulation study

  • replicate_data() Check model using replicate data data for a model

  • Mathematical Details Detailed description of models

Examples

mod <- mod_norm(value ~ diag:age + year,
                data = nld_expenditure,
                weights = 1)

## use formula to specify weights
mod <- mod_norm(value ~ diag:age + year,
                data = nld_expenditure,
                weights = ~sqrt(value))

bage documentation built on Aug. 8, 2025, 6:09 p.m.