IQSS / Amelia

Amelia: A Package for Missing Data
http://gking.harvard.edu/amelia
61 stars 17 forks source link

Missmap plot (axis, label and order) #8

Closed FransAndersen closed 6 years ago

FransAndersen commented 7 years ago

Hi, first of all I would like to thank you for a great package!

As you see in the picture below the missmap plot looks a bit strange:

Secondly, my missing data in this example is located in observation x8: 2,6 and x13: 2,3,7 while looking at the plot it seems that its located in the end of the variable (around observation 120).

Further, it would be great to also present the percentage missing in the ledgend, such as missing 5%

To reproduce the plot, see data and code-snippet below.

missmap

R 3.3.2 Amelia 1.7.4

---------------Script below--------------------- dates <- c("2004-01-01","2004-02-01","2004-03-01","2004-04-01","2004-05-01","2004-06-01","2004-07-01","2004-08-01","2004-09-01","2004-10-01","2004-11-01","2004-12-01","2005-01-01","2005-02-01","2005-03-01","2005-04-01","2005-05-01","2005-06-01","2005-07-01","2005-08-01","2005-09-01","2005-10-01","2005-11-01","2005-12-01","2006-01-01","2006-02-01","2006-03-01","2006-04-01","2006-05-01","2006-06-01","2006-07-01","2006-08-01","2006-09-01","2006-10-01","2006-11-01","2006-12-01","2007-01-01","2007-02-01","2007-03-01","2007-04-01","2007-05-01","2007-06-01","2007-07-01","2007-08-01","2007-09-01","2007-10-01","2007-11-01","2007-12-01","2008-01-01","2008-02-01","2008-03-01","2008-04-01","2008-05-01","2008-06-01","2008-07-01","2008-08-01","2008-09-01","2008-10-01","2008-11-01","2008-12-01","2009-01-01","2009-02-01","2009-03-01","2009-04-01","2009-05-01","2009-06-01","2009-07-01","2009-08-01","2009-09-01","2009-10-01","2009-11-01","2009-12-01","2010-01-01","2010-02-01","2010-03-01","2010-04-01","2010-05-01","2010-06-01","2010-07-01","2010-08-01","2010-09-01","2010-10-01","2010-11-01","2010-12-01","2011-01-01","2011-02-01","2011-03-01","2011-04-01","2011-05-01","2011-06-01","2011-07-01","2011-08-01","2011-09-01","2011-10-01","2011-11-01","2011-12-01","2012-01-01","2012-02-01","2012-03-01","2012-04-01","2012-05-01","2012-06-01","2012-07-01","2012-08-01","2012-09-01","2012-10-01","2012-11-01","2012-12-01","2013-01-01","2013-02-01","2013-03-01","2013-04-01","2013-05-01","2013-06-01","2013-07-01","2013-08-01","2013-09-01","2013-10-01","2013-11-01","2013-12-01") c0 <- c(33736.25,NA,35005.65,35640.35,36275.05,NA,37604.00,35536.00,37919.25,38211.00,39905.75,38832.75,36678.75,37647.75,41619.50,39772.00,34867.25,38081.75,37346.50,41084.00,40469.00,40494.25,45103.50,44942.25,49926.50,49098.25,55861.75,49798.50,60079.50,54494.25,52755.50,54108.50,51919.50,58384.00,59443.75,53449.75,61783.50,56632.25,60741.25,53469.25,58679.25,56215.50,60113.75,55327.25,47813.50,56163.75,55138.25,42860.50,53791.75,58305.75,57092.25,65094.00,58048.50,62106.75,70625.75,58003.75,57788.25,48779.00,37041.50,31290.50,29668.50,26596.25,29381.00,28410.00,27741.25,34613.25,38353.25,38667.75,40339.25,41320.00,40927.75,45773.50,44696.75,40971.50,50719.75,46328.00,38762.75,42482.50,43731.25,44469.75,47563.50,49267.50,51317.50,49352.00,48782.50,50155.00,58700.25,47921.25,51833.50,56210.75,52743.50,52627.50,50518.75,45608.75,45609.25,40429.50,45020.25,46274.50,48017.00,38877.50,44003.75,35805.50,41224.25,40429.75,41069.75,45422.00,42740.25,39639.75,44829.50,41062.75,38255.50,38981.00,38435.50,36320.00,40649.25,38103.50,36962.00,41676.00,36727.25,12062.25) c1 <- c(50885.5,NA,NA,58949.00,51924.25,59090.50,NA,59753.00,63674.50,63230.50,68688.25,66035.00,63383.50,65055.75,70958.75,71269.00,64961.75,77509.00,75885.00,83534.50,84858.00,85241.75,93909.75,91522.00,99407.00,99633.25,117389.50,114951.75,168926.25,158309.50,161919.50,169263.50,159617.50,164985.50,154616.75,126790.50,124711.25,113504.50,141918.00,147539.75,161306.75,156962.00,175396.50,165245.25,152951.00,184169.25,153251.25,118557.25,155322.25,165626.25,160326.00,191048.25,167630.75,173460.25,193503.50,152676.25,159510.75,113272.75,74325.25,64498.75,67625.75,66280.75,82473.00,88117.25,86794.75,110290.00,119936.50,123294.50,136306.75,138322.25,140173.25,146597.25,147712.25,136953.75,171634.50,154887.75,129906.75,142970.50,148161.75,152943.75,169596.50,174128.75,186321.00,192080.00,191098.25,197343.50,219192.50,170692.25,178529.75,198992.50,201994.75,198898.00,182915.25,154289.25,166130.00,151343.25,168903.00,176862.50,186044.00,156918.75,174224.25,140976.00,166951.50,164822.00,161360.50,185588.75,169266.25,151279.75,177073.00,161400.25,153244.75,151262.25,151801.00,140074.25,158527.75,150819.50,150383.25,165332.75,148387.25,49426.25) data <- data.frame(c0,c1) colnames(data) <- c("X8","X13") ind_category <- NULL ind_group <- NULL target <- 0 amelia_results <-amelia(data,m=5,ts='dates',p2s=0,idvars=ind_category,cs=ind_group,lags=colnames(data)) missingMapAmelia <- missmap(amelia_results, legend = TRUE) missingMapData <- missmap(data[,-1])

mattblackwell commented 7 years ago

Thanks for reporting this. I'll try to get on this, but first, I wanted to post some corrected code, since the above is missing a few things.

dates <- c("2004-01-01",  "2004-02-01",  "2004-03-01",  "2004-04-01",
           "2004-05-01", "2004-06-01", "2004-07-01", "2004-08-01",
           "2004-09-01", "2004-10-01", "2004-11-01", "2004-12-01",
           "2005-01-01", "2005-02-01", "2005-03-01", "2005-04-01",
           "2005-05-01", "2005-06-01", "2005-07-01", "2005-08-01",
           "2005-09-01", "2005-10-01", "2005-11-01", "2005-12-01",
           "2006-01-01", "2006-02-01", "2006-03-01", "2006-04-01",
           "2006-05-01", "2006-06-01", "2006-07-01", "2006-08-01",
           "2006-09-01", "2006-10-01", "2006-11-01", "2006-12-01",
           "2007-01-01", "2007-02-01", "2007-03-01", "2007-04-01",
           "2007-05-01", "2007-06-01", "2007-07-01", "2007-08-01",
           "2007-09-01", "2007-10-01", "2007-11-01", "2007-12-01",
           "2008-01-01", "2008-02-01", "2008-03-01", "2008-04-01",
           "2008-05-01", "2008-06-01", "2008-07-01", "2008-08-01",
           "2008-09-01", "2008-10-01", "2008-11-01", "2008-12-01",
           "2009-01-01", "2009-02-01", "2009-03-01", "2009-04-01",
           "2009-05-01", "2009-06-01", "2009-07-01", "2009-08-01",
           "2009-09-01", "2009-10-01", "2009-11-01", "2009-12-01",
           "2010-01-01", "2010-02-01", "2010-03-01", "2010-04-01",
           "2010-05-01", "2010-06-01", "2010-07-01", "2010-08-01",
           "2010-09-01", "2010-10-01", "2010-11-01", "2010-12-01",
           "2011-01-01", "2011-02-01", "2011-03-01", "2011-04-01",
           "2011-05-01", "2011-06-01", "2011-07-01", "2011-08-01",
           "2011-09-01", "2011-10-01", "2011-11-01", "2011-12-01",
           "2012-01-01", "2012-02-01", "2012-03-01", "2012-04-01",
           "2012-05-01", "2012-06-01", "2012-07-01", "2012-08-01",
           "2012-09-01", "2012-10-01", "2012-11-01", "2012-12-01",
           "2013-01-01", "2013-02-01", "2013-03-01", "2013-04-01",
           "2013-05-01", "2013-06-01", "2013-07-01", "2013-08-01",
           "2013-09-01", "2013-10-01", "2013-11-01", "2013-12-01")
c0 <- c(33736.25, NA, 35005.65, 35640.35, 36275.05, NA, 37604.00,
        35536.00, 37919.25, 38211.00, 39905.75, 38832.75, 36678.75,
        37647.75, 41619.50, 39772.00, 34867.25, 38081.75, 37346.50,
        41084.00, 40469.00, 40494.25, 45103.50, 44942.25, 49926.50,
        49098.25, 55861.75, 49798.50, 60079.50, 54494.25, 52755.50,
        54108.50, 51919.50, 58384.00, 59443.75, 53449.75, 61783.50,
        56632.25, 60741.25, 53469.25, 58679.25, 56215.50, 60113.75,
        55327.25, 47813.50, 56163.75, 55138.25, 42860.50, 53791.75,
        58305.75, 57092.25, 65094.00, 58048.50, 62106.75, 70625.75,
        58003.75, 57788.25, 48779.00, 37041.50, 31290.50, 29668.50,
        26596.25, 29381.00, 28410.00, 27741.25, 34613.25, 38353.25,
        38667.75, 40339.25, 41320.00, 40927.75, 45773.50, 44696.75,
        40971.50, 50719.75, 46328.00, 38762.75, 42482.50, 43731.25,
        44469.75, 47563.50, 49267.50, 51317.50, 49352.00, 48782.50,
        50155.00, 58700.25, 47921.25, 51833.50, 56210.75, 52743.50,
        52627.50, 50518.75, 45608.75, 45609.25, 40429.50, 45020.25,
        46274.50, 48017.00, 38877.50, 44003.75, 35805.50, 41224.25,
        40429.75, 41069.75, 45422.00, 42740.25, 39639.75, 44829.50,
        41062.75, 38255.50, 38981.00, 38435.50, 36320.00, 40649.25,
        38103.50, 36962.00, 41676.00, 36727.25, 12062.25)
c1 <- c(50885.5, NA, NA, 58949.00, 51924.25, 59090.50, NA, 59753.00,
        63674.50, 63230.50, 68688.25, 66035.00, 63383.50, 65055.75,
        70958.75, 71269.00, 64961.75, 77509.00, 75885.00, 83534.50,
        84858.00, 85241.75, 93909.75, 91522.00, 99407.00, 99633.25,
        117389.50, 114951.75, 168926.25, 158309.50, 161919.50,
        169263.50, 159617.50, 164985.50, 154616.75, 126790.50,
        124711.25, 113504.50, 141918.00, 147539.75, 161306.75,
        156962.00, 175396.50, 165245.25, 152951.00, 184169.25,
        153251.25, 118557.25, 155322.25, 165626.25, 160326.00,
        191048.25, 167630.75, 173460.25, 193503.50, 152676.25,
        159510.75, 113272.75, 74325.25, 64498.75, 67625.75, 66280.75,
        82473.00, 88117.25, 86794.75, 110290.00, 119936.50, 123294.50,
        136306.75, 138322.25, 140173.25, 146597.25, 147712.25,
        136953.75, 171634.50, 154887.75, 129906.75, 142970.50,
        148161.75, 152943.75, 169596.50, 174128.75, 186321.00,
        192080.00, 191098.25, 197343.50, 219192.50, 170692.25,
        178529.75, 198992.50, 201994.75, 198898.00, 182915.25,
        154289.25, 166130.00, 151343.25, 168903.00, 176862.50,
        186044.00, 156918.75, 174224.25, 140976.00, 166951.50,
        164822.00, 161360.50, 185588.75, 169266.25, 151279.75,
        177073.00, 161400.25, 153244.75, 151262.25, 151801.00,
        140074.25, 158527.75, 150819.50, 150383.25, 165332.75,
        148387.25, 49426.25)
data <- data.frame(as.Date(dates), c0, c1)
colnames(data) <- c("dates","X8","X13")
ind_category <- NULL
ind_group <- NULL
target <- 0
library(Amelia)
amelia_results <- amelia(data, m=5, ts='dates', p2s=0, idvars=ind_category, cs=ind_group, lags=colnames(data))
missingMapAmelia <- missmap(amelia_results,  legend = TRUE)
missingMapData <- missmap(data[, -1])