2015-11-02 128 views
1

说我有x和一些结果变量之间的一些关系,为三个不同的群体,ABC绘制围绕曲线定制置信区间符合[R

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.参数的估计也有关联错误:

err.A<-0.24 
err.B<-0.22 
err.C<-0.29 

我想绘制这些曲线拟合,以及每个弯道阴影误差区域的基础上,在的不确定性参数。所以,阴影区域将是+/-一个错误值。我可以生成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) 

但我怎么能添加的自定义阴影周围的区域,根据指定的误差项?

enter image description here

回答

2

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

# 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) 

enter image description here