为什么在使用predict()时拟合结果如此不同?

问题描述 投票:0回答:1

我使用以下拟合来平滑数据:

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

现在,为什么以下两个命令提供完全不同的拟合结果?

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

r
1个回答
0
投票

检查以下`lines()中不存在的差异>>

library(ggplot2)
library(tidyverse)

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

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)
© www.soinside.com 2019 - 2024. All rights reserved.