simulate.mclogit mclogit 0.8.5.1

Simulating responses from baseline-category and conditional logit models.

Description

The simulate() methods allow to simulate responses from models fitted with mclogit() and mblogit(). Currently only models without random effects are supported for this.

Usage

## S4 method for signature 'mblogit'
simulate(object, nsim = 1, seed = NULL, ...)
## S4 method for signature 'mclogit'
simulate(object, nsim = 1, seed = NULL, ...)

# These methods are currently just 'stubs', causing an error
# message stating that simulation from models with random
# effects are not supported yet
## S4 method for signature 'mmblogit'
simulate(object, nsim = 1, seed = NULL, ...)
## S4 method for signature 'mmclogit'
simulate(object, nsim = 1, seed = NULL, ...)

Arguments

object

an object from the relevant class

nsim

a number, specifying the number of simulated responses for each observation.

seed

an object specifying if and how the random number generator should be initialized (‘seeded’). The interpetation of this argument follows the default method, see link[stats]{simulate}

...

other arguments, ignored.

Value

The result of the simulate method for objects created by mclogit is a data frame with one variable for each requested simulation run (their number is given by the nsim= argument). The contents of the columns are counts (or zero-one values), with group-wise multinomial distribution (within choice sets) just like it is assumed for the original response.

The shape of the result of the simulate method for objects created by mblogit is also a data frame. The variables within the data frame have a mode or shape that corresponds to the response to which the model was fitted. If the response is a matrix of counts, then the variables in the data frame are also matrices of counts. If the response is a factor and mblogit was called with an argument from.table=FALSE, the variables in the data frame are factors with the same factor levels as the response to which the model was fitted. If instead the function was called with from.table=TRUE, the variables in the data frame are counts, which represent frequency weights that would result from applying as.data.frame to a contingency table of simulated frequency counts.

Examples

library(MASS)
(house.mblogit <- mblogit(Sat ~ Infl + Type + Cont,
                         data = housing,
                         weights=Freq,
                         from.table=TRUE))
Iteration 1 - Deviance = 38.84842
Iteration 2 - Deviance = 38.66222
Iteration 3 - Deviance = 38.6622
Iteration 4 - Deviance = 38.6622
converged

Call: mblogit(formula = Sat ~ Infl + Type + Cont, data = housing, weights =
  Freq, from.table = TRUE)

Coefficients:
                   Predictors
Response categories (Intercept) InflMedium InflHigh TypeApartment TypeAtrium
  TypeTerrace
Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 -0.6666
High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 -1.4123
                   Predictors
Response categories  ContHigh
         Medium/Low   0.3609
         High/Low     0.4818

Null Deviance:     262.1
Residual Deviance: 38.66
sm <- simulate(house.mblogit,nsim=7)
housing.long <- housing[rep(seq.int(nrow(housing)),housing$Freq),]
(housel.mblogit <- mblogit(Sat ~ Infl + Type + Cont,
                          data=housing.long))
Iteration 1 - Deviance = 3474.691
Iteration 2 - Deviance = 3470.086
Iteration 3 - Deviance = 3470.084
Iteration 4 - Deviance = 3470.084
converged

Call:  mblogit(formula = Sat ~ Infl + Type + Cont, data = housing.long)

Coefficients:
                   Predictors
Response categories (Intercept) InflMedium InflHigh TypeApartment TypeAtrium
  TypeTerrace
Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 -0.6666
High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 -1.4123
                   Predictors
Response categories  ContHigh
         Medium/Low   0.3609
         High/Low     0.4818

Null Deviance:     3694
Residual Deviance: 3470
sml <- simulate(housel.mblogit,nsim=7)
housing.table <- xtabs(Freq~.,data=housing)
housing.mat <- memisc::to.data.frame(housing.table)
head(housing.mat)
    Infl      Type Cont Low Medium High
1    Low     Tower  Low  21     21   28
2 Medium     Tower  Low  34     22   36
3   High     Tower  Low  10     11   36
4    Low Apartment  Low  61     23   17
5 Medium Apartment  Low  43     35   40
6   High Apartment  Low  26     18   54
(housem.mblogit <- mblogit(cbind(Low,Medium,High) ~
                              Infl + Type + Cont,
                          data=housing.mat))
