非参数分位数回归曲线到散点图

shi*_*ywu 14 regression r scatter-plot quantile

我创建了一个散点图(多组GRP)用IV=time,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')
Run Code Online (Sandbox Code Playgroud)

因为我在这里创建的数据是我的较大数据的一小部分,所以它看起来可能近似为矩形夸张.但我不想在我的独立变量和因变量之间调用数学关系.

我认为nlrq从包中quantreg可能是答案,但是当我不知道我的变量之间的关系时,我不明白如何使用该函数.

我从一篇科学文章中找到了这个图,我想要做的就是同一种图: 目标

再次感谢您的帮助!

更新

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)
Run Code Online (Sandbox Code Playgroud)

我也试过qcbvnonpar :: evd,但曲线看起来不是很平滑.

EDi*_*EDi 8

也许看一下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')
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


jor*_*ran 5

我过去经常挣扎,rqss我的问题几乎总是与点的排序有关.

您可以在不同的时间点进行多次测量,这就是您获得不同长度的原因.这对我有用:

dat <- read.csv("~/Downloads/Test.csv")

library(quantreg)
dat <- plyr::arrange(dat,Time)
fit<-rqss(Concentration~qss(Time,constraint="N"),tau=0.5,data = dat)
with(dat,plot(Time,Concentration))
lines(unique(dat$Time)[-1],fit$coef[1] + fit$coef[-1])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在拟合模型之前对数据帧进行排序似乎是必要的.