Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict

Predicting responses or linear parts of the baseline-category and conditional logit models


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

## S3 method for class 'mblogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE, ...)
## S3 method for class 'mclogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE, ...)
## S3 method for class 'mmblogit'
predict(object, newdata=NULL,type=c("link","response"),se.fit=FALSE,
                             conditional=TRUE, ...)
## S3 method for class '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))

head(pred.house.mblogit <- predict(house.mblogit))
str(pred.house.mblogit <- predict(house.mblogit,se=TRUE))

head(pred.house.mblogit <- predict(house.mblogit,
                                   type="response"))
str(pred.house.mblogit <- predict(house.mblogit,se=TRUE,
                                  type="response"))
 # This takes a bit longer.
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))))

str(predict(mcre))
str(predict(mcre,type="response"))

str(predict(mcre,se.fit=TRUE))
str(predict(mcre,type="response",se.fit=TRUE))

mclogit

Multinomial Logit Models, with or without Random Effects or Overdispersion

v0.8.7.3
GPL-2
Authors
Martin Elff
Initial release
2021-03-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.