[R] plotting missing data patterns

Patrick E. McKnight pem at theriver.com
Fri Jan 4 21:46:31 CET 2002


I have one other problem and then I'll stop and get back to writing.  I 
want to plot a missing data matrix (the R matrix a la Little and Rubin) 
to graphically depict where the missing data lie in the matrix.  Some 
statistical packages produce a graphical depiction of the missing data 
patterns by plotting the matrix, color-coding the plot with contrasting 
colors for either missing or present.

So far, I have fumbled my way through parts of it but I can't figure out 
what I am doing wrong.  Here is my situation....

Dataset...now sorted the way I want it (thanks)

 > newcouple
    id age sex iv1 iv2 dv mdpf
2   0   0   0   0   0  0    1
3   0   0   0   0   0  0    1
5   0   0   0   0   0  0    1
7   0   0   0   0   0  0    1
9   0   1   0   0   0  0    3
6   0   0   1   0   0  0    5
10  0   0   0   1   0  0    9
1   0   0   0   0   1  0   17
4   0   0   0   0   0  1   33
8   0   0   0   0   0  1   33


# begin code

# create matrix from data.frame for easy indexing

 > dummy <- as.matrix(newcouple)

# create new vectors to later plot

x <- mat.or.vec(1,1)
y <- mat.or.vec(1,1)

# define default plotting information with par

par(bg="black",pch=22)

# create new frame for plotting

plot.new()

# loop through the matrix to only plot a square for the observations and
# variables that are missing

     for (i in 1:nrow(dummy)){
       for (j in 1:ncol(dummy)){
         if (dummy[i,j] == 1){

# record the coordinates for the missing values to plot with a points
# call later

            y <- append(y,i)
            x <- append(x,j)
          }
       }
     }


# points to plot from my

     points(x,y,bg="white")

# end code


The graphical output is just a black window with one point plotted (0,0 
I think).  What am I doing wrong?  The points function does not appear 
to be adding the extra points the way I want it to add them to the same 
display window.

In the end, I would like to have either a black background with white 
squares (holes) or a white background with black squares to represent 
where the data are missing.  I will adjust the squares to an appropriate 
size later.  I know that there are other procedures for graphically 
depicting missing data but I (and my colleagues) want this graph for now.

Any help would be greatly appreciated.  Thanks again in advance.



-- 
________________________________________________________________________

Cheers,

Patrick

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list