# Memory allocating error with coxph model

I'm working with cox models and as I am adding more variables, I am facing a memory issue. I tried to subset my dataframe by selecting columns which have variables of interest but even then I am facing this problem. How can I overcome that?

My data has around 451,557 observations with 270 variables. 70 Percent of variables are categorical (strings).

coxdf_2<- coxph(surv_df ~ NS_group + age_at_recruitment + Gender + Alcohol_drinking +
Smoking + Diabetes + BMI +  +Hypertention,
method="breslow", data = DFMODEL)


Error: cannot allocate vector of size 16.1 Gb

coxdf_3<- coxph(surv_df ~ NS_group + SOC+ towndep_I + Education+age_at_recruitment +
Gender + Alcohol_drinking  + Smoking + Diabetes + BMI +
+Hypertention,
method="breslow", data = DFMODEL)


Error: cannot allocate vector of size 24.4 Gb

• Have you tried my solution below? If you think that my answer helped you, please consider accepting it by clicking the checkmark (✔️) on the left side under the vote arrows and/or upvoting (▲). In reference to What should I do when someone answers my question? Thanks! – M-- Jun 29 '20 at 16:48

If you're using a 64-bit version of R on Windows (I'm not sure about other operating systems), then you can allocate additional memory to R with memory.limit function.
memory.limit(size = 25000) ## limit is set based on Mb