feat(ssa): Complete T-test end-to-end testing with 9 bug fixes - Phase 1 core 85% complete. R service: missing value auto-filter. Backend: error handling, variable matching, dynamic filename. Frontend: module activation, session isolation, error propagation. Full flow verified.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
44
r-statistics-service/utils/result_formatter.R
Normal file
44
r-statistics-service/utils/result_formatter.R
Normal file
@@ -0,0 +1,44 @@
|
||||
# utils/result_formatter.R
|
||||
# 统计结果格式化,确保 p 值显示规范
|
||||
|
||||
# 格式化 p 值(符合 APA 规范)
|
||||
format_p_value <- function(p) {
|
||||
if (is.na(p)) return(NA)
|
||||
|
||||
if (p < 0.001) {
|
||||
return("< 0.001")
|
||||
} else {
|
||||
return(sprintf("%.3f", p))
|
||||
}
|
||||
}
|
||||
|
||||
# 构建标准化结果(包含 p_value_fmt)
|
||||
make_result <- function(p_value, statistic, method, ...) {
|
||||
list(
|
||||
p_value = p_value,
|
||||
p_value_fmt = format_p_value(p_value),
|
||||
statistic = statistic,
|
||||
method = method,
|
||||
...
|
||||
)
|
||||
}
|
||||
|
||||
# 格式化置信区间
|
||||
format_ci <- function(lower, upper, digits = 2) {
|
||||
sprintf("[%.2f, %.2f]", lower, upper)
|
||||
}
|
||||
|
||||
# 格式化效应量
|
||||
format_effect_size <- function(value, type = "d") {
|
||||
interpretation <- ""
|
||||
if (type == "d") { # Cohen's d
|
||||
if (abs(value) < 0.2) interpretation <- "微小"
|
||||
else if (abs(value) < 0.5) interpretation <- "小"
|
||||
else if (abs(value) < 0.8) interpretation <- "中等"
|
||||
else interpretation <- "大"
|
||||
}
|
||||
list(
|
||||
value = round(value, 3),
|
||||
interpretation = interpretation
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user