【问题标题】:Predict values from sinusoidal noise从正弦噪声预测值
【发布时间】:2011-05-31 10:30:18
【问题描述】:

背景

使用 R 预测系列中的下一个值。

问题

以下代码为具有一些均匀噪声的曲线生成并绘制模型:

slope = 0.55
offset = -0.5
amplitude = 0.22
frequency = 3
noise = 0.75
x <- seq( 0, 200 )
y <- offset + (slope * x / 100) + (amplitude * sin( frequency * x / 100 ))
yn <- y + (noise * runif( length( x ) ))

gam.object <- gam( yn ~ s( x ) + 0 )
plot( gam.object, col = rgb( 1.0, 0.392, 0.0 ) )
points( x, yn, col = rgb( 0.121, 0.247, 0.506 ) )

正如预期的那样,该模型揭示了趋势。问题在于预测后续值:

p <- predict( gam.object, data.frame( x=201:210 ) )

绘制时预测看起来不正确:

df <- data.frame( fit=c( fitted( gam.object ), p ) )
plot( seq( 1:211 ), df[,], col="blue" )
points( yn, col="orange" )

预测值(从 201 开始)似乎太低了。

问题

  1. 如图所示,预测值是否实际上是最准确的预测?
  2. 如果不是,如何提高准确性?
  3. 连接两个数据集(fitted.values( gam.object )p)的更好方法是什么?

【问题讨论】:

  • 预测 x 从 1 到 211。根本不要使用拟合

标签: r plot prediction gam


【解决方案1】:
  1. 模拟数据很奇怪,因为您添加到“真实”y 的所有错误都大于 0。(runif[0,1] 上创建数字,而不是[-1,1]。)
  2. 当模型中的截距项被允许时,问题就消失了。

例如:

gam.object2 <- gam( yn ~ s( x ))
p2 <- predict( gam.object2, data.frame( x=201:210 ))
points( 1:211, c( fitted( gam.object2 ), p2), col="green")

在没有截距的模型中系统性低估的原因可能是gam 对估计的平滑函数使用了和为零的约束。我认为第 2 点回答了您的第一个和第二个问题。

您的第三个问题需要澄清,因为gam-object 不是data.frame。这两种数据类型不能混用。

一个更完整的例子:

slope = 0.55
amplitude = 0.22
frequency = 3
noise = 0.75
x <- 1:200
y <- (slope * x / 100) + (amplitude * sin( frequency * x / 100 ))
ynoise <- y + (noise * runif( length( x ) ))

gam.object <- gam( ynoise ~ s( x ) )
p <- predict( gam.object, data.frame( x = 1:210 ) )

plot( p, col = rgb( 0, 0.75, 0.2 ) )
points( x, ynoise, col = rgb( 0.121, 0.247, 0.506 ) )
points( fitted( gam.object ), col = rgb( 1.0, 0.392, 0.0 ) )

【讨论】:

    猜你喜欢
    • 2020-04-20
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-13
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多