design: Design Matrix

Description Usage Arguments Value Author(s) Examples

View source: R/design.R

Description

This function returns the design matrix for an ordinal Bradley-Terry-Luce model.

Usage

1
2
3
design(X, var1, var2, use.vars=NULL, reference=NULL,
              prefix="GAMMA", prefix.home="ALPHA",
              home.advantage=c("no","specific","yes"))

Arguments

X

a data frame in long format (see wide2long).

var1

a character of the column name from X specifying the first object to be compared (or, in sport context, the home team).

var2

a character of the column name from X specifying the second object to be compared (or, in sport context, the away team).

use.vars

a character vector with the names of additional covariates of X that will additionally be included into the design matrix. (example: use.vars = c("ENG", "SEX")) if the covariates ENG and SEX should be included. If all covariates of X should be included, you can use use.vars = "ALL". The default is use.vars = NULL for no additional covariates.

reference

a character specifying the reference object.

prefix

(optional) a character added in the names of the estimated object parameters

prefix.home

(optional) a character added in the names of the estimated home advantage parameters

home.advantage

Note that the home advantage is equivalent to an order effect home.advantage="no" uses no home advantage (order effect), home.advantage="specific" uses one home advantage (order effect) for each object and home.advantage="yes" uses one home advantage (order effect) for any object.

Value

A data frame where each row refers to a pair comparison and each column corresponds to an object.

Author(s)

Giuseppe Casalicchio

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
# load german football-league (Bundesliga) data
library("wikibooks")
data(Bundesliga)

# add new variable Y3 reflecting the response which is coded as 
# 1 if the home team wins
# 2 if the game ends up with a tie
# 3 if the home team loses
diff <- Bundesliga$Tore.Heim - Bundesliga$Tore.Gast
Bundesliga$Y3 <- as.ordered(ifelse(diff >= 1, 1, 
                                   ifelse(diff <= -1, 3, 2)))
buli0506 <- subset(Bundesliga, Saison=="2005/2006")
str(buli0506)

# Design matrix without home advantage
des.nohome <- design(buli0506, var1="Heim", var2="Gast", 
                     home.advantage="no")
str(des.nohome)

# Design matrix with one home advantage parameter for all objects
des.onehome <- design(buli0506, var1="Heim", var2="Gast", 
                      home.advantage="yes")
str(des.onehome)

# Design matrix with home advantage parameters for each object
des.teamhome <- design(buli0506, var1="Heim", var2="Gast",
                       home.advantage="specific")
str(des.teamhome)

# Design matrix with additional covariable "Spieltag"
des.covs <- design(buli0506, var1="Heim", var2="Gast", 
                   use.vars=c("Spieltag"), home.advantage="no")
str(des.covs)

Example output

Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Loading required package: VGAM
Loading required package: stats4
Loading required package: splines

Attaching package: 'VGAM'

The following object is masked from 'package:caret':

    predictors

Loading required package: wikibooks
Loading required package: gtools

Attaching package: 'gtools'

The following object is masked from 'package:VGAM':

    logit

'data.frame':	306 obs. of  11 variables:
 $ Saison            : Factor w/ 44 levels "1963/1964","1964/1965",..: 43 43 43 43 43 43 43 43 43 43 ...
 $ Spieltag          : int  1 1 1 1 1 1 1 1 1 2 ...
 $ Datum             : Date, format: "2005-08-05" "2005-08-06" ...
 $ Anpfiff           : Factor w/ 31 levels "14:00","14:15",..: 28 6 6 6 6 6 6 15 15 6 ...
 $ Heim              : Factor w/ 50 levels "1. FC Kaiserslautern",..: 18 2 31 24 49 40 25 20 16 8 ...
 $ Gast              : Factor w/ 50 levels "1. FC Kaiserslautern",..: 11 5 47 3 10 7 27 1 8 18 ...
 $ Tore.Heim         : int  3 1 1 3 2 5 2 2 1 2 ...
 $ Tore.Gast         : int  0 0 1 0 2 2 2 1 4 5 ...
 $ Tore.Heim.Halbzeit: int  1 0 1 2 1 3 0 0 1 1 ...
 $ Tore.Gast.Halbzeit: int  0 0 1 0 0 2 0 1 1 3 ...
 $ Y3                : Ord.factor w/ 3 levels "1"<"2"<"3": 1 1 2 1 2 1 2 1 3 3 ...
