Adding Models and Methods to Zelig
Zelig is highly modular. You can add methods to Zelig and, if
you wish, release your programs as a stand-alone package. By making
your package compatible with Zelig, you will advertise your package
and help it achieve a widespread distribution.
This chapter assumes that your model is written as a function that
takes a user-defined formula and data set (see Chapter ),
and returns a list of output that includes (at the very least) the
estimated parameters and terms that describe the data used to fit the
model. You should choose a class (either S3 or S4 class) for this
list of output, and provide appropriate methods for generic functions
such as summary(), print(), coef() and vcov().
To add new models to Zelig, you need to provide six R functions,
illustrated in Figure . Let mymodel be a new model
with class "myclass".
Figure:
Six functions (solid boxes) to implement a new Zelig model
139#139 |
These functions are as follows:
- zelig2mymodel() translates zelig() arguments into
the arguments for mymodel().
- mymodel() estimates your statistical procedure.
- param.myclass() simulates parameters for your model.
Alternatively, if your model's parameters consist of one vector with a
correspondingly observed variance-covariance matrix, you may write
two simple functions to substitute for param.myclass():
- coef.myclass() to extract the coefficients from your model
output, and
- vcov.myclass() to extract the variance-covariance matrix
from your model.
- qi.myclass() calculates expected values, simulates
predicted values, and generates other quantities of interest for your
model (applicable only to models that take explanatory variables).
- plot.zelig.mymodel() to plot the simulated quantities of
interest from your model.
- A reference manual page to document the model.
(See Section )
- A function (describe.mymodel()) describing the inputs to
your model, for use with a graphical user interface. (See Section ).
- An optional demo script mymodel.R which contains commented code for
the models contained in the example section of your reference manual
page.
Subsections
Gary King
2011-11-29