公開・実測日:2026年11月22日。
どのコードを変えるとこの結果になりますか?
Matplotlib でJ≈1−3/(4df−1)、g=Jdを使うと、df=8,d=1では約28/31です。 ここでは data.csv の 38 行を元の順序で読み込みます。
本記事では説明用のシミュレーションデータを使います。


実際の出力はどう変わりますか?
approximate g df8 の計算には 1-3/(4*8-1) を使いました。この例での値は 0.903225806 です。
| degrees_of_freedom | approximate_correction_J | Cohen_d |
|---|---|---|
| 3 | 0.7272727272727273 | 1 |
| 4 | 0.8 | 1 |
| 5 | 0.8421052631578947 | 1 |
| 6 | 0.8695652173913043 | 1 |
| 7 | 0.8888888888888888 | 1 |
| 8 | 0.9032258064516129 | 1 |
| 9 | 0.9142857142857143 | 1 |
| 10 | 0.9230769230769231 | 1 |
| 11 | 0.9302325581395349 | 1 |
| 12 | 0.9361702127659575 | 1 |
| 13 | 0.9411764705882353 | 1 |
| 14 | 0.9454545454545454 | 1 |
表は先頭12行で、CSVには全行があります。 (38)
この設定を使う前に何を確認しますか?
ガンマ関数による補正の近似です。非常に低い自由度で精度が必要なら厳密式を使います。
図を再現してファイルを取得するには?
書き込み可能なフォルダーで python example.py を実行します。実行環境は Python 3.12.4、Matplotlib 3.8.4、NumPy 1.26.4です。スクリプトと同じ場所に data.csv、before.png、after.png、after.pdf を作ります。
以下は本文で使ったコード、データ、実行結果のファイルです。コードを動かしたり、自分の結果と見比べたりするときに使ってください。
- example.py自分のパソコンで実行できる例のコード一式です。
- data.csv例に使った入力データです。表として開けます。
- before.png比較用の変更前の図です。
- after.png本文の設定で作成した結果の図です。
- after.pdf閲覧やページへの配置に使える PDF 形式の結果です。
- 利用条件 · LICENSE.txtコード・データ・図の利用条件と、出典・フォントの情報。
ファイルの確認
- hashes.jsonダウンロードしたファイルの完全性を確認するための照合値です。
完全な Python コード
# Original Bopbun example code and synthetic input: CC0-1.0.
# Python 3.12.4, NumPy 1.26.4, Matplotlib 3.8.4. See LICENSE.txt for font rights.
from pathlib import Path
import csv,json,math,itertools
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import colors,patches
OUT=Path(__file__).resolve().parent
plt.rcdefaults()
plt.rcParams.update({'font.family':'DejaVu Sans','font.size':11,'figure.dpi':120,'savefig.dpi':160,'pdf.fonttype':42})
def pair():
f0,a0=plt.subplots(figsize=(7.2,4.5),layout='constrained')
f1,a1=plt.subplots(figsize=(7.2,4.5),layout='constrained')
return f0,a0,f1,a1
def data_file(names,rows):
with (OUT/'data.csv').open('w',newline='',encoding='utf-8') as f:
w=csv.writer(f);w.writerow(names);w.writerows(rows)
before,a0,after,ax=pair()
df=np.arange(3,41);J=1-3/(4*df-1);data_file(['degrees_of_freedom','approximate_correction_J','Cohen_d'],[(v,j,1) for v,j in zip(df,J)]);a0.plot(df,J);a0.set(xlabel='Residual degrees of freedom',ylabel='Approximate J',title='Small-sample correction approaches one as df increases')
ax.bar(['Cohen d','Approximate Hedges g'],[1,1-3/31]);ax.set(ylabel='Standardized effect',title='For d = 1 and df = 8, g is about 0.9032');metric=1-3/(4*8-1)
before.savefig(OUT/'before.png')
after.savefig(OUT/'after.png')
after.savefig(OUT/'after.pdf',metadata={'CreationDate':None,'ModDate':None})
after.canvas.draw()
print(json.dumps({'metric':float(metric),'axes':len(after.axes),'beforeTitle':a0.get_title(),'afterTitle':ax.get_title(),'afterXLabel':ax.get_xlabel(),'afterYLabel':ax.get_ylabel(),'inputRows':sum(1 for _ in (OUT/'data.csv').open())-1}))
plt.close('all')
参照元と商用利用の条件は何ですか?
独自のコードとデータは CC0-1.0です。図は DejaVu Sans を使い、フォントの許諾は別途保持します。Matplotlib と NumPy はインストール済みの依存関係を呼び出し、配布しません。
R言語入門

