View source: R/segmented.lme.r
segmented.lme | R Documentation |
Fits linear mixed models with a segmented relationship between the response and a numeric covariate. Random effects are allowed in each model parameter, including the breakpoint.
## S3 method for class 'lme'
segmented(obj, seg.Z, psi, npsi = 1, fixed.psi = NULL,
control = seg.control(), model = TRUE,
z.psi = ~1, x.diff = ~1, random = NULL,
random.noG = NULL, start.pd = NULL, psi.link = c("identity", "logit"),
start = NULL, data, fixed.parms = NULL,...)
obj |
A 'lme' fit returned by |
seg.Z |
A one-sided formula indicating the segmented variable, i.e. the quantitative variable having a segmented relationship with the response. In longitudinal studies typically it is the time. |
psi |
An optional starting value for the breakpoint. If missing a starting value is obtained via the nadir estimate of a quadratic fit. When provided it may be a single numeric value or a vector of length equal to the number of clusters (i.e. subjects). |
z.psi |
Optional. A one-sided formula meaning the covariates in the sub-regression model for the changepoint parameter. Default to |
x.diff |
Optional. A one-sided formula meaning the covariates in the sub-regression model for the difference-in-slopes parameter.
Default to |
npsi |
Ignored. Currently only |
fixed.psi |
Ignored. |
control |
A list returned by |
model |
Ignored. |
random |
A list, as the one supplied in
|
random.noG |
Ignored. |
start.pd |
An optional starting value for the variances of the random effects. It should be coherent with the
specification in |
psi.link |
The link function used to specify the sub-regression model for the breakpoint
while the logit link is
where |
start |
An optional list including the starting values for the difference-in-slopes parameter, delta0 and delta, and the changepoint parameter, kappa and kappa0. When provided, 'kappa0' overwrites 'psi'. If provided, the components 'delta' and 'kappa' should be named vectors with length and names
matching length and names in |
data |
the dataframe where the variables are stored. If missing, the dataframe of the |
fixed.parms |
An optional named vector representing the coefficients of the changepoint to be maintained fixed
during the estimation process. Allowed names are "G0" or any variable (in the dataframe) supposed to
affect the location of breakpoints.
For instance |
... |
Ignored |
The function fits segmented mixed regression models, i.e. segmented models with random effects also in the slope-difference and change-point parameters.
A list of class segmented.lme
with several components. The most relevant are
lme.fit |
The fitted lme object at convergence |
lme.fit.noG |
The fitted lme object at convergence assuming known the breakpoints |
psi.i |
The subject/cluster-specific change points (fixed + random). It includes 2 attributes: |
fixed.eta.psi |
The fixed-effect linear predictor for the change points regression equation. These values will different among 'clusters' only if at least one covariate has been specified in |
fixed.eta.delta |
The fixed-effect linear predictor of the slope difference regression equation. These values will different among 'clusters' only if at least one covariate has been specified in |
The function deals with estimation with a single breakpoint only.
Currently only one breakpoint (with or without random effects) can be estimated. If fit
is the segmented.lme fit, use VarCorr(fit$lme.fit)
to extract the random effect covariance matrix.
Vito M.R. Muggeo vito.muggeo@unipa.it
Muggeo V., Atkins D.C., Gallop R.J., Dimidjian S. (2014) Segmented mixed models with random changepoints: a maximum likelihood approach with application to treatment for depression study. Statistical Modelling, 14, 293-313.
Muggeo V. (2016) Segmented mixed models with random changepoints in R. Working paper available on RG. doi: 10.13140/RG.2.1.4180.8402
plot.segmented.lme
for the plotting method and segmented.default
(example 2) for segmented models with no random effects in breakpoints or slope difference.
## Not run:
library(nlme)
data(Cefamandole)
Cefamandole$lTime <-log(Cefamandole$Time)
Cefamandole$lconc <-log(Cefamandole$conc)
o<-lme(lconc ~ lTime, random=~1|Subject, data=Cefamandole)
os<-segmented.lme(o, ~lTime, random=list(Subject=pdDiag(~1+lTime+U+G0)),
control=seg.control(n.boot=0, display=TRUE))
slope(os)
####################################################
# covariate effect on the changepoint and slope diff
#let's assume a new subject-specific covariates..
set.seed(69)
Cefamandole$z <- rep(runif(6), rep(14,6))
Cefamandole$group <- gl(2,42,labels=c('a','b'))
#Here 'group' affects the slopes and 'z' affects the changepoint
o1 <-lme(lconc ~ lTime*group, random=~1|Subject, data=Cefamandole)
os1 <- segmented(o1, ~lTime, x.diff=~group, z.psi=~z,
random=list(Subject=pdDiag(~1+lTime+U+G0)))
slope(os1, by=list(group="a")) #the slope estimates in group="a" (baseline level)
slope(os1, by=list(group="b")) #the slope estimates in group="b"
###################################################
# A somewhat "complicated" example:
# i) strong heterogeneity in the changepoints
# ii) No changepoint for the Subject #7 (added)
d<-Cefamandole
d$x<- d$lTime
d$x[d$Subject==1]<- d$lTime[d$Subject==1]+3
d$x[d$Subject==5]<- d$lTime[d$Subject==5]+5
d$x[d$Subject==3]<- d$lTime[d$Subject==3]-5
d<-rbind(d, d[71:76,])
d$Subject <- factor(d$Subject, levels=c(levels(d$Subject),"7"))
d$Subject[85:90] <- rep("7",6)
o<-lme(lconc ~ x, random=~1|Subject, data=d)
os2<-segmented.lme(o, ~x, random=list(Subject=pdDiag(~1+x+U+G0)),
control=seg.control(n.boot=5, display=TRUE))
#plots with common x- and y- scales (to note heterogeneity in the changepoints)
plot(os2, n.plot = c(3,3))
os2$psi.i
attr(os2$psi.i, "is.break") #it is FALSE for Subject #7
#plots with subject-specific scales
plot(os2, n.plot = c(3,3), xscale=-1, yscale = -1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.