apc.fit | R Documentation |
Fits the classical five models to tabulated rate data (cases, person-years) classified by two of age, period, cohort: Age, Age-drift, Age-Period, Age-Cohort and Age-Period-Cohort. There are no assumptions about the age, period or cohort classes being of the same length, or that tabulation should be only by two of the variables. Only requires that mean age and period for each tabulation unit is given.
apc.fit( data,
A,
P,
D,
Y,
ref.c,
ref.p,
dist = c("poisson","binomial"),
model = c("ns","bs","ls","factor"),
dr.extr = "Y",
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 )
data |
Data frame with (at least) variables, |
A |
Age; numerical vector with mean age at diagnosis for each unit. |
P |
Period; numerical vector with mean date of diagnosis for each unit. |
D |
Cases, deaths; numerical vector. |
Y |
Person-years; numerical vector. Also used as denominator for binomial
data, see the |
ref.c |
Reference cohort, numerical. Defaults to median date of
birth among cases. If used with |
ref.p |
Reference period, numerical. Defaults to median date of diagnosis among cases. |
dist |
Distribution (or more precisely: Likelihood) used for modeling.
if a binomial model us used, |
model |
Type of model (covariate effects) fitted:
|
dr.extr |
Character or numeric. How the drift parameter should be extracted from the age-period-cohort model. Specifies the inner product used for definition of orthogonality of the period / cohort effects to the linear effects — in terms of a diagonal matrix.
If given If If The setting of this parameter has no effect on the fit of the model,
it only influences the parametrization returned in the |
parm |
Character. Indicates the parametrization of the effects.
The first four refer to the ML-fit of the Age-Period-Cohort model,
the last four give Age-effects from a smaller model and residuals
relative to this. If one of the latter is chosen, the argument
|
npar |
The number of parameters/knots to use for each of the terms in
the model. If it is vector of length 3, the numbers are taken as the
no. of knots for Age, Period and Cohort, respectively. Unless it has
a names attribute with values "A", "P" and "C" in which case these
will be used. The knots chosen are the quantiles
|
alpha |
The significance level. Estimates are given with
(1- |
scale |
numeric(1), factor multiplied to the rate estimates before output. |
print.AOV |
Should the analysis of deviance table for the models be printed? |
Each record in the input data frame represents a subset of a Lexis
diagram. The subsets need not be of equal length on the age and
period axes, in fact there are no restrictions on the shape of
these; they could be Lexis triangles for example. The requirement is
that 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 approach is different from to the vast majority of the uses of
APC-models in the literature where a factor model is used for age,
period and cohort effects. The latter can be obtained by using
model="factor"
. Note however that the cohort factor is defined
from A
and P
, so that it is not possible in this
framework to replicate the Boyle-Robertson fallacy.
An object of class "apc" (recognized by apc.plot
and
apc.lines
) — a list with components:
Type |
Text describing the model and parametrization returned. |
Model |
The model object(s) on which the parametrization is based. |
Age |
Matrix with 4 columns: |
Per |
Matrix with 4 columns: |
Coh |
Matrix with 4 columns: |
Drift |
A 3 column matrix with drift-estimates and c.i.s: The
first row is the ML-estimate of the drift (as defined by
|
Ref |
Numerical vector of length 2 with reference period and cohort. If ref.p or ref.c was not supplied the corresponding element is NA. |
Anova |
Analysis of deviance table comparing the five classical models. |
Knots |
If |
Bendix Carstensen, http://bendixcarstensen.com
The considerations behind the parametrizations used in this function are given in detail in: B. Carstensen: Age-Period-Cohort models for the Lexis diagram. Statistics in Medicine, 10; 26(15):3018-45, 2007.
Various links to course material etc. is available through http://bendixcarstensen.com/APC/
apc.frame
,
apc.lines
,
apc.plot
,
LCa.fit
,
apc.LCa
.
library( Epi )
data(lungDK)
# Taylor a dataframe that meets the requirements for variable names
exd <- lungDK[,c("Ax","Px","D","Y")]
names(exd)[1:2] <- c("A","P")
# Three different ways of parametrizing the APC-model, ML
ex.1 <- apc.fit( exd, npar=7, model="ns", dr.extr="1", parm="ACP", scale=10^5 )
ex.D <- apc.fit( exd, npar=7, model="ns", dr.extr="D", parm="ACP", scale=10^5 )
ex.Y <- apc.fit( exd, npar=7, model="ns", dr.extr="Y", 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.1[["Drift"]]
ex.D[["Drift"]]
ex.Y[["Drift"]]
ex.S[["Drift"]]
# Plot the effects
lt <- c("solid","22")[c(1,1,2)]
apc.plot( ex.1, lty=c(1,1,3) )
apc.lines( ex.D, col="red", lty=c(1,1,3) )
apc.lines( ex.Y, col="limegreen", lty=c(1,1,3) )
apc.lines( ex.S, col="blue", lty=c(1,1,3) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.