Description Usage Arguments Details Value Author(s) See Also Examples

The methods are called by the `mi`

function to model a given
`missing_variable`

as a function of all the other
`missing_variable`

s and also their missingness pattern.
By overwriting these methods, users can change the way a
`missing_variable`

is modeled for the purposes of imputing
its missing values. See also the table in `missing_variable`

.

1 |

`y` |
An object that inherits from |

`data` |
A |

`...` |
Additional arguments, not currently utilized |

In `mi`

, each `missing_variable`

is modeled as a function of
all the other `missing_variable`

s plus their missingness pattern. The
`fit_model`

methods are typically short wrappers around a statistical model fitting
function and return the estimated model. The model is then passed to one of the
`mi-methods`

to impute the missing values of that `missing_variable`

.

Users can easily overwrite these methods to estimate a different model, such as wrapping
`glm`

instead of `bayesglm`

. See the source code for examples,
but the basic outline is to first extract the `X`

slot of the
`missing_data.frame`

, then drop some of its columns using the `index`

slot
of the `missing_data.frame`

, next pass the result along with the `data`

slot
of `y`

to a statistical fitting function, and finally returned the appropriately classed
result (along with the subset of `X`

used in the model).

Many of the optional arguments to a statistical fitting function can be specified using the
slots of `y`

(e.g. its `family`

slot) or the slots of **data** (e.g. its
`weights`

slot).

The exception is the method where `y`

is missing, which is used internally by
`mi`

, and should *not* be overwritten unless great care is taken to understand
its role.

If `y`

is missing, then the modified `missing_data.frame`

passed to
`data`

is returned. Otherwise, the estimated model is returned as a classed
list object.

Ben Goodrich and Jonathan Kropko, for this version, based on earlier versions written by Yu-Sung Su, Masanao Yajima, Maria Grazia Pittau, Jennifer Hill, and Andrew Gelman.

`missing_variable`

, `mi`

, `get_parameters`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
getMethod("fit_model", signature(y = "binary", data = "missing_data.frame"))
setMethod("fit_model", signature(y = "binary", data = "missing_data.frame"), def =
function(y, data, ...) {
to_drop <- data@index[[y@variable_name]]
X <- data@X[, -to_drop]
start <- NULL
# using glm.fit() instead of bayesglm.fit()
out <- glm.fit(X, y@data, weights = data@weights[[y@variable_name]], start = start,
family = y@family, Warning = FALSE, ...)
out$x <- X
class(out) <- c("glm", "lm") # not "bayesglm" class anymore
return(out)
})
## Not run:
if(!exists("imputations", env = .GlobalEnv)) {
imputations <- mi:::imputations # cached from example("mi-package")
}
imputations <- mi(imputations) # will use new fit_model() method for binary variables
## End(Not run)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.