I have a (x,y) dataset, and I would like to calculate the r_value**2
for every 10 elements (so between element 0 and 9, between 1 and 10, ..., between n-10 and n).
Ideally the code should give out the r_value**2_max
and save all r
-values in a list. I've made a loop, but don't know how to tell stats.linregress
to look between test_i
and test_i+10
and save all r-values**2
in a list.
So far, I have this:
import matplotlib.pyplot as plt
from scipy import stats
import numpy as np
import csv
path = '/storage/.../01_python_in/'
test = np.loadtxt(path + 'sample_data.txt', skiprows=0)
test_min = 0
test_max = len(test)
for test_i in range(test_min, test_max-10):
slope, intercept, r_value, p_value, std_err = stats.linregress(test[:, 0], test[:, 1])
print 'i:', test_i, 'r**2:', r_value**2