[R] Piecewise regression using lme()
goulvenS
goulven.salic at edf.fr
Wed Jul 21 15:37:57 CEST 2010
Hi everyone,
I'm trying to fit a of piecewise regression model on a time series. The idea
is to divide the series into segments and then to apply linear regression
models on each segment but in a "global way" and considering
heteroskedasticity between the segments. For example, I build a time series
y with 3 segments:
segment1=1:20+rnorm(20,0,2)
segment2=20-2*1:30+rnorm(30,0,5)
segment3=-40+0.5*1:15+rnorm(15,0,1)
group=c(rep(1,20),rep(2,30),rep(3,15))
y=c(segment1,segment2,segment3)
Data=data.frame(y,t=1:65,group=as.factor(group))
the model I'd like to fit is:
y_t=
(beta_01+beta_11*t+error_1)*(group==1)+(beta_02+beta_12*t+error_2)*(group==2)+(beta_03+beta_13*t+error_3)*(group==3)
It looks like a mixed effects model were the fixed effect are the piecewise
linear regression parts (beta_0i+beta_1i*t) and the random effects are the
variance components error_i.
The problem is that I can't find the way the write this model correctly
using the lme() function of the package nlme. I can't remove the global
intercept and the global variance component. Here's what I tried:
#1 Using a prior piecewise linear regression
lm.list=lmList(y~t|group,Data)
model.lme=lme(lm.list,weights=varIdent(form=~1|group))
#2 Trying to estimate the whole model directly and considering the different
lines as random effects
model.lme=lme(y~1,random=~t|group,data=Data)
but the intercept remains...
I read a lot of R-help messages before posting this one (my first!) and I'm
not getting any closer. It looks like no one tried to estimate the exact
same model. I'll be very grateful if someone could help me on this.
Thanks
Goulven
--
View this message in context: http://r.789695.n4.nabble.com/Piecewise-regression-using-lme-tp2297118p2297118.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list