医学 性别、年龄、受教育年限的校正 方法与代码

@创建于:2022.07.17
@修改于:2022.07.17

1、参数介绍

statsmodels.regression.linear_model.OLS(endog, exog=None, missing='none', hasconst=None, **kwargs)


Parameters

    endog: array_like
        A 1-d endogenous response variable. The dependent variable.
        
    exog: array_like
        A nobs x k array where nobs is the number of observations and k is the number of regressors. An intercept is not included by default and should be added by the user. See statsmodels.tools.add_constant.

    missing: str
        Available options are ‘none’, ‘drop’, andraise. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise, an error is raised. Default is ‘none’.
    
    hasconst: None or bool
        Indicates whether the RHS includes a user-supplied constant. If True, a constant is not checked for and k_constant is set to 1 and all result statistics are calculated as if a constant is present. If False, a constant is not checked for and k_constant is set to 0.

指示 RHS 是否包含用户提供的常量。
如果为 True,则不检查常量并将 k_constant 设置为 1,并且所有结果统计信息都按照存在常量的方式进行计算。
如果为 False,则不检查常量并将 k_constant 设置为 0

statsmodels.regression.linear_model.OLS

2、官网代码

>>> import statsmodels.api as sm
>>> import numpy as np
>>> duncan_prestige = sm.datasets.get_rdataset("Duncan", "carData")
>>> Y = duncan_prestige.data['income']
>>> X = duncan_prestige.data['education']
>>> X = sm.add_constant(X)
>>> model = sm.OLS(Y,X)
>>> results = model.fit()
>>> results.params
const        10.603498
education     0.594859
dtype: float64

>>> results.tvalues
const        2.039813
education    6.892802
dtype: float64

>>> print(results.t_test([1, 0]))
                             Test for Constraints
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
c0            10.6035      5.198      2.040      0.048       0.120      21.087
==============================================================================

>>> print(results.f_test(np.identity(2)))
<F test: F=array([[159.63031026]]), p=1.2607168903696672e-20, df_denom=43, df_num=2>

3、参考资料

python 中 statsmodels模块的 API接口

python statsmodel 回归结果提取(回归系数、t值、pvalue、R方)

python statsmodel 回归结果提取(R方 T值 P-value)

在scikit学习LinearRegression中找到p值(重要性)

python 线性回归 统计检验 p值_Python统计的新选择:pingouin

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值