Skip to content

Commit

Permalink
@gvegayon @chipmanj My dirty work... I will get things done over the …
Browse files Browse the repository at this point in the history
  • Loading branch information
Haojia-biostat committed Mar 17, 2023
0 parents commit 2217413
Show file tree
Hide file tree
Showing 21 changed files with 750 additions and 0 deletions.
19 changes: 19 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Package: ImbLassoRcpp
Type: Package
Title: LASSO for Logistic Regression with Imbalanced Outcome by Rcpp (Title Case)
Version: 0.1.0
Author: Haojia Li
Maintainer: Haojia Li <[email protected]>
Description: More about what it does (maybe more than one line)
Use four spaces when indenting paragraphs within the Description.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
RoxygenNote: 7.2.3
LinkingTo:
Rcpp
Imports:
Rcpp
21 changes: 21 additions & 0 deletions ImbLassoRcpp.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
YEAR: 2023
COPYRIGHT HOLDER: Haojia Li
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2023 ImbLassoRcpp authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by roxygen2: do not edit by hand

export(lambda_gen)
47 changes: 47 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

coord_desc <- function(X, y, lambda, thresh = 1e-7, maxit = 1e5L) {
.Call('_ImbLassoRcpp_coord_desc', PACKAGE = 'ImbLassoRcpp', X, y, lambda, thresh, maxit)
}

logit_i <- function(X, b0, b) {
.Call('_ImbLassoRcpp_logit_i', PACKAGE = 'ImbLassoRcpp', X, b0, b)
}

#'run the coordinate descent algorithm on the penalized weighted-least-squares
#'
#'Update the quadratic approx
#'
#'@name single_coord_des
#'
#'@param X input matrix, of dimension nobs x nvars; each row is an observation vector.
#'@param y binary response variable, positive outcome = 1 and negative outcome = 0.
#'@param lambda A user supplied lambda
#'@param thresh Convergence threshold for coordinate descent. Each inner coordinate-descent loop continues until the maximum change in the objective after any coefficient update is less than thresh times the null deviance. Defaults value is 1E-7.
#'@param maxit Maximum number of passes over the data for all lambda values; default is 10^5.
#'
betamat <- function(X, y, lambda, thresh = 1e-7, maxit = 1e5L) {
.Call('_ImbLassoRcpp_betamat', PACKAGE = 'ImbLassoRcpp', X, y, lambda, thresh, maxit)
}

prob_i <- function(logit) {
.Call('_ImbLassoRcpp_prob_i', PACKAGE = 'ImbLassoRcpp', logit)
}

smoteCpp <- function(X, y, k, m) {
.Call('_ImbLassoRcpp_smoteCpp', PACKAGE = 'ImbLassoRcpp', X, y, k, m)
}

soft_thresh <- function(z, gamma) {
.Call('_ImbLassoRcpp_soft_thresh', PACKAGE = 'ImbLassoRcpp', z, gamma)
}

stratifiedCpp <- function(X, y, size) {
.Call('_ImbLassoRcpp_stratifiedCpp', PACKAGE = 'ImbLassoRcpp', X, y, size)
}

weight_i <- function(prob) {
.Call('_ImbLassoRcpp_weight_i', PACKAGE = 'ImbLassoRcpp', prob)
}

54 changes: 54 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# ImbLassoRcpp

<!-- badges: start -->
<!-- badges: end -->

The goal of ImbLassoRcpp is to ...

## Installation

You can install the development version of ImbLassoRcpp like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(ImbLassoRcpp)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this. You could also use GitHub Actions to re-render `README.Rmd` every time you push. An example workflow can be found here: <https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# ImbLassoRcpp

<!-- badges: start -->
<!-- badges: end -->

The goal of ImbLassoRcpp is to …

## Installation

You can install the development version of ImbLassoRcpp like so:

``` r
# FILL THIS IN! HOW CAN PEOPLE INSTALL YOUR DEV PACKAGE?
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(ImbLassoRcpp)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`?
You can include R chunks like so:

``` r
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
```

You’ll still need to render `README.Rmd` regularly, to keep `README.md`
up-to-date. `devtools::build_readme()` is handy for this. You could also
use GitHub Actions to re-render `README.Rmd` every time you push. An
example workflow can be found here:
<https://github.com/r-lib/actions/tree/v1/examples>.

You can also embed plots, for example:

<img src="man/figures/README-pressure-1.png" width="100%" />

In that case, don’t forget to commit and push the resulting figure
files, so they display on GitHub and CRAN.
Binary file added man/figures/README-pressure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions man/lambda_gen.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.dll
133 changes: 133 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <Rcpp.h>

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// coord_desc
NumericVector coord_desc(NumericMatrix X, NumericVector y, double lambda, double thresh, int maxit);
RcppExport SEXP _ImbLassoRcpp_coord_desc(SEXP XSEXP, SEXP ySEXP, SEXP lambdaSEXP, SEXP threshSEXP, SEXP maxitSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type X(XSEXP);
Rcpp::traits::input_parameter< NumericVector >::type y(ySEXP);
Rcpp::traits::input_parameter< double >::type lambda(lambdaSEXP);
Rcpp::traits::input_parameter< double >::type thresh(threshSEXP);
Rcpp::traits::input_parameter< int >::type maxit(maxitSEXP);
rcpp_result_gen = Rcpp::wrap(coord_desc(X, y, lambda, thresh, maxit));
return rcpp_result_gen;
END_RCPP
}
// logit_i
NumericVector logit_i(NumericMatrix X, double b0, NumericVector b);
RcppExport SEXP _ImbLassoRcpp_logit_i(SEXP XSEXP, SEXP b0SEXP, SEXP bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type X(XSEXP);
Rcpp::traits::input_parameter< double >::type b0(b0SEXP);
Rcpp::traits::input_parameter< NumericVector >::type b(bSEXP);
rcpp_result_gen = Rcpp::wrap(logit_i(X, b0, b));
return rcpp_result_gen;
END_RCPP
}
// betamat
mat betamat(NumericMatrix X, NumericVector y, double lambda, double thresh, int maxit);
RcppExport SEXP _ImbLassoRcpp_betamat(SEXP XSEXP, SEXP ySEXP, SEXP lambdaSEXP, SEXP threshSEXP, SEXP maxitSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericMatrix >::type X(XSEXP);
Rcpp::traits::input_parameter< NumericVector >::type y(ySEXP);
Rcpp::traits::input_parameter< double >::type lambda(lambdaSEXP);
Rcpp::traits::input_parameter< double >::type thresh(threshSEXP);
Rcpp::traits::input_parameter< int >::type maxit(maxitSEXP);
rcpp_result_gen = Rcpp::wrap(betamat(X, y, lambda, thresh, maxit));
return rcpp_result_gen;
END_RCPP
}
// prob_i
NumericVector prob_i(NumericVector logit);
RcppExport SEXP _ImbLassoRcpp_prob_i(SEXP logitSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type logit(logitSEXP);
rcpp_result_gen = Rcpp::wrap(prob_i(logit));
return rcpp_result_gen;
END_RCPP
}
// smoteCpp
NumericMatrix smoteCpp(const NumericMatrix& X, const IntegerVector& y, const int k, const int m);
RcppExport SEXP _ImbLassoRcpp_smoteCpp(SEXP XSEXP, SEXP ySEXP, SEXP kSEXP, SEXP mSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const NumericMatrix& >::type X(XSEXP);
Rcpp::traits::input_parameter< const IntegerVector& >::type y(ySEXP);
Rcpp::traits::input_parameter< const int >::type k(kSEXP);
Rcpp::traits::input_parameter< const int >::type m(mSEXP);
rcpp_result_gen = Rcpp::wrap(smoteCpp(X, y, k, m));
return rcpp_result_gen;
END_RCPP
}
// soft_thresh
double soft_thresh(double z, double gamma);
RcppExport SEXP _ImbLassoRcpp_soft_thresh(SEXP zSEXP, SEXP gammaSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< double >::type z(zSEXP);
Rcpp::traits::input_parameter< double >::type gamma(gammaSEXP);
rcpp_result_gen = Rcpp::wrap(soft_thresh(z, gamma));
return rcpp_result_gen;
END_RCPP
}
// stratifiedCpp
List stratifiedCpp(const NumericMatrix& X, const IntegerVector& y, const int size);
RcppExport SEXP _ImbLassoRcpp_stratifiedCpp(SEXP XSEXP, SEXP ySEXP, SEXP sizeSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const NumericMatrix& >::type X(XSEXP);
Rcpp::traits::input_parameter< const IntegerVector& >::type y(ySEXP);
Rcpp::traits::input_parameter< const int >::type size(sizeSEXP);
rcpp_result_gen = Rcpp::wrap(stratifiedCpp(X, y, size));
return rcpp_result_gen;
END_RCPP
}
// weight_i
NumericVector weight_i(NumericVector prob);
RcppExport SEXP _ImbLassoRcpp_weight_i(SEXP probSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< NumericVector >::type prob(probSEXP);
rcpp_result_gen = Rcpp::wrap(weight_i(prob));
return rcpp_result_gen;
END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_ImbLassoRcpp_coord_desc", (DL_FUNC) &_ImbLassoRcpp_coord_desc, 5},
{"_ImbLassoRcpp_logit_i", (DL_FUNC) &_ImbLassoRcpp_logit_i, 3},
{"_ImbLassoRcpp_betamat", (DL_FUNC) &_ImbLassoRcpp_betamat, 5},
{"_ImbLassoRcpp_prob_i", (DL_FUNC) &_ImbLassoRcpp_prob_i, 1},
{"_ImbLassoRcpp_smoteCpp", (DL_FUNC) &_ImbLassoRcpp_smoteCpp, 4},
{"_ImbLassoRcpp_soft_thresh", (DL_FUNC) &_ImbLassoRcpp_soft_thresh, 2},
{"_ImbLassoRcpp_stratifiedCpp", (DL_FUNC) &_ImbLassoRcpp_stratifiedCpp, 3},
{"_ImbLassoRcpp_weight_i", (DL_FUNC) &_ImbLassoRcpp_weight_i, 1},
{NULL, NULL, 0}
};

RcppExport void R_init_ImbLassoRcpp(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
Loading

0 comments on commit 2217413

Please sign in to comment.