Wie berechnet man P-Werte aus Xarray.Polyfit-Kovarianzmatrix?Python

Python-Programme
Anonymous
 Wie berechnet man P-Werte aus Xarray.Polyfit-Kovarianzmatrix?

Post by Anonymous »

Ich versuche, P-Werte für die mit Xarray.Polyfit () erhaltene Steigung zu berechnen, indem die Kovarianzmatrix extrahiert und ein T-Test verwendet wird. Ich bekomme jedoch 1s für alle P-Werte, was falsch erscheint. Dieselben Datensätze geben bei Verwendung von scipy.stats.Linegress () gültige P-Werte für bestimmte Punkte an, gilt jedoch nur langsam für den gesamten Datensatz. < /P>
def compute_trends(data : xr.Dataset):
trends = xr.Dataset()

#
data = data.sortby("time")
n = data.dims["time"] # Number of time points

# Perform linear regression using xarray.polyfit()
ds = data.polyfit(dim="time", deg=1, cov=True)

# Extract slope and covariance matrix
slope = ds["polyfit_coefficients"].sel(degree=1)
slope_variance = ds["polyfit_covariance"].sel(cov_i=0, cov_j=0) # Variance of the slope

# Compute standard error, t-statistic, and p-values
stderr = np.sqrt(slope_variance)
t_stat = slope / stderr
p_values = 2 * (1 - stats.t.cdf(np.abs(t_stat), df=n - 2))

# Store in dataset
trends["slope"] = slope
trends["p_value"] = xr.DataArray(p_values, coords=slope.coords, dims=slope.dims)

return trends
< /code>
Ich vermute ein Problem damit, wie ich die Kovarianzmatrix (polyfit_covarianz) oder das Berechnen von Stderr extrahiere. Extrahiere ich die Steigungsvarianz aus polyfit_covarianz?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post