[R] Piecewise regression using segmented package plotted in xyplot

Sumitrajit Dhar s-dhar at northwestern.edu
Fri Aug 28 06:11:45 CEST 2015


Hi,

xyplot(threshold ~ age |frequency.a, data=rage,
groups=HL,
  cex=0.5,
  layout=c(7,4),
par.strip.tex=list(cex=0.8),
  xlab="Age (years)",
  ylab="Threshold (dB SPL)",
  na.rm="TRUE",
  panel=function(x,y,groups,...) {
panel.superpose(x,y,groups=HL,...)
# panel.abline(segmented(lm(threshold~age),seg.Z = ~age, psi = NA, control = seg.control(K=1)))
panel.abline(lm(threshold~age))
  },
  )

Is there anyway to make the commented line work in lattice? I need to fit my data in each panel using piecewise regression. Being able to use segmented would make it easy.

The code above works to give me a linear fit.

Thanks for your help in advance.

Regards,
Sumit



	[[alternative HTML version deleted]]



More information about the R-help mailing list