cv.BTLLasso: Cross-validation function for BTLLasso

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/cv.BTLLasso.R

Description

Performs cross-validation of BTLLasso, including the BTLLasso algorithm for the whole data set.

Usage

1
2
3
cv.BTLLasso(Y, X = NULL, Z1 = NULL, Z2 = NULL, folds = 10,
  lambda = NULL, 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. If NULL, automatically a grid of tuning parameters is created.

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.

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 intervalls using boot.BTLLasso.

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.

df

Vector containing degrees of freedom for all models along the grid of tuning parameters.

Author(s)

Gunther Schauberger
[email protected]
http://www.semsto.statistik.uni-muenchen.de/personen/doktoranden/schauberger/index.html

References

Schauberger, Gunther and Tutz, Gerhard (2017): Subject-specific modelling of paired comparison data: A lasso-type penalty approach, Statistical Modelling, 17(3), 223 - 243

Schauberger, Gunther, Groll Andreas and Tutz, Gerhard (2017): Analysis of the importance of on-field covariates in the German Bundesliga, Journal of Applied Statistics, published online

See Also

BTLLasso, boot.BTLLasso, ctrl.BTLLasso, plot.BTLLasso, paths, print.cv.BTLLasso, predict.BTLLasso, coef

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
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
## Not run: 
op <- par(no.readonly = TRUE)

##############################
##### Example with simulated data set containing X, Z1 and Z2
##############################
data(SimData)

## 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, control = ctrl)
m.sim

par(xpd = TRUE)
plot(m.sim)


## Cross-validate BTLLasso model for tuning parameters lambda
set.seed(1860)
m.sim.cv <- cv.BTLLasso(Y = SimData$Y, X = SimData$X, Z1 = SimData$Z1,
                        Z2 = SimData$Z2, control = ctrl)
m.sim.cv
coef(m.sim.cv)
logLik(m.sim.cv)

head(predict(m.sim.cv, type="response"))
head(predict(m.sim.cv, type="trait"))

plot(m.sim.cv, plots_per_page = 4)


## Example for bootstrap intervals for illustration only
## Don't calculate bootstrap intervals with B = 20!!!!
set.seed(1860)
m.sim.boot <- boot.BTLLasso(m.sim.cv, B = 20, cores = 20)
m.sim.boot
plot(m.sim.boot, plots_per_page = 4)


##############################
##### 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)')

## Cross-validate BTLLasso model
m.gles.cv <- cv.BTLLasso(Y = Y, X = X, Z1 = Z1)
m.gles.cv

coef(m.gles.cv)
logLik(m.gles.cv)

head(predict(m.gles.cv, type="response"))
head(predict(m.gles.cv, type="trait"))

par(xpd = TRUE, mar = c(5,4,4,6))
plot(m.gles.cv, subs.X = subs.X, plots_per_page = 4, which = 2:5)
paths(m.gles.cv, y.axis = 'L2')


##############################
##### Example with Bundesliga data set
##############################
data(Buli1516)

Y <- Buli1516$Y5

Z1 <- scale(Buli1516$Z1, scale = FALSE)

ctrl.buli <- ctrl.BTLLasso(object.order.effect = TRUE, 
                           name.order = "Home", 
                           penalize.order.effect.diffs = TRUE, 
                           penalize.order.effect.absolute = FALSE,
                           order.center = TRUE, lambda2 = 1e-2)

set.seed(1860)
m.buli <- cv.BTLLasso(Y = Y, Z1 = Z1, control = ctrl.buli)
m.buli

par(xpd = TRUE, mar = c(5,4,4,6))
plot(m.buli)


##############################
##### Example with Topmodel data set
##############################
data("Topmodel2007", package = "psychotree")

Y.models <- response.BTLLasso(Topmodel2007$preference)
X.models <- scale(model.matrix(preference~., data = Topmodel2007)[,-1])
rownames(X.models) <- paste0("Subject",1:nrow(X.models))
colnames(X.models) <- c("Gender","Age","KnowShow","WatchShow","WatchFinal")

set.seed(5)
m.models <- cv.BTLLasso(Y = Y.models, X = X.models)
plot(m.models, plots_per_page = 6)

par(op)

## End(Not run)

BTLLasso documentation built on Nov. 17, 2017, 6:41 a.m.