추정치 차이의 유의성
오차 막대가 있는 선 그래프는 추세를 대략적으로 보여주지만, 연도별 차이가 통계적으로 유의미할까요? 이 연습 문제에서는 필라델피아의 중위 주택 가격 변화의 유의성을 판단해 봅니다. 2011년부터 2017년까지 연도별 차이를 평가할 거예요.
두 표본 Z-통계량의 공식은 다음과 같습니다:
$$Z = \frac{x_1 - x_2}{\sqrt{SE_{x_1}^2 + SE_{x_2}^2}}$$
philly DataFrame에는 median_home_value, median_home_value_moe, year 열이 준비되어 있어요.
pandas는 pd로 임포트되어 있고, numpy 모듈에서 sqrt 함수가 임포트되어 있어요.
이 연습은 강의의 일부입니다
Python으로 미국 인구조사 데이터 분석하기
연습 안내
x1에는 현재 연도의 중위 주택 가격을,x2에는 이전 연도(현재 연도에서 1을 뺀 값)의 중위 주택 가격을 설정하세요.se_x1에는 현재 연도의 중위 주택 가격 MOE를Z_CRIT로 나눈 값을,se_x2에는 이전 연도에 대해 동일한 계산 결과를 설정하세요.- Python의 삼항 연산자(
result1 if condition else result2)를 사용해,z의 절댓값이Z_CRIT보다 크면 빈 문자열을 반환하고, 그렇지 않으면"not "를 반환하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Set the critical Z score for 90% confidence, prepare message
Z_CRIT = 1.645
msg = "Philadelphia median home values in {} were {}significantly different from {}."
for year in range(2012, 2018):
# Assign current and prior year's median home value to variables
x1 = int(philly[philly["year"] == ____]["median_home_value"])
x2 = int(____)
# Calculate standard error as 90% MOE / critical Z score
se_x1 = float(____)
se_x2 = float(____)
# Calculate two-sample z-statistic, output message if greater than critical Z score
z = (x1 - x2) / sqrt(se_x1**2 + se_x2**2)
print(msg.format(year, ____, year - 1))