## Generate data
set.seed(1)
X = matrix(runif(200*17), nrow=200)
X_test = matrix(runif(20*17), nrow=20)
n = dim(X)[1]
n_test = dim(X_test)[1]
groups = c(1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,6,6)
true_beta = c(-2,2,2,0,0,0,0,0,0,0,0,0,2.5,-2.5,0,0,0)
Y = crossprod(t(X), true_beta) + rnorm(n)
## Fit SSGL model. You should use the default burn=1000 and n_mcmc=2000
SSGL_mod = SSGL_gibbs(Y, X, groups, family="gaussian", X_test, burn=500, n_mcmc=1000)
## Evaluate results
cbind("True Beta" = true_beta,
"Posterior Mean" = SSGL_mod$beta_hat,
"95 CI lower" = SSGL_mod$beta_lower,
"95 CI upper"= SSGL_mod$beta_upper)
## Predictions on test data
cbind("Predicted E(Y)" = SSGL_mod$Y_pred_hat,
"95 CI lower" = SSGL_mod$Y_pred_lower,
"95 CI upper" = SSGL_mod$Y_pred_upper)
# \donttest{
## Example with binary logistic regression
## Generate data
set.seed(123)
X = matrix(runif(200*16), nrow=200)
X_test = matrix(runif(50*16), nrow=50)
n = dim(X)[1]
n_test = dim(X)[2]
groups = c(1,1,1,1,2,2,2,2,3,4,4,5,5,6,6,6)
true_beta = c(-2,2,2,-2,0,0,0,0,0,0,0,2.5,-2.5,0,0,0)
## Generate binary responses
eta = crossprod(t(X), true_beta)
Y = rbinom(n, 1, 1/(1+exp(-eta)))
## Fit SSGL logistic model
SSGL_logistic_mod = SSGL_gibbs(Y, X, groups, family="binomial", X_test)
## Evaluate results
cbind("True Beta" = true_beta,
"Posterior Mean" = SSGL_logistic_mod$beta_hat,
"95 CI lower" = SSGL_logistic_mod$beta_lower,
"95 CI upper"= SSGL_logistic_mod$beta_upper)
## Predictions on test data
cbind("Predicted E(Y)" = SSGL_logistic_mod$Y_pred_hat,
"95 CI lower" = SSGL_logistic_mod$Y_pred_lower,
"95 CI upper" = SSGL_logistic_mod$Y_pred_upper)
# }
Run the code above in your browser using DataLab