Hi Dears, When I introduce an interaciton in a piecewise model I obtain some quite unusual results.
If that would't take u such a problem I'd really appreciate an advise from you. I've reproduced an example below... Many thanks x<-rnorm(1000) y<-exp(-x)+rnorm(1000) plot(x,y) abline(v=-1,col=2,lty=2) mod<-lm(y~x+x*(x>-1)) summary(mod) yy<-predict(mod) lines(x[order(x)],yy[order(x)],col=2,lwd=2) #--lme #grouping factor, unbalanced g<-as.character(c(1:200)) id<-sample(g,size=1000,replace=T, prob=sample(0:1,200,rep=T)) table(id) #unbalanced mod2<-lme(y~x+x*(x>-1),random=~x|id, data=data.frame(x,y,id)) summary(mod2) newframe<-data.frame( #fictious id id="fictious", x) newframe[1:5,] #predictions yy2<-predict(mod2,level=0, newdata=newframe) lines(x[order(x)],yy2[order(x)],col="blue",lwd=2) # add variable in the model z<-rgamma(1000,4,6) mod3<-lme(y~x+x*(x>-1)+z ,random=~x|id, data=data.frame(x,y,z,id)) summary(mod3) #new id newframe2<-data.frame( #fictious id id="fictious", x, z) #predict yy3<-predict(mod3,level=0, newdata=newframe2) lines(x[order(x)],yy3[order(x)],col="green",lwd=2) # ADD INTERACTION z:x mod4<-lme(y~x+x*(x>-1)+ z+ z:x+ z:x*(x>-1) ,random=~x|id, data=data.frame(x,y,z,id)) #predict yy4<-predict(mod4,level=0, newdata=newframe2) lines(x[order(x)],yy4[order(x)],col="violet",lwd=2) #something bizarre #starts to happen #in the predicted values # they begin to jiggle around the straight line -- *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]] ______________________________________________ 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.