[R] Piecewise regression using segmented package plotted in xyplot

Duncan Mackay dulcalma at bigpond.com
Fri Aug 28 16:31:15 CEST 2015


Hi

Without a reproducible example I am only guessing 

Try this 

xyplot(threshold ~ age |frequency.a, data=subset(rage !is.na(threshold} &
!is.na(age)),
       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", # see above
       type = c("p","l"),  # re-read ?xyplot: from the panel section:
panel.abline(lm(threshold~age))
       panel = panel.superpose,
       panel.groups =function(x,y,groups,...) {

                        panel.xyplot(x,y,...)
                        # panel.abline(segmented(lm(threshold~age),seg.Z =
~age, psi = NA, control = seg.control(K=1)))

                      },
)

I do not know what the commented line means-- you may need to look at the
subscripts section as well as panel.groups of ?xyplot
and ?panel.xyplot

Regards

Duncan

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au


-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Sumitrajit
Dhar
Sent: Friday, 28 August 2015 14:12
To: r-help at r-project.org
Subject: [R] Piecewise regression using segmented package plotted in xyplot

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]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.



More information about the R-help mailing list