我正在尝试为我的数据集建立比例赔率序数逻辑回归模型,该模型主要具有分类预测变量。我正在使用rms
软件包。
等效的glm()
模型运行没有错误。
这是我的代码:
model1=rms::lrm(`Length of Stay (Days)`~.,data = trainElective2)
这给我以下错误:
Error in X[, mmcolnames, drop = FALSE] : subscript out of bounds
这些是我数据集中的变量类型:
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 3361 obs. of 21 variables:
$ Admission Type : Factor w/ 3 levels "Elective - Booked",..: 3 3 3 3 3 3 3 3 3 3 ...
$ Site : Factor w/ 2 levels "Furness General Hospital",..: 2 1 1 2 1 1 2 1 1 2 ...
$ Treatment Function : Factor w/ 7 levels "BREAST SURGERY",..: 1 3 2 3 1 3 2 3 3 1 ...
$ Main Health Care Provider Job Title: Factor w/ 23 levels "COLORECTAL CONSULTANT",..: 4 2 12 9 15 12 5 12 2 4 ...
$ Theatre Description : Factor w/ 30 levels "FGH Theatre 1",..: 16 12 12 14 13 NA 22 NA 12 16 ...
$ ASA Code : Factor w/ 5 levels "1","2","3","4",..: 1 3 2 1 1 NA 2 NA 3 3 ...
$ Anaesthetic Type : Factor w/ 11 levels "Block","Epidural Anaesthetic",..: 4 4 4 4 4 NA 3 NA 4 4 ...
$ Was Operation Delayed? : Factor w/ 2 levels "No","Yes": 1 2 2 1 1 1 2 1 2 2 ...
$ Is Readmission? : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
$ Did Patient Die? : Factor w/ 2 levels "No","Yes": 1 1 1 1 1 1 1 1 1 1 ...
$ Patient Age On Admit : num 51 58 60 74 83 73 61 73 77 82 ...
$ Patient Sex : Factor w/ 2 levels "Female","Male": 1 1 1 1 1 1 2 1 1 1 ...
$ Patient Ethnicity : Factor w/ 15 levels "Any Other Ethnic Group",..: 14 14 11 14 14 14 11 14 14 14 ...
$ Patient Deprivation Index Decile : num 9 8 9 6 6 7 3 NA 1 4 ...
$ BMI : num 32.1 32.4 2.81 23.8 26.7 26.3 22.1 25 25.4 29.1 ...
$ Smoking Status : Factor w/ 3 levels "Current Smoker",..: 3 2 2 3 2 2 1 1 2 2 ...
$ Drinking Status : Factor w/ 2 levels "No","Yes": NA 2 2 2 2 2 NA 1 1 2 ...
$ DayOfWeek : Factor w/ 7 levels "Friday","Monday",..: 5 7 2 5 1 7 7 2 1 7 ...
$ CodeDescription : Factor w/ 45 levels "Abdominal wall",..: 8 15 34 1 8 11 17 11 25 8 ...
$ OperationDuration : num 118 111 677 78 169 NA 107 NA 337 84 ...
$ Length of Stay (Days) : num 1 1 5 1 2 1 11 2 3 1 ...
此外,我尝试使用相同的函数拟合模型,但在公式中仅包含数字变量,并且它起作用。仅当我尝试添加分类变量时,才会出现此错误。