围绕曲线拟合R绘制自定义置信区间

围绕曲线拟合R绘制自定义置信区间,r,plot,R,Plot,假设对于三个不同的组,A,B和C,我在x和一些结果变量之间有一些关系: x<-c(0:470)/1000 #3 groups, each has a different v-max parameter value. v.A<-5 v.B<-4 v.C<-3 C<- (v.C*x)/(0.02+x) B<- (v.B*x)/(0.02+x) A<-(v.A*x)/(0.02+x) d.curve<-data.frame(x,A,B,C) 我想根据v

假设对于三个不同的组,
A
B
C
,我在
x
和一些结果变量之间有一些关系:

x<-c(0:470)/1000
#3 groups, each has a different v-max parameter value.
v.A<-5
v.B<-4
v.C<-3
C<- (v.C*x)/(0.02+x)
B<- (v.B*x)/(0.02+x)
A<-(v.A*x)/(0.02+x)
d.curve<-data.frame(x,A,B,C)
我想根据
v.
参数中的不确定性绘制这些曲线拟合,以及每条曲线周围的阴影误差区域。因此,阴影区域将是+/-一个误差值。我可以很容易地生成3条曲线的绘图:

limx<-c(0,0.47)
limy<-c(0,5.5)

plot(A~x,data=d.curve,xlim=limx,ylim=limy,col=NA)
lines(smooth.spline(d.curve$x,d.curve$A),col='black',lwd=3)
par(new=T)
plot(B~x,data=d.curve,xlim=limx,ylim=limy,col=NA,ylab=NA,xlab=NA,axes=F)
lines(smooth.spline(d.curve$x,d.curve$B),col='black',lwd=3,lty=2)
par(new=T)
plot(C~x,data=d.curve,xlim=limx,ylim=limy,col=NA,ylab=NA,xlab=NA,axes=F)
lines(smooth.spline(d.curve$x,d.curve$C),col='black',lwd=3,lty=3)

limx您可以将以下代码添加到当前代码中。直线误差的计算基于系数的误差(假定标准误差)。如果需要,可以将直线误差的计算更改为其他值。可能需要更改打印顺序,以使多边形显示在线条后面

# calculating the standard error of the line base on standard error of A,B,C
# could substitute another calculation
se.line.A <- ((x)/(0.02+x))*err.A
se.line.B <- ((x)/(0.02+x))*err.B
se.line.C <- ((x)/(0.02+x))*err.C

# library for polygons
library(graphics)

# plotting polygons
# colors can be changed
# polygons will be drawn over the existing lines
# may change the order of plotting for the shaded regions to be behind line
polygon(c(x,rev(x))
        ,c(A+se.line.A,rev(A-se.line.A))
        ,col='gray'
        ,density=100)

polygon(c(x,rev(x))
        ,c(B+se.line.B,rev(B-se.line.B))
        ,col='blue'
        ,density=100)

polygon(c(x,rev(x))
        ,c(C+se.line.C,rev(C-se.line.C))
        ,col='green'
        ,density=100)
#根据A、B、C的标准误差计算线路的标准误差
#可以替代另一种计算
东南线
# calculating the standard error of the line base on standard error of A,B,C
# could substitute another calculation
se.line.A <- ((x)/(0.02+x))*err.A
se.line.B <- ((x)/(0.02+x))*err.B
se.line.C <- ((x)/(0.02+x))*err.C

# library for polygons
library(graphics)

# plotting polygons
# colors can be changed
# polygons will be drawn over the existing lines
# may change the order of plotting for the shaded regions to be behind line
polygon(c(x,rev(x))
        ,c(A+se.line.A,rev(A-se.line.A))
        ,col='gray'
        ,density=100)

polygon(c(x,rev(x))
        ,c(B+se.line.B,rev(B-se.line.B))
        ,col='blue'
        ,density=100)

polygon(c(x,rev(x))
        ,c(C+se.line.C,rev(C-se.line.C))
        ,col='green'
        ,density=100)