【问题标题】:regressing on functions with steps (Python/R)使用步骤回归函数(Python/R)
【发布时间】:2016-07-17 00:11:22
【问题描述】:

正如标题所示,我希望能够在 R 或 Python 中对以下(非线性阶跃函数)执行回归(不仅仅是简单的优化)(问题很关键,所以我愿意使用无论哪种软件都能完成工作):

https://beta.postimg.org/image/3pqj0zb1b/

或在

Y = alpha + beta * Dummy_1 + error_term
where Dummy_1 = 1 if x > gamma * f(x) and if x < theta * f(x) Parameters: alpha, beta, gamma, theta

所以我想使用强大的统计工具,并希望通过 GLM 来计算这个模型提供的所有好东西(我还不关心关于可靠性的优化问题,所以我很乐意采用任何可行的方法)。不幸的是,我不知道如何设置这样一个特殊的问题 - 无论是在 R 中还是在 Python 中。

你会怎么做?

【问题讨论】:

    标签: python r regression glm


    【解决方案1】:

    最适合您的解决方案是scipy 一个我的示例代码

    import xlrd
    import matplotlib.pyplot
    import pylab
    from scipy import stats
    import numpy as np
    import math
    
    cord = xlrd.open_workbook('MT_coordenadas_todas.xls')
    
    id1 = cord.sheet_by_index(0)
    values1 = id1.col_values(0)
    
    id2 = cord.sheet_by_index(0)
    values2 = id2.col_values(1)
    
    id3 = cord.sheet_by_index(0)
    values3 = id3.col_values(2)
    
    print type(values3)
    
    a1= values1[1:16]
    
    a2= values2[1:16]
    print a2
    
    a3= values3[1:16]
    print a3
    
    slope, intercept, r_value, p_value, std_err = stats.linregress(a2,a3)
    
    print slope
    print intercept
    

    然后你得到斜率和界面

    -1.76630044629
    10061774.6817
    

    【讨论】:

      猜你喜欢
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2021-01-09
      • 2013-08-05
      • 2018-10-10
      • 1970-01-01
      相关资源
      最近更新 更多