如何找到“y"对应于原始“x"的非单调回归曲线的已经估计的单调函数的值点? [英] How to find "y" values of the already estimated monotone function of the non-monotone regression curve corresponding to the original "x" points?

查看:45
本文介绍了如何找到“y"对应于原始“x"的非单调回归曲线的已经估计的单调函数的值点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题听起来很复杂,但这正是我要找的.专注于图片.

The title sounds complicated but that is what I am looking for. Focus on the picture.

## data
x <- c(1.009648,1.017896,1.021773,1.043659,1.060277,1.074578,1.075495,1.097086,1.106268,1.110550,1.117795,1.143573,1.166305,1.177850,1.188795,1.198032,1.200526,1.223329,1.235814,1.239068,1.243189,1.260003,1.262732,1.266907,1.269932,1.284472,1.307483,1.323714,1.326705,1.328625,1.372419,1.398703,1.404474,1.414360,1.415909,1.418254,1.430865,1.431476,1.437642,1.438682,1.447056,1.456152,1.457934,1.457993,1.465968,1.478041,1.478076,1.485995,1.486357,1.490379,1.490719)
y <- c(0.5102649,0.0000000,0.6360097,0.0000000,0.8692671,0.0000000,1.0000000,0.0000000,0.4183691,0.8953987,0.3442624,0.0000000,0.7513169,0.0000000,0.0000000,0.0000000,0.0000000,0.1291901,0.4936121,0.7565551,1.0085108,0.0000000,0.0000000,0.1655482,0.0000000,0.1473168,0.0000000,0.0000000,0.0000000,0.1875293,0.4918018,0.0000000,0.0000000,0.8101771,0.6853480,0.0000000,0.0000000,0.0000000,0.0000000,0.4068802,1.1061434,0.0000000,0.0000000,0.0000000,0.0000000,0.0000000,0.0000000,0.0000000,0.0000000,0.0000000,0.6391678)
fit1 <- c(0.5102649100,0.5153380934,0.5177234836,0.5255544980,0.5307668662,0.5068087080,0.5071001179,0.4825657520,0.4832969250,0.4836378194,0.4842147729,0.5004039310,0.4987301366,0.4978800742,0.4978042478,0.4969807064,0.5086987191,0.4989497612,0.4936121200,0.4922210302,0.4904593166,0.4775197108,0.4757040857,0.4729265271,0.4709141776,0.4612406896,0.4459316517,0.4351338346,0.4331439717,0.4318664278,0.3235179189,0.2907908968,0.1665721429,0.1474035158,0.1443999345,0.1398517097,0.1153991839,0.1142140393,0.1022584672,0.1002410843,0.0840033244,0.0663669309,0.0629119398,0.0627979240,0.0473336492,0.0239237481,0.0238556876,0.0084990298,0.0077970954,0.0000000000,-0.0006598571)
fit2 <- c(-0.0006598571,0.0153328298,0.0228511733,0.0652889427,0.0975108758,0.1252414661,0.1270195143,0.1922510501,0.2965234797,0.3018551305,0.3108761043,0.3621749370,0.4184150225,0.4359301495,0.4432114081,0.4493565757,0.4510158144,0.4661865431,0.4744926045,0.4766574718,0.4796937554,0.4834718810,0.4836125426,0.4839450098,0.4841092849,0.4877317306,0.4930561638,0.4964939389,0.4970089201,0.4971376528,0.4990394601,0.5005881678,0.5023814257,0.5052125977,0.5056691690,0.5064254338,0.5115481820,0.5117259449,0.5146054557,0.5149729419,0.5184178197,0.5211542908,0.5216215426,0.5216426533,0.5239797875,0.5273573222,0.5273683002,0.5293994824,0.5295130266,0.5306236672,0.5307303109)

## picture
plot(x, y)

## red regression curve
points(x, fit1, col=2); lines(x, fit1, col=2)                        

## blue monotonic curve to the regression
points(min(x) + cumsum(c(0, rev(diff(x)))), rev(fit2), col="blue"); lines(min(x) + cumsum(c(0, rev(diff(x)))), rev(fit2), col="blue")    

## "x" original point matches with the regression estimated point
## but not with the estimated (fit2=estimate) monotonic curve
abline(v=1.223329, lty=2, col="grey")

关注灰色虚线.其思想是得到 x 原始值对应的单调蓝色曲线的 y 值.灰线应该跨越三个点(原始一个黑色",回归估计红色",调整后的回归估计蓝色").我们可以这样做吗?

Focus on the dashed grey line. The idea is to get y value of the monotonic blue curve corresponding to x original value. The grey line should cross three points (the original one "black", the regression estimate "red", the adjusted regression estimate "blue"). Can we do this?

方法论:
对象fit2"是函数rearrangement()的输出.它总是单调递增.

Methodology:
The object "fit2" is the output of the function rearrangement(). It is always monotonically increasing.

library(Rearrangement)
fit2 <- rearrangement(x=as.data.frame(x), y=fit1)

推荐答案

听起来您可能对 approxfun

fn <- approxfun(x=min(x) + cumsum(c(0, rev(diff(x)))), y=rev(fit2))
fn(1.223329)

它不是很花哨,但它会在未观察到的 x 值的观察点之间进行基本的线性插值.上面的代码将使用现有点估计 x=1.223329 值的 y 值.然后,您也可以使用 fn 函数来估计其他点.

It's not very fancy, but it will do a basic linear interpolation between observed points for unobserved x values. The code above will estimate a y value for the value x=1.223329 using the existing points. You can then use the fn function to estimate other points as well.

这篇关于如何找到“y"对应于原始“x"的非单调回归曲线的已经估计的单调函数的值点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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