### R Code Examples Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/DELIVERY_SUMMARY.txt This documentation set includes over 20 working R code examples to illustrate methods and workflows. These examples are intended for testing in R 4.0+. ```R # Example R code snippet (placeholder) # Actual examples would be detailed in quick-reference.md ``` -------------------------------- ### Install softImpute Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'softImpute' package for nuclear norm minimization. ```r install.packages("softImpute") ``` -------------------------------- ### Install hot.deck Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'hot.deck' package for hot-deck imputation. ```r install.packages("hot.deck") ``` -------------------------------- ### Install yaImpute Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'yaImpute' package for k-NN imputation. ```r install.packages("yaImpute") ``` -------------------------------- ### Install VIM Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'VIM' package for visualization and imputation methods. ```r install.packages("VIM") ``` -------------------------------- ### Browse Vignettes for mice Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Open the vignettes for the 'mice' package to find detailed examples and usage guides. ```r browseVignettes("mice") ``` -------------------------------- ### Install missMDA Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'missMDA' package for matrix completion using PCA/SVD. ```r install.packages("missMDA") ``` -------------------------------- ### Install mice Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'mice' package for multiple imputation. ```r install.packages("mice") ``` -------------------------------- ### Install Amelia Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'Amelia' package for bootstrap multiple imputation. ```r install.packages("Amelia") ``` -------------------------------- ### Install jomo Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'jomo' package for multilevel multiple imputation. ```r install.packages("jomo") ``` -------------------------------- ### Install naniar Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'naniar' package for missing data visualization. ```r install.packages("naniar") ``` -------------------------------- ### Install imputeTS Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use this command to install the 'imputeTS' package for time series imputation. ```r install.packages("imputeTS") ``` -------------------------------- ### Missing Data Visualization with naniar Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/selection-guide.md Provides examples of visualizing missing data patterns using the 'naniar' package, including heatmaps and upset plots. ```R vis_miss(data) gg_miss_upset(data) ``` -------------------------------- ### Help Page for Amelia Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Access the help documentation for the 'Amelia' package, a tool for handling missing data. ```r ?Amelia::amelia ``` -------------------------------- ### Help Page for mice Package Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Access the help documentation for the 'mice' package to learn about its functions for multivariate imputation. ```r ?mice::mice ``` -------------------------------- ### Missing Data Visualization with VIM Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/selection-guide.md Demonstrates visualization of missing data using traditional methods from the 'VIM' package, such as matrix plots and marginal plots. ```R matrixplot(data) marginplot(data) ``` -------------------------------- ### MICE Standard Workflow Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/methods-reference.md Outlines the standard workflow for Multiple Imputation by Chained Equations (MICE), including imputation and analysis steps. This pseudocode illustrates the iterative process. ```pseudocode Input: Dataset with missing values, m = number of imputations, K = iterations For each of m imputations: 1. Initialize: Fill missing values with simple method (e.g., mean) 2. For iteration k = 1 to K: For each variable j with missing values: - Regress j on other variables using complete cases - Impute missing j values from predictive distribution 3. Output: Complete dataset i Analysis: - Fit model M times (once per imputation) - Pool results: Combine m estimates using Rubin's rules ``` -------------------------------- ### SEM/FIML Analysis with Missing Data (lavaan) Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/README.md This snippet demonstrates how to perform Structural Equation Modeling (SEM) using Full Information Maximum Likelihood (FIML) for handling missing data automatically with the 'lavaan' package. ```r library(lavaan) fit <- sem(model, data=data, missing="fiml") # Automatic summary(fit) ``` -------------------------------- ### Repository Structure Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/overview.md Illustrates the directory structure of the missingdata CRAN Task View repository. It shows the location of the main README, the task view source document, and the CI validation workflow. ```bash missingdata/ ├── README.md # Project metadata and contribution guide ├── MissingData.md # Main task view source document └── .github/ └── workflows/ └── validate-ctv.yml # CI validation workflow ``` -------------------------------- ### Visualization of Missing Data Patterns Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Visualize missing data patterns using `naniar` for modern plots like heatmaps and upset diagrams, or `VIM` for traditional approaches such as matrix plots and margin plots. ```r library(naniar) vis_miss(data) # Heatmap gg_miss_upset(data) # Upset diagram vis_miss_cluster(data) # Clustering of patterns # Traditional approach library(VIM) matrixplot(data) marginplot(data[,c("y","x")]) ``` -------------------------------- ### Sensitivity Analysis for MNAR Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/selection-guide.md If Missing Not At Random (MNAR) is suspected, use ui::bounding_ci() for sensitivity analysis or isni for further checks. ```r ui::bounding_ci() isni ``` -------------------------------- ### Sensitivity Analysis for MNAR (ui) Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/README.md Use the 'ui' package to perform sensitivity analysis for data missing not at random (MNAR). This code calculates bounds on confidence intervals to assess the impact of MNAR assumptions. ```r library(ui) ci <- bounding_ci(y ~ x, data=data) # Bounds on CI print(ci) ``` -------------------------------- ### Check MICE Convergence with Plot Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Visualize the convergence of MICE imputation chains by plotting the imputation object. Look for stabilization of trace lines within the first approximately 10 iterations. ```r plot(mice_object) ``` -------------------------------- ### Bootstrap Multiple Imputation using Amelia Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md The `Amelia` package offers bootstrap multiple imputation. Specify continuous, nominal, and ordinal variables as needed. Analysis involves fitting models to each imputation and combining the results. ```r library(Amelia) # Specify: y=continuous, d=binary imp <- amelia(data, m=5, noms="d", ords=NULL) # Analyze library(mitools) models <- lapply(imp$imputations, function(x) lm(y ~ x1, x)) MIcombine(models) ``` -------------------------------- ### Visualize Missing Data Patterns Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Use the 'vis_miss' function from the 'naniar' package to visualize missing data patterns, often presented as a table showing the percentage of missing values per variable. ```r naniar::vis_miss() ``` -------------------------------- ### Standard Multiple Imputation Workflow (mice) Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/README.md Use this workflow for standard multiple imputation using the 'mice' package. It involves imputing missing values, fitting models to imputed datasets, and pooling the results. ```r library(mice) imp <- mice(data, m=5, seed=123) # Impute fit <- with(imp, lm(y ~ x)) # Fit summary(pool(fit)) # Pool ``` -------------------------------- ### Nuclear Norm Minimization for Matrix Completion Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Perform matrix completion using nuclear norm minimization with the `softImpute` function from the `softImpute` package. Suitable for high-dimensional data. ```r softImpute::softImpute() ``` -------------------------------- ### MNAR Sensitivity Analysis (Local Sensitivity) Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Perform local sensitivity analysis for MNAR assumptions using the 'isni' package. ```r isni() ``` -------------------------------- ### Assess Missing Data Patterns Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/selection-guide.md Use VIM::matrixplot() or naniar::vis_miss() to visualize missing data patterns. Test for MCAR using misty::Little(). ```r VIM::matrixplot() naniar::vis_miss() misty::Little() ``` -------------------------------- ### PCA-based Matrix Completion Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Perform matrix completion using PCA with the `imputePCA` function from the `missMDA` package. Suitable for high-dimensional data. ```r missMDA::imputePCA() ``` -------------------------------- ### Imputation for Small Continuous Datasets Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md For small datasets (n < 50) with continuous data, consider using 'em.norm' followed by 'imp.norm' from the 'norm' package. ```r norm::em.norm() then norm::imp.norm() ``` -------------------------------- ### Faster Imputation for Large Datasets Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md For large datasets (n > 5000), 'miceRanger::miceRanger()' offers a faster imputation alternative. ```r miceRanger::miceRanger() ``` -------------------------------- ### Sensitivity to Missing Data Assumption (ui) Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Calculates bounds on confidence intervals under different Missing Not At Random (MNAR) mechanisms, providing a range of plausible results. ```r library(ui) # Bounds on confidence interval under different MNAR mechanisms ci_bounds <- bounding_ci(response~treatment, data=data) print(ci_bounds) # Shows range of plausible CIs ``` -------------------------------- ### General Item Response Theory (IRT) Models Source: https://github.com/cran-task-views/missingdata/blob/main/_autodocs/quick-reference.md Fit general IRT models using the `mirt` function from the `mirt` package. ```r mirt::mirt() ```