Description Usage Arguments Details Value Examples
View source: R/credible_gradient.r
This function takes as input some continuous covariate x
and predictions from NDPMix, ZDPMix, fDPMix, etc. It outputs a credible band and posterior mean line of the predictions across x
1 2 3 4 5 6 | credible_gradient(
x,
post_draws,
col_gradient = "lightblue",
col_mean_line = "steelblue"
)
|
x |
A vector of type |
post_draws |
matrix with dimensions length(x) by # posterior draws. |
col_gradient |
Optional. Defaults to lightblue. Darkest color that gradient goes to. |
col_mean_line |
Optional. Defaults to steelblue. Color of the posterior mean regression line. |
Please see https://stablemarkets.github.io/ChiRPsite/index.html for examples and details.
overlays credible band and posterior mean line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | set.seed(1)
N = 200
x<-seq(1,10*pi, length.out = N) # confounder
y<-rnorm(n = length(x), sin(.5*x), .07*x )
d <- data.frame(x=x, y=y)
d$x <- as.numeric(scale(d$x))
d$y <- as.numeric(scale(d$y))
d_test = data.frame(x=seq(max(d$x), max(d$x+1 ), .01 ))
res = fDPMix(d_train = d, d_test = d_test, formula = y ~ x,
iter=100, burnin=50, tau_x = c(.01, .001) )
par(mfrow=c(1,1))
plot(d$x,d$y, pch=20, xlim=c(min(d$x), max(d$x)+1 ), col='gray')
credible_gradient(d$x, res$train)
credible_gradient(d_test$x, res$test, col_gradient = 'pink', col_mean_line = 'darkred')
points(d$x, d$y, pch=20, col='gray') ## re-plot points to bring the to the top.
abline(v=max(d$x), lty=2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.