Previous: Making the Model Compatible | Up: Making the Model Compatible | Next: To Work with setx() |
Zelig has implemented a unique method for incorporating new models which lets contributors test their models within the Zelig framework without any modification of the zelig() function itself.
Using a wrapper function zelig2contrib() (where contrib is the name of your new model), zelig2contrib() redefines the inputs to zelig() to work with the inputs you need for your function contrib(). For example, if you type
zelig(..., model = "normal.regression")zelig() looks for a zelig2normal.regression() wrapper in any environment (either attached libraries or your workspace). If the wrapper exists, then zelig() runs the model.
If you have a pre-existing model, writing a zelig2contrib() function is quite easy. Let's say that your model is contrib(), and takes the following arguments: formula, data, weights, and start. The zelig() function, in contrast, only takes the formula, data, model, and by arguments. You may use the ... to pass additional arguments from zelig() to zelig2contrib(), and <- NULL to omit the elements you do not need. Continuing the Normal regression example from Section , let formula, model, and data be the inputs to zelig(), M is the number of subsets, and ... are the additional arguments not defined in the zelig() call, but passed to normal.regression().
zelig2normal.regression <- function(formula, model, data, M, ...) { mf <- match.call(expand.dots = TRUE) # [1] mf$model <- mf$M <- NULL # [2] mf[[1]] <- as.name("normal.regression") # [3] as.call(mf) # [4] }The bracketed numbers above correspond to the comments below:
If you use an S4 class to represent your model, say mymodel, within zelig.default(), Zelig's internal function, create.ZeligS4(), automatically creates a new S4 class called ZeligS4mymodel in the global environment with two additional slots. These include zelig, which stores the name of the model, and zelig.data, which stores the data frame if save.data=TRUE and is empty otherwise. These names are taken from the original call. This new output inherits the original class mymodel so all the generic functions associated with mymodel should still work. If you would like to see an example, see the models implemented using the VGAM package, such as multinomial probit.