gpt4 book ai didi

r - 散点图的非参数分位数回归曲线

转载 作者:行者123 更新时间:2023-12-03 22:23:46 24 4
gpt4 key购买 nike

我用 IV=time 创建了一个散点图(多组 GRP) , DV=concentration .我想添加分位数回归曲线 (0.025,0.05,0.5,0.95,0.975)到我的情节。

顺便说一句,这就是我为创建散点图所做的:

attach(E)  ## E is the name I gave to my data
## Change Group to factor so that may work with levels in the legend
Group<-as.character(Group)
Group<-as.factor(Group)

## Make the colored scatter-plot
mycolors = c('red','orange','green','cornflowerblue')
plot(Time,Concentration,main="Template",xlab="Time",ylab="Concentration",pch=18,col=mycolors[Group])

## This also works identically
## with(E,plot(Time,Concentration,col=mycolors[Group],main="Template",xlab="Time",ylab="Concentration",pch=18))

## Use identify to identify each point by group number (to check)
## identify(Time,Concentration,col=mycolors[Group],labels=Group)
## Press Esc or press Stop to stop identify function

## Create legend
## Use locator(n=1,type="o") to find the point to align top left of legend box
legend('topright',legend=levels(Group),col=mycolors,pch=18,title='Group')

因为我在这里创建的数据是我的大数据的一个小子集,所以它可能看起来可以近似为矩形双曲线。但我还不想在我的自变量和因变量之间调用数学关系。

我想 nlrq来自包裹 quantreg可能是答案,但是当我不知道变量之间的关系时,我不明白如何使用该函数。

我从一篇科学文章中找到了这张图,我想做完全相同的图:
Goal

再次感谢您的帮助!

更新

Test.csv
有人指出我的样本数据不可重现。这是我的数据示例。
library(evd)
qcbvnonpar(p=c(0.025,0.05,0.5,0.95,0.975),cbind(TAD,DV),epmar=T,plot=F,add=T)

我也试过qcbvnonpar::evd,但曲线似乎不太平滑。

最佳答案

也许看看 quantreg:::rqss 来平滑样条曲线和分位数回归。
抱歉,示例数据不太好:

set.seed(1234)
period <- 100
x <- 1:100
y <- sin(2*pi*x/period) + runif(length(x),-1,1)


require(quantreg)
mod <- rqss(y ~ qss(x))
mod2 <- rqss(y ~ qss(x), tau=0.75)
mod3 <- rqss(y ~ qss(x), tau=0.25)
plot(x, y)
lines(x[-1], mod$coef[1] + mod$coef[-1], col = 'red')
lines(x[-1], mod2$coef[1] + mod2$coef[-1], col = 'green')
lines(x[-1], mod3$coef[1] + mod3$coef[-1], col = 'green')

enter image description here

关于r - 散点图的非参数分位数回归曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15015556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com