简体   繁体   English

渐变阴影置信区间

[英]gradient shaded confidence interval

I want to improvise my regression plot shade which is proportional to density. 我想即兴创建与密度成正比的回归阴影。 For example is the confidence interval is narrow the shade is dense while if confidence interval wide the fill color is light. 例如,置信区间较窄,阴影密集,而如果置信区间宽,则填充颜色较浅。 The result graph might look like this: 结果图可能如下所示:

在此输入图像描述

Here is an working example: 这是一个工作示例:

set.seed(1234)
md <- c(seq(0.01, 1, 0.01), rev(seq(0.01, 1, 0.01)))
cv <-  c(rev(seq(0.01, 1, 0.01)), seq(0.01, 1, 0.01))
rv <- rnorm (length(md), 0.1, 0.05)

 df <- data.frame(x =1:length(md),  F = md*2.5 + rv, L =md*2.5 -rv-cv, U =md*2.5+ rv+ cv)
 plot(df$x, df$F, ylim = c(0,4), type = "l")

 polygon(c(df$x,rev(df$x)),c(df$L,rev(df$U)),col = "cadetblue", border = FALSE)
 lines(df$x, df$F, lwd = 2)
 #add red lines on borders of polygon
 lines(df$x, df$U, col="red",lty=2)
 lines(df$x, df$L, col="red",lty=2)

The densregion() command in the denstrip package seems to do what you want. denstrip包中的densregion()命令似乎denstrip你的需要。 A little adaptation from the example in its help page: 从其帮助页面中的示例进行了一些调整:

require(denstrip)
x <- 1:10
nx <- length(x)
est <- seq(0, 1, length=nx)^3
se <- seq(.7,1.3,length.out=nx)/qnorm(0.975)
y <- seq(-3, 3, length=100)
z <- matrix(nrow=nx, ncol=length(y))
for(i in 1:nx) z[i,] <- dnorm(y, est[i], se[i])
plot(x, type="n", ylim=c(-3, 3),xlab="")
densregion(x, y, z)
lines(x,est,col="white")

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM