# \donttest{
n <- 100
# Continuous Covariate
X1 <- runif(n, -1,1)
# Binary Covariate
X2 <- rbinom(n, 1, 0.5)
pi <- exp(2*X1 + -2*X2)/(exp(2*X1 + -2*X2) + 1)
# Binary response
Y <- rbinom(n, 1, pi)
keep <- 1:(n-25)
# standardize X1 to have mean zero and sd 1.
X <- data.frame(X1=scale(X1), X2=as.factor(X2))
Xtn <- X[keep,]
ytn <- Y[keep]
Xtt <- X[-keep,]
ytt <- Y[-keep]
# Since we have a binary response there are two "latent states".
# The boundaries of the latent states can be selected arbitrarily.
# Below I essentially use (-Inf, 0, Inf) to define the two latent spaces.
co <- c(-1e5, 0, 1e5)
# m0 s20 v k0 n0 a0 alpha
simParms <- c(0, 1.0, 0.5, 1.0, 2.0, 0.1, 1)
# m s2 s s0
modelPriors <- c(0, 10, 1, 1)
draws <- 50000
burn <- 25000
thin <- 25
nout <- (draws - burn)/thin
# Takes about 20 seconds to run
fit <- ordinal_ppmx(y = ytn, co=co, X=Xtn, Xpred=Xtt,
meanModel=1,
similarity_function=1, consim=1,
calibrate=0,
simParms=simParms,
modelPriors=modelPriors,
draws=draws, burn=burn, thin=thin, verbose=FALSE)
# The first partition iterate is used for plotting
# purposes only. We recommended using the salso
# R-package to estimate the partition based on Si
pairs(cbind(Y, X), col=fit$Si[1,])
# in-sample confusion matrix
table(ytn, apply(fit$ord.fitted.values, 2, median))
# out-of-sample confusion matrix based on posterior predictive samples
table(ytt, apply(fit$ord.ppred, 2, median))
# }
Run the code above in your browser using DataLab