createX: Create X Matrix for Use in Multinomial Logit and Probit... In bayesm: Bayesian Inference for Marketing/Micro-Econometrics

Description

`createX` makes up an X matrix in the form expected by Multinomial Logit (`rmnlIndepMetrop` and `rhierMnlRwMixture`) and Probit (`rmnpGibbs` and `rmvpGibbs`) routines. Requires an array of alternative-specific variables and/or an array of "demographics" (or variables constant across alternatives) which may vary across choice occasions.

Usage

 `1` ```createX(p, na, nd, Xa, Xd, INT = TRUE, DIFF = FALSE, base=p) ```

Arguments

 `p` integer number of choice alternatives `na` integer number of alternative-specific vars in `Xa` `nd` integer number of non-alternative specific vars `Xa` n x p*na matrix of alternative-specific vars `Xd` n x nd matrix of non-alternative specific vars `INT` logical flag for inclusion of intercepts `DIFF` logical flag for differencing wrt to base alternative `base` integer index of base choice alternative

Note: `na`, `nd`, `Xa`, `Xd` can be `NULL` to indicate lack of `Xa` or `Xd` variables.

Value

`X` matrix of dimension n*(p-DIFF) x [(INT+nd)*(p-1) + na].

Note

`rmnpGibbs` assumes that the `base` alternative is the default.

Author(s)

Peter Rossi, Anderson School, UCLA, [email protected].

References

For further discussion, see Bayesian Statistics and Marketing by Rossi, Allenby, and McCulloch.
http://www.perossi.org/home/bsm-1

`rmnlIndepMetrop`, `rmnpGibbs`

Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11``` ```na=2; nd=1; p=3 vec = c(1, 1.5, 0.5, 2, 3, 1, 3, 4.5, 1.5) Xa = matrix(vec, byrow=TRUE, ncol=3) Xa = cbind(Xa,-Xa) Xd = matrix(c(-1,-2,-3), ncol=1) createX(p=p, na=na, nd=nd, Xa=Xa, Xd=Xd) createX(p=p, na=na, nd=nd, Xa=Xa, Xd=Xd, base=1) createX(p=p, na=na, nd=nd, Xa=Xa, Xd=Xd, DIFF=TRUE) createX(p=p, na=na, nd=nd, Xa=Xa, Xd=Xd, DIFF=TRUE, base=2) createX(p=p, na=na, nd=NULL, Xa=Xa, Xd=NULL) createX(p=p, na=NULL, nd=nd, Xa=NULL, Xd=Xd) ```

Example output

```      [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    0   -1    0  1.0 -1.0
[2,]    0    1    0   -1  1.5 -1.5
[3,]    0    0    0    0  0.5 -0.5
[4,]    1    0   -2    0  2.0 -2.0
[5,]    0    1    0   -2  3.0 -3.0
[6,]    0    0    0    0  1.0 -1.0
[7,]    1    0   -3    0  3.0 -3.0
[8,]    0    1    0   -3  4.5 -4.5
[9,]    0    0    0    0  1.5 -1.5
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    0    0    0    0  1.0 -1.0
[2,]    1    0   -1    0  1.5 -1.5
[3,]    0    1    0   -1  0.5 -0.5
[4,]    0    0    0    0  2.0 -2.0
[5,]    1    0   -2    0  3.0 -3.0
[6,]    0    1    0   -2  1.0 -1.0
[7,]    0    0    0    0  3.0 -3.0
[8,]    1    0   -3    0  4.5 -4.5
[9,]    0    1    0   -3  1.5 -1.5
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    0   -1    0  0.5 -0.5
[2,]    0    1    0   -1  1.0 -1.0
[3,]    1    0   -2    0  1.0 -1.0
[4,]    0    1    0   -2  2.0 -2.0
[5,]    1    0   -3    0  1.5 -1.5
[6,]    0    1    0   -3  3.0 -3.0
[,1] [,2] [,3] [,4] [,5] [,6]
[1,]    1    0   -1    0 -0.5  0.5
[2,]    0    1    0   -1 -1.0  1.0
[3,]    1    0   -2    0 -1.0  1.0
[4,]    0    1    0   -2 -2.0  2.0
[5,]    1    0   -3    0 -1.5  1.5
[6,]    0    1    0   -3 -3.0  3.0
[,1] [,2] [,3] [,4]
[1,]    1    0  1.0 -1.0
[2,]    0    1  1.5 -1.5
[3,]    0    0  0.5 -0.5
[4,]    1    0  2.0 -2.0
[5,]    0    1  3.0 -3.0
[6,]    0    0  1.0 -1.0
[7,]    1    0  3.0 -3.0
[8,]    0    1  4.5 -4.5
[9,]    0    0  1.5 -1.5
[,1] [,2] [,3] [,4]
[1,]    1    0   -1    0
[2,]    0    1    0   -1
[3,]    0    0    0    0
[4,]    1    0   -2    0
[5,]    0    1    0   -2
[6,]    0    0    0    0
[7,]    1    0   -3    0
[8,]    0    1    0   -3
[9,]    0    0    0    0
```

bayesm documentation built on July 21, 2017, 7:18 p.m.