外观
简单线性回归
用OLS分析连续结局与解释变量之间的条件关联。
计算口径
一行一个独立观测。分类因素须登记为分类变量并选定参照组;同一模型使用完整案例。关注线性关系、共线性、残差及影响点。
指定一个连续Y与一个解释因素X。若X为分类因素,在分析设置中登记并选择参照组,单个因素可对应多个虚拟变量。
B表示原单位变化,β为标准化系数。置信区间与R²补充p值信息。HC1/HC3调整标准误,不能修正错误函数形式或遗漏变量偏差。
同源实现
以下片段来自 core/statistical/regression.py 的 analyze_regression,由镜像脚本按语法树提取。共享辅助函数和分发逻辑包含在完整下载包中。
py
def analyze_regression(data, method, options):
if method in ('stat_linear_simple', 'stat_linear_multiple', 'stat_linear_hierarchical'):
return linear_regression(data, options, hierarchical=method == 'stat_linear_hierarchical', simple=method == 'stat_linear_simple')
if method in ('stat_logistic_univariate', 'stat_logistic_multivariate'):
return logistic_regression(data, options, univariate=method == 'stat_logistic_univariate')
if method.startswith('stat_mediation_'):
from .mechanisms import mediation
return mediation(data, method, options)
from .mechanisms import moderation
return moderation(data, method, options)复现本方法
在解压目录安装 requirements.txt 后执行。样例为固定种子的模拟数据,仅供验证;输出不得冒充真实研究结果。
python
import examples._bootstrap
from examples.statistics_cases import build_data, method_cases
from core.statistical.runner import analyze
method = "stat_linear_simple"
options = dict(method_cases())[method]
result = analyze(build_data(), method, options)
print(result.tables[0].html())