View source: R/as.data.frame.predict.R
as.data.frame.predictNestedLogit | R Documentation |
These functions provide simple ways to convert the results of predict.nestedLogit
to a data frame in a consistent format for plotting and other actions.
## S3 method for class 'predictNestedLogit'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
a |
row.names |
row.names for result (for conformity with generic; not currently used) |
optional |
logical. If TRUE, setting row names and converting column names
(to syntactic names: see |
... |
other arguments (unused) |
For predict(..., model="nested")
(the default), returns
a data frame containing the values of predictors along with the columns
response
, p
, se.p
, logit
, se.logit
.
For predict(..., model="dichotomies")
, returns
a data frame containing the values of predictors along with the columns
response
, logit
, and se.logit
.
data("Womenlf", package = "carData")
comparisons <- logits(work=dichotomy("not.work", c("parttime", "fulltime")),
full=dichotomy("parttime", "fulltime"))
wlf.nested <- nestedLogit(partic ~ hincome + children,
dichotomies = comparisons,
data=Womenlf)
# get predicted values for a grid of `hincome` and `children`
new <- expand.grid(hincome=seq(0, 45, length=10),
children=c("absent", "present"))
pred.nested <- predict(wlf.nested, new)
plotdata <- as.data.frame(pred.nested)
str(plotdata)
# Predicted logit values for the dichotomies
pred.dichot <- predict(wlf.nested, new, model = "dichotomies")
plotlogit <- as.data.frame(pred.dichot)
str(plotlogit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.