Title: | Joint Mean-Covariance Models using 'Armadillo' and S4 |
---|---|
Description: | Fit joint mean-covariance models for longitudinal data. The models and their components are represented using S4 classes and methods. The core computational algorithms are implemented using the 'Armadillo' C++ library for numerical linear algebra and 'RcppArmadillo' glue. |
Authors: | Jianxin Pan [aut, cre], Yi Pan [aut] |
Maintainer: | Jianxin Pan <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.2.4 |
Built: | 2024-11-16 06:49:50 UTC |
Source: | CRAN |
Fit joint mean-covariance models based on ACD.
acd_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
acd_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
m |
an integer vector of numbers of measurements for subject. |
Y |
a vector of responses for all subjects. |
X |
model matrix for the mean structure model. |
Z |
model matrix for the diagonal matrix. |
W |
model matrix for the lower triangular matrix. |
start |
starting values for the parameters in the model. |
mean |
when covonly is true, it is used as the given mean. |
trace |
the values of the objective function and the parameters are printed for all the trace'th iterations. |
profile |
whether parameters should be estimated sequentially using the idea of profile likelihood or not. |
errormsg |
whether or not the error message should be print. |
covonly |
estimate the covariance structure only, and use given mean. |
optim_method |
optimization method, choose "default" or "BFGS"(vmmin in R). |
mcd_estimation
for joint mean covariance model fitting
based on MCD, hpc_estimation
for joint mean covariance
model fitting based on HPC.
The aids dataset comprises a total of 2376 CD4+ cell counts for 369 HIV infected men with a follow up period of approximately eight and half year. The number of measurements for each individual varies from 1 to 12 and the times are not equally spaced. The CD4+ cell data are highly unbalanced.
data(aids)
data(aids)
A data frame with 2376 rows and 8 variables
id: subject id
time: measurement time
cd4: CD4+ cell count
Plot fitted curves and corresponding 95% confidence interval using bootstrapping method.
bootcurve(object, nboot)
bootcurve(object, nboot)
object |
a fitted joint mean covariance model of class "jmcmMod", i.e., typically the result of jmcm(). |
nboot |
number of the bootstrap replications. |
## Not run: # It may take hours for large bootstrap replications fit.mcd <- jmcm(I(sqrt(cd4)) | id | time ~ 1 | 1, data=aids, triple = c(8, 1, 3), cov.method = 'mcd', control = jmcmControl(trace=T)) bootcurve(fit.mcd, nboot = 1000) ## End(Not run)
## Not run: # It may take hours for large bootstrap replications fit.mcd <- jmcm(I(sqrt(cd4)) | id | time ~ 1 | 1, data=aids, triple = c(8, 1, 3), cov.method = 'mcd', control = jmcmControl(trace=T)) bootcurve(fit.mcd, nboot = 1000) ## End(Not run)
Kenward (1987) reported an experiment in which cattle were assigned randomly to two treatment groups A and B, and their body weights were recorded in kilogram. Thirty animals received treatment A and another 30 received treatment B. The animals were weighted 11 times over a 133-day period; the first 10 measurements for each animal were made at two-week intervals and the last measurement was made one week later. Since no observation was missing, it is considered to be a balanced longitudinal dataset.
data(cattle)
data(cattle)
A data frame with 660 rows and 4 variables
id: subject id
day: measurement time
group: Treatment A or Treatment B
weight: cattle weight
Extract (or "get") "components" - in a generalized sense - from a fitted joint mean covariance model from an object of class "jmcmMod".
getJMCM(object, name, sub.num) ## S3 method for class 'jmcmMod' getJMCM(object, name = c("m", "Y", "X", "Z", "W", "D", "T", "Sigma", "mu", "n2loglik", "grad", "hess", "theta", "beta", "lambda", "gamma", "loglik", "BIC", "iter", "triple"), sub.num = 0)
getJMCM(object, name, sub.num) ## S3 method for class 'jmcmMod' getJMCM(object, name = c("m", "Y", "X", "Z", "W", "D", "T", "Sigma", "mu", "n2loglik", "grad", "hess", "theta", "beta", "lambda", "gamma", "loglik", "BIC", "iter", "triple"), sub.num = 0)
object |
a fitted joint mean covariance model of class "jmcmMod", i.e., typically the result of jmcm(). |
name |
a character vector specifying the name(s) of the "component". When sub.num is not specified or equal to 0, possible values are:
When sub.num is specified, possible values are:
|
sub.num |
refer to i's subject |
jmcmMod
: Extract or Get Generalized Components from a Fitted Joint
Mean Covariance Model
fit.mcd <- jmcm(I(sqrt(cd4)) | id | time ~ 1 | 1, data = aids, triple = c(8, 1, 3), cov.method = 'mcd') beta <- getJMCM(fit.mcd, "beta") BIC <- getJMCM(fit.mcd, "BIC") Di <- getJMCM(fit.mcd, "D", 10)
fit.mcd <- jmcm(I(sqrt(cd4)) | id | time ~ 1 | 1, data = aids, triple = c(8, 1, 3), cov.method = 'mcd') beta <- getJMCM(fit.mcd, "beta") BIC <- getJMCM(fit.mcd, "BIC") Di <- getJMCM(fit.mcd, "D", 10)
Fit joint mean-covariance models based on HPC.
hpc_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
hpc_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
m |
an integer vector of numbers of measurements for subject. |
Y |
a vector of responses for all subjects. |
X |
model matrix for the mean structure model. |
Z |
model matrix for the diagonal matrix. |
W |
model matrix for the lower triangular matrix. |
start |
starting values for the parameters in the model. |
mean |
when covonly is true, it is used as the given mean. |
trace |
the values of the objective function and the parameters are printed for all the trace'th iterations. |
profile |
whether parameters should be estimated sequentially using the idea of profile likelihood or not. |
errormsg |
whether or not the error message should be print. |
covonly |
estimate the covariance structure only, and use given mean. |
optim_method |
optimization method, choose "default" or "BFGS"(vmmin in R). |
mcd_estimation
for joint mean covariance model fitting
based on MCD, acd_estimation
for joint mean covariance
model fitting based on ACD.
Fit a joint mean-covariance model to longitudinal data, via maximum likelihood.
jmcm(formula, data = NULL, triple = c(3, 3, 3), cov.method = c("mcd", "acd", "hpc"), optim.method = c("default", "BFGS"), control = jmcmControl(), start = NULL)
jmcm(formula, data = NULL, triple = c(3, 3, 3), cov.method = c("mcd", "acd", "hpc"), optim.method = c("default", "BFGS"), control = jmcmControl(), start = NULL)
formula |
a two-sided linear formula object describing the covariates for both the mean and covariance matrix part of the model, with the response, the corresponding subject id and measurement time on the left of a operator~, divided by vertical bars ("|"). |
data |
a data frame containing the variables named in formula. |
triple |
an integer vector of length three containing the degrees of the three polynomial functions for the mean structure, the log innovation -variances and the autoregressive or moving average coefficients when 'mcd' or 'acd' is specified for cov.method. It refers to the degree for the mean structure, variances and angles when 'hpc' is specified for cov.method. |
cov.method |
covariance structure modelling method, choose 'mcd' (Pourahmadi 1999), 'acd' (Chen and Dunson 2013) or 'hpc' (Zhang et al. 2015). |
optim.method |
optimization method, choose 'default' or 'BFGS' (vmmin in R) |
control |
a list (of correct class, resulting from jmcmControl()) containing control parameters, see the *jmcmControl documentation for details. |
start |
starting values for the parameters in the model. |
Pan J, Pan Y (2017). "jmcm: An R Package for Joint Mean-Covariance Modeling of Longitudinal Data." Journal of Statistical Software, 82(9), 1–29.
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 4, 3), cov.method = 'mcd', control = jmcmControl(trace = TRUE, ignore.const.term = FALSE, original.poly.order = TRUE))
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 4, 3), cov.method = 'mcd', control = jmcmControl(trace = TRUE, ignore.const.term = FALSE, original.poly.order = TRUE))
Construct control structures for joint mean covariance model fitting
jmcmControl(trace = FALSE, profile = TRUE, ignore.const.term = TRUE, original.poly.order = FALSE, errormsg = FALSE)
jmcmControl(trace = FALSE, profile = TRUE, ignore.const.term = TRUE, original.poly.order = FALSE, errormsg = FALSE)
trace |
whether or not the value of the objective function and the parameters should be print on every trace'th iteration. |
profile |
whether or not parameters should be estimated sequentially using the idea of profile likelihood. |
ignore.const.term |
whether or not the constant term should be considered when calculating log-likelihood and BIC. function |
original.poly.order |
whether or not the original poly order p q d should be used |
errormsg |
whether or not the error message should be print |
Class "jmcmMod" of Fitted Joint Mean-Covariance Models.
call
the matched call
opt
the optimization result returned by optimizeJmcm
args
arguments m, Y, X, Z, W, time
triple
an integer vector of length three containing the degrees of the three polynomial functions for the mean structure, the log innovation -variances and the autoregressive or moving average coefficients when 'mcd' or 'acd' is specified for cov.method. It refers to the mean structure, variances and angles when 'hpc' is specified for cov.method.
devcomp
the deviance components list
Fit joint mean-covariance models based on MCD.
mcd_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
mcd_estimation(m, Y, X, Z, W, start, mean, trace = FALSE, profile = TRUE, errormsg = FALSE, covonly = FALSE, optim_method = "default")
m |
an integer vector of numbers of measurements for subject. |
Y |
a vector of responses for all subjects. |
X |
model matrix for the mean structure model. |
Z |
model matrix for the diagonal matrix. |
W |
model matrix for the lower triangular matrix. |
start |
starting values for the parameters in the model. |
mean |
when covonly is true, it is used as the given mean. |
trace |
the values of the objective function and the parameters are printed for all the trace'th iterations. |
profile |
whether parameters should be estimated sequentially using the idea of profile likelihood or not. |
errormsg |
whether or not the error message should be print. |
covonly |
estimate the covariance structure only, and use given mean. |
optim_method |
optimization method, choose "default" or "BFGS"(vmmin in R). |
acd_estimation
for joint mean covariance model fitting
based on ACD, hpc_estimation
for joint mean covariance
model fitting based on HPC.
plot fitted mean curves
meanplot(object)
meanplot(object)
object |
a fitted joint mean covariance model of class "jmcmMod", i.e., typically the result of jmcm(). |
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 3, 4), cov.method = 'mcd') meanplot(fit.mcd)
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 3, 4), cov.method = 'mcd') meanplot(fit.mcd)
Modular Functions for joint mean covariance model fits
ldFormula(formula, data = NULL, triple = c(3, 3, 3), cov.method = c("mcd", "acd", "hpc"), optim.method = c("default", "BFGS"), control = jmcmControl(), start = NULL) optimizeJmcm(m, Y, X, Z, W, time, cov.method, optim.method, control, start) mkJmcmMod(opt, args, triple, cov.method, optim.method, mc)
ldFormula(formula, data = NULL, triple = c(3, 3, 3), cov.method = c("mcd", "acd", "hpc"), optim.method = c("default", "BFGS"), control = jmcmControl(), start = NULL) optimizeJmcm(m, Y, X, Z, W, time, cov.method, optim.method, control, start) mkJmcmMod(opt, args, triple, cov.method, optim.method, mc)
formula |
a two-sided linear formula object describing the covariates for both the mean and covariance matrix part of the model, with the response, the corresponding subject id and measurement time on the left of a operator~, divided by vertical bars ("|"). |
data |
a data frame containing the variables named in formula. |
triple |
an integer vector of length three containing the degrees of the three polynomial functions for the mean structure, the log innovation -variances and the autoregressive or moving average coefficients when 'mcd' or 'acd' is specified for cov.method. It refers to the degree for the mean structure, variances and angles when 'hpc' is specified for cov.method. |
cov.method |
covariance structure modelling method, choose 'mcd' (Pourahmadi 1999), 'acd' (Chen and Dunson 2013) or 'hpc' (Zhang et al. 2015). |
optim.method |
optimization method, choose 'default' or 'BFGS' (vmmin in R) |
control |
a list (of correct class, resulting from jmcmControl()) containing control parameters, see the *jmcmControl documentation for details. |
start |
starting values for the parameters in the model. |
m |
an integer vector of number of measurements for each subject. |
Y |
a vector of responses for all subjects. |
X |
model matrix for mean structure model. |
Z |
model matrix for the diagonal matrix. |
W |
model matrix for the lower triangular matrix. |
time |
a vector of time from the data. |
opt |
optimized results returned by optimizeJmcm. |
args |
arguments returned by ldFormula. |
mc |
matched call from the calling function. |
Plot the sample regressograms based on the sample covariance matrix and superimpose the corresponding fitted curves to check the model fitting when the longitudinal dataset is balanced.
regressogram(object, time)
regressogram(object, time)
object |
a fitted joint mean covariance model of class "jmcmMod", i.e., typically the result of jmcm(). |
time |
a vector of obeservation time points |
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 3, 4), cov.method = 'mcd') regressogram(fit.mcd, time = 1:11)
cattleA <- cattle[cattle$group=='A', ] fit.mcd <- jmcm(weight | id | I(ceiling(day/14 + 1)) ~ 1 | 1, data=cattleA, triple = c(8, 3, 4), cov.method = 'mcd') regressogram(fit.mcd, time = 1:11)
Print information for jmcmMod-class
## S4 method for signature 'jmcmMod' show(object)
## S4 method for signature 'jmcmMod' show(object)
object |
a fitted joint mean covariance model of class "jmcmMod", i.e., typically the result of jmcm(). |