-
Notifications
You must be signed in to change notification settings - Fork 9
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
Plot variance of predicted values after imputation #97
base: main
Are you sure you want to change the base?
Conversation
@KyuriP Thank you for your contribution! As discussed, I've implemented your code into the existing library(ggmice)
imp <- mice::mice(mice::nhanes, printFlag = FALSE)
plot_variance(imp) Created on 2023-03-27 with reprex v2.0.2 library(ggmice)
imp <- mice::mice(mice::nhanes, printFlag = FALSE)
fit <- mice:::with.mids(imp, lm(bmi~age))
plot_variance(fit) Created on 2023-03-27 with reprex v2.0.2 Adjustments/suggestions are welcome! (cc @gerkovink ) |
use |
Thanks a bunch!! I do have two questions still:
library(ggmice)
library(mice)
#>
#> Attaching package: 'mice'
#> The following objects are masked from 'package:ggmice':
#>
#> bwplot, densityplot, stripplot, xyplot
#> The following object is masked from 'package:stats':
#>
#> filter
#> The following objects are masked from 'package:base':
#>
#> cbind, rbind
mira <- with(mice(nhanes, print = FALSE), lm(bmi~chl))
plot_variance(mira)
#> Warning: Removed 9 rows containing missing values (`geom_point()`). Created on 2023-04-11 with reprex v2.0.2 |
One issue. This function does not allow for the mild workflow (e.g. library(mice, warn.conflicts = FALSE)
library(ggmice, warn.conflicts = FALSE)
library(magrittr)
library(purrr)
# mild workflow with purrr:map()
mild_mira <-
nhanes %>%
mice(print = FALSE) %>%
complete("all") %>%
map(~.x %$% lm(bmi~chl))
plot_variance(mild_mira)
#> Error in plot_variance(mild_mira): Input is not a Multiply Imputed Data Set of class `mids`/ `mira`.
#>
#> Perhaps function mice::as.mids() can be of use? This error message is slightly informative, but not sufficiently as it should point towards The with workflow works without fail: # regular workflow
mira <- with(mice(nhanes,
print = FALSE),
lm(bmi~chl))
plot_variance(mira)
#> Warning: Removed 9 rows containing missing values (`geom_point()`). Now the interesting thing is that both # pooling
pool(mira)
#> Class: mipo m = 5
#> term m estimate ubar b t dfcom
#> 1 (Intercept) 5 20.35823098 1.530174e+01 5.1736784106 2.151015e+01 23
#> 2 chl 5 0.03256681 4.122791e-04 0.0001760493 6.235383e-04 23
#> df riv lambda fmi
#> 1 11.48917 0.4057326 0.2886272 0.3868209
#> 2 10.00654 0.5124178 0.3388070 0.4404779
pool(mild_mira)
#> Class: mipo m = 5
#> term m estimate ubar b t dfcom
#> 1 (Intercept) 5 22.77324050 1.472193e+01 4.800490e-01 1.529799e+01 23
#> 2 chl 5 0.01958118 3.950836e-04 2.448063e-05 4.244603e-04 23
#> df riv lambda fmi
#> 1 20.28439 0.03912930 0.03765585 0.1203159
#> 2 19.30457 0.07435579 0.06920965 0.1526715 Created on 2023-04-12 with reprex v2.0.2 |
Nice work, @KyuriP! One more thing: could you maybe change the discrete scale for the variance to a continuous one to match the |
Okay, now there are just 1 error message in the example and 1 NOTE remaining :)
|
Optional: add a 'perfect prediction' line with |
Another addition: the |
Status check: requested edits not implemented. Converting to draft. |
gerko's new var plot idea