0
votes

Good morning, I'm dealing with graphic representation of missing data imputeted via mean imputation method. This is the dataset I'm working on:

> data2
    age   fev  ht sex smoke
1     9 1.708 145   1     1
2     8 1.724 171   1     1
3     7 1.720 138   1     1
4     9 1.558 135   2     1
5     9 1.895 145   2     1
6     8 2.336 155   1     1
7     6 1.919 147   1     1
8     6 1.415 142   1     1
9     8 1.987 149   1     1
10    9 1.942 152   1     1
11    6 1.602 135   1     1
12    8 1.735 137   2     1
13    8 2.193 149   1     1
14    8 2.118 154   2     1
15    8 2.258 147   2     1
16    7 1.932 135   2     1
17    5 1.472 127   2     1
18    6 1.878  NA   1     1
19    9 2.352 150   2     1
20    9 2.604 156   2     1
21    5 1.400 124   1     1
22    5 1.256 133   1     1
23    4 0.839 122   1     1
24    7 2.578 159   2     1
25    9 2.988 165   1     1
26    3 1.404 131   2     1
27    9 2.348 152   2     1
28    5 1.755 132   2     1
29    8 2.980 152   1     1
30    9 2.100 152   1     1
31    5 1.282 124   1     1
32    9 3.000 166   2     1
33    8 2.673 152   1     1
34    7 2.093 146   1     1
35    5 1.612 132   1     1
36    8 2.175 150   1     1
37    9 2.725 150   2     1
38    8 2.071 140   2     1
39    8 1.547 145   2     1
40    8 2.004 145   2     1
41    9 3.135 152   1     1
42    8 2.420 150   2     1
43    5 1.776 130   2     1
44    8 1.931 145   1     1
45    5 1.343 127   1     1
46    9 2.076 145   1     1
47    7 1.624 137   2     1
48    8 1.344 133   1     1
49    6 1.650 140   2     1
50    8 2.732 154   2     1
51    5 2.017 138   2     1
52    9 2.797 156   1     1
53    9    NA 157   2     1
54    8 1.703 138   2     1
55    6 1.634 137   2     1
56    9 2.570 145   2     1
57    9 3.016 159   1     1
58    7 2.419 152   1     1
59    4 1.569 127   1     1
60    8 1.698 146   1     1
61    8 2.123 152   2     1
62    8 2.481 152   1     1
63    6 1.481 130   1     1
64    4 1.577 124   1     1
65    8 1.940 150   2     1
66    6 1.747 146   2     1
67    9 2.069 147   2     1
68    7 1.631 141   1     1
69    5 1.536 132   1     1
70    9 2.560 154   1     1
71    8 1.962 145   2     1
72    8 2.531 147   1     1
73    9 2.715 152   2     1
74    9 2.457 150   2     1
75    9 2.090 151   2     1
76    7 1.789 142   2     1
77    5 1.858 135   2     1
78    5 1.452 130   2     1
79    9    NA 175   2     1
80    6 1.719 135   1     1
81    7 2.111 145   1     1
82    6 1.695 135   1     1
83    8 2.211 160   2     1
84    8 1.794 138   2     1
85    7 1.917 147   1     1
86    8 2.144  NA   1     1
87    7 1.253 132   2     1
88    9 2.659 156   2     1
89    5 1.580 133   2     1
90    9 2.126 157   2     1
91    9 3.029 156   1     1
92    9 2.964 164   2     1
93    7 1.611  NA   2     1
94    8 2.215 152   1     1
95    8 2.388 152   1     1
96    9 2.196 155   2     1
97    9 1.751 147   2     1
98    9 2.165 156   2     1
99    7 1.682 140   2     1
100   8 1.523 140   2     1
101   8 1.292 132   1     1
102   7 1.649 137   2     1
103   9 2.588 160   2     1
104   4 0.796 119   2     1
105   9 2.574 154   1     1
106   6 1.979 142   2     1
107   8 2.354 149   2     1
108   6 1.718 140   2     1
109   7 1.742 149   1     1
110   7 1.603 130   1     1
111   8 2.639 151   1     1
112   7 1.829 137   1     1
113   7 2.084 147   2     1
114   7 2.220 147   2     1
115   7 1.473 133   1     1
116   8 2.341 154   1     1
117   7 1.698 138   1     1
118   5 1.196 118   1     1
119   8 1.872 144   1     1
120   7 2.219 140   2     1
121   9 2.420 145   2     1
122   7 1.827 138   1     1
123   7 1.461 137   1     1
124   6 1.338  NA   2     1
125   8 2.090 145   2     1
126   8 1.697 150   1     1
127   8 1.562 140   2     1
128   9 2.040 141   1     1
129   7 1.609 131   1     1
130   8 2.458 155   1     1
131   9 2.650 161   2     1
132   8 1.429 146   2     1
133   8 1.675 135   2     1
134   9 1.947 144   1     1
135   8 2.069 137   2     1
136   6 1.572 132   2     1
137   6 1.348 135   2     1
138   8 2.288 156   1     1
139   9 1.773 149   2     1
140   5 0.791 132   1     1
141   7 1.905 147   2     1
142   9 2.463 155   1     1
143   6 1.431 130   2     1
144   9 2.631 157   1     1
145   9 3.114 164   2     1
146   9 2.135 149   2     1
147   6 1.527 133   2     1
148   8 2.293 147   1     1
149   9 3.042 168   1     1
150   8 2.927 161   2     1
151   8 2.665 163   1     1
152   9 2.301 149   2     1
153   9 2.460 163   2     1
154   9 2.592 154   1     1
155   7 1.750 140   1     1
156   8 1.759 135   2     1
157   6 1.536 122   2     1
158   9 2.259 149   1     1
159   9 2.048 164   1     1
160   9 2.571 154   2     1
161   7 2.046 142   2     1
162   8 1.780 149   1     1
163   5 1.552 137   1     1
164   8 1.953 147   1     1
165   9 2.893 164   2     1
166   6 1.713 128   2     1
167   9 2.851 152   1     1
168   6 1.624 131   2     1
169   8 2.631 150   2     1
170   5 1.819 135   2     1
171   7 1.658 135   2     1
172   7 2.158 136   2     1
173   4 1.789 132   2     1
174   9 3.004 163   1     1
175   8 2.503 160   2     1
176   9 1.933 147   1     1
177   9 2.091 149   1     1
178   9 2.316  NA   1     1
179   5 1.704  NA   1     1
180   9 1.606 146   1     1
181   7 1.165 119   2     1
182   6 2.102 141   1     1
183   9 2.320 145   1     1
184   9 2.230 155   2     1
185   9 1.716 141   2     1
186   7 1.790 136   2     1
187   5 1.146 127   1     1
188   8 2.187 156   1     1
189   9 2.717 156   2     1
190   7 1.796 140   2     1
191   9 1.953 147   2     2
192   8 1.335 144   1     1
193   9 2.119 145   2     1
194   6 1.666 132   2     1
195   6 1.826 133   2     1
196   8 2.709 159   1     1
197   9 2.871 165   2     1
198   5 1.092 127   1     1
199   6 2.262 146   2     1
200   6 2.104 144   2     1

