Created
December 18, 2023 01:13
-
-
Save kazuho/1041d81beaf6258ab89708940ec9b64e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 必要なモジュールのインポート | |
import numpy as np | |
import scipy.stats as stats | |
# カウントされた足の本数 | |
counts = np.array([57, 62, 63, 60, 57, 60, 58, 60, 61, 62]) | |
# つるとかめの個体数は合計で20匹 | |
total_animals = 20 | |
# つるの足は2本、かめの足は4本 | |
crane_legs = 2 | |
turtle_legs = 4 | |
# つるの個体数を推定する関数 | |
def estimate_crane_number(legs_count): | |
# つるの個体数 = (総足数 - かめの足の総数) / (つるの足 - かめの足) | |
return (legs_count - total_animals * turtle_legs) / (crane_legs - turtle_legs) | |
# 各カウントでのつるの個体数を推定 | |
crane_counts = np.array([estimate_crane_number(x) for x in counts]) | |
# 平均と標準偏差を計算 | |
mean_crane_count = np.mean(crane_counts) | |
std_dev_crane_count = np.std(crane_counts, ddof=1) | |
# 95%信頼区間の計算 | |
confidence_interval = stats.t.interval(0.95, len(crane_counts)-1, loc=mean_crane_count, scale=std_dev_crane_count/np.sqrt(len(crane_counts))) | |
# 結果の表示 | |
print("95%信頼区間:", confidence_interval) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment