1
0

More than 1 year has passed since last update.

世代間の身長の変遷をnumpyでシミュレーションしてみた

Posted at

はじめに

両親の身長が子供の身長に影響を与えることは既知の事実ですが、ではある集団について身長が与えられたとき、次の世代、そのまた次の世代の身長はどう変遷していくかをシミュレートしてみました。

シミュレーション

男子= (両親の身長の合計+13)/ 2+2
女子= (両親の身長の合計-13)/ 2+2
https://keisan.casio.jp/exec/system/1372142265

男子・女子の平均身長

26-29歳 男子 平均171.8cm 標準偏差6.7cm
26-29歳 男子 平均157.9cm 標準偏差5.8cm
https://www.e-stat.go.jp/dbview?sid=0003224177

コード

# male height
def mheight(x,y):
    mu = (x + y + 13) / 2 + 2
    return np.random.normal(mu, 6.7, 1)[0]

# female height
def fheight(x,y):
    mu = (x + y - 13) / 2 + 2
    return np.random.normal(mu, 5.8, 1)[0]

def simulate():
    # number of men of women
    n = 100
    # number of generation
    niter = 100
    # men's height
    m = np.random.normal(171.8, 6.7, n)
    # women's height	
    f = np.random.normal(157.9, 5.8, n)

    mmean = [np.mean(m)]
    mstd = [np.std(m)]
    fmean = [np.mean(f)]
    fstd = [np.std(f)]

    for i in range(niter):
        m = np.random.permutation(m)
        mf = [[mheight(x,y), fheight(x,y)] for x,y in zip(m,f)]
        mf = list(zip(*mf))
        m, f = mf

        mmean.append(np.mean(m))
        mstd.append(np.std(m))
        fmean.append(np.mean(f))
        fstd.append(np.std(f))
    
    return mmean, mstd, fmean, fstd

mmean, mstd, fmean, fstd = simulate()

plt.plot(mmean)
plt.plot(fmean)

image.png

値が徐々に上がって爆発してしまいました。では、身長の計算式を微調整してもう一度試します。

# male height
def mheight(x,y):
    # mu = (x + y + 13) / 2 + 2
    mu = (x + y + 13) / 2 # <- it's changed here
    return np.random.normal(mu, 6.7, 1)[0]

# female height
def fheight(x,y):
    # mu = (x + y - 13) / 2 + 2
    mu = (x + y - 13) / 2 # <- it's changed here
    return np.random.normal(mu, 5.8, 1)[0]

image.png

値が安定しました。+2の項はもしかしたら、食の欧米化により世代間で平均身長が上がっていることを考慮しているのかもしれません。ですが、その影響はいつかは飽和するため上に上げたような異様な身長の上昇が現れると考えられます。

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0