분산, 표준편차 구하기(도수분포표) [공식사용][Sage Math이용]

자료의 Nims 서버의 Sage Math 주소 : http://sage.nims.re.kr/home/pub/269

 

 

 
 
 
아래는 Sage Math의 Text 파일이다. 위의 Nims 서버와 같은 내용인데, 혹시나 Nims 서버가 없어지는 경우를 대비하여 Text 형식을 아래에 붙여 놓았다.

<table border="1" width="20%" bordercolorlight="#000000" bordercolordark="#000000" style="border-collapse: collapse">
<tr>
<td style="border-left-color: #000000; border-left-width: 1px" align="center">
$x_i$</td>
<td align="center">$f_i$</td>
<td style="border-right-color: #000000; border-right-width: 1px" align="center">
$x_i f_i$</td>
</tr>
<tr>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: none; border-bottom-width: medium" align="center">
$x_1$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: none; border-bottom-width: medium" align="center">
$f_1$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: none; border-bottom-width: medium" align="center">
$x_1 f_1$</td>
</tr>
<tr>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium" align="center">
$\vdots$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium" align="center">
$\vdots$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium" align="center">
$\vdots$</td>
</tr>
<tr>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px" align="center">
$x_n$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-top-style: none; border-top-width: medium; border-bottom: 1px solid #000000" align="center">
$f_n$</td>
<td style="border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: none; border-top-width: medium; border-bottom: 1px solid #000000" align="center">
$x_n f_n$</td>
</tr>
</table>
<p>
$ f_1 +f_2 +f_3 +\cdots+f_n  =\displaystyle\sum_{i=1}^n x_i f_i  =N$
<p>
 $\begin{array}{rcl}
\displaystyle \text{Mean }&:&  m  =
            \displaystyle \frac{\displaystyle\sum_{i=1}^n x_i f_i }{\displaystyle\sum_{i=1}^n f_i }
=\displaystyle \frac{1}{N}   \sum_{i=1}^n x_i f_i  \\
&& \\
\end{array}$
<p>
 $\begin{array}{rcl}
\displaystyle \displaystyle \text{Variance } : 
 \sigma^2 &=&\displaystyle \frac{\displaystyle\sum_{i=1}^n(x_i-m)^2 f_i}{\displaystyle\sum_{i=1}^n  f_i} 
=\displaystyle \frac{1}{N}\sum_{i=1}^n(x_i-m)^2 f_i 
=\displaystyle \frac{1}{N}\sum_{i=1}^n(x_i^2-2mx_i+m^2) f_i  \\
   &=&\displaystyle \frac{1}{N}\sum_{i=1}^n x_i^2 f_i
                                           - 2m  \times \frac{1}{N}\sum_{i=1}^n x_i f_i
                                           +m^2  \times \frac{1}{N}\sum_{i=1}^n f_i  \\
  &=&\displaystyle \frac{1}{N}\sum_{i=1}^n x_i^2 f_i
                                           - 2m \times m
                                           +m^2 \times \frac{1}{N} \times N  \\
 &=&\displaystyle \frac{1}{N}\sum_{i=1}^n x_i^2 f_i
                                           - 2m^2 +  m^2 
                                        =\displaystyle \frac{1}{N}\sum_{i=1}^n x_i^2 f_i -m^2\\
\end{array}$

<p>
$\begin{array}{rcl}
\text{Standard Deviation }  &:&  \sigma  =\sqrt{\sigma^2} \\
\end{array}$
sage: list_of_class_boundaries=[50,60,70,80,90,100]
sage: class_frequency=[1,9,11,7,2]
sage: class_marks=[]
sage: for i in range(len(list_of_class_boundaries)-1):
...       class_marks.insert(i,(list_of_class_boundaries[i]+list_of_class_boundaries[i+1])/2)
sage: %latex
sage: Class Marks$=\sage{latex(class_marks)}$
sage: temp=copy(class_marks)
sage: temp[0]=list_of_class_boundaries[0]
sage: temp[len(class_marks)-1]=list_of_class_boundaries[len(list_of_class_boundaries)-1]
sage: histogram(temp,bins=len(temp), weights=class_frequency)
sage: mean_of_frequency_distribution=vector(class_frequency).dot_product(vector(class_marks))/sum(class_frequency)
sage: %latex
sage: $m=\displaystyle\sage{latex(mean_of_frequency_distribution)}$
sage: squar_of_class_marks=[]
sage: for i in range(len(class_marks)):
...       squar_of_class_marks.insert(i,class_marks[i]^2)
sage: %latex
sage: squar of class marks : $\displaystyle=\sage{latex(squar_of_class_marks)}$
sage: variance_of_frequency_distribution=vector(squar_of_class_marks).dot_product(vector(class_frequency))/sum(class_frequency)-mean_of_frequency_distribution^2
sage: %latex
sage: $\sigma^2\displaystyle=\sage{latex(variance_of_frequency_distribution)}$
sage: standard_deviation_of_frequency_distribution=sqrt(variance_of_frequency_distribution)
sage: %latex
sage: $\sigma\displaystyle=\sage{latex(standard_deviation_of_frequency_distribution.simplify())}$

 

 

Geogebra와 수학의 시각화 : http://min7014.iptime.org/math/2017063002.htm