Ich habe eine Reihe von Daten und passen Sie das entsprechende Histogramm durch eine lognormal Verteilung. Zuerst berechne ich die optimalen Parameter für die Lognormalfunktion und zeichne dann das Histogramm und die Lognormalfunktion. Dies gibt recht gute Ergebnisse:Sehr niedrige p-Werte in Python Kolmogorov-Smirnov Anpassungsgüte Test
import scipy as sp
import numpy as np
import matplotlib.pyplot as plt
num_data = len(data)
x_axis = np.linspace(min(data),
max(data),num_data)
number_of_bins = 240
histo, bin_edges = np.histogram(data, number_of_bins, normed=False)
shape, location, scale = sp.stats.lognorm.fit(data)
plt.hist(data, number_of_bins, normed=False);
# the scaling factor scales the normalized lognormal function up to the size
# of the histogram:
scaling_factor = len(data)*(max(data)-min(data))/number_of_bins
plt.plot(x_axis,scaling_factor*sp.stats.lognorm.pdf(x_axis, shape,
location, scale),'r-')
# adjust the axes dimensions:
plt.axis([bin_edges[0]-10,bin_edges[len(bin_edges)-1]+10,0, histo.max()*1.1])
Wenn jedoch auf die Daten in Abhängigkeit von der Anpassungsfunktion des Kolmogorov-Smirnov-Test durchzuführen, erhalte ich viel zu niedrig p-Werte (in der Größenordnung von e- 32):
lognormal_ks_statistic, lognormal_ks_pvalue =
sp.stats.kstest(
data,
lambda k: sp.stats.lognorm.cdf(k, shape, location, scale),
args=(),
N=len(data),
alternative='two-sided',
mode='approx')
print(lognormal_ks_statistic)
print(lognormal_ks_pvalue)
das ist nicht normal, da wir von dem Grundstück zu sehen, dass der Einbau ganz richtig ist ... weiß jemand, wo ich einen Fehler gemacht?
Vielen Dank !! Charles