使骗局功能更强大,可抵御离群值

时间:2019-01-25 14:06:53

标签: r gam loess

我使用R包“ scam”从散点图建立具有单调约束的平滑模型。但是,我希望它对诸如lowess函数之类的离群值更加健壮。 有没有一种方法可以修改骗局的用法来实现此目的?

library(scam)

x <- seq(1, 100, length.out = 500)
y <- rnorm(500, mean = 10, sd = 2) + x
y[c(480, 490:495, 500)] <- y[c(480, 490:495, 500)] - 80

data <- data.frame(x=x, y=y)
scam_model <- scam(y~s(x, k= 50, bs="mpi"), data=data)
prediction <- predict(scam_model, newdata = data, type="link", se=T)

lowess.out <- lowess(x, y, f = 0.2)

# scam
plot(x, y)
lines(x, prediction$fit, col="red", lwd=2)
lines(x, prediction$fit + prediction$se.fit * 3, col ="blue", lty=2)
lines(x, prediction$fit - prediction$se.fit * 3, col ="blue", lty=2)

# lowess
plot(x, y)
lines(lowess.out$x, lowess.out$y, col="red", lwd=2)

骗局: enter image description here

lowess: enter image description here

0 个答案:

没有答案