clear;

x = [
     1.74  5.30 10.80;
     6.32  5.42  9.40;
     6.22  8.41  7.20;
    10.52  4.63  8.50;
     1.19 11.60  9.40;
     1.22  5.85  9.90;
     4.10  6.62  8.00;
     6.32  8.72  9.10;
     4.08  4.42  8.70;
     4.15  7.60  9.20;
    10.15  4.83  9.40
     1.72  3.12  7.60;
     1.70  5.30  8.20];

y = [ 25.5; 31.2; 25.9; 38.4; 18.4; 26.7; 26.4; 25.9; 32.0; 25.2; 39.7; 35.7; 26.5];

n = length(x(:,1));
k = length(x(1,:));

[SSE, SSR, b] = modelo(x, y, [1 2 3]);

SST = SSE + SSR;

v1 = k;
v2 = n-k-1;

s2 = SSE/(n-k-1);

F = (SSR/k)/s2

alfa = 0.05;
Fc = finv(1-alfa, v1, v2);
fprintf('---------------------------------------------------------------------\n');
fprintf('Curva ajustada\n');
display (b)
fprintf('---------------------------------------------------------------------\n');
fprintf('Analisis de Varianza\n');
fprintf('---------------------------------------------------------------------\n');
fprintf('Fuente de     Suma            Grados de      Cuadrado        F calc\n');
fprintf('Variacion     cuadrados       Libertad          medio         \n');
fprintf('---------------------------------------------------------------------\n');
fprintf('Regresion %13.2f  %13.f  %13.2f %13.2f\n', SSR, v1, SSR/v1, F);
fprintf('Error     %13.2f  %13.f  %13.2f \n', SSE, v2, s2);
fprintf('Total     %13.2f  %13.f  \n', SST, v1+v2);
fprintf('---------------------------------------------------------------------\n');
fprintf('Con (1-alfa) = %5.3f tenemos %13.2f > %13.2f\n', 1-alfa, F, Fc);

