Err.lsgl: Error Rates

Description Usage Arguments Value Author(s) Examples

View source: R/navigate.R

Description

Compute and return an error for each model. The error may be spicifed in the loss argument.

The root-mean-square error (RMSE) is

\frac{1}{K}∑_{i = 1}^K √{\frac{1}{N}∑_{j=1}^N (Y_{ji}-(X\hat β)_{ji})^2}

RMSE is the default error.

The objective value error (OVE) is

\|Y - X\hat β\|_F

The scaled objective value error (SOVE) is

\frac{1}{NK}\|Y - X\hat β\|_F

Usage

1
2
3
## S3 method for class 'lsgl'
Err(object, data = NULL, response = object$Y.true,
  loss = "RMSE", ...)

Arguments

object

a lsgl object.

data

a design matrix (the X matrix).

response

a matrix of the true responses (the Y matrix).

loss

the loss (error) function. Either a function taking two arguments or one of the following character strings RMSE, OVE or SOVE.

...

ignored.

Value

a vector of errors.

Author(s)

Martin Vincent

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
set.seed(100) # This may be removed, it ensures consistency of the daily tests

## Simulate from Y=XB+E, the dimension of Y is N x K, X is N x p, B is p x K

N <- 100 #number of samples
p <- 50 #number of features
K <- 15  #number of groups

# simulate beta matrix and X matrix
B<-matrix(sample(c(rep(1,p*K*0.1),rep(0, p*K-as.integer(p*K*0.1)))),nrow=p,ncol=K)
X1<-matrix(rnorm(N*p,1,1),nrow=N,ncol=p)
Y1 <-X1%*%B+matrix(rnorm(N*K,0,1),N,K)

X2<-matrix(rnorm(N*p,1,1),nrow=N,ncol=p)
Y2 <-X2%*%B+matrix(rnorm(N*K,0,1),N,K)

#### Fit models using X1
lambda <- lsgl::lambda(X1, Y1, alpha = 1, d = 25L, lambda.min = 5, intercept = FALSE)
fit <- lsgl::fit(X1, Y1, alpha = 1, lambda = lambda, intercept = FALSE)

## Training errors:
Err(fit, X1)

## Errors predicting Y2:
Err(fit, X2, Y2)

#### Do cross validation
fit.cv <- lsgl::cv(X1, Y1, alpha = 1, lambda = lambda, intercept = FALSE)

## Cross validation errors (estimated expected generalization error)
Err(fit.cv)

## Cross validation errors using objective value error measures
Err(fit.cv, loss = "OVE")

lsgl documentation built on May 29, 2017, 11:43 a.m.