Branch Coverage: LikeR.xs

# Branch Coverage

File: | LikeR.xs
Coverage: | 66.9%

line | % | coverage | branch
--- | --- | --- | ---
30 | 50 | T | F | if (df <= 0.0) return 0.0;
40 | 100 | T | F | for (unsigned short i = 1; i < n_steps; i++) {
52 | 100 | T | F | double weight = (i % 2 != 0) ? 4.0 : 2.0;
73 | 100 | T | F | for (size_t i = 0; i < n; i++) {
79 | 100 | T | F | for (size_t i = 0; i < n; ) {
81 | 100 | T | F | while (j < n && items[j].val == items[i].val) j++;
| 50 | T | F | while (j < n && items[j].val == items[i].val) j++;
83 | 100 | T | F | for (size_t k = i; k < j; k++) items[k].rank = avg_rank;
87 | 100 | T | F | for (size_t i = 0; i < n; i++) ranks[i] = items[i].rank;
93 | 100 | T | F | if (prob <= 0.0) return 0;
94 | 100 | T | F | if (prob >= 1.0) return size;
97 | 100 | T | F | for (size_t i = 0; i < size; i++) {
98 | 100 | T | F | if (Drand01() <= prob) successes++;
111 | 100 | T | F | for(size_t k = 0; k <= max_x - min_x; ++k) {
113 | 100 | T | F | if (d_val > max_d) max_d = d_val;
117 | 100 | T | F | for(size_t k = 0; k <= max_x - min_x; ++k) {
124 | 100 | T | F | for(size_t k = 0; k <= max_x - min_x; ++k) {
126 | 100 | T | F | if (min_x + k <= a) *lower_tail += p_prob;
127 | 100 | T | F | if (min_x + k >= a) *upper_tail += p_prob;
135 | 100 | T | F | size_t min_x = (r2 > c1) ? 0 : c1 - r2;
143 | 100 | T | F | for(size_t x = min_x; x <= max_x; ++x) {
148 | 50 | T | F | if (a == min_x && a == max_x) *mle_or = 1.0;
| 0 | T | F | if (a == min_x && a == max_x) *mle_or = 1.0;
149 | 50 | T | F | else if (a == min_x) *mle_or = 0.0;
150 | 100 | T | F | else if (a == max_x) *mle_or = INFINITY;
153 | 50 | T | F | for (unsigned short int i = 0; i < 3000; i++) {
156 | 100 | T | F | for(size_t k = 0; k <= max_x - min_x; ++k) {
158 | 100 | T | F | if (d_val > max_d) max_d = d_val;
161 | 100 | T | F | for(size_t k = 0; k <= max_x - min_x; ++k) {
168 | 100 | T | F | if (exp_val > a) log_high = log_mid;
170 | 100 | T | F | if (log_high - log_low < 1e-15) break;
179 | 100 | T | F | if (!is_less) {
180 | 100 | T | F | double target_alpha = is_greater ? alpha : alpha / 2.0;
181 | 50 | T | F | if (a != min_x) {
183 | 50 | T | F | for (unsigned short int i = 0; i < 1000; i++) {
188 | 100 | T | F | if (err < best_err) { best_err = err; best = mid; }
189 | 100 | T | F | if (ut > target_alpha) log_high = log_mid;
191 | 100 | T | F | if (log_high - log_low < 1e-15) break;
198 | 100 | T | F | if (!is_greater) {
199 | 100 | T | F | double target_alpha = is_less ? alpha : alpha / 2.0;
200 | 100 | T | F | if (a != max_x) {
202 | 50 | T | F | for (unsigned short int i = 0; i < 1000; i++) {
207 | 100 | T | F | if (err < best_err) { best_err = err; best = mid; }
208 | 100 | T | F | if (lt > target_alpha) log_low = log_mid;
210 | 100 | T | F | if (log_high - log_low < 1e-15) break;
221 | 100 | T | F | size_t min_x = (r2 > c1) ? 0 : c1 - r2;
226 | 100 | T | F | for(size_t x = min_x; x <= max_x; ++x) {
232 | 100 | T | F | if (strcmp(alt, "less") == 0) {
233 | 100 | T | F | for(size_t x = min_x; x <= a; ++x) p_val += exp(logdc[x - min_x]);
234 | 100 | T | F | } else if (strcmp(alt, "greater") == 0) {
235 | 100 | T | F | for(size_t x = a; x <= max_x; ++x) p_val += exp(logdc[x - min_x]);
239 | 100 | T | F | for(size_t x = min_x; x <= max_x; ++x) {
241 | 100 | T | F | if (p_cur <= p_obs * relErr) p_val += p_cur;
246 | 50 | T | F | return (p_val > 1.0) ? 1.0 : p_val;
261 | 100 | T | F | for (size_t k = 0; k < n; k++) {
266 | 100 | T | F | for (size_t k = 0; k < n; k++) {
269 | 100 | T | F | if (fabs(A[k * n + k]) <= 1e-10 * orig_diag[k] || fabs(A[k * n + k]) < 1e-24) {
| 50 | T | F | if (fabs(A[k * n + k]) <= 1e-10 * orig_diag[k] || fabs(A[k * n + k]) < 1e-24) {
272 | 100 | T | F | for (size_t i = 0; i < n; i++) {
281 | 100 | T | F | for (size_t j = 0; j < n; j++) A[k * n + j] *= pivot;
282 | 100 | T | F | for (size_t i = 0; i < n; i++) {
283 | 100 | T | F | if (i != k && A[i * n + k] != 0.0) {
| 100 | T | F | if (i != k && A[i * n + k] != 0.0) {
286 | 100 | T | F | for (size_t j = 0; j < n; j++) {
299 | 100 | T | F | if (row_hashes) {
301 | 50 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 50 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 50 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
305 | 50 | T | F | } else if (data_hoa) {
307 | 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
312 | 50 | T | F | if (val && SvOK(*val)) {
| 100 | T | F | if (val && SvOK(*val)) {
313 | 50 | T | F | if (looks_like_number(*val)) return SvNV(*val);
322 | 50 | T | F | if (data_hoa) {
325 | 100 | T | F | while ((entry = hv_iternext(data_hoa))) {
328 | 0 | T | F | } else if (row_hashes && n > 0 && row_hashes[0]) {
| 0 | T | F | } else if (row_hashes && n > 0 && row_hashes[0]) {
| 0 | T | F | } else if (row_hashes && n > 0 && row_hashes[0]) {
331 | 0 | T | F | while ((entry = hv_iternext(row_hashes[0]))) {
340 | 50 | T | F | if (!term || term[0] == '\0') return NAN;
| 50 | T | F | if (!term || term[0] == '\0') return NAN;
344 | 100 | T | F | if (colon) {
350 | 50 | T | F | if (isnan(left) || isnan(right)) return NAN;
| 50 | T | F | if (isnan(left) || isnan(right)) return NAN;
353 | 50 | T | F | if (strncmp(term_cpy, "I(", 2) == 0) {
355 | 0 | T | F | if (end) *end = '\0';
359 | 0 | T | F | if (caret) {
366 | 0 | T | F | if (isnan(v)) return NAN;
367 | 0 | T | F | return power == 1 ? v : pow(v, power);
376 | 100 | T | F | for (size_t i = 0; i < n; i++) {
378 | 100 | T | F | if (row_hashes) {
380 | 100 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 50 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 50 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
384 | 50 | T | F | } else if (data_hoa) {
386 | 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
391 | 100 | T | F | if (val && SvOK(*val)) {
| 50 | T | F | if (val && SvOK(*val)) {
392 | 100 | T | F | if (looks_like_number(*val)) return false; // First valid is number -> Numeric Column
402 | 50 | T | F | if (row_hashes) {
404 | 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVAV) {
408 | 50 | T | F | } else if (data_hoa) {
410 | 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
| 50 | T | F | if (col && SvROK(*col) && SvTYPE(SvRV(*col)) == SVt_PVAV) {
415 | 50 | T | F | if (val && SvOK(*val)) {
| 50 | T | F | if (val && SvOK(*val)) {
430 | 100 | T | F | if (diff < 0) return -1;
431 | 50 | T | F | if (diff > 0) return 1;
447 | 100 | T | F | if (diff < 0) return -1;
448 | 100 | T | F | if (diff > 0) return 1;
456 | 50 | T | F | Newx(ri, n, RankItem);
457 | 100 | T | F | for (size_t i = 0; i < n; i++) { ri[i].val = in[i]; ri[i].idx = i; }
461 | 100 | T | F | while (i < n) {
464 | 100 | T | F | while (j + 1 < n && ri[j + 1].val == ri[j].val) j++;
| 100 | T | F | while (j + 1 < n && ri[j + 1].val == ri[j].val) j++;
467 | 100 | T | F | for (size_t k = i; k <= j; k++) out[ri[k].idx] = avg;
477 | 100 | T | F | for (size_t i = 0; i < n; i++) {
483 | 50 | T | F | if (den == 0.0) return NAN;
497 | 100 | T | F | for (size_t i = 0; i < n - 1; i++) {
498 | 100 | T | F | for (size_t j = i + 1; j < n; j++) {
501 | 100 | T | F | if (sx == 0 && sy == 0) { /* joint tie â€” not counted */ }
| 50 | T | F | if (sx == 0 && sy == 0) { /* joint tie â€” not counted */ }
502 | 100 | T | F | else if (sx == 0) tie_x++;
503 | 50 | T | F | else if (sy == 0) tie_y++;
504 | 50 | T | F | else if (sx == sy) C++;
509 | 50 | T | F | if (denom == 0.0) return NAN;
517 | 100 | T | F | if (strcmp(method, "spearman") == 0) {
519 | 50 | T | F | Newx(rx, n, double); Newx(ry, n, double);
| 50 | T | F | Newx(rx, n, double); Newx(ry, n, double);
526 | 100 | T | F | if (strcmp(method, "kendall") == 0)
542 | 50 | T | F | if (fabs(d) < FPMIN) d = FPMIN;
544 | 50 | T | F | for (m = 1; m <= MAX_ITER; m++) {
548 | 50 | T | F | if (fabs(d) < FPMIN) d = FPMIN;
550 | 50 | T | F | if (fabs(c) < FPMIN) c = FPMIN;
554 | 50 | T | F | if (fabs(d) < FPMIN) d = FPMIN;
556 | 50 | T | F | if (fabs(c) < FPMIN) c = FPMIN;
558 | 100 | T | F | if (fabs(del - 1.0) < EPS) break;
564 | 50 | T | F | if (x <= 0.0) return 0.0;
565 | 100 | T | F | if (x >= 1.0) return 1.0;
567 | 100 | T | F | if (x < (a + 1.0) / (a + b + 2.0)) return bt * _incbeta_cf(a, b, x) / a;
574 | 100 | T | F | if (strcmp(alt, "less") == 0) return (t < 0) ? 0.5 * prob_2tail : 1.0 - 0.5 * prob_2tail;
| 100 | T | F | if (strcmp(alt, "less") == 0) return (t < 0) ? 0.5 * prob_2tail : 1.0 - 0.5 * prob_2tail;
575 | 100 | T | F | if (strcmp(alt, "greater") == 0) return (t > 0) ? 0.5 * prob_2tail : 1.0 - 0.5 * prob_2tail;
| 50 | T | F | if (strcmp(alt, "greater") == 0) return (t > 0) ? 0.5 * prob_2tail : 1.0 - 0.5 * prob_2tail;
583 | 100 | T | F | while (get_t_pvalue(high, df, "greater") > p_tail) {
586 | 50 | T | F | if (high > 1000000.0) break; /* Fallback limit */
589 | 50 | T | F | for (unsigned short int i = 0; i < 100; i++) {
592 | 100 | T | F | if (p_mid > p_tail) {
597 | 100 | T | F | if (high - low < 1e-8) break;
609 | 0 | T | F | if (n == 0) return 1;
618 | 50 | T | F | double step = (n_bins > 0) ? (breaks[1] - breaks[0]) : 0.0;
620 | 100 | T | F | for (size_t i = 0; i < n_bins; i++) {
625 | 100 | T | F | if (step > 0.0) {
626 | 100 | T | F | for (size_t j = 0; j < n; j++) {
629 | 50 | T | F | if (isnan(val) || isinf(val) || val < min_val) continue;
| 50 | T | F | if (isnan(val) || isinf(val) || val < min_val) continue;
| 50 | T | F | if (isnan(val) || isinf(val) || val < min_val) continue;
633 | 100 | T | F | if (idx >= n_bins) {
639 | 100 | T | F | while (idx > 0 && val <= breaks[idx]) {
| 100 | T | F | while (idx > 0 && val <= breaks[idx]) {
643 | 100 | T | F | while (idx < n_bins - 1 && val > breaks[idx + 1]) {
| 50 | T | F | while (idx < n_bins - 1 && val > breaks[idx + 1]) {
648 | 50 | T | F | } else if (n_bins > 0) {
653 | 100 | T | F | for (size_t i = 0; i < n_bins; i++) {
655 | 100 | T | F | if (bin_width > 0) {
658 | 50 | T | F | density[i] = (n_bins == 1) ? 1.0 : 0.0;
681 | 100 | T | F | if (fabs(y) < 0.42) {
687 | 100 | T | F | if (y > 0) r = 1.0 - p;
691 | 100 | T | F | if (y < 0) x = -x;
709 | 100 | T | F | for (size_t i = 0; i < n; i++) { perm[i] = i + 1; c[i] = 0; }
724 | 100 | T | F | TALLY_PERM(); /* initial permutation [1, 2, ..., n] */
| 50 | T | F | TALLY_PERM(); /* initial permutation [1, 2, ..., n] */
| 50 | T | F | TALLY_PERM(); /* initial permutation [1, 2, ..., n] */
727 | 100 | T | F | while (k < n) {
728 | 100 | T | F | if (c[k] < k) {
730 | 100 | T | F | if (k % 2 == 0) {
735 | 100 | T | F | TALLY_PERM();
| 100 | T | F | TALLY_PERM();
| 100 | T | F | TALLY_PERM();
751 | 50 | T | F | if (strcmp(alt, "greater") == 0) return p_le;
752 | 50 | T | F | if (strcmp(alt, "less") == 0) return p_ge;
754 | 50 | T | F | double p = 2.0 * (p_le < p_ge ? p_le : p_ge);
755 | 50 | T | F | return (p > 1.0) ? 1.0 : p;
764 | 100 | T | F | for (long i = 0; i <= max_inv; i++) dp[i] = 0.0;
767 | 100 | T | F | for (size_t i = 2; i <= n; i++) {
769 | 100 | T | F | for (long k = 0; k <= max_inv; k++) next_dp[k] = 0.0;
771 | 100 | T | F | for (int k = 0; k <= current_max_inv; k++) {
773 | 100 | T | F | for (int j = 0; j <= i - 1 && k - j >= 0; j++) {
| 100 | T | F | for (int j = 0; j <= i - 1 && k - j >= 0; j++) {
784 | 50 | T | F | if (i_obs < 0) i_obs = 0;
785 | 50 | T | F | if (i_obs > max_inv) i_obs = max_inv;
787 | 100 | T | F | for (long k = i_obs; k <= max_inv; k++) p_le += dp[k];
789 | 100 | T | F | for (long k = 0; k <= i_obs; k++) p_ge += dp[k];
791 | 50 | T | F | if (strcmp(alt, "greater") == 0) return p_ge;
792 | 100 | T | F | if (strcmp(alt, "less") == 0) return p_le;
794 | 50 | T | F | double p = 2.0 * (p_ge < p_le ? p_ge : p_le);
795 | 50 | T | F | return p > 1.0 ? 1.0 : p;
799 | 50 | T | F | if (f <= 0.0) return 0.0;
808 | 100 | T | F | for (size_t k = 0; k < p; k++) {
810 | 50 | T | F | if (r >= n) {
816 | 100 | T | F | for (size_t i = r; i < n; i++) {
817 | 100 | T | F | if (fabs(X[i][k]) > max_val) max_val = fabs(X[i][k]);
819 | 100 | T | F | if (max_val < 1e-10) {
825 | 100 | T | F | for (size_t i = r; i < n; i++) {
830 | 100 | T | F | double s = (X[r][k] > 0) ? -norm : norm;
834 | 100 | T | F | for (size_t j = k + 1; j < p; j++) {
836 | 100 | T | F | for (size_t i = r + 1; i < n; i++) dot += X[i][j] * X[i][k];
839 | 100 | T | F | for (size_t i = r + 1; i < n; i++) X[i][j] += tau * X[i][k];
844 | 100 | T | F | for (size_t i = r + 1; i < n; i++) dot_y += y[i] * X[i][k];
847 | 100 | T | F | for (size_t i = r + 1; i < n; i++) y[i] += tau_y * X[i][k];
863 | 50 | T | F | if (!sv || !SvOK(sv)) return 0;
| 50 | T | F | if (!sv || !SvOK(sv)) return 0;
866 | 100 | T | F | for (size_t i = 0; i < len; i++) {
867 | 50 | T | F | if (!isdigit(s[i])) return 1;
874 | 50 | T | F | if (!str) str = "";
876 | 100 | T | F | if (strstr(str, sep) != NULL || strchr(str, '"') != NULL || strchr(str, '\r') != NULL || strchr(str, '\n') != NULL) {
| 100 | T | F | if (strstr(str, sep) != NULL || strchr(str, '"') != NULL || strchr(str, '\r') != NULL || strchr(str, '\n') != NULL) {
| 50 | T | F | if (strstr(str, sep) != NULL || strchr(str, '"') != NULL || strchr(str, '\r') != NULL || strchr(str, '\n') != NULL) {
| 50 | T | F | if (strstr(str, sep) != NULL || strchr(str, '"') != NULL || strchr(str, '\r') != NULL || strchr(str, '\n') != NULL) {
880 | 100 | T | F | if (needs_quotes) {
882 | 100 | T | F | for (const char *restrict p = str; *p; p++) {
883 | 100 | T | F | if (*p == '"') {
899 | 100 | T | F | for (size_t i = 0; i < len; i++) {
900 | 100 | T | F | if (i > 0) PerlIO_write(fh, sep, sep_len);
901 | 50 | T | F | if (row[i]) {
912 | 50 | T | F | if (x < 0.0 || a <= 0.0) return 1.0;
| 50 | T | F | if (x < 0.0 || a <= 0.0) return 1.0;
913 | 50 | T | F | if (x == 0.0) return 1.0;
916 | 100 | T | F | if (x < a + 1.0) {
920 | 100 | T | F | while (fabs(term) > 1e-15) {
933 | 50 | T | F | while (i < 10000) { // Safety bound
937 | 50 | T | F | if (fabs(d) < 1e-30) d = 1e-30;
939 | 50 | T | F | if (fabs(c) < 1e-30) c = 1e-30;
943 | 100 | T | F | if (fabs(del - 1.0) < 1e-15) break;
951 | 50 | T | F | if (df <= 0) return 1.0;
952 | 50 | T | F | if (stat <= 0.0) return 1.0;
963 | 50 | T | F | if (k < 0 || k > n) return 0.0L;
| 50 | T | F | if (k < 0 || k > n) return 0.0L;
964 | 50 | T | F | if (k > n / 2) k = n - k;
966 | 100 | T | F | for (int i = 1; i <= k; i++) {
977 | 100 | T | F | if (k < 0) return 0.0;
978 | 50 | T | F | if (k >= max_u) return 1.0;
983 | 100 | T | F | for (int j = 1; j <= n; j++) {
984 | 100 | T | F | for (int i = j; i <= max_u; i++) w[i] += w[i - j];
985 | 100 | T | F | for (int i = max_u; i >= j + m; i--) w[i] -= w[i - j - m];
989 | 100 | T | F | for (int i = 0; i <= k; i++) cum_p += w[i];
1003 | 50 | T | F | if (k < 0) return 0.0;
1004 | 100 | T | F | if (k >= max_v) return 1.0;
1009 | 100 | T | F | for (int i = 1; i <= n; i++) {
1010 | 100 | T | F | for (int j = max_v; j >= i; j--) w[j] += w[j - i];
1014 | 100 | T | F | for (int i = 0; i <= k; i++) cum_p += w[i];
1030 | 50 | T | F | if (n == 0) return 0.0;
1035 | 100 | T | F | while (i < n) {
1037 | 100 | T | F | while (j < n && ri[j].val == ri[i].val) j++;
| 100 | T | F | while (j < n && ri[j].val == ri[i].val) j++;
1039 | 100 | T | F | for (size_t k = i; k < j; k++) ri[k].rank = r;
1041 | 100 | T | F | if (t > 1) { *has_ties = 1; tie_adj += ((double)t * t * t - t); }
1059 | 50 | T | F | if (n == 0) return 1.0;
1060 | 50 | T | F | if (n < 0) return 1.0 / r_pow_di(x, -n);
1062 | 100 | T | F | for (int i = 0; i < n; i++) val *= x;
1070 | 0 | T | F | if(x <= 0.) {
1071 | 0 | T | F | if(lower) p = 0.;
1073 | 0 | T | F | } else if(x < 1.) {
1078 | 0 | T | F | for(k = 1; k < k_max; k += 2) {
1082 | 0 | T | F | if(!lower) p = 1.0 - p;
1087 | 0 | T | F | if(lower) {
1092 | 0 | T | F | while(fabs(old_val - new_val) > tol) {
1105 | 100 | T | F | for(unsigned int i = 0; i < m; i++) {
1106 | 100 | T | F | for(unsigned int j = 0; j < m; j++) {
1108 | 100 | T | F | for(unsigned int k = 0; k < m; k++) s += A[i * m + k] * B[k * m + j];
1115 | 100 | T | F | if(n == 1) {
1116 | 100 | T | F | for(int i = 0; i < m * m; i++) V[i] = A[i];
1124 | 100 | T | F | if((n % 2) == 0) {
1125 | 100 | T | F | for(int i = 0; i < m * m; i++) V[i] = B[i];
1131 | 50 | T | F | if(V[(m / 2) * m + (m / 2)] > 1e140) {
1132 | 0 | T | F | for(int i = 0; i < m * m; i++) V[i] = V[i] * 1e-140;
1146 | 100 | T | F | for(int i = 0; i < m; i++) {
1147 | 100 | T | F | for(int j = 0; j < m; j++) {
1148 | 100 | T | F | if(i - j + 1 < 0) H[i * m + j] = 0;
1152 | 100 | T | F | for(int i = 0; i < m; i++) {
1156 | 50 | T | F | H[(m - 1) * m] += ((2 * h - 1 > 0) ? r_pow_di(2 * h - 1, m) : 0);
1158 | 100 | T | F | for(int i = 0; i < m; i++) {
1159 | 100 | T | F | for(int j = 0; j < m; j++) {
1160 | 100 | T | F | if(i - j + 1 > 0) {
1161 | 100 | T | F | for(int g = 1; g <= i - j + 1; g++) H[i * m + j] /= g;
1170 | 100 | T | F | for(int i = 1; i <= n; i++) {
1172 | 50 | T | F | if(s < 1e-140) {
1191 | 100 | T | F | while(i < nx || j < ny) {
| 50 | T | F | while(i < nx || j < ny) {
1193 | 50 | T | F | if (i < nx && j < ny) val = (x[i] < y[j]) ? x[i] : y[j];
| 100 | T | F | if (i < nx && j < ny) val = (x[i] < y[j]) ? x[i] : y[j];
| 100 | T | F | if (i < nx && j < ny) val = (x[i] < y[j]) ? x[i] : y[j];
1194 | 50 | T | F | else if (i < nx) val = x[i];
1197 | 100 | T | F | while(i < nx && x[i] <= val) i++;
| 100 | T | F | while(i < nx && x[i] <= val) i++;
1198 | 100 | T | F | while(j < ny && y[j] <= val) j++;
| 100 | T | F | while(j < ny && y[j] <= val) j++;
1204 | 100 | T | F | if (diff > max_d_plus) max_d_plus = diff;
1205 | 100 | T | F | if (-diff > max_d_minus) max_d_minus = -diff;
1206 | 100 | T | F | if (fabs(diff) > max_d) max_d = fabs(diff);
1215 | 100 | T | F | if (two_sided) return (fabs(r - s) >= q);
1225 | 100 | T | F | for(unsigned int j = 1; j <= n; j++) {
1226 | 100 | T | F | if(psmirnov_exact_test(q, 0., j / nd, two_sided)) u[j] = 1.;
1229 | 100 | T | F | for(unsigned int i = 1; i <= m; i++) {
1230 | 100 | T | F | if(psmirnov_exact_test(q, i / md, 0., two_sided)) u[0] = 1.;
1231 | 100 | T | F | for(int j = 1; j <= n; j++) {
1232 | 100 | T | F | if(psmirnov_exact_test(q, i / md, j / nd, two_sided)) u[j] = 1.;
1247 | 50 | T | F | if (nu < 1e-7) nu = 1e-7;
1255 | 50 | T | F | if (strict && tside == 2) {
| 0 | T | F | if (strict && tside == 2) {
1276 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
1281 | 50 | T | F | if (arg_idx < items) {
1282 | 100 | T | F | if (SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
1285 | 50 | T | F | } else if (SvPOK(ST(arg_idx))) {
1292 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
1295 | 50 | T | F | if (strEQ(key, "x")) x_sv = val;
1296 | 50 | T | F | else if (strEQ(key, "y")) y_sv = val;
1297 | 50 | T | F | else if (strEQ(key, "exact")) {
1298 | 0 | T | F | if (!SvOK(val)) exact = -1;
1301 | 50 | T | F | else if (strEQ(key, "alternative")) alternative = SvPV_nolen(val);
1305 | 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV) {
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV) {
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV) {
1313 | 100 | T | F | if (!is_two_sided && !is_greater && !is_less) {
| 100 | T | F | if (!is_two_sided && !is_greater && !is_less) {
| 50 | T | F | if (!is_two_sided && !is_greater && !is_less) {
1319 | 50 | T | F | if (nx == 0) croak("Not enough 'x' observations");
1324 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
1326 | 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
1335 | 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
| 100 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
| 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
1341 | 100 | T | F | for (size_t i = 0; i < ny; i++) {
1343 | 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
1348 | 50 | T | F | if (valid_nx < 1 || valid_ny < 1) {
| 50 | T | F | if (valid_nx < 1 || valid_ny < 1) {
1357 | 100 | T | F | if (is_greater) statistic = d_plus;
1358 | 100 | T | F | else if (is_less) statistic = d_minus;
1363 | 50 | T | F | if (exact == 1) use_exact = true;
1364 | 50 | T | F | else if (exact == 0) use_exact = false;
1370 | 100 | T | F | for(size_t i=0; i<valid_nx; i++) comb[i] = x_data[i];
1371 | 100 | T | F | for(size_t i=0; i<valid_ny; i++) comb[valid_nx+i] = y_data[i];
1375 | 100 | T | F | for(size_t i = 1; i < total_n; i++) {
1376 | 50 | T | F | if(comb[i] == comb[i-1]) { has_ties = true; break; }
1379 | 50 | T | F | if (use_exact && has_ties) {
| 50 | T | F | if (use_exact && has_ties) {
1383 | 50 | T | F | if (use_exact) {
1390 | 0 | T | F | if (is_two_sided) {
1399 | 50 | T | F | else if (y_sv && SvPOK(y_sv)) {
| 50 | T | F | else if (y_sv && SvPOK(y_sv)) {
1401 | 50 | T | F | if (strEQ(dist, "pnorm")) {
1404 | 100 | T | F | for(size_t i = 0; i < valid_nx; i++) {
1412 | 50 | T | F | if (diff1 > max_d_plus) max_d_plus = diff1;
1413 | 100 | T | F | if (diff2 > max_d_plus) max_d_plus = diff2;
1414 | 100 | T | F | if (-diff1 > max_d_minus) max_d_minus = -diff1;
1415 | 50 | T | F | if (-diff2 > max_d_minus) max_d_minus = -diff2;
1417 | 100 | T | F | if (fabs(diff1) > max_d) max_d = fabs(diff1);
1418 | 50 | T | F | if (fabs(diff2) > max_d) max_d = fabs(diff2);
1420 | 50 | T | F | if (is_greater) statistic = max_d_plus;
1421 | 50 | T | F | else if (is_less) statistic = max_d_minus;
1423 | 50 | T | F | bool use_exact = (exact == -1) ? (valid_nx < 100) : (exact == 1);
1424 | 50 | T | F | if (use_exact) {
1426 | 50 | T | F | if (is_two_sided) {
1436 | 0 | T | F | if (is_two_sided) p_value = K2l(z, 0, 1e-6);
1448 | 50 | T | F | if (p_value > 1.0) p_value = 1.0;
1449 | 50 | T | F | if (p_value < 0.0) p_value = 0.0;
1470 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
1475 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
1480 | 50 | T | F | if ((items - arg_idx) % 2 != 0) {
1484 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
1487 | 100 | T | F | if (strEQ(key, "x")) x_sv = val;
1488 | 100 | T | F | else if (strEQ(key, "y")) y_sv = val;
1489 | 100 | T | F | else if (strEQ(key, "paired")) paired = SvTRUE(val);
1490 | 50 | T | F | else if (strEQ(key, "correct")) correct = SvTRUE(val);
1491 | 100 | T | F | else if (strEQ(key, "mu")) mu = SvNV(val);
1492 | 50 | T | F | else if (strEQ(key, "exact")) {
1493 | 0 | T | F | if (!SvOK(val)) exact = -1;
1496 | 50 | T | F | else if (strEQ(key, "alternative")) alternative = SvPV_nolen(val);
1500 | 100 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
1504 | 50 | T | F | if (nx == 0) croak("Not enough 'x' observations");
1508 | 100 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
| 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
| 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV) {
1516 | 100 | T | F | if (ny > 0 && !paired) {
| 100 | T | F | if (ny > 0 && !paired) {
1519 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
1521 | 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
1527 | 100 | T | F | for (size_t i = 0; i < ny; i++) {
1529 | 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
1535 | 50 | T | F | if (valid_nx == 0) { Safefree(ri); croak("not enough (non-missing) 'x' observations"); }
1536 | 50 | T | F | if (valid_ny == 0) { Safefree(ri); croak("not enough 'y' observations"); }
1541 | 100 | T | F | for (size_t i = 0; i < total_n; i++) if (ri[i].idx == 1) w_rank_sum += ri[i].rank;
| 100 | T | F | for (size_t i = 0; i < total_n; i++) if (ri[i].idx == 1) w_rank_sum += ri[i].rank;
1544 | 50 | T | F | if (exact == 1) use_exact = true;
1545 | 50 | T | F | else if (exact == 0) use_exact = false;
1546 | 50 | T | F | else use_exact = (valid_nx < 50 && valid_ny < 50 && !has_ties);
| 50 | T | F | else use_exact = (valid_nx < 50 && valid_ny < 50 && !has_ties);
| 100 | T | F | else use_exact = (valid_nx < 50 && valid_ny < 50 && !has_ties);
1548 | 100 | T | F | if (use_exact && has_ties) {
| 50 | T | F | if (use_exact && has_ties) {
1552 | 100 | T | F | if (use_exact) {
1557 | 100 | T | F | if (strcmp(alternative, "less") == 0) p_value = p_less;
1558 | 50 | T | F | else if (strcmp(alternative, "greater") == 0) p_value = p_greater;
1560 | 0 | T | F | double p = (p_less < p_greater) ? p_less : p_greater;
1564 | 50 | T | F | method_desc = correct ? "Wilcoxon rank sum test with continuity correction" : "Wilcoxon rank sum test";
1570 | 50 | T | F | if (correct) {
1571 | 50 | T | F | if (strcmp(alternative, "two.sided") == 0) CORRECTION = (z > 0 ? 0.5 : -0.5);
| 100 | T | F | if (strcmp(alternative, "two.sided") == 0) CORRECTION = (z > 0 ? 0.5 : -0.5);
1572 | 0 | T | F | else if (strcmp(alternative, "greater") == 0) CORRECTION = 0.5;
1573 | 0 | T | F | else if (strcmp(alternative, "less") == 0) CORRECTION = -0.5;
1577 | 50 | T | F | if (strcmp(alternative, "less") == 0) p_value = approx_pnorm(z);
1578 | 50 | T | F | else if (strcmp(alternative, "greater") == 0) p_value = 1.0 - approx_pnorm(z);
1583 | 100 | T | F | if (paired && (!y_av || nx != ny)) croak("'x' and 'y' must have the same length for paired test");
| 50 | T | F | if (paired && (!y_av || nx != ny)) croak("'x' and 'y' must have the same length for paired test");
| 100 | T | F | if (paired && (!y_av || nx != ny)) croak("'x' and 'y' must have the same length for paired test");
1587 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
1589 | 50 | T | F | if (!x_el || !SvOK(*x_el) || !looks_like_number(*x_el)) continue;
| 50 | T | F | if (!x_el || !SvOK(*x_el) || !looks_like_number(*x_el)) continue;
| 50 | T | F | if (!x_el || !SvOK(*x_el) || !looks_like_number(*x_el)) continue;
1592 | 100 | T | F | if (paired) {
1594 | 50 | T | F | if (!y_el || !SvOK(*y_el) || !looks_like_number(*y_el)) continue;
| 50 | T | F | if (!y_el || !SvOK(*y_el) || !looks_like_number(*y_el)) continue;
| 50 | T | F | if (!y_el || !SvOK(*y_el) || !looks_like_number(*y_el)) continue;
1597 | 50 | T | F | if (d == 0.0) has_zeroes = true; // Drop exact zeroes
1601 | 50 | T | F | if (d == 0.0) has_zeroes = true;
1605 | 50 | T | F | if (n_nz == 0) {
1610 | 100 | T | F | for (size_t i = 0; i < n_nz; i++) {
1617 | 100 | T | F | for (size_t i = 0; i < n_nz; i++) {
1618 | 100 | T | F | if (ri[i].idx) statistic += ri[i].rank;
1620 | 50 | T | F | if (exact == 1) use_exact = true;
1621 | 50 | T | F | else if (exact == 0) use_exact = false;
1622 | 50 | T | F | else use_exact = (n_nz < 50 && !has_ties);
| 50 | T | F | else use_exact = (n_nz < 50 && !has_ties);
1623 | 50 | T | F | if (use_exact && has_ties) {
| 50 | T | F | if (use_exact && has_ties) {
1627 | 50 | T | F | if (use_exact && has_zeroes) {
| 50 | T | F | if (use_exact && has_zeroes) {
1631 | 50 | T | F | if (use_exact) {
1636 | 50 | T | F | if (strcmp(alternative, "less") == 0) p_value = p_less;
1637 | 50 | T | F | else if (strcmp(alternative, "greater") == 0) p_value = p_greater;
1639 | 50 | T | F | double p = (p_less < p_greater) ? p_less : p_greater;
1643 | 0 | T | F | method_desc = correct ? "Wilcoxon signed rank test with continuity correction" : "Wilcoxon signed rank test";
1648 | 0 | T | F | if (correct) {
1649 | 0 | T | F | if (strcmp(alternative, "two.sided") == 0) CORRECTION = (z > 0 ? 0.5 : -0.5);
| 0 | T | F | if (strcmp(alternative, "two.sided") == 0) CORRECTION = (z > 0 ? 0.5 : -0.5);
1650 | 0 | T | F | else if (strcmp(alternative, "greater") == 0) CORRECTION = 0.5;
1651 | 0 | T | F | else if (strcmp(alternative, "less") == 0) CORRECTION = -0.5;
1655 | 0 | T | F | if (strcmp(alternative, "less") == 0) p_value = approx_pnorm(z);
1656 | 0 | T | F | else if (strcmp(alternative, "greater") == 0) p_value = 1.0 - approx_pnorm(z);
1661 | 50 | T | F | if (p_value > 1.0) p_value = 1.0;
1677 | 50 | T | F | int r = av_top_index(obs_av) + 1, c = 0;
1680 | 50 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
| 100 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
| 50 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
1683 | 50 | T | F | c = av_top_index(first_row) + 1;
1691 | 100 | T | F | int yates = (is_2d && r == 2 && c == 2) ? 1 : 0;
| 50 | T | F | int yates = (is_2d && r == 2 && c == 2) ? 1 : 0;
| 100 | T | F | int yates = (is_2d && r == 2 && c == 2) ? 1 : 0;
1694 | 100 | T | F | if (is_2d) {
1697 | 100 | T | F | for(unsigned int i=0; i<r; i++) row_sum[i] = 0.0;
1698 | 100 | T | F | for(unsigned int j=0; j<c; j++) col_sum[j] = 0.0;
1699 | 100 | T | F | for (unsigned int i = 0; i < r; i++) {
1702 | 100 | T | F | for (unsigned int j = 0; j < c; j++) {
1710 | 100 | T | F | for (unsigned int i = 0; i < r; i++) {
1714 | 100 | T | F | for (unsigned int j = 0; j < c; j++) {
1719 | 100 | T | F | if (yates) {
1722 | 50 | T | F | double y_corr = (abs_diff > 0.5) ? 0.5 : abs_diff;
1734 | 100 | T | F | for (unsigned int j = 0; j < c; j++) {
1739 | 100 | T | F | for (unsigned int j = 0; j < c; j++) {
1753 | 100 | T | F | if (is_2d) {
1754 | 100 | T | F | if (yates) {
1777 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx))) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx))) {
1779 | 100 | T | F | if (type == SVt_PVHV || type == SVt_PVAV) {
| 50 | T | F | if (type == SVt_PVHV || type == SVt_PVAV) {
1784 | 50 | T | F | if (arg_idx < items) {
1794 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
1795 | 50 | T | F | if (arg_idx + 1 >= items) croak("write_table: Odd number of arguments passed");
1798 | 50 | T | F | if (strEQ(key, "data")) data_sv = val;
1799 | 100 | T | F | else if (strEQ(key, "col.names")) col_names_sv = val;
1800 | 50 | T | F | else if (strEQ(key, "file")) file_sv = val;
1801 | 100 | T | F | else if (strEQ(key, "row.names")) row_names_sv = val;
1802 | 50 | T | F | else if (strEQ(key, "sep")) sep = SvPV_nolen(val);
1806 | 50 | T | F | if (!data_sv || !SvROK(data_sv)) {
| 50 | T | F | if (!data_sv || !SvROK(data_sv)) {
1810 | 100 | T | F | if (SvTYPE(data_ref) != SVt_PVHV && SvTYPE(data_ref) != SVt_PVAV) {
| 50 | T | F | if (SvTYPE(data_ref) != SVt_PVHV && SvTYPE(data_ref) != SVt_PVAV) {
1814 | 50 | T | F | if (!file_sv || !SvOK(file_sv)) croak("write_table: file name missing\n");
| 50 | T | F | if (!file_sv || !SvOK(file_sv)) croak("write_table: file name missing\n");
1817 | 100 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
| 50 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
1818 | 100 | T | F | if (!SvROK(col_names_sv) || SvTYPE(SvRV(col_names_sv)) != SVt_PVAV) {
| 50 | T | F | if (!SvROK(col_names_sv) || SvTYPE(SvRV(col_names_sv)) != SVt_PVAV) {
1827 | 100 | T | F | if (SvTYPE(data_ref) == SVt_PVHV) {
1829 | 50 | T | F | if (hv_iterinit(hv) == 0) XSRETURN_EMPTY;
1833 | 50 | T | F | if (!first_val || !SvROK(first_val)) {
| 50 | T | F | if (!first_val || !SvROK(first_val)) {
1837 | 100 | T | F | if (first_type != SVt_PVHV && first_type != SVt_PVAV) {
| 50 | T | F | if (first_type != SVt_PVHV && first_type != SVt_PVAV) {
1845 | 100 | T | F | while ((entry = hv_iternext(hv))) {
1847 | 50 | T | F | if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != first_type) {
| 50 | T | F | if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != first_type) {
| 50 | T | F | if (!val || !SvROK(val) || SvTYPE(SvRV(val)) != first_type) {
1848 | 0 | T | F | croak("write_table: Mixed data types detected. Ensure all values are %s references.\n", is_hoh ? "HASH" : "ARRAY");
1852 | 100 | T | F | if (is_hoh) {
1855 | 100 | T | F | while ((entry = hv_iternext(hv))) {
1861 | 50 | T | F | if (av_len(av) < 0) XSRETURN_EMPTY;
1863 | 50 | T | F | if (!first_ptr || !*first_ptr || !SvROK(*first_ptr) || SvTYPE(SvRV(*first_ptr)) != SVt_PVHV) {
| 50 | T | F | if (!first_ptr || !*first_ptr || !SvROK(*first_ptr) || SvTYPE(SvRV(*first_ptr)) != SVt_PVHV) {
| 50 | T | F | if (!first_ptr || !*first_ptr || !SvROK(*first_ptr) || SvTYPE(SvRV(*first_ptr)) != SVt_PVHV) {
| 50 | T | F | if (!first_ptr || !*first_ptr || !SvROK(*first_ptr) || SvTYPE(SvRV(*first_ptr)) != SVt_PVHV) {
1867 | 100 | T | F | for (size_t i = 0; i <= av_len(av); i++) {
1869 | 50 | T | F | if (!ptr || !*ptr || !SvROK(*ptr) || SvTYPE(SvRV(*ptr)) != SVt_PVHV) {
| 50 | T | F | if (!ptr || !*ptr || !SvROK(*ptr) || SvTYPE(SvRV(*ptr)) != SVt_PVHV) {
| 50 | T | F | if (!ptr || !*ptr || !SvROK(*ptr) || SvTYPE(SvRV(*ptr)) != SVt_PVHV) {
| 50 | T | F | if (!ptr || !*ptr || !SvROK(*ptr) || SvTYPE(SvRV(*ptr)) != SVt_PVHV) {
1877 | 50 | T | F | if (!fh) croak("write_table: Could not open '%s' for writing", file);
1880 | 50 | T | F | int inc_rownames = (row_names_sv && SvTRUE(row_names_sv)) ? 1 : 0;
| 100 | T | F | int inc_rownames = (row_names_sv && SvTRUE(row_names_sv)) ? 1 : 0;
1884 | 100 | T | F | if (is_hoh) {
1885 | 100 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
| 50 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
1887 | 100 | T | F | for(size_t i=0; i<=av_len(c_av); i++) {
1889 | 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
| 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
1895 | 100 | T | F | while((entry = hv_iternext((HV*)data_ref))) {
1899 | 100 | T | F | while((inner_entry = hv_iternext(inner))) {
1905 | 100 | T | F | for(unsigned i=0; i<num_cols; i++) {
1910 | 100 | T | F | for(unsigned i=0; i<num_cols; i++) av_push(headers_av, newSVpv(col_array[i], 0));
1918 | 50 | T | F | if (inc_rownames) header_row[h_idx++] = "";
1919 | 100 | T | F | for(unsigned short int i=0; i<num_headers; i++) {
1921 | 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
1928 | 100 | T | F | for(size_t i=0; i<num_rows; i++) {
1936 | 100 | T | F | for(size_t i=0; i<num_rows; i++) {
1938 | 50 | T | F | if (inc_rownames) row_data[d_idx++] = row_array[i];
1941 | 50 | T | F | HV *restrict inner_hv = inner_hv_ptr ? (HV*)SvRV(*inner_hv_ptr) : NULL;
1943 | 100 | T | F | for(size_t j=0; j<num_headers; j++) {
1945 | 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
1946 | 50 | T | F | SV **restrict cell_ptr = inner_hv ? hv_fetch(inner_hv, col_name, strlen(col_name), 0) : NULL;
1947 | 100 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
| 100 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
1948 | 100 | T | F | if (SvROK(*cell_ptr)) {
1952 | 50 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
1953 | 50 | T | F | if (rows_av) SvREFCNT_dec(rows_av);
1965 | 100 | T | F | } else if (is_hoa) { // ----- Hash of Arrays -----
1970 | 100 | T | F | while((entry = hv_iternext(data_hv))) {
1973 | 100 | T | F | if (len > max_rows) max_rows = len;
1976 | 100 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
| 50 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
1978 | 100 | T | F | for(size_t i=0; i<=av_len(c_av); i++) {
1980 | 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
| 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
1985 | 100 | T | F | for(unsigned int i=0; i<num_cols; i++) {
1990 | 100 | T | F | for(unsigned i=0; i<num_cols; i++) av_push(headers_av, newSVpv(col_array[i], 0));
1993 | 50 | T | F | if (av_len(headers_av) < 0) croak("Could not get headers in write_table");
1994 | 100 | T | F | if (inc_rownames && contains_nondigit(row_names_sv)) {
| 50 | T | F | if (inc_rownames && contains_nondigit(row_names_sv)) {
1998 | 0 | T | F | for(size_t i=0; i<=av_len(headers_av); i++) {
2000 | 0 | T | F | if (!h_ptr || !*h_ptr) continue;
| 0 | T | F | if (!h_ptr || !*h_ptr) continue;
2002 | 0 | T | F | if (strcmp(SvPV_nolen(h_sv), rownames_col) != 0) {
2012 | 100 | T | F | if (inc_rownames) header_row[h_idx++] = "";
2013 | 100 | T | F | for(size_t i=0; i<num_headers; i++) {
2015 | 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
2020 | 100 | T | F | for(size_t i=0; i<max_rows; i++) {
2022 | 100 | T | F | if (inc_rownames) {
2023 | 50 | T | F | if (rownames_col) {
2025 | 0 | T | F | if (rn_arr_ptr && SvROK(*rn_arr_ptr)) {
| 0 | T | F | if (rn_arr_ptr && SvROK(*rn_arr_ptr)) {
2028 | 0 | T | F | if (rn_val_ptr && SvOK(*rn_val_ptr)) {
| 0 | T | F | if (rn_val_ptr && SvOK(*rn_val_ptr)) {
2029 | 0 | T | F | if (SvROK(*rn_val_ptr)) {
2032 | 0 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
2048 | 100 | T | F | for(size_t j=0; j<num_headers; j++) {
2050 | 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
2052 | 50 | T | F | if (arr_ptr && SvROK(*arr_ptr)) {
| 50 | T | F | if (arr_ptr && SvROK(*arr_ptr)) {
2055 | 100 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
| 100 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
2056 | 50 | T | F | if (SvROK(*cell_ptr)) {
2059 | 0 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
2071 | 100 | T | F | if (inc_rownames && !rownames_col) safefree((char*)row_data[0]);
| 50 | T | F | if (inc_rownames && !rownames_col) safefree((char*)row_data[0]);
2074 | 50 | T | F | } else if (is_aoh) {// ----- Array of Hashes -----
2077 | 100 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
| 50 | T | F | if (col_names_sv && SvOK(col_names_sv)) {
2079 | 100 | T | F | for(size_t i=0; i<=av_len(c_av); i++) {
2081 | 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
| 50 | T | F | if(c && SvOK(*c)) av_push(headers_av, newSVsv(*c));
2085 | 100 | T | F | for(size_t i=0; i<num_rows; i++) {
2087 | 50 | T | F | if (row_ptr && SvROK(*row_ptr)) {
| 50 | T | F | if (row_ptr && SvROK(*row_ptr)) {
2091 | 100 | T | F | while((entry = hv_iternext(row_hv))) {
2098 | 100 | T | F | for(unsigned int i=0; i<num_cols; i++) {
2103 | 100 | T | F | for(unsigned int i=0; i<num_cols; i++) av_push(headers_av, newSVpv(col_array[i], 0));
2107 | 100 | T | F | if (inc_rownames && contains_nondigit(row_names_sv)) {
| 50 | T | F | if (inc_rownames && contains_nondigit(row_names_sv)) {
2110 | 0 | T | F | for(size_t i=0; i<=av_len(headers_av); i++) {
2112 | 0 | T | F | if (!h_ptr || !*h_ptr) continue;
| 0 | T | F | if (!h_ptr || !*h_ptr) continue;
2114 | 0 | T | F | if (strcmp(SvPV_nolen(h_sv), rownames_col) != 0) {
2124 | 100 | T | F | if (inc_rownames) header_row[h_idx++] = "";
2125 | 100 | T | F | for(size_t i=0; i<num_headers; i++) {
2127 | 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | header_row[h_idx++] = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
2132 | 100 | T | F | for(size_t i=0; i<num_rows; i++) {
2135 | 50 | T | F | HV *restrict row_hv = (row_ptr && SvROK(*row_ptr)) ? (HV*)SvRV(*row_ptr) : NULL;
| 50 | T | F | HV *restrict row_hv = (row_ptr && SvROK(*row_ptr)) ? (HV*)SvRV(*row_ptr) : NULL;
2136 | 100 | T | F | if (inc_rownames) {
2137 | 50 | T | F | if (rownames_col) {
2138 | 0 | T | F | SV **restrict rn_val_ptr = row_hv ? hv_fetch(row_hv, rownames_col, strlen(rownames_col), 0) : NULL;
2139 | 0 | T | F | if (rn_val_ptr && SvOK(*rn_val_ptr)) {
| 0 | T | F | if (rn_val_ptr && SvOK(*rn_val_ptr)) {
2140 | 0 | T | F | if (SvROK(*rn_val_ptr)) {
2143 | 0 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
2157 | 100 | T | F | for(size_t j=0; j<num_headers; j++) {
2159 | 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
| 50 | T | F | const char *restrict col_name = (h_ptr && SvOK(*h_ptr)) ? SvPV_nolen(*h_ptr) : "";
2160 | 50 | T | F | SV **restrict cell_ptr = row_hv ? hv_fetch(row_hv, col_name, strlen(col_name), 0) : NULL;
2161 | 100 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
| 50 | T | F | if (cell_ptr && SvOK(*cell_ptr)) {
2162 | 50 | T | F | if (SvROK(*cell_ptr)) {
2165 | 0 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
2174 | 100 | T | F | if (inc_rownames && !rownames_col) safefree((char*)row_data[0]);
| 50 | T | F | if (inc_rownames && !rownames_col) safefree((char*)row_data[0]);
2178 | 50 | T | F | if (headers_av) SvREFCNT_dec(headers_av);
2179 | 100 | T | F | if (rows_av) SvREFCNT_dec(rows_av);
2196 | 50 | T | F | if (SvOK(callback) && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) {
| 50 | T | F | if (SvOK(callback) && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) {
| 50 | T | F | if (SvOK(callback) && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) {
2201 | 50 | T | F | sep_len = sep_str ? strlen(sep_str) : 0;
2202 | 50 | T | F | comment_len = comment_str ? strlen(comment_str) : 0;
2205 | 50 | T | F | if (!fp) {
2210 | 100 | T | F | while (sv_gets(line_sv, fp, 0) != NULL) {
2214 | 50 | T | F | if (len > 0 && line[len-1] == '\n') {
| 100 | T | F | if (len > 0 && line[len-1] == '\n') {
2216 | 50 | T | F | if (len > 0 && line[len-1] == '\r') {
| 100 | T | F | if (len > 0 && line[len-1] == '\r') {
2220 | 100 | T | F | if (!in_quotes) {
2223 | 50 | T | F | for (size_t i = 0; i < len; i++) {
2224 | 50 | T | F | if (line[i] != ' ' && line[i] != '\t') { is_empty = 0; break; }
| 100 | T | F | if (line[i] != ' ' && line[i] != '\t') { is_empty = 0; break; }
2226 | 50 | T | F | if (is_empty) continue;
2229 | 50 | T | F | if (comment_len > 0 && len >= comment_len && strncmp(line, comment_str, comment_len) == 0) {
| 50 | T | F | if (comment_len > 0 && len >= comment_len && strncmp(line, comment_str, comment_len) == 0) {
| 50 | T | F | if (comment_len > 0 && len >= comment_len && strncmp(line, comment_str, comment_len) == 0) {
2234 | 100 | T | F | for (size_t i = 0; i < len; i++) {
2236 | 100 | T | F | if (ch == '\r') continue;
2237 | 100 | T | F | if (ch == '"') {
2238 | 100 | T | F | if (in_quotes && (i + 1 < len) && line[i+1] == '"') {
| 100 | T | F | if (in_quotes && (i + 1 < len) && line[i+1] == '"') {
| 100 | T | F | if (in_quotes && (i + 1 < len) && line[i+1] == '"') {
2241 | 100 | T | F | } else if (in_quotes) {
2244 | 100 | T | F | } else if (!post_quote) {
2247 | 100 | T | F | } else if (!in_quotes && sep_len > 0 && (len - i) >= sep_len && strncmp(line + i, sep_str, sep_len) == 0) {
| 50 | T | F | } else if (!in_quotes && sep_len > 0 && (len - i) >= sep_len && strncmp(line + i, sep_str, sep_len) == 0) {
| 50 | T | F | } else if (!in_quotes && sep_len > 0 && (len - i) >= sep_len && strncmp(line + i, sep_str, sep_len) == 0) {
| 100 | T | F | } else if (!in_quotes && sep_len > 0 && (len - i) >= sep_len && strncmp(line + i, sep_str, sep_len) == 0) {
2256 | 100 | T | F | if (in_quotes) {
2265 | 50 | T | F | if (use_cb) {
2269 | 50 | T | F | PUSHMARK(SP);
2270 | 50 | T | F | XPUSHs(sv_2mortal(newRV_inc((SV*)current_row)));
2273 | 50 | T | F | FREETMPS;
2285 | 100 | T | F | if (in_quotes) {
2287 | 50 | T | F | if (use_cb) {
2291 | 50 | T | F | PUSHMARK(SP);
2292 | 50 | T | F | XPUSHs(sv_2mortal(newRV_inc((SV*)current_row)));
2295 | 50 | T | F | FREETMPS;
2306 | 50 | T | F | if (use_cb) {
2318 | 50 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV) {
| 50 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV) {
2321 | 50 | T | F | if (!SvROK(y_sv) || SvTYPE(SvRV(y_sv)) != SVt_PVAV) {
| 50 | T | F | if (!SvROK(y_sv) || SvTYPE(SvRV(y_sv)) != SVt_PVAV) {
2326 | 100 | T | F | if (strcmp(method, "pearson") != 0 &&
2327 | 100 | T | F | strcmp(method, "spearman") != 0 &&
2328 | 50 | T | F | strcmp(method, "kendall") != 0) {
2337 | 50 | T | F | if (nx != ny) {
2348 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
2353 | 50 | T | F | double xv = (x_tv && SvOK(*x_tv) && looks_like_number(*x_tv)) ? SvNV(*x_tv) : NAN;
| 50 | T | F | double xv = (x_tv && SvOK(*x_tv) && looks_like_number(*x_tv)) ? SvNV(*x_tv) : NAN;
| 50 | T | F | double xv = (x_tv && SvOK(*x_tv) && looks_like_number(*x_tv)) ? SvNV(*x_tv) : NAN;
2354 | 50 | T | F | double yv = (y_tv && SvOK(*y_tv) && looks_like_number(*y_tv)) ? SvNV(*y_tv) : NAN;
| 50 | T | F | double yv = (y_tv && SvOK(*y_tv) && looks_like_number(*y_tv)) ? SvNV(*y_tv) : NAN;
| 50 | T | F | double yv = (y_tv && SvOK(*y_tv) && looks_like_number(*y_tv)) ? SvNV(*y_tv) : NAN;
2357 | 50 | T | F | if (!isnan(xv) && !isnan(yv)) {
| 50 | T | F | if (!isnan(xv) && !isnan(yv)) {
2365 | 50 | T | F | if (n < 2) {
2373 | 100 | T | F | if (strcmp(method, "kendall") == 0) {
2375 | 100 | T | F | for (size_t i = 0; i < n; i++) {
2376 | 100 | T | F | for (size_t j = 0; j < n; j++) {
2385 | 100 | T | F | if (strcmp(method, "spearman") == 0) {
2394 | 100 | T | F | for (size_t i = 0; i < n; i++) {
2406 | 100 | T | F | for (size_t i = 0; i < n; i++) {
2462 | 50 | T | F | if (items % 2 != 0) croak("Usage: glm(formula => 'am ~ wt + hp', data => \\%mtcars)");
2464 | 100 | T | F | for (unsigned short i_arg = 0; i_arg < items; i_arg += 2) {
2467 | 100 | T | F | if (strEQ(key, "formula")) formula = SvPV_nolen(val);
2468 | 100 | T | F | else if (strEQ(key, "data")) data_sv = val;
2469 | 50 | T | F | else if (strEQ(key, "family")) family_str = SvPV_nolen(val);
2472 | 50 | T | F | if (!formula) croak("glm: formula is required");
2473 | 50 | T | F | if (!data_sv || !SvROK(data_sv)) croak("glm: data is required and must be a reference");
| 50 | T | F | if (!data_sv || !SvROK(data_sv)) croak("glm: data is required and must be a reference");
2477 | 100 | T | F | if (!is_binomial && !is_gaussian) croak("glm: unsupported family '%s'", family_str);
| 50 | T | F | if (!is_binomial && !is_gaussian) croak("glm: unsupported family '%s'", family_str);
2485 | 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 50 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
2489 | 50 | T | F | if (!tilde) croak("glm: invalid formula, missing '~'");
2493 | 50 | T | F | if (strstr(rhs, "-1")) has_intercept = false;
2494 | 50 | T | F | if (has_intercept) terms[num_terms++] = savepv("Intercept");
2497 | 100 | T | F | while (chunk != NULL) {
2498 | 50 | T | F | if (num_terms >= term_cap - 3) {
2502 | 50 | T | F | if (strcmp(chunk, "1") == 0 || strcmp(chunk, "-1") == 0) {
| 50 | T | F | if (strcmp(chunk, "1") == 0 || strcmp(chunk, "-1") == 0) {
2507 | 50 | T | F | if (star) {
2510 | 0 | T | F | char *restrict c_l = strchr(left, '^'); if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
| 0 | T | F | char *restrict c_l = strchr(left, '^'); if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
2511 | 0 | T | F | char *restrict c_r = strchr(right, '^'); if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
| 0 | T | F | char *restrict c_r = strchr(right, '^'); if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
2520 | 50 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
| 0 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
2526 | 100 | T | F | for (i = 0; i < num_terms; i++) {
2528 | 100 | T | F | for (size_t j = 0; j < num_uniq; j++) {
2529 | 50 | T | F | if (strcmp(terms[i], uniq_terms[j]) == 0) { found = true; break; }
2531 | 50 | T | F | if (!found) uniq_terms[num_uniq++] = savepv(terms[i]);
2537 | 50 | T | F | if (SvTYPE(ref) == SVt_PVHV) {
2539 | 50 | T | F | if (hv_iterinit(hv) == 0) croak("glm: Data hash is empty");
2541 | 50 | T | F | if (entry) {
2543 | 50 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
| 100 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
2546 | 50 | T | F | Newx(row_names, n, char*);
2547 | 100 | T | F | for(i = 0; i < n; i++) {
2551 | 50 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
| 50 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
2553 | 50 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
| 50 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
2555 | 100 | T | F | while ((entry = hv_iternext(hv))) {
2563 | 0 | T | F | } else if (SvTYPE(ref) == SVt_PVAV) {
2566 | 0 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
| 0 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
2567 | 0 | T | F | for (i = 0; i < n; i++) {
2569 | 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
2574 | 0 | T | F | for (size_t k = 0; k < i; k++) Safefree(row_names[k]);
2582 | 100 | T | F | for (size_t j = 0; j < p; j++) {
2583 | 50 | T | F | if (p_exp + 32 >= exp_cap) {
2588 | 100 | T | F | if (strcmp(uniq_terms[j], "Intercept") == 0) {
2591 | 100 | T | F | if (is_column_categorical(data_hoa, row_hashes, n, uniq_terms[j])) {
2593 | 50 | T | F | Newx(levels, levels_cap, char*);
2594 | 100 | T | F | for (i = 0; i < n; i++) {
2596 | 50 | T | F | if (str_val) {
2598 | 100 | T | F | for (size_t l = 0; l < num_levels; l++) {
2599 | 100 | T | F | if (strcmp(levels[l], str_val) == 0) { found = true; break; }
2601 | 100 | T | F | if (!found) {
2602 | 50 | T | F | if (num_levels >= levels_cap) { levels_cap *= 2; Renew(levels, levels_cap, char*); }
| 0 | T | F | if (num_levels >= levels_cap) { levels_cap *= 2; Renew(levels, levels_cap, char*); }
2608 | 50 | T | F | if (num_levels > 0) {
2609 | 100 | T | F | for (size_t l1 = 0; l1 < num_levels - 1; l1++) {
2610 | 100 | T | F | for (size_t l2 = l1 + 1; l2 < num_levels; l2++) {
2611 | 50 | T | F | if (strcmp(levels[l1], levels[l2]) > 0) {
2616 | 100 | T | F | for (size_t l = 1; l < num_levels; l++) {
2617 | 50 | T | F | if (p_exp >= exp_cap) {
2628 | 100 | T | F | for (size_t l = 0; l < num_levels; l++) Safefree(levels[l]);
2639 | 50 | T | F | Newx(X, n * p, double); Newx(Y, n, double);
| 50 | T | F | Newx(X, n * p, double); Newx(Y, n, double);
2640 | 50 | T | F | Newx(valid_row_names, n, char*);
2643 | 100 | T | F | for (size_t i = 0; i < n; i++) {
2645 | 50 | T | F | if (isnan(y_val)) { Safefree(row_names[i]); continue; }
2649 | 100 | T | F | for (size_t j = 0; j < p; j++) {
2650 | 100 | T | F | if (strcmp(exp_terms[j], "Intercept") == 0) {
2652 | 100 | T | F | } else if (is_dummy[j]) {
2654 | 50 | T | F | if (str_val) {
2655 | 100 | T | F | row_x[j] = (strcmp(str_val, dummy_level[j]) == 0) ? 1.0 : 0.0;
2660 | 50 | T | F | if (isnan(row_x[j])) { row_ok = false; break; }
2663 | 50 | T | F | if (!row_ok) { Safefree(row_names[i]); Safefree(row_x); continue; }
2665 | 100 | T | F | for (size_t j = 0; j < p; j++) X[valid_n * p + j] = row_x[j];
2671 | 50 | T | F | if (valid_n <= p) {
2672 | 0 | T | F | Safefree(X); Safefree(Y); Safefree(valid_row_names); if (row_hashes) Safefree(row_hashes);
2681 | 100 | T | F | for (i = 0; i < p; i++) { beta[i] = 0.0; beta_old[i] = 0.0; }
2684 | 100 | T | F | for (i = 0; i < valid_n; i++) sum_y += Y[i];
2686 | 100 | T | F | for (i = 0; i < valid_n; i++) {
2687 | 100 | T | F | if (is_binomial) {
2688 | 50 | T | F | if (Y[i] < 0.0 || Y[i] > 1.0) croak("glm: binomial family requires response between 0 and 1");
| 50 | T | F | if (Y[i] < 0.0 || Y[i] > 1.0) croak("glm: binomial family requires response between 0 and 1");
2692 | 100 | T | F | if (Y[i] == 0.0) dev = -2.0 * log(1.0 - mu[i]);
2693 | 50 | T | F | else if (Y[i] == 1.0) dev = -2.0 * log(mu[i]);
2702 | 50 | T | F | for (iter = 1; iter <= max_iter; iter++) {
2703 | 100 | T | F | for (i = 0; i < valid_n; i++) {
2704 | 100 | T | F | if (is_binomial) {
2707 | 50 | T | F | if (varmu < 1e-10) varmu = 1e-10;
2716 | 100 | T | F | for (i = 0; i < p; i++) { XtWZ[i] = 0.0; for (size_t j = 0; j < p; j++) XtWX[i * p + j] = 0.0; }
| 100 | T | F | for (i = 0; i < p; i++) { XtWZ[i] = 0.0; for (size_t j = 0; j < p; j++) XtWX[i * p + j] = 0.0; }
2717 | 100 | T | F | for (size_t k = 0; k < valid_n; k++) {
2719 | 100 | T | F | for (i = 0; i < p; i++) {
2722 | 100 | T | F | for (size_t j = 0; j < p; j++) XtWX[i * p + j] += xw * X[k * p + j];
2726 | 100 | T | F | for (i = 0; i < p; i++) {
2727 | 50 | T | F | if (aliased[i]) { beta[i] = NAN; } else {
2729 | 50 | T | F | for (size_t j = 0; j < p; j++) if (!aliased[j]) sum += XtWX[i * p + j] * XtWZ[j];
| 100 | T | F | for (size_t j = 0; j < p; j++) if (!aliased[j]) sum += XtWX[i * p + j] * XtWZ[j];
2735 | 100 | T | F | for (unsigned short int half = 0; half < 10; half++) {
2737 | 100 | T | F | for (i = 0; i < valid_n; i++) {
2739 | 50 | T | F | for (size_t j = 0; j < p; j++) if (!aliased[j]) linear_pred += X[i * p + j] * beta[j];
| 100 | T | F | for (size_t j = 0; j < p; j++) if (!aliased[j]) linear_pred += X[i * p + j] * beta[j];
2741 | 100 | T | F | if (is_binomial) {
2744 | 50 | T | F | if (mu[i] < 10 * DBL_EPSILON) mu[i] = 10 * DBL_EPSILON;
2745 | 50 | T | F | if (mu[i] > 1.0 - 10 * DBL_EPSILON) mu[i] = 1.0 - 10 * DBL_EPSILON;
2748 | 100 | T | F | if (Y[i] == 0.0) dev = -2.0 * log(1.0 - mu[i]);
2749 | 50 | T | F | else if (Y[i] == 1.0) dev = -2.0 * log(mu[i]);
2759 | 100 | T | F | if (!is_binomial || deviance_new <= deviance_old + 1e-7 || !isfinite(deviance_new)) {
| 100 | T | F | if (!is_binomial || deviance_new <= deviance_old + 1e-7 || !isfinite(deviance_new)) {
| 50 | T | F | if (!is_binomial || deviance_new <= deviance_old + 1e-7 || !isfinite(deviance_new)) {
2764 | 100 | T | F | for (size_t j = 0; j < p; j++) beta[j] = (beta[j] + beta_old[j]) / 2.0;
2767 | 100 | T | F | if (fabs(deviance_new - deviance_old) / (0.1 + fabs(deviance_new)) < epsilon) {
2771 | 100 | T | F | for (size_t j = 0; j < p; j++) beta_old[j] = beta[j];
2774 | 100 | T | F | for (i = 0; i < p; i++) { for (size_t j = 0; j < p; j++) XtWX[i * p + j] = 0.0; }
| 100 | T | F | for (i = 0; i < p; i++) { for (size_t j = 0; j < p; j++) XtWX[i * p + j] = 0.0; }
2775 | 100 | T | F | for (size_t k = 0; k < valid_n; k++) {
2776 | 100 | T | F | double w = is_binomial ? (mu[k] * (1.0 - mu[k])) : 1.0;
2777 | 50 | T | F | if (w < 1e-10) w = 1e-10;
2778 | 100 | T | F | for (i = 0; i < p; i++) {
2780 | 100 | T | F | for (size_t j = 0; j < p; j++) XtWX[i * p + j] += xw * X[k * p + j];
2786 | 100 | T | F | for (i = 0; i < valid_n; i++) {
2787 | 100 | T | F | if (is_binomial) {
2788 | 100 | T | F | if (Y[i] == 0.0) null_dev += -2.0 * log(1.0 - wtdmu);
2789 | 50 | T | F | else if (Y[i] == 1.0) null_dev += -2.0 * log(wtdmu);
2797 | 100 | T | F | if (is_gaussian) {
2800 | 50 | T | F | } else if (is_binomial) {
2806 | 100 | T | F | dispersion = is_binomial ? 1.0 : ((df_res > 0) ? (deviance_new / df_res) : NAN);
| 50 | T | F | dispersion = is_binomial ? 1.0 : ((df_res > 0) ? (deviance_new / df_res) : NAN);
2807 | 100 | T | F | for (size_t i = 0; i < valid_n; i++) {
2809 | 100 | T | F | if (is_binomial) {
2812 | 100 | T | F | if (Y[i] == 0.0) d_res = sqrt(-2.0 * log(1.0 - mu[i]));
2813 | 50 | T | F | else if (Y[i] == 1.0) d_res = sqrt(-2.0 * log(mu[i]));
2815 | 100 | T | F | res = (Y[i] > mu[i]) ? d_res : -d_res;
2824 | 100 | T | F | for (size_t j = 0; j < p; j++) {
2829 | 50 | T | F | if (aliased[j]) {
2832 | 0 | T | F | hv_store(row_hv, is_binomial ? "z value" : "t value", 7, newSVpv("NaN", 0), 0);
2833 | 0 | T | F | hv_store(row_hv, is_binomial ? "Pr(>|z|)" : "Pr(>|t|)", 8, newSVpv("NaN", 0), 0);
2837 | 100 | T | F | double p_val = is_binomial ? 2.0 * (1.0 - approx_pnorm(fabs(val_stat))) : get_t_pvalue(val_stat, df_res, "two.sided");
2841 | 100 | T | F | hv_store(row_hv, is_binomial ? "z value" : "t value", 7, newSVnv(val_stat), 0);
2842 | 100 | T | F | hv_store(row_hv, is_binomial ? "Pr(>|z|)" : "Pr(>|t|)", 8, newSVnv(p_val), 0);
2864 | 100 | T | F | for (i = 0; i < num_terms; i++) Safefree(terms[i]);
2866 | 100 | T | F | for (i = 0; i < num_uniq; i++) Safefree(uniq_terms[i]);
2868 | 100 | T | F | for (size_t j = 0; j < p_exp; j++) {
2870 | 100 | T | F | if (is_dummy[j]) { Safefree(dummy_base[j]); Safefree(dummy_level[j]); }
2877 | 100 | T | F | if (row_hashes) Safefree(row_hashes);
2887 | 50 | T | F | if (items < 2 || items % 2 != 0)
| 50 | T | F | if (items < 2 || items % 2 != 0)
2899 | 100 | T | F | for (unsigned short int i = 2; i < items; i += 2) {
2903 | 100 | T | F | if (strEQ(key, "alternative")) alternative = SvPV_nolen(val);
2904 | 100 | T | F | else if (strEQ(key, "method")) method = SvPV_nolen(val);
2905 | 50 | T | F | else if (strEQ(key, "exact")) exact_sv = val;
2906 | 100 | T | F | else if (strEQ(key, "conf.level") || strEQ(key, "conf_level")) conf_level = SvNV(val);
| 50 | T | F | else if (strEQ(key, "conf.level") || strEQ(key, "conf_level")) conf_level = SvNV(val);
2907 | 50 | T | F | else if (strEQ(key, "continuity")) continuity = SvTRUE(val);
2920 | 50 | T | F | if (!SvOK(x_ref) || !SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV ||
| 50 | T | F | if (!SvOK(x_ref) || !SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV ||
| 50 | T | F | if (!SvOK(x_ref) || !SvROK(x_ref) || SvTYPE(SvRV(x_ref)) != SVt_PVAV ||
2921 | 50 | T | F | !SvOK(y_ref) || !SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) {
| 50 | T | F | !SvOK(y_ref) || !SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) {
| 50 | T | F | !SvOK(y_ref) || !SvROK(y_ref) || SvTYPE(SvRV(y_ref)) != SVt_PVAV) {
2929 | 50 | T | F | if (n_raw != av_len(y_av) + 1) croak("incompatible dimensions");
2935 | 100 | T | F | for (size_t i = 0; i < n_raw; i++) {
2939 | 50 | T | F | double xv = (x_val && SvOK(*x_val) && looks_like_number(*x_val)) ? SvNV(*x_val) : NAN;
| 100 | T | F | double xv = (x_val && SvOK(*x_val) && looks_like_number(*x_val)) ? SvNV(*x_val) : NAN;
| 50 | T | F | double xv = (x_val && SvOK(*x_val) && looks_like_number(*x_val)) ? SvNV(*x_val) : NAN;
2940 | 50 | T | F | double yv = (y_val && SvOK(*y_val) && looks_like_number(*y_val)) ? SvNV(*y_val) : NAN;
| 100 | T | F | double yv = (y_val && SvOK(*y_val) && looks_like_number(*y_val)) ? SvNV(*y_val) : NAN;
| 50 | T | F | double yv = (y_val && SvOK(*y_val) && looks_like_number(*y_val)) ? SvNV(*y_val) : NAN;
2943 | 100 | T | F | if (!isnan(xv) && !isnan(yv)) {
| 100 | T | F | if (!isnan(xv) && !isnan(yv)) {
2950 | 50 | T | F | if (n < 3) {
2956 | 100 | T | F | if (is_pearson) {
2959 | 100 | T | F | for (size_t i = 0; i < n; i++) {
2968 | 50 | T | F | estimate = (M2_x > 0.0 && M2_y > 0.0) ? cov / sqrt(M2_x * M2_y) : 0.0;
| 50 | T | F | estimate = (M2_x > 0.0 && M2_y > 0.0) ? cov / sqrt(M2_x * M2_y) : 0.0;
2982 | 100 | T | F | } else if (is_kendall) {
2984 | 100 | T | F | for (size_t i = 0; i < n - 1; i++) {
2985 | 100 | T | F | for (size_t j = i + 1; j < n; j++) {
2989 | 50 | T | F | if (sign_x == 0 && sign_y == 0) { /* Joint tie, ignore */ }
| 0 | T | F | if (sign_x == 0 && sign_y == 0) { /* Joint tie, ignore */ }
2990 | 50 | T | F | else if (sign_x == 0) tie_x++;
2991 | 50 | T | F | else if (sign_y == 0) tie_y++;
2992 | 100 | T | F | else if (sign_x * sign_y > 0) c++;
2997 | 50 | T | F | estimate = (denom == 0.0) ? (0.0/0.0) : (double)(c - d) / denom;
2999 | 50 | T | F | bool has_ties = (tie_x > 0 || tie_y > 0);
| 50 | T | F | bool has_ties = (tie_x > 0 || tie_y > 0);
3003 | 50 | T | F | if (!exact_sv || !SvOK(exact_sv)) {
| 0 | T | F | if (!exact_sv || !SvOK(exact_sv)) {
3004 | 50 | T | F | do_exact = (n < 50) && !has_ties;
| 50 | T | F | do_exact = (n < 50) && !has_ties;
3009 | 50 | T | F | if (do_exact && has_ties) do_exact = 0;
| 50 | T | F | if (do_exact && has_ties) do_exact = 0;
3011 | 50 | T | F | if (do_exact) {
3019 | 0 | T | F | if (continuity) S -= (S > 0 ? 1 : -1);
| 0 | T | F | if (continuity) S -= (S > 0 ? 1 : -1);
3022 | 0 | T | F | if (strcmp(alternative, "two.sided") == 0) {
3024 | 0 | T | F | } else if (strcmp(alternative, "less") == 0) {
3030 | 50 | T | F | } else if (is_spearman) {
3038 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3047 | 50 | T | F | estimate = (M2_x > 0.0 && M2_y > 0.0) ? cov / sqrt(M2_x * M2_y) : 0.0;
| 50 | T | F | estimate = (M2_x > 0.0 && M2_y > 0.0) ? cov / sqrt(M2_x * M2_y) : 0.0;
3051 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3058 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3059 | 50 | T | F | if (rank_x[i] != floor(rank_x[i]) || rank_y[i] != floor(rank_y[i])) {
| 50 | T | F | if (rank_x[i] != floor(rank_x[i]) || rank_y[i] != floor(rank_y[i])) {
3064 | 50 | T | F | if (!exact_sv || !SvOK(exact_sv)) {
| 0 | T | F | if (!exact_sv || !SvOK(exact_sv)) {
3065 | 50 | T | F | do_exact = (n < 10) && !has_ties;
| 50 | T | F | do_exact = (n < 10) && !has_ties;
3070 | 50 | T | F | if (do_exact) {
3075 | 0 | T | F | if (continuity)
3092 | 100 | T | F | if (is_pearson) {
3114 | 50 | T | F | if (!SvROK(data) || SvTYPE(SvRV(data)) != SVt_PVAV) {
| 50 | T | F | if (!SvROK(data) || SvTYPE(SvRV(data)) != SVt_PVAV) {
3121 | 50 | T | F | Newx(x, n_raw, double);
3124 | 100 | T | F | for (size_t i = 0; i < n_raw; i++) {
3126 | 50 | T | F | if (elem && SvOK(*elem)) {
| 50 | T | F | if (elem && SvOK(*elem)) {
3128 | 50 | T | F | if (!isnan(val)) {
3136 | 50 | T | F | if (n < 3 || n > 5000) {
| 50 | T | F | if (n < 3 || n > 5000) {
3143 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3146 | 50 | T | F | if (ssq == 0.0) {
3153 | 50 | T | F | if (n == 3) {
3157 | 0 | T | F | if (w < 0.75) w = 0.75;
3163 | 50 | T | F | Newx(m, n, double);
3164 | 50 | T | F | Newx(a, n, double);
3165 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3173 | 50 | T | F | if (n == 4 || n == 5) {
| 100 | T | F | if (n == 4 || n == 5) {
3175 | 100 | T | F | for (unsigned int i = 1; i < n-1; i++) {
3183 | 100 | T | F | for (unsigned int i = 2; i < n-2; i++) {
3187 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3197 | 100 | T | F | if (n <= 11) {
3203 | 50 | T | F | if (y >= gamma) {
3226 | 50 | T | F | if (p_val > 1.0) p_val = 1.0;
3227 | 50 | T | F | if (p_val < 0.0) p_val = 0.0;
3237 | 50 | T | F | EXTEND(SP, 1);
3247 | 100 | T | F | for (unsigned short int i = 0; i < items; i++) {
3249 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
3252 | 100 | T | F | for (size_t j = 0; j < len; j++) {
3254 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3256 | 100 | T | F | if (first || val < min_val) {
| 50 | T | F | if (first || val < min_val) {
3263 | 50 | T | F | } else if (SvOK(arg)) {
3265 | 100 | T | F | if (first || val < min_val) {
| 100 | T | F | if (first || val < min_val) {
3272 | 100 | T | F | if (count == 0) croak("min needs >= 1 numeric element");
3273 | 50 | T | F | RETVAL = min_val;
3284 | 100 | T | F | for (size_t i = 0; i < items; i++) {
3286 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
3289 | 100 | T | F | for (size_t j = 0; j < len; j++) {
3291 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3293 | 100 | T | F | if (first || val > max_val) {
| 100 | T | F | if (first || val > max_val) {
3300 | 50 | T | F | } else if (SvOK(arg)) {
3302 | 100 | T | F | if (first || val > max_val) {
| 100 | T | F | if (first || val > max_val) {
3309 | 100 | T | F | if (count == 0) croak("max needs >= 1 numeric element");
3310 | 50 | T | F | RETVAL = max_val;
3325 | 50 | T | F | if (items == 0) {
3329 | 100 | T | F | while (i < items) {
3331 | 100 | T | F | if (i + 1 < items && SvPOK(ST(i))) {
| 100 | T | F | if (i + 1 < items && SvPOK(ST(i))) {
3333 | 100 | T | F | if (strEQ(key, "n")) {
3338 | 100 | T | F | } else if (strEQ(key, "min")) {
3343 | 50 | T | F | } else if (strEQ(key, "max")) {
3352 | 100 | T | F | if (!n_set) {
3355 | 100 | T | F | } else if (!min_set) {
3358 | 50 | T | F | } else if (!max_set) {
3366 | 50 | T | F | if (!n_set) {
3370 | 50 | T | F | AUTO_SEED_PRNG();
3372 | 50 | T | F | if (n > 0) {
3376 | 100 | T | F | for (size_t j = 0; j < n; j++) {
3378 | 50 | T | F | if (max < min) {
3394 | 50 | T | F | AUTO_SEED_PRNG();
3395 | 100 | T | F | if (items % 2 != 0)
3403 | 100 | T | F | for (unsigned short i = 0; i < items; i += 2) {
3407 | 100 | T | F | if (strEQ(key, "n")) n = (unsigned int)SvUV(val);
3408 | 100 | T | F | else if (strEQ(key, "size")) { size = (unsigned int)SvUV(val); size_set = true; }
3409 | 50 | T | F | else if (strEQ(key, "prob")) { prob = SvNV(val); prob_set = true; }
3414 | 100 | T | F | if (!size_set || !prob_set) croak("rbinom: 'size' and 'prob' are required arguments");
| 100 | T | F | if (!size_set || !prob_set) croak("rbinom: 'size' and 'prob' are required arguments");
3415 | 100 | T | F | if (prob < 0.0 || prob > 1.0) croak("rbinom: prob must be between 0 and 1");
| 100 | T | F | if (prob < 0.0 || prob > 1.0) croak("rbinom: prob must be between 0 and 1");
3418 | 50 | T | F | if (n > 0) {
3420 | 100 | T | F | for (unsigned int i = 0; i < n; i++) {
3435 | 100 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 100 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
3440 | 100 | T | F | if (n_raw == 0) croak("hist: input array is empty");
3444 | 50 | T | F | Newx(x, n_raw, double);
3448 | 100 | T | F | for (size_t i = 0; i < n_raw; i++) {
3450 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3453 | 100 | T | F | if (val < min_val) min_val = val;
3454 | 100 | T | F | if (val > max_val) max_val = val;
3457 | 50 | T | F | if (n == 0) {
3464 | 50 | T | F | if (items == 2) {
3467 | 50 | T | F | } else if (items > 2) {
3469 | 50 | T | F | for (unsigned short i = 1; i < items - 1; i++) {
3471 | 50 | T | F | if (SvPOK(ST(i)) && strEQ(SvPV_nolen(ST(i)), "breaks")) {
| 50 | T | F | if (SvPOK(ST(i)) && strEQ(SvPV_nolen(ST(i)), "breaks")) {
3477 | 50 | T | F | if (n_bins == 0 && looks_like_number(ST(1))) {
| 0 | T | F | if (n_bins == 0 && looks_like_number(ST(1))) {
3481 | 50 | T | F | if (n_bins == 0) n_bins = calculate_sturges_bins(n);
3485 | 50 | T | F | Newx(breaks, n_bins + 1, double);
3486 | 50 | T | F | Newx(mids, n_bins, double);
3487 | 50 | T | F | Newx(density, n_bins, double);
3488 | 50 | T | F | Newx(counts, n_bins, size_t);
3492 | 100 | T | F | for (size_t i = 0; i <= n_bins; i++) {
3505 | 100 | T | F | for (size_t i = 0; i <= n_bins; i++) {
3507 | 100 | T | F | if (i < n_bins) {
3535 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
3541 | 50 | T | F | if ((items - arg_idx) % 2 != 0)
3544 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
3548 | 100 | T | F | if (strEQ(key, "x")) x_sv = val;
3549 | 50 | T | F | else if (strEQ(key, "probs")) probs_sv = val;
3552 | 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
3556 | 50 | T | F | if (n_raw == 0) croak("quantile: 'x' is empty");
3560 | 50 | T | F | Newx(x, n_raw, double);
3562 | 100 | T | F | for (size_t i = 0; i < n_raw; i++) {
3564 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3568 | 50 | T | F | if (n == 0) {
3579 | 50 | T | F | if (probs_sv && SvROK(probs_sv) && SvTYPE(SvRV(probs_sv)) == SVt_PVAV) {
| 50 | T | F | if (probs_sv && SvROK(probs_sv) && SvTYPE(SvRV(probs_sv)) == SVt_PVAV) {
| 50 | T | F | if (probs_sv && SvROK(probs_sv) && SvTYPE(SvRV(probs_sv)) == SVt_PVAV) {
3583 | 100 | T | F | for (unsigned int i = 0; i < n_probs; i++) {
3585 | 50 | T | F | probs[i] = (tv && SvOK(*tv)) ? SvNV(*tv) : 0.0;
| 50 | T | F | probs[i] = (tv && SvOK(*tv)) ? SvNV(*tv) : 0.0;
3586 | 50 | T | F | if (probs[i] < 0.0 || probs[i] > 1.0) {
| 50 | T | F | if (probs[i] < 0.0 || probs[i] > 1.0) {
3593 | 0 | T | F | for (unsigned int i = 0; i < n_probs; i++) probs[i] = default_probs[i];
3599 | 100 | T | F | for (size_t i = 0; i < n_probs; i++) {
3602 | 100 | T | F | if (n == 1) {
3604 | 100 | T | F | } else if (p == 1.0) {
3606 | 100 | T | F | } else if (p == 0.0) {
3620 | 50 | T | F | if (pct == (unsigned int)pct) {
3644 | 100 | T | F | for (size_t i = 0; i < items; i++) {
3646 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
3649 | 100 | T | F | for (size_t j = 0; j < len; j++) {
3651 | 50 | T | F | if (tv && SvOK(*tv)) { total += SvNV(*tv); count++; }
| 50 | T | F | if (tv && SvOK(*tv)) { total += SvNV(*tv); count++; }
3653 | 50 | T | F | } else if (SvOK(arg)) {
3657 | 100 | T | F | if (count == 0) croak("mean needs >= 1 element");
3658 | 100 | T | F | RETVAL = total / count;
3669 | 100 | T | F | for (size_t i = 0; i < items; i++) {
3671 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
3674 | 100 | T | F | for (size_t j = 0; j < len; j++) {
3676 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3684 | 50 | T | F | } else if (SvOK(arg)) {
3692 | 100 | T | F | if (count < 2) croak("stdev needs >= 2 elements");
3693 | 50 | T | F | RETVAL = sqrt(M2 / (count - 1));
3704 | 100 | T | F | for (size_t i = 0; i < items; i++) {
3706 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
3709 | 100 | T | F | for (size_t j = 0; j < len; j++) {
3711 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
3719 | 50 | T | F | } else if (SvOK(arg)) {
3727 | 100 | T | F | if (count < 2) croak("var needs >= 2 elements");
3728 | 100 | T | F | RETVAL = M2 / (count - 1);
3744 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
3750 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
| 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx)) && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
3756 | 50 | T | F | if ((items - arg_idx) % 2 != 0) {
3761 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
3765 | 100 | T | F | if (strEQ(key, "x")) x_sv = val;
3766 | 100 | T | F | else if (strEQ(key, "y")) y_sv = val;
3767 | 100 | T | F | else if (strEQ(key, "mu")) mu = SvNV(val);
3768 | 100 | T | F | else if (strEQ(key, "paired")) paired = SvTRUE(val);
3769 | 100 | T | F | else if (strEQ(key, "var_equal")) var_equal = SvTRUE(val);
3770 | 100 | T | F | else if (strEQ(key, "conf_level")) conf_level = SvNV(val);
3771 | 50 | T | F | else if (strEQ(key, "alternative")) alternative = SvPV_nolen(val);
3776 | 100 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
3780 | 50 | T | F | if (nx < 2) croak("t_test: 'x' needs at least 2 elements");
3782 | 100 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV)
| 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV)
| 50 | T | F | if (y_sv && SvROK(y_sv) && SvTYPE(SvRV(y_sv)) == SVt_PVAV)
3785 | 50 | T | F | if (conf_level <= 0.0 || conf_level >= 1.0)
| 100 | T | F | if (conf_level <= 0.0 || conf_level >= 1.0)
3790 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
3792 | 50 | T | F | double val = (tv && SvOK(*tv)) ? SvNV(*tv) : 0;
| 50 | T | F | double val = (tv && SvOK(*tv)) ? SvNV(*tv) : 0;
3798 | 100 | T | F | if (var_x == 0.0 && !y_av) croak("t_test: data are essentially constant");
| 50 | T | F | if (var_x == 0.0 && !y_av) croak("t_test: data are essentially constant");
3800 | 100 | T | F | if (paired || y_av) {
| 100 | T | F | if (paired || y_av) {
3801 | 100 | T | F | if (!y_av) croak("t_test: 'y' must be provided for paired or two-sample tests");
3803 | 100 | T | F | if (paired && ny != nx) croak("t_test: Paired arrays must be same length");
| 100 | T | F | if (paired && ny != nx) croak("t_test: Paired arrays must be same length");
3805 | 100 | T | F | for (size_t i = 0; i < ny; i++) {
3807 | 50 | T | F | double val = (tv && SvOK(*tv)) ? SvNV(*tv) : 0;
| 50 | T | F | double val = (tv && SvOK(*tv)) ? SvNV(*tv) : 0;
3813 | 100 | T | F | if (paired) {
3815 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
3818 | 50 | T | F | double dx = (dx_ptr && SvOK(*dx_ptr)) ? SvNV(*dx_ptr) : 0.0;
| 50 | T | F | double dx = (dx_ptr && SvOK(*dx_ptr)) ? SvNV(*dx_ptr) : 0.0;
3819 | 50 | T | F | double dy = (dy_ptr && SvOK(*dy_ptr)) ? SvNV(*dy_ptr) : 0.0;
| 50 | T | F | double dy = (dy_ptr && SvOK(*dy_ptr)) ? SvNV(*dy_ptr) : 0.0;
3826 | 50 | T | F | if (var_d == 0.0) croak("t_test: data are essentially constant");
3832 | 100 | T | F | } else if (var_equal) {
3833 | 50 | T | F | if (var_x == 0.0 && var_y == 0.0) croak("t_test: data are essentially constant");
| 0 | T | F | if (var_x == 0.0 && var_y == 0.0) croak("t_test: data are essentially constant");
3842 | 50 | T | F | if (var_x == 0.0 && var_y == 0.0) croak("t_test: data are essentially constant");
| 0 | T | F | if (var_x == 0.0 && var_y == 0.0) croak("t_test: data are essentially constant");
3862 | 100 | T | F | if (strcmp(alternative, "less") == 0) {
3866 | 100 | T | F | } else if (strcmp(alternative, "greater") == 0) {
3889 | 100 | T | F | if (!SvROK(p_sv) || SvTYPE(SvRV(p_sv)) != SVt_PVAV) {
| 50 | T | F | if (!SvROK(p_sv) || SvTYPE(SvRV(p_sv)) != SVt_PVAV) {
3895 | 100 | T | F | if (n == 0) {
3901 | 100 | T | F | for(unsigned short int i = 0; meth[i]; i++) meth[i] = tolower(meth[i]);
3903 | 100 | T | F | if (strstr(meth, "benjamini") && strstr(meth, "hochberg")) strcpy(meth, "bh");
| 100 | T | F | if (strstr(meth, "benjamini") && strstr(meth, "hochberg")) strcpy(meth, "bh");
3904 | 100 | T | F | if (strstr(meth, "benjamini") && strstr(meth, "yekutieli")) strcpy(meth, "by");
| 50 | T | F | if (strstr(meth, "benjamini") && strstr(meth, "yekutieli")) strcpy(meth, "by");
3905 | 50 | T | F | if (strcmp(meth, "fdr") == 0) strcpy(meth, "bh");
3909 | 50 | T | F | Newx(arr, n, PVal);
3910 | 50 | T | F | Newx(adj, n, double);
3912 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3914 | 50 | T | F | arr[i].p = (tv && SvOK(*tv)) ? SvNV(*tv) : 1.0;
| 50 | T | F | arr[i].p = (tv && SvOK(*tv)) ? SvNV(*tv) : 1.0;
3920 | 100 | T | F | if (strcmp(meth, "bonferroni") == 0) {
3921 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3923 | 100 | T | F | adj[arr[i].orig_idx] = (v < 1.0) ? v : 1.0;
3925 | 100 | T | F | } else if (strcmp(meth, "holm") == 0) {
3927 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3929 | 100 | T | F | if (v > cummax) cummax = v;
3930 | 100 | T | F | adj[arr[i].orig_idx] = (cummax < 1.0) ? cummax : 1.0;
3932 | 100 | T | F | } else if (strcmp(meth, "hochberg") == 0) {
3934 | 100 | T | F | for (ssize_t i = n - 1; i >= 0; i--) {
3936 | 100 | T | F | if (v < cummin) cummin = v;
3937 | 50 | T | F | adj[arr[i].orig_idx] = (cummin < 1.0) ? cummin : 1.0;
3939 | 100 | T | F | } else if (strcmp(meth, "bh") == 0) {
3941 | 100 | T | F | for (ssize_t i = n - 1; i >= 0; i--) {
3943 | 100 | T | F | if (v < cummin) cummin = v;
3944 | 50 | T | F | adj[arr[i].orig_idx] = (cummin < 1.0) ? cummin : 1.0;
3946 | 100 | T | F | } else if (strcmp(meth, "by") == 0) {
3948 | 100 | T | F | for (size_t i = 1; i <= n; i++) q += 1.0 / i;
3950 | 100 | T | F | for (ssize_t i = n - 1; i >= 0; i--) {
3952 | 100 | T | F | if (v < cummin) cummin = v;
3953 | 100 | T | F | adj[arr[i].orig_idx] = (cummin < 1.0) ? cummin : 1.0;
3955 | 100 | T | F | } else if (strcmp(meth, "hommel") == 0) {
3957 | 50 | T | F | Newx(pa, n, double);
3958 | 50 | T | F | Newx(q_arr, n, double);
3961 | 100 | T | F | for (size_t i = 1; i < n; i++) {
3963 | 50 | T | F | if (temp < min_val) {
3968 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3972 | 100 | T | F | for (size_t j = n - 1; j >= 2; j--) {
3977 | 100 | T | F | for (size_t k = 1; k < i2_len; k++) {
3979 | 100 | T | F | if (temp_q1 < q1) {
3984 | 100 | T | F | for (size_t i = 0; i <= n_mj; i++) {
3986 | 100 | T | F | q_arr[i] = (v < q1) ? v : q1;
3989 | 100 | T | F | for (size_t i = 0; i < i2_len; i++) {
3993 | 100 | T | F | for (size_t i = 0; i < n; i++) {
3994 | 100 | T | F | if (pa[i] < q_arr[i]) {
4000 | 100 | T | F | for (size_t i = 0; i < n; i++) {
4001 | 100 | T | F | double v = (pa[i] > arr[i].p) ? pa[i] : arr[i].p;
4002 | 50 | T | F | if (v > 1.0) v = 1.0;
4006 | 50 | T | F | } else if (strcmp(meth, "none") == 0) {
4007 | 0 | T | F | for (size_t i = 0; i < n; i++) {
4015 | 50 | T | F | EXTEND(SP, n);
4016 | 100 | T | F | for (size_t i = 0; i < n; i++) {
4030 | 100 | T | F | for (size_t i = 0; i < items; i++) {
4032 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
4035 | 100 | T | F | for (size_t j = 0; j < len; j++) {
4037 | 50 | T | F | if (tv && SvOK(*tv)) { total_count++; }
| 50 | T | F | if (tv && SvOK(*tv)) { total_count++; }
4039 | 50 | T | F | } else if (SvOK(arg)) {
4043 | 100 | T | F | if (total_count == 0) croak("median needs >= 1 element");
4045 | 50 | T | F | Newx(nums, total_count, double);
4047 | 100 | T | F | for (size_t i = 0; i < items; i++) {
4049 | 100 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
4052 | 100 | T | F | for (size_t j = 0; j < len; j++) {
4054 | 50 | T | F | if (tv && SvOK(*tv)) {
| 50 | T | F | if (tv && SvOK(*tv)) {
4058 | 50 | T | F | } else if (SvOK(arg)) {
4064 | 100 | T | F | if (total_count % 2 == 0) {
4070 | 100 | T | F | RETVAL = median_val;
4077 | 100 | T | F | if (strcmp(method, "pearson") != 0 &&
4078 | 100 | T | F | strcmp(method, "spearman") != 0 &&
4079 | 100 | T | F | strcmp(method, "kendall") != 0)
4084 | 50 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
4089 | 50 | T | F | if (nx == 0) croak("cor: x is empty");
4095 | 50 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
| 100 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
| 50 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
4100 | 50 | T | F | bool has_y = (SvOK(y_sv) && SvROK(y_sv) &&
| 50 | T | F | bool has_y = (SvOK(y_sv) && SvROK(y_sv) &&
4101 | 50 | T | F | SvTYPE(SvRV(y_sv)) == SVt_PVAV);
4103 | 50 | T | F | AV*restrict y_av = has_y ? (AV*)SvRV(y_sv) : NULL;
4104 | 50 | T | F | size_t ny = has_y ? av_len(y_av) + 1 : 0;
4107 | 50 | T | F | if (has_y && ny > 0) {
| 50 | T | F | if (has_y && ny > 0) {
4109 | 50 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
| 100 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
| 50 | T | F | if (fp && SvROK(*fp) && SvTYPE(SvRV(*fp)) == SVt_PVAV)
4115 | 100 | T | F | if (!x_is_matrix && !y_is_matrix) {
| 50 | T | F | if (!x_is_matrix && !y_is_matrix) {
4116 | 50 | T | F | if (!has_y) {
4120 | 100 | T | F | if (nx != ny)
4124 | 50 | T | F | if (nx < 2)
4128 | 50 | T | F | Newx(xd, nx, double);
4129 | 50 | T | F | Newx(yd, ny, double);
4131 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
4133 | 50 | T | F | xd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
| 50 | T | F | xd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
| 50 | T | F | xd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
4135 | 100 | T | F | for (size_t i = 0; i < ny; i++) {
4137 | 50 | T | F | yd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
| 50 | T | F | yd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
| 50 | T | F | yd[i] = (tv && SvOK(*tv) && looks_like_number(*tv)) ? SvNV(*tv) : NAN;
4146 | 50 | T | F | if (!x_is_matrix)
4151 | 50 | T | F | if (!xr0 || !SvROK(*xr0) || SvTYPE(SvRV(*xr0)) != SVt_PVAV)
| 50 | T | F | if (!xr0 || !SvROK(*xr0) || SvTYPE(SvRV(*xr0)) != SVt_PVAV)
| 50 | T | F | if (!xr0 || !SvROK(*xr0) || SvTYPE(SvRV(*xr0)) != SVt_PVAV)
4155 | 50 | T | F | if (ncols_x == 0) croak("cor: x matrix has zero columns");
4160 | 100 | T | F | for (size_t i = 0; i < nrows; i++) {
4162 | 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
| 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
| 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
4166 | 50 | T | F | if (has_y && y_is_matrix) {
| 50 | T | F | if (has_y && y_is_matrix) {
4167 | 50 | T | F | if (ny != nrows) croak("cor: x and y must have the same number of rows (%lu vs %lu)", nrows, ny);
4168 | 100 | T | F | for (size_t i = 0; i < nrows; i++) {
4170 | 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
| 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
| 50 | T | F | if (!rv || !SvROK(*rv) || SvTYPE(SvRV(*rv)) != SVt_PVAV)
4177 | 50 | T | F | Newx(col_x, ncols_x, double*);
4179 | 100 | T | F | for (size_t j = 0; j < ncols_x; j++) {
4180 | 50 | T | F | Newx(col_x[j], nrows, double);
4181 | 100 | T | F | for (size_t i = 0; i < nrows; i++) {
4185 | 50 | T | F | col_x[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
| 50 | T | F | col_x[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
| 50 | T | F | col_x[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
4195 | 50 | T | F | if (has_y && y_is_matrix) {
| 50 | T | F | if (has_y && y_is_matrix) {
4199 | 50 | T | F | if (ncols_y == 0) croak("cor: y matrix has zero columns");
4201 | 50 | T | F | Newx(col_y, ncols_y, double*);
4202 | 100 | T | F | for (size_t j = 0; j < ncols_y; j++) {
4203 | 50 | T | F | Newx(col_y[j], nrows, double);
4204 | 100 | T | F | for (size_t i = 0; i < nrows; i++) {
4208 | 50 | T | F | col_y[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
| 50 | T | F | col_y[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
| 50 | T | F | col_y[j][i] = (cv && SvOK(*cv) && looks_like_number(*cv)) ? SvNV(*cv) : NAN;
4216 | 50 | T | F | if (nrows < 2)
4223 | 50 | T | F | Newx(rows_out, ncols_x, AV*);
4224 | 100 | T | F | for (size_t i = 0; i < ncols_x; i++) {
4228 | 50 | T | F | if (symmetric) {
4231 | 0 | T | F | Newx(r_cache, ncols_x, double*);
4232 | 0 | T | F | for (size_t i = 0; i < ncols_x; i++)
4233 | 0 | T | F | Newx(r_cache[i], ncols_x, double);
4235 | 0 | T | F | for (size_t i = 0; i < ncols_x; i++) {
4237 | 0 | T | F | for (size_t j = i + 1; j < ncols_x; j++) {
4244 | 0 | T | F | for (size_t i = 0; i < ncols_x; i++)
4245 | 0 | T | F | for (size_t j = 0; j < ncols_x; j++)
4248 | 0 | T | F | for (size_t i = 0; i < ncols_x; i++) Safefree(r_cache[i]);
4252 | 100 | T | F | for (size_t i = 0; i < ncols_x; i++)
4253 | 100 | T | F | for (size_t j = 0; j < ncols_y; j++)
4257 | 100 | T | F | for (size_t i = 0; i < ncols_x; i++)
4261 | 100 | T | F | for (size_t j = 0; j < ncols_x; j++) Safefree(col_x[j]);
4263 | 50 | T | F | if (!symmetric) {
4264 | 100 | T | F | for (size_t j = 0; j < ncols_y; j++) Safefree(col_y[j]);
4280 | 50 | T | F | if (items > 0) {
4282 | 100 | T | F | if (SvROK(last_arg) && SvTYPE(SvRV(last_arg)) == SVt_PVHV) {
| 100 | T | F | if (SvROK(last_arg) && SvTYPE(SvRV(last_arg)) == SVt_PVHV) {
4287 | 50 | T | F | if (center_sv) {
4289 | 50 | T | F | if (!SvOK(val_sv)) {
4294 | 50 | T | F | if (strcasecmp(str, "mean") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
| 50 | T | F | if (strcasecmp(str, "mean") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
| 100 | T | F | if (strcasecmp(str, "mean") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
4296 | 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
4298 | 0 | T | F | } else if (looks_like_number(val_sv)) {
4300 | 0 | T | F | } else if (SvTRUE(val_sv)) {
4309 | 100 | T | F | if (scale_sv) {
4311 | 50 | T | F | if (!SvOK(val_sv)) {
4315 | 50 | T | F | if (strcasecmp(str, "sd") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
| 50 | T | F | if (strcasecmp(str, "sd") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
| 50 | T | F | if (strcasecmp(str, "sd") == 0 || strcasecmp(str, "true") == 0 || strcmp(str, "1") == 0) {
4317 | 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
| 50 | T | F | } else if (strcasecmp(str, "none") == 0 || strcasecmp(str, "false") == 0 || strcmp(str, "0") == 0 || strcmp(str, "") == 0) {
4319 | 0 | T | F | } else if (looks_like_number(val_sv)) {
4321 | 0 | T | F | if (scale_val == 0.0) scale_val = 1.0; /* Prevent Division By Zero */
4322 | 0 | T | F | } else if (SvTRUE(val_sv)) {
4333 | 100 | T | F | if (data_items == 1) {
4335 | 100 | T | F | if (SvROK(first_arg) && SvTYPE(SvRV(first_arg)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(first_arg) && SvTYPE(SvRV(first_arg)) == SVt_PVAV) {
4337 | 50 | T | F | if (av_len(av) >= 0) {
4339 | 50 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
| 50 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
| 50 | T | F | if (first_elem && SvROK(*first_elem) && SvTYPE(SvRV(*first_elem)) == SVt_PVAV) {
4345 | 100 | T | F | if (is_matrix) {
4355 | 50 | T | F | if (nrow == 0 || ncol == 0) croak("scale requires non-empty matrix");
| 50 | T | F | if (nrow == 0 || ncol == 0) croak("scale requires non-empty matrix");
4361 | 100 | T | F | for (size_t r = 0; r < nrow; r++) {
4367 | 100 | T | F | for (size_t c = 0; c < ncol; c++) {
4370 | 50 | T | F | Newx(col_data, nrow, double);
4372 | 100 | T | F | for (size_t r = 0; r < nrow; r++) {
4374 | 50 | T | F | if (row_sv && SvROK(*row_sv)) {
| 50 | T | F | if (row_sv && SvROK(*row_sv)) {
4377 | 50 | T | F | col_data[r] = (cell_sv && SvOK(*cell_sv)) ? SvNV(*cell_sv) : 0.0;
| 50 | T | F | col_data[r] = (cell_sv && SvOK(*cell_sv)) ? SvNV(*cell_sv) : 0.0;
4384 | 50 | T | F | double col_center = do_center_mean ? (col_sum / nrow) : center_val;
4387 | 50 | T | F | if (do_scale_sd) {
4388 | 50 | T | F | if (nrow <= 1) {
4394 | 100 | T | F | for (size_t r = 0; r < nrow; r++) {
4401 | 100 | T | F | for (size_t r = 0; r < nrow; r++) {
4403 | 50 | T | F | double final_val = (col_scale == 0.0) ? (0.0 / 0.0) : (centered / col_scale);
4410 | 50 | T | F | EXTEND(SP, 1);
4419 | 100 | T | F | for (size_t i = 0; i < data_items; i++) {
4421 | 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 0 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
4424 | 0 | T | F | for (unsigned int j = 0; j < len; j++) {
4426 | 0 | T | F | if (tv && SvOK(*tv)) { total_count++; }
| 0 | T | F | if (tv && SvOK(*tv)) { total_count++; }
4428 | 50 | T | F | } else if (SvOK(arg)) {
4432 | 50 | T | F | if (total_count == 0) croak("scale requires at least 1 numeric element");
4433 | 50 | T | F | Newx(nums, total_count, double);
4434 | 100 | T | F | for (size_t i = 0; i < data_items; i++) {
4436 | 50 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
| 0 | T | F | if (SvROK(arg) && SvTYPE(SvRV(arg)) == SVt_PVAV) {
4439 | 0 | T | F | for (size_t j = 0; j < len; j++) {
4441 | 0 | T | F | if (tv && SvOK(*tv)) {
| 0 | T | F | if (tv && SvOK(*tv)) {
4446 | 50 | T | F | } else if (SvOK(arg)) {
4452 | 100 | T | F | if (do_center_mean) center_val = sum / total_count;
4454 | 100 | T | F | if (do_scale_sd) {
4455 | 100 | T | F | if (total_count <= 1) {
4460 | 100 | T | F | for (size_t i = 0; i < total_count; i++) {
4466 | 50 | T | F | EXTEND(SP, total_count);
4467 | 100 | T | F | for (size_t i = 0; i < total_count; i++) {
4469 | 50 | T | F | double final_val = (scale_val == 0.0) ? (0.0 / 0.0) : (centered / scale_val);
4479 | 50 | T | F | if (items % 2 != 0) {
4486 | 100 | T | F | for (size_t i = 0; i < items; i += 2) {
4489 | 100 | T | F | if (strEQ(key, "data")) {
4491 | 100 | T | F | } else if (strEQ(key, "nrow")) {
4494 | 50 | T | F | } else if (strEQ(key, "ncol")) {
4497 | 0 | T | F | } else if (strEQ(key, "byrow")) {
4504 | 50 | T | F | if (!data_sv || !SvROK(data_sv) || SvTYPE(SvRV(data_sv)) != SVt_PVAV) {
| 100 | T | F | if (!data_sv || !SvROK(data_sv) || SvTYPE(SvRV(data_sv)) != SVt_PVAV) {
| 50 | T | F | if (!data_sv || !SvROK(data_sv) || SvTYPE(SvRV(data_sv)) != SVt_PVAV) {
4508 | 50 | T | F | size_t data_len = (UV)(av_top_index(data_av) + 1);
4509 | 100 | T | F | if (data_len == 0) {
4513 | 50 | T | F | if (!nrow_set && !ncol_set) {
| 0 | T | F | if (!nrow_set && !ncol_set) {
4516 | 50 | T | F | } else if (nrow_set && !ncol_set) {
| 100 | T | F | } else if (nrow_set && !ncol_set) {
4518 | 50 | T | F | } else if (!nrow_set && ncol_set) {
| 0 | T | F | } else if (!nrow_set && ncol_set) {
4522 | 100 | T | F | if (nrow == 0 || ncol == 0) {
| 50 | T | F | if (nrow == 0 || ncol == 0) {
4530 | 100 | T | F | for (r = 0; r < nrow; r++) {
4537 | 100 | T | F | for (size_t i = 0; i < total_cells; i++) {
4540 | 50 | T | F | SV*restrict val = fetched ? newSVsv(*fetched) : newSV(0);
4541 | 50 | T | F | if (byrow) {
4584 | 50 | T | F | if (items % 2 != 0) croak("Usage: lm(formula => 'mpg ~ wt * hp', data => \\%%mtcars)");
4586 | 100 | T | F | for (unsigned short i_arg = 0; i_arg < items; i_arg += 2) {
4589 | 100 | T | F | if (strEQ(key, "formula")) formula = SvPV_nolen(val);
4590 | 50 | T | F | else if (strEQ(key, "data")) data_sv = val;
4593 | 100 | T | F | if (!formula) croak("lm: formula is required");
4594 | 100 | T | F | if (!data_sv || !SvROK(data_sv)) croak("lm: data is required and must be a reference");
| 100 | T | F | if (!data_sv || !SvROK(data_sv)) croak("lm: data is required and must be a reference");
4600 | 50 | T | F | if (SvTYPE(ref) == SVt_PVHV) {
4602 | 50 | T | F | if (hv_iterinit(hv) == 0) croak("lm: Data hash is empty");
4604 | 50 | T | F | if (entry) {
4606 | 50 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
| 100 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
4609 | 50 | T | F | Newx(row_names, n, char*);
4610 | 100 | T | F | for (i = 0; i < n; i++) {
4615 | 50 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
| 50 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
4617 | 50 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
| 50 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
4619 | 100 | T | F | while ((entry = hv_iternext(hv))) {
4627 | 0 | T | F | } else if (SvTYPE(ref) == SVt_PVAV) {
4629 | 0 | T | F | Newx(row_names, n, char*);
4630 | 0 | T | F | Newx(row_hashes, n, HV*);
4631 | 0 | T | F | for (i = 0; i < n; i++) {
4633 | 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
4638 | 0 | T | F | for (k = 0; k < i; k++) Safefree(row_names[k]);
4649 | 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 50 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
4653 | 100 | T | F | if (!tilde) {
4654 | 100 | T | F | for (i = 0; i < n; i++) Safefree(row_names[i]);
4655 | 50 | T | F | Safefree(row_names); if (row_hashes) Safefree(row_hashes);
4667 | 100 | T | F | while (*p_idx) {
4669 | 50 | T | F | if (p_idx[0] == 'I' && p_idx[1] == '(') {
| 0 | T | F | if (p_idx[0] == 'I' && p_idx[1] == '(') {
4671 | 0 | T | F | while (*p_idx) { if (*p_idx == '(') depth++; else if (*p_idx == ')') { depth--; if (depth == 0) { p_idx++; break; } } p_idx++; }
| 0 | T | F | while (*p_idx) { if (*p_idx == '(') depth++; else if (*p_idx == ')') { depth--; if (depth == 0) { p_idx++; break; } } p_idx++; }
| 0 | T | F | while (*p_idx) { if (*p_idx == '(') depth++; else if (*p_idx == ')') { depth--; if (depth == 0) { p_idx++; break; } } p_idx++; }
| 0 | T | F | while (*p_idx) { if (*p_idx == '(') depth++; else if (*p_idx == ')') { depth--; if (depth == 0) { p_idx++; break; } } p_idx++; }
4675 | 100 | T | F | if (p_idx[0] == '-' && p_idx[1] == '1' &&
| 50 | T | F | if (p_idx[0] == '-' && p_idx[1] == '1' &&
4676 | 50 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
4682 | 100 | T | F | if (p_idx[0] == '+' && p_idx[1] == '0' &&
| 50 | T | F | if (p_idx[0] == '+' && p_idx[1] == '0' &&
4683 | 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
4689 | 100 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '+') {
| 50 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '+') {
| 0 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '+') {
4695 | 100 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '\0') {
| 50 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '\0') {
| 0 | T | F | if (p_idx == rhs && p_idx[0] == '0' && p_idx[1] == '\0') {
4699 | 100 | T | F | if (p_idx[0] == '+' && p_idx[1] == '1' &&
| 50 | T | F | if (p_idx[0] == '+' && p_idx[1] == '1' &&
4700 | 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
| 0 | T | F | (p_idx[2] == '\0' || p_idx[2] == '+' || p_idx[2] == '-')) {
4705 | 100 | T | F | if (p_idx == rhs) {
4706 | 50 | T | F | if (p_idx[0] == '1' && p_idx[1] == '\0') { p_idx[0] = '\0'; break; }
| 0 | T | F | if (p_idx[0] == '1' && p_idx[1] == '\0') { p_idx[0] = '\0'; break; }
4707 | 50 | T | F | if (p_idx[0] == '1' && p_idx[1] == '+') { memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); continue; }
| 0 | T | F | if (p_idx[0] == '1' && p_idx[1] == '+') { memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); continue; }
4716 | 50 | T | F | while ((p_idx = strstr(rhs, "++")) != NULL)
4718 | 50 | T | F | if (rhs[0] == '+') memmove(rhs, rhs + 1, strlen(rhs + 1) + 1);
4720 | 50 | T | F | if (len_rhs > 0 && rhs[len_rhs - 1] == '+') rhs[len_rhs - 1] = '\0';
| 50 | T | F | if (len_rhs > 0 && rhs[len_rhs - 1] == '+') rhs[len_rhs - 1] = '\0';
4727 | 100 | T | F | while (chunk != NULL) {
4728 | 100 | T | F | if (strcmp(chunk, ".") == 0) {
4730 | 100 | T | F | for (size_t c = 0; c <= (size_t)av_len(cols); c++) {
4732 | 50 | T | F | if (col_sv && SvOK(*col_sv)) {
| 50 | T | F | if (col_sv && SvOK(*col_sv)) {
4734 | 100 | T | F | if (strcmp(col_name, lhs) != 0) {
4736 | 50 | T | F | if (rhs_len + slen + 2 < sizeof(rhs_expanded)) {
4737 | 100 | T | F | if (rhs_len > 0) { strcat(rhs_expanded, "+"); rhs_len++; }
4747 | 50 | T | F | if (rhs_len + slen + 2 < sizeof(rhs_expanded)) {
4748 | 100 | T | F | if (rhs_len > 0) { strcat(rhs_expanded, "+"); rhs_len++; }
4760 | 100 | T | F | if (has_intercept) { terms[num_terms++] = savepv("Intercept"); }
4762 | 50 | T | F | if (strlen(rhs_expanded) > 0) {
4764 | 100 | T | F | while (chunk != NULL) {
4765 | 50 | T | F | if (num_terms >= term_cap - 3) {
4770 | 100 | T | F | if (star) {
4775 | 50 | T | F | if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
| 0 | T | F | if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
4777 | 50 | T | F | if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
| 50 | T | F | if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
4785 | 50 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
| 0 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
4792 | 100 | T | F | for (i = 0; i < num_terms; i++) {
4794 | 50 | T | F | for (j = 0; j < num_uniq; j++) { if (strcmp(terms[i], uniq_terms[j]) == 0) { found = true; break; } }
| 100 | T | F | for (j = 0; j < num_uniq; j++) { if (strcmp(terms[i], uniq_terms[j]) == 0) { found = true; break; } }
4795 | 50 | T | F | if (!found) uniq_terms[num_uniq++] = savepv(terms[i]);
4802 | 100 | T | F | for (j = 0; j < p; j++) {
4803 | 50 | T | F | if (p_exp + 32 >= exp_cap) {
4808 | 100 | T | F | if (strcmp(uniq_terms[j], "Intercept") == 0) {
4811 | 100 | T | F | if (is_column_categorical(data_hoa, row_hashes, n, uniq_terms[j])) {
4815 | 100 | T | F | for (i = 0; i < n; i++) {
4817 | 50 | T | F | if (str_val) {
4819 | 100 | T | F | for (l = 0; l < num_levels; l++) { if (strcmp(levels[l], str_val) == 0) { found = true; break; } }
| 100 | T | F | for (l = 0; l < num_levels; l++) { if (strcmp(levels[l], str_val) == 0) { found = true; break; } }
4820 | 100 | T | F | if (!found) {
4821 | 50 | T | F | if (num_levels >= levels_cap) { levels_cap *= 2; Renew(levels, levels_cap, char*); }
4827 | 50 | T | F | if (num_levels > 0) {
4828 | 100 | T | F | for (l1 = 0; l1 < num_levels - 1; l1++)
4829 | 100 | T | F | for (l2 = l1 + 1; l2 < num_levels; l2++)
4830 | 100 | T | F | if (strcmp(levels[l1], levels[l2]) > 0) { char *tmp = levels[l1]; levels[l1] = levels[l2]; levels[l2] = tmp; }
4831 | 100 | T | F | for (l = 1; l < num_levels; l++) {
4832 | 50 | T | F | if (p_exp >= exp_cap) {
4845 | 100 | T | F | for (l = 0; l < num_levels; l++) Safefree(levels[l]);
4856 | 50 | T | F | Newx(X, n * p, double); Newx(Y, n, double);
| 50 | T | F | Newx(X, n * p, double); Newx(Y, n, double);
4857 | 50 | T | F | Newx(valid_row_names, n, char*);
4862 | 100 | T | F | for (i = 0; i < n; i++) {
4864 | 100 | T | F | if (isnan(y_val)) { Safefree(row_names[i]); continue; }
4868 | 100 | T | F | for (j = 0; j < p; j++) {
4869 | 100 | T | F | if (strcmp(exp_terms[j], "Intercept") == 0) {
4871 | 100 | T | F | } else if (is_dummy[j]) {
4873 | 50 | T | F | if (str_val) {
4874 | 100 | T | F | row_x[j] = (strcmp(str_val, dummy_level[j]) == 0) ? 1.0 : 0.0;
4879 | 50 | T | F | if (isnan(row_x[j])) { row_ok = false; break; }
4882 | 50 | T | F | if (!row_ok) { Safefree(row_names[i]); Safefree(row_x); continue; }
4885 | 100 | T | F | for (j = 0; j < p; j++) X[valid_n * p + j] = row_x[j];
4892 | 100 | T | F | if (valid_n <= p) {
4893 | 100 | T | F | for (i = 0; i < num_terms; i++) Safefree(terms[i]); Safefree(terms);
4894 | 100 | T | F | for (i = 0; i < num_uniq; i++) Safefree(uniq_terms[i]); Safefree(uniq_terms);
4895 | 100 | T | F | for (j = 0; j < p_exp; j++) {
4897 | 50 | T | F | if (is_dummy[j]) { Safefree(dummy_base[j]); Safefree(dummy_level[j]); }
4901 | 50 | T | F | if (row_hashes) Safefree(row_hashes);
4909 | 100 | T | F | for (i = 0; i < p; i++)
4910 | 100 | T | F | for (j = 0; j < p; j++) {
4912 | 100 | T | F | for (k = 0; k < valid_n; k++) sum += X[k * p + i] * X[k * p + j];
4916 | 100 | T | F | for (i = 0; i < p; i++) {
4918 | 100 | T | F | for (k = 0; k < valid_n; k++) sum += X[k * p + i] * Y[k];
4924 | 100 | T | F | for (i = 0; i < p; i++) {
4925 | 100 | T | F | if (aliased[i]) { beta[i] = NAN; }
4928 | 100 | T | F | for (j = 0; j < p; j++) if (!aliased[j]) sum += XtX[i * p + j] * XtY[j];
| 100 | T | F | for (j = 0; j < p; j++) if (!aliased[j]) sum += XtX[i * p + j] * XtY[j];
4943 | 100 | T | F | for (i = 0; i < valid_n; i++) sum_y += Y[i];
4946 | 100 | T | F | for (i = 0; i < valid_n; i++) {
4948 | 100 | T | F | for (j = 0; j < p; j++) if (!aliased[j]) y_hat += X[i * p + j] * beta[j];
| 100 | T | F | for (j = 0; j < p; j++) if (!aliased[j]) y_hat += X[i * p + j] * beta[j];
4951 | 100 | T | F | double diff_m = has_intercept ? (y_hat - mean_y) : y_hat;
4960 | 50 | T | F | rse_sq = (df_res > 0) ? (rss / (double)df_res) : NAN;
4966 | 50 | T | F | if (final_rank != df_int && (mss + rss) > 0.0) {
| 50 | T | F | if (final_rank != df_int && (mss + rss) > 0.0) {
4969 | 50 | T | F | if (rse_sq > 0.0 && numdf > 0) {
| 50 | T | F | if (rse_sq > 0.0 && numdf > 0) {
4972 | 0 | T | F | } else if (rse_sq == 0.0) {
4976 | 0 | T | F | } else if (final_rank == df_int) {
4980 | 100 | T | F | for (j = 0; j < p; j++) {
4984 | 100 | T | F | if (aliased[j]) {
4991 | 50 | T | F | double t_val = (se > 0.0) ? (beta[j] / se) : (INFINITY * (beta[j] >= 0.0 ? 1.0 : -1.0));
| 0 | T | F | double t_val = (se > 0.0) ? (beta[j] / se) : (INFINITY * (beta[j] >= 0.0 ? 1.0 : -1.0));
5011 | 50 | T | F | if (!isnan(f_stat)) {
5021 | 100 | T | F | for (i = 0; i < num_terms; i++) Safefree(terms[i]); Safefree(terms);
5022 | 100 | T | F | for (i = 0; i < num_uniq; i++) Safefree(uniq_terms[i]); Safefree(uniq_terms);
5023 | 100 | T | F | for (j = 0; j < p_exp; j++) {
5025 | 100 | T | F | if (is_dummy[j]) { Safefree(dummy_base[j]); Safefree(dummy_level[j]); }
5030 | 100 | T | F | if (row_hashes) Safefree(row_hashes);
5044 | 50 | T | F | if (by == 0.0) {
5045 | 0 | T | F | if (from == to) {
5046 | 0 | T | F | EXTEND(SP, 1);
5054 | 100 | T | F | if ((from < to && by < 0.0) || (from > to && by > 0.0)) {
| 50 | T | F | if ((from < to && by < 0.0) || (from > to && by > 0.0)) {
| 100 | T | F | if ((from < to && by < 0.0) || (from > to && by > 0.0)) {
| 50 | T | F | if ((from < to && by < 0.0) || (from > to && by > 0.0)) {
5062 | 50 | T | F | if (n_elements_d < 0.0) n_elements_d = 0.0;
5065 | 50 | T | F | EXTEND(SP, n_elements);
5066 | 100 | T | F | for (size_t i = 0; i < n_elements; i++) {
5076 | 100 | T | F | AUTO_SEED_PRNG();
5083 | 50 | T | F | if (items > 0 && SvIOK(ST(0)) && (items == 1 || items % 2 != 0)) {
| 50 | T | F | if (items > 0 && SvIOK(ST(0)) && (items == 1 || items % 2 != 0)) {
| 0 | T | F | if (items > 0 && SvIOK(ST(0)) && (items == 1 || items % 2 != 0)) {
| 0 | T | F | if (items > 0 && SvIOK(ST(0)) && (items == 1 || items % 2 != 0)) {
5089 | 50 | T | F | if ((items - arg_start) % 2 != 0) {
5093 | 100 | T | F | for (int i = arg_start; i < items; i += 2) {
5097 | 100 | T | F | if (strEQ(key, "n")) n = (unsigned int)SvUV(val);
5098 | 100 | T | F | else if (strEQ(key, "mean")) mean = SvNV(val);
5099 | 50 | T | F | else if (strEQ(key, "sd")) sd = SvNV(val);
5103 | 100 | T | F | if (sd < 0.0) croak("rnorm: standard deviation must be non-negative");
5106 | 50 | T | F | if (n > 0) {
5109 | 100 | T | F | for (size_t i = 0; i < n; ) {
5116 | 100 | T | F | } while (s >= 1.0 || s == 0.0);
| 50 | T | F | } while (s >= 1.0 || s == 0.0);
5121 | 100 | T | F | if (i < n) {
5156 | 50 | T | F | if (!SvROK(data_sv)) croak("aov: data is required and must be a reference");
5162 | 50 | T | F | if (SvTYPE(ref) == SVt_PVHV) {
5164 | 50 | T | F | if (hv_iterinit(hv) == 0) croak("aov: Data hash is empty");
5166 | 50 | T | F | if (entry) {
5168 | 50 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
| 50 | T | F | if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVAV) {
5171 | 50 | T | F | Newx(row_names, n, char*);
5172 | 100 | T | F | for(i = 0; i < n; i++) {
5176 | 0 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
| 0 | T | F | } else if (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVHV) {
5178 | 0 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
| 0 | T | F | Newx(row_names, n, char*); Newx(row_hashes, n, HV*);
5180 | 0 | T | F | while ((entry = hv_iternext(hv))) {
5188 | 0 | T | F | } else if (SvTYPE(ref) == SVt_PVAV) {
5191 | 0 | T | F | Newx(row_names, n, char*);
5192 | 0 | T | F | Newx(row_hashes, n, HV*);
5193 | 0 | T | F | for (i = 0; i < n; i++) {
5195 | 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
| 0 | T | F | if (val && SvROK(*val) && SvTYPE(SvRV(*val)) == SVt_PVHV) {
5201 | 0 | T | F | for (size_t k = 0; k < i; k++) Safefree(row_names[k]);
5212 | 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 100 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
| 50 | T | F | while (*src && (dst - f_cpy < 511)) { if (!isspace(*src)) { *dst++ = *src; } src++; }
5216 | 100 | T | F | if (!tilde) {
5217 | 100 | T | F | for (i = 0; i < n; i++) Safefree(row_names[i]);
5218 | 50 | T | F | Safefree(row_names); if (row_hashes) Safefree(row_hashes);
5226 | 50 | T | F | while ((p_idx = strstr(rhs, "-1")) != NULL) { has_intercept = false; memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); }
5227 | 50 | T | F | while ((p_idx = strstr(rhs, "+0")) != NULL) { has_intercept = false; memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); }
5228 | 50 | T | F | while ((p_idx = strstr(rhs, "0+")) != NULL) { has_intercept = false; memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); }
5229 | 50 | T | F | if (rhs[0] == '0' && rhs[1] == '\0') { has_intercept = false; rhs[0] = '\0'; }
| 0 | T | F | if (rhs[0] == '0' && rhs[1] == '\0') { has_intercept = false; rhs[0] = '\0'; }
5230 | 50 | T | F | while ((p_idx = strstr(rhs, "+1")) != NULL) { memmove(p_idx, p_idx + 2, strlen(p_idx + 2) + 1); }
5231 | 50 | T | F | if (rhs[0] == '1' && rhs[1] == '\0') { rhs[0] = '\0'; }
| 0 | T | F | if (rhs[0] == '1' && rhs[1] == '\0') { rhs[0] = '\0'; }
5232 | 50 | T | F | else if (rhs[0] == '1' && rhs[1] == '+') { memmove(rhs, rhs + 2, strlen(rhs + 2) + 1); }
| 0 | T | F | else if (rhs[0] == '1' && rhs[1] == '+') { memmove(rhs, rhs + 2, strlen(rhs + 2) + 1); }
5234 | 50 | T | F | while ((p_idx = strstr(rhs, "++")) != NULL) memmove(p_idx, p_idx + 1, strlen(p_idx + 1) + 1);
5235 | 50 | T | F | if (rhs[0] == '+') memmove(rhs, rhs + 1, strlen(rhs + 1) + 1);
5237 | 50 | T | F | if (len_rhs > 0 && rhs[len_rhs - 1] == '+') rhs[len_rhs - 1] = '\0';
| 50 | T | F | if (len_rhs > 0 && rhs[len_rhs - 1] == '+') rhs[len_rhs - 1] = '\0';
5242 | 100 | T | F | while (chunk != NULL) {
5243 | 100 | T | F | if (strcmp(chunk, ".") == 0) {
5245 | 100 | T | F | for (size_t c = 0; c <= av_len(cols); c++) {
5247 | 50 | T | F | if (col_sv && SvOK(*col_sv)) {
| 50 | T | F | if (col_sv && SvOK(*col_sv)) {
5249 | 100 | T | F | if (strcmp(col_name, lhs) != 0) {
5251 | 50 | T | F | if (rhs_len + slen + 2 < sizeof(rhs_expanded)) {
5252 | 100 | T | F | if (rhs_len > 0) { strcat(rhs_expanded, "+"); rhs_len++; }
5262 | 50 | T | F | if (rhs_len + slen + 2 < sizeof(rhs_expanded)) {
5263 | 100 | T | F | if (rhs_len > 0) { strcat(rhs_expanded, "+"); rhs_len++; }
5279 | 50 | T | F | if (has_intercept) { terms[num_terms++] = savepv("Intercept"); }
5281 | 50 | T | F | if (strlen(rhs_expanded) > 0) {
5283 | 100 | T | F | while (chunk != NULL) {
5284 | 50 | T | F | if (num_terms >= term_cap - 3) {
5289 | 100 | T | F | if (star) {
5294 | 50 | T | F | if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
| 0 | T | F | if (c_l && strncmp(left, "I(", 2) != 0) *c_l = '\0';
5295 | 50 | T | F | char *restrict c_r = strchr(right, '^'); if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
| 0 | T | F | char *restrict c_r = strchr(right, '^'); if (c_r && strncmp(right, "I(", 2) != 0) *c_r = '\0';
5303 | 50 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
| 0 | T | F | if (c_chunk && strncmp(chunk, "I(", 2) != 0) *c_chunk = '\0';
5310 | 100 | T | F | for (i = 0; i < num_terms; i++) {
5312 | 100 | T | F | for (size_t k = 0; k < num_uniq; k++) {
5313 | 50 | T | F | if (strcmp(terms[i], uniq_terms[k]) == 0) { found = true; break; }
5315 | 50 | T | F | if (!found) uniq_terms[num_uniq++] = savepv(terms[i]);
5322 | 100 | T | F | for (j = 0; j < p; j++) {
5323 | 100 | T | F | if (p_exp + 64 >= exp_cap) {
5331 | 100 | T | F | if (strcmp(uniq_terms[j], "Intercept") == 0) {
5341 | 100 | T | F | if (colon) {
5349 | 100 | T | F | for (size_t e = 0; e < p_exp; e++) {
5350 | 100 | T | F | if (strcmp(parent_term[e], left) == 0) l_indices[l_count++] = e;
5351 | 100 | T | F | if (strcmp(parent_term[e], right) == 0) r_indices[r_count++] = e;
5354 | 100 | T | F | if (l_count == 0 || r_count == 0) {
| 50 | T | F | if (l_count == 0 || r_count == 0) {
5358 | 100 | T | F | for (int li = 0; li < l_count; li++) {
5359 | 100 | T | F | for (int ri = 0; ri < r_count; ri++) {
5360 | 50 | T | F | if (p_exp >= exp_cap) {
5381 | 100 | T | F | if (is_column_categorical(data_hoa, row_hashes, n, uniq_terms[j])) {
5385 | 100 | T | F | for (i = 0; i < n; i++) {
5387 | 50 | T | F | if (str_val) {
5389 | 100 | T | F | for (size_t l = 0; l < num_levels; l++) {
5390 | 100 | T | F | if (strcmp(levels[l], str_val) == 0) { found = true; break; }
5392 | 100 | T | F | if (!found) {
5393 | 50 | T | F | if (num_levels >= levels_cap) { levels_cap *= 2; Renew(levels, levels_cap, char*); }
5400 | 50 | T | F | if (num_levels > 0) {
5401 | 100 | T | F | for (size_t l1 = 0; l1 < num_levels - 1; l1++) {
5402 | 100 | T | F | for (size_t l2 = l1 + 1; l2 < num_levels; l2++) {
5403 | 100 | T | F | if (strcmp(levels[l1], levels[l2]) > 0) {
5408 | 100 | T | F | for (size_t l = 1; l < num_levels; l++) {
5409 | 50 | T | F | if (p_exp >= exp_cap) {
5426 | 100 | T | F | for (size_t l = 0; l < num_levels; l++) Safefree(levels[l]);
5446 | 100 | T | F | for(i = 0; i < n; i++) X_mat[i] = (double*)safemalloc(p_exp * sizeof(double));
5447 | 50 | T | F | Newx(Y, n, double);
5451 | 100 | T | F | for (i = 0; i < n; i++) {
5453 | 50 | T | F | if (isnan(y_val)) { Safefree(row_names[i]); continue; }
5456 | 100 | T | F | for (j = 0; j < p_exp; j++) {
5457 | 100 | T | F | if (strcmp(exp_terms[j], "Intercept") == 0) {
5459 | 100 | T | F | } else if (is_interact[j]) {
5461 | 100 | T | F | } else if (is_dummy[j]) {
5463 | 50 | T | F | if (str_val) {
5464 | 100 | T | F | row_x[j] = (strcmp(str_val, dummy_level[j]) == 0) ? 1.0 : 0.0;
5469 | 50 | T | F | if (isnan(row_x[j])) { row_ok = false; break; }
5472 | 50 | T | F | if (!row_ok) { Safefree(row_names[i]); Safefree(row_x); continue; }
5475 | 100 | T | F | for (j = 0; j < p_exp; j++) X_mat[valid_n][j] = row_x[j];
5481 | 100 | T | F | if (valid_n <= p_exp) {
5483 | 100 | T | F | for (i = 0; i < num_terms; i++) Safefree(terms[i]); Safefree(terms);
5484 | 100 | T | F | for (i = 0; i < num_uniq; i++) Safefree(uniq_terms[i]); Safefree(uniq_terms);
5485 | 100 | T | F | for (j = 0; j < p_exp; j++) {
5487 | 50 | T | F | if (is_dummy[j]) { Safefree(dummy_base[j]); Safefree(dummy_level[j]); }
5493 | 100 | T | F | for(i = 0; i < n; i++) Safefree(X_mat[i]);
5495 | 50 | T | F | if (row_hashes) Safefree(row_hashes);
5509 | 100 | T | F | for (i = 0; i < p_exp; i++) {
5510 | 100 | T | F | if (strcmp(exp_terms[i], "Intercept") == 0) continue;
5511 | 100 | T | F | if (aliased_qr[i]) continue;
5518 | 100 | T | F | for (i = 0; i < p_exp; i++) {
5519 | 100 | T | F | if (!aliased_qr[i]) rank++;
5522 | 100 | T | F | for (i = rank; i < valid_n; i++) {
5526 | 50 | T | F | double ms_res = (res_df > 0) ? rss_prev / res_df : 0.0;
5529 | 100 | T | F | for (j = 0; j < num_uniq; j++) {
5530 | 100 | T | F | if (strcmp(uniq_terms[j], "Intercept") == 0) continue;
5534 | 100 | T | F | double ms = (df > 0) ? ss / df : 0.0;
5539 | 50 | T | F | if (ms_res > 0.0 && df > 0) {
| 100 | T | F | if (ms_res > 0.0 && df > 0) {
5557 | 100 | T | F | for (i = 0; i < num_terms; i++) Safefree(terms[i]); Safefree(terms);
5558 | 100 | T | F | for (i = 0; i < num_uniq; i++) Safefree(uniq_terms[i]); Safefree(uniq_terms);
5559 | 100 | T | F | for (j = 0; j < p_exp; j++) {
5561 | 100 | T | F | if (is_dummy[j]) { Safefree(dummy_base[j]); Safefree(dummy_level[j]); }
5568 | 100 | T | F | for (i = 0; i < n; i++) Safefree(X_mat[i]);
5571 | 50 | T | F | if (row_hashes) Safefree(row_hashes);
5582 | 100 | T | F | if (items < 1) croak("fisher_test requires at least a data reference");
5589 | 100 | T | F | for (unsigned short int i = 1; i < items; i += 2) {
5590 | 50 | T | F | if (i + 1 >= items) croak("fisher_test: odd number of arguments");
5593 | 50 | T | F | if (strEQ(key, "conf_level") || strEQ(key, "conf.level")) {
| 50 | T | F | if (strEQ(key, "conf_level") || strEQ(key, "conf.level")) {
5595 | 50 | T | F | } else if (strEQ(key, "alternative")) {
5600 | 50 | T | F | if (!SvROK(data_ref)) croak("fisher_test requires a reference to an Array or Hash");
5604 | 100 | T | F | if (SvTYPE(deref) == SVt_PVAV) {
5606 | 50 | T | F | if (av_len(outer) != 1) croak("Outer array must have exactly 2 rows");
5609 | 50 | T | F | if (row1_ptr && row2_ptr && SvROK(*row1_ptr) && SvROK(*row2_ptr)) {
| 50 | T | F | if (row1_ptr && row2_ptr && SvROK(*row1_ptr) && SvROK(*row2_ptr)) {
| 50 | T | F | if (row1_ptr && row2_ptr && SvROK(*row1_ptr) && SvROK(*row2_ptr)) {
| 50 | T | F | if (row1_ptr && row2_ptr && SvROK(*row1_ptr) && SvROK(*row2_ptr)) {
5616 | 50 | T | F | a = (a_ptr && SvOK(*a_ptr)) ? SvIV(*a_ptr) : 0;
| 50 | T | F | a = (a_ptr && SvOK(*a_ptr)) ? SvIV(*a_ptr) : 0;
5617 | 50 | T | F | b = (b_ptr && SvOK(*b_ptr)) ? SvIV(*b_ptr) : 0;
| 50 | T | F | b = (b_ptr && SvOK(*b_ptr)) ? SvIV(*b_ptr) : 0;
5618 | 50 | T | F | c = (c_ptr && SvOK(*c_ptr)) ? SvIV(*c_ptr) : 0;
| 50 | T | F | c = (c_ptr && SvOK(*c_ptr)) ? SvIV(*c_ptr) : 0;
5619 | 50 | T | F | d = (d_ptr && SvOK(*d_ptr)) ? SvIV(*d_ptr) : 0;
| 50 | T | F | d = (d_ptr && SvOK(*d_ptr)) ? SvIV(*d_ptr) : 0;
5623 | 50 | T | F | } else if (SvTYPE(deref) == SVt_PVHV) {
5626 | 50 | T | F | if (hv_iterinit(outer) != 2) croak("Outer hash must have exactly 2 keys");
5629 | 50 | T | F | if (!he1 || !he2) croak("Invalid outer hash");
| 50 | T | F | if (!he1 || !he2) croak("Invalid outer hash");
5632 | 100 | T | F | HE*restrict row1_he = (strcmp(k1, k2) < 0) ? he1 : he2;
5633 | 100 | T | F | HE*restrict row2_he = (strcmp(k1, k2) < 0) ? he2 : he1;
5636 | 50 | T | F | if (!SvROK(row1_sv) || SvTYPE(SvRV(row1_sv)) != SVt_PVHV ||
| 50 | T | F | if (!SvROK(row1_sv) || SvTYPE(SvRV(row1_sv)) != SVt_PVHV ||
5637 | 50 | T | F | !SvROK(row2_sv) || SvTYPE(SvRV(row2_sv)) != SVt_PVHV) {
| 50 | T | F | !SvROK(row2_sv) || SvTYPE(SvRV(row2_sv)) != SVt_PVHV) {
5642 | 50 | T | F | if (hv_iterinit(in1) != 2 || hv_iterinit(in2) != 2) croak("Inner hashes must have exactly 2 keys");
| 50 | T | F | if (hv_iterinit(in1) != 2 || hv_iterinit(in2) != 2) croak("Inner hashes must have exactly 2 keys");
5647 | 100 | T | F | HE*restrict in1_c1 = (strcmp(in1_k1, in1_k2) < 0) ? in1_he1 : in1_he2;
5648 | 100 | T | F | HE*restrict in1_c2 = (strcmp(in1_k1, in1_k2) < 0) ? in1_he2 : in1_he1;
5653 | 100 | T | F | HE*restrict in2_c1 = (strcmp(in2_k1, in2_k2) < 0) ? in2_he1 : in2_he2;
5654 | 100 | T | F | HE*restrict in2_c2 = (strcmp(in2_k1, in2_k2) < 0) ? in2_he2 : in2_he1;
5655 | 50 | T | F | a = (hv_iterval(in1, in1_c1) && SvOK(hv_iterval(in1, in1_c1))) ? SvIV(hv_iterval(in1, in1_c1)) : 0;
| 50 | T | F | a = (hv_iterval(in1, in1_c1) && SvOK(hv_iterval(in1, in1_c1))) ? SvIV(hv_iterval(in1, in1_c1)) : 0;
5656 | 50 | T | F | b = (hv_iterval(in1, in1_c2) && SvOK(hv_iterval(in1, in1_c2))) ? SvIV(hv_iterval(in1, in1_c2)) : 0;
| 50 | T | F | b = (hv_iterval(in1, in1_c2) && SvOK(hv_iterval(in1, in1_c2))) ? SvIV(hv_iterval(in1, in1_c2)) : 0;
5657 | 50 | T | F | c = (hv_iterval(in2, in2_c1) && SvOK(hv_iterval(in2, in2_c1))) ? SvIV(hv_iterval(in2, in2_c1)) : 0;
| 50 | T | F | c = (hv_iterval(in2, in2_c1) && SvOK(hv_iterval(in2, in2_c1))) ? SvIV(hv_iterval(in2, in2_c1)) : 0;
5658 | 50 | T | F | d = (hv_iterval(in2, in2_c2) && SvOK(hv_iterval(in2, in2_c2))) ? SvIV(hv_iterval(in2, in2_c2)) : 0;
| 50 | T | F | d = (hv_iterval(in2, in2_c2) && SvOK(hv_iterval(in2, in2_c2))) ? SvIV(hv_iterval(in2, in2_c2)) : 0;
5700 | 50 | T | F | if (items % 2 != 0) croak("Usage: power_t_test(n => 30, delta => 0.5, sd => 1.0, ...)");
5701 | 100 | T | F | for (unsigned short int i = 0; i < items; i += 2) {
5705 | 100 | T | F | if (strEQ(key, "n")) sv_n = val;
5706 | 100 | T | F | else if (strEQ(key, "delta")) sv_delta = val;
5707 | 100 | T | F | else if (strEQ(key, "sd")) sv_sd = val;
5708 | 50 | T | F | else if (strEQ(key, "sig.level") || strEQ(key, "sig_level")) sv_sig_level = val;
| 100 | T | F | else if (strEQ(key, "sig.level") || strEQ(key, "sig_level")) sv_sig_level = val;
5709 | 100 | T | F | else if (strEQ(key, "power")) sv_power = val;
5710 | 100 | T | F | else if (strEQ(key, "type")) type = SvPV_nolen(val);
5711 | 50 | T | F | else if (strEQ(key, "alternative")) alternative = SvPV_nolen(val);
5712 | 0 | T | F | else if (strEQ(key, "strict")) strict = SvTRUE(val);
5713 | 0 | T | F | else if (strEQ(key, "tol")) tol = SvNV(val);
5717 | 100 | T | F | bool is_null_n = (!sv_n || !SvOK(sv_n));
| 50 | T | F | bool is_null_n = (!sv_n || !SvOK(sv_n));
5718 | 50 | T | F | bool is_null_delta = (!sv_delta || !SvOK(sv_delta));
| 50 | T | F | bool is_null_delta = (!sv_delta || !SvOK(sv_delta));
5719 | 100 | T | F | bool is_null_power = (!sv_power || !SvOK(sv_power));
| 50 | T | F | bool is_null_power = (!sv_power || !SvOK(sv_power));
5720 | 50 | T | F | bool is_null_sd = (sv_sd && !SvOK(sv_sd));
| 50 | T | F | bool is_null_sd = (sv_sd && !SvOK(sv_sd));
5721 | 100 | T | F | bool is_null_sig_level = (sv_sig_level && !SvOK(sv_sig_level));
| 50 | T | F | bool is_null_sig_level = (sv_sig_level && !SvOK(sv_sig_level));
5724 | 100 | T | F | if (is_null_n) missing_count++;
5725 | 50 | T | F | if (is_null_delta) missing_count++;
5726 | 100 | T | F | if (is_null_power) missing_count++;
5727 | 50 | T | F | if (is_null_sd) missing_count++;
5728 | 50 | T | F | if (is_null_sig_level) missing_count++;
5730 | 50 | T | F | if (missing_count != 1) {
5734 | 100 | T | F | double n = is_null_n ? 0.0 : SvNV(sv_n);
5735 | 50 | T | F | double delta = is_null_delta ? 0.0 : SvNV(sv_delta);
5736 | 50 | T | F | double sd = (!sv_sd || is_null_sd) ? 1.0 : SvNV(sv_sd);
| 50 | T | F | double sd = (!sv_sd || is_null_sd) ? 1.0 : SvNV(sv_sd);
5737 | 100 | T | F | double sig_level = (!sv_sig_level || is_null_sig_level) ? 0.05 : SvNV(sv_sig_level);
| 50 | T | F | double sig_level = (!sv_sig_level || is_null_sig_level) ? 0.05 : SvNV(sv_sig_level);
5738 | 100 | T | F | double power = is_null_power ? 0.0 : SvNV(sv_power);
5739 | 100 | T | F | short int tsample = (strEQ(type, "one.sample") || strEQ(type, "paired")) ? 1 : 2;
| 100 | T | F | short int tsample = (strEQ(type, "one.sample") || strEQ(type, "paired")) ? 1 : 2;
5740 | 100 | T | F | short int tside = (strEQ(alternative, "one.sided") || strEQ(alternative, "greater") || strEQ(alternative, "less")) ? 1 : 2;
| 50 | T | F | short int tside = (strEQ(alternative, "one.sided") || strEQ(alternative, "greater") || strEQ(alternative, "less")) ? 1 : 2;
| 50 | T | F | short int tside = (strEQ(alternative, "one.sided") || strEQ(alternative, "greater") || strEQ(alternative, "less")) ? 1 : 2;
5741 | 100 | T | F | if (tside == 2 && !is_null_delta) delta = fabs(delta);
| 50 | T | F | if (tside == 2 && !is_null_delta) delta = fabs(delta);
5742 | 100 | T | F | if (is_null_power) {
5744 | 50 | T | F | } else if (is_null_n) {
5746 | 50 | T | F | while (p_body(high, delta, sd, sig_level, tsample, tside, strict) < power && high < 1e12) high *= 2.0;
| 0 | T | F | while (p_body(high, delta, sd, sig_level, tsample, tside, strict) < power && high < 1e12) high *= 2.0;
5747 | 100 | T | F | while (high - low > tol) {
5749 | 100 | T | F | if (p_body(mid, delta, sd, sig_level, tsample, tside, strict) < power) low = mid;
5753 | 0 | T | F | } else if (is_null_sd) {
5755 | 0 | T | F | while (high - low > tol) {
5757 | 0 | T | F | if (p_body(n, delta, mid, sig_level, tsample, tside, strict) > power) low = mid;
5761 | 0 | T | F | } else if (is_null_delta) {
5763 | 0 | T | F | while (p_body(n, high, sd, sig_level, tsample, tside, strict) < power && high < 1e12) high *= 2.0;
| 0 | T | F | while (p_body(n, high, sd, sig_level, tsample, tside, strict) < power && high < 1e12) high *= 2.0;
5764 | 0 | T | F | while (high - low > tol) {
5766 | 0 | T | F | if (p_body(n, mid, sd, sig_level, tsample, tside, strict) < power) low = mid;
5770 | 0 | T | F | } else if (is_null_sig_level) {
5772 | 0 | T | F | while (high - low > tol) {
5774 | 0 | T | F | if (p_body(n, delta, sd, mid, tsample, tside, strict) < power) low = mid;
5786 | 100 | T | F | const char*restrict m_str = (tsample == 1) ? (strEQ(type, "paired") ? "Paired t test power calculation" : "One-sample t test power calculation") : "Two-sample t test power calculation";
| 100 | T | F | const char*restrict m_str = (tsample == 1) ? (strEQ(type, "paired") ? "Paired t test power calculation" : "One-sample t test power calculation") : "Two-sample t test power calculation";
5788 | 100 | T | F | const char*restrict n_str = (tsample == 2) ? "n is number in *each* group" : (strEQ(type, "paired") ? "n is number of *pairs*, sd is std.dev. of *differences* within pairs" : "");
| 100 | T | F | const char*restrict n_str = (tsample == 2) ? "n is number in *each* group" : (strEQ(type, "paired") ? "n is number of *pairs*, sd is std.dev. of *differences* within pairs" : "");
5789 | 100 | T | F | if (n_str[0] != '\0') hv_stores(ret, "note", newSVpv(n_str, 0));
5803 | 50 | T | F | if (arg_idx < items && SvROK(ST(arg_idx))) {
| 100 | T | F | if (arg_idx < items && SvROK(ST(arg_idx))) {
5805 | 100 | T | F | if (t == SVt_PVAV) {
5807 | 50 | T | F | } else if (t == SVt_PVHV) {
5811 | 100 | T | F | if (!h_sv && arg_idx < items
| 50 | T | F | if (!h_sv && arg_idx < items
5812 | 100 | T | F | && SvROK(ST(arg_idx))
5813 | 50 | T | F | && SvTYPE(SvRV(ST(arg_idx))) == SVt_PVAV) {
5817 | 100 | T | F | for (; arg_idx < items; arg_idx += 2) {
5820 | 100 | T | F | if (strEQ(key, "x")) x_sv = val;
5821 | 50 | T | F | else if (strEQ(key, "g")) g_sv = val;
5822 | 0 | T | F | else if (strEQ(key, "h")) h_sv = val;
5826 | 100 | T | F | if (h_sv && (x_sv || g_sv))
| 50 | T | F | if (h_sv && (x_sv || g_sv))
| 50 | T | F | if (h_sv && (x_sv || g_sv))
5838 | 100 | T | F | if (h_sv) {
5839 | 50 | T | F | if (!SvROK(h_sv) || SvTYPE(SvRV(h_sv)) != SVt_PVHV)
| 50 | T | F | if (!SvROK(h_sv) || SvTYPE(SvRV(h_sv)) != SVt_PVHV)
5846 | 100 | T | F | while ((he = hv_iternext(h_hv))) {
5848 | 50 | T | F | if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV)
| 50 | T | F | if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV)
5852 | 50 | T | F | if (total < 2) croak("not enough observations");
5859 | 100 | T | F | while ((he = hv_iternext(h_hv))) {
5862 | 100 | T | F | for (size_t i = 0; i < n_g; i++) {
5864 | 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
| 50 | T | F | if (el && SvOK(*el) && looks_like_number(*el)) {
5878 | 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
| 50 | T | F | if (!x_sv || !SvROK(x_sv) || SvTYPE(SvRV(x_sv)) != SVt_PVAV)
5880 | 50 | T | F | if (!g_sv || !SvROK(g_sv) || SvTYPE(SvRV(g_sv)) != SVt_PVAV)
| 50 | T | F | if (!g_sv || !SvROK(g_sv) || SvTYPE(SvRV(g_sv)) != SVt_PVAV)
| 50 | T | F | if (!g_sv || !SvROK(g_sv) || SvTYPE(SvRV(g_sv)) != SVt_PVAV)
5887 | 50 | T | F | if (nx != ng) croak("kruskal_test: 'x' and 'g' must have the same length");
5888 | 50 | T | F | if (nx < 2) croak("not enough observations");
5896 | 100 | T | F | for (size_t i = 0; i < nx; i++) {
5899 | 50 | T | F | if (x_el && SvOK(*x_el) && looks_like_number(*x_el)
| 50 | T | F | if (x_el && SvOK(*x_el) && looks_like_number(*x_el)
| 50 | T | F | if (x_el && SvOK(*x_el) && looks_like_number(*x_el)
5900 | 50 | T | F | && g_el && SvOK(*g_el)) {
| 50 | T | F | && g_el && SvOK(*g_el)) {
5905 | 100 | T | F | if (id_sv) {
5923 | 50 | T | F | if (valid_n < 2) { Safefree(ri); croak("not enough observations"); }
5924 | 50 | T | F | if (k < 2) { Safefree(ri); croak("all observations are in the same group"); }
5933 | 100 | T | F | for (size_t i = 0; i < valid_n; i++) {
5941 | 100 | T | F | for (size_t i = 0; i < k; i++) {
5942 | 50 | T | F | if (group_counts[i] > 0)
5950 | 50 | T | F | if (tie_adj > 0.0) {