0
|
6472 Views
|
6 Replies
|
5 Total Likes
View groups...
Share

# Mean Imputation

Posted 10 years ago
 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
6 Replies
Sort By:
Posted 10 years ago
 You have a syntax error, instead of list[3]=new; to replace the third element, you should use list[[3]]=new; In general, using list manipulation functions will avoid these sort of syntax errors. Here are a few comments.  Array[s1, n]; Array[s2, n]; Array[h, n]; This is unnecessary. You don't need to initialize the arrays. Table[{y[[i]], x[[i]]}, {i, 1, 20}]; There are a number of other ways to do this like MapThread[List,{y,x},1] f1 = Mean[y];; Should not have double semicolons. Table[i, {i, 1, n}]; Could be Range[n]`
Posted 10 years ago
 I want to study the effect of mean imputation (and other methods later on..). My main idea is1- generate a population N=20 sample for two variables x, y 2- then draw all samples without replacement (n=12). (calculate descriptive statistics) 3- drop a random values (k=3) to be missing.4- compensate this values by mean of other respondent values.5- compute bias and MSE new imputed data.
Posted 10 years ago
 What are you getting as a result? What do you want as a result??
Posted 10 years ago
 http://community.wolfram.com/groups/-/m/t/270507 has instructions for formatting code and lists nicely.
Posted 10 years ago
 It's not clear what is the question here. Is there a problem with the code you have?
Posted 10 years ago
 Yes the problem with code RandomKSubset and Do list1 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 ? *)
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.