Created
August 30, 2017 20:11
-
-
Save fernandomayer/8443765e3e66413f5299d348f05dafd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Segmented regression plots in lattice | |
## Example for view purposes only | |
head(iris) | |
library(xyplot) | |
xyplot(Sepal.Length ~ Sepal.Width, iris, | |
panel = function(x, y, ...){ | |
panel.xyplot(x, y, ...) | |
le <- lm(Sepal.Length ~ Sepal.Width, iris, | |
subset = Sepal.Width <= 3) | |
llines(iris$Sepal.Width[iris$Sepal.Width <= 3], | |
predict(le)) | |
ld <- lm(Sepal.Length ~ Sepal.Width, iris, | |
subset = Sepal.Width > 3) | |
llines(iris$Sepal.Width[iris$Sepal.Width > 3], | |
predict(ld), col = 2) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment