How do I get a medical linear regression model in R to ignore NA values that result from patients not taking every test?

I am building a simple linear regression model to be used in neuropsychology offices that takes patient data from cognitive testing, compares it to past patient data/diagnosis, and predicts a statistical analysis of what disease a patient has (Parkinson’s or Alzheimer’s). The issue is that when I go to use the “train” function, the model can’t compute it because every patient has multiple “NA” values from not taking that specific test. I need the model to compute it anyway because we can’t have every patient take every test, but it keeps defaulting to the “accuracy” metric, which cannot be calculated since every patient has missing values. I also can’t input a constant to replace any missing values because doing so would warp the cognitive diagnosis, as it is possible for a patient to legitimately score a 0 on a test, indicating a severe memory deficiency. I have tried multiple custom metrics to work around the default “accuracy” metric, but it won’t work. I’ve tried:

model <- train(
  x = combined_data[, c("age", "hvlt_immed_total", "hvlt_delayed_recall", 
                        "hvlt_retention", "hvlt_recogn", "cvlt_tot", 
                        "cvlt_ldfr", "cvlt_recog", "wms_iv_lm1", 
                        "wms_iv_lm2", "wms_iv_lm_rec", "bvmt_immed_total", 
                        "bvmt_delayed_recall", "bvmt_retention", 
                        "bvmt_recogn", "rcf_copy", "rcf_delayed", 
                        "rcf_recogn")],
  y = combined_data$Disease,
  method = "glm",
  family = "binomial",
  trControl = ctrl,
  na.action = "na.pass"
)

as well as

model <- train(
  x = combined_data[, c("age", "hvlt_immed_total", "hvlt_delayed_recall", 
                        "hvlt_retention", "hvlt_recogn", "cvlt_tot", 
                        "cvlt_ldfr", "cvlt_recog", "wms_iv_lm1", 
                        "wms_iv_lm2", "wms_iv_lm_rec", "bvmt_immed_total", 
                        "bvmt_delayed_recall", "bvmt_retention", 
                        "bvmt_recogn", "rcf_copy", "rcf_delayed", 
                        "rcf_recogn")],
  y = combined_data$Disease,
  method = "glm",
  family = "binomial")

So I tried to create a custom metric using F1 as an accuracy measure. This worked initially using the code

custom_F1 <- function(data, lev = NULL, model = NULL) {
  predictions <- predict(model, data)
  actual <- data$Disease
  cm <- confusionMatrix(predictions, actual)
  precision <- cm$byClass["Pos Pred Value"]
  recall <- cm$byClass["Sensitivity"]
  f1_score <- ifelse(precision + recall == 0, 0, 2 * (precision * recall) / (precision + recall))
  return(f1_score)
}

but then when I went to enter this code (which also worked at first)

model <- train(
  x = combined_data[, c("age", "hvlt_immed_total", "hvlt_delayed_recall", 
                        "hvlt_retention", "hvlt_recogn", "cvlt_tot", 
                        "cvlt_ldfr", "cvlt_recog", "wms_iv_lm1", 
                        "wms_iv_lm2", "wms_iv_lm_rec", "bvmt_immed_total", 
                        "bvmt_delayed_recall", "bvmt_retention", 
                        "bvmt_recogn", "rcf_copy", "rcf_delayed", 
                        "rcf_recogn")],
  y = combined_data$Disease,
  method = "glm",
  family = "binomial",
  trControl = trainControl(method = "cv", # Cross-validation
                           summaryFunction = custom_F1, # Use custom F1 score metric
                           na.action = na.pass # Pass through NA values
                           )
)

but after I inputted all of that code successfully, and it seemed to be successful, it said that the object “model” doesn’t exist. I don’t know what to do. Please let me know if you can help! Thank you!

New contributor

Kate Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật