0

I am interested in SplitReg package and I would like to know how the author developed his method inside the function 'cv.SplitReg', more precisely the function I want is 'Main_Ensemble_EN' and 'construct.cv.SplitReg'. I am a beginner in R, after research I found the Rcpp package but I can't find exactly the function in Rcpp that can help me to find the content of the function 'Main_Ensemble_EN' and 'construct.cv.SplitReg'. Thanks in advance.

functionBody(cv.SplitReg)
{
    if (all(!inherits(x, "matrix"), !inherits(x, "data.frame"))) {
        stop("x should belong to one of the following classes: matrix, data.frame")
    }
    else if (all(!inherits(y, "matrix"), all(!inherits(y, "numeric")))) {
        stop("y should belong to one of the following classes: matrix, numeric")
    }
    else if (any(anyNA(x), any(is.nan(x)), any(is.infinite(x)))) {
        stop("x should not have missing, infinite or nan values")
    }
    else if (any(anyNA(y), any(is.nan(y)), any(is.infinite(y)))) {
        stop("y should not have missing, infinite or nan values")
    }
    else {
        if (inherits(y, "matrix")) {
            if (ncol(y) > 1) {
                stop("y should be a vector")
            }
            y <- as.numeric(y)
        }
        len_y <- length(y)
        if (len_y != nrow(x)) {
            stop("y and x should have the same number of rows")
        }
    }
    if (!inherits(tolerance, "numeric")) {
        stop("tolerance should be numeric")
    }
    else if (!all(tolerance < 1, tolerance > 0)) {
        stop("tolerance should be between 0 and 1")
    }
    if (!inherits(alpha, "numeric")) {
        stop("alpha should be numeric")
    }
    else if (!all(alpha <= 1, alpha > 0)) {
        stop("alpha should be between 0 and 1")
    }
    if (!inherits(max_iter, "numeric")) {
        stop("max_iter should be numeric")
    }
    else if (any(!max_iter == floor(max_iter), max_iter <= 0)) {
        stop("max_iter should be a positive integer")
    }
    if (!inherits(num_models, "numeric")) {
        stop("num_models should be numeric")
    }
    else if (any(!num_models == floor(num_models), num_models <= 
        1)) {
        stop("num_models should be an integer, greater than one")
    }
    if (!inherits(num_lambdas_sparsity, "numeric")) {
        stop("num_lambdas_sparsity should be numeric")
    }
    else if (any(!num_lambdas_sparsity == floor(num_lambdas_sparsity), 
        num_lambdas_sparsity <= 0)) {
        stop("num_lambdas_sparsity should be a positive integer")
    }
    if (!inherits(num_lambdas_diversity, "numeric")) {
        stop("num_lambdas_diversity should be numeric")
    }
    else if (any(!num_lambdas_diversity == floor(num_lambdas_diversity), 
        num_lambdas_diversity <= 0)) {
        stop("num_lambdas_diversity should be a positive integer")
    }
    n <- nrow(x)
    random.permutation <- sample(1:n, n)
    x.permutation <- x[random.permutation, ]
    y.permutation <- y[random.permutation]
    output <- Main_Ensemble_EN(x.permutation, y.permutation, 
        num_lambdas_sparsity, num_lambdas_diversity, alpha, num_models, 
        tolerance, max_iter, num_folds, num_threads)
    fn_call <- match.call()
    output <- construct.cv.SplitReg(output, fn_call, x, y)
    return(output)
}

I tried Rcpp package and watch some video on youtub but I can't find what I need.

Phil
  • 7,287
  • 3
  • 36
  • 66
  • Welcome to StackOverflow. As best as I can tell the function you posted has nothing to with either Rcpp or RcppArmadillo. And sadly few people here will have the time to write a custom function for you on demand. – Dirk Eddelbuettel Feb 26 '23 at 17:53
  • If you go to the GH repo for the package, specifically this page: https://github.com/AnthonyChristidis/SplitReg/blob/master/src/SplitReg.cpp you can find the code for that function starting at line 437. – Phil Feb 27 '23 at 05:36
  • And the code for the other function here https://github.com/AnthonyChristidis/SplitReg/blob/master/R/methods.R – Phil Feb 27 '23 at 05:38
  • I'll look at the links. Thank you very much for your help. – user17674721 Feb 28 '23 at 00:27

0 Answers0