Você está na página 1de 12

Tugas Kelompok Komputasi Statistika

PROGRAM MATLAB UNTUK REGRESI LINIER


BERGANDA DENGAN MENGGUNAKAN GAUSS-NEWTON
ITERATIONS

OLEH :
JUMRIANTI H12116008

ROSDIANA H12116010

BUNGA APRILIA H12116020

PROGRAM STUDI STATISTIKA


DEPARTEMEN MATEMATIKA
FAKULTAS MATEMATIKA DAN ILMU PENGETAHUAN ALAM
UNIVERSITAS HASANUDDIN
2018
PROGRAM MATLAB UNTUK REGRESI LINIER
BERGANDA DENGAN MENGGUNAKAN GAUSS-NEWTON
ITERATIONS

Untuk membuat program matlab regresi linier berganda hal pertama yang
harus dilakukan yaitu menyiapkan data bilangan random menggunakan excel
dengan rumus :
=rand()atau =randbetween(bottom;top)
Contoh data regresi linier berganda
No Y X1 X2
1 0.89 62 1
2 0.90 94 6
3 0.07 94 4
4 0.56 17 8
5 0.16 65 1
6 0.88 82 2
7 0.74 73 9
8 0.28 84 1
9 0.82 44 7
10 0.43 72 1
11 0.41 66 10
12 0.36 73 8
13 0.36 96 9
14 0.11 55 7
15 0.46 88 3
16 0.35 82 6
17 0.74 56 3
18 0.22 18 8
19 0.16 80 9
20 0.58 90 6
21 0.74 28 6
22 0.66 96 4
23 0.06 60 4
24 0.66 22 10
25 0.89 66 3
26 0.19 19 7
27 0.27 19 6
28 0.84 53 3
29 0.91 100 6
30 0.65 72 2
31 0.10 99 2
32 0.80 53 8
33 0.21 97 7
34 0.90 48 6
35 0.84 55 6
36 0.69 80 3
37 0.19 52 10
38 0.93 37 2
39 0.69 48 4
40 0.64 75 8
41 0.89 24 5
42 0.43 75 8
43 0.97 74 5
44 0.04 65 5
45 0.70 86 5
46 0.98 70 4
47 0.81 62 1
48 0.99 20 4
49 0.14 94 7
50 0.44 11 8
Ada dua penyelesaiaan yang dilakukan yaitu menggunakan aplikasi Matlab
dan secara Analitik (manual). Adapun uraiannya yaitu:
1. PROGRAM MATLAB
% Nonlinear Least Square
% Cobb-Douglas Production Function
% Non Linear Least Square Gauss-Newton Iterations
% Memerlukan file: f1, numgradf1, dan numgradS1
% Program iniakanmenaksir parameter b1, b2, dan b3
yang adapada Cobb-Douglas
Production Function
% Q = b1.(L^b2).(K^b3)

Program Utama

clear;
clc;
LKy=xlsread ('D:\Data.xlsx');
L = LKy(:,1);
K = LKy(:,2);
Q = LKy(:,3);

y = Q;
x = [L K];
T =length (x);

tic;
% Gauss-Newton Iterations
rep = 100; %The size of 'rep' depends on
the convergence criterion
b = 1.0* ones (3,1); % initial values of b,
replace this if necessary

k = length(b);
e = eye(k);
f = f1(b,x);
S = (y-f)'*(y-f);

j1 = 0;
j2 = 0;
tn = 1; %dalamiterasiGuss-Newton tidakperlumengubahtn

for i = 1:rep ;
z = numgradf1(b,x); %Numerical gradient of f1
zS = numgradS1(b,x,y);%Numerical gradient of S1
step = -0.5*inv(z'*z)*zS ;% Gauss-Newton Iterations
bnext = b + tn*step;
fnext = f1(bnext,x);
Snext = (y-fnext)'*(y-fnext) ;

if norm(bnext-b) <= 1e-9 & abs(S-Snext) <= 1e-9


disp('===============================================
===');
disp('Sudah konvergen. Dengan jumlah iterasinya
adalah:') ;
disp('===============================================
===');
disp(i) ;
break ;
end ;

if i == rep
disp('===============================================
===');
disp('Belum konvergen, iterasinya perlu di
tambah lagi.') ;
disp('Atau ubahlah initial values-nya') ;
disp('===============================================
===');
disp(' ') ;
end ;

b = bnext ;
f = f1(b,x) ;
S = (y-f)'*(y-f) ;

end ;
disp('===============================================
===');
disp('Hasil dari penggunaan iterasi Gauss-Newton
adalah:') ;
disp('===============================================
===');
[bnext' S]
t1 = toc;

% MenentukanNilai AIC dan SC


% Menggunakan file L1.m
LL = L1(b,x,y); %dengan output skalar 1x1
AIC = abs(-2*LL+2*k);
SC = abs(-2*LL+log(T)*k);
disp('===============================================
==');
disp ('Nilai AIC dan SC adalah:');
disp('===============================================
==');
[AIC SC]
disp('-----------------------------------------------
--');

Pogram Pendukung

%File f1.m
function f = f1(b,x)
%f1 Cobb-Douglas production
function %f = f1(b,x)

L = x(:,1) ;
K = x(:,2) ;

b1 = b(1,:);
b2 = b(2,:);
b3 = b(3,:);

f = b1*(D.^b2).*(R.^b3);

%file numgradf1.m
function z = numgradf1(b,x)

%Numerical z (numerical gradient of f1)

k = length(b);
d = 1e-7;
e = eye(k);

for j=1:k ; % Numerical


gradients bplus = b + d*e(:,j);
fplus = feval('f1',bplus,x) ;
bmin = b - d*e(:,j) ;
fmin =feval('f1',bmin,x) ;
z(:,j)= (fplus - fmin)/(2*d);
end;
%File numgradS1.m
function z = numgradS1(b,x,y)

%Numerical z (numerical gradient of L)


%Output berupa vector berdimensi Kx1

k = length(b);
d = 1e-6;
e = eye(k);

for j=1:k; % Numerical gradients


bplus = b + d*e(:,j) ;
fplus = feval('f1',bplus,x) ;
Splus = (y-fplus)'*(y-fplus);
bmin = b - d*e(:,j) ;
fmin =feval('f1',bmin,x) ;
Smin = (y-fmin)'*(y-fmin);
z(j,:) = (Splus - Smin)/(2*d);
end;
%File L1.m
function LL = L1(b,x,y)

%Log of likelihood function for the


%Cobb Douglas Production Function

%L = L1(b,x,y), Outputnyaberupa scalar


dengandimensi 1x1

T = length(x);
f = f1(b,x);
s2 = (y-f)'*(y-f)/T;
LL = -0.5*(log(2*pi*s2) + (y-f)'*(y-f)/s2);
Hasil program matlab tersebut sebagai berikut:
2. SECARA ANALITIK (MANUAL)
Dari data diatas kita akan mencari nilai bo, b1, dan b2 secara manual
dengan menggunakan rumus analisis regresi linier berganda. Adapun langkah-
langkahnya yaitu:
 Persamaan regresi linear berganda : Y' = b0 + b1X1 + b2X2
 Menentukan nilai konstanta dan koefisien regresi
Kita membuat tabel bantu sebagai berikut:

n Y X1 X2 2 2 2 X1X2 X1Y X2Y


X1 X2 Y
1 0,89 62 1 3844 1 0,79 62 55,10269 0,888753
2 0,90 94 6 8836 36 0,81 564 84,65706 5,403642
3 0,07 94 4 8836 16 0,01 376 6,825528 0,290448
4 0,56 17 8 289 64 0,32 136 9,602535 4,51884
5 0,16 65 1 4225 1 0,03 65 10,71363 0,164825
6 0,88 82 2 6724 4 0,78 164 72,56459 1,769868
7 0,74 73 9 5329 81 0,55 657 54,32288 6,697341
8 0,28 84 1 7056 1 0,08 84 23,37518 0,278276
9 0,82 44 7 1936 49 0,67 308 36,14772 5,750773
10 0,43 72 1 5184 1 0,19 72 31,3187 0,434982
11 0,41 66 10 4356 100 0,17 660 26,87395 4,07181
12 0,36 73 8 5329 64 0,13 584 26,41301 2,894576
13 0,36 96 9 9216 81 0,13 864 34,40189 3,225177
14 0,11 55 7 3025 49 0,01 385 6,12535 0,77959
15 0,46 88 3 7744 9 0,21 264 40,55603 1,382592
16 0,35 82 6 6724 36 0,12 492 28,4982 2,085234
17 0,74 56 3 3136 9 0,54 168 41,23454 2,208993
18 0,22 18 8 324 64 0,05 144 4,023666 1,788296
19 0,16 80 9 6400 81 0,03 720 13,17216 1,481868
20 0,58 90 6 8100 36 0,34 540 52,36857 3,491238
21 0,74 28 6 784 36 0,55 168 20,74472 4,445298
22 0,66 96 4 9216 16 0,43 384 63,10733 2,629472
23 0,06 60 4 3600 16 0,00 240 3,51972 0,234648
24 0,66 22 10 484 100 0,44 220 14,52785 6,60357
25 0,89 66 3 4356 9 0,79 198 58,81306 2,673321
26 0,19 19 7 361 49 0,04 133 3,656835 1,347255
27 0,27 19 6 361 36 0,07 114 5,18719 1,63806
28 0,84 53 3 2809 9 0,70 159 44,44866 2,515962
29 0,91 100 6 10000 36 0,83 600 91,2335 5,47401
30 0,65 72 2 5184 4 0,42 144 46,65521 1,295978
31 0,10 99 2 9801 4 0,01 198 10,08097 0,203656
32 0,80 53 8 2809 64 0,64 424 42,2905 6,383472
33 0,21 97 7 9409 49 0,04 679 20,03496 1,445822
34 0,90 48 6 2304 36 0,81 288 43,21435 5,401794
35 0,84 55 6 3025 36 0,70 330 46,09935 5,02902
36 0,69 80 3 6400 9 0,48 240 55,41416 2,078031
37 0,19 52 10 2704 100 0,04 520 10,11665 1,94551
38 0,93 37 2 1369 4 0,87 74 34,46269 1,862848
39 0,69 48 4 2304 16 0,47 192 32,94149 2,745124
40 0,64 75 8 5625 64 0,41 600 47,73368 5,091592
41 0,89 24 5 576 25 0,78 120 21,25615 4,428365
42 0,43 75 8 5625 64 0,18 600 32,24775 3,43976
43 0,97 74 5 5476 25 0,94 370 71,67588 4,842965
44 0,04 65 5 4225 25 0,00 325 2,69399 0,20723
45 0,70 86 5 7396 25 0,49 430 60,27224 3,5042
46 0,98 70 4 4900 16 0,96 280 68,60805 3,92046
47 0,81 62 1 3844 1 0,65 62 50,01695 0,806725
48 0,99 20 4 400 16 0,98 80 19,8291 3,96582
49 0,14 94 7 8836 49 0,02 658 13,4498 1,001581
50 0,44 11 8 121 64 0,20 88 4,873671 3,544488
Selanjutnya dilakukan perhitungan sebagai berikut:

 ∑ 2 = ∑ 2−
(Ʃ 1)
2

1 1

9928801
= 230917 − 50

= 230917 – 198576
= 32340,98
 (Ʃ 2)2
∑2 =∑ 2

2 2

71824

= 1786 −
50

= 1786 – 1436,48
 2 2
(Ʃ )
2

∑ =∑ −

= 19,92 − 770,5650

= 19,92 – 15,41124606
 ∑1 =∑1 −
Ʃ 1× Ʃ
= 4,51
= 1697,504 − 3151∗27,76
50

= 1697,504 – 1749,372
= -51,86811
Ʃ 2×Ʃ
 ∑2 =∑ 2 −
268∗27,76
= 140,3132 −
50

= 140,3132 – 148,7883
 ∑1 2=∑1 2−
Ʃ 1×Ʃ 2
= -8,475102
= 16227 − 3151∗268
50

= 16227 – 16889,36
= - 662,36

Kemudian, kita dapat menghitung penduga parameter b0, b1 dan b2.


Adapun langkahnya sebagai berikut:
 1=
[(Ʃ 2× Ʃ
1
)−(Ʃ
2
×Ʃ )]
1 2 [(Ʃ 12 Ʃ 22)−(Ʃ 1× 2)2]

= [(349,52 ×(−51,86811)−(−8,475102 ×(−662,36)]

2
[(32340,98 (349,52))−(−662,36) ]

= -0,00219

2
[(Ʃ 1 ×Ʃ 2 )−(Ʃ 1 ×Ʃ 1 2)]
 2=

[(Ʃ 12×Ʃ 2)−(Ʃ 1× 2)2]


2

= [(32340,98×(−8,475102)−(−51,86811 ×(−662,36)]

[(32340,98 (349,52))−(−662,36) 2]

= -0,02839
(Ʃ )−(
 0= 1×Ʃ 1)−( 2×Ʃ 2)

= (27,76)−(−0,00219×3151)−(−0,02839×268)

50

= 0,845057
Jadi persamaan Regresi Linier Berganda dengan dua variabel
bebas adalah:
Y' = 0,845057 - 0,00219X1 – 0,02839 X2

Você também pode gostar