Description Usage Arguments Details Value Examples
This function takes in a training data.frame and optional testing data.frame and performs posterior sampling. It returns posterior predictions and posterior clustering for training and test sets. The function is built for continuous outcomes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
d_train |
A |
formula |
Specified in the usual way, e.g. for |
d_test |
Optional |
burnin |
integer specifying number of burn-in MCMC draws. |
iter |
integer greater than |
phi_y |
Optional. Length two |
beta_prior_mean |
Optional. If there are |
beta_prior_var |
Optional. If there are |
init_k |
Optional. integer specifying the initial number of clusters to kick off the MCMC sampler. |
beta_var_scale |
Optional. A multiplicative constant that scales |
mu_scale |
Optional. An numeric, scalar constant that controls how widely distributed new cluster continuous covariate means are distributed around the empirical covariate mean. Specifically, all continuous covariates are assumed to have Gaussian likelihood with Gaussian prior on their means. |
tau_scale |
Optional. An numeric, scalar constant that controls how widely distributed new cluster continuous covariate variances are distributed around the empirical variance. Specifically, all continuous covariates are assumed to have Gaussian likelihood with Inverse Gamma prior on their variance. |
Please see https://stablemarkets.github.io/ChiRPsite/index.html for examples and detailed model and parameter descriptions.
Returns predictions$train
and cluster_inds$train
. predictions$train
returns an nrow(d_train)
by iter - burnin
matrix of posterior predictions. cluster_inds$train
returns an nrow(d_train)
by iter - burnin
matrix of cluster assignment indicators, which can be input into the function cluster_assign_mode()
to compute posterior mode assignment. predictions$test
and cluster_inds$test
are returned if d_test
is specified.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Simulate data from sin() wave.
set.seed(3)
n <- 200
# training
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 <- scale(d$x) # standardize covariates
d_test <- data.frame(x=seq(1.5,2,.01))
# run model.
set.seed(1)
NDP_res<-NDPMix(d_train = d, d_test = d_test,
formula = y ~ x,
burnin=100, iter = 200,
phi_y = c(5,10), beta_var_scale = 10000,
init_k = 10, mu_scale = 2, tau_scale = .001)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.