decomposition | R Documentation |
Decompose a
DemographicArray
into terms
made up of component dimensions, plus an error.
decomposition
is typically used to obtain
initial estimates of main effects and interactions,
as part of model building.
decomposition(object, max = NULL)
## S4 method for signature 'DemographicArray'
decomposition(object, max = NULL)
object |
An object of class
|
max |
An integer. Optional. |
When building a Poisson model, the decomposition is usually carried out on log-rates, and when building a binomial model, it is usually carried out on logit-proportions, though in both cases other transformations (or no transformation) may be appropriate if there are lots of zeros (and also lots of ones in the case of binomial models).
The final element in the return value is an 'error'
array. This equals the observed value for object
minus the
sum of the terms in the decomposition.
The max
argument controls the maximum order of
the interactions included in decomposition. For instance,
if max
is 2
, then only main effects and second-order
interactions are included in the decomposition. By default,
all interactions are included.
Internally, decomposition
calls function
pairToState
on object
,
to cope with origin-destination or parent-child dimensions.
A named list, the elements of which have class
Values
.
Chapter 12 of Bryant and Zhang, Bayesian Demographic Estimation and Forecasting.
deaths <- Counts(demdata::VADeaths2)
popn <- Counts(demdata::VAPopn)
rates <- deaths/popn
log.rates <- log(rates)
ans <- decomposition(log.rates)
names(ans)
ans[1:3]
ans[["age:residence"]]
mean(log.rates)
round(sapply(ans, sum), 5)
all.equal(Reduce("+", ans), log.rates)
## main effects only
decomposition(log.rates, max = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.