(***********************************************************************
This file was generated automatically by the Mathematica front end.
It contains Initialization cells from a Notebook file, which typically
will have the same name as this file except ending in ".nb" instead of
".m".

This file is intended to be loaded into the Mathematica kernel using
the package loading commands Get or Needs.  Doing so is equivalent to
using the Evaluate Initialization Cells menu command in the front end.

DO NOT EDIT THIS FILE.  This entire file is regenerated automatically 
each time the parent Notebook file is saved in the Mathematica front end.
Any changes you make to this file will be overwritten.
***********************************************************************)





BeginPackage["DataAnalysis`Inertias`","DataAnalysis`Symbols`",
    "Graphics`Colors`"];

Inertias::usage = 
    "Inertias[Dat,P], donde Dat es una matriz n x p y P una partici\[OAcute]n \
de los enteros de 1 a n. Produce una  arreglo  {G,g,I,B} donde las filas de G \
son los  centros de gravedad de las clases de P, g es el centro de gravedad \
global, I la descomposici\[OAcute]n matricial de la inercia total clases x \
variables y  B es la descomposici\[OAcute]n matricial de la inercia INTER, \
clases x variables." ;
Totals::usage = "Totals[A], calcula {Tc,Tf,T}, donde Tc son los totales de
     las columnas de A, Tf los totales de las filas y T el total de todas sus \
entradas.";
MultiListPlot::usage = 
    "MultiListPlot[A,Opciones] si A es una matriz num\[EAcute]rica,
    	 traza un gr\[AAcute]fico con una l\[IAcute]nea por los puntos
    	 {{1,ai1},{2,ai2},...{k,aik}} para cada fila de la matriz A.";
Add::usage = "Add->True|False, opci\[OAcute]n para MultListPlot";

Begin["`Privado`"];

Inertias[X_:MatrixQ,prtc:{ {__Integer}..},pss_:Iquals] := 
    Module[{psscl,n,Mds,Io,Xc2,G,B},
	  n = Length[X];
	 Switch[pss,
		   Iquals, psscl = Map[(Length[#]/n)&,prtc];
			           Mds =  Apply[Plus,X]/n;
		                    Xc2 =  Transpose[(Transpose[X] - Mds)^2]/n;
			           G = Map[Apply[Plus,Part[X,#]/n]&,prtc]/psscl,
		_List, psscl = Map[Apply[Plus,Part[pss,#]]&,prtc];
			        Mds = Apply[Plus,pss*X];
			        Xc2 =	pss  Transpose[(Transpose[X] - Mds)^2];
			       G = Map[Apply[Plus,Part[pss,#]*Part[X,#]]&,prtc]/psscl
		]; 
      Io =  Map[Apply[Plus,Part[Xc2,#]]&,prtc];
      B =  psscl  Transpose[(Transpose[G] - Mds)^2];
      {G,Mds,Io,B}
		];
Totals[A_?MatrixQ] := Module[{Tc = Apply[Plus,A]},
      {Tc,Apply[Plus,A,1],Apply[Plus,Tc]}];
Options[MultiListPlot] = {Add\[Rule]False,
      ColorsBase\[Rule]{Blue,Green,Magenta,Cyan,Red,IvoryBlack,Black},
      	 Labels->Automatic,Ticks->Automatic,PlotRange->Automatic}; 
MultiListPlot[A_,Opc:(_Rule|_RuleDelayed)...] := 
    Module[{ColsB,Colr,ncols,dts,gr1,gr2,x1,x2,y1,y2,d,Lns,Etq,k,kColores,
        Polis},
      	EstaNo[opcion:_Rule|_RuleDelayed]:=FreeQ[{Add,ColorsBase,
            		Labels,Ticks},
          opcion\[LeftDoubleBracket]1\[RightDoubleBracket]];
        ColsB = ColorsBase/.{Opc}/.Options[MultiListPlot];
        ncols = Length[ColsB];
      kColores[r_] := With[{t=Quotient[r,ncols]},
          Join[Flatten[Table[ColsB,{t}]],Take[ColsB,r- t ncols]]];
      k = Length[A];
      Colr = Reverse[ kColores[k]];
      	Acml = Add/.{Opc}/.Options[MultiListPlot];
      	Etq = 
        Labels/.{Opc}/.Options[MultiListPlot]/.{Automatic->Range[k],
            None\[Rule]{}};
      	dts = If[Acml,FoldList[Plus,First[A],Rest[A]],A];
      	MisTicks = 
        Ticks/.{Opc}/.Options[MultiListPlot]/.{Automatic->
              Range[Length[A\[LeftDoubleBracket]1\[RightDoubleBracket]]]};
      Polis = Map[ Line[Transpose[{Range[Length[#]],#}]]&,dts];
      	gr1 = Graphics[Transpose[{Colr,Polis}],Axes->True];
          {{x1,x2},{y1,y2}} = FullOptions[gr1,PlotRange];
           d = (y2-y1)/(k+1);
            (* 
        Lns = Map[Line[{{0.5,#},{1.0,#}}]&,  Table[y2 - i d,{i,1,k}]]; *)
            
      Etqta = If[Length[Etq]>0, 
          Table[Text[Etq[[i]],{x2+0.2,y1 + i d},{-1,0}],{i,1,k}],{}];
      	Opcns=Select[{Opc},EstaNo];
      Polis = 
        If[Length[Etq]>0,Transpose[{Colr,Polis,Etqta}],
          Transpose[{Colr,Polis}]];
      		Apply[Show, 
        Join[{Graphics[Polis,Axes->True,PlotRange->{{x1,x2+2},{y1,y2}},
              		    Ticks->{MisTicks,Automatic}]},Opcns]]];

End[];

EndPackage[];