'data.frame':	306 obs. of  18 variables:
 $ GAMMA.1.FC.Kaiserslautern      : num  0 0 0 0 0 0 0 -1 0 0 ...
 $ GAMMA.1.FC.Koeln               : num  0 1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.1.FC.Nuernberg           : num  0 0 0 -1 0 0 0 0 0 0 ...
 $ GAMMA.1.FSV.Mainz.05           : num  0 -1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Arminia.Bielefeld        : num  0 0 0 0 0 -1 0 0 0 0 ...
 $ GAMMA.Bayer.Leverkusen         : num  0 0 0 0 0 0 0 0 -1 1 ...
 $ GAMMA.Borussia.Dortmund        : num  0 0 0 0 -1 0 0 0 0 0 ...
 $ GAMMA.Borussia.Moenchengladbach: num  -1 0 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Eintracht.Frankfurt      : num  0 0 0 0 0 0 0 0 1 0 ...
 $ GAMMA.FC.Bayern.Muenchen       : num  1 0 0 0 0 0 0 0 0 -1 ...
 $ GAMMA.FC.Schalke.04            : num  0 0 0 0 0 0 0 1 0 0 ...
 $ GAMMA.Hamburger.SV             : num  0 0 0 1 0 0 0 0 0 0 ...
 $ GAMMA.Hannover.96              : num  0 0 0 0 0 0 1 0 0 0 ...
 $ GAMMA.Hertha.BSC.Berlin        : num  0 0 0 0 0 0 -1 0 0 0 ...
 $ GAMMA.MSV.Duisburg             : num  0 0 1 0 0 0 0 0 0 0 ...
 $ GAMMA.SV.Werder.Bremen         : num  0 0 0 0 0 1 0 0 0 0 ...
 $ GAMMA.VfB.Stuttgart            : num  0 0 -1 0 0 0 0 0 0 0 ...
 $ GAMMA.VfL.Wolfsburg            : num  0 0 0 0 1 0 0 0 0 0 ...
'data.frame':	306 obs. of  19 variables:
 $ GAMMA.1.FC.Kaiserslautern      : num  0 0 0 0 0 0 0 -1 0 0 ...
 $ GAMMA.1.FC.Koeln               : num  0 1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.1.FC.Nuernberg           : num  0 0 0 -1 0 0 0 0 0 0 ...
 $ GAMMA.1.FSV.Mainz.05           : num  0 -1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Arminia.Bielefeld        : num  0 0 0 0 0 -1 0 0 0 0 ...
 $ GAMMA.Bayer.Leverkusen         : num  0 0 0 0 0 0 0 0 -1 1 ...
 $ GAMMA.Borussia.Dortmund        : num  0 0 0 0 -1 0 0 0 0 0 ...
 $ GAMMA.Borussia.Moenchengladbach: num  -1 0 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Eintracht.Frankfurt      : num  0 0 0 0 0 0 0 0 1 0 ...
 $ GAMMA.FC.Bayern.Muenchen       : num  1 0 0 0 0 0 0 0 0 -1 ...
 $ GAMMA.FC.Schalke.04            : num  0 0 0 0 0 0 0 1 0 0 ...
 $ GAMMA.Hamburger.SV             : num  0 0 0 1 0 0 0 0 0 0 ...
 $ GAMMA.Hannover.96              : num  0 0 0 0 0 0 1 0 0 0 ...
 $ GAMMA.Hertha.BSC.Berlin        : num  0 0 0 0 0 0 -1 0 0 0 ...
 $ GAMMA.MSV.Duisburg             : num  0 0 1 0 0 0 0 0 0 0 ...
 $ GAMMA.SV.Werder.Bremen         : num  0 0 0 0 0 1 0 0 0 0 ...
 $ GAMMA.VfB.Stuttgart            : num  0 0 -1 0 0 0 0 0 0 0 ...
 $ GAMMA.VfL.Wolfsburg            : num  0 0 0 0 1 0 0 0 0 0 ...
 $ ALPHA                          : num  1 1 1 1 1 1 1 1 1 1 ...
