Ben
Ben

Reputation: 1522

Why fit results so differently when using predict()?

I use following fit to smooth the data:

lo<- loess(df_raw$`101` ~ df_raw$Scan)

Now, why do following two commands provide completely different fit results?

plot(df_raw$Scan, df_raw$`101`)
lines(lo,col='red')

Fit1

plot(df_raw$Scan, df_raw$`101`)
lines(predict(lo), col='red', lwd=2)

Fit2

Upvotes: 0

Views: 59

Answers (1)

mnist
mnist

Reputation: 6954

Check the non existent differences in the following `lines()

library(ggplot2)
library(tidyverse)

iris <- iris %>% arrange(Sepal.Width)
lo <- loess(iris$Sepal.Length ~ iris$Sepal.Width)

plot(iris$Sepal.Width, iris$Sepal.Length)
lines(lo, col = "blue")
lines(lo$x, lo$y, col='red')
lines(iris$Sepal.Width, iris$Sepal.Length, col = "orange")


plot(iris$Sepal.Width, iris$Sepal.Length)
lines(predict(lo), col='blue', lwd=2)
lines(lo$fitted, col='red', lwd=2)

Upvotes: 1

Related Questions