dear Lucas,
If you are interested in selecting the number of breakpoints here a
possible remedy:
1. Fit a segmented model with a large number of breakpoints via the
arguments psi=NA and stop.if.error=FALSE in seg.control() (see the
example below)
2. extract the "model matrix" relevant to the variables of the breakpoints
3. Use lars with the extracted model matrix
Notice that there are at least two issues that I did not mention:
a) The criterion to be used to select the variables (i.e the breakpoints)
b) When you remove variables (i.e. breakpoints) you are assuming that
the ML estimate of the remaining breakpoints is the same (and this is
not the case here, as point estimates of the breakpoints depend on the
number of breakpoints themselves..)
vito
###Here a simple example
n=100
xx<-1:n/n
psi0<-seq(.2,.8,by=.2)
X<-sapply(c(0,psi0), function(x)pmax(xx-x,0))
b<-c(-.6,.7,.4,-1,.5)
mu<-drop(X%*%b)
yy<-mu+rnorm(n)*.01
plot(xx,mu);lines(xx, mu)
library(segmented)
o<-lm(yy~xx)
os<-segmented(o,seg.Z=~xx,psi=NA,control=seg.control(stop.if.error=FALSE,K=30,
n.boot=0))
plot(os, add=T, col=2) #have a look to results
#extract the new model matrix
new.X<-model.matrix(os)[,os$nameUV$U]
#finally use lars on y~new.X
Hope this helps you,
vito
Il 06/06/2012 15.48, Lucas Santana dos Santos ha scritto:
Hi Vito,
I am more interested in selecting the number of breakpoints. My data has some
structure and I believe that fitting a piecewise regression would be of great
benefit.
Thanks,
Lucas
On Jun 6, 2012, at 4:54 AM, Vito Muggeo (UniPa) wrote:
dear lucas,
yes you are right, segmented does not handle 'lars' objects.
Out of curisity, are you interested in selecting the number of breakpoints or
in selecting additional covariates with linear parameters?
vito
Il 06/06/2012 0.01, Lucas Santana dos Santos ha scritto:
Hi All,
I am trying to fit a piecewise lasso regression, but package Segmented does not
work with Lars objects.
Does any know of any package or implementation of piecewise lasso regression?
Thanks,
Lucas
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
--
====================================
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726
http://dssm.unipa.it/vmuggeo
====================================
--
====================================
Vito M.R. Muggeo
Dip.to Sc Statist e Matem `Vianelli'
Università di Palermo
viale delle Scienze, edificio 13
90128 Palermo - ITALY
tel: 091 23895240
fax: 091 485726
http://dssm.unipa.it/vmuggeo
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.