I try to generate Simple Random sample with missing data, I do the following
- generate random sample for x, y
- delete some observation
- use mean Imputation to replace it on deleted values
here the program
<< MultivariateStatistics`;
y = RandomSample[Range[200], 20];
x = RandomSample[Range[100], 20] + 0.9*y;
iter = 1000;
n = 12;
r = 9;
k = n - r;
c1 = 0; c2 = 0; c3 = 0; c4 = 0; c5 = 0; c6 = 0;
c7 = 0; c8 = 0; c9 = 0; c10 = 0; c11 = 0; c12 = 0;
c13 = 0; c14 = 0; c15 = 0; c16 = 0; c17 = 0; c18 = 0;
c19 = 0; c20 = 0; c21 = 0; c22 = 0; c23 = 0; c24 = 0;
c25 = 0; c26 = 0;
Array[s1, n]; Array[s2, n]; Array[h, n];
data = Table[{y[[i]], x[[i]]}, {i, 1, 20}];
f1 = Mean[y];; f2 = Mean[x];
Sx2 = Variance[x];
Sy2 = Variance[y];
Cy = Sy2/(f1)^2;
Cx = Sx2/(f2)^2;
SSS = Correlation[x, y];
Sxy = SSS*Sqrt[Sx2*Sy2];
Do
sa = RandomkSubset[data, n];
s1 = Table[sa[[i, 1]], {i, 1, n}];
s2 = Table[sa[[i, 2]], {i, 1, n}];
xn = Mean[s2];
h = Table[i, {i, 1, n}];
dropss = RandomKSubset[h, k];
comp = Complement[h, dropss];
Do[list1[i] = sa[[dropss[[i]]]], {i, 1, k}]; here doesn't work
list2 = Table[list1[[i]], {i, 1, k}];
a1 = Table[list2[[i, 1]], {i, 1, k}];
a2 = Table[list2[[i, 2]], {i, 1, k}];
Do[list3[i] = sa[[comp[[i]]]], {i, 1, n - k}];
list4 = Table[list3[i], {i, 1, n - k}];
a3 = Table[list4[[i, 1]], {i, 1, n - k}];
a4 = Table[list4[[i, 2]], {i, 1, n - k}];
yr = Mean[a3];
xr = Mean[a4];
(* Mean method of imputaion*)
Do[w1[i] = yr, {i, 1, k}];
w2 = Table[w1[i], {i, 1, k}];
meth1 = Join[w2, a3];
m1[j] = Mean[meth1];
c1 = c1 + m1[j];
c2 = c2 + (m1[j] - f1)^2;
,
{j, 1, iter}];
need help.
thanks in advance