stepwise_replacement | R Documentation |
This implements the algorithm described in Andreev et al (2002), with defaults set to approximate their recommendations for replacement ordering and result averaging.
stepwise_replacement(
func,
pars1,
pars2,
symmetrical = TRUE,
direction = "up",
...
)
func |
A function specified by the user. This must be able to take the vectors |
pars1 |
vector of covariates to be passed on as arguments to |
pars2 |
is the same as |
symmetrical |
logical. default |
direction |
character. One of |
... |
optional parameters to pass on to |
The symmetrical
argument toggles whether or not we replace pars1 with pars2 (FALSE
),
or take the arithmetic average or replacement in both directions. direction
refers to whether we go
from the bottom up or top down, or take the arithmetic average of these when replacing vector elements.
Although the total difference will always sum correctly, the calculated contribution from individual components
can vary greatly depending on the order in general. Defaults are set to symmetrically replace from the bottom
up, per the authors' suggestion.
a matrix of the variable effects that is organized in the same way as
pars1
and pars2
.
horiuchi2008decompositionDemoDecomp \insertRefandreev2012excelDemoDecomp
data(Mxc1)
data(Mxc2)
# we'll want to pass in these dimensions
dims <- dim(Mxc1)
# we need parameters in vec form
Mxc1v <- c(Mxc1)
Mxc2v <- c(Mxc2)
B <- stepwise_replacement(func = Mxc2e0abrvec,
pars1 = Mxc1v, pars2 = Mxc2v, dims = dims,
# authors' recommendations:
symmetrical = TRUE, direction = "up")
dim(B) <- dims
# the output, B, is also a single vector. Each element corresponds
# to the effect of changes in that particular covariate toward the
# overall change in the function value. sum(B) should equal the
# original difference
(check1 <- Mxc2e0abr(Mxc2) - Mxc2e0abr(Mxc1))
(check2 <- sum(B))
# This package does not supply default plotting functions, but one
# strategy might be the following:
## Not run:
Age <- c(0, 1, seq(5, 85, by = 5))
matplot(Age, B, type = 'l',
xlab = "Age", ylab = "Contrib to diff in e(0)", col = 1:6)
legend("bottomleft",lty=1:5,col=1:6,
legend = c("Neoplasms","Circulatory","Respiratory",
"Digestive","Acc/viol","Other"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.