apc.fit( data, A, P, D, Y, ref.c, ref.p, dist = c("poisson","binomial"), model = c("ns","bs","ls","factor"), dr.extr = "weighted", parm = c("ACP","APC","AdCP","AdPC","Ad-P-C","Ad-C-P","AC-P","AP-C"), npar = c( A=5, P=5, C=5 ), scale = 1, alpha = 0.05, print.AOV = TRUE )
A
(age),
P
(period), D
(cases, deaths) and Y
(person-years). Cohort (date of birth) is computed as P-A
.
If this argument is given the arguments A
, P
,
D
and Y
are ignored.dist
argument.parm="AdCP"
or parm="AdPC"
,
the residual cohort effects will be 1 at ref.c
Y
is assumed to be the
denominator; "binomial"
gives a binomial model with logit
link.ns
fits a model with natural splines for each of
the terms, with npar
parameters for the terms.
bs
fits a model with B-splines for each of
the terms, with npar
parameters for the terms.
ls
fits a model with linear splines.
factor
fits a factor model with one parameter
per value of A
, P
and C
. npar
is ignored in this case.
"weighted"
(or "t") (default) uses the no. cases, D
,
corresponding to the observed information about the log-rate
(usually termed "theta", hence the "t
"). "r"
or "l"
uses
Y*Y/D
corresponding to the observed information about the
rate (usually termed "lambda", hence the "l
"). "y"
uses the person-years as the weight in the inner product. If given
"n
" (Naive) (well, in fact any other character value) will
induce the use of the standard inner product putting equal weight on
all units in the dataset.
If given as a numeric vector this is used as the diagonal of the matrix inducing the inner product.
The setting of this parameter has no effect on the fit of the model, only on the parametrization.
dr.extr
is ignored. Possible values for parm
are:
"ACP"
: ML-estimates. Age-effects as rates for the
reference cohort. Cohort effects as RR relative to the reference
cohort. Period effects constrained to be 0 on average with 0 slope.
"APC"
: ML-estimates. Age-effects as rates for the
reference period. Period effects as RR relative to the reference
period. Cohort effects constrained to be 0 on average with 0 slope.
"AdCP"
: ML-estimates. Age-effects as rates for the
reference cohort. Cohort and period effects constrained to be 0 on
average with 0 slope. In this case returned effects do not
multiply to the fitted rates, the drift is missing and needs to be
included to produce the fitted values.
"AdPC"
: ML-estimates. Age-effects as rates for the
reference period. Cohort and period effects constrained to be 0 on
average with 0 slope. In this case returned effects do not
multiply to the fitted rates, the drift is missing and needs to be
included to produce the fitted values.
"Ad-C-P"
: Age effects are rates for the reference
cohort in the Age-drift model (cohort drift). Cohort effects are from the model
with cohort alone, using log(fitted values) from the Age-drift
model as offset. Period effects are from the model with period
alone using log(fitted values) from the cohort model as offset.
"Ad-P-C"
: Age effects are rates for the reference
period in the Age-drift model (period drift). Period effects are from the model
with period alone, using log(fitted values) from the Age-drift
model as offset. Cohort effects are from the model with cohort
alone using log(fitted values) from the period model as offset.
"AC-P"
: Age effects are rates for the reference
cohort in the Age-Cohort model, cohort effects are RR relative to
the reference cohort. Period effects are from the model
with period alone, using log(fitted values) from the Age-Cohort
model as offset.
"AP-C"
: Age effects are rates for the reference
period in the Age-Period model, period effects are RR relative to
the reference period. Cohort effects are from the model
with cohort alone, using log(fitted values) from the Age-Period
model as offset.
(1:nk-0.5)/nk
of the events (i.e. of rep(A,D)
) npar
may also be a named list of three numerical vectors with
names "A", "P" and "C", in which case these taken as the knots for
the age, period and cohort effect, the smallest and largest element in
each vector are used as the boundary knots.
alpha
) confidence limits.A
and P
are coded with the mean age and calendar
time of observation in the subset. This is essential since A
and P
are used as quantitative variables in the models. This is a different approach relative to the vast majority of the
uses of APC-models in the literature where a factor model is used for
age, perido and cohort effects. The latter can be obtained by using
model="factor"
.
Various links to course material etc. is available through http://BendixCarstensen.com/APC
LCa.fit
,
apc.frame
,
apc.lines
,
apc.plot
.
library( Epi )
data(lungDK)
# Taylor a dataframe that meets the requirements
exd <- lungDK[,c("Ax","Px","D","Y")]
names(exd)[1:2] <- c("A","P")
# Two different ways of parametrizing the APC-model, ML
ex.H <- apc.fit( exd, npar=7, model="ns", dr.extr="Holford", parm="ACP", scale=10^5 )
ex.W <- apc.fit( exd, npar=7, model="ns", dr.extr="weighted", parm="ACP", scale=10^5 )
# Sequential fit, first AC, then P given AC.
ex.S <- apc.fit( exd, npar=7, model="ns", parm="AC-P", scale=10^5 )
# Show the estimated drifts
ex.H[["Drift"]]
ex.W[["Drift"]]
ex.S[["Drift"]]
# Plot the effects
fp <- apc.plot( ex.H )
apc.lines( ex.W, frame.par=fp, col="red" )
apc.lines( ex.S, frame.par=fp, col="blue" )
Run the code above in your browser using DataLab