tag:crieit.net,2005:https://crieit.net/tags/%E7%9B%B8%E9%96%A2%E4%BF%82%E6%95%B0/feed
「相関係数」の記事 - Crieit
Crieitでタグ「相関係数」に投稿された最近の記事
2022-08-07T06:48:41+09:00
https://crieit.net/tags/%E7%9B%B8%E9%96%A2%E4%BF%82%E6%95%B0/feed
tag:crieit.net,2005:PublicArticle/16643
2021-01-23T02:29:26+09:00
2022-08-07T06:48:41+09:00
https://crieit.net/posts/Python-Fisher
Pythonでピアソンの積率相関係数,Fisherの相関係数を求めるプログラム
<h1 id="ピアソン(Pearson)の積率相関係数"><a href="#%E3%83%94%E3%82%A2%E3%82%BD%E3%83%B3%28Pearson%29%E3%81%AE%E7%A9%8D%E7%8E%87%E7%9B%B8%E9%96%A2%E4%BF%82%E6%95%B0">ピアソン(Pearson)の積率相関係数</a></h1>
<p>相関係数を求める.</p>
<pre><code class="python">def corre_factor(retsu):
X=Estimate[index2,retsu]
Y=Target[index2,retsu]
E_xx=np.sum((X-np.mean(X))**2)
E_yy=np.sum((Y-np.mean(Y))**2)
E_xy=np.sum((X-np.mean(X))*(Y-np.mean(Y)))
return E_xy/np.sqrt(E_xx)/np.sqrt(E_yy)
df=pd.DataFrame([['H1',corre_factor(0)],['λ1',corre_factor(3)],['ω1',corre_factor(4)],
['H2',corre_factor(5)],['λ2',corre_factor(8)],['ω2',corre_factor(9)] ])
df
</code></pre>
<p>以上です.</p>
<h1 id="Fisherの相関係数"><a href="#Fisher%E3%81%AE%E7%9B%B8%E9%96%A2%E4%BF%82%E6%95%B0">Fisherの相関係数</a></h1>
<p>方向統計では,ピアソンの積率相関係数を適用できません.<br />
例えば,[0°, 360°)で満遍なくデータが散布していた場合,平均の方向など定義できないからです.<br />
そこで,Fisherの相関係数を使用します.</p>
<pre><code class="python">Sxy,Sxx,Syy=0,0,0
sin_est=Estimate[index2,2]
cos_est=Estimate[index2,1]
sin_tar=Target[index2,2]
cos_tar=Target[index2,1]
for i in range(len(index2)-1):
for j in range(i+1,len(index2)):
Sxy +=math.sin(math.atan2(sin_est[i],cos_est[i])-math.atan2(sin_est[j],cos_est[j] ))*math.sin(math.atan2(sin_tar[i],cos_tar[i])-math.atan2(sin_tar[j],cos_tar[j]))
Sxx += math.sin(math.atan2(sin_est[i],cos_est[i] )-math.atan2(sin_est[j],cos_est[j] ))**2
Syy += math.sin(math.atan2(sin_tar[i],cos_tar[i] )-math.atan2(sin_tar[j],cos_tar[j] ))**2
Rc=Sxy/(math.sqrt(Sxx*Syy))
print(Rc)
</code></pre>
kawai_mizugorou