【问题标题】:Calibration (inverse prediction) from LOESS object in RR中黄土对象的校准(逆预测)
【发布时间】:2014-05-30 14:52:32
【问题描述】:

我已经对一些数据进行了 LOESS 局部回归,我希望能够找到与给定 Y 值相关的 X 值。

plot(cars, main = "Stopping Distance versus Speed")
car_loess <- loess(cars$dist~cars$speed,span=.5)
lines(1:50, predict(car_loess,data.frame(speed=1:50)))

我希望我可以使用 chemCal 包中的 inverse.predict 函数,但这不适用于 LOESS 对象。

有没有人知道我如何能够以比从 X 值的长向量预测 Y 值并通过结果拟合 Y 查找感兴趣的 Y 值并取其对应的 X 更好的方式来进行此校准价值?

实际上在上面的例子中,假设我想找到停止距离为 15 的速度。

谢谢!

【问题讨论】:

    标签: r calibration loess


    【解决方案1】:

    您添加到绘图中的预测线不太正确。改用这样的代码:

    # plot the loess line
    lines(cars$speed, car_loess$fitted, col="red")
    

    您可以使用approx() 函数在给定的 y 值处从黄土线获得线性近似值。它适用于您提供的示例:

    # define a given y value at which you wish to approximate x from the loess line
    givenY <- 15
    estX <- approx(x=car_loess$fitted, y=car_loess$x, xout=givenY)$y
    # add corresponding lines to the plot
    abline(h=givenY, lty=2)
    abline(v=estX, lty=2)
    

    但是,在 loess fit 的情况下,给定的 y 可能有多个 x。我建议的方法不会为您提供给定 y 的所有 x 值。比如……

    # example with non-monotonic x-y relation
    y <- c(1:20, 19:1, 2:20)
    x <- seq(y)
    plot(x, y)
    fit <- loess(y ~ x)
    # plot the loess line
    lines(x, fit$fitted, col="red")
    
    # define a given y value at which you wish to approximate x from the loess line
    givenY <- 15
    estX <- approx(x=fit$fitted, y=fit$x, xout=givenY)$y
    # add corresponding lines to the plot
    abline(h=givenY, lty=2)
    abline(v=estX, lty=2)
    

    【讨论】:

    • 您也可以使用骗局包而不是 loess 来拟合单调递增或递减样条曲线(对于校准模型,这通常是您想要的),然后在其上使用 approx() 以保证您给定的 y 只有一个 x...
    猜你喜欢
    • 1970-01-01
    • 2012-09-23
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多