【发布时间】:2019-03-08 04:21:05
【问题描述】:
所以我正在尝试学习 python 和一些统计数据。在有关 F 检验的一个示例代码中,出现了这一点。
np.random.seed(12)
# Generate random data
voter_race = np.random.choice(a= races, p = [0.05, 0.15 ,0.25, 0.05, 0.5], size=1000)
# Use a different distribution for white ages
white_ages = stats.poisson.rvs(loc=18, mu=32, size=1000)
voter_age = stats.poisson.rvs(loc=18, mu=30, size=1000)
voter_age = np.where(voter_race=="white", white_ages, voter_age)
# Group age data by race
voter_frame = pd.DataFrame({"race":voter_race,"age":voter_age})
groups = voter_frame.groupby("race").groups
# Extract individual groups
asian = voter_age[groups["asian"]]
black = voter_age[groups["black"]]
hispanic = voter_age[groups["hispanic"]]
other = voter_age[groups["other"]]
white = voter_age[groups["white"]]
# Perform the ANOVA
stats.f_oneway(asian, black, hispanic, other, white)
在加粗的代码中,为什么voter_race出现了两次,为什么white_ages也在np.where代码中?
【问题讨论】: