View source: R/plot_effects_1.R
plot.fmlogit | R Documentation |
Plot marginal or discrete effects of willingness to pay, potentially against another variable
## S3 method for class 'fmlogit' plot(object, wtp.vec, varlist, against = NULL, mfrow = NULL, t = 500, effect = c("discrete", "marginal"), type = "l", plot.show = T, ...)
object |
An "fmlogit" object. |
varlist |
A string vector which provides the name of variables to plot the effect. If missing, all variables in object will be plotted. |
against |
A vector with the same length as the number of observations in the model. Serve as the x-axis in the plots. |
mfrow |
A numeric vector with two elements. Specify the number of rows and columns in a panel. Similar to par(mfrow=c()). Default to Null, and the program will choose a square panel. |
plot.show |
If true, the plot will be created. Otherwise the function returns raw data that can be used to create user-specified (fancier) plots. |
X |
The covariates matrix. Recommend to use element X from the fmlogit object. |
y |
The covariates matrix. Recommend to use element y from the fmlogit object. |
This function provides a visualization tool for potentially heterogeneous marginal and discrete effects. The function lets the user to plot marginal effects to detect any patterns in the effects, in itself and against other variables. The plot also allows visualization of sub-groups in data, which can be very useful to visualize categorical and dummy variables.
The functions takes an fmlogit.margins object, created by the effects(fmlogit) function. Note that since
the plotting requires marginal effects for all observations, the object should be created by choosing
marg.type="aveacr"
, the average across method for effects calculation.
Additional parameters including varlist
, a vector of string variable names to be plotted. X
and y
, the dependent and independent variable matrix in the original regression model.
against
, against.x
, and against.y
allows different variables to be chosen
as the x-axis. against
directly supplies the vector to be plotted against, whereas against.x
and against.y
supplies variable names in the original dataset. Note that the user has to provide
X
and y
in order to use the column name option, respectively.
group.x
supplies the column name in the X matrix to be grouped by. The plot will be able to
differentiate different groups by colors. Additionally, the user can supply a string to group.by
,
which provides a algebra method that will be evaluated on the group vector. For example, choose
group.x = "a"
and group.by= ">0"
will create two groups, one with X$a>0, and one with X$a
<=0
Panel plots of effects vs. chosen variables
# Not running # results1 = fmlogit(y,X) # effect1 = effects(results1,effect="marginal",marg.type="aveacr") # Plot only takes effects with marg.type="aveacr". plot(effect1,X=results1$X,against.x = "popdens", group = "tot", groupby = ">3")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.