【问题标题】:How can I calculate the correlation coefficient (R-values) for this set of values? (Linear Regression)如何计算这组值的相关系数(R 值)? (线性回归)
【发布时间】:2021-02-13 20:32:41
【问题描述】:

我已经计算了以下值的斜率、截距、皮尔逊 r、p 值和标准误差。

x 值

[1.2934100756644895, 1.2148454109214604, 1.1452785890167783, 1.0832475762335483, 1.0275908133381289, 0.977373796608513, 0.9318361831989935]

y 值

[-9.776387800749989, -9.175342621188113, -8.93878723996764, -8.422091376497663, -8.027043257822346, -7.681859756453859, -7.308696476846782]

代码:

slope1, intercept1, r1, p1, std_err1 = stats.linregress(C_to_K, ln_conversion_rate_CH4)

def myfunc1(C_to_K):
    return slope1*C_to_K + intercept1

mymodel1 = list(map(myfunc1, C_to_K))
plt.plot(C_to_K, mymodel1, "k:", label="y={0:.1f}x+{1:.1f}".format(slope1,intercept1))

【问题讨论】:

  • 请在提问的同时在此处提供您的代码,以便我们检查实际出了什么问题。

标签: python linear-regression


【解决方案1】:

假设这是你所做的:

from scipy import stats

x = [1.2934100756644895, 1.2148454109214604, 1.1452785890167783, 1.0832475762335483, 
     1.0275908133381289, 0.977373796608513, 0.9318361831989935]

y = [-9.776387800749989, -9.175342621188113, -8.93878723996764, -8.422091376497663, 
     -8.027043257822346, -7.681859756453859, -7.308696476846782]

slope, intercept, r, p, se = linregress(x, y)

help page for lingress 中已经声明:

r value float: Correlation coefficient.

所以 r 是您在问题中所述的相关系数或 Pearson 的 r。如果你需要coefficient of determination,它基本上是r的平方,即

r**2
0.9927964085754613

【讨论】:

    猜你喜欢
    • 2011-08-05
    • 2019-12-10
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    相关资源
    最近更新 更多