또한 사용 사례에 가장 적합한 스케일을 고려하십시오. 로지스틱 회귀 모델링의 목적으로 육안 검사를 수행하고 연속 예측 변수를 시각화하여 스플라인 또는 다항식을 모형에 추가해야하는지 여부를 결정하려고한다고 가정합니다. 이 경우 확률 / 비율 대신 로그 홀드로 스케일을 원할 수 있습니다.
아래 요점의 함수는 일부 제한된 휴리스틱을 사용하여 연속 예측 변수를 구간으로 나누고, 평균 비율을 계산하고, 로그 홀수로 변환 한 다음 geom_smooth이러한 집계 지점 을 플로팅 합니다.
공변량에 이진 목표의 로그 홀수와 2 차 관계 (+ 소음)가있는 경우이 차트의 예는 다음과 같습니다.
devtools::source_gist("https://gist.github.com/brshallo/3ccb8e12a3519b05ec41ca93500aa4b3")
# simulated dataset with quadratic relationship between x and y
set.seed(12)
samp_size <- 1000
simulated_df <- tibble(x = rlogis(samp_size),
y_odds = 0.2*x^2,
y_probs = exp(y_odds)/(1 + exp(y_odds))) %>%
mutate(y = rbinom(samp_size, 1, prob = y_probs))
# looking at on balanced dataset
simulated_df_balanced <- simulated_df %>%
group_by(y) %>%
sample_n(table(simulated_df$y) %>% min())
ggplot_continuous_binary(df = simulated_df,
covariate = x,
response = y,
snip_scales = TRUE)
#> [1] "bin size: 18"
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'

reprex 패키지 (v0.2.1)로 2019-02-06에 작성
비교를 위해 1/0을 플로팅하고 다음을 추가하면 이차 관계는 다음과 같습니다 geom_smooth.
simulated_df %>%
ggplot(aes(x, y))+
geom_smooth()+
geom_jitter(height = 0.01, width = 0)+
coord_cartesian(ylim = c(0, 1), xlim = c(-3.76, 3.59))
# set xlim to be generally consistent with prior chart
#> `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

reprex 패키지 (v0.2.1) 에서 2019-02-25에 작성
로짓과의 관계가 명확하지 않으며 사용 geom_smooth에 문제가 있습니다.