开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 899|回复: 7
收起左侧

[已解决] 有数据统计高手吗 协整性里面的P怎么求 有python参考

 关闭 [复制链接]
结帖率:97% (98/101)
发表于 2023-1-18 23:31:55 | 显示全部楼层 |阅读模式   重庆市重庆市
50精币
QQ截图20230118232440.jpg

2组数据 通涨同跌  计算相关性 几乎是相关性超级高  但是他们不具备协整性  协整性的P值非常大

QQ截图20230118232548.jpg

同理 这蓝色和红色线  不同涨跌  几乎没有相关性  但是具有协整性

所谓的相关性 我用老外的公式会计算   但是这个协整性的P值  我翻了很久没找到我能理解的公式 基本都是python的函数  看不懂不会计算 大致相当于这种
  
import pandas as pd
import numpy as np
from scipy.stats import pearsonr
from statsmodels.tsa.stattools import coint
import matplotlib.pyplot as plt
x1 = pd.Series (np.random.normal (0,1,1000))
x2 = x1.copy ()
for i in range (10):
x2[ (100*i): (100*i+100)] = (-1)**i

plt.figure (figsize= (6,3))
plt.plot (x1, c= ' blue')
plt.plot (x2, c= ' red')
plt.show ()   
_, pv, _ = coint (x1, x2)
print ("Cointegration test p-value : ", pv)
correl, pv = pearsonr (x1, x2)
print ("Correlation : ", correl)


也就是
_, pv, _ = coint(x1, x2)
print("Cointegration test p-value : ", pv)


有没有大佬能改写个易语言版本的  只要PV那个计算就行了,

子程序 传入2个文本型的参数数组 分别代表2组数据 返回协整性的P值

文章参考
https://zhuanlan.zhihu.com/p/158871695

最佳答案

查看完整内容

def coint(y0, y1, trend='c', method='aeg', maxlag=None, autolag='aic', return_results=None): """Test for no-cointegration of a univariate equation The null hypothesis is no cointegration. Variables in y0 and y1 are assumed to be integrated of order 1, I(1). This uses the augmented Engle-Granger two-step cointegration test. Constant or trend is included in 1st stage re ...

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳

结帖率:100% (45/45)

签到天数: 14 天

发表于 2023-1-18 23:31:56 | 显示全部楼层   广东省东莞市
def coint(y0, y1, trend='c', method='aeg', maxlag=None, autolag='aic',
          return_results=None):
    """Test for no-cointegration of a univariate equation
    The null hypothesis is no cointegration. Variables in y0 and y1 are
    assumed to be integrated of order 1, I(1).
    This uses the augmented Engle-Granger two-step cointegration test.
    Constant or trend is included in 1st stage regression, i.e. in
    cointegrating equation.
    **Warning:** The autolag default has changed compared to statsmodels 0.8.
    In 0.8 autolag was always None, no the keyword is used and defaults to
    'aic'. Use `autolag=None` to avoid the lag search.
    Parameters
    ----------
    y1 : array_like, 1d
        first element in cointegrating vector
    y2 : array_like
        remaining elements in cointegrating vector
    trend : str {'c', 'ct'}
        trend term included in regression for cointegrating equation
        * 'c' : constant
        * 'ct' : constant and linear trend
        * also available quadratic trend 'ctt', and no constant 'nc'
    method : string
        currently only 'aeg' for augmented Engle-Granger test is available.
        default might change.
    maxlag : None or int
        keyword for `adfuller`, largest or given number of lags
    autolag : string
        keyword for `adfuller`, lag selection criterion.
        * if None, then maxlag lags are used without lag search
        * if 'AIC' (default) or 'BIC', then the number of lags is chosen
          to minimize the corresponding information criterion
        * 't-stat' based choice of maxlag.  Starts with maxlag and drops a
          lag until the t-statistic on the last lag length is significant
          using a 5%-sized test
    return_results : bool
        for future compatibility, currently only tuple available.
        If True, then a results instance is returned. Otherwise, a tuple
        with the test outcome is returned.
        Set `return_results=False` to avoid future changes in return.
    Returns
    -------
    coint_t : float
        t-statistic of unit-root test on residuals
    pvalue : float
        MacKinnon's approximate, asymptotic p-value based on MacKinnon (1994)
    crit_value : dict
        Critical values for the test statistic at the 1 %, 5 %, and 10 %
        levels based on regression curve. This depends on the number of
        observations.
    Notes
    -----

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:97% (98/101)

签到天数: 14 天

 楼主| 发表于 2023-1-18 23:50:12 | 显示全部楼层   重庆市重庆市
我在想 易语言这方面内容太少了 我要不要学一下调用python  这样用易语言调用 就好解决了 程序也不需要大改动
回复

使用道具 举报

结帖率:100% (3/3)
发表于 2023-1-19 02:30:17 | 显示全部楼层   湖北省荆门市
等待大佬解决。。
回复

使用道具 举报

结帖率:97% (98/101)

签到天数: 14 天

 楼主| 发表于 2023-1-19 03:50:34 | 显示全部楼层   重庆市重庆市
再问一下 如果要用易语言调用python的话 是不是运行exe的电脑 也需要单独装一遍python的环境?
回复

使用道具 举报

结帖率:100% (45/45)

签到天数: 14 天

发表于 2023-1-19 11:12:24 | 显示全部楼层   广东省东莞市
按原理一算不就好了吗
回复

使用道具 举报

结帖率:100% (45/45)

签到天数: 14 天

发表于 2023-1-19 13:18:57 | 显示全部楼层   广东省东莞市
    .. [1] MacKinnon, J.G. 1994  "Approximate Asymptotic Distribution Functions
       for Unit-Root and Cointegration Tests." Journal of Business & Economics
       Statistics, 12.2, 167-76.
    .. [2] MacKinnon, J.G. 2010.  "Critical Values for Cointegration Tests."
       Queen"s University, Dept of Economics Working Papers 1227.
       http://ideas.repec.org/p/qed/wpaper/1227.html
回复

使用道具 举报

结帖率:97% (98/101)

签到天数: 14 天

 楼主| 发表于 2023-1-20 07:49:22 | 显示全部楼层   重庆市重庆市
搞定了 学会了python了 然后就是调用问题了  模块那个  我装完python下了很多包后就没法正常初始化了 只有用精易支持库去
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表