Learn R Programming

BTLLasso (version 0.1-5)

cv.BTLLasso: Cross-validation function for BTLLasso

Description

Performs crossvalidation of BTLLasso, including the BTLLasso algorithm for the whole data set.

Usage

cv.BTLLasso(Y, X = NULL, Z1 = NULL, Z2 = NULL, folds = 10, lambda,
  control = ctrl.BTLLasso(), cores = folds, trace = TRUE,
  trace.cv = TRUE, cv.crit = c("RPS", "Deviance"))

Arguments

Y
A response.BTLLasso object created by response.BTLLasso.
X
Matrix containing all subject-specific covariates that are to be included with object-specific effects. One row represents one subject, one column represents one covariate. X has to be standardized.
Z1
Matrix containing all object-subject-specific covariates that are to be included with object-specific effects. One row represents one subject, one column represents one combination between covariate and object. Column names have to follow the scheme 'firstvar.object1',...,'firstvar.objectm',...,'lastvar.objectm'. The object names 'object1',...,'objectm' have to be identical to the object names used in the response.BTLLasso object Y. The variable names and the object names have to be separated by '.'. The rownames of the matrix', Z.name, 'have to be equal to the subjects specified in the response object. Z1 has to be standardized.
Z2
Matrix containing all object-subject-specific covariates or object-specific covariates that are to be included with global effects. One row represents one subject, one column represents one combination between covariate and object. Column names have to follow the scheme 'firstvar.object1',...,'firstvar.objectm',...,'lastvar.objectm'. The object names 'object1',...,'objectm' have to be identical to the object names used in the response.BTLLasso object Y. The variable names and the object names have to be separated by '.'. The rownames of the matrix', Z.name, 'have to be equal to the subjects specified in the response object. Z2 has to be standardized.
folds
Number of folds for the crossvalidation. Default is 10.
lambda
Vector of tuning parameters.
control
Function for control arguments, mostly for internal use. See also ctrl.BTLLasso.
cores
Number of cores used for (parallelized) cross-validation. By default, equal to the number of folds.
trace
Should the trace of the BTLLasso algorithm be printed?
trace.cv
Should the trace fo the cross-validation be printed? If parallelized, the trace is not working on Windows machines.
cv.crit
Which criterion should be used to evaluate cross-validation. Choice is between Ranked probability score and deviance. Only RPS considers the ordinal structure of the response.

Value

coefs
Matrix containing all (original) coefficients, one row per tuning parameter, one column per coefficient.
coefs.repar
Matrix containing all reparameterized (for symmetric side constraint) coefficients, one row per tuning parameter, one column per coefficient.
logLik
Vector of log-likelihoods, one value per tuning parameter.
design
List containing design matrix and several additional information like, e.g., number and names of covariates.
Y
Response object.
penalty
List containing all penalty matrices and some further information on penalties
response
Vector containing 0-1 coded response.
X
X matrix containing subject-specific covariates.
Z1
Z1 matrix containing subject-object-specific covariates.
Z2
Z2 matrix containing (subject)-object-specific covariates.
lambda
Vector of tuning parameters.
control
Control argument, specified by ctrl.BTLLasso.
criterion
Vector containing values of the chosen cross-validation criterion, one value per tuning parameter.
folds
Number of folds in cross validation.
cv.crit
Cross-validation criterion, either RPS or Deviance.

Details

Cross validation can be performed parallel, default is 10-fold cross validation on 10 cores. Output is a cv.BTLLasso object which can then be used for bootstrap confidence intervalls using boot.BTLLasso and ci.BTLLasso.

References

Schauberger, Gunther and Tutz, Gerhard (2015): Modelling Heterogeneity in Paired Comparison Data - an L1 Penalty Approach with an Application to Party Preference Data, Department of Statistics, LMU Munich, Technical Report 183

Schauberger, Gunther, Groll Andreas and Tutz, Gerhard (2016): Modelling Football Results in the German Bundesliga Using Match-specific Covariates, Department of Statistics, LMU Munich, Technical Report 197

See Also

BTLLasso, boot.BTLLasso, ctrl.BTLLasso, singlepaths, paths

Examples

Run this code

## Not run: ------------------------------------
# ##### Example with simulated data set containing X, Z1 and Z2
# data(SimData)
# 
# ## Specify tuning parameters
# lambda <- exp(seq(log(151), log(1.05), length = 30)) - 1
# 
# ## Specify control argument
# ## -> allow for object-specific order effects and penalize intercepts
# ctrl <- ctrl.BTLLasso(penalize.intercepts = TRUE, object.order.effect = TRUE,
#                       penalize.order.effect.diffs = TRUE)
# 
# ## Simple BTLLasso model for tuning parameters lambda
# m.sim <- BTLLasso(Y = SimData$Y, X = SimData$X, Z1 = SimData$Z1, 
#                   Z2 = SimData$Z2, lambda = lambda, control = ctrl)
# print(m.sim)
# 
# singlepaths(m.sim)
# 
# ## Cross-validate BTLLasso model for tuning parameters lambda
# set.seed(5)
# m.sim.cv <- cv.BTLLasso(Y = SimData$Y, X = SimData$X, Z1 = SimData$Z1, 
#                         Z2 = SimData$Z2, lambda = lambda, control = ctrl)
# print(m.sim.cv)
# 
# singlepaths(m.sim.cv, plot.order.effect = FALSE, 
#             plot.intercepts = FALSE, plot.Z2 = FALSE)
# paths(m.sim.cv, y.axis = 'L2')
# 
# ## Example for bootstrap confidence intervals for illustration only
# ## Don't calculate bootstrap confidence intervals with B = 10!!!!
# set.seed(5)
# m.sim.boot <- boot.BTLLasso(m.sim.cv, B = 10, cores = 10)
# print(m.sim.boot)
# ci.BTLLasso(m.sim.boot)
# 
# 
# ##### Example with small version from GLES data set
# data(GLESsmall)
# 
# ## extract data and center covariates for better interpretability
# Y <- GLESsmall$Y
# X <- scale(GLESsmall$X, scale = FALSE)
# Z1 <- scale(GLESsmall$Z1, scale = FALSE)
# 
# ## vector of subtitles, containing the coding of the X covariates
# subs.X <- c('', 'female (1); male (0)')
# 
# ## vector of tuning parameters
# lambda <- exp(seq(log(61), log(1), length = 30)) - 1
# 
# 
# ## compute BTLLasso model 
# m.gles <- BTLLasso(Y = Y, X = X, Z1 = Z1, lambda = lambda)
# print(m.gles)
# 
# singlepaths(m.gles, subs.X = subs.X)
# paths(m.gles, y.axis = 'L2')
# 
# ## Cross-validate BTLLasso model 
# m.gles.cv <- cv.BTLLasso(Y = Y, X = X, Z1 = Z1, lambda = lambda)
# print(m.gles.cv)
# 
# singlepaths(m.gles.cv, subs.X = subs.X)
## ---------------------------------------------

Run the code above in your browser using DataLab