Skip to contents

Residuals

Usage

# S3 method for class 'cv.corila'
residuals(object, ...)

Arguments

object

object of class "cv.corila"

...

(for compatibility with stats::residuals)

Value

Returns a numeric vector of length \(n_0\) (one entry for each training observation).

Details

This function extracts the observed and fitted values from the fitted model and calls the internal function .residuals() to calculate the residuals.

Examples

# listing S3 methods
methods(class = "cv.corila")
#> [1] coef      deviance  fitted    nobs      plot      predict   print    
#> [8] residuals summary  
#> see '?methods' for accessing help and source code

# simulating data
n <- 10L; p <- 20L; q <- 5L
x <- matrix(rnorm(n * p), nrow = n , ncol = p)
y <- rnorm(n)
group <- rep(seq_len(q), length.out = p)
primary <- as.logical(rbinom(n = p, size = 1L, prob = 0.5))

# fitting the model
object <- cv.corila(x = x, y = y, group = group, primary = primary)
#> Warning: Option grouped=FALSE enforced in cv.glmnet, since < 3 observations per fold
#>    wgt_local exp_local wgt_global exp_global threshold      cvm
#> 11         1         0          0        Inf         0 1.792635

# using S3 methods
coef(object)
#> (intercept)        <NA>        <NA>        <NA>        <NA>        <NA> 
#>   0.1910942  -0.4528897   0.0000000   0.0000000   0.0000000   0.0000000 
#>        <NA>        <NA>        <NA>        <NA>        <NA>        <NA> 
#>   0.0000000   0.0000000   0.0000000  -0.2268216   0.0000000   0.0000000 
#>        <NA>        <NA>        <NA>        <NA>        <NA>        <NA> 
#>   0.0000000   0.0000000   0.0000000   0.0000000   0.0000000   0.0000000 
#>        <NA>        <NA>        <NA> 
#>   0.0000000   0.0000000   0.0000000 
predict(object, newx = x)
#>  [1] -0.186875744  0.816536087  0.461487360 -0.302035846  0.296781032
#>  [6]  0.418972095  0.009587133 -0.740386858  0.045254514  0.648661414
fitted(object)
#>  [1] -0.186875744  0.816536087  0.461487360 -0.302035846  0.296781032
#>  [6]  0.418972095  0.009587133 -0.740386858  0.045254514  0.648661414
residuals(object)
#>  [1] -0.53418090  0.19316925  0.35717618 -0.18173426 -0.28458351  1.49568597
#>  [7]  0.35078531 -0.60900795 -0.03311259 -0.75419750
plot(object)

print(object)
#> object of class ‘cv.corila’ 
#> (contains multiple objects of class ‘cv.glmnet’)
#> selected 2 from 20 predictors
summary(object)
#> --- object of class “cv.corila” --- 
#> generalised linear model with gaussian family 
#> 20 features (10 primary and 10 auxiliary features)
#> initial coefficients: ridge regression 
#> final coefficients: adaptive lasso regression 
#> optimised regularisation parameter: lambda.min = 0.3004 
#> selected weights: local = 1, global = 0
#> selected exponents: local = 0, global = Inf
#> 3 non-zero coefficients (including intercept)