I've used the following code to return back the observed vs the imputed data scenario and the sided scatterplot of Y="fev" versus X="age".

1. FIRST GRAPH
library(lattice)

par(mfrow=c(1,2))
breaks <- seq(-20, 200, 10)
nudge <- 1
lwd <- 1.5
x <- matrix(c(breaks-nudge, breaks+nudge), ncol=2, nrow = 46)
obs <- data2[,"fev"]
mis  <- imp$imp$fev[,1]
fobs <- c(hist(obs, breaks, plot=FALSE)$fev, 0)
fmis <- c(hist(mis, breaks, plot=FALSE)$fev, 0)
y <- matrix(c(fobs, fmis), ncol=2, nrow = 46)
matplot(x, y, type="s",
        col=c(mdc(4),mdc(5)), lwd=2, lty=1,
        xlim = c(0, 150), ylim = c(0,40), yaxs = "i",
        xlab="fev",
        ylab="Frequency")
box() 

2. SECOND GRAPH
tp <- xyplot(imp, fev ~ age, na.groups=ici(imp), 
             ylab="fev", xlab="age",
             cex = 0.75, lex=lwd, pch=19,
             ylim = c(-20, 180), xlim = c(0,350))
print(tp, newpage = FALSE, position = c(0.48,0.08,1,0.92))

Although the code works well, I'm not so as to its validity, as I am supposed to have back a graphic results like those I let attached here enter image description here, whereas I'm keeping on getting a sort of graphs like these enter image description here

What do you think about? Any clue as to making the right cade out? Thanks for helping

1

1 Answers

1
votes

You didn't post the complete code. It isn't exactly clear what your imp data, which you are trying to plot looks like. The data you posted is named data2, but I don't really know at which point in your code this is used.

As for reasons, why your code might not not show anything, it seems the range for fev is about from 0 to 3. age is about from 1 to 10.

But axis limits in the first plot are:

xlim = c(0, 150), ylim = c(0,40)

In the second plot

ylim = c(-20, 180), xlim = c(0,350)

Which means, the actual data you want to plot is in quite a small area of the plot (as you can see).

You have to adjust your axis limits to the range of your data.