Model an imputed dataset
model_impute(
object,
model_fun,
rhs,
model_args = list(),
extractor,
extractor_args = list(),
filter = list(),
mutate = list(),
...
)
# S4 method for ANY
model_impute(
object,
model_fun,
rhs,
model_args = list(),
extractor,
extractor_args = list(),
filter = list(),
mutate = list(),
...
)
# S4 method for aggregatedImputed
model_impute(
object,
model_fun,
rhs,
model_args = list(),
extractor,
extractor_args = list(),
filter = list(),
mutate = list(),
...
)
The imputed dataset.
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"
.
The right hand side of the model.
An optional list of arguments to pass to the model function.
A function which return a matrix
or data.frame
.
The first column should contain the estimate,
the second the standard error of the estimate.
An optional list of arguments to pass to the extractor
function.
An optional argument to filter the raw dataset before aggregation.
Will be passed to dplyr::filter()
.
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.
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
)
#> # A tibble: 10 × 5
#> Parameter Estimate SE LCL UCL
#> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 factor(Year)1 1311. 288. 746. 1875.
#> 2 factor(Year)2 1416. 288. 850. 1981.
#> 3 factor(Year)3 1592. 289. 1026. 2157.
#> 4 factor(Year)4 1676. 289. 1110. 2243.
#> 5 factor(Year)5 1975. 288. 1410. 2541.
#> 6 factor(Year)6 2501. 288. 1936. 3066.
#> 7 factor(Year)7 2122. 288. 1556. 2687.
#> 8 factor(Year)8 2249. 289. 1683. 2814.
#> 9 factor(Year)9 2137. 288. 1572. 2702.
#> 10 factor(Year)10 2363. 288. 1798. 2928.