jwb133 / smcfcs

R package implementing Substantive Model Compatible Fully Conditional Specification Multiple Imputation
11 stars 7 forks source link

Plotting method for smcfcs convergence #15

Closed edbonneville closed 3 years ago

edbonneville commented 3 years ago

Hi Jonathan,

From using smcfcs regularly, I had made a helper function to check for convergence - I thought it could be useful to have it in the package as a plot() method, as is done in the mice package.

It requires loading ggplot2, which is thus added to suggests instead of imports in DESCRIPTION. To make it work, running smcfcs() returns an object of class "smcfcs", and the list returned additionally contains element smInfo = list("smtype" = smtype, "smformula" = smformula) (on top of impDatasets and smCoefIter). Latest commit passes CRAN/travis checks, and have tested it locally on all smtypes (based on examples in testthat).

I am also happy to re-work this so instead of using ggplot2 it uses base R graphics, with the lattice package - let me know what your preference might be. Thanks!

Best, Ed

Example

library(smcfcs)
library(ggplot2)

imps <- smcfcs(
  originaldata = ex_linquad,
  smtype = "lm",
  smformula = "y ~ z + x + xsq",
  method = c("", "", "norm", "x^2", ""),
  numit = 30,
  m = 10
)

plot(imps)

plot_smcfcs

jwb133 commented 3 years ago

Thanks Ed, this is fantastic, and great addition to the package. Many thanks for doing this!