model_impute: Model an imputed dataset

Description Usage Arguments Examples

Description

Model an imputed dataset

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
model_impute(object, model.fun, rhs, model.args, extractor, extractor.args,
  filter, mutate)

## S4 method for signature 'ANY'
model_impute(object, model.fun, rhs, model.args, extractor,
  extractor.args, filter, mutate)

## S4 method for signature 'aggregatedImputed'
model_impute(object, model.fun, rhs,
  model.args, extractor, extractor.args, filter, mutate)

Arguments

object

the imputed dataset

model.fun

the function to apply on each imputation set

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 the .dots argument of filter_

mutate

an optional argument to alter the aggregated dataset. Will be passed to the .dots argument of mutate_. This is mainly useful for simple convertions, e.g. factors to numbers and viceversa

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
dataset <- generateData(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/multimput documentation built on Dec. 16, 2019, 6:04 p.m.