Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including more general formulas in irmi #33

Open
matthias-da opened this issue Dec 20, 2019 · 1 comment
Open

including more general formulas in irmi #33

matthias-da opened this issue Dec 20, 2019 · 1 comment
Assignees
Milestone

Comments

@matthias-da
Copy link
Collaborator

matthias-da commented Dec 20, 2019

currently, in irmi only simple formulas for each variable can be specified, such as

form=list(
  NonD  = c("BodyWgt", "BrainWgt"),
  Dream = c("BodyWgt", "BrainWgt"),
  Sleep = c("BrainWgt"),
  Span  = c("BodyWgt"),
  Gest  = c("BodyWgt", "BrainWgt")
)

However, it should also work for any formula specified (as long as the correct variable names are used).

library(VIM)
data(sleep)
form = list(
  "log(NonD)  ~ log(BodyWgt) + log(BrainWgt) + I(Sleep^2)",
  "Dream      ~ BodyWgt + BrainWgt:Danger",
  "log(Sleep) ~ BrainWgt * Danger + I(BrainWgt^2)",
  "Span       ~ ."
  "Gest       ~ sqrt(BodyWgt) + Span * Danger"
)
irmi(sleep, modelFormulas = form, trace = TRUE)

Only with this enhancement irmi can outperform other imputation methods and be efficiently used in practice for more complex data and statistical modelling purposes.

@GregorDeCillia
Copy link
Contributor

GregorDeCillia commented Apr 22, 2020

I would prefer a syntax without quotes for example

form = list(
  log(NonD)  ~ log(BodyWgt) + log(BrainWgt) + I(Sleep^2),
  Dream      ~ BodyWgt + BrainWgt:Danger,
  log(Sleep) ~ BrainWgt * Danger + I(BrainWgt^2),
  Span       ~ .,
  Gest       ~ sqrt(BodyWgt) + Span * Danger
)

As discussed with @matthias-da, transormations on the lhs (log(NonD) ~ .) are a bit tricky because determining back-transformations is not trivial. However, I will try to make the rhs more flexible. Possibly, the API will also use named lists where the names correspond to the column names

form = list(
  NonD  = ~ log(BodyWgt) + log(BrainWgt) + I(Sleep^2),
  Dream = ~ BodyWgt + BrainWgt:Danger,
  Sleep = ~ BrainWgt * Danger + I(BrainWgt^2),
  Span  = ~ .,
  Gest  = ~ sqrt(BodyWgt) + Span * Danger
)

This would make it fairly straightforward to maintain backward compability

normalize_model_formulas <- function(form) {
  lapply(
    form,
    function(x) {
      if (is.character(x))
        convert_to_formula(x)
      else
        x
    }
  )
}

@alexkowa alexkowa modified the milestones: VIM 6.0.0, 6.2.0 Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants