import javastat.regression.glm.LogLinearRegression;
/**
*
* <p>Example: class LogLinearRegression.</p>
* <p>Data Source: McCullagh, P. and Nelder, J. A.
(1989).
* Generalized Linear Models.
*/
String[][] shipData = { {"a",
"a", "a", "a", "a", "a",
"a", "a",
"b", "b", "b", "b",
"b", "b", "b", "b",
"c", "c", "c", "c",
"c", "c", "c", "c",
"d", "d", "d", "d",
"d", "d", "d", "d",
"e", "e", "e", "e",
"e", "e", "e", "e"},
{"1960-64", "1960-64", "1965-69",
"1965-69",
"1970-74", "1970-74", "1975-79",
"1975-79",
"1960-64", "1960-64", "1965-69",
"1965-69",
"1970-74", "1970-74", "1975-79",
"1975-79",
"1960-64", "1960-64", "1965-69",
"1965-69",
"1970-74",
"1970-74", "1975-79", "1975-79",
"1960-64", "1960-64", "1965-69",
"1965-69",
"1970-74", "1970-74", "1975-79",
"1975-79",
"1960-64", "1960-64", "1965-69",
"1965-69",
"1970-74", "1970-74", "1975-79",
"1975-79"},
{"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79",
"1960-74", "1975-79", "1960-74",
"1975-79"} };
double[] offset = {127, 63, 1095, 1095, 1512, 3353, 0, 2244, 44882,
17176, 28609, 20370, 7064, 13099, 0, 7177, 1179,
552, 781, 676, 783, 1948, 0, 274, 251, 105, 288,
192, 349, 1208, 0, 2051, 45, 0, 789, 437, 1157,
2161, 0, 542};
double[] damageNumber = {0, 0, 3, 4, 6, 18, 0,
11, 39, 29, 58, 53, 12,
44, 0, 18, 1, 1, 0, 1, 6, 2, 0, 1, 0, 0, 0, 0,
2, 11, 0, 4, 0, 0, 7, 7, 5, 12, 0, 1};
testclass1
= new LogLinearRegression(damageNumber, offset, shipData);
coefficients = testclass1.coefficients;
confidenceInterval =
testclass1.confidenceInterval;
testStatistic =
testclass1.testStatistic;
pValue = testclass1.pValue;
devianceTable =
testclass1.devianceTable;
print("The estimated coefficients (non-null constructor)
= [" +
coefficients[0]
+ " , " + coefficients[1] + " , " +
coefficients[2]
+ " , " + coefficients[3] + " , " +
coefficients[4]
+ " , " + coefficients[5] + " , " +
coefficients[6] + " , " +
coefficients[7] + " , "
coefficients[8]
+ "]");
testclass2
= new LogLinearRegression();
coefficients = testclass2.coefficients(damageNumber,
offset, shipData);
confidenceInterval =
testclass2.confidenceInterval(0.1, damageNumber,
offset, shipData);
testStatistic =
testclass2.testStatistic(damageNumber, offset, shipData);
pValue = testclass2.pValue(damageNumber,
offset, shipData);
devianceTable =
testclass2.devianceTable(damageNumber, offset, shipData);
print("The z statistics (null constructor) =
["
+ testStatistic[0] + " ,
" + testStatistic[1] + " , " +
testStatistic[2] + " , "
+ testStatistic[3] + " , " +
testStatistic[4] + " , " + testStatistic[5]
+ " , " +
testStatistic[6] + " ,
" + testStatistic[7] + " , " +
testStatistic[8] +
"]");
print("The p-values for the z statistics (null constructor)
= ["
+ pValue[0] + " , "
+ pValue[1] + " , " + pValue[2]
+ " , " + pValue[3] +
" , "
+ pValue[4] + " , " + pValue[5]
+ " , " + pValue[6] + " , " +
pValue[7] + " , " + pValue[8]
+ "]");
Results:
The estimated coefficients (non-null constructor)
= [-6.405 , -0.545, -0.688, -0.075 , 0.325
, 0.697 , 0.818 , 0.449 , 0.384]
The
z statistics (null constructor)
=
[-29.457, -3.068 , -2.091 , -0.258, 1.378, 4.658 ,
4.817 , 1.926, 3.250]
The
p-values for the z statistics (null constructor)
= [0.0 , 0.002, 0.036 , 0.796, 0.168, 3.196E-6 , 1.457E-6 ,
0.054 , 0.001]