L.2-22 "variable yang mempengaruhi ","About Forecasting",JOptionPane.INFORMATION_MESSAGE); } if(e.getSource()==mi[0]||e.getSource()==b2){ //ketika menekan tombol process
RegresiBerganda RB = new RegresiBerganda(RB_Tgl,RB_TdkBebas,RB_Bebas1,RB_Bebas2,RB_Bebas3,jmlData Perbandingan,jumlah,jmlColumnRB); RB_Hasil = RB.peramalanRB(); fungsiTransfer TF = new fungsiTransfer(TF_Tgl,TF_Output,TF_Input,jmlDataPerbandingan,jumlah); TF_Hasil = TF.cariHasilPeramalan();
if(flag==false){ mi[3].setEnabled(true); } b2.setEnabled(false); RB_Multikolinearitas = RB.cekMultikolinearitas(); if(RB_Multikolinearitas==true){ temp2 = "[ Terjadi Multikolinearitas ]"; } if(RB_Multikolinearitas==false){ temp2 = "[ Tidak Terjadi Multikolinearitas ]"; } RB_F = RB.cekFTest(); if(RB_F==true){ temp1 = "[ Significant F-Test = Valid ]"; } if(RB_F==false){ temp1 = "[ Significant F-Test = Tidak Valid ]"; }
TF_Model = TF.tampilModel(); ta.setText(""); columns1.clear(); columns2.clear(); rows1.clear();
L.2-23 rows2.clear(); tampilanProcess(); } } /*-----------------------------------------Function actionEvent End -------------------------------------------*/ /*----------------------------------------------------Function ambil semua data dari database di hal view ------------------------------------------------------*/ public void getDataBaseView(int idx){ ctr = 0; System.out.println("select * from DataPengamatan where DataID = "+idx); try{ // Connect Data Base Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=DataBaseSkripsi.mdb"); ResultSet rs = con.createStatement().executeQuery("select * from DataPengamatan where DataID = '"+idx+"'"); ResultSet rs2 = con.createStatement().executeQuery("select * from Hasil where DataID = '"+idx+"'"); ResultSet rs3 = con.createStatement().executeQuery("select * from Error where DataID = '"+idx+"'"); ResultSet rs4= con.createStatement().executeQuery("select * from KetVariabel where DataID = '"+idx+"'"); ResultSet rs5 = con.createStatement().executeQuery("select count(DataID) from DataPengamatan where DataID = '"+idx+"'"); ResultSet rs6 = con.createStatement().executeQuery("select count(DataID) from Hasil where DataID = '"+idx+"'"); ResultSetMetaData rsmd = rs.getMetaData(); for (j=1; j<=rsmd.getColumnCount(); j++) { H_ColumnName[j-1] = rsmd.getColumnName(j); } jumlahColumnV = rsmd.getColumnCount()-1; rs3.next(); H_MapeRB = Double.parseDouble(rs3.getString(2)); H_MseRB = Double.parseDouble(rs3.getString(3)); H_MapeTF = Double.parseDouble(rs3.getString(4)); H_MseTF = Double.parseDouble(rs3.getString(5));
L.2-24
rs4.next(); H_VariabelRB = rs4.getString(2); H_VariabelTF = rs4.getString(3); rs5.next(); jumlahH = Integer.parseInt(rs5.getString(1)); rs6.next(); jmlDataBanding2 = Integer.parseInt(rs6.getString(1)); //System.out.println(jmlDataBanding2);
while(ctr!=jumlahH){ rs.next(); // Ambil data disimpan di String array V_Tgl[ctr] = rs.getString(2); V_YangDiramal[ctr] = Double.parseDouble(rs.getString(3)); V_Variabel1[ctr] = Double.parseDouble(rs.getString(4)); V_Variabel2[ctr] = Double.parseDouble(rs.getString(5)); if(jumlahColumnV>4){ V_Variabel3[ctr] = Double.parseDouble(rs.getString(6)); } //System.out.println(""+V_Tgl[ctr]); ctr++; } ctr=0; while(ctr!=jmlDataBanding2){ rs2.next(); // Ambil data disimpan di String array H_Tgl[ctr] = rs2.getString(2); H_Pengamatan[ctr] = Double.parseDouble(rs2.getString(3)); H_RegresiBerganda[ctr] = Double.parseDouble(rs2.getString(4)); H_FungsiTransfer[ctr] = Double.parseDouble(rs2.getString(5)); ctr++; }
con.close(); } catch(Exception err){ System.out.println(err); // pemberitahuan error } } /*-------------------------------------------------------------Function ambil semua data dari database di hal view End
L.2-25 ---------------------------------------------------------------*/ /*----------------------------------------------Function ambil DataID dari database ------------------------------------------------*/ public void getDataId(){ //ambilDataId terakhir dari DataBase int temp; try{ // Connect Data Base Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=DataBaseSkripsi.mdb"); ResultSet rs = con.createStatement().executeQuery("select DataID from Error"); while(rs.next()){ dataID = rs.getString(1); } if(dataID.equals(null)==true){ dataID = "0001"; }else{ temp = Integer.parseInt(dataID); temp = temp + 1; dataID = ""+temp; } System.out.println(""+dataID); con.close(); } catch(Exception err){ System.out.println(err); // pemberitahuan error } }
/*----------------------------------------------Function ambil DataID dari database End ------------------------------------------------*/ /*----------------------------------------------Function insert Data Base (SAVE) ------------------------------------------------*/ public void insertDataBase(){
L.2-26 String temp1=""; String temp2=""; try{ // Connect Data Base Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Statement st; Connection con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=DataBaseSkripsi.mdb"); con.setAutoCommit(false); for(i=0;i<jumlah;i++){ st = con.createStatement(); st.executeUpdate("insert into DataPengamatan (DataID,Tanggal,YangDiramal,Variabel1,Variabel2,Variabel3) Values ('"+dataID+"','"+RB_Tgl[i]+"',"+RB_TdkBebas[i]+","+RB_Bebas1[i]+","+RB_Bebas2[i ]+","+RB_Bebas3[i]+")"); con.commit(); st.close(); } for(i=0;i<jmlDataPerbandingan;i++){ st = con.createStatement(); st.executeUpdate("insert into Hasil (DataID,Tanggal,Pengamatan,RegresiBerganda,FungsiTransfer) Values ('"+dataID+"','"+RB_Tgl[(jumlahjmlDataPerbandingan)+i]+"','"+RB_TdkBebas[(jumlahjmlDataPerbandingan)+i]+"','"+RB_Hasil[i]+"','"+TF_Hasil[i]+"')"); con.commit(); st.close(); } for(i=1;i<jmlColumnRB;i++){ temp1 = temp1 + RB_ColumnName[i] + " "; } for(i=1;i<3;i++){ temp2 = temp2 + TF_ColumnName[i] + " "; } st = con.createStatement(); st.executeUpdate("insert into KetVariabel (DataID,VariabelRB,VariabelTF) Values ('"+dataID+"','"+temp1+"','"+temp2+"')"); con.commit(); st.close(); st = con.createStatement();
L.2-27 st.executeUpdate("insert into Error (DataID,MapeRB,MseRB,MapeTF,MseTF) Values ('"+dataID+"','"+RB_MAPE+"','"+RB_MSE+"','"+TF_MAPE+"','"+TF_MSE+"')"); con.commit(); st.close(); con.close(); } catch(Exception err){ System.out.println(err); // pemberitahuan error } JOptionPane.showMessageDialog(null,"Data Berhasil Di Save ke DataBase dengan DataID = "+dataID,"Informasi",JOptionPane.INFORMATION_MESSAGE); } /*----------------------------------------------Function insert Data Base (SAVE) End ------------------------------------------------*/ /*----------------------------------------------Function ambil Data Base di awal ------------------------------------------------*/ public void getDataBase(String metode){ ctr = 0;
if(metode.equals("Regresi Berganda")==true){ try{ // Connect Data Base Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=DataBaseSkripsi.mdb"); ResultSet rs = con.createStatement().executeQuery("select * from RegresiBerganda"); ResultSet rs2 = con.createStatement().executeQuery("select count(Tanggal) from RegresiBerganda"); rs2.next(); jumlah = Integer.parseInt(rs2.getString(1)); ResultSetMetaData rsmd = rs.getMetaData(); for (j=1; j<=rsmd.getColumnCount(); j++) { RB_ColumnName[j-1] = rsmd.getColumnName(j); }
L.2-28 jmlColumnRB = j-1; while(ctr!=jumlah){ rs.next(); // Ambil data disimpan di String array RB_Tgl[ctr] = rs.getString(1); RB_TdkBebas[ctr] = Double.parseDouble(rs.getString(2)); RB_Bebas1[ctr] = Double.parseDouble(rs.getString(3)); RB_Bebas2[ctr] = Double.parseDouble(rs.getString(4)); if(jmlColumnRB>4){ RB_Bebas3[ctr] = Double.parseDouble(rs.getString(5)); } ctr++; } con.close(); } catch(Exception err){ System.out.println(err); // pemberitahuan error } JOptionPane.showMessageDialog(null,"Data Berhasil diinput ke dalam metode Regresi Berganda ","Informasi",JOptionPane.INFORMATION_MESSAGE); } // tutup if Regresi Berganda if(metode.equals("Fungsi Transfer")){ try{ // Connect Data Base Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=DataBaseSkripsi.mdb"); ResultSet rs = con.createStatement().executeQuery("select * from FungsiTransfer"); ResultSet rs2 = con.createStatement().executeQuery("select count(Tanggal) from FungsiTransfer"); rs2.next(); jumlah = Integer.parseInt(rs2.getString(1)); ResultSetMetaData rsmd = rs.getMetaData(); for (j=1; j<=rsmd.getColumnCount(); j++) { TF_ColumnName[j-1] = rsmd.getColumnName(j); } ctr = 0; while(ctr!=jumlah){ rs.next(); // Ambil data disimpan di String array TF_Tgl[ctr] = rs.getString(1); TF_Output[ctr] = Double.parseDouble(rs.getString(2));
L.2-29 TF_Input[ctr] = Double.parseDouble(rs.getString(3)); ctr++; } con.close(); } catch(Exception err){ System.out.println(err); // pemberitahuan error } JOptionPane.showMessageDialog(null,"Data Berhasil diinput ke dalam metode Fungsi Transfer","Informasi",JOptionPane.INFORMATION_MESSAGE); } // tutup if Fungsi Transfer } /*---------------------------------------------Function ambil dataBase End -----------------------------------------------*/
public static void main(String[] args){ new LayarUtama(); }
}
1.2 Class RegresiBerganda.Java import java.awt.*; import javax.swing.*; import java.sql.*; import java.lang.Math; public class RegresiBerganda { String RB_Tgl[] = new String[100]; double RB_TdkBebas[] = new double[100]; double RB_Bebas1[] = new double[100]; double RB_Bebas2[] = new double[100]; double RB_Bebas3[] = new double[100]; double RB_Bebas4[] = new double[100]; double Matrix_X1[][] = new double[100][100]; double Matrix_X2[][] = new double[100][100]; double Matrix_X3[][] = new double[6][6]; //X'X double Matrix_X4[][] = new double[6][6]; double Matrix_Y[] = new double[100];
L.2-30 double Matrix_XY[] = new double[6]; //X'Y double Matrix_Final[] = new double[6]; double Matrix_Invers[][] = new double[6][12]; double K_X1X2; double K_X1X3; double K_X2X3; double K_YX1; double K_YX2; double K_YX3; double Peramalan[] = new double[40]; int ctr=0,jumlah,jmlColumn; int jmlDataPerbandingan; // data yang diambil untuk jadi perbandingan
RegresiBerganda(String[] a,double[] jmlDataBanding,int jml,int jmlClmn){ int i,j;
b,double[]
RB_Tgl = a; RB_TdkBebas = b; RB_Bebas1 = c; RB_Bebas2 = d; RB_Bebas3 = e; jmlDataPerbandingan = jmlDataBanding; jumlah = jml; jmlColumn = jmlClmn;
for(i=0;i<6;i++){ for(j=0;j<6;j++){ Matrix_X3[i][j] = 0; } Matrix_XY[i] = 0; Matrix_Final[i]=0; } for(i=0;i<6;i++){ for(j=0;j<12;j++){ Matrix_Invers[i][j] = 0; } }
c,double[]
d,double[]
e,int
L.2-31
for(i=0;i<jumlah;i++){ if((jmlColumn-1)==3){ Matrix_X1[i][0] = 1; Matrix_X1[i][1] = RB_Bebas1[i]; Matrix_X1[i][2] = RB_Bebas2[i]; Matrix_X2[0][i] = 1; Matrix_X2[1][i] = RB_Bebas1[i]; Matrix_X2[2][i] = RB_Bebas2[i]; }
if((jmlColumn-1)==4){ Matrix_X1[i][0] = 1; Matrix_X1[i][1] = RB_Bebas1[i]; Matrix_X1[i][2] = RB_Bebas2[i]; Matrix_X1[i][3] = RB_Bebas3[i]; Matrix_X2[0][i] = 1; Matrix_X2[1][i] = RB_Bebas1[i]; Matrix_X2[2][i] = RB_Bebas2[i]; Matrix_X2[3][i] = RB_Bebas3[i]; } Matrix_Y[i] = RB_TdkBebas[i]; }
perhitungan(); invers(); peramalanRB(); } // tutup constructor public boolean cekMultikolinearitas(){ boolean flag=false; double hslKorelasi; hslKorelasi = korelasi(RB_Bebas1,RB_Bebas2,0); if(hslKorelasi>=0.75) { flag=true; } if(jmlColumn==5){ hslKorelasi = korelasi(RB_Bebas1,RB_Bebas3,0); if(hslKorelasi>=0.75) { flag=true; } hslKorelasi = korelasi(RB_Bebas2,RB_Bebas3,0);
L.2-32 if(hslKorelasi>=0.75) { flag=true; } } return flag; } public boolean cekFTest(){ boolean flag=false; double nilaiF,FTabel=0; double y1[] = new double[100]; double y2[] = new double[100]; double y3[] = new double[100]; double rata2=0,jumlah1=0,jumlah2=0; int i; for(i=0;i<(jumlah-jmlDataPerbandingan);i++){ rata2 = rata2 + RB_TdkBebas[i]; } rata2 = rata2 / (jumlah-jmlDataPerbandingan); for(i=0;i<(jumlah-jmlDataPerbandingan);i++){ y1[i] = Matrix_Final[0] + (Matrix_Final[1]*RB_Bebas1[i]) (Matrix_Final[2]*RB_Bebas2[i]) + (Matrix_Final[3]*RB_Bebas3[i]) ; y2[i] = (RB_TdkBebas[i] - y1[i]) * (RB_TdkBebas[i] - y1[i]); y3[i] = (y1[i]-rata2) * (y1[i]-rata2); }
+
for(i=0;i<(jumlah-jmlDataPerbandingan);i++){ jumlah1 = jumlah1 + y2[i]; jumlah2 = jumlah2 + y3[i]; } nilaiF= (jumlah2/(jmlColumn-2)) / (jumlah1/((jumlah-jmlDataPerbandingan)(jmlColumn-1))); if(jmlColumn==3){ if((jumlah-jmlDataPerbandingan)>0&&(jumlah-jmlDataPerbandingan)<=10){ FTabel = 5.41; } if((jumlah-jmlDataPerbandingan)>10&&(jumlah-jmlDataPerbandingan)<=20){ FTabel = 3.06; } if((jumlah-jmlDataPerbandingan)>20&&(jumlah-jmlDataPerbandingan)<=30){ FTabel = 2.99; } if((jumlah-jmlDataPerbandingan)>30){ FTabel = 2.84; }
L.2-33 } if(jmlColumn==2){ if((jumlah-jmlDataPerbandingan)>0&&(jumlah-jmlDataPerbandingan)<=10){ FTabel = 5.79; } if((jumlah-jmlDataPerbandingan)>10&&(jumlah-jmlDataPerbandingan)<=20){ FTabel = 3.68; } if((jumlah-jmlDataPerbandingan)>20&&(jumlah-jmlDataPerbandingan)<=30){ FTabel = 3.39; } if((jumlah-jmlDataPerbandingan)>30){ FTabel = 3.23; } } if(nilaiF>FTabel){ return true; }else{ return false; } }
public void perhitungan(){ int i,j,z; for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ for(z=0;z<jumlah-jmlDataPerbandingan;z++){ Matrix_X3[i][j] = Matrix_X3[i][j] + Matrix_X2[j][z]);
(Matrix_X1[z][i]
} } } for(i=0;i<jmlColumn-1;i++){ for(z=0;z<jumlah-jmlDataPerbandingan;z++){ Matrix_XY[i] = Matrix_XY[i] + (Matrix_X2[i][z] * Matrix_Y[z]); } } } public void invers(){
*
L.2-34 int i,j,z; double temp[] = new double[6]; for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ Matrix_Invers[i][j] = Matrix_X3[i][j]; if(i==j){ Matrix_Invers[i][j+(jmlColumn-1)] = 1; } } } if((jmlColumn-1)==3){ temp[0] = Matrix_Invers[0][0]; temp[1] = Matrix_Invers[1][0]; temp[2] = Matrix_Invers[2][0]; for(i=0;i<6;i++){ // tahap 1 Matrix_Invers[0][i] = Matrix_Invers[0][i]/temp[0]; } for(i=0;i<6;i++){ // tahap 2 Matrix_Invers[1][i] = Matrix_Invers[1][i]-(temp[1]*Matrix_Invers[0][i]); Matrix_Invers[2][i] = Matrix_Invers[2][i]-(temp[2]*Matrix_Invers[0][i]); }
temp[0] = Matrix_Invers[1][1]; temp[1] = Matrix_Invers[0][1]; temp[2] = Matrix_Invers[2][1]; for(i=0;i<6;i++){ // tahap 3 Matrix_Invers[1][i] = Matrix_Invers[1][i]/temp[0]; } for(i=0;i<6;i++){ // tahap 4 Matrix_Invers[0][i] = Matrix_Invers[0][i]-(temp[1]*Matrix_Invers[1][i]); Matrix_Invers[2][i] = Matrix_Invers[2][i]-(temp[2]*Matrix_Invers[1][i]); } temp[0] = Matrix_Invers[2][2]; temp[1] = Matrix_Invers[0][2]; temp[2] = Matrix_Invers[1][2]; for(i=0;i<6;i++){ // tahap 5 Matrix_Invers[2][i] = Matrix_Invers[2][i]/temp[0]; } for(i=0;i<6;i++){ // tahap 6 Matrix_Invers[0][i] = Matrix_Invers[0][i]-(temp[1]*Matrix_Invers[2][i]);
L.2-35 Matrix_Invers[1][i] = Matrix_Invers[1][i]-(temp[2]*Matrix_Invers[2][i]); } for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ Matrix_X4[i][j] = Matrix_Invers [i][j+3]; } } for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ Matrix_Final[i] = Matrix_Final[i] + (Matrix_X4[j][i] * Matrix_XY[j]); } } } if((jmlColumn-1)==4){ temp[0] = Matrix_Invers[0][0]; temp[1] = Matrix_Invers[1][0]; temp[2] = Matrix_Invers[2][0]; temp[3] = Matrix_Invers[3][0]; for(i=0;i<8;i++){ // tahap 1 Matrix_Invers[0][i] = Matrix_Invers[0][i]/temp[0]; }
for(i=0;i<8;i++){ // tahap 2 Matrix_Invers[1][i] = Matrix_Invers[1][i]-(temp[1]*Matrix_Invers[0][i]); Matrix_Invers[2][i] = Matrix_Invers[2][i]-(temp[2]*Matrix_Invers[0][i]); Matrix_Invers[3][i] = Matrix_Invers[3][i]-(temp[3]*Matrix_Invers[0][i]); }
temp[0] = Matrix_Invers[1][1]; temp[1] = Matrix_Invers[0][1]; temp[2] = Matrix_Invers[2][1]; temp[3] = Matrix_Invers[3][1]; for(i=0;i<8;i++){ // tahap 3 Matrix_Invers[1][i] = Matrix_Invers[1][i]/temp[0]; } for(i=0;i<8;i++){ // tahap 4 Matrix_Invers[0][i] = Matrix_Invers[0][i]-(temp[1]*Matrix_Invers[1][i]); Matrix_Invers[2][i] = Matrix_Invers[2][i]-(temp[2]*Matrix_Invers[1][i]); Matrix_Invers[3][i] = Matrix_Invers[3][i]-(temp[3]*Matrix_Invers[1][i]); }
L.2-36
temp[0] = Matrix_Invers[2][2]; temp[1] = Matrix_Invers[0][2]; temp[2] = Matrix_Invers[1][2]; temp[3] = Matrix_Invers[3][2]; for(i=0;i<8;i++){ // tahap 5 Matrix_Invers[2][i] = Matrix_Invers[2][i]/temp[0]; } for(i=0;i<8;i++){ // tahap 6 Matrix_Invers[0][i] = Matrix_Invers[0][i]-(temp[1]*Matrix_Invers[2][i]); Matrix_Invers[1][i] = Matrix_Invers[1][i]-(temp[2]*Matrix_Invers[2][i]); Matrix_Invers[3][i] = Matrix_Invers[3][i]-(temp[3]*Matrix_Invers[2][i]); } temp[0] = Matrix_Invers[3][3]; temp[1] = Matrix_Invers[0][3]; temp[2] = Matrix_Invers[1][3]; temp[3] = Matrix_Invers[2][3]; for(i=0;i<8;i++){ // tahap 7 Matrix_Invers[3][i] = Matrix_Invers[3][i]/temp[0]; } for(i=0;i<8;i++){ // tahap 8 Matrix_Invers[0][i] = Matrix_Invers[0][i]-(temp[1]*Matrix_Invers[3][i]); Matrix_Invers[1][i] = Matrix_Invers[1][i]-(temp[2]*Matrix_Invers[3][i]); Matrix_Invers[2][i] = Matrix_Invers[2][i]-(temp[3]*Matrix_Invers[3][i]); } for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ Matrix_X4[i][j] = Matrix_Invers [i][j+4]; } } for(i=0;i<jmlColumn-1;i++){ for(j=0;j<jmlColumn-1;j++){ Matrix_Final[i] = Matrix_Final[i] + (Matrix_X4[j][i] * Matrix_XY[j]); } } }
} public double korelasi(double[] a,double[] b,int timeLag){ // cari korelasi double X=0,X2=0,Y=0,Y2=0,XY=0;
L.2-37 double K_nilai1,K_nilai2,K_nilai3; int i,jml;
for(i=timeLag;i<jumlah-(jmlDataPerbandingan-1);i++){ XY = XY + (a[i]*b[i-timeLag]); X = X + a[i]; Y = Y + b[i-timeLag]; Y2 = Y2 + (b[i-timeLag]*b[i-timeLag]); X2 = X2 + (a[i]*a[i]); } jml = jumlah-jmlDataPerbandingan-timeLag; K_nilai1 = (jml*XY)-(X*Y); K_nilai2 = Math.sqrt((jml*X2)-(X*X))*Math.sqrt((jml*Y2)-(Y*Y)); K_nilai3 = K_nilai1/K_nilai2; return K_nilai3; } public double[] peramalanRB(){ int i,j; for(i=jumlah-jmlDataPerbandingan;i<jumlah;i++){ Peramalan[i-jumlah+jmlDataPerbandingan] = Matrix_Final[0] + (Matrix_Final[1]*RB_Bebas1[i]) + (Matrix_Final[2]*RB_Bebas2[i]) + (Matrix_Final[3]*RB_Bebas3[i]) ; } return Peramalan; } }
1.3 Class fungsiTransfer.Java import java.awt.*; import javax.swing.*; import java.sql.*; import java.lang.Math; public class fungsiTransfer{ String TF_Tgl[] = new String[100]; double TF_Input[] = new double[100]; double TF_Output[] = new double[100];
L.2-38
double xt[] = new double[100]; double yt[] = new double[100]; double nt[] = new double[100]; double alpha[] = new double[100]; double beta[] = new double[100]; double at[] = new double[100]; double hasil1[] = new double[40]; double hasil2[] = new double[40]; //hasil sebenarnya double tempHasil; double bobotImpuls[] = new double[7]; double tetaAtas,tetaSamping; double rata2Alpha,rata2Beta,ragamAlpha,ragamBeta; double omega0,omega1,omega2,delta1,delta2; double k[] = new double[10]; //korelasi String a[] = new String[5]; int ctr=0,jumlah,i,j,b2; double r,s,b,p,q; int jmlDataPerbandingan; double p1,p2; boolean stationer=true,run=false; /*----------------------------------------Constractor Fungsi Transfer ------------------------------------------*/ fungsiTransfer(String[] a,double[] b,double[] c,int jmlDataBanding,int jml){ TF_Tgl = a; TF_Output = b; TF_Input = c; jmlDataPerbandingan = jmlDataBanding; jumlah = jml;
rata2Alpha = 0; rata2Beta = 0; nilai_xt();
L.2-39 nilai_yt(); pemutihanAplhaBeta(); cariRataRagam(); for(i=0;i<10;i++){ k[i] = korelasi(alpha,beta,i); }
cariBobotImpuls(); nilaiNoise(); while(stationer==true){ cekModel(); cariParameter(); cariNilaiA(); cekStationerNilai(); } cariHasilPeramalan(); } /*----------------------------------------Constractor Fungsi Transfer End ------------------------------------------*/ public void nilai_xt(){ // cari nilai xt xt[0] = 0; for(i=0;i<jumlah;i++){ if(i!=0){ xt[i] = TF_Input[i] - TF_Input[i-1]; } } } public void nilai_yt(){ // cari nilai yt yt[0] = 0; for(i=0;i<jumlah;i++){ if(i!=0){ yt[i] = TF_Output[i] - TF_Output[i-1]; } } } public void pemutihanAplhaBeta(){ // pemutihan untuk aplha dan Beta double p=0,q=0; double z; double temp1=0,temp2=0; boolean flag=true;
L.2-40 int ctr=0; p = korelasi(xt,xt,1); q = korelasi(xt,xt,1); z=1.96*(1/Math.sqrt(jumlah-jmlDataPerbandingan)); if(p>z&&q>z){ p=1; q=1; }else{ p=0; q=0; }
if(p==1&q==1){ // arma(1,1); p1 = korelasi(xt,xt,1); p2 = korelasi(xt,xt,2); tetaAtas = p1/p2; tetaSamping = -0.99999; while(flag==true){ tetaSamping = tetaSamping + 0.00001; temp2 = ((1-(tetaAtas*tetaSamping))*(tetaAtastetaSamping))/(1+(tetaSamping*tetaSamping)-(2*tetaAtas*tetaSamping)); temp1 = tetaAtas; temp2 = temp2; if(temp1<=temp2+0.01&&temp1>=temp2-0.01){ flag=false; } ctr++; } System.out.println("temp1->"+temp1); System.out.println("temp2->"+temp2); System.out.println("tetaSamping->"+tetaSamping); System.out.println("counter->"+ctr);
alpha[0] = 0; // indexnya mulai dr 1 beta[0] = 0; // indexnya mulai dr 1 for(i=2;i<jumlah-jmlDataPerbandingan;i++){ alpha[i-1] = xt[i] + tetaAtas*xt[i-1] - tetaSamping*alpha[i-2]; // karena alpha mulai dari 1 beta[i-1] = yt[i] + tetaAtas*yt[i-1] - tetaSamping*beta[i-2]; // karena beta mulai dari 1
L.2-41 } }
if(p==0&q==0){ // arma(0,0); alpha[0] = 0; // indexnya mulai dr 1 beta[0] = 0; // indexnya mulai dr 1 for(i=2;i<jumlah-jmlDataPerbandingan;i++){ alpha[i-1] = xt[i]; // karena alpha mulai dari 1 beta[i-1] = yt[i]; // karena beta mulai dari 1 } } } public void cariRataRagam(){ for(i=0;i<jumlah-jmlDataPerbandingan;i++){ rata2Alpha = rata2Alpha + alpha[i]; rata2Beta = rata2Beta + beta[i]; } rata2Alpha = rata2Alpha/(jumlah-(jmlDataPerbandingan+1)); rata2Beta = rata2Beta/(jumlah-(jmlDataPerbandingan+1)); for(i=0;i<jumlah-jmlDataPerbandingan;i++){ ragamAlpha = ragamAlpha + ((alpha[i]-rata2Alpha)*(alpha[i]-rata2Alpha)); ragamBeta = ragamBeta + ((beta[i]-rata2Beta)*(beta[i]-rata2Beta)); } ragamAlpha = ragamAlpha/(jumlah-(jmlDataPerbandingan+1)); ragamBeta = ragamBeta/(jumlah-(jmlDataPerbandingan+1)); } public void cariBobotImpuls(){ for(i=0;i<7;i++){ bobotImpuls[i] = k[i] * Math.sqrt(ragamBeta/ragamAlpha); } } public void nilaiNoise(){ for(i=7;i<jumlah-jmlDataPerbandingan;i++){ //nilai nt dimulai dari index ke 7 karena terdapat 7 impuls nt[i-7] = yt[i]; for(j=0;j<7;j++){ nt[i-7] = nt[i-7] - (bobotImpuls[j]*xt[i-j]); }
L.2-42 } } public void cekModel(){ double temp,z; int ctr=0;
if(run==false){ z=1.96*(1/Math.sqrt(jumlah-(jmlDataPerbandingan+7))); for(i=0;i<10;i++){ if(Math.abs(k[i])>(z-0.2)){ ctr++; } } if(ctr>2){ r=2; s=2; }else{ r=1; s=1; } if(k[0]>z){ b=0; b2=0; }else if(k[1]>z){ b=1; b2=1; }else{ b=2; b2=2; } p = korelasi(nt,nt,1); q = korelasi(nt,nt,1); if(p>z&&q>z){ p=1; q=1; }else{ p=0; q=0; } }else if(run==true){
L.2-43 if(b==2){ b=0; b2=0; }else{ b=b+1; b2=b2+1; } } a[0] = ""+r; a[1] = ""+s; a[2] = ""+b; a[3] = ""+p; a[4] = ""+q;
} public String tampilModel(){ String temp2=""; temp2 = "Model ["+ a[0].substring(0,1) +","+ a[1].substring(0,1) +","+ a[2].substring(0,1) +","+ a[3].substring(0,1) +","+ a[4].substring(0,1) +"]"; return temp2; } public void cariParameter(){ double temp1,temp2,temp3; boolean flag=true; if(b==0){ temp1 = bobotImpuls[4]/bobotImpuls[3]*bobotImpuls[4]; temp2 = bobotImpuls[3]/bobotImpuls[3]*bobotImpuls[4]; temp3 = bobotImpuls[2]/bobotImpuls[3]*bobotImpuls[4]; delta2 = (temp1-bobotImpuls[5])/(temp3-bobotImpuls[3]); temp1 = bobotImpuls[4]/bobotImpuls[2]*bobotImpuls[3]; temp2 = bobotImpuls[3]/bobotImpuls[2]*bobotImpuls[3]; temp3 = bobotImpuls[2]/bobotImpuls[2]*bobotImpuls[3]; delta1 = (temp1-bobotImpuls[5])/(temp2-bobotImpuls[4]); omega0 = bobotImpuls[0]; omega1 = (delta1*bobotImpuls[0]) - bobotImpuls[1];
L.2-44 omega2 = ((delta1*bobotImpuls[1]) + (delta2*bobotImpuls[0])) bobotImpuls[2]; } if(b==1){ temp1 = bobotImpuls[5]/bobotImpuls[4]*bobotImpuls[5]; temp2 = bobotImpuls[4]/bobotImpuls[4]*bobotImpuls[5]; temp3 = bobotImpuls[3]/bobotImpuls[4]*bobotImpuls[5]; delta2 = (temp1-bobotImpuls[6])/(temp3-bobotImpuls[4]); temp1 = bobotImpuls[5]/bobotImpuls[3]*bobotImpuls[4]; temp2 = bobotImpuls[4]/bobotImpuls[3]*bobotImpuls[4]; temp3 = bobotImpuls[3]/bobotImpuls[3]*bobotImpuls[4]; delta1 = (temp1-bobotImpuls[6])/(temp2-bobotImpuls[5]); omega0 = bobotImpuls[1]; omega1 = (delta1*bobotImpuls[1]) - bobotImpuls[2]; omega2 = ((delta1*bobotImpuls[2]) + (delta2*bobotImpuls[1])) bobotImpuls[3]; } if(b==2){ temp1 = bobotImpuls[5]/bobotImpuls[4]*bobotImpuls[5]; temp2 = bobotImpuls[4]/bobotImpuls[4]*bobotImpuls[5]; temp3 = bobotImpuls[3]/bobotImpuls[4]*bobotImpuls[5]; delta2 = (temp1-bobotImpuls[6])/(temp3-bobotImpuls[4]); temp1 = bobotImpuls[5]/bobotImpuls[3]*bobotImpuls[4]; temp2 = bobotImpuls[4]/bobotImpuls[3]*bobotImpuls[4]; temp3 = bobotImpuls[3]/bobotImpuls[3]*bobotImpuls[4]; delta1 = (temp1-bobotImpuls[6])/(temp2-bobotImpuls[5]); omega0 = bobotImpuls[2]; omega1 = (delta1*bobotImpuls[2]) - bobotImpuls[3]; omega2 = ((delta1*bobotImpuls[3]) + (delta2*bobotImpuls[2])) bobotImpuls[4]; } if(p==1){ p1 = korelasi(nt,nt,1); p2 = korelasi(nt,nt,2); tetaAtas = p1/p2; tetaSamping = -0.99999;
L.2-45
while(flag==true){ tetaSamping = tetaSamping + 0.00001; temp2 = ((1-(tetaAtas*tetaSamping))*(tetaAtastetaSamping))/(1+(tetaSamping*tetaSamping)-(2*tetaAtas*tetaSamping)); temp1 = tetaAtas; temp2 = temp2; if(temp1<=temp2+0.01&&temp1>=temp2-0.01){ flag=false; } ctr++; } } } public void cariNilaiA(){ if(p==0&&q==0){ for(i=0;i<7;i++){ at[i] = 0; } for(i=7;i<jumlah-jmlDataPerbandingan;i++){ at[i] = yt[i] - (delta1*yt[i-1]) - (delta2*yt[i-2]) - (omega0*xt[i-b2]) + (omega1*xt[i-1-b2]) + (omega2*xt[i-2-b2]) + (delta1*at[i-1]) + (delta2*at[i-2]); } for(i=jumlah;i<jumlah+jmlDataPerbandingan;i++){ at[i] = 0; } } if(p==1&&q==1){ for(i=0;i<7;i++){ at[i] = 0; } for(i=7;i<jumlah-jmlDataPerbandingan;i++){ at[i] = yt[i] - ((delta1*tetaAtas)*yt[i-1]) + (((delta1*tetaAtas)-delta2)*yt[i2]) + (delta2*yt[i-3]) - (omega0*xt[i-b2]) + ((omega1+omega0)*xt[i-1-b2]) + ((omega2(omega1*tetaAtas))*xt[i-2-b2]) - ((omega2*tetaAtas)*xt[i-3-b2]) + ((delta1+tetaSamping)*at[i-1]) + ((delta2-(delta1*tetaSamping))*at[i-2]) ((delta2*tetaSamping)*at[i-3]); }
L.2-46 for(i=jumlah;i<jumlah+jmlDataPerbandingan;i++){ at[i] = 0; } } } public void cekStationerNilai(){ double temp1,temp2,z; double temp3[] = new double[100]; int ctr=0; for(i=7;i<jumlah-jmlDataPerbandingan;i++){ temp3[i-7] = at[i]; } z=1.96*(1/Math.sqrt(jumlah-(jmlDataPerbandingan+7))); for(i=0;i<10;i++){ temp1 = korelasi(alpha,temp3,i); if(temp1>z){ ctr++; } } if(ctr>9){ stationer = true; run = true; }else{ stationer = false; run = true; } } public double[] cariHasilPeramalan(){ tempHasil = TF_Output[jumlah-(jmlDataPerbandingan+1)]; if(p==0&&q==0){ for(i=jumlah-jmlDataPerbandingan;i<jumlah;i++){ hasil1[i-(jumlah-jmlDataPerbandingan)] = (delta1*yt[i-1]) + (delta2*yt[i-2]) + (omega0*xt[i-b2]) - (omega1*xt[i-1-b2]) - (omega2*xt[i-2-b2]) + at[i] - (delta1*at[i1]) - (delta2*at[i-2]); yt[i] = hasil1[i-(jumlah-jmlDataPerbandingan)]; tempHasil = tempHasil + hasil1[i-(jumlah-(jmlDataPerbandingan))]; hasil2[i-(jumlah-jmlDataPerbandingan)] = tempHasil; } }
L.2-47 if(p==1&&q==1){ for(i=jumlah-jmlDataPerbandingan;i<jumlah;i++){ hasil1[i-(jumlah-jmlDataPerbandingan)] = ((tetaAtas+delta1)*yt[i-1]) (((delta1*tetaAtas)-delta2)*yt[i-2]) - (delta2*yt[i-3]) + (omega0*xt[i-b2]) ((omega1+(omega0*tetaAtas))*xt[i-1-b2]) - ((omega2-(omega1*tetaAtas))*xt[i-2-b2]) ((omega2*tetaAtas)*xt[i-3-b2]) + at[i] - ((tetaSamping+delta1)*at[i-1]) - ((delta2(delta1*tetaSamping))*at[i-2]) + ((delta2*tetaSamping)*at[i-3]); yt[i] = hasil1[i-(jumlah-jmlDataPerbandingan)]; tempHasil = tempHasil + hasil1[i-(jumlah-(jmlDataPerbandingan))]; hasil2[i-(jumlah-jmlDataPerbandingan)] = tempHasil; } } return hasil2; }
public double korelasi(double[] a,double[] b,int timeLag){ // cari korelasi double X=0,X2=0,Y=0,Y2=0,XY=0; double K_nilai1,K_nilai2,K_nilai3; int i,jml;
for(i=timeLag;i<jumlah-(jmlDataPerbandingan+1);i++){ XY = XY + (a[i]*b[i-timeLag]); X = X + a[i]; Y = Y + b[i-timeLag]; Y2 = Y2 + (b[i-timeLag]*b[i-timeLag]); X2 = X2 + (a[i]*a[i]); }
jml = jumlah-jmlDataPerbandingan-timeLag;; K_nilai1 = (jml*XY)-(X*Y); K_nilai2 = Math.sqrt((jml*X2)-(X*X))*Math.sqrt((jml*Y2)-(Y*Y)); K_nilai3 = K_nilai1/K_nilai2;
return K_nilai3; } }
L.3-1 LAMPIRAN 3 : LANGKAH PERHITUNGAN
3.1
Perhitungan Galat Fungsi Transfer
2006 May 2006 June 2006 July 2006 Aug 2006 Sept
Pengamatan 172,634,000 165,623,000 169,412,000 171,867,000 167,523,000
Fungsi Transfer 181,659,292 171,186,987 173,948,063 179,385,453 172,286,376
Galat -9,025,292 -5,563,987 -4,536,063 -7,518,453 -4,763,376
|PE| 5.227991962 3.359429114 2.677533744 4.374576295 2.843416019
Galat kuadrat 8.14559E+13 3.0958E+13 2.05759E+13 5.65271E+13 2.26897E+13
847,059,000
878,466,171
-31,407,171
18.482947
2.12207E+14
MAPE 3.69658%
MSE 4.24413E+13
3.2 Perhitungan Galat Regresi Berganda
2006 May 2006 June 2006 July 2006 Aug 2006 Sept
Pengamatan 172,634,000 165,623,000 169,412,000 171,867,000 167,523,000
Regresi Berganda 170,912,339 162,487,032 167,369,200 173,589,648 163,526,949
Galat 1,721,661 3,135,968 2,042,800 -1,722,648 3,996,051
|PE| 0.997289897 1.8934375 1.205817871 1.002314408 2.385374504
Galat kuadrat 2.96412E+12 9.8343E+12 4.17303E+12 2.96752E+12 1.59684E+13
847,059,000
837,885,167
9,173,833
7.484234
3.59074E+13
MAPE 1.496846%
MSE 7.18148E+12
L.3-2 3.2
Perhitungan F-test
Tanggal Jan-03
Laba (Y) 184002000
Kurs Dollar (X1)
Penjualan (X2)
8864
12
Advertise (X3) 73125000
Ŷi
(Yi-Ŷi)2
(Ŷi-Ỹi)2
176794460.8
5.19486E+13
1.80979E+13
Feb-03
188905000
8935
15
69550000
182354960.3
4.2903E+13
9.63276E+13
Mar-03
169259000
8910
9
64470000
167721691.4
2.36332E+12
2.3219E+13
Apr-03
174229000
8842
10
65650000
170812818.8
1.16703E+13
2.98419E+12
May-03
168178000
8451
9
66500000
171851258.4
1.34928E+13
4.74778E+11
Jun-03
189130000
8195
12
69600000
181451783.1
5.8955E+13
7.94145E+13
Jul-03
174636000
8220
12
64425000
180163330.1
3.05514E+13
5.81106E+13
Aug-03
169997000
8547
12
67525000
178176054.9
6.68969E+13
3.17617E+13
Sep-03
163989000
8455
11
64500000
175988376.6
1.43985E+14
1.18892E+13
Oct-03
177232000
8438
9
69650000
172617644
2.12923E+13
5982094336
Nov-03
174732000
8522
9
57500000
169388421.9
2.85538E+13
9.93434E+12
Dec-03
170786000
8483
10
75775000
175835523.9
2.54977E+13
1.08585E+13
Jan-04
181326000
8350
10
74350000
176609333.9
2.22469E+13
1.6557E+13
Feb-04
191625000
8399
15
78800000
188621972.6
9.01817E+12
2.5862E+14
Mar-04
179632000
8645
10
59250000
171058238.5
7.35094E+13
2.19651E+12
Apr-04
182871000
8618
12
54500000
174867968.4
6.40485E+13
5.41804E+12
May-04
172523000
8965
10
67525000
170214190.1
5.3306E+12
5.41079E+12
Jun-04
154501000
9400
8
71420000
162933117.2
7.11006E+13
9.2298E+13
Jul-04
168169000
8980
9
68850000
168076723
8515052111
1.99235E+13
Aug-04
161525000
9248
12
68520000
172729252.8
1.25535E+14
35703145512
Sep-04
182262000
9097
16
77250000
184959620.2
7.27715E+12
1.5424E+14
Oct-04
163742000
9102
11
52600000
168269303
2.04965E+13
1.82414E+13
Nov-04
157652000
9051
9
57950000
165214886.4
5.71973E+13
5.36617E+13
Dec-04
165635000
9350
12
68125000
171823354.5
3.82957E+13
5.14011E+11
Jan-05
181842000
9160
15
75625000
181815383.3
708449783.6
8.60272E+13
Feb-05
184314000
9250
17
78325000
186245643.1
3.73125E+12
1.87836E+14
Mar-05
179321000
9360
16
69520000
181214404.6
3.58498E+12
7.52401E+13 1.92679E+13
Apr-05
167825000
9525
12
57360000
168150783.5
1.06135E+11
May-05
160952000
9490
9
54050000
160853981.8
9607575373
1.3657E+14
Jun-05
164641000
9595
10
64745000
164547474.5
8747022891
6.38853E+13
Jul-05
169847000
9810
11
61250000
164373574
2.99584E+13
6.66954E+13
Aug-05
168312000
9830
11
67150000
165451211.6
8.18411E+12
5.02552E+13
Sep-05
161625000
10015
9
65250000
158970218.8
7.04786E+12
1.84147E+14
Oct-05
157978000
10140
8
62595000
155109458.4
8.22853E+12
3.03834E+14
Nov-05
158342000
10020
9
62545000
158361828.2
393155929
2.01029E+14
Dec-05
162875000
9815
9
71650000
161927842.8
8.97107E+11
1.12624E+14
Jan-06
181412000
9370
13
73523000
175090267.4
3.99643E+13
6.50233E+12
Feb-06
181412000
9215
12
79555000
175312850.7
3.71996E+13
7.68704E+12
Mar-06
178523000
9143
14
74125000
179342846
6.72147E+11
4.62746E+13
Apr-06
175853000
9010
11
71750000
173033070
7.95201E+12
2.42822E+11
Total
6901612000
362815
450
2696428000
6888335123
1.13972E+15
2.51831E+15
Rata-rata
172,540,300 F=
8.394E+14 3.166E+13
=
26.5150585
L.4-1 LAMPIRAN 4 : DAFTAR TABEL 4.1
Tabel F Tabel Sebaran F (v1=1-9) f0.05(v1,v2)
L.4-2
Tabel Sebaran F (v1=10-∞) f0.05(v1,v2)
L.4-3 4.2
Tabel Z