1 year ago

#387837

test-img

D.C. the III

Trouble fitting `glmer()` and `gamm4()` models on uncomplicated data set - Is it a computer speed or complexity issue?

I am having issues with computing a GLMM in R using the lme4 package. The issue is that it is attempting to build the model but the loading stays in a suspended state (The stop sign button just remains on). Surely it can't be because of the "complexity" of my model or the data set. My full data set is under 20,000 observations. I fit a less complex model to the data and it produced a result without issue:

binary_female_model_3_5 = glmer(data = binary_female_data, formula = sex ~ device_name + (1| province), 
family = binomial, control=glmerControl(optimizer="bobyqa",  optCtrl=list(maxfun=2e5)))

For reference our professor gave us the code control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=2e5)) to add to our models if we have "convergence issues". It is not a concept that I fully understand and it isn't a part of the content of what I'm doing it was given as a fix just in case.

I am at a loss for what I could do. I attempted using a gam() and gamm4(), but I have not really learned anything on using those models and that package yet so I feel uncomfortable trying to mess with it on this constricted schedule. I posted part of the data set below. All the data is made up so it is of no concern to be shown.

The model I am attempting to fit:

binary_female_model_4 = glmer(data = binary_female_data, formula = sex ~ device_name + (device_name| province), 
family = binomial, control=glmerControl(optimizer="bobyqa",  optCtrl=list(maxfun=2e5)))

The data:

dput(head(binary_female_data, 15))
structure(list(cust_id = c("0000af7e-418a-402d-a7c4-0dfe2d7eafcb", 
"00084c10-8e0f-4ab9-a9b8-2e5eef964f60", "00092283-3131-44a5-be65-c802a6a38fd4", 
"000bbf08-551c-41c3-8ae2-c136d33e721d", "00128697-9e88-44ce-b57f-5859cff6bc09", 
"0014164a-f65a-4324-b58f-11f3576a5f54", "00146c9e-16c3-43ae-b2e7-b2d56f9343e8", 
"0014b3d9-7f56-4321-b2b7-9f06bab0dac2", "00153635-09d2-4500-8513-0d50d87a8110", 
"00169e8f-f855-4bbf-8138-7f5a1fdd1991", "001ae3ef-da49-4ce6-bfc9-71d119ec8f03", 
"001fa5b5-03e0-401c-9291-0a60c4d5a846", "0020d464-ed55-4d28-8719-1d473e74e57c", 
"0020e97e-7868-4179-a79d-b3339c1f9cd2", "0023e3e9-4742-4e54-8e27-5b243b4c1b50"
), dob = structure(c(-985, -1690, 4197, -9358, 8216, 198, 1850, 
-225, -3407, 6928, -7278, 3995, -14041, -3981, 10678), class = "Date"), 
    age = c(55, 57, 41, 78, 30, 52, 47, 53, 62, 34, 72, 42, 91, 
    63, 23), province = c("Quebec", "Alberta", "Alberta", "Ontario", 
    "Ontario", "Ontario", "Alberta", "British Columbia", "Alberta", 
    "Ontario", "Quebec", "Quebec", "Ontario", "Ontario", "Ontario"
    ), sex = c(FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, 
    FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE), pronouns = c("he/him", 
    "she/her", "he/him", "he/him", "he/him", "she/her", "she/her", 
    "he/him", "he/him", "she/her", "she/her", "she/her", "she/her", 
    "she/her", "she/her"), hhld_median_inc = c(59881, 87225, 
    97334, 65829, 65829, 65829, 97334, 65241, 97334, 83018, 50227, 
    50227, 65829, 87290, 85981), age_grp = c("51 , 64", "51 , 64", 
    "41 , 50", "65 +", "24 , 32", "51 , 64", "41 , 50", "51 , 64", 
    "51 , 64", "33 , 40", "65 +", "41 , 50", "65 +", "51 , 64", 
    "18 , 23"), emoji_modifier = structure(c("U+1F3FF", NA, NA, 
    "U+1F3FD", "U+1F3FF", NA, "U+1F3FC", NA, "U+1F3FC", "U+1F3FB", 
    "U+1F3FF", "U+1F3FD", NA, "U+1F3FB", "U+1F3FD"), .Names = c("", 
    "", "", "", "", "", "", "", "", "", "", "", "", "", "")), 
    skin_tone = c("dark", NA, NA, "medium", "dark", NA, "medium-light", 
    NA, "medium-light", "light", "dark", "medium", NA, "light", 
    "medium"), dev_id = c("mg-2020-909", "mg-2020-909", "mg-2021-960", 
    "mg-2021-960", "mg-2021-987", "mg-2021-987", "mg-2021-960", 
    "mg-2020-909", "mg-2021-960", "mg-2021-987", "mg-2020-658", 
    "mg-2020-909", "mg-2021-987", "mg-2021-960", "mg-2021-960"
    ), device_name = c("Run BE", "Run BE", "Advance 2", "Advance 2", 
    "Run ON", "Run ON", "Advance 2", "Run BE", "Advance 2", "Run ON", 
    "Active Alpha", "Run BE", "Run ON", "Advance 2", "Advance 2"
    ), line = c("Run", "Run", "Advance", "Advance", "Run", "Run", 
    "Advance", "Run", "Advance", "Run", "Active", "Run", "Run", 
    "Advance", "Advance"), released = structure(c(18586, 18586, 
    18816, 18816, 18965, 18965, 18816, 18586, 18816, 18965, 18626, 
    18586, 18965, 18816, 18816), class = "Date"), recommended_retail_price = c(299.99, 
    299.99, 145, 145, 349.99, 349.99, 145, 299.99, 145, 349.99, 
    99.99, 299.99, 349.99, 145, 145)), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -15L), groups = structure(list(
    cust_id = c("0000af7e-418a-402d-a7c4-0dfe2d7eafcb", "00084c10-8e0f-4ab9-a9b8-2e5eef964f60", 
    "00092283-3131-44a5-be65-c802a6a38fd4", "000bbf08-551c-41c3-8ae2-c136d33e721d", 
    "00128697-9e88-44ce-b57f-5859cff6bc09", "0014164a-f65a-4324-b58f-11f3576a5f54", 
    "00146c9e-16c3-43ae-b2e7-b2d56f9343e8", "0014b3d9-7f56-4321-b2b7-9f06bab0dac2", 
    "00153635-09d2-4500-8513-0d50d87a8110", "00169e8f-f855-4bbf-8138-7f5a1fdd1991", 
    "001ae3ef-da49-4ce6-bfc9-71d119ec8f03", "001fa5b5-03e0-401c-9291-0a60c4d5a846", 
    "0020d464-ed55-4d28-8719-1d473e74e57c", "0020e97e-7868-4179-a79d-b3339c1f9cd2", 
    "0023e3e9-4742-4e54-8e27-5b243b4c1b50"), .rows = structure(list(
        1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
        14L, 15L), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -15L), .drop = TRUE))

