Please help!
I am trying to perform a HL test to assess the goodness of fit for my model but I keep getting the above error!
I have these packages installed: library(jtools) library(skimr) library(epiR) library(rms) library(epimisc) library(DescTools) library(car) library(readxl) library(summarytools) library(survival) library(ggplot2) library(survminer) library(PredictABEL)
This is my code:
# Final model
l_final <- glm(pro$treatment ~ pro$age,family = binomial(link="logit"),data = pro, x=TRUE)
summ(l_final)
# Assessing the fit of the model
#predict proabailities
pro$l_final_pred <- predict(l_final, type = "response")
# Hosmer-Lemeshow test
HosmerLemeshowTest(pro$l_final_pred, pro$treatment, X = l_final_pred$x)
This is the output:
> # Assessing the fit of the model
> pro$l_final_pred <- predict(l_final, type = "response")
Error:
! Assigned data `predict(l_final, type = "response")` must be compatible with existing data.
✖ Existing data has 866 rows.
✖ Assigned data has 864 rows.
ℹ Only vectors of size 1 are recycled.
Backtrace:
1. base::`$<-`(`*tmp*`, l_final_pred, value = `<dbl>`)
12. tibble (local) `<fn>`(`<vctrs___>`)
> # Hosmer-Lemeshow test
> HosmerLemeshowTest(pro$l_final_pred, pro$treatment, X = l_final_pred$x)
Error in cut.default(fit, breaks = brks, include.lowest = TRUE) :
'x' must be numeric
In addition: Warning message:
Unknown or uninitialised column: `l_final_pred`.
Thankyou!!
I know it has something to do with the lengths of the data sets (there are two missing in treatment = 864, compared to age - 866) but can't quite work out for to fix it