| apc.fit {Epi} | R Documentation |
Fits the classical five models to tabulated rate data (cases, person-years) classified by age and period: Age, Age-drift, Age-Period, Age-Cohort and Age-period.
apc.fit( data,
A,
P,
D,
Y,
ref.c,
ref.p,
model = c("ns","bs ","factor","fpol"),
drift = c("weighted","Holford"),
parm = c("ACP","APC","AdCP","Ad-P-C","Ad-C-P","AC-P","AP-C"),
npar = c( A=5, P=5, C=5 ),
scale = 10^5,
alpha = 0.05,
print.AOV = TRUE )
data |
Data frame with (at least) variables, A (age),
P (period), D (cases, deaths) and Y
(person-years). Cohort (date of birth) is computed as P-A. |
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. |
ref.c |
reference cohort, numerical. Defaults to median date of birth among cases. |
ref.p |
recerence period, numerical. Defaults to median date of diagnosis among cases. |
model |
Defines the type of model fitted:
|
drift |
How the drift parameter should be extracted from the
age-period-cohort model. weighted (default) lets the
weighted average (by marginal no. cases, D) of the estimated
period and cohort effects have 0 slopw. Holford uses the
naïve average over all values for the estimated effects,
disregarding the no. cases. |
parm |
The parametrization of the effects. The first four all
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, drift is ignored.
Possible values are:
|
npar |
The number of parameters to use for each of the terms in
the model. If fractional polynomials are requested, this can be a
list with up to 6 elements. The first 3 vectors of powers to use for
each of the three terms, the next three the offsets (i.e. using
(x+off)^power). These defaults to 0, and if only one is given the
same is used for all three terms. |
alpha |
The significance level. Estimates are given with
(1-alpha) confidence limits. |
scale |
numeric(1), factor multiplied to the rate estimates before output. |
print.AOV |
Should the analysis of deviance table for the models be printed? |
An object of class "apc" (recognized by apc.lines) —
a list with 7 components:
Age |
Matrix with 4 colums: A.pt with the ages (equals
unique(A)) and three columns giving the estimated rates with
c.i.s. |
Per |
Matrix with 4 colums: P.pt with the dates of
diagnosis (equals unique(P)) and three columns giving the
estimated RRs with c.i.s. |
Coh |
Matrix with 4 colums: C.pt with the dates of birth
(equals unique(P-A)) and three columns giving the estimated
RRs with c.i.s. |
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 drift), the
second row is the estimate from the Age-drift model. For the
sequential parametrizations, only the latter is given. |
Ref |
Numerical vector of length 2 with reference period and cohort. |
AOV |
Analysis of deviance table comparing the five classical models. |
Type |
Character string explaining the model and the parametrization. |
Bendix Carstensen, http://www.pubhealth.ku.dk/~bxc
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", drift="Holford", parm="ACP", scale=10^5 )
ex.W <- apc.fit( exd, npar=7, model="ns", drift="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"]]
# First nice plot frame
par( mar=c(3,4,1,4), mgp=c(3,1,0)/1.5, las=1 )
sc <- apc.frame(a.lab = seq( 30, 90, 20 ),
a.tic = seq( 30, 90, 10 ),
cp.lab = seq( 1860, 2000, 20 ),
cp.tic = seq( 1860, 2000, 10 ),
r.lab = c(1,2,5,10,20,50)*10,
r.tic = c(1:9*10, 1:5*100),
rr.ref = 200,
gap = 22 )
# Reference lines
abline( v=ex.H[[5]][2]-sc[1] )
segments( 1860-sc[1], sc[2], 2000-sc[1], sc[2] )
# Fill in the estimated effects
apc.lines( ex.S, col="green", scale="rates", frame.par=sc, ci=TRUE )
apc.lines( ex.H, col="red", scale="rates", frame.par=sc, ci=TRUE )
apc.lines( ex.W, col="blue", scale="rates", frame.par=sc, ci=TRUE )
# Extract the drifts in % per year
rd <- formatC( (ex.W[["Drift"]]["A-d",]-1)*100, format="f", digits=2 )
wd <- formatC( (ex.W[["Drift"]]["APC",]-1)*100, format="f", digits=2 )
hd <- formatC( (ex.H[["Drift"]]["APC",]-1)*100, format="f", digits=2 )
# Put them on the plot
text( 1999-sc[1], 11,
paste( "Weighted drift:", wd[1], "(", wd[2], "-", wd[3], ") %/year" ),
col="blue", adj=c(1,0), font=2, cex=0.8 )
text( 1999-sc[1], 11*1.2,
paste( "Naïve drift:", hd[1], "(", hd[2], "-", hd[3], ") %/year" ),
col="red", adj=c(1,0), font=2, cex=0.8 )
text( 1999-sc[1], 11*1.2^2,
paste( "Raw drift:", rd[1], "(", rd[2], "-", rd[3], ") %/year" ),
col="green", adj=c(1,0), font=2, cex=0.8 )