Learn R Programming

UPG (version 0.2.2)

plot.UPG.MNL: Coefficient plots for UPG.MNL objects

Description

plot generates plots from UPG.MNL objects using ggplot2. Coefficient plots show point estimates for all coefficients in all groups except the baseline as well as their credible intervals.

Usage

# S3 method for UPG.MNL
plot(
  x = NULL,
  ...,
  sort = FALSE,
  names = NULL,
  groups = NULL,
  xlab = NULL,
  ylab = NULL,
  q = c(0.025, 0.975),
  include = NULL
)

Arguments

x

an object of class UPG.MNL.

...

other plot parameters.

sort

a logical variable indicating whether the plotted coefficients should be sorted according to average effect sizes across groups. Default is FALSE.

names

a character vector indicating names for the variables used in the plots.

groups

a character vector indicating names for the groups excluding the baseline. The group names must correspond to the ordering in the dependent variable used for estimation.

xlab

a character vector of length 1 indicating a title for the x-axis.

ylab

a character vector of length 1 indicating a title for the y-axis.

q

a numerical vector of length two holding the posterior quantiles to be extracted. Default are 0.025 and 0.975 quantiles.

include

can be used to plot only a subset of variables. Specificy the columns of X that should be kept in the plot. See examples for further information.

Value

Returns a ggplot2 object.

See Also

summary.UPG.MNL to summarize the estimates of a discrete choice model from an UPG.MNL object and create tables. predict.UPG.MNL to predict probabilities from a discrete choice model from an UPG.MNL object. coef.UPG.MNL to extract coefficients from an UPG.MNL object.

Examples

Run this code
# NOT RUN {
# estimate a multinomial logit model using example data
library(UPG)
data(program)
y = program[,1]
X = program[,-1]
results.mnl = UPG(y = y, X = X, type = "mnl")

# plot the results and sort coefficients by average effect size
plot(results.mnl, sort = TRUE)

# plot only variables 1 and 3 with custom group and variable names
# also, customize credible intervals and axis labels
plot(results.mnl,
     include  = c(1,3),
     names    = c("Custom 1", "Custom 2"),
     groups   = c("Alpha", "Beta"),
     q        = c(0.1, 0.9),
     xlab     = c("Custom X"),
     ylab     = c("Custom Y"))
# }

Run the code above in your browser using DataLab