model_impute: Model an imputed dataset

model_imputeR Documentation

Model an imputed dataset

Description

Model an imputed dataset

Usage

model_impute(
  object,
  model_fun,
  rhs,
  model_args = list(),
  extractor,
  extractor_args = list(),
  filter = list(),
  mutate = list(),
  ...
)

## S4 method for signature 'ANY'
model_impute(
  object,
  model_fun,
  rhs,
  model_args = list(),
  extractor,
  extractor_args = list(),
  filter = list(),
  mutate = list(),
  ...
)

## S4 method for signature 'aggregatedImputed'
model_impute(
  object,
  model_fun,
  rhs,
  model_args = list(),
  extractor,
  extractor_args = list(),
  filter = list(),
  mutate = list(),
  ...
)

Arguments

object

The imputed dataset.

model_fun

The function to apply on each imputation set. Or a string with the name of the function. Include the package name when the function is not in one of the base R packages. For example: "glm" or "INLA::inla".

rhs

The right hand side of the model.

model_args

An optional list of arguments to pass to the model function.

extractor

A function which return a matrix or data.frame. The first column should contain the estimate, the second the standard error of the estimate.

extractor_args

An optional list of arguments to pass to the extractor function.

filter

An optional argument to filter the raw dataset before aggregation. Will be passed to dplyr::filter().

mutate

An optional argument to alter the aggregated dataset. Will be passed to the .dots argument ofdplyr::mutate(). This is mainly useful for simple conversions, e.g. factors to numbers and vice versa.

...

currently ignored.

Examples

dataset <- generate_data(n_year = 10, n_site = 50, n_run = 1)
dataset$Count[sample(nrow(dataset), 50)] <- NA
model <- lm(Count ~ Year + factor(Period) + factor(Site), data = dataset)
imputed <- impute(data = dataset, model = model)
aggr <- aggregate_impute(imputed, grouping = c("Year", "Period"), fun = sum)
extractor <- function(model) {
  summary(model)$coefficients[, c("Estimate", "Std. Error")]
}
model_impute(
  object = aggr,
  model_fun = lm,
  rhs = "0 + factor(Year)",
  extractor = extractor
)

INBO-BMK/multimput documentation built on Sept. 14, 2023, 6:04 p.m.