MCPcopy Create free account
hub / github.com/apache/madlib / stateToResult

Function stateToResult

src/modules/stats/coxph_improved.cpp:35–71  ·  view source on GitHub ↗

* @brief Compute the diagnostic statistics * */

Source from the content-addressed store, hash-verified

33 *
34 */
35AnyType stateToResult(
36 const Allocator &inAllocator, const ColumnVector &inCoef,
37 const ColumnVector &diagonal_of_inverse_of_hessian,
38 double logLikelihood, const Matrix &inHessian,
39 int nIter, const ColumnVector &stds)
40{
41 MutableNativeColumnVector coef(
42 inAllocator.allocateArray<double>(inCoef.size()));
43 MutableNativeColumnVector std_err(
44 inAllocator.allocateArray<double>(inCoef.size()));
45 MutableNativeColumnVector waldZStats(
46 inAllocator.allocateArray<double>(inCoef.size()));
47 MutableNativeColumnVector waldPValues(
48 inAllocator.allocateArray<double>(inCoef.size()));
49
50 for (Index i = 0; i < inCoef.size(); ++i) {
51 coef(i) = inCoef(i) / stds(i);
52 std_err(i) = std::sqrt(diagonal_of_inverse_of_hessian(i)) / stds(i);
53 waldZStats(i) = coef(i) / std_err(i);
54 waldPValues(i) = 2. * prob::cdf( prob::normal(),
55 -std::abs(waldZStats(i)));
56 }
57
58 // Hessian being symmetric is updated as lower triangular matrix.
59 // We need to convert diagonal matrix to full-matrix before output
60 Matrix full_hessian = inHessian + inHessian.transpose();
61 full_hessian.diagonal() /= 2;
62 for (Index i = 0; i < inCoef.size(); ++i)
63 for (Index j = 0; j < inCoef.size(); ++j)
64 full_hessian(i,j) *= stds(i) * stds(j);
65
66 // Return all coefficients, standard errors, etc. in a tuple
67 AnyType tuple;
68 tuple << coef << logLikelihood << std_err << waldZStats << waldPValues
69 << full_hessian << nIter;
70 return tuple;
71}
72
73// ------------------------------------------------------------
74

Callers 1

runMethod · 0.70

Calls 2

cdfFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected