Dear R-users, I am trying to fit my data using one or more horizontal lines. If my data is in "y", I understand that "lm(y~1)" will fit a single horizontal line at mean(y). However, I want to try and fit the data with multiple horizontal lines if that reduces the error while still keeping the number of horizontal lines to be as small as possible.
Concretely, assume: y=c(2,4,2,4,2,4,2,4,8,10,8,10,8,10,8,10) lm(y~1) fits a single horizontal line at y=6. A better fit using multiple horizontal lines would be 2 horizontal lines at y = 3 and y = 9. An even better (if the objective is to solely minimize error and not penalize the number of horizontal lines) would be 4 horizontal lines at y=2, y=4, y=8, y=10. kMeans works for the simple example I have shown, but I would like advice on whether there is a better method that will work when the data does not fit a horizontal line exactly. Thanks, -sashi. [[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.