## Not run:
# # compare gvcm.cat.flex and gvcm.cat for Lasso-type penalties:
# n <- 100
# ncov <- 7
# set.seed(123)
# X <- matrix(rnorm(n*ncov, sd=5), ncol=ncov)
# coefs <- rpois(ncov + 1, 2)
# y <- cbind(1, X)
# data <- as.data.frame(cbind(y, X))
# names(data) <- c("y", paste("x", 1:ncov, sep=""))
#
# m1 <- gvcm.cat.flex(
# whichCoefs = paste("x", 1:ncov, sep=""),
# data=data,
# indexNrCoefs=rep(1, ncov),
# indexPenNorm=rep("L1", ncov),
# indexPenA=list(1,1,1,1,1,1,1),
# indexPenWeight=list(1,1,1,1,1,1,1)
# )
#
# m2 <- gvcm.cat(y ~ 1 + p(x1) + p(x2) + p(x3) + p(x4) + p(x5) + p(x6) + p(x7),
# data=data, tuning=list(lambda=m1$sp, specific=TRUE), start=rep(1, 8))
#
# rbind(m1$coefficients, m2$coefficients)
#
# # Lasso-type fusion penalty with gvcm.cat.flex
# n <- 100
# ncat <- 8
# set.seed(567)
# X <- t(rmultinom(n, 1, rep(1/ncat, ncat)))[, -1]
# coefs <- c(rpois(1, 2), sort(rpois(ncat-1, 1)))
#
# y <- cbind(1, X)
# data <- as.data.frame(y)
# data$x1 <- X
# names(data) <- c("y", "x1")
#
# A <- a(1:(ncat-1), ncat-2)
#
# m3 <- gvcm.cat.flex(
# whichCoefs = c("x1"),
# data = data,
# indexNrCoefs = c(ncat-1),
# indexPenNorm = c("L1"),
# indexPenA = list(A),
# indexPenWeight = list(rep(1, ncol(A))),
# tuning = 100 # fixed and large - in order to demonstrate the fusion of the coefficients
# )
# m3$coefficients
# ## End(Not run)
Run the code above in your browser using DataLab