- numpy - matplotlib

Project Details of Statistical Calculator

logo 05

Samuel Delmonte


Statistical Calculator


Pure Python make Code Application
Integrate Probability Density Function
P( a ≤ X ≤ b ) =
1√2.Π
e-1/2.x2
dx

Média μ = 100 Desvio σ = 15
Insira um valor entre 53 ≤ X ≤ 142
import numpy as np import matplotlib import matplotlib.pyplot as plt from js import name import sys import os def restart_program(): python = sys.executable os.execl(python, python, * sys.argv) name = str(name) name1 = name name1=int(name1) np.random.seed(19680801) # example data mu = 100 # mean of distribution sigma = 15 # standard deviation of distribution x = mu + sigma * np.random.randn(437) vStd=0.00 vStd=np.std(x) vs, vsM,vasV,vsP,vsQ,min,max=0.00,0.00,0.00,0.00,0.00,0.00,0.00 vs = 100* vStd//1 vs=vs/100 vsM = 100* np.mean(x, axis=0)//1 vsM=vsM/100 vsV = 100* np.var(x, axis=0)//1 vsV=vsV/100 vsP = 100* np.percentile(x, 25, axis=0)//1 vsP=vsP/100 vsQ = 100* np.quantile(x, 0.75, axis=0)//1 vsQ=vsQ/100 vsQ2 = 100* np.quantile(x, 0.25, axis=0)//1 vsQ2=vsQ2/100 vsQ3 = 100* np.quantile(x, 0.50, axis=0)//1 vsQ3=vsQ3/100 min = 100* np.amin(x)//1 min=min/100 max = 100* np.amax(x)//1 max=max/100 num_bins = 50 fig, ax = plt.subplots(nrows=2, figsize=(19, 7.6)) ax[0] = plt.subplot(121) ax[0].set_facecolor('#eafff5') # the histogram of the data n, bins, patches = ax[0].hist(x, num_bins, density=True, edgecolor = "white") # add a 'best fit' line y = ((1 / (np.sqrt(2 * np.pi) * sigma)) * np.exp(-0.5 * (1 / sigma * (bins - mu))**2)) ax[0].plot(bins, y, '--',linewidth=3, color='#000') ax[0].set_xlabel('Values x', fontsize=20) ax[0].set_ylabel('Probability density', fontsize=20) ax[0].grid(True, linestyle='-.') left, width = .15, .5 bottom, height = .35, .5 right = left + width top = bottom + height ax[0].text(left, top, 'x value: '+str(name1), horizontalalignment='center', verticalalignment='center', rotation=45, transform=ax[0].transAxes) msg2 = (r" $pdf(x)=\ " r"\frac{1}{\sqrt{2\pi}}\int_{0}^{\infty }e^{\frac{-x^2}{2}} dx$") msg = (r" $Standard \ normal\ distribution:\ " r"\int_{0}^{\infty }e^{-x^2 /2} dx$") ax[0].set_title(msg, fontsize=20) escore=np.linspace(name1,min,51) y2 = ((1 / (np.sqrt(2 * np.pi) * sigma)) * np.exp(-0.5 * (1 / sigma * (escore - mu))**2)) y3 = ((1 / (np.sqrt(2 * np.pi) * sigma)) * np.exp(-0.5 * (1 / sigma * ( name1- mu))**2)) y3 = round(y3, 6) ax[0].axvline(x = name1, color = '#d3c415', label = 'Density' ,linestyle='-.',linewidth=3) ax[0].axvline(x = name1, color = 'r', label = 'Value',linestyle='-.',linewidth=3) ax[0].axvline(x = vsM, color = 'w', label = 'Media',linewidth=2,linestyle='-.') ax[0].legend(loc="upper left",fontsize=20,facecolor="gray") ax[0].fill_between(escore,y2,0, alpha=0.7,color='#daa520') bbox = dict(boxstyle="round", fc="0.6") arrowprops = dict( arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90,rad=10") xdata, ydata = 80, 0.005 offset = 82 ax[0].annotate( f'XI - Density', (xdata, ydata), xytext=(-2*offset, offset), textcoords='offset points', bbox=bbox, arrowprops=arrowprops,fontsize=20) ax[0].plot(xdata, ydata) fig.tight_layout() ax[1] = plt.subplot(122) ax[1].set_facecolor('#000008') ax[1].axes.xaxis.set_ticks([]) ax[1].axes.yaxis.set_ticks([]) trap=(0.0283+y3)*(name1-100)/2 trap=trap+0.5 trapRight=1-trap trap=round(trap,4) trapRight=round(trapRight,4) trappor=trap*100 trappor=round(trappor,4) trapporRight=trapRight*100 trapporRight=round(trapporRight,4) ax[1].axis([55, 175, 0, 0.03]) varia = (name1-100)/sigma varia=round(varia,3) ax[1].text(70, .028,'Probability Density Function' , fontsize=27,color='#ae841a' ) ax[1].text(60, .025,'I- Value: '+str(name1) , fontsize=20,color='#fff') ax[1].text(120, .025,'II- Média: '+str(mu), fontsize=20,color='#fff') ax[1].text(60, .022,'III- Desvio: '+str(sigma), fontsize=20,color='#fff') ax[1].text(120, .022,'IV- Z-escore: '+str(varia),fontsize=20,color='#fff') ax[1].text(60, .019,'V- min: '+str(min),fontsize=20,color='#fff') ax[1].text(120, .019,'VI- max: '+str(max),fontsize=20,color='#fff') ax[1].text(60, .016,'VII- Quartil: 01: Até '+str(vsQ2),fontsize=20,color='#fff') ax[1].text(120, .016, 'VIII- Quartil 02: Até '+str(vsQ3),fontsize=20,color='#fff') ax[1].text(60, .013, 'IX- Quartil 03: Até '+str(vsQ) , fontsize=20,color='#fff') ax[1].text(120, .013,'X- f(x) = '+str(y3), fontsize=20,color='#fff') ax[1].text(80, .008,msg2, fontsize=25,color='#ae841a') ax[1].text(60, .004,'XI- Density: '+str(trap)+' ='+str(trappor)+'%', fontsize=20,color='#fff') ax[1].text(120, .004,'XII- less: '+str(trapRight)+' ='+str(trapporRight)+'%', fontsize=20,color='#fff') fig