- Remove unconditional use of cairo_pdf in vignette, per CRAN policy.
- Setup a
cplot.default()
method and modified documentation ofcplot()
,image()
, andpersp()
methods slightly. (#84, h/t Luke Sonnet) - Improve the documentation the behavior of
cplot()
for generalized linear models, which can generate unexpected confidence intervals (albeit ones consistent with base R's behavior). (#92) - Fix bug that caused spurious
NA
s and errors inmargins()
whenvce
was"bootstrap"
or"simulation"
andvariables
had a length of 1. (#112) - Models fit using the
lme4
package can now have variance estimation via bootstrap and simulation (#105). - Updated documentation to be more explicit about what the package does for users unfamiliar with Stata. (#119)
- Added new function
margins_summary()
which provides a single-function expression ofsummary(margins(...))
. (#94, h/t Mike DeCrescenzo) - Added variances of marginal effects to "polr" objects from MASS. (#98, @eijoac)
- Fix a bug in
persp()
related to attempting to take the mean of a factor variable. (#93, h/t Jared Knowles)
- Fix a small issue in
print()
andsummary()
methods related to the release of prediction 0.3.6.
- Expanded support for objects of class "merMod" from lme4, including support for variance estimation and an expanded test suite. (#56)
- Modified the internals of
gradient_factory()
to be more robust to an expanded set of model classes through the introduction of an internal functionreset_coefs()
. A test suite for this function has been added.
- Added support for objects of class "ivreg" from AER.
margins.default()
now attempts to calculate marginal effect variances in order to, by default, support additional model classes.
- Added support for objects of class "betareg" from betareg. (#90)
margins()
now returns attributes "vcov" and "jacobian" (the latter only whenvce = "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 thevcov()
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)- The "at" attribute returned by
margins()
now contains the input value passed to theat
argument to the function. New attribute "at_vars" returns a character vector of variables specified therein. - The data frame returned by
margins()
now contains an added column"_at_number"
, which specifies whichat
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 newvcov.margins()
method is provided for extracting it. Behavior when usingat
specifications is unspecified and may change in the future. (#87, h/t Trenton Mize)- Updated examples in
README.Rmd
. (#83)
- Fixed a bug in
cplot()
whenxvar
was of class "ordered". (#77, h/t Francisco Llaneras) - Fixed a bug in
plot.margins()
whenat
contained only one variable. (#78, h/t @cyberbryce)
- Tried to improve the handling of edge case model specifications like
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) - Continued to update behavior of internal function
find_terms_in_model()
.
- Fixed a bug in survey-weighted objects involving weights and expanded the test suite to cover these cases.
- Fixed a bug in all functions (ultimately in internal utility
clean_terms()
) that occurred when formulae contained variables with backticked names that contained spaces. (#80)
dydx()
now uses the performance-enhancingprediction::prediction(..., calculate_se = FALSE)
setting, where possible (introduced in prediction 0.2.4)data.table::rbindlist()
is used instead ofbase::rbind()
insidedydx()
.
- Changed some internal representations from data frames to matrices in an effort to improve performance.
marginal_effects()
anddydx()
gain anas.data.frame
argument to regulate the class of their responses. - Internal calls to
prediction::prediction()
were halved by stacking data frames used in calculating numerical derivatives (insidedydx()
methods) and then splitting the resulting predicted value vectors.
- Added an (internal use only) argument,
varslist
, tomarginal_effects()
and several internal functions that significantly improves performance. The performance gain is due to computational cost of identifying terms in model formulae each timemarginal_effects()
was called, which occurred repeatedly (e.g., during variance estimation). By performing this once at themargins()
-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! - Some internal edits were made to the formula-processing functions
find_terms_in_model()
andclean_terms()
, removing many regex calls with the goal of improving performance. - Removed compiler dependency, which appeared to not improve performance.
- Fixed a bug wherein model formulae involving non-standard variables names with spaces in them led to errors. (#80)
- Added method for "svyglm" from survey.
- Improved handling of survey-weighted estimates. Removed weight-related warnings from
margins()
for unweighted models. print()
andsummary()
now handle survey-weighted marginal effects.
margins()
andmarginal_effects()
gain avariables
argument to request marginal effects for a subset of variables included in a model. (#65, h/t Vincent Arul-Bundock)
- Export
margins.merMod()
. (#56)
- Added a
cplot.clm()
method. (#63, h/t David Barron)
- Fixed a bug in
cplot.polr()
. (#62, h/t David Barron)
- Fixed "margins" object structure in
margins.merMod()
. - Switched
print()
andsummary()
methods to usingweighted.mean()
instead ofmean()
. (#45)
- Added method for class "polr" from MASS. (#60)
- Added method for class "nnet" from nnet as an initial implementation of multi-category outcome models. (#60)
- Significantly modified the data structure returned by
margins()
. It now returns a data frame with an addedat
attribute, specifying the names of the variables that have been fixed bybuild_datalist()
. (#58) - Renamed marginal effects, variance, and standard error columns returned by
margins()
. Marginal effects columns are prefixed bydydx_
. Variances of the average marginal effect are stored (repeatedly, across observations) in newVar_dydx_
columns. Unit-specific standard errors, if requested, are stored asSE_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 theby_factor
attribute, which by default sorts the data frame by the factor/term. If set toby_factor = FALSE
, the data frame is sorted by theat
variables. This behavior cascades into theprint.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 usingat
is improved and tidied. (#58)build_margins()
is no longer exported. Arguments used to control its behavior have been exposed inmargins()
methods.plot.margins()
now displays marginal effects across each level ofat
. (#58)build_margins()
and thusmargins()
no longer returns the original data twice (a bug introduced by change in behavior ofprediction()
). (#57)- All methods for objects of class
"marginslist"
have been removed. (#58) - The
at
argument inplot.margins()
has been renamed topos
, to avoid ambiguity withat
as used elsewhere in the package. persp()
andimage()
methods gain adx
argument (akin to that incplot()
) to allow visualization of marginal effects of a variable across levels of two other variables. The default behavior remains unchanged.- Cleaned up documentation and add some examples.
- Added support for
"merMod"
models from lme4, though no variance estimation is currently supported. - Imported
prediction::mean_or_mode()
for use incplot()
methods.
cplot.polr()
now allows the display of "stacked" (cumulative) predicted probabilities. (#49)- Added an example of
cplot(draw = "add")
to display predicted probabilities across a third factor variable. (#46) - Moved the
build_datalist()
andseq_range()
functions to the prediction package. - A tentative
cplot.multinom()
method has been added.
- The internal code of
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) - A new
cplot()
method for objects of class"polr"
has been added (#49).
- The
extract_marginal_effects()
function has been removed and replaced bymarginal_effects()
methods for objects of classes"margins"
and"marginslist"
. - Added a dependency on prediction v.0.1.3 and, implicitly, an enhances suggestion of survey v3.31-5 to resolve an underlying
prediction()
issue for models of class"svyglm"
. (#47, h/t Carl Ganz)
- A warning is now issued when a model uses weights, indicating that they are ignored. (#4)
- Various errors and warnings that occurred when applying
margins()
to a model with weights have been fixed. cplot()
now issues an error when attempting to display the effects of a factor (with > 2 levels).
- Fixed a bug in
get_effect_variances(vce = "bootstrap")
, wherein the variance of the marginal effects was always zero.
- Factored the
prediction()
generic and methods into a separate package, prediction, to ease maintainence. - Added a
print.summary.margins()
method to separate construction of the summary data frame the printing thereof. - The "Technical Details" vignette now describes the package functionality and computational approach in near-complete detail.
- Plotting functions
cplot()
,persp()
, andimage()
gain avcov
argumetn to pass to `build_margins(). (#43) cplot()
now allows for the display of multiple conditional relationships by settingdraw = "add"
. (#32)- The package Introduction vignette has improved examples, including ggplot2 examples using
cplot()
data. (#31)
- Added support in
dydx.default()
to allow the calculation of various discrete changes rather than only numerical derivatives.
- Fixes to handling of factors and ordered variables converted within formulae. (#38)
- Reconfigured the
data
argument inmargins()
andprediction()
to be clearer about what is happening when it is set to missing.
- Switched to using a more reliable "central difference" numerical differentiation and updated the calculation of the step size to follow
marfx
(#31, h/t Jeffrey Arnold) - Added some functionality
prediction()
methods to, hopefully, reduce memory footprint of model objects. (#26) - Changed the capitalization of the
variances
field in "margins" objects (to lower case), for consistency. - Fixed some small errors in documentation and improved width of examples.
- Expose previously internal
dydx()
generic and methods to provide variable-specific marginal effects calculations. (#31) - Added example dataset from marfx package. (#31)
- Added support for calculating marginal effects of logical terms, treating them as factors. (#31)
- Added an
image()
method for "lm", "glm", and "loess" objects, as a flat complement to existingpersp()
methods. (#42)
- Added a
prediction()
method for "gls" objects (fromMASS::gls()
). (#3)
- Replaced
numDeriv::jacobian()
with an internal alternative. (#41)
- Added a
prediction()
method for "ivreg" objects (fromAER::ivreg()
). (#3) - Added a
prediction()
method for "survreg" objects (fromsurvival::survreg()
). (#3)
- Added a
prediction()
method for "polr" objects (fromMASS::polr()
). (#3) - Added a
prediction()
method for "coxph" objects (fromsurvival::coxph()
). (#3)
marginal_effects()
andprediction()
are now S3 generics, with methods for "lm" and "glm" objects, improving extensability. (#39, #40)prediction()
returns a new class ("prediction") and gains aprint()
method.- Added preliminary support for "loess" objects, including methods for
prediction()
,marginal_effects()
,cplot()
, andpersp()
. No effect variances are currently calculated. (#3) - Added a
prediction()
method for "nls" objects. (#3) - Internal function
get_effect_variances()
gains a "none" option for thevce
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 viaI()
. (#38)
- Added better support for factor
x
variables incplot()
. - Added (rudimentary) tests of variance methods. (#21)
- Removed
.build_predict_fun()
factory function, as it was no longer needed. - Fix vignettes so package can be built with them. (#16)
- Modified
marginal_effects()
to use a vectorized approach to simple numerical differentiation. (#36/#37, h/t Vincent Arel-Bundock) - Removed
margins.plm()
method, which didn't actually work because "plm" does not provide apredict()
method. - Updated Stata/R comparison documents included in
inst/doc
. - Expanded tests of unit-specific variances. (#21)
- Added a logical argument to enable/disable calculation of unit-specific marginal effect variances and set it to FALSE by default. (#36, h/t Vincent Arel-Bundock)
- Removed support for "marginal effects at means" (MEMs) and the
atmeans
argument throughout package. (#35) - Renamed the
vc
argument tovcov
for consistency with other packages. (#34)
build_margins()
now returns columns containing unit-specific standard errors of marginal effects.- Added a
vc
argument tobuild_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.- Fixed a bug in
get_marginal_effects()
wherein themethod
argument was ignored. This improves performance significantly when usingmethod = "simple"
(the default differentiation method).
- Added
persp()
methods for "lm" and "glm" class objects to display 3-dimensional representations of predicted values and marginal effects. - Added
plot.margins()
method for mimicking Stata'smarginsplot
behavior. - Added
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. - Added various variance estimation procedures for marginal effects: delta method (the default), bootstrap, and simulation (ala Clarify).
- Fixed estimation of marginal effect variances for generalized linear models, so that they are correct on both "link" and "response" scales.
- Exposed two internal marginal effect estimation functions. First,
build_margins()
is called bymargins()
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 noat
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). - Implemented estimation of "discrete change" representations of marginal effects of factor variables in models, ala Stata's default settings.
- Re-implemented marginal effects estimation using numeric derivatives provided by
numDeriv::grad()
rather than symbolic differentiation. This allowsmargins()
to handle almost any model that can be specified in R, including models that cannot be specified in Stata. - Used compiler to byte compile prediction and gradient fucntions, thereby improving estimation speed.
- The internal
build_datalist()
now checks for specification of illegal factor levels inat
and errors when these are encountered. - Use the webuse package to handle examples.
- Initial package released.