Previous: Example 3: Weighted regression Up: Advanced Zelig Uses Next: Managing Statistical Model Inputs


Writing New Models

With Zelig, writing a new model in R is straightforward. (If you already have a model, see Chapter [*] for how to include it in Zelig.) With tools to streamline user inputs, writing a new model does not require a lot of programming knowledge, but lets developers focus on the model's math. Generally, writing a new statistical procedure or model comes in orderly steps:

  1. Write down the mathematical model. Define the parameters that you need, grouping parameters into convenient vectors or matrices whenever possible (this will make your code clearer).
  2. Write the code.
  3. Test the code (usually using Monte Carlo data, where you know the true values being estimated ) and make sure that it works as expected.
  4. Write some documentation explaining your model and the functions that run your model.
Somewhere between steps [1] and [2], you will need to translate input data into the mathematical notation that you used to write down the model. Rather than repeating whole blocks of code, use functions to streamline the number of commands that users will need to run your model.

With more steps being performed by fewer commands, the inputs to these commands become more sophisticated. The structure of those inputs actually matters quite a lot. If your function has a convoluted syntax, it will be difficult to use, difficult to explain, and difficult to document. If your function is easy to use and has an intuitive syntax, however, it will be easy to explain and document, which will make your procedure more accessible to all users.



Subsections

Gary King 2011-11-29