Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file modified Data/imputed_1999-2000_1.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_10.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_11.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_12.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_13.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_14.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_15.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_2.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_3.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_4.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_5.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_6.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_7.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_8.rds
Binary file not shown.
Binary file modified Data/imputed_1999-2000_9.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_1.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_10.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_11.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_12.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_13.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_14.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_15.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_2.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_3.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_4.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_5.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_6.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_7.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_8.rds
Binary file not shown.
Binary file modified Data/imputed_2001-2002_9.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_1.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_10.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_11.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_12.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_13.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_14.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_15.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_2.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_3.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_4.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_5.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_6.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_7.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_8.rds
Binary file not shown.
Binary file modified Data/imputed_2003_2004_9.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_1.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_10.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_11.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_12.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_13.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_14.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_15.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_2.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_3.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_4.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_5.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_6.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_7.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_8.rds
Binary file not shown.
Binary file modified Data/imputed_2005_2006_9.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_1.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_10.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_11.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_12.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_13.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_14.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_15.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_2.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_3.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_4.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_5.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_6.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_7.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_8.rds
Binary file not shown.
Binary file modified Data/imputed_2007_2008_9.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_1.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_10.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_11.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_12.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_13.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_14.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_15.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_2.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_3.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_4.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_5.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_6.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_7.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_8.rds
Binary file not shown.
Binary file modified Data/imputed_2009_2010_9.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_1.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_10.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_11.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_12.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_13.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_14.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_15.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_2.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_3.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_4.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_5.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_6.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_7.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_8.rds
Binary file not shown.
Binary file modified Data/imputed_2011_2012_9.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_1.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_10.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_11.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_12.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_13.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_14.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_15.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_2.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_3.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_4.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_5.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_6.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_7.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_8.rds
Binary file not shown.
Binary file modified Data/imputed_2013_2014_9.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_1.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_10.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_11.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_12.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_13.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_14.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_15.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_2.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_3.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_4.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_5.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_6.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_7.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_8.rds
Binary file not shown.
Binary file modified Data/imputed_2015_2016_9.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_1.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_10.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_11.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_12.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_13.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_14.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_15.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_2.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_3.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_4.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_5.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_6.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_7.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_8.rds
Binary file not shown.
Binary file modified Data/imputed_2017_2018_9.rds
Binary file not shown.
22 changes: 19 additions & 3 deletions NHANES_R/03_imputation.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
# Set working directory
setwd("~/GitHub/NHANES_T2D/Data")
setwd("~/Documents/GitHub/NHANES_T2D/Data") # I need to use the Documents directory in MAC-OS

# load necessary libraries
library(mice)
library(tidyverse)


# load complete merged data to obtain survey number levels
# nothing to do with this data, we only need the factor levels for the loop
cleaned_full_df <- readRDS("cleaned_full_df.rds")

# Correctly fill the missing values of now_BP_meds variable

cleaned_full_df <- cleaned_full_df |> mutate(now_BP_meds =
if_else(hypertension_ever == 'no hypertension' & is.na(now_BP_meds),
'no BP meds', as.character(now_BP_meds)))

# Recode the now_BP_meds variable as factor

cleaned_full_df$now_BP_meds <- as.factor(cleaned_full_df$now_BP_meds)

cleaned_full_df_used <- cleaned_full_df[cleaned_full_df$survey_nr %in% c("1999-2000","2001-2002","2003_2004","2005_2006","2007_2008","2009_2010"),]

# calculate average missingness in data
(sum(is.na(cleaned_full_df))/prod(dim(cleaned_full_df)))*100
# it is 13.9%, which we round up to 15% - so we will make 15 imputed copies
# it is 11.9%, which we round up to 15% - so we will make 15 imputed copies

# load data per survey (loop)
for (i in levels(cleaned_full_df$survey_nr)) {
Expand All @@ -28,7 +41,10 @@ SDMVSTRA <- full_df$SDMVSTRA
full_df$SDMVSTRA <- NULL

# imputation: 5 copies, 5 iterations, random forest algorithm
imputation_object <- mice(full_df, method = "rf", m = 15, maxit = 5, seed = 64370)

# After changes in the mice
# We specify in mice that rfPackage = 'randomForest', otherwise we receive error of incorrect dimensions
imputation_object <- mice(full_df, rfPackage = 'randomForest', m = 15, maxit = 5, seed = 64370)

# investigate convergence visually
# imputation_object$method #those variables with no missing have "" as method - they are still used for imputation
Expand Down