【问题标题】:plotting custom confidence intervals around curve fits R围绕曲线拟合 R 绘制自定义置信区间
【发布时间】:2015-11-03 05:45:37
【问题描述】:

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

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

我想根据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)

但是如何根据指定的错误术语在它们周围添加自定义阴影区域?

【问题讨论】:

    标签: r plot


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-09-16
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 2022-01-13
      • 2012-11-11
      • 2018-05-05
      • 1970-01-01
      相关资源
      最近更新 更多