Iteration 1 - Deviance = 38.84842
Iteration 2 - Deviance = 38.66222
Iteration 3 - Deviance = 38.6622
Iteration 4 - Deviance = 38.6622
converged

Call: mblogit(formula = cbind(Low, Medium, High) ~ Infl + Type + Cont, data =
  housing.mat)

Coefficients:
                   Predictors
Response categories (Intercept) InflMedium InflHigh TypeApartment TypeAtrium
  TypeTerrace
Medium/Low -0.4192 0.4464 0.6649 -0.4357 0.1314 -0.6666
High/Low -0.1387 0.7349 1.6126 -0.7356 -0.4080 -1.4123
                   Predictors
Response categories  ContHigh
         Medium/Low   0.3609
         High/Low     0.4818

Null Deviance:     262.1
Residual Deviance: 38.66
smm <- simulate(housem.mblogit,nsim=7)
str(sm)
'data.frame':        72 obs. of  7 variables:
 $ sim_1: int  32 19 19 31 22 39 9 12 36 55 ...
 $ sim_2: int  33 15 22 23 21 48 10 10 37 50 ...
 $ sim_3: int  28 19 23 35 18 39 9 16 32 51 ...
 $ sim_4: int  23 18 29 13 26 53 11 12 34 60 ...
 $ sim_5: int  20 23 27 26 27 39 9 12 36 54 ...
 $ sim_6: int  25 15 30 25 20 47 9 10 38 47 ...
 $ sim_7: int  28 13 29 28 27 37 10 11 36 65 ...
- attr(*, "seed")= int [1:626] 10403 91 609962523 -903420738 655523295
  2000421234 354192334 -377612257 2115622805 1694434725 ...
str(sml)
'data.frame':        1681 obs. of  7 variables:
 $ sim_1: Factor w/ 3 levels "Low","Medium",..: 3 2 2 2 2 3 1 1 2 2 ...
 $ sim_2: Factor w/ 3 levels "Low","Medium",..: 2 2 1 1 1 3 2 1 1 2 ...
 $ sim_3: Factor w/ 3 levels "Low","Medium",..: 2 1 1 2 2 3 1 2 1 2 ...
 $ sim_4: Factor w/ 3 levels "Low","Medium",..: 1 2 3 3 3 1 1 1 1 2 ...
 $ sim_5: Factor w/ 3 levels "Low","Medium",..: 2 3 3 3 3 3 1 3 3 2 ...
 $ sim_6: Factor w/ 3 levels "Low","Medium",..: 3 1 2 1 3 1 1 3 3 2 ...
 $ sim_7: Factor w/ 3 levels "Low","Medium",..: 1 2 1 2 3 1 3 1 3 2 ...
- attr(*, "seed")= int [1:626] 10403 542 609962523 -903420738 655523295
  2000421234 354192334 -377612257 2115622805 1694434725 ...
str(smm)
'data.frame':        24 obs. of  7 variables:
 $ sim_1: int [1:24, 1:3] 25 26 4 55 44 27 13 6 5 16 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_2: int [1:24, 1:3] 21 20 11 54 46 21 12 8 4 25 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_3: int [1:24, 1:3] 33 28 7 57 53 23 9 9 1 21 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_4: int [1:24, 1:3] 36 22 9 56 41 26 7 10 5 19 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_5: int [1:24, 1:3] 26 28 12 54 46 26 16 11 2 21 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_6: int [1:24, 1:3] 24 20 13 48 48 28 19 11 3 22 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ sim_7: int [1:24, 1:3] 27 21 12 61 42 27 14 8 4 23 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
- attr(*, "seed")= int [1:626] 10403 453 250977508 2097591383 84913566
  -1055779874 1365819011 -713387534 -1488773045 -1814827609 ...
head(smm[[1]])
     Low Medium High
[1,]  25     19   26
[2,]  26     27   39
[3,]   4     11   42
[4,]  55     31   15
[5,]  44     33   41
[6,]  27     31   40