rarefit.cv: Perform K-fold cross validation

Description Usage Arguments Value See Also Examples

Description

The function does K-fold cross validaton (CV) to choose an optimal pair of (lambda, alpha) on which the model performs best according to the chosen error metric: mean squared error or mean absolute error.

Usage

1
2
rarefit.cv(fitObj, y, X, errtype = "mean-squared-error", nfolds = 5,
  ...)

Arguments

fitObj

Output of rarefit

y

Response variable.

X

nobs-by-nvars input matrix: each row is an observation vector and each column stores a count covariate.

errtype

Type of error metric used in cross validation. Available choices are mean-squared-error (default) and mean-absolute-error.

nfolds

Number of folds (default is 5)

...

Other arguments that can be passed to rarefit

Value

folds

A length-nfolds list with the kth element being elements in the kth fold.

errs

A nlam-by-nalpha-by-nfolds 3-dimensional array of errors. errs[i,j,k] is error incurred in using lambda[i] and alpha[j] on the kth fold.

m

A nlam-by-nalpha matrix for storing CV error (i.e., mean error across folds). m[i,j] is CV error incurred in using lambda[i] and alpha[j].

se

A nlam-by-nalpha matrix for storing standard error across folds. se[i,j] is standard error incurred in using lambda[i] and alpha[j].

ibest

Indices of pair of (lambda, alpha) minimizing CV error.

lambda.best

Value of lambda minimizing CV error.

alpha.best

Value of alpha minimizing CV error.

See Also

rarefit, rarefit.predict

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
# See vignette for more details.
set.seed(100)
ts <- sample(1:length(data.rating), 400) # Train set indices
# Fit the model on train set
ourfit <- rarefit(y = data.rating[ts], X = data.dtm[ts, ], hc = data.hc, lam.min.ratio = 1e-6,
                  nlam = 20, nalpha = 10, rho = 0.01, eps1 = 1e-5, eps2 = 1e-5, maxite = 1e4)
# Cross validation
ourfit.cv <- rarefit.cv(ourfit, y = data.rating[ts], X = data.dtm[ts, ],
                        rho = 0.01, eps1 = 1e-5, eps2 = 1e-5, maxite = 1e4)

## End(Not run)

rare documentation built on May 1, 2019, 9:17 p.m.