If somebody knowledgeable would be gracious enough to help.

EDIT: the 3 calls requested by Gregor:

> table(binary_female_data$sex)

FALSE  TRUE 
 7966 11091 
> table(binary_female_data$device_name)

      Active Active Alpha    Active HR      Advance    Advance 2         iDOL          Run        Run 7   Run 7 Plus 
         279         1763          299         2044         6191          158            3           43           72 
     Run 875    Run 875 X       Run BE     Run HYYH   Run Leader       Run ON 
         631           77         3736            1            2         3758 
> with(binary_female_data, table(device_name, province))
              province
device_name    Alberta British Columbia Manitoba New Brunswick Newfoundland and Labrador Nova Scotia Ontario
  Active            27               18       10             2                         0           6     140
  Active Alpha      62              119       80             5                         1          40     885
  Active HR         33               27       11             2                         1           7     137
  Advance          242              147       99             2                         3          36    1104
  Advance 2       1004              340      164            15                         9          93    2807
  iDOL              31               11        5             0                         0           2      79
  Run                0                0        0             0                         0           0       0
  Run 7              0                2        0             0                         0           0      36
  Run 7 Plus        28                1        0             0                         0           0      27
  Run 875          156               29       23             0                         0          14     337
  Run 875 X          9                5        2             0                         0           2      44
  Run BE           678              258      130             6                         3          66    1961
  Run HYYH           0                0        0             0                         0           0       0
  Run Leader         0                0        0             0                         0           0       0
  Run ON           703              242      165             8                         2          54    1952
              province
device_name    Prince Edward Island Quebec Saskatchewan Yukon
  Active                          0     75            1     0
  Active Alpha                    0    554           17     0
  Active HR                       2     78            1     0
  Advance                         1    397           13     0
  Advance 2                       1   1689           68     1
  iDOL                            0     26            4     0
  Run                             0      3            0     0
  Run 7                           0      4            1     0
  Run 7 Plus                      0     14            1     1
  Run 875                         0     64            8     0
  Run 875 X                       0     14            1     0
  Run BE                          1    592           41     0
  Run HYYH                        0      1            0     0
  Run Leader                      0      2            0     0
  Run ON                          0    595           37     0

r

lme4

mgcv

0 Answers

Your Answer

Accepted video resources