# NOT RUN {
## Generate data
set.seed(12345)
X = matrix(runif(100*10), nrow=100)
n = dim(X)[1]
groups = c("A","A","A","B","B","B","C","C","D","D")
groups = as.factor(groups)
true.beta = c(-2.5,1.5,1.5,0,0,0,2,-2,0,0)
## Generate responses from Gaussian distribution
y = crossprod(t(X),true.beta) + rnorm(n)
## Generate test data
n.test = 50
X.test = matrix(runif(n.test*10), nrow=n.test)
## Fit SSGL model with 10 spike hyperparameters
## Note that if user does not specify lambda0, the SSGL function chooses a grid automatically.
SSGL.mod = SSGL(y, X, X.test, groups, family="gaussian", lambda0=seq(from=50,to=5,by=-5))
## Regression coefficient estimates
SSGL.mod$beta
# Predicted n.test-dimensional vectors mu=E(Y.test) based on test data, X.test.
# The kth column of 'mu.pred' corresponds to the kth entry in 'lambda.'
SSGL.mod$mu.pred
# Classifications of the 8 groups. The kth column of 'classifications'
# corresponds to the kth entry in 'lambda.'
SSGL.mod$classifications
# }
# NOT RUN {
## Example with binomial regression
## Generate binary responses
eta = crossprod(t(X), true.beta)
y = rbinom(n, size=1, prob=1/(1+exp(-eta)))
## Fit SSGL model with 10 spike hyperparameters
## Note that if user does not specify lambda0, the SSGL function chooses a grid automatically.
SSGL.mod = SSGL(y, X, X.test, groups, family="binomial",
lambda0=seq(from=10,to=1,by=-1))
## Predicted probabilities of success mu=E(Y.test) based on test data, X.test
SSGL.mod$mu.pred
## Classifications of the 8 groups.
SSGL.mod$classifications
# }
Run the code above in your browser using DataLab