← 返回题库
初级

样本量与标准误关系图

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    url = 'https://data.zuihe.com/wooldridge/wage1.csv'
    df = pd.read_csv(url)
    sig = df['wage'].std(ddof=0)
    ns = [10,20,50,100,200,500]
    ses = [round(sig/np.sqrt(n),4) for n in ns]
    for n,se in zip(ns,ses): print(f'n={n}: SE={se}')
    plt.plot(ns, ses, 'o-', color='steelblue')
    plt.xlabel('n'); plt.ylabel('SE'); plt.title('n与SE关系')
    plt.tight_layout(); plt.show()

示例

输入
solve()
期望输出
n=10: SE=1.3393
n=20: SE=0.9469
n=50: SE=0.5990
n=100: SE=0.4234
n=200: SE=0.2994
n=500: SE=0.1894
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码