Last chance! 50% off unlimited learning
Sale ends in
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.
rarefit.cv(fitObj, y, X, errtype = "mean-squared-error", nfolds = 5,
...)
A length-nfolds
list with the kth element being elements in the k
th fold.
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 k
th fold.
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]
.
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]
.
Indices of pair of (lambda
, alpha
) minimizing CV error.
Value of lambda
minimizing CV error.
Value of alpha
minimizing CV error.
Output of rarefit
Response variable.
nobs
-by-nvars
input matrix:
each row is an observation vector and each column stores
a count covariate.
Type of error metric used in cross validation. Available choices are mean-squared-error (default) and mean-absolute-error.
Number of folds (default is 5)
Other arguments that can be passed to rarefit
rarefit
, rarefit.predict
if (FALSE) {
# 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)
}
Run the code above in your browser using DataLab