predict mclogit 0.8.6.2

Description

The predict() methods allow to obtain within-sample and out-of-sample predictions from models fitted with mclogit() and mblogit().

For models with random effecs fitted using the PQL-method, it is possible to obtain responses that are conditional on the reconstructed random effects.

Usage

## S4 method for signature 'mblogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE, ...)
## S4 method for signature 'mclogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE, ...)
## S4 method for signature 'mmblogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE,
                             conditional=TRUE, ...)
## S4 method for signature 'mmclogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE,
                             conditional=TRUE, ...)

Arguments

object

an object in class “mblogit”, “mmblogit”, “mclogit”, or “mmclogit”

newdata

an optional data frame with new data

type

a character string specifying the kind of prediction

se.fit

a logical value; whether predictions should be accompanied with standard errors

conditional

a logical value; whether predictions should be made conditional on the random effects (or whether they are set to zero, i.e. their expectation). This argument is consequential only if the “mmblogit” or “mmclogit” object was created with method="PQL".

...

other arguments, ignored.

Value

The predict methods return either a matrix (unless called with se.fit=TRUE) or a list with two matrix-valued elements "fit" and "se.fit".

Examples

library(MASS)
(house.mblogit <- mblogit(Sat ~ Infl + Type + Cont,
                         data = housing,
                         weights=Freq))
Iteration 1 - Deviance = 3493.764
Iteration 2 - Deviance = 3470.111
Iteration 3 - Deviance = 3470.084
Iteration 4 - Deviance = 3470.084
converged

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

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
head(pred.house.mblogit <- predict(house.mblogit))
          Medium       High
[1,] -0.41922874 -0.1387428
[2,] -0.41922874 -0.1387428
[3,] -0.41922874 -0.1387428
[4,]  0.02716715  0.5961205
[5,]  0.02716715  0.5961205
[6,]  0.02716715  0.5961205
str(pred.house.mblogit <- predict(house.mblogit,se=TRUE))
List of 2
 $ fit   : num [1:72, 1:2] -0.4192 -0.4192 -0.4192 0.0272 0.0272 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "Medium" "High"
 $ se.fit: num [1:72, 1:2] 0.173 0.173 0.173 0.17 0.17 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "Medium" "High"
head(pred.house.mblogit <- predict(house.mblogit,
                                  type="response"))
           Low    Medium      High
[1,] 0.3955687 0.2601077 0.3443236
[2,] 0.3955687 0.2601077 0.3443236
[3,] 0.3955687 0.2601077 0.3443236
[4,] 0.2602403 0.2674072 0.4723526
[5,] 0.2602403 0.2674072 0.4723526
[6,] 0.2602403 0.2674072 0.4723526
str(pred.house.mblogit <- predict(house.mblogit,se=TRUE,
                                 type="response"))
List of 2
 $ fit   : num [1:72, 1:3] 0.396 0.396 0.396 0.26 0.26 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
 $ se.fit: num [1:72, 1:3] 0.0343 0.0343 0.0343 0.0273 0.0273 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:3] "Low" "Medium" "High"
data(electors)
(mcre <- mclogit(
   cbind(Freq,interaction(time,class))~econ.left/class+welfare/class+auth/class,
   random=~1|party.time,
   data=within(electors,party.time<-interaction(party,time))))
Iteration 1 - deviance = 1054.511 - criterion = 0.1598497
Iteration 2 - deviance = 923.1626 - criterion = 0.02666473
Iteration 3 - deviance = 890.3113 - criterion = 0.006530011
Iteration 4 - deviance = 883.0567 - criterion = 0.0005723444
Iteration 5 - deviance = 881.4344 - criterion = 1.387329e-05
Iteration 6 - deviance = 881.2041 - criterion = 1.394381e-07
Iteration 7 - deviance = 881.1809 - criterion = 1.04388e-09
converged
mclogit(formula = cbind(Freq, interaction(time, class)) ~ econ.left/class +
welfare/class + auth/class, data = within(electors, party.time <-
  interaction(party,
    time)), random = ~1 | party.time)

Coefficients:
econ.left welfare auth
-0.1260 2.0196 0.1141
econ.left:classnew.middle econ.left:classold.middle classnew.middle:welfare
-1.8170 -3.1386 -0.8958
classold.middle:welfare classnew.middle:auth classold.middle:auth
-1.4790 -1.4339 1.4411

(Co-)Variances:
Grouping level: 1
             (Intercept)
(Intercept)  3.066

Null Deviance:     80580
Residual Deviance: 881.2
str(predict(mcre))
num [1:450] -1.747 4.428 3.146 -3.402 0.609 ...
str(predict(mcre,type="response"))
num [1:450] 0.00158 0.759379 0.210788 0.000302 0.016676 ...
str(predict(mcre,se.fit=TRUE))
List of 2
 $ fit   : num [1:450] -1.747 4.428 3.146 -3.402 0.609 ...
 $ se.fit: Named num [1:450] 0.822 0.727 0.821 0.808 0.81 ...
  ..- attr(*, "names")= chr [1:450] "1" "2" "3" "4" ...
str(predict(mcre,type="response",se.fit=TRUE))
List of 2
 $ fit   : num [1:450] 0.00158 0.759379 0.210788 0.000302 0.016676 ...
 $ se.fit: num [1:450] 0.000843 0.051945 0.056008 0.000112 0.006931 ...