model4<- glm(data$early ~ male + age + nihss_middle+ nihss_high + macro+ micro +mca +cortical , data = data)
data <- data %>%
dplyr::select_if(is.numeric)
predictors <- colnames(data)
probabilities <- predict(model4, type = "response")
data <- data %>%
mutate(logit = log(probabilities/(1-probabilities))) %>%
gather(key = "predictors", value = "predictor.value", -logit)
ggplot(data, aes(logit, predictor.value))+
geom_point(size = 0.5, alpha = 0.5) +
geom_smooth(method = "loess") +
theme_bw() +
facet_wrap(~predictors, scales = "free_y")
## `geom_smooth()` using formula 'y ~ x'
plot(model4, which = 4, id.n = 3)
data <- augment(model4) %>%
mutate(index = 1:n())
data %>% top_n(3, .cooksd)
ggplot(data, aes(index, .std.resid)) +
geom_point(aes(color = data$early), alpha = .5) +
theme_bw()
data %>%
filter(abs(.std.resid) > 3)
regclass::VIF(model4)
## male age nihss_middle nihss_high macro
## 1.040418 1.037522 1.207140 1.335680 1.096623
## micro mca cortical
## 1.240248 1.117226 1.124693
ph <- cox.zph(model3)
ph
## chisq df p
## male 5.90e-01 1 0.442
## age 1.68e+00 1 0.194
## early 7.81e-01 1 0.377
## nihss_high 2.00e+00 1 0.157
## macro 3.11e-01 1 0.577
## micro 9.13e-04 1 0.976
## mca 2.44e-01 1 0.621
## cortical 5.17e+00 1 0.023
## nihss_middle 1.55e+00 1 0.213
## GLOBAL 1.05e+01 9 0.313
ggcoxdiagnostics(model3, type = "deviance",
linear.predictions = FALSE, ggtheme = theme_bw())
## `geom_smooth()` using formula 'y ~ x'
# Linearity/martingale residuals ## Lines shoudl be linear
ggcoxfunctional(Surv(data$late_day, data$los) ~ male + age+early+ nihss_high + macro+ micro +mca +cortical +nihss_middle, data = data)
# Multicolinearity ## VIF should be close to 1
regclass::VIF(model3)
## male age early nihss_high macro
## 1.048896 1.037049 1.031412 1.694240 1.092560
## micro mca cortical nihss_middle
## 1.193461 1.106522 1.076730 1.528283