Skip to content

Commit

Permalink
Merge pull request #22 from sahirbhatnagar/jasa
Browse files Browse the repository at this point in the history
First CRAN Release
  • Loading branch information
sahirbhatnagar authored Dec 14, 2019
2 parents a151e96 + 192963d commit 089edda
Show file tree
Hide file tree
Showing 157 changed files with 14,245 additions and 6,813 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@
^_pkgdown\.yml$
^manuscript$
^rda/scott/$
^appveyor\.yml$
^CRAN-RELEASE$
^cran-comments\.md$
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Instances of abusive, harassing, or otherwise unacceptable behavior may be repor
opening an issue or contacting one or more of the project maintainers.

This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.0.0, available at
http://contributor-covenant.org/version/1/0/0/
(https://www.contributor-covenant.org), version 1.0.0, available at
https://contributor-covenant.org/version/1/0/0/.
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2019-12-02.
Once it is accepted, delete this file and tag the release (commit 357d86d705).
14 changes: 8 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sail
Title: Sparse Additive Interaction Learning
Version: 0.0.0.9000
Version: 0.1.0
Authors@R: c(
person("Sahir", "Bhatnagar", email = "[email protected]",
role = c("aut", "cre"), comment = "http://sahirbhatnagar.com/"),
Expand All @@ -9,10 +9,12 @@ Authors@R: c(
person("Celia", "Greenwood", email = "[email protected]",
role = c("aut"), comment = "https://www.mcgill.ca/statisticalgenetics/")
)
Description: Sparse Additive Interaction Learning with the strong heredity property, i.e.,
Description: Sparse additive interaction learning with the strong heredity property, i.e.,
an interaction is selected only if its corresponding main effects are also included.
Fits a linear model with non-linear interactions via penalized maximum likelihood.
Interactions are limited to a single exposure or environment variable.
Interactions are limited to a single exposure or environment variable. For more information,
see the website below and the accompanying paper: Bhatnagar et al., "A sparse additive model for
high-dimensional interactions with an exposure variable", 2019, <DOI:10.1101/445304>.
Depends: R (>= 3.4.0)
Imports:
glmnet,
Expand All @@ -22,7 +24,7 @@ Suggests:
grpreg,
truncnorm,
foreach,
doMC,
doParallel,
testthat,
covr,
vdiffr,
Expand All @@ -32,6 +34,6 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
BugReports: https://github.com/sahirbhatnagar/sail/issues
URL: https://github.com/sahirbhatnagar/sail
RoxygenNote: 6.0.1
URL: https://sahirbhatnagar.com/sail
RoxygenNote: 6.1.1
VignetteBuilder: knitr
54 changes: 27 additions & 27 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# Generated by roxygen2: do not edit by hand
S3method(coef,cv.sail)
S3method(coef,sail)
S3method(plot,cv.sail)
S3method(plot,sail)
S3method(predict,cv.sail)
S3method(predict,sail)
S3method(print,sail)
export(cv.sail)
export(gendata)
export(plotInter)
export(plotMain)
export(sail)
importFrom(grDevices,hcl)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot.default)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(stats,approx)
importFrom(stats,coef)
importFrom(stats,predict)
# Generated by roxygen2: do not edit by hand

S3method(coef,cv.sail)
S3method(coef,sail)
S3method(plot,cv.sail)
S3method(plot,sail)
S3method(predict,cv.sail)
S3method(predict,sail)
S3method(print,sail)
export(cv.sail)
export(gendata)
export(plotInter)
export(plotMain)
export(sail)
importFrom(grDevices,hcl)
importFrom(graphics,abline)
importFrom(graphics,axis)
importFrom(graphics,legend)
importFrom(graphics,lines)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot.default)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(stats,approx)
importFrom(stats,coef)
importFrom(stats,predict)
37 changes: 11 additions & 26 deletions R/cv.sail.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' Default: FALSE
#' @param parallel If \code{TRUE}, use parallel \code{foreach} to fit each fold.
#' Must register parallel before hand using the
#' \code{\link[doMC]{registerDoMC}} function from the \code{doMC} package. See
#' \code{\link[doParallel]{registerDoParallel}} function from the \code{doParallel} package. See
#' the example below for details. Default: FALSE
#' @return an object of class \code{"cv.sail"} is returned, which is a list with
#' the ingredients of the cross-validation fit. \describe{ \item{lambda}{the
Expand Down Expand Up @@ -80,42 +80,27 @@
#' models with the strong heredity property (2018+). Preprint.
#' @seealso \code{\link[splines]{bs}} \code{\link{sail}}
#' @examples
#' \dontrun{
#' if(interactive()){
#' f.basis <- function(i) splines::bs(i, degree = 5)
#' f.basis <- function(i) splines::bs(i, degree = 3)
#' data("sailsim")
#' cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
#' basis = f.basis, nfolds = 10)
#'
#' # Parallel
#' library(doMC)
#' registerDoMC(cores = 4)
#' library(doParallel)
#' cl <- makeCluster(2)
#' registerDoParallel(cl)
#' cvfit <- cv.sail(x = sailsim$x, y = sailsim$y, e = sailsim$e,
#' parallel = TRUE, nlambda = 100, nfolds = 10)
#' parallel = TRUE, nlambda = 10,
#' maxit = 25, basis = f.basis,
#' nfolds = 3, dfmax = 5)
#' stopCluster(cl)
#' # plot cross validated curve
#' plot(cvfit)
#' # plot solution path
#' plot(cvfit$sail.fit)
#'
#' # solution at lambda.min
#' coef(cvfit, s = "lambda.min")
#' # solution at lambda.1se
#' coef(cvfit, s = "lambda.1se")
#' # non-zero coefficients at lambda.min
#' predict(cvfit, s = "lambda.min", type = "nonzero")
#'
#' # predicted response
#' predict(cvfit, s = "lambda.min")
#' predict(cvfit, s = "lambda.1se")
#' # predict response at any value for lambda
#' predict(cvfit, s = 0.457)
#'
#' # predict response for new data set
#' newx <- sailsim$x * 1.10
#' newe <- sailsim$e * 2
#' predict(cvfit, newx = newx, newe = newe, s = "lambda.min")
#' }
#' }
#' @rdname cv.sail
#' @export
cv.sail <- function(x, y, e, ...,
Expand Down Expand Up @@ -259,7 +244,7 @@ cv.sail <- function(x, y, e, ...,
#' @return A vector of CV fold ID's for each observation in \code{y}
#' @details For numeric y, the sample is split into groups sections based on
#' percentiles and sampling is done within these subgroups
#' @references \url{http://topepo.github.io/caret/splitting.html}
#' @references \url{https://topepo.github.io/caret/data-splitting.html}
createfolds <- function(y, k = 10, list = FALSE, returnTrain = FALSE) {
if (class(y)[1] == "Surv") {
y <- y[, "time"]
Expand Down Expand Up @@ -335,7 +320,7 @@ createfolds <- function(y, k = 10, list = FALSE, returnTrain = FALSE) {
#' @rdname cv.lspath
#' @seealso \code{\link{cv.sail}}
#' @details The output of the \code{cv.lspath} function only returns values for
#' those tuning paramters that converged. \code{cvcompute, getmin,
#' those tuning parameters that converged. \code{cvcompute, getmin,
#' lambda.interp} are taken verbatim from the \code{glmnet} package
#' @references Jerome Friedman, Trevor Hastie, Robert Tibshirani (2010).
#' Regularization Paths for Generalized Linear Models via Coordinate Descent.
Expand Down
30 changes: 15 additions & 15 deletions R/kkt.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ KKT <- function(b0, betaE, beta, gamma, alpha, y, phij, xe_phij, e, df,

for (l in 1:length(lambda)) {
if (abs(B0[l, ]) > thr) {
cat("violate at b0 ", B0[l, ], " lambda=", lambda[l], "\n")
warning("violate at b0 ", B0[l, ], " lambda=", lambda[l], "\n")
ctr <- ctr + 1
}
}

cat("% of violations for beta0", ctr / length(lambda), "\n")
warning("% of violations for beta0", ctr / length(lambda), "\n")


# KKT for betaE -----------------------------------------------------------
Expand All @@ -147,19 +147,19 @@ KKT <- function(b0, betaE, beta, gamma, alpha, y, phij, xe_phij, e, df,
if (betaE[l] == 0) {
BE <- dl_norm_betaE / (-lambda[l] * (1 - lambda2) * we)
if (abs(BE) > 1 + thr) {
cat("violate at bE = 0", abs(BE), " lambda=", lambda[l], "\n")
warning("violate at bE = 0", abs(BE), " lambda=", lambda[l], "\n")
ctr <- ctr + 1
}
} else {
BE <- as.vector(dl_norm_betaE + lambda[l] * (1 - lambda2) * we * sign(betaE[l]))
if (abs(BE) > thr) {
cat("violate at bE != 0", abs(BE), " lambda=", lambda[l], "\n")
warning("violate at bE != 0", abs(BE), " lambda=", lambda[l], "\n")
ctr <- ctr + 1
} # else {cat("no violation at bE != 0", BE, " lambda=",lambda[l], "\n")}
} # else {warning("no violation at bE != 0", BE, " lambda=",lambda[l], "\n")}
}
}

cat("% of violations for betaE", ctr / length(lambda), "\n")
warning("% of violations for betaE", ctr / length(lambda), "\n")
# return(list(v = ctr/length(lambda)))

# browser()
Expand All @@ -181,20 +181,20 @@ KKT <- function(b0, betaE, beta, gamma, alpha, y, phij, xe_phij, e, df,
if (gamma[g, l] == 0) {
BE <- dl_norm_gammaj / (-lambda[l] * (1 - lambda2) * we)
if (abs(BE) > 1 + thr) {
cat("violate at gamma_j = 0", BE, " lambda=", lambda[l], "\n")
warning("violate at gamma_j = 0", BE, " lambda=", lambda[l], "\n")
ctr <- ctr + 1
}
} else {
BE <- as.vector(dl_norm_gammaj + lambda[l] * (1 - lambda2) * we * sign(gamma[g, l]))
if (abs(BE) > thr) {
cat("violate at gamma_j != 0", BE, " lambda=", lambda[l], "\n")
warning("violate at gamma_j != 0", BE, " lambda=", lambda[l], "\n")
ctr <- ctr + 1
} # else {cat("no violation at bE != 0", BE, " lambda=",lambda[l], "\n")}
} # else {warning("no violation at bE != 0", BE, " lambda=",lambda[l], "\n")}
}
}
}

cat("% of violations for gamma", ctr / length(lambda), "\n")
warning("% of violations for gamma", ctr / length(lambda), "\n")



Expand Down Expand Up @@ -223,22 +223,22 @@ KKT <- function(b0, betaE, beta, gamma, alpha, y, phij, xe_phij, e, df,

if (b_norm != 0) {
AA <- dl_prod + beta[ind, l] * lambda[l] * (1 - lambda2) * wj[g] / b_norm
# cat(AA,"\n")
# warning(AA,"\n")
if (sum(abs(AA)) >= thr) {
cat("violate at bX != 0", sum(abs(AA)), " lambda=", lambda[l], "\n")
warning("violate at bX != 0", sum(abs(AA)), " lambda=", lambda[l], "\n")
ctr <- ctr + 1
}
} else {
BB <- dl_norm - lambda[l] * (1 - lambda2) * wj[g]
# cat(BB,"\n")
# warning(BB,"\n")
if (BB > thr) {
cat("violate at bX = 0", BB, " lambda=", lambda[l], "\n")
warning("violate at bX = 0", BB, " lambda=", lambda[l], "\n")
ctr <- ctr + 1
}
}
}
}
cat("% of violations for bTheta", ctr / length(lambda), "\n")
warning("% of violations for bTheta", ctr / length(lambda), "\n")
return(ctr / length(lambda))
}
# nocov end
Loading

0 comments on commit 089edda

Please sign in to comment.