Skip to content

Commit

Permalink
neff
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiluM committed Dec 18, 2023
1 parent 2279449 commit 7a1dd48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sacpy/LinReg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LinReg:
p_value (np.ndarray) : T test p value , shape = [*number]
"""

def __init__(self, x: np.ndarray or xr.DataArray, y: np.ndarray or xr.DataArray):
def __init__(self, x: np.ndarray or xr.DataArray, y: np.ndarray or xr.DataArray,neff=None):
""" Simple linear regression y[idx] = slope[idx] * x + intcp[idx]
Args:
Expand All @@ -48,7 +48,7 @@ def __init__(self, x: np.ndarray or xr.DataArray, y: np.ndarray or xr.DataArray)
self.x = x
self.y = y

slope, intcpt, corr, p_value = linear_reg(x, y)
slope, intcpt, corr, p_value = linear_reg(x, y,neff=neff)

# judge dataarray trans
if ydims is not None and ycoords is not None:
Expand Down
7 changes: 5 additions & 2 deletions sacpy/linger_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
EPS = 1e-10


def linear_reg(x: np.ndarray, y: np.ndarray):
def linear_reg(x: np.ndarray, y: np.ndarray,neff=None):
""" Simple linear regression y[idx] = slope[idx] * x + intcp[idx]
Args:
x (np.ndarray): shape = (time,)
Expand Down Expand Up @@ -43,7 +43,10 @@ def linear_reg(x: np.ndarray, y: np.ndarray):
intcpt = y_rs.mean(axis=0) - slope * x.mean(axis=0)
# cal t-valpue
t = corr / (np.sqrt(1 - corr**2) + EPS) * np.sqrt(Num0 - 2)
p_value = sts.t.sf(t, df=Num0 - 2)
if neff is None:
p_value = sts.t.sf(t, df=Num0 - 2)
else:
p_value = sts.t.sf(t, df=neff)
# transform t value
pv_cp = np.copy(p_value)
p_value[pv_cp >= 0.5] = (1 - p_value[pv_cp >= 0.5]) * 2
Expand Down

0 comments on commit 7a1dd48

Please sign in to comment.