Skip to content

Commit

Permalink
Bug fix for gBridge group multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
pbreheny committed Jul 20, 2017
1 parent b856d08 commit f20824e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions R/newXG.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ newXG <- function(X, g, m, ncolY, bilevel) {
XX <- std[[1]]
center <- std[[2]]
scale <- std[[3]]
nz <- which(scale > 1e-6) # non-constant columns
nz <- which(scale > 1e-6) # non-constant columns
zg <- setdiff(unique(g), unique(g[nz])) # constant groups
if (length(zg)) m <- m[-zg]
if (length(zg)) {
gf <- factor(g[!(g %in% zg)])
if (any(levels(gf)=="0")) {
g <- as.numeric(gf) - 1
} else {
g <- as.numeric(gf)
}
m <- m[-zg]
}
if (length(nz) != ncol(X)) {
XX <- XX[ ,nz, drop=FALSE]
g <- g[nz]
}
if (!bilevel) {
XX <- orthogonalize(XX, g)
Expand Down
2 changes: 1 addition & 1 deletion R/setupLambda.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ setupLambda.gBridge <- function(X, y, group, family, alpha, lambda.min, lambda.m
z <- crossprod(X[,ind], fit$weights * residuals(fit, "working")) / n
a <- .2
}
lambda.max <- max(abs(z)/group.multiplier)*a^(1-gamma)/(gamma*alpha)
lambda.max <- max(abs(z)/group.multiplier[group])*a^(1-gamma)/(gamma*alpha)
}
if (lambda.min==0) {
lambda <- c(exp(seq(log(lambda.max), log(.001*lambda.max), len=nlambda-1)),0)
Expand Down
4 changes: 2 additions & 2 deletions inst/tests/extra-features.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ cvfit <- cv.grpreg(X, y, group, penalty="grLasso")

.test = "group.multiplier works"
n <- 50
p <- 10
p <- 11
X <- matrix(rnorm(n*p),ncol=p)
y <- rnorm(n)
group <- rep(0:3,1:4)
group <- rep(0:3,c(1, 2, 3, 5))
gm <- 1:3
plot(fit <- grpreg(X, y, group, penalty="cMCP", lambda.min=0, group.multiplier=gm), main=fit$penalty)
plot(fit <- gBridge(X, y, group, lambda.min=0, group.multiplier=gm), main=fit$penalty)
Expand Down
Empty file added inst/tests/gBridge.R
Empty file.

0 comments on commit f20824e

Please sign in to comment.