0

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 になる速度を見つけたいとしましょう。

ありがとう!

4

1 に答える 1

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)

しかし、黄土適合では、特定の 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)
于 2014-05-30T19:23:51.340 に答える