MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Ignore missing data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119005] Re: Ignore missing data
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 19 May 2011 07:43:52 -0400 (EDT)

On 5/18/11 at 7:15 AM, dimemples at gmail.com (dim) wrote:

>I would like to know how to ignore missing data and to be more
>specific I'll give an example.

>his = {1,2,3,4,5,6,7,,9};
>simcs1 = RandomReal[10, 9];
>simcs2 = RandomReal[10, 9];

>simcsi = a1*simcs1 + a2*simcs2;
>(his - simcsi)^2;
>er = Plus @@ %
>Minimize[{er, 0 <= a1 <= 1 && 0 <= a2 <= 1  && a1 + a2== 1}, {a1, a2}]

>It doesn't work, since the 8th value of "his" is missing. Do you
>know how i could make Mathematica ignore also the corresponding
>values of simcs1 and simcs2? Namely, in my example how to ignore the
>8th value of simcs1 and simcs2.

>Please note that i don't want to delete the missing data, neither to
>make them equal to 0.

Uses Cases[his,_?NumericQ] to select only the numeric values in
his. And use

Pick[his, simcs1, _?NumericQ] to select the corresponding values
of simcs1. To demonstrate:

In[4]:= x = Cases[his, _?NumericQ];
y = Pick[simcs1, his, _?NumericQ];
z = Pick[simcs2, his, _?NumericQ];

In[7]:= Complement[simcs1, y][[1]] == simcs1[[8]]

Out[7]= True

demonstrating the 8th entry for simcs1 was omitted from y. Then
setting up your example equations with the new data items

In[8]:= simcsi = a1*y + a2*z;
(x - simcsi)^2;
er = Plus @@ %;
Minimize[{er, 0 <= a1 <= 1 && 0 <= a2 <= 1 && a1 + a2 == 1},
{a1, a2}]


Out[11]= {49.5278,{a1->0.400533,a2->0.599467}}



  • Prev by Date: Re: Count Ouccrence of words in a long text
  • Next by Date: Re: Large bar character
  • Previous by thread: Re: Ignore missing data
  • Next by thread: ListSurfacePlot3D-Question