기본 콘텐츠로 건너뛰기

라벨이 표본분포인 게시물 표시

pandas_ta를 적용한 통계적 인덱스 지표

통계관련 그래프

다음 그래프들은 전자책 파이썬과 함께하는 통계이야기 4 장에 수록된 그림들의 코드들입니다. import numpy as np import pandas as pd from scipy import stats from sklearn.preprocessing import StandardScaler import FinanceDataReader as fdr import yfinance as yf import matplotlib.pyplot as plt import seaborn as sns sns.set_style("darkgrid") #fig 421 st=pd.Timestamp(2022,12, 1) et=pd.Timestamp(2023, 4, 1) da=fdr.DataReader("KS11", st, et) pop=(da['Close']-da['Open'])/da['Open']*100 np.random.seed(1) xBar=np.array([]) for i in range(20): x=pop.sample(5, random_state=i) xBar=np.append(xBar, x.mean()) xBar2=np.array([]) for i in range(100): x=pop.sample(5, random_state=i) xBar2=np.append(xBar2, x.mean()) fig, ax=plt.subplots(1, 2, figsize=(8, 3)) ax[0].hist(xBar, 10, rwidth=0.8, color="blue", label="n=20") ax[0].axvline(xBar.mean(), 0, 0.9, color="red", label=f"m={round(xBar.mean(), 2)}") ax[0].set_xlabel("x", weight=...

[data anlysis]표본분포(Sample distribution)

표본분포(Sample distribution) 다음과 같이 모집단에서 추출한 표본들이 모든 요소(데이터)들을 사용하는 이상적인 경우 모평균과 표본평균들의 평균은 같습니다. 즉, 6개의 요소를 가지는 모집단으로부터 요소 3개를 포함하는 표본 2개에 대해 식 1의 관계가 성립합니다. \begin{align}X&=\{x_1, \,x_2, \,x_3, \,x_4, \,x_5, \,x_6\} \\ X_1&=\{x_1, \,x_2, \,x_3\},\; X_2=\{x_4, \,x_5, \,x_6\}\\ \mu&=\frac{x_1+x_2+x_3+x_4+x_5+x_6}{6}\\ \overline{X_1} &=\frac{x_1+x_2+x_3}{3}\\ \overline{X_2} &=\frac{x_4+x_5+x_6}{3}\\ \overline{X} &= \frac{\overline{X_1}+\overline{X_2}}{2}\\&=\frac{\frac{x_1+x_2+x_3}{3}+\frac{x_4+x_5+x_6}{3}}{2}\\ &=\mu\end{align} (식 1) 표본 집단들은 모집단으로부터 무작위로 추출된 것으로 표본들 사이에는 편차가 존재합니다. 그러나 모든 샘플들이 모집단의 요소들을 포함한다면 식 1과 같이 각 샘플의 평균으로 유도되는 평균은 모평균과 같아질 것입니다. 다시 말하면 각 샘플의 평균들은 일정한 분포를 이룰 수 있습니다. 중심극한 정리 에 의해 그 수가 많으며 정규분포에 부합합니다. 이러한 분포를 표본평균분포 또는 표본 분포(sample distribution) 라고 하고 이 분포의 평균을 표본평균(sample mean) 이라 합니다. 식 1과 중심극한 정리와 같은 모집단과 표본들의 관계로 인해 표본평균은 미지의 모평균을 대체하여 사용합니다. 이러한 추정치를 불편추정치(unbiased estimator) 라고 합니다. 즉, 모평균과 표본평균 사이에 발생하는 편차는 일반적인 ...