Compute the stats from coef and errs
| 182 | |
| 183 | // Compute the stats from coef and errs |
| 184 | AnyType clustered_compute_stats (AnyType& args, |
| 185 | void (*func)( |
| 186 | MutableNativeColumnVector&, |
| 187 | MutableNativeColumnVector&, |
| 188 | int, int), bool ismlogr) |
| 189 | { |
| 190 | //const MappedColumnVector& coef = args[0].getAs<MappedColumnVector>(); |
| 191 | ColumnVector coef; |
| 192 | if (ismlogr){ |
| 193 | MappedMatrix coefMat = args[0].getAs<MappedMatrix>(); |
| 194 | Matrix mat = coefMat; |
| 195 | mat.transposeInPlace(); |
| 196 | mat.resize(coefMat.size(), 1); |
| 197 | coef = mat; |
| 198 | }else{ |
| 199 | coef = args[0].getAs<MappedColumnVector>(); |
| 200 | } |
| 201 | const MappedColumnVector& meatvec = args[1].getAs<MappedColumnVector>(); |
| 202 | const MappedColumnVector& breadvec = args[2].getAs<MappedColumnVector>(); |
| 203 | int mcluster = args[3].getAs<int>(); |
| 204 | int numRows = args[4].getAs<int>(); |
| 205 | int k = static_cast<int>(coef.size()); |
| 206 | Matrix bread(k,k); |
| 207 | Matrix meat(k,k); |
| 208 | int count = 0; |
| 209 | |
| 210 | for (int i = 0; i < k; i++) |
| 211 | for (int j = 0; j < k; j++) |
| 212 | { |
| 213 | meat(i,j) = meatvec(count); |
| 214 | bread(i,j) = breadvec(count); |
| 215 | count++; |
| 216 | } |
| 217 | |
| 218 | if (mcluster == 1) { |
| 219 | //throw std::domain_error ("Clustered variance error: Number of clusters cannot be smaller than 2!"); |
| 220 | warning("Clustered variance error: Number of clusters cannot be smaller than 2!"); |
| 221 | return Null(); |
| 222 | } |
| 223 | double dfc = (mcluster / (mcluster - 1.)) * ((numRows - 1.) / (numRows - k)); |
| 224 | |
| 225 | SymmetricPositiveDefiniteEigenDecomposition<Matrix> decomposition( |
| 226 | bread, EigenvaluesOnly, ComputePseudoInverse); |
| 227 | Matrix inverse_of_bread = decomposition.pseudoInverse(); |
| 228 | Matrix cov(k, k); |
| 229 | cov = inverse_of_bread * meat * inverse_of_bread; |
| 230 | |
| 231 | MutableNativeColumnVector errs; |
| 232 | MutableNativeColumnVector stats; |
| 233 | MutableNativeColumnVector pValues; |
| 234 | Allocator& allocator = defaultAllocator(); |
| 235 | |
| 236 | errs.rebind(allocator.allocateArray<double>(k)); |
| 237 | stats.rebind(allocator.allocateArray<double>(k)); |
| 238 | pValues.rebind(allocator.allocateArray<double>(k)); |
| 239 | for (int i = 0; i < k; i++) |
| 240 | { |
| 241 | if (inverse_of_bread(i,i) < 0) |