I Dears,
if that wouldn't take u too much effort I'd like to ask for a swift opinion:

I have a alinear (mixed effect) model that I wish to run as a piecewise one.

When I predict the values Iget quite some odds and disturbing results:
The predicted stright line after the break point is not straight at all,
instead behaves like if it was a hig order polynomial or something
similar!!!!

I attach the codes below, hoping someone can point me the mistake....


I sincerely  express many thanks in advance ......

Federico Bonofiglio


frame3<-data.frame(id,chol,cd4,rt,sex,age,
nadir,pharmac2,hbs,hcv,resp2,
hivbl,switch)

# I run a model specifing the function

(t-t*)+   = 0 if t<=t*

AND

(t-t*)+   = t if t>t*

with the following syntax, emulating MJ Crawley (The R book 2007, Wiley),

#   rt+rt*(rt>15)


I run the model, is a mixed effect one.......

PCWISE<-lme(chol~rt+rt*(rt>15)
+sex+age+cd4+cd4:rt+
cd4:rt*(rt>15)+nadir+hivbl+
pharmac2:rt+resp2:rt+
resp2:rt*(rt>15)+hbs+hcv+
switch,data=frame3,
random= ~rt|id,
 na.action=na.omit)


# I prepare a fictious data.frame for the predictions , in fact lme predict
values inside the clusters
, id in my case, they are patients..
I need instead a population result...


nx<-seq(
min(cd4,na.rm=T),
max(cd4,na.rm=T),
length.out=200)

nt<-seq(
min(rt,na.rm=T),
max(rt,na.rm=T),
length.out=200)



newframe<-data.frame(        #generate a fictious patient's profile
id="48",
cd4=nx,
rt=nt,
sex=rep("M",200),
age=rep(mean(age),200),
nadir=rep(mean(age),200),
pharmac2=rep("PI.boost",200),
resp2=rep("mild",200),
hbs=rep(1,200),
hcv=rep(1,200),
hivbl=rep(mean(hivbl,na.rm=T),200),
switch=rep(1,200))



yy<-predict(PCWISE,level=0,newdata=newframe)   #predict the response


# I plot the predicted values against the observed......

xyplot(chol~rt,
groups=id,
panel=function(x, y){panel.xyplot(x,y)
panel.abline(v=15,col=2,lty=2)
panel.lines(nt,yy,col=2,lwd=2)             # plot the predicted values
panel.axis("top",at=15,labels="15")
})


# I get a quite puzzling result : predictions are not linear!!!! they act
more like they were from a polynomial of high order!!!   for instance after
time 15, (rt>15), I get a line that is not straight, but flexes smoothly
downward!!!!



#Also if I try run the model separetely for time <= 15 and  >15...


prova2<-lme(chol~rt+sex+age+cd4+cd4:rt+
nadir+hivbl+
pharmac2:rt+resp2:rt+hbs+hcv+
switch,data=frame3,
random= ~rt|id, subset=which(rt<=15),
 na.action=na.omit,correlation=corAR1())





prova3<-lme(chol~rt+sex+age+cd4+cd4:rt+
nadir+hivbl+
pharmac2:rt+resp2:rt+hbs+hcv+
switch,data=frame3,
random= ~rt|id, subset=which(rt>15),
 na.action=na.omit,correlation=corAR1())



# ..I get quite completely different estimeates for time and all the time
interactions (sometimes an order of magnitude!)....







-- 
*Little u can do against ignorance,....it will always disarm u:
is the 2nd principle of thermodinamics made manifest, ...entropy in
expansion.**....But setting order is the real quest 4 truth, ......and the
mission of a (temporally) wise dude.
*

	[[alternative HTML version deleted]]


