NEWS.md
cplot.default()
method and modified documentation of cplot()
, image()
, and persp()
methods slightly. (#84, h/t Luke Sonnet)cplot()
for generalized linear models, which can generate unexpected confidence intervals (albeit ones consistent with base R’s behavior). (#92)margins_summary()
which provides a single-function expression of summary(margins(...))
. (#94, h/t Mike DeCrescenzo)persp()
related to attempting to take the mean of a factor variable. (#93, h/t Jared Knowles)print()
and summary()
methods related to the release of prediction 0.3.6.gradient_factory()
to be more robust to an expanded set of model classes through the introduction of an internal function reset_coefs()
. A test suite for this function has been added.margins.default()
now attempts to calculate marginal effect variances in order to, by default, support additional model classes.margins()
now returns attributes “vcov” and “jacobian” (the latter only when vce = "delta"
), which contain the full variance-covariance matrix for the average marginal effects and jacobian for the same. This is different behavior from the previous draft (v0.3.17) because the attributes now always contain a single matrix; again use the vcov()
method rather than accessing the attribute directly lest it change in the future. This allows calculation combination of marginal effects, such as the difference between two AMEs. Some internal functions have been renamed and code reorganized to make this possible. (#87, h/t Trenton Mize)margins()
now contains the input value passed to the at
argument to the function. New attribute “at_vars” returns a character vector of variables specified therein.margins()
now contains an added column "_at_number"
, which specifies which at
combination a row comes from. This may be changed or removed in the future, but is useful for matching subsets of the data frame to corresponding entries in the “vcov” and “jacobian” matrices.margins()
now returns an attribute (“vcov”) containing the variance-covariance matrix for the average marginal effects and a new vcov.margins()
method is provided for extracting it. Behavior when using at
specifications is unspecified and may change in the future. (#87, h/t Trenton Mize)README.Rmd
. (#83)master
cplot()
when xvar
was of class “ordered”. (#77, h/t Francisco Llaneras)plot.margins()
when at
contained only one variable. (#78, h/t @cyberbryce)y ~ I(x^2)
, y ~ x + I(2*x)
, and those involving RHS interactions between factors where some cells are not observed in the data. Added a test suite to cover these cases. (#82)find_terms_in_model()
.clean_terms()
) that occurred when formulae contained variables with backticked names that contained spaces. (#80)dydx()
now uses the performance-enhancing prediction::prediction(..., calculate_se = FALSE)
setting, where possible (introduced in prediction 0.2.4)data.table::rbindlist()
is used instead of base::rbind()
inside dydx()
.marginal_effects()
and dydx()
gain an as.data.frame
argument to regulate the class of their responses.prediction::prediction()
were halved by stacking data frames used in calculating numerical derivatives (inside dydx()
methods) and then splitting the resulting predicted value vectors.varslist
, to marginal_effects()
and several internal functions that significantly improves performance. The performance gain is due to computational cost of identifying terms in model formulae each time marginal_effects()
was called, which occurred repeatedly (e.g., during variance estimation). By performing this once at the margins()
-level and passing the argument throughout, margins()
is perhaps twice as fast as in versions <= 0.3.9. But, importantly, note that this argument should not be specified by end users!find_terms_in_model()
and clean_terms()
, removing many regex calls with the goal of improving performance.margins()
for unweighted models.print()
and summary()
now handle survey-weighted marginal effects.margins()
and marginal_effects()
gain a variables
argument to request marginal effects for a subset of variables included in a model. (#65, h/t Vincent Arul-Bundock)margins.merMod()
. (#56)cplot.clm()
method. (#63, h/t David Barron)cplot.polr()
. (#62, h/t David Barron)margins.merMod()
.print()
and summary()
methods to using weighted.mean()
instead of mean()
. (#45)margins()
. It now returns a data frame with an added at
attribute, specifying the names of the variables that have been fixed by build_datalist()
. (#58)margins()
. Marginal effects columns are prefixed by dydx_
. Variances of the average marginal effect are stored (repeatedly, across observations) in new Var_dydx_
columns. Unit-specific standard errors, if requested, are stored as SE_dydx_
columns. (#58)summary.margins()
now returns a single data frame of marginal effect estimates. Column names have also changed to avoid use of special characters (thus making it easier to use column names in plotting with, for example, ggplot2). Row-order can be controlled by the by_factor
attribute, which by default sorts the data frame by the factor/term. If set to by_factor = FALSE
, the data frame is sorted by the at
variables. This behavior cascades into the print.summary.margins()
method. (#58)print.margins()
now presents (but does not return) effect estimates as a condensed data frame with some auxiliary information. Its behavior when using at
is improved and tidied. (#58)build_margins()
is no longer exported. Arguments used to control its behavior have been exposed in margins()
methods.plot.margins()
now displays marginal effects across each level of at
. (#58)build_margins()
and thus margins()
no longer returns the original data twice (a bug introduced by change in behavior of prediction()
). (#57)"marginslist"
have been removed. (#58)at
argument in plot.margins()
has been renamed to pos
, to avoid ambiguity with at
as used elsewhere in the package.persp()
and image()
methods gain a dx
argument (akin to that in cplot()
) to allow visualization of marginal effects of a variable across levels of two other variables. The default behavior remains unchanged."merMod"
models from lme4, though no variance estimation is currently supported.prediction::mean_or_mode()
for use in cplot()
methods.cplot.polr()
now allows the display of “stacked” (cumulative) predicted probabilities. (#49)cplot(draw = "add")
to display predicted probabilities across a third factor variable. (#46)build_datalist()
and seq_range()
functions to the prediction package.cplot.multinom()
method has been added.cplot.lm()
has been refactored so that the actual plotting code now relies in non-exported utility functions, which can be used in other methods. This should make it easier to maintain existing methods and add new ones. (#49)cplot()
method for objects of class "polr"
has been added (#49).extract_marginal_effects()
function has been removed and replaced by marginal_effects()
methods for objects of classes "margins"
and "marginslist"
.prediction()
issue for models of class "svyglm"
. (#47, h/t Carl Ganz)get_effect_variances(vce = "bootstrap")
, wherein the variance of the marginal effects was always zero.prediction()
generic and methods into a separate package, prediction, to ease maintainence.print.summary.margins()
method to separate construction of the summary data frame the printing thereof.cplot()
, persp()
, and image()
gain a vcov
argumetn to pass to `build_margins(). (#43)cplot()
now allows for the display of multiple conditional relationships by setting draw = "add"
. (#32)cplot()
data. (#31)dydx.default()
to allow the calculation of various discrete changes rather than only numerical derivatives.data
argument in margins()
and prediction()
to be clearer about what is happening when it is set to missing.marfx
(#31, h/t Jeffrey Arnold)prediction()
methods to, hopefully, reduce memory footprint of model objects. (#26)variances
field in “margins” objects (to lower case), for consistency.image()
method for “lm”, “glm”, and “loess” objects, as a flat complement to existing persp()
methods. (#42)prediction()
method for “gls” objects (from MASS::gls()
). (#3)numDeriv::jacobian()
with an internal alternative. (#41)prediction()
method for “ivreg” objects (from AER::ivreg()
). (#3)prediction()
method for “survreg” objects (from survival::survreg()
). (#3)prediction()
method for “polr” objects (from MASS::polr()
). (#3)prediction()
method for “coxph” objects (from survival::coxph()
). (#3)marginal_effects()
and prediction()
are now S3 generics, with methods for “lm” and “glm” objects, improving extensability. (#39, #40)prediction()
returns a new class (“prediction”) and gains a print()
method.prediction()
, marginal_effects()
, cplot()
, and persp()
. No effect variances are currently calculated. (#3)prediction()
method for “nls” objects. (#3)get_effect_variances()
gains a “none” option for the vce
argument, to skip calculation of ME variances.marginal_effects()
issues a warning (rather than fails) when trying to extract the marginal effect of a factor variable that was coerced to numeric in a model formula via I()
. (#38)marginal_effects()
to use a vectorized approach to simple numerical differentiation. (#36/#37, h/t Vincent Arel-Bundock)margins.plm()
method, which didn’t actually work because “plm” does not provide a predict()
method.inst/doc
.build_margins()
now returns columns containing unit-specific standard errors of marginal effects.vc
argument to build_margins()
to allow the passing of arbitrary variance-covariance matrices. (#16, h/t Alex Coppock & Gijs Schumacher)cplot()
now draws confidence intervals for “effect” plots.get_marginal_effects()
wherein the method
argument was ignored. This improves performance significantly when using method = "simple"
(the default differentiation method).persp()
methods for “lm” and “glm” class objects to display 3-dimensional representations of predicted values and marginal effects.plot.margins()
method for mimicking Stata’s marginsplot
behavior.cplot()
generic and methods for “lm” and “glm” class objects to display conditional predictions and conditional marginal effects in the style of the interplot and plotMElm packages.build_margins()
is called by margins()
methods (perhaps repeatedly) and actually assembles a “margins” object from a model and data. It is never necessary to call this directly, but may be useful for very simple marginal effect estimation procedures (i.e., using original data with no at
specification). Second, marginal_effects()
is the very low level function that differentiates a model with respect to some input data (or calculate discrete changes in the outcome with respect to factor variables). This is the fastest way to obtain marginal effects without the overhead of creating a “margins” object (for which variance estimation is fairly time-consuming).numDeriv::grad()
rather than symbolic differentiation. This allows margins()
to handle almost any model that can be specified in R, including models that cannot be specified in Stata.build_datalist()
now checks for specification of illegal factor levels in at
and errors when these are encountered.