Learn R Programming

Epi (version 0.7.0)

apc.fit: Fit an Age-Period-Cohort model to tabular data.

Description

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. There are no assumtions 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.

Usage

apc.fit( data,
            A,
            P,
            D,
            Y,
        ref.c,
        ref.p,
         model = c("ns","bs","ls","factor"),
       dr.extr = c("weighted","Holford"),
          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 )

Arguments

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. If used with parm="AdCP" or parm="AdPC", the resdiual cohort effects will be 1 at ref.c
ref.p
reference period, numerical. Defaults to median date of diagnosis among cases.
model
Type of model fitted:
  • bsfits a model with B-splines for each of the terms, withnparparameters for the terms.
  • nsfits a model with natural splines for each of the terms
dr.extr
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. H
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
npar
The number of parameters to use for each of the terms in the model. It can be a list of three numerical vectors, in which case these taken as the knots for the age, period and cohort effect, the first and last element in each vector are use
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?

Value

  • An object of class "apc" (recognized by apc.lines and apc.plot) --- a list with components:
  • AgeMatrix with 4 colums: A.pt with the ages (equals unique(A)) and three columns giving the estimated rates with c.i.s.
  • PerMatrix with 4 colums: P.pt with the dates of diagnosis (equals unique(P)) and three columns giving the estimated RRs with c.i.s.
  • CohMatrix 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.
  • DriftA 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.
  • RefNumerical vector of length 2 with reference period and cohort. If ref.p or ref.c was not supplied the corresponding element is NA.
  • AOVAnalysis of deviance table comparing the five classical models.
  • TypeCharacter string explaining the model and the parametrization.
  • KnotsIf model is one of "ns" or "bs", a list with three components: Age, Per, Coh, each one a vector of knots. The max and the min are the boundary knots.
  • PowersIf model is "fpol", a list with three components: Age, Per, Coh, each one a vector of the powers used in the fractional polynomials.

References

The considerations behind the parametrizations used in this function are given in details in a preprint from Department of Biostatistics in Copenhagen: http://www.pubhealth.ku.dk/bs/publikationer/rr-06-1.pdf.

See Also

apc.frame, apc.lines, apc.plot.

Examples

Run this code
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