apc.indiv.est.model {apc} | R Documentation |
The function apc.indiv.est.model
is used to estimate any of:
the APC model, any APC submodel, or the time-saturated model. To estimate
the APC model or a submodel, it calls apc.indiv.design.collinear
,
apc.indiv.design.model
, and apc.indiv.fit.model
in that order.
To estimate the time-saturated (TS) model it calls either
apc.indiv.estimate.TS
or apc.indiv.logit.TS
, depending on the
selected model.family
. These functions can also be called directly by
the user.
apc.indiv.est.model(data, unit = 1, model.design = "APC", dep.var = NULL, covariates = NULL, model.family = NULL, n.coh.excl.start = 0, n.coh.excl.end = 0, n.per.excl.start = 0, n.per.excl.end = 0, n.age.excl.start = 0, n.age.excl.end = 0, NR.controls = NULL, existing.collinear = NULL, existing.design = NULL) apc.indiv.design.collinear(data, unit = 1, n.coh.excl.start = 0, n.coh.excl.end = 0, n.per.excl.start = 0, n.per.excl.end = 0, n.age.excl.start = 0, n.age.excl.end = 0) apc.indiv.design.model(apc.indiv.design.collinear, model.design = "APC", dep.var = NULL, covariates = NULL) apc.indiv.fit.model(apc.indiv.design.model, model.family = NULL, DV = NULL) apc.indiv.estimate.TS(data, dep.var, covariates = NULL) apc.indiv.logit.TS(data, dep.var, covariates = NULL, maxit.loop = 10, maxit.linesearch = 30, tolerance = 0.002, init = "ols", inv.tol = NULL, d1.tol = 0.002, custom.kappa = NULL,custom.zeta = NULL)
data |
The data.frame in use |
unit |
The interval at which age, period, and cohort are recorded (must be the same for each). Default 1. |
n.coh.excl.start |
If any cohorts have been censored (AP data only). Default 0. |
n.coh.excl.end |
If any cohorts have been censored (AP data only). Default 0. |
n.per.excl.start |
If any periods have been censored (AC data only). Default 0. |
n.per.excl.end |
If any periods have been censored (AC data only). Default 0. |
n.age.excl.start |
If any ages have been censored (PC data only). Default 0. |
n.age.excl.end |
If any ages have been censored (PC data only). Default 0. |
model.design |
The name of the model to be estimated. One of "TS", "APC", "AC", etc. |
dep.var |
The name of the dependent variable as it appears in the data |
DV |
apc.indiv.fit.model only. Optional. Vector containing dependent variable. |
covariates |
A vector of the names of covariates as they appear in the data. Default NULL. |
model.family |
Either "gaussian" or "binomial" |
NR.controls |
Optional list to modify aspects of the Newton-Rhapson iteration for binomial TS model. |
existing.collinear |
Optional specify the output of apc.indiv.design.collinear, if already run. |
existing.design |
Optional specify the output of apc.indiv.design.model, if already run. |
maxit.loop |
Optional. Maximum number Newton-Rhapson iterations. Default 10. |
maxit.linesearch |
Optional. Maximum number linesearch iterations. Default 20. |
tolerance |
Optional. Difference between previous and updated likelihoods to be tolerated in Newton-Rhapson iteration. |
init |
Optional. Starting values for Newton-Rhapson. One of "zero", "ols", "custom". Default "ols". |
inv.tol |
Optional. Tolerance of small values when inverting a matrix
(using |
d1.tol |
Optional. Magnitude of norm of first derivative to be tolerated in Newton-Rhapson iteration. |
custom.kappa |
Optional. User-specified starting values for |
custom.zeta |
Optional. User-specified starting values for |
apc.indiv.design.collinear |
Output from the command
|
apc.indiv.design.model |
Output from the command
|
The casual user should start with the general function
apc.indiv.est.model
for analysis. The underlying functions should be
employed if the user needs to run many models using the same relatively large
dataset, in which case time can be saved by running
apc.indiv.design.collinear
just once and using
apc.indiv.design.model
and apc.indiv.fit.model
to estimate
each of the models.
coefficients |
Vector of point estimates of all coefficients. |
coefficients.canonical |
Matrix of estimates, standard error, etc of canonical parameter. |
coefficients.covariates |
Matrix of estimates, standard error, etc of covariates. |
fitted.values |
Vector of fitted values from model as estimated. |
residuals |
Vector of residuals from model as estimated. |
linear.predictors |
Vector of fitted values from model as estimated. |
deviance |
model deviance from glm.fit. |
aic |
model Akaike information criterion from glm.fit. |
null.deviance |
model null deviance from glm.fit. |
y |
vector of the outcome variable. |
likelihood |
model likelihood. |
model.design |
which APC submodel has been estimated. |
structure.design.collinear |
from apc.indiv.design.collinear only. A matrix indicating the age-period-cohort design for any age-cohort cell in the data. |
full.design.collinear |
from apc.indiv.design.collinear only. The collinear design matrix. |
full.design |
from apc.indiv.design.model only. The design matrix used to estimate the model. |
Zoe Fannon <zoe.fannon@economics.ox.ac.uk> 26 Aug 2018
Fannon, Z. (2018) apc.indiv
: R tools to estimate age-period-cohort models with
repeated cross section data. Mimeo. University of Oxford.
Fannon, Z., Monden, C. and Nielsen, B. (2018) Age-period-cohort modelling and covariates, with an application to obesity in England 2001-2014. Mimeo. University of Oxford.
The example below uses data from the NHIS,
see data.NHIS.sample
data("data.NHIS.sample") ## Get appropriate data formats # Age-cohort AC_sub <- data.NHIS.sample[data.NHIS.sample$age>=40 & data.NHIS.sample$age<=47 & data.NHIS.sample$cohort>=1961 & data.NHIS.sample$cohort<=1967,] # Age-cohort triangular AC_tri_sub <- data.NHIS.sample[data.NHIS.sample$age>=44 & data.NHIS.sample$age<=53 & data.NHIS.sample$cohort>=1961 & data.NHIS.sample$cohort<=1974,] # Period-cohort PC_sub <- data.NHIS.sample[data.NHIS.sample$cohort>=1961 & data.NHIS.sample$cohort<=1968 & data.NHIS.sample$period>=2008,] # Age-period AP_sub <- data.NHIS.sample[data.NHIS.sample$age<=48 & data.NHIS.sample$age>=40 & data.NHIS.sample$period<=2010 & data.NHIS.sample$period>=2003,] # Age-period with early and late cohorts dropped AP_cc_sub <- AP_sub[!AP_sub$cohort %in% c(1955, 1956, 1957, 1970, 1969, 1968),] ## Estimate models # Gaussian model, age-cohort triangular data, no covariates M1 <- apc.indiv.est.model(AC_tri_sub, dep.var = "Lbmi", model.family = "gaussian") # Binomial model, period-cohort data, no covariates, age-drift sub-model M2 <- apc.indiv.est.model(PC_sub, dep.var = "obese", model.family = "binomial", model.design = "Ad") # Gaussian model, period-cohort data, three covariates, trend submodel # (note: this is the model selected by the table, see example in # help for apc.indiv.model.table) M3 <- apc.indiv.est.model(PC_sub, dep.var = "Lbmi", covariates = c("daysbed", "nowsmoke", "eversmoke"), model.family = "gaussian", model.design = "t") # Gaussian model, age-period data, one covariate, # time-saturated model M4 <- apc.indiv.est.model(AP_sub, dep.var = "Lbmi", covariates = c("daysbed"), model.family="gaussian", model.design = "TS") # Binomial model, age-period cohort-cut data, no covariates, # time-saturated model M5 <- apc.indiv.est.model(AP_cc_sub, dep.var = "obese", model.family = "binomial", model.design = "TS", n.coh.excl.start = 3, n.coh.excl.end = 3) # Binomial model, age-period cohort-cut data, one covariate, # time-saturated model, specification of controls on Newton-Rhapson # procedure myspec1 <- list(8) names(myspec1) <- c("maxit.loop") M8 <- apc.indiv.est.model(AP_cc_sub, dep.var = "obese", model.family = "binomial", covariates = c("daysbed"), model.design = "TS", n.coh.excl.start = 3, n.coh.excl.end = 3, NR.controls = myspec1) # Binomial model using underlying functions, two models shown using # the same collinear design matrix but different outcome variables, # covariates, and specifications raw3.collinear <- apc.indiv.design.collinear(AP_sub) raw3.model <- apc.indiv.design.model(raw3.collinear, dep.var= "Lbmi", covariates = c("daysbed", "nowsmoke", "eversmoke")) raw3.fit <- apc.indiv.fit.model(raw3.model,model.family = "gaussian") raw3.model2 <- apc.indiv.design.model(raw3.collinear, dep.var="obese", model.design="AP") raw3.fit2 <- apc.indiv.fit.model(raw3.model2, model.family = "binomial")