From 977427d27820fc05dc6c9f2f51598ea18bc2c69b Mon Sep 17 00:00:00 2001 From: Jeremy Coyle Date: Mon, 30 Oct 2023 13:31:32 -0700 Subject: [PATCH] * fix Matrix tests and other issues * bump version * update news --- .NEWS.md.swp | Bin 0 -> 1024 bytes DESCRIPTION | 4 ++-- NEWS.md | 3 +++ R/formula_hal9001.R | 2 +- R/predict.R | 22 ++++++++-------------- man/formula_helpers.Rd | 20 -------------------- man/generate_all_rules.Rd | 14 ++++++++++++++ 7 files changed, 28 insertions(+), 37 deletions(-) create mode 100644 .NEWS.md.swp delete mode 100644 man/formula_helpers.Rd create mode 100644 man/generate_all_rules.Rd diff --git a/.NEWS.md.swp b/.NEWS.md.swp new file mode 100644 index 0000000000000000000000000000000000000000..4f4015fd91609a8f5201fbe1dc78f29e0e435bc6 GIT binary patch literal 1024 zcmYc?$V<%2S1{4DU_b%avl$q&ijwmyb5c>nv2n8V@{^MD^9U;Ra}5vH%T2*%#HiS4 O2#kgR?L#0G-3kDeNDUJJ literal 0 HcmV?d00001 diff --git a/DESCRIPTION b/DESCRIPTION index 21c99e4b..a57654b8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hal9001 Title: The Scalable Highly Adaptive Lasso -Version: 0.4.5 +Version: 0.4.6 Authors@R: c( person("Jeremy", "Coyle", email = "jeremyrcoyle@gmail.com", role = c("aut", "cre"), @@ -68,5 +68,5 @@ LinkingTo: Rcpp, RcppEigen VignetteBuilder: knitr -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) diff --git a/NEWS.md b/NEWS.md index 777be02b..c04ae0c2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +# hal9001 0.4.6 +* Fixed predict method to address changes required by Matrix 1.6.2 + # hal9001 0.4.5 * Added multivariate outcome prediction diff --git a/R/formula_hal9001.R b/R/formula_hal9001.R index f30f06e1..9d8e3d68 100644 --- a/R/formula_hal9001.R +++ b/R/formula_hal9001.R @@ -216,7 +216,7 @@ h <- function(..., k = NULL, s = NULL, pf = 1, }) - basis_list_item <- hal9001:::make_basis_list( + basis_list_item <- make_basis_list( X[, col_index, drop = FALSE], col_index, rep(s, ncol(X)) ) diff --git a/R/predict.R b/R/predict.R index 3ef9f3ad..5767b4a9 100644 --- a/R/predict.R +++ b/R/predict.R @@ -80,16 +80,13 @@ predict.hal9001 <- function(object, # generate predictions if (!family %in% c("cox", "mgaussian")) { if (ncol(object$coefs) > 1) { - preds <- apply(object$coefs, 2, function(hal_coefs) { - as.vector(Matrix::tcrossprod( - x = pred_x_basis, - y = hal_coefs[-1] - ) + hal_coefs[1]) - }) + preds <- pred_x_basis%*%object$coefs[-1,]+ + matrix(object$coefs[1,], nrow=nrow(pred_x_basis), + ncol=ncol(object$coefs), byrow = TRUE) } else { preds <- as.vector(Matrix::tcrossprod( x = pred_x_basis, - y = object$coefs[-1] + y = matrix(object$coefs[-1],nrow=1) ) + object$coefs[1]) } } else { @@ -99,16 +96,13 @@ predict.hal9001 <- function(object, # Note: there is no intercept in the Cox model (built into the baseline # hazard and would cancel in the partial likelihood). if (ncol(object$coefs) > 1) { - preds <- apply(object$coefs, 2, function(hal_coefs) { - as.vector(Matrix::tcrossprod( - x = pred_x_basis, - y = hal_coefs - )) - }) + preds <- pred_x_basis%*%object$coefs[-1,]+ + matrix(object$coefs[1,], nrow=nrow(pred_x_basis), + ncol=ncol(object$coefs), byrow = TRUE) } else { preds <- as.vector(Matrix::tcrossprod( x = pred_x_basis, - y = as.vector(object$coefs) + y = as.matrix(object$coefs,nrow = 1) )) } } else if (family == "mgaussian") { diff --git a/man/formula_helpers.Rd b/man/formula_helpers.Rd deleted file mode 100644 index 893a2de1..00000000 --- a/man/formula_helpers.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/formula_hal9001.R -\name{formula_helpers} -\alias{formula_helpers} -\alias{fill_dots_helper} -\alias{fill_dots} -\title{Formula Helpers} -\usage{ -fill_dots_helper(var_names, .) - -fill_dots(var_names, .) -} -\arguments{ -\item{var_names}{A \code{character} vector of variable names.} - -\item{.}{Specification of variables for use in the formula.} -} -\description{ -Formula Helpers -} diff --git a/man/generate_all_rules.Rd b/man/generate_all_rules.Rd new file mode 100644 index 00000000..6fc2967a --- /dev/null +++ b/man/generate_all_rules.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/summary.R +\name{generate_all_rules} +\alias{generate_all_rules} +\title{Generates rules based on knot points of the fitted HAL basis functions with +non-zero coefficients.} +\usage{ +generate_all_rules(basis_list, coefs, X_colnames) +} +\description{ +Generates rules based on knot points of the fitted HAL basis functions with +non-zero coefficients. +} +\keyword{internal}