Introduction
Introduction Statistics Contact Development Disclaimer Help
tadded python version of linear regression analysis - numtools - perform numeri…
git clone git://src.adamsgaard.dk/numtools
Log
Files
Refs
README
LICENSE
---
commit 0cc78918862ea2153868166130c2c4bf51ee5ae4
parent 980e62e250ba67b8a2e89cf4160b85aa9c14372e
Author: Anders Damsgaard <[email protected]>
Date: Wed, 24 Nov 2021 14:40:40 +0100
added python version of linear regression analysis
Diffstat:
A linregress | 67 +++++++++++++++++++++++++++++…
1 file changed, 67 insertions(+), 0 deletions(-)
---
diff --git a/linregress b/linregress
t@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+import sys, getopt
+import numpy
+import scipy.stats
+
+def usage(arg0):
+ print("usage: {} [-h] [-s significance_level]".format(sys.argv[0]))
+
+def read2dstdin():
+ input = numpy.loadtxt(sys.stdin)
+ return input[:,0], input[:, 1]
+
+def reportregress(res):
+ print("slope =\t{:5g}\nslope_stderr =\t{:5g}".format(res.slope, res.st…
+ print("intercept =\t{:5g}\nintercept_stderr =\t{:5g}".format(res.inter…
+ print("r_value =\t{:5g}\np_value =\t{:5g}\n".format(res.rvalue, res.pv…
+
+def reportsignif(p, significlvl):
+ print("Checking null hypothesis using the Wald Test with t-distributio…
+ print("The p-value is ", end="")
+ if (p < significlvl):
+ print("less than the significance level ({:g}),".format(signif…
+ print("which means that the null hypothesis of zero slope is R…
+ else:
+ print("greater or equal than the significance level ({:g}),".f…
+ print("which means that the null hypothesis of zero slope CANN…
+
+
+def reportcorr(r):
+ print("The correlation coefficient (r-value) denotes ", end="")
+ if (abs(r) < 0.01):
+ print("zero correlation.")
+ else:
+ print("a ", end="")
+ if (abs(r) < 0.2):
+ print("weak", end="")
+ elif (abs(r) < 0.3):
+ print("moderate", end="")
+ elif (abs(r) < 0.4):
+ print("strong", end="")
+ elif (abs(r) < 0.7):
+ print("very strong", end="")
+ print(" positive" if r > 0.0 else " negative")
+ print(" relationship.")
+
+def main(argv):
+ significlvl = 0.05
+ try:
+ opts, args = getopt.getopt(argv, "hs:")
+ except getopt.GetoptError:
+ usage()
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == "-h":
+ usage()
+ sys.exit(0)
+ elif opt == "-s":
+ significlvl = float(arg)
+
+ x, y = read2dstdin()
+ res = scipy.stats.linregress(x, y, alternative="two-sided")
+ reportregress(res)
+ reportsignif(res.pvalue, significlvl)
+ reportcorr(res.rvalue)
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.