plot.fmlogit.margins: Plot marginal or discrete effects, at each observation & for...

View source: R/plot_effects.R

plot.fmlogit.marginsR Documentation

Plot marginal or discrete effects, at each observation & for each choice

Description

Plot the desired effect at each observed value for each choice

Usage

## S3 method for class 'fmlogit.margins'
plot(object, varlist = NULL, X = NULL,
  y = NULL, against = NULL, against.x = NULL, against.y = NULL,
  group.x = NULL, group.algebra = NULL, mfrow = NULL)

Arguments

object

An "fmlogit.margins" object.

varlist

A string vector which provides the name of variables to plot the effect. If missing, all variables in object will be plotted.

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.

against

A vector with the same length as the number of observations in the model. Serve as the x-axis in the plots.

against.x

A character string, Supply the column name in the X matrix to be plot against.

against.y

A character string, Supply the column name in the y matrix to be plot against.

group.x

A character string. Supply the column name in the X matrix to be grouped upon.

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.

group.by

A character string. Supply additional algebra emposed on the group variable.

Details

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

Value

Panel plots of effects vs. chosen variables

Examples

 
# 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")

f1kidd/fmlogit documentation built on June 26, 2022, 4:33 p.m.