0

I am trying to build a continuation ratio model on a large dataset that has many categorical variables using glmnetcr package.

I'm trying to fit this model:

fit3=glmnetcr(x=trainElective2[,1:26],y=trainElective2[,27],method="forward")

This got me the following error:

Error in y * weights : non-numeric argument to binary operator

Here's the type of my variables:

 $ Admission.Type                     : Factor w/ 3 levels "Elective - Booked",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ 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/ 25 levels "Colorectal Consultant",..: 7 4 15 12 18 15 8 15 4 6 ...
 $ Dominant.Procedure.OPCS.Code       : Factor w/ 373 levels "A732","A752",..: 22 219 166 329 19 152 85 159 55 24 ...
 $ Procedure.Code.Desc                : Factor w/ 373 levels "Abdominolipectomy",..: 231 325 2 50 329 339 33 340 11 261 ...
 $ Primary.Diagnosis.ICD10.Code       : Factor w/ 330 levels "A099","A419",..: 30 220 20 301 32 1 323 183 169 32 ...
 $ Primary.Diagnosis.Desc             : Factor w/ 323 levels "Abdominal aortic aneurysm, without mention of rupture",..: 196 67 161 139 197 130 31 98 89 197 ...
 $ Secondary.Diagnosis.ICD10.Code     : Factor w/ 568 levels "A047","A099",..: NA 175 NA 510 175 285 344 229 182 107 ...
 $ Secondary.Diagnosis.Desc           : Factor w/ 550 levels "Abdominal aortic aneurysm, without mention of rupture",..: NA 177 NA 465 177 157 437 116 110 521 ...
 $ 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 ...
 $ Reason.For.Operation.Delay         : Factor w/ 56 levels "Additions / Changes to List",..: NA 30 17 NA NA NA 28 NA 30 31 ...
 $ 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 ...
 $ BMI.Category                       : Factor w/ 4 levels "Healthy","Obese",..: 2 2 4 1 3 3 1 3 3 3 ...
 $ 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 ...
 $ OperationDuration                  : num  118 111 677 78 169 NA 107 NA 337 84 ...
 $ LOS                                : Ord.factor w/ 54 levels "1"<"2"<"3"<"4"<..: 1 1 5 1 2 1 11 2 3 1 .

I followed the example from RDocumentation: https://www.rdocumentation.org/packages/glmnetcr/versions/1.0.2/topics/glmnet.cr

Also, I'm not sure if I'm using the right package.

Here is a link to a sample of my dataset:

https://github.com/connor20/MyProject/blob/master/trainElectiveDemo.xlsx

Connor
  • 3
  • 4
  • `y=trainElective2[,27]` is `LOS Ord.factor w/ 54 levels`, you need a numeric vector. – Rui Barradas Jul 07 '19 at 17:31
  • I tried to transform it into a numeric vector but it gives me the same error. Also, in the documentation it says that y should be an ordinal response variable. – Connor Jul 07 '19 at 17:34
  • @Connor can you share example data (something limited to reproduce error even with y as numeric) – Ben Jul 08 '19 at 01:05
  • @Ben I edited the post and I added a github link to my dataset. – Connor Jul 08 '19 at 09:59
  • i took a closer look and the data and the problem may be related to the covariates/factors in trainElective2. calling glmnetcr with numeric variables such as BMI and OperationDuration and keeping LOS an ordered factor seemed to work by themselves (as well as when i included Drinking.Status after converting to numeric). i admit i am not familiar with glmnetcr but interested in other methods of modeling ordinal response data in healthcare. hope this might be helpful. – Ben Jul 08 '19 at 20:13
  • @Ben Thanks! I saw that it works if I include only the numerical variables but I am trying to keep the variables as they are because I wouldn't understand anything when interpreting the model. – Connor Jul 09 '19 at 09:22

0 Answers0