'data.frame':	306 obs. of  36 variables:
 $ GAMMA.1.FC.Kaiserslautern      : num  0 0 0 0 0 0 0 -1 0 0 ...
 $ GAMMA.1.FC.Koeln               : num  0 1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.1.FC.Nuernberg           : num  0 0 0 -1 0 0 0 0 0 0 ...
 $ GAMMA.1.FSV.Mainz.05           : num  0 -1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Arminia.Bielefeld        : num  0 0 0 0 0 -1 0 0 0 0 ...
 $ GAMMA.Bayer.Leverkusen         : num  0 0 0 0 0 0 0 0 -1 1 ...
 $ GAMMA.Borussia.Dortmund        : num  0 0 0 0 -1 0 0 0 0 0 ...
 $ GAMMA.Borussia.Moenchengladbach: num  -1 0 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Eintracht.Frankfurt      : num  0 0 0 0 0 0 0 0 1 0 ...
 $ GAMMA.FC.Bayern.Muenchen       : num  1 0 0 0 0 0 0 0 0 -1 ...
 $ GAMMA.FC.Schalke.04            : num  0 0 0 0 0 0 0 1 0 0 ...
 $ GAMMA.Hamburger.SV             : num  0 0 0 1 0 0 0 0 0 0 ...
 $ GAMMA.Hannover.96              : num  0 0 0 0 0 0 1 0 0 0 ...
 $ GAMMA.Hertha.BSC.Berlin        : num  0 0 0 0 0 0 -1 0 0 0 ...
 $ GAMMA.MSV.Duisburg             : num  0 0 1 0 0 0 0 0 0 0 ...
 $ GAMMA.SV.Werder.Bremen         : num  0 0 0 0 0 1 0 0 0 0 ...
 $ GAMMA.VfB.Stuttgart            : num  0 0 -1 0 0 0 0 0 0 0 ...
 $ GAMMA.VfL.Wolfsburg            : num  0 0 0 0 1 0 0 0 0 0 ...
 $ ALPHA.1.FC.Kaiserslautern      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.1.FC.Koeln               : num  0 1 0 0 0 0 0 0 0 0 ...
 $ ALPHA.1.FC.Nuernberg           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.1.FSV.Mainz.05           : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.Arminia.Bielefeld        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.Bayer.Leverkusen         : num  0 0 0 0 0 0 0 0 0 1 ...
 $ ALPHA.Borussia.Dortmund        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.Borussia.Moenchengladbach: num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.Eintracht.Frankfurt      : num  0 0 0 0 0 0 0 0 1 0 ...
 $ ALPHA.FC.Bayern.Muenchen       : num  1 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.FC.Schalke.04            : num  0 0 0 0 0 0 0 1 0 0 ...
 $ ALPHA.Hamburger.SV             : num  0 0 0 1 0 0 0 0 0 0 ...
 $ ALPHA.Hannover.96              : num  0 0 0 0 0 0 1 0 0 0 ...
 $ ALPHA.Hertha.BSC.Berlin        : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.MSV.Duisburg             : num  0 0 1 0 0 0 0 0 0 0 ...
 $ ALPHA.SV.Werder.Bremen         : num  0 0 0 0 0 1 0 0 0 0 ...
 $ ALPHA.VfB.Stuttgart            : num  0 0 0 0 0 0 0 0 0 0 ...
 $ ALPHA.VfL.Wolfsburg            : num  0 0 0 0 1 0 0 0 0 0 ...
'data.frame':	306 obs. of  19 variables:
 $ GAMMA.1.FC.Kaiserslautern      : num  0 0 0 0 0 0 0 -1 0 0 ...
 $ GAMMA.1.FC.Koeln               : num  0 1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.1.FC.Nuernberg           : num  0 0 0 -1 0 0 0 0 0 0 ...
 $ GAMMA.1.FSV.Mainz.05           : num  0 -1 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Arminia.Bielefeld        : num  0 0 0 0 0 -1 0 0 0 0 ...
 $ GAMMA.Bayer.Leverkusen         : num  0 0 0 0 0 0 0 0 -1 1 ...
 $ GAMMA.Borussia.Dortmund        : num  0 0 0 0 -1 0 0 0 0 0 ...
 $ GAMMA.Borussia.Moenchengladbach: num  -1 0 0 0 0 0 0 0 0 0 ...
 $ GAMMA.Eintracht.Frankfurt      : num  0 0 0 0 0 0 0 0 1 0 ...
 $ GAMMA.FC.Bayern.Muenchen       : num  1 0 0 0 0 0 0 0 0 -1 ...
 $ GAMMA.FC.Schalke.04            : num  0 0 0 0 0 0 0 1 0 0 ...
 $ GAMMA.Hamburger.SV             : num  0 0 0 1 0 0 0 0 0 0 ...
 $ GAMMA.Hannover.96              : num  0 0 0 0 0 0 1 0 0 0 ...
 $ GAMMA.Hertha.BSC.Berlin        : num  0 0 0 0 0 0 -1 0 0 0 ...
 $ GAMMA.MSV.Duisburg             : num  0 0 1 0 0 0 0 0 0 0 ...
 $ GAMMA.SV.Werder.Bremen         : num  0 0 0 0 0 1 0 0 0 0 ...
 $ GAMMA.VfB.Stuttgart            : num  0 0 -1 0 0 0 0 0 0 0 ...
 $ GAMMA.VfL.Wolfsburg            : num  0 0 0 0 1 0 0 0 0 0 ...
 $ Spieltag                       : int  1 1 1 1 1 1 1 1 1 2 ...

ordBTL documentation built on May 2, 2019, 7:59 a.m.

Related to design in ordBTL...