Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

R plottinjg polynomial regression line

$
0
0

I try to plot a polynomial regression line but the plotted line does not make sense. I use the iris dataset from the package datasets. This is my code:

library(datasets)
data2 <- iris[iris$Species != "setosa", ]
x<- data2$Sepal.Length
y <- data2$Species
fit <- lm(y ~ poly(x, 3))   ## polynomial of degree 3
plot(x, y)  ## scatter plot (colour: black)

x0 <- seq(min(x), max(x), length = 20)  ## prediction grid
y0 <- predict.lm(fit, newdata = list(x = x0))  ## predicted values
lines(x0, y0, col = 2) 

Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>