我有一些变量,我有兴趣找到它们之间的非线性关系。所以我决定拟合一些样条曲线或黄土,并打印出漂亮的图(见下面的代码)。但是,我还想要一些统计数据,让我知道这种关系是随机问题的可能性有多大……即,我需要一些整体 p 值,例如线性回归。换句话说,我需要知道拟合曲线是否有意义,因为我的代码会将曲线拟合到任何数据。
x <- rnorm(1000)
y <- sin(x) + rnorm(1000, 0, 0.5)
cor.test(x,y)
plot(x, y, xlab = xlab, ylab = ylab)
spl1 <- smooth.spline(x, y, tol = 1e-6, df = 8)
lines(spl1, col = "green", lwd = 2)
spl2 <- loess(y ~ x)
x.pr <- seq(min(x), max(x), length.out = 100)
lines(x.pr, predict(spl2, x.pr), col = "blue", lwd = 2)