从R中的LOESS对象进行校准(逆预测) [英] Calibration (inverse prediction) from LOESS object in R

查看:188
本文介绍了从R中的LOESS对象进行校准(逆预测)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一些数据进行了LOESS局部回归分析,并且我希望能够找到与给定Y值关联的X值.

I have fit a LOESS local regression to some data and I want to be able to find the X value associated with a given Y value.

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对象.

I was hoping that I could use teh inverse.predict function from the chemCal package, but that does not work for LOESS objects.

有没有人比从长X值向量中预测Y值并通过结果拟合的Y寻找感兴趣的Y值并取其对应的X更好的方式来进行校准?价值?

Does anyone have any idea how I might be able to do this calibrationa in a better way than predicticting Y values from a long vector of X values and looking through the resulting fitted Y for the Y value of interest and taking its corresponding X value?

实际上在上面的示例中,我想找到停止距离为15的速度.

Practically speaking in the above example, let's say I wanted to find the speed at which the stopping distance is 15.

谢谢!

推荐答案

您添加到绘图中的预测线不太正确.使用如下代码:

The predicted line that you added to the plot is not quite right. Use code like this instead:

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

您可以使用approx()函数以给定y值从黄土线获得线性近似值.对于您给出的示例,它工作得很好:

You can use the approx() function to get a linear approximation from the loess line at a give y value. It works just fine for the example that you give:

# 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)

但是,对于黄土来说,给定的y可能有多个x.我建议的方法不能为您提供给定y的所有x值.例如...

But, with a loess fit, there may be more than one x for a given y. The approach I am suggesting does not provide you with ALL of the x values for the given y. For example ...

# 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)

这篇关于从R中的LOESS对象进行校准(逆预测)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