This document describes the statistical methods used in Phi Statistics Drawer v3.0.1. The goal is transparent reporting of the calculations, assumptions, and implementation choices used by each plotting tool.
1. Data Handling
The tools accept either manual table input or imported spreadsheet data. CSV and delimited text files are parsed by detecting tab, semicolon, or comma delimiters. For Excel workbooks with multiple worksheets, select a worksheet and confirm its preview before importing. A workbook with one worksheet is imported directly. Worksheets are not combined. The first row of the used worksheet range is interpreted as the header row. Duplicate or empty column names are made unique without overwriting existing names or values; data columns beyond a shorter header row are retained. Project files store the selected table and worksheet name, not the entire workbook.
Numeric Excel cells are imported using their stored value, independently of thousands separators, display rounding, currency symbols, or percentage formatting. For example, a cell displayed as 25% supplies the value 0.25. Lossless numeric formatting, such as a zero-padded identifier, is retained where it gives exactly the same numeric value. Text cells, headers, and date/time displays are kept as text; ambiguous numeric text follows the parsing rules below. Formula cells use the result stored in the workbook; Phi does not recalculate Excel formulas.
Numeric entries are parsed after trimming whitespace and accepting a decimal comma or decimal point. Values that cannot be parsed as finite numbers are treated as missing for numeric calculations.
Missing or invalid values are handled by complete-case inclusion for the variables required by the selected tool. In practice, rows with missing required fields are ignored for that calculation and a warning reports the number and type of ignored rows where applicable. The application does not impute missing values and does not silently replace missing values with zero.
2. Kaplan–Meier Survival Analysis
The Kaplan–Meier module implements the standard product-limit estimator, Greenwood variance, and pointwise log–log 95% confidence intervals for right-censored time-to-event data.
2.1 Event Definition
The user selects a time column, a status column, and an event code. A row is treated as an event when the status value matches the configured event code. A non-empty status value that does not match the event code is treated as censored. Rows with missing time, negative time, or missing status are ignored. If no group is supplied, the row is assigned to a default group.
2.2 Kaplan–Meier Estimator
For each group, let \(t_i\) denote follow-up time and \(\delta_i\) the event indicator, where \(\delta_i = 1\) denotes an event and \(\delta_i = 0\) denotes censoring. At each unique event time \(t_j\):
- \(n_j\): number of individuals at risk just before time \(t_j\)
- \(d_j\): number of events at time \(t_j\)
\( S(t_j) = S(t_{j-1}) \cdot \frac{n_j - d_j}{n_j}, \quad S(0) = 1. \)
The curve is drawn as a step function and remains constant between event times. Censored observations are displayed at the survival value active at their censoring time.
2.3 Risk Sets
The risk set at time \(t\) is:
\( n(t) = \#\{ i : \text{follow-up time}_i \ge t \}. \)
This same definition is used for the patients-at-risk table. The table can be shown as a separate table view or embedded below the plot; both use the same risk-set calculation at the displayed time points.
2.4 Greenwood Variance and Log–log Confidence Intervals
Greenwood’s variance estimator is:
\( \mathrm{Var}\bigl(S(t_j)\bigr) = S(t_j)^2 \sum_{k \le j} \frac{d_k}{n_k (n_k - d_k)}. \)
The confidence interval is computed on the log–log scale, corresponding to the
conf.type = "log-log" option in R’s survival package for
survfit. With
\(S_j = S(t_j)\) and \(V_j = \mathrm{Var}(S_j)\):
\( z_j = \log\bigl(-\log(S_j)\bigr), \quad SE(z_j) = \frac{\sqrt{V_j}}{S_j \cdot |\log(S_j)|}. \)
\( z_j \pm 1.96 \cdot SE(z_j). \)
The lower and upper limits are transformed back to the survival scale and constrained to \([0,1]\). Confidence shadows show these pointwise limits as a stepwise band; they are not simultaneous confidence bands. At survival probabilities of 0 or 1, the implementation reports a collapsed interval at that value.
The alternative incidence view displays the complement of the Kaplan–Meier estimate, \(1 - S(t)\), with interval limits \([1 - U(t), 1 - L(t)]\), where \(L(t)\) and \(U(t)\) are the survival confidence limits. It does not fit a competing-risks model.
3. Forest Plot
The forest plot module is a visualization tool for user-supplied point estimates and intervals. It does not estimate odds ratios, risk ratios, hazard ratios, mean differences, or confidence intervals. It also does not perform pooling, weighting, hypothesis testing, or meta-analysis.
3.1 Input Data
For each row, the user supplies a label, a point estimate, a lower interval limit, and an upper interval limit. Rows are ignored if the label is missing, an estimate or interval limit is invalid, or the lower limit is greater than the upper limit.
3.2 Ratio and Difference Scales
The tool supports two effect-type presets:
- Ratio effects: typical for OR, RR, or HR values. The default reference value is 1 and the default x-axis scale is logarithmic.
- Difference effects: typical for mean differences or risk differences. The default reference value is 0 and the default x-axis scale is linear.
Logarithmic axes require strictly positive estimate and interval values. Non-positive values are ignored when a logarithmic axis is selected because they cannot be represented on that scale.
3.3 Plotting Method
The central estimate is plotted as a point symbol. The supplied lower and upper limits are plotted as a horizontal interval line. Optional vertical caps at the ends of the interval are visual markers only and do not alter the interval values.
4. ROC / AUC Analysis
The ROC / AUC tool evaluates one or more numeric marker columns against a binary outcome. The user defines the positive outcome class. Any non-empty outcome value that does not match the positive class is treated as the negative class, so the outcome variable should be binary before analysis.
4.1 ROC Curve
For each marker, thresholds are evaluated across the unique observed marker scores. Depending on the selected direction, a predicted positive result is defined as either:
\( \text{score} \ge c \quad \text{or} \quad \text{score} \le c. \)
At each threshold \(c\), sensitivity and specificity are calculated as:
\( \text{Sensitivity} = \frac{TP}{TP + FN}, \quad \text{Specificity} = \frac{TN}{TN + FP}. \)
The ROC curve plots sensitivity against the false-positive rate \(1 - \text{Specificity}\). The diagonal reference line represents random classification.
4.2 AUC
The AUC is computed as the pairwise probability that a randomly selected positive case has a more positive marker score than a randomly selected negative case according to the selected score direction, with ties contributing 0.5:
\( \mathrm{AUC} = \frac{1}{n_+ n_-} \sum_{i:Y_i=1}\sum_{j:Y_j=0} \psi(s_i, s_j). \)
Here \(\psi = 1\) if the positive case ranks above the negative case after applying the selected score direction, \(\psi = 0.5\) for a tie, and \(\psi = 0\) otherwise. This is equivalent to the Mann–Whitney/Wilcoxon rank interpretation of the AUC.
4.3 Cutoff Selection
The optimal cutoff reported by the tool is selected by maximizing Youden’s index:
\( J = \text{Sensitivity} + \text{Specificity} - 1. \)
If two thresholds have numerically equal Youden index values, the implementation prefers the threshold with higher sensitivity.
4.4 DeLong Statistics and Bootstrap Confidence Intervals
The standard error and p-value for AUC versus 0.5 are calculated using a DeLong-style variance based on placement values for positive and negative cases. The reported p-value uses a two-sided normal approximation:
\( z = \frac{\mathrm{AUC} - 0.5}{SE(\mathrm{AUC})}. \)
DeLong variance, standard error and inference require at least two valid positive cases and two valid negative cases. If either class contains only one valid case, the empirical AUC and ROC curve remain available, but the standard error and p-value are shown as Not estimable. If either class is absent, the AUC is not available.
When multiple markers are selected, paired DeLong comparisons are reported relative to the first valid marker. These comparisons use only rows with valid scores for both markers being compared. The same minimum of two cases per class applies to these shared complete cases, not to each marker's individual sample. With one shared case in either class, the paired AUC difference remains available but the DeLong test is shown as Not estimable.
Bootstrap 95% confidence intervals for AUC are percentile intervals from stratified resampling: positive cases are sampled with replacement from the positive set and negative cases are sampled with replacement from the negative set. The same bootstrap samples are used to draw pointwise ROC confidence bands on a fixed false-positive-rate grid. These ROC bands are pointwise bootstrap bands, not simultaneous confidence bands.
Bootstrap resampling uses a deterministic random seed derived from the marker name, the number of valid observations, and the selected number of iterations. With the same data in the same row order and these settings unchanged, the bootstrap results are reproducible. Renaming a marker can change its bootstrap confidence limits and bands; the empirical ROC curve, AUC, and DeLong statistics are unaffected by the name. Bootstrap intervals and bands are omitted when the number of iterations is set to zero.
5. Boxplot, Scatterplot, and Fusion Plot
The boxplot tool uses raw numeric values and a grouping variable. For each group, values are sorted and the following descriptive statistics are computed:
- Mean: arithmetic mean
- Median: 50th percentile
- First quartile (Q1): 25th percentile
- Third quartile (Q3): 75th percentile
- Minimum and maximum: smallest and largest observed values
Quartiles are calculated as interpolated empirical quantiles. The box spans Q1 to Q3, with a line at the median. Whiskers extend to the observed minimum and maximum. This is a min-to-max boxplot implementation, not a Tukey 1.5·IQR outlier-rule implementation.
Scatterplot mode displays the raw observations. Fusion mode overlays raw observations and a boxplot. Jitter is a visual separation method for overlapping points and does not change the underlying values. The tool does not perform group comparison tests.
6. Bar Charts
The bar chart tool uses one numeric value column and one group column. Values are aggregated within each group, and each group is represented by one bar. The user can choose the bar height:
- Mean: arithmetic mean of the group values
- Median: 50th percentile of the group values
- Max: largest observed value in the group
- Sum: sum of all valid group values
- Count: number of valid observations in the group
Mean is the default because a bar chart grouped by category is commonly used to display a summary value per category. The summary table always reports \(n\), the selected bar value, mean, median, quartiles, minimum, and maximum.
Optional summary reference lines can display mean, median, and quartiles for the group when the selected bar value is Mean, Median, or Max. The bar chart tool does not calculate standard deviations, standard errors, confidence intervals, or p-values and therefore does not draw inferential error bars.
7. Grouped and Stacked Bar Charts
The grouped and stacked bar chart tools are categorical frequency tools. They use a main group variable and a subgroup variable. No numeric measurement column is used.
For every group \(g\) and subgroup \(s\), the tools compute:
\( n_{g,s} = \#\{ i : \text{group}_i = g,\ \text{subgroup}_i = s \}. \)
If percentage mode is selected, percentages are normalized within each main group:
\( p_{g,s} = 100 \cdot \frac{n_{g,s}}{\sum_s n_{g,s}}. \)
Grouped bar charts display subgroup counts or percentages side by side within each group. Stacked bar charts display subgroup counts or percentages stacked within each group; in percentage mode each stack sums to 100% apart from rounding. These tools are descriptive and do not compute chi-square tests, risk ratios, odds ratios, or confidence intervals.
8. Paired Dot Plot
The paired dot plot visualizes two numeric measurements for the same observational unit, usually a before/after or timepoint 1/timepoint 2 structure. The required fields are ID, group, timepoint 1, and timepoint 2. Rows with missing ID, missing group, or invalid numeric values at either timepoint are ignored.
For each valid row, the change is:
\( \Delta_i = y_{i,2} - y_{i,1}. \)
Individual points show the two measurements for each ID, and optional connecting lines show the direction and magnitude of individual change. Jitter is used only to separate overlapping points visually.
The summary table reports \(n\), mean and median values at both timepoints, and mean and median changes. The optional summary line displays either the group mean or group median at each timepoint. The tool does not perform paired t-tests, Wilcoxon signed-rank tests, confidence intervals, or multiplicity adjustments.
9. Regression Tools
The regression tools fit curves separately for each group. Linear regression uses a centered ordinary least-squares calculation. Exponential regression uses a centered weighted fit; logarithmic regression uses centered ordinary least squares of log(x) and y. A group requires at least two valid observations and at least two distinct x-values to produce a fitted curve. The tools report \(n\), \(R^2\), fitted parameters, and the fitted equation for each group.
The fitted line or curve is sampled for drawing. Display choices such as a logarithmic y-axis change only how the fitted values are plotted; they do not change which regression model is fitted.
9.1 Linear Regression
The linear regression model is:
\( y = a x + b. \)
Slope \(a\) and intercept \(b\) are estimated by ordinary least squares:
\( a = \frac{\sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})} {\sum_{i=1}^n (x_i - \bar{x})^2}, \quad b = \bar{y} - a \bar{x}. \)
The calculation subtracts a reference origin before centering the data and uses compensated summation. This avoids subtracting nearly equal large sums when x-values have a large common offset. Fitted values and residuals are evaluated in centered coordinates; coefficients are rounded only for display. Input values remain subject to JavaScript floating-point precision. If all y-values are identical, \(R^2\) is undefined and no fit is reported.
9.2 Logarithmic Regression
The logarithmic model is:
\( y = a + b \ln(x). \)
Only observations with \(x > 0\) are valid for this model. Rows with \(x \le 0\) are ignored because \(\ln(x)\) is undefined for non-positive values in the real-number domain. The model is fitted by applying linear regression to \((\ln(x_i), y_i)\).
Logarithmic differences relative to a reference x-value are evaluated directly with
log1p for nearby values. This preserves differences that separate logarithm
evaluations can lose for large, closely spaced x-values. Centering, scaling and compensated
summation stabilize the unweighted least-squares fit. Fitted values and residuals use these
same coordinates; coefficients are not rounded before calculation.
Small and large coefficients use scientific notation. In narrow ranges far from x = 1, the equation is displayed in the equivalent form \(y = y_0 + b\ln(x/x_0)\), with \(y_0\) the fitted value at the reference \(x_0\). The reported intercept still refers to x = 1 in \(y = a + b\ln(x)\). Constant y-values have undefined \(R^2\) and no fit is reported.
9.3 Exponential Regression
The exponential model is:
\( y = a e^{b x}. \)
Only observations with \(y > 0\) are valid for this model. Rows with \(y \le 0\) are ignored. The
fit minimizes \(\sum_i y_i [\ln(y_i) - (\alpha + b x_i)]^2\), with \(a = e^\alpha\).
This retains the Y-weighted log-linear estimator previously provided by
regression-js; it is not unweighted log-linear regression or nonlinear least
squares on the original response scale. This is not a generalized linear model and does
not estimate Poisson, logistic, or Cox regression parameters.
The implementation centers and scales x-values, scales the weights and uses compensated summation. Fitted values are evaluated relative to a reference x-value without rounding coefficients first. Very small coefficients are displayed in scientific notation. If the coefficient at x = 0 is outside the numeric range, it is shown in exponential form and the equation uses an equivalent reference-point form. This does not change the fitted curve. For constant y-values, \(R^2\) is undefined and no fit is reported.
Exponential-fit \(R^2\) is evaluated on the original response scale, as below. Because the fit minimizes weighted log-scale errors, this \(R^2\) may legitimately be negative.
9.4 Coefficient of Determination
For all regression tools, \(R^2\) is computed from observed and fitted values on the original response scale:
\( R^2 = 1 - \frac{\sum_{i=1}^n (y_i - \hat{y}_i)^2} {\sum_{i=1}^n (y_i - \bar{y})^2}. \)
The regression tools are descriptive curve-fitting tools. They do not report standard errors, confidence bands, prediction intervals, p-values, or residual diagnostics.
10. General Remarks
- Displayed values are rounded for readability; internal calculations use unrounded numeric values unless a third-party library returns rounded parameters.
- Annotations, legends, axis formatting, and export settings are visual tools and do not modify the dataset or statistical output.
- The application avoids undocumented smoothing and does not add statistical tests where the selected visualization is descriptive only.
Users remain responsible for verifying that the chosen model, visualization, and data preprocessing are appropriate for their specific data and research question.
