kalseries  R Documentation 
kalseries
is designed to handle repeated measurements models with
timevarying covariates. The distributions have two extra parameters as
compared to the functions specified by intensity
and are generally
longer tailed than those distributions. Dependence among observations on a
unit can be through gamma or power variance family frailties (a type of
random effect), with or without autoregression, or one of two types of
serial dependence over time.
kalseries(
response = NULL,
times = NULL,
intensity = "exponential",
depend = "independence",
mu = NULL,
shape = NULL,
density = FALSE,
ccov = NULL,
tvcov = NULL,
torder = 0,
interaction = NULL,
preg = NULL,
ptvc = NULL,
pintercept = NULL,
pshape = NULL,
pinitial = 1,
pdepend = NULL,
pfamily = NULL,
delta = NULL,
transform = "identity",
link = "identity",
envir = parent.frame(),
print.level = 0,
ndigit = 10,
gradtol = 1e05,
steptol = 1e05,
fscale = 1,
iterlim = 100,
typsize = abs(p),
stepmax = 10 * sqrt(p %*% p)
)
response 
A list of two column matrices with responses and
corresponding times for each individual, one matrix or dataframe of
response values, or an object of class, 
times 
When response is a matrix, a vector of possibly unequally
spaced times when they are the same for all individuals or a matrix of
times. Not necessary if equally spaced. Ignored if response has class,

intensity 
The form of function to be put in the Pareto distribution. Choices are exponential, Weibull, gamma, normal, logistic, Cauchy, log normal, log logistic, log Cauchy, log Student, inverse Gauss, and gen(eralized) logistic. (For definitions of distributions, see the corresponding [dpqr]distribution help.) 
depend 
Type of dependence. Choices are 
mu 
A regression function for the location parameter or a formula
beginning with ~, specifying either a linear regression function in the
Wilkinson and Rogers notation or a general function with named unknown
parameters. Give the initial estimates in 
shape 
A regression function for the shape parameter or a formula beginning with ~, specifying either a linear regression function in the Wilkinson and Rogers notation or a general function with named unknown parameters. It must yield one value per observation. 
density 
If TRUE, the density of the function specified in

ccov 
A vector or matrix containing timeconstant baseline covariates
with one row per individual, a model formula using vectors of the same
size, or an object of class, 
tvcov 
A list of matrices with timevarying covariate values,
observed at the event times in 
torder 
The order of the polynomial in time to be fitted. 
interaction 
Vector of length equal to the number of timeconstant
covariates, giving the levels of interactions between them and the
polynomial in time in the 
preg 
Initial parameter estimates for the regression model:
intercept, one for each covariate in 
ptvc 
Initial parameter estimates for the coefficients of the
timevarying covariates, as many as in 
pintercept 
The initial estimate of the intercept for the generalized logistic intensity. 
pshape 
An initial estimate for the shape parameter of the intensity
function (except exponential intensity). If 
pinitial 
An initial estimate for the initial parameter. With

pdepend 
An initial estimate for the serial dependence parameter. For

pfamily 
An optional initial estimate for the second parameter of a
twoparameter power variance family mixture instead of the default gamma
mixture. This yields a gamma mixture as 
delta 
Scalar or vector giving the unit of measurement for each
response value, set to unity by default. For example, if a response is
measured to two decimals, delta=0.01. If the response has been
pretransformed, this must be multiplied by the Jacobian. This
transformation cannot contain unknown parameters. For example, with a log
transformation, 
transform 
Transformation of the response variable: 
link 
Link function for the mean: 
envir 
Environment in which model formulae are to be interpreted or a
data object of class, 
print.level 
Arguments for nlm. 
ndigit 
Arguments for nlm. 
gradtol 
Arguments for nlm. 
steptol 
Arguments for nlm. 
fscale 
Arguments for nlm. 
iterlim 
Arguments for nlm. 
typsize 
Arguments for nlm. 
stepmax 
Arguments for nlm. 
By default, a gamma mixture of the distribution specified in
intensity
is used, as the conditional distribution in the
Markov
and serial
dependence models, and as a symmetric
multivariate (random effect) model for frailty
dependence. For
example, with a Weibull intensity
and frailty
dependence,
this yields a multivariate Burr distribution and with Markov
or
serial
dependence, univariate Burr conditional distributions.
If a value for pfamily
is used, the gamma mixture is replaced by a
power variance family mixture.
Nonlinear regression models can be supplied as formulae where parameters
are unknowns in which case factor variables cannot be used and parameters
must be scalars. (See finterp
.)
Marginal and individual profiles can be plotted using
mprofile
and iprofile
and
residuals with plot.residuals
.
A list of classes kalseries
and recursive
is
returned.
J.K. Lindsey
treat < c(0,0,1,1)
tr < tcctomat(treat)
dose < matrix(rpois(20,10), ncol=5)
dd < tvctomat(dose)
y < restovec(matrix(rnorm(20), ncol=5), name="y")
reps < rmna(y, ccov=tr, tvcov=dd)
#
# normal intensity, independence model
kalseries(y, intensity="normal", dep="independence", preg=1, pshape=5)
## Not run:
# random effect
kalseries(y, intensity="normal", dep="frailty", preg=1, pinitial=1, psh=5)
# serial dependence
kalseries(y, intensity="normal", dep="serial", preg=1, pinitial=1,
pdep=0.1, psh=5)
# random effect and autoregression
kalseries(y, intensity="normal", dep="frailty", preg=1, pinitial=1,
pdep=0.1, psh=5)
#
# add timeconstant variable
kalseries(y, intensity="normal", dep="serial", pinitial=1,
pdep=0.1, psh=5, preg=c(1,0), ccov=treat)
# or equivalently
kalseries(y, intensity="normal", mu=~treat, dep="serial", pinitial=1,
pdep=0.1, psh=5, preg=c(1,0))
# or
kalseries(y, intensity="normal", mu=~b0+b1*treat, dep="serial",
pinitial=1, pdep=0.1, psh=5, preg=c(1,0), envir=reps)
#
# add timevarying variable
kalseries(y, intensity="normal", dep="serial", pinitial=1, pdep=0.1,
psh=5, preg=c(1,0), ccov=treat, ptvc=0, tvc=dose)
# or equivalently, from the environment
dosev < as.vector(t(dose))
kalseries(y, intensity="normal",
mu=~b0+b1*rep(treat,rep(5,4))+b2*dosev,
dep="serial", pinitial=1, pdep=0.1, psh=5, ptvc=c(1,0,0))
# or from the reps data object
kalseries(y, intensity="normal", mu=~b0+b1*treat+b2*dose,
dep="serial", pinitial=1, pdep=0.1, psh=5, ptvc=c(1,0,0),
envir=reps)
# try power variance family instead of gamma distribution for mixture
kalseries(y, intensity="normal", mu=~b0+b1*treat+b2*dose,
dep="serial", pinitial=1, pdep=0.1, psh=5, ptvc=c(1,0,0),
pfamily=0.1, envir=reps)
# firstorder onecompartment model
# data objects for formulae
dose < c(2,5)
dd < tcctomat(dose)
times < matrix(rep(1:20,2), nrow=2, byrow=TRUE)
tt < tvctomat(times)
# vector covariates for functions
dose < c(rep(2,20),rep(5,20))
times < rep(1:20,2)
# functions
mu < function(p) exp(p[1]p[3])*(dose/(exp(p[1])exp(p[2]))*
(exp(exp(p[2])*times)exp(exp(p[1])*times)))
shape < function(p) exp(p[1]p[2])*times*dose*exp(exp(p[1])*times)
# response
conc < matrix(rgamma(40,shape(log(c(0.01,1))),
scale=mu(log(c(1,0.3,0.2))))/shape(log(c(0.1,0.4))),ncol=20,byrow=TRUE)
conc[,2:20] < conc[,2:20]+0.5*(conc[,1:19]matrix(mu(log(c(1,0.3,0.2))),
ncol=20,byrow=TRUE)[,1:19])
conc < restovec(ifelse(conc>0,conc,0.01))
reps < rmna(conc, ccov=dd, tvcov=tt)
#
# constant shape parameter
kalseries(reps, intensity="gamma", dep="independence", mu=mu,
ptvc=c(1,1.1,1), pshape=1.5)
# or
kalseries(reps, intensity="gamma", dep="independence",
mu=~exp(absorptionvolume)*
dose/(exp(absorption)exp(elimination))*
(exp(exp(elimination)*times)exp(exp(absorption)*times)),
ptvc=list(absorption=1,elimination=1.1,volume=1),
pshape=1.2)
# add serial dependence
kalseries(reps, intensity="gamma", dep="serial", pdep=0.9,
mu=~exp(absorptionvolume)*
dose/(exp(absorption)exp(elimination))*
(exp(exp(elimination)*times)exp(exp(absorption)*times)),
ptvc=list(absorption=1,elimination=1.1,volume=1),
pshape=0.2)
# time dependent shape parameter
kalseries(reps, intensity="gamma", dep="independence", mu=mu,
shape=shape, ptvc=c(1,1.1,1), pshape=c(3,0))
# or
kalseries(reps, intensity="gamma", dep="independence",
mu=~exp(absorptionvolume)*
dose/(exp(absorption)exp(elimination))*
(exp(exp(elimination)*times)exp(exp(absorption)*times)),
ptvc=list(absorption=1,elimination=1.1,volume=1),
shape=~exp(b1b2)*times*dose*exp(exp(b1)*times),
pshape=list(b1=3,b2=0))
# add serial dependence
kalseries(reps, intensity="gamma", dep="serial", pdep=0.5,
mu=~exp(absorptionvolume)*
dose/(exp(absorption)exp(elimination))*
(exp(exp(elimination)*times)exp(exp(absorption)*times)),
ptvc=list(absorption=1,elimination=1.1,volume=1),
shape=~exp(b1b2)*times*dose*exp(exp(b1)*times),
pshape=list(b1=3,b2=0))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.