시작하기무료로 시작하기

결과 표시하기

모델을 만들 때 마지막이자 어쩌면 가장 중요한 단계는 결과를 공유하는 일입니다.

이번 연습에서는 카운티(군) 수준의 추정치를 추출해 ggplot2로 시각화해 보겠습니다. 각 카운티의 기울기 추정치를 얻으려면 카운티 수준의 랜덤 효과 기울기를 고정 효과 기울기에 더해야 합니다.

이에 더해, 데이터를 더 명확하게 시각화할 수 있도록 범죄 비율(기울기 추정치)에 따라 카운티를 정렬하는 코드도 포함되어 있습니다.

앞서 적합한 모델 glmer_out가 미리 로드되어 있습니다.

이 연습은 강의의 일부입니다

R로 배우는 계층 및 혼합 효과 모형

강의 보기

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Extract out the fixed-effect slope for Year2
Year2_slope <- fixef(___)['Year2']

# Extract out the random-effect slopes for county
county_slope <- ranef(___)$County

# Create a new column for the slope
county_slope$slope <- county_slope$Year2 + Year2_slope

# Use the row names to create a county name column
county_slope$county <- rownames(county_slope)

# Create an ordered county-level factor based upon slope values
county_slope$county_plot <- factor(county_slope$county, 
                                   levels = county_slope$county[order(county_slope$slope)])
코드 편집 및 실행