[R] Fitting multiple horizontal lines to data

David Carlson dcarlson at tamu.edu
Wed Nov 6 21:45:47 CET 2013

The changepoint package might give you a way to do this.

David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Sashikanth
Sent: Wednesday, November 6, 2013 11:20 AM
To: r-help at r-project.org
Subject: [R] Fitting multiple horizontal lines to data

I am not trying to fit a horizontal line at every unique value
of y. I am
trying fit the y values with as few horizontal lines by trading
off the
number of horizontal lines with the error. The actual problem I
am trying
to solve is to smooth data in a time series. Here is a realistic
example of


An example fit for y using multiple horizontal lines (may not be
the best
fit in terms of squared error or another error metric, but I
have included
the y value for concreteness)

1. A horizontal line at approximately y=140 (to fit the first 13
values -
134.45 to 148.77)
2. A horizontal line at approximately y=110 (to fit the next 7
values -
71.64 to 111.64)
3. A horizontal line at approximately y=150 (to fit the next 2
values -
157.26 to 143.8)
4. A horizontal line at approximately y=65 (to fit the last 8
values -
40.19 to 64.99)

	[[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible

More information about the R-help mailing list