I've got repeated measurements data on an outcome
including a total of 310 measurements (range in the amount of measurements per patient is 1-6) conducted in 149 patients. For all patients, clinical risk factors were measured once at baseline. For my analyses, I've modeled the association of all risk factors with change in the outcome, using a linear mixed model with age as time variable. Furthermore, the mixed models include a random intercept per patient and a continuous first order autoregressive correlation structure on residuals, and the natural log transformation of the outcome (as that was severely right skewed).
My data looks as follows:
# Load packages
library(tidyverse)
library(magrittr)
library(nlme)
library(broom.mixed)
library(GLMMadaptive)
# Get data.
mydata <- structure(list(pat_id = c(2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4,
4, 7, 7, 8, 8, 13, 13, 13, 13, 14, 14, 14, 14, 16, 19, 19, 22,
22, 24, 24, 25, 25, 27, 27, 28, 29, 29, 29, 29, 30, 30, 31, 31,
34, 34, 34, 34, 36, 36, 37, 38, 38, 39, 39, 40, 40, 40, 40, 46,
48, 48, 49, 49, 49, 49, 50, 50, 51, 51, 51, 52, 52, 54, 54, 56,
57, 58, 58, 60, 60, 61, 61, 61, 61, 64, 65, 65, 67, 74, 74, 74,
74, 75, 76, 76, 76, 76, 77, 77, 77, 80, 80, 81, 81, 83, 83, 84,
84, 87, 87, 88, 88, 88, 90, 92, 92, 94, 94, 95, 95, 95, 95, 96,
96, 96, 96, 97, 97, 98, 99, 102, 103, 103, 104, 104, 105, 105,
105, 105, 108, 108, 114, 114, 115, 115, 115, 116, 116, 117, 117,
119, 119, 120, 125, 125, 125, 125, 126, 126, 127, 127, 132, 132,
132, 132, 134, 134, 135, 135, 135, 135, 137, 137, 138, 138, 142,
142, 148, 151, 152, 152, 152, 153, 153, 153, 153, 154, 154, 154,
154, 158, 158, 159, 161, 162, 162, 162, 162, 164, 164, 164, 164,
165, 165, 165, 165, 169, 171, 171, 171, 171, 172, 172, 174, 179,
179, 179, 179, 185, 185, 189, 189, 189, 191, 195, 195, 195, 195,
198, 198, 198, 198, 202, 202, 202, 202, 203, 203, 203, 205, 205,
205, 205, 206, 206, 209, 209, 213, 213, 218, 221, 221, 223, 225,
226, 226, 230, 231, 250, 252, 253, 253, 255, 255, 257, 258, 258,
262, 262, 269, 271, 271, 273, 273, 275, 277, 277, 279, 279, 281,
282, 283, 285, 288, 293, 306, 308, 310, 310, 313, 315, 315, 320,
320, 332, 333, 335, 351, 355, 358, 360, 368, 371, 379, 385, 388,
399, 400), age = c(56.5941136208077, 57.138945927447, 58.7624914442163,
59.27446954141, 59.7782340862423, 62.2888432580424, 43.2169746748802,
45.1088295687885, 51.958932238193, 52.8980150581793, 53.409993155373,
53.9137577002053, 56.3121149897331, 58.507871321013, 62.9568788501027,
57.3990417522245, 61.4045174537988, 57.8015058179329, 58.6584531143053,
59.1622176591376, 61.5605749486653, 52.3613963039014, 53.3141683778234,
53.8179329226557, 56.3915126625599, 62.0342231348392, 54.1875427789185,
60.870636550308, 59.2470910335387, 59.8028747433265, 61.5003422313484,
63.1622176591376, 48.9199178644764, 54.4777549623546, 54.2067077344285,
55.4140999315537, 60.3750855578371, 50.0561259411362, 51.3949349760438,
52.3915126625599, 54.2505133470226, 55.3757700205339, 56.1095140314853,
48.5941136208077, 50.8637919233402, 64.1889117043121, 64.8021902806297,
65.8370978781656, 68.3860369609856, 68.2847364818617, 68.8405201916496,
66.6721423682409, 60.5147159479808, 64.8350444900753, 56.5119780971937,
60.8870636550308, 62.7049965776865, 63.27446954141, 63.7782340862423,
66.3819301848049, 43.8357289527721, 49.0403832991102, 49.8398357289528,
60.9582477754962, 61.8206707734428, 62.8172484599589, 65.2867898699521,
59.9780971937029, 60.8405201916496, 61.9575633127995, 62.8774811772758,
63.8740588637919, 52.9774127310062, 53.8973305954825, 52.0383299110199,
57.0431211498973, 71.151266255989, 64.1314168377823, 68.1889117043121,
68.974674880219, 45.2457221081451, 46.031485284052, 54.9541409993155,
56.1478439425051, 57.1444216290212, 59.4661190965092, 72.684462696783,
56.2847364818617, 57.3963039014374, 24.4380561259411, 54.6283367556468,
55.4277891854894, 55.9315537303217, 58.2696783025325, 60.8788501026694,
57.5523613963039, 58.4093086926762, 58.9130732375086, 61.4045174537988,
60.7063655030801, 61.5687885010267, 64.4052019164956, 40.6817248459959,
44.8350444900753, 64.7583846680356, 68.8350444900753, 36.2847364818617,
40.8350444900753, 66.5133470225873, 70.4010951403149, 56.9199178644764,
58.031485284052, 57.3771389459274, 58.3737166324435, 60.517453798768,
50.9568788501027, 54.9596167008898, 60.8980150581793, 56.9555099247091,
58.299794661191, 56.0492813141684, 57.3004791238877, 58.2970568104038,
60.5037645448323, 51.0499657768652, 52.0383299110199, 53.0102669404517,
55.460643394935, 71.0554414784394, 75.8357289527721, 69.0513347022587,
27.0554414784394, 64.0903490759754, 52.0876112251882, 53.3004791238877,
67.0691307323751, 72.0191649555099, 60.0739219712526, 61.2621492128679,
62.258726899384, 64.2929500342231, 68.1259411362081, 74.8583162217659,
66.1492128678987, 67.3757700205339, 45.264887063655, 48.8487337440109,
51.9917864476386, 60.1697467488022, 61.2621492128679, 75.170431211499,
79.3347022587269, 58.2039698836413, 59.2607802874743, 49.201916495551,
67.2498288843258, 68.0520191649555, 69.0485968514716, 71.4004106776181,
35.2443531827515, 36.435318275154, 65.2484599589322, 66.0506502395619,
46.3189596167009, 46.9349760438056, 47.9315537303217, 50.3490759753593,
67.2991101984942, 68.186173853525, 50.3025325119781, 50.8199863107461,
51.8165639972622, 54.2696783025325, 65.3032169746749, 65.8781656399726,
48.3039014373717, 53.0184804928131, 47.4962354551677, 48.1478439425051,
53.6262833675565, 48.662559890486, 61.6618754277892, 62.5681040383299,
65.4264202600958, 64.684462696783, 65.429158110883, 65.9712525667351,
68.35318275154, 55.6632443531828, 56.5256673511294, 57.0294318959617,
59.8877481177276, 51.7070499657769, 57.8015058179329, 73.7056810403833,
63.7262149212868, 47.7262149212868, 48.7173169062286, 49.3552361396304,
51.3867214236824, 53.5715263518138, 54.5051334702259, 55.0088980150582,
57.2292950034223, 74.7433264887064, 75.6577686516085, 76.1615331964408,
78.7843942505133, 82.7816563997262, 55.8220396988364, 56.6023271731691,
57.1060917180014, 59.6139630390144, 62.8199863107461, 66.8336755646817,
59.9014373716632, 60.9171800136893, 61.6399726214921, 62.1437371663244,
64.517453798768, 63.9315537303217, 67.8357289527721, 69.0650239561944,
69.8945927446954, 73.0184804928131, 42.2039698836413, 61.2566735112936,
61.927446954141, 62.4312114989733, 65.056810403833, 55.2553045859001,
55.8685831622177, 56.37234770705, 58.403832991102, 63.2936344969199,
63.9069130732375, 64.4106776180698, 66.3271731690623, 46.2943189596167,
46.9267624914442, 47.4305270362765, 53.3524982888433, 53.927446954141,
54.4312114989733, 56.3860369609856, 50.3764544832307, 55.5318275154004,
39.4332648870637, 42.8336755646817, 55.5099247091034, 59.0417522245038,
58.9568788501027, 57.741273100616, 60.8350444900753, 48.933607118412,
65.9520876112252, 56.952772073922, 61.8398357289528, 46.0123203285421,
58.2012320328542, 38.8911704312115, 23.9288158795346, 59.9288158795346,
61.8343600273785, 57.9301848049281, 59.8357289527721, 53.0239561943874,
64.1013004791239, 65.8343600273785, 52.2546201232033, 53.8343600273785,
44.4325804243669, 40.4079397672827, 41.8343600273785, 57.5195071868583,
59.0417522245038, 34.5106091718001, 53.5605749486653, 54.8336755646817,
51.6769336071184, 53.4784394250513, 48.0547570157426, 49.7905544147844,
20.7912388774812, 19.8302532511978, 59.9096509240246, 50.9075975359343,
65.9630390143737, 42.1738535249829, 61.1882272416153, 62.694045174538,
58.2121834360027, 58.0616016427105, 59.4004106776181, 54.0588637919233,
54.8336755646817, 29.5195071868583, 56.5338809034908, 48.6351813826146,
56.0958247775496, 59.4004106776181, 56.5366187542779, 49.5359342915811,
40.6707734428474, 70.7460643394935, 53.0732375085558, 44.1478439425051,
49.264887063655, 32.7611225188227, 57.8015058179329), sex = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L,
1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 1L, 1L, 1L, 1L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L,
1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 2L), .Label = c("Above 90",
"Below 90"), class = "factor"), outcome = c(99.18212890625,
510.1, 176.8329668964, 122.0704375001, 254.490352094, 629.4,
0, 42.205078125, 0, 0, 0, 0, 0, 0, 732.421875, 0, 10.4, 0,
0, 0, 282.28759765625, 0, 26.7029082031, 0, 568.4, 2002.71606445312,
0, 6.71267700195312, 549.31640625, 623.43045915852, 95.4,
111.97342532814, 0, 0, 0, 19.0041765469, 0, 0, 0, 0, 0, 376.366821289062,
682.831509766, 0, 0, 278.472900390625, 397.6406882053, 162.5097656245,
205.99365234375, NA, NA, 64.849853515625, 39.2521362304688,
0, 83.9, 1453.3, 3128, 1947.9, 4489.9032793011, 4489.89868164062,
0, 339.508056640625, 319.923370711, 41.961669921875, 33.78520275005,
10.72340001563, 217.437744140625, 240.325927734375, 277.595608875,
148.8, 39.4191863525, 98.8, 1069.62071228027, 1293.183697266,
0, 0, 438.690185546875, 0, 1296.9970703125, 2474.450875227,
0, 0, 0, 28.595733375, 30.517609375, 34.332275390625, NA,
0, 0, 0, 164.031982421875, 30.517609375, 184.759523508, 34.332275390625,
153.73388671875, 183.10546875, 232.5625000005, 186.9203574223,
190.73486328125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240.3, 450.1,
1190.2, 1193.9776708285, 400.543623047, 398.8, 386, 133.514404296875,
0, 0, 0, 0, 1762.4, 2373.146013416, 1959.685165932, 2483.4,
0, 0, 0, 0, 3198.6, 1598.35815429688, 30.517578125, 0, 209.808349609375,
1499.2, 1670.839113281, 41.961669921875, 38.1, 106.5, 311.9,
299.2, 273.1, 591.2, 1049.04174804688, 26.702880859375, 102.99693164068,
38.1, 57.8, 80.108642578125, 0, 0, 3604.9, 5512.3, 125.885009765625,
68.6646210938, 0, 289.9169921875, 339.4183043813, 495.9111523433,
381.4697265625, 0, 0, 7.62939453125, 52.7892921094, 259.3994140625,
345.7630540544, 129.6998398438, 343.32275390625, 0, 0, 0,
5.20535762305, 55.8731089424, 26.7, 0, 0, 18.8704833984375,
38.14697265625, 255.6, 597.5471151571, 0, 15.2587890625,
NA, NA, NA, 359.098083496094, 135.888671875, 261.1158471676,
446.3, 244.140625, 507.35525586, 485.9332674133, 1789.09301757812,
396.8, 1056.67114257812, 87.738037109375, 217.437744140625,
152.6, 45.7764140625, 76.3800358535, 22.88818359375, 0, 53.4,
14, 53.40576171875, 22.88818359375, 99.1822304688, 186.625251914,
640.918884277344, 57.220458984375, 304.204055786133, 442.96875,
451.0797414142, 877.38037109375, 1384.27734375, 3284.4, 3147.12524414062,
30.517578125, 91.552828125, 142.344612272, 34.332275390625,
21.3, 34.332275390625, 515, 194.549759766, 251.8, 0, 99.18212890625,
49.5911152344, 60.0625, 41.961669921875, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 186.9, 83.9234257813, 68.6646210938, 125.885009765625,
0, 0, 0, 0, 308.990478515625, 793.6, 427.24609375, 26.702880859375,
0, 0, 2273.5595703125, 0, 122.0703125, 0, 80.108642578125,
0, 0, 20.4, 15.2587890625, 0, 0, 0, 118.255615234375, 64.849853515625,
3.5, 0, 0, 0, 0, 454, 438.690185546875, 0, 22.88818359375,
45.7763671875, 961.3, 1201.6, 0, 0, 0, 0, 164.031982421875,
39.9904327392578, 0, 0, 495.8, 728.607177734375, 61.03515625,
87.738037109375, 153, 282.28759765625, 232.696533203125,
0, 274.658203125, 0, 5.80126953125, 4821.77734375, 354.766845703125,
34.332275390625, 0, 3292.08374023438, 686.6455078125, 0,
0, 0, 7.62939453125), outcome_log = c(4.60698981851472, 6.23656526577423,
5.18084472150775, 4.8127568540662, 5.54318464804626, 6.44635453854367,
0, 3.76595803753151, 0, 0, 0, 0, 0, 0, 6.59772108202634,
0, 2.43361335540045, 0, 0, 0, 5.64646262774987, 0, 3.32153739696389,
0, 6.34458317484394, 7.60275876776194, 0, 2.04286533897829,
6.31049339690497, 6.43683996893536, 4.5685062016165, 4.72715261696732,
0, 0, 0, 2.9959410790976, 0, 0, 0, 0, 0, 5.93321771515634,
6.52771155652669, 0, 0, 5.63290533043696, 5.98806048035461,
5.09687271714384, 5.33268812778915, NA, NA, 4.18737720367087,
3.69516307650511, 0, 4.4414740933173, 7.28227996418366, 8.04846874366888,
7.57502038982798, 8.40980913629405, 8.40980811252165, 0,
5.83043878651559, 5.77120237410526, 3.76030832099716, 3.54919208802184,
2.46158684579961, 5.3865010500956, 5.48614841706325, 5.62976129982523,
5.00930107108312, 3.69930458194852, 4.60316818331742, 6.97599386419496,
7.16563542577826, 0, 0, 6.08607035514364, 0, 7.16857764018329,
7.81417783022041, 0, 0, 0, 3.38763020820397, 3.45054641741155,
3.56479686322093, NA, 0, 0, 0, 5.10613928797727, 3.45054641741155,
5.22445295285155, 3.56479686322093, 5.04170678154724, 5.21550879312103,
5.45344970724784, 5.23601824234065, 5.25611349726835, 0,
0, 0, 0, 0, 0, 0, 0, 0, 5.48604097263099, 6.11168904441435,
7.0827164813698, 7.08588277869187, 5.99531617766414, 5.9909644220663,
5.95842469302978, 4.90167128845167, 0, 0, 0, 0, 7.47499904265293,
7.77239307850824, 7.58104926559275, 7.81778646068515, 0,
0, 0, 0, 8.07078108097467, 7.3773576741798, 3.45054542590184,
0, 5.35094942503542, 7.31335371153554, 7.42167956490058,
3.76030832099716, 3.66612246699132, 4.67749084756772, 5.74588365067484,
5.70444891919936, 5.61349300330874, 6.38384441566749, 6.9565852024058,
3.32153640992895, 4.64436139525114, 3.66612246699132, 4.07414185490458,
4.39578952237477, 0, 0, 8.19032667182022, 8.61491863394208,
4.84328124138846, 4.24369260057567, 0, 5.67303797626514,
5.83017516840655, 6.20841124219481, 5.94664950389253, 0,
0, 2.1551743440304, 3.98507441593456, 5.56221666018787, 5.84864170536274,
4.87290339525682, 5.84157945560271, 0, 0, 0, 1.82541305165329,
4.04082262735395, 3.32143241319329, 0, 0, 2.98923538432203,
3.66732309265895, 5.54751845218154, 6.39450524396661, 0,
2.7886336279454, NA, NA, NA, 5.88637644849708, 4.91916798142725,
5.5687865707969, 6.1032295104388, 5.50183202547328, 6.23118052572546,
6.18812708579464, 7.4900228626121, 5.98594936641987, 6.96382473477956,
4.48568862613631, 5.3865010500956, 5.03435182071357, 3.84537910286301,
4.3487288126155, 3.17338392637304, 0, 3.9963641538619, 2.70805020110221,
3.99647006220102, 3.17338392637304, 4.60699083229332, 5.23444663259896,
6.46446194722966, 4.06423682190672, 5.72098058826739, 6.09575417707235,
6.11385858333018, 6.77807972430084, 7.23365564676939, 8.0972436891071,
8.05456239405103, 3.45054542590184, 4.52777959635922, 4.96525160719335,
3.56479686322093, 3.10458667846607, 3.56479686322093, 6.24610676548156,
5.27581487269655, 5.5325986622727, 0, 4.60698981851472, 3.92377597262303,
4.111897929803, 3.76030832099716, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 5.23590990641942, 4.44174997729904, 4.24369260057567,
4.84328124138846, 0, 0, 0, 0, 5.73654158254177, 6.6778388433805,
6.05969801573823, 3.32153640992895, 0, 0, 7.729541717176,
0, 4.81275583838635, 0, 4.39578952237477, 0, 0, 3.06339092202781,
2.7886336279454, 0, 0, 0, 4.78126921657914, 4.18737720367087,
1.50407739677627, 0, 0, 0, 0, 6.12029741895095, 6.08607035514364,
0, 3.17338392637304, 3.84537810075491, 6.86932625236236,
7.09224115860547, 0, 0, 0, 0, 5.10613928797727, 3.71333869165149,
0, 0, 6.20818753061927, 6.5925062766152, 4.12770126063108,
4.48568862613631, 5.03695260241363, 5.64646262774987, 5.45402340704507,
0, 5.61916170379841, 0, 1.91710929052863, 8.48110525349429,
5.87427558849292, 3.56479686322093, 0, 8.09957971182357,
6.53327345487378, 0, 0, 0, 2.1551743440304)), row.names = c(NA,
-310L), class = c("tbl_df", "tbl", "data.frame"))
The model that I have specified is as follows:
model <-
lme(data = mydata,
fixed = outcome_log ~ age + sex*age + smoking*age +
obesity*age + diab*age + hypt*age + hyperchol*age + ckd*age,
random=~1|pat_id,
na.action="na.omit",
method="REML",
correlation=corCAR1(form=~1 + age|pat_id),
control=lmeControl(opt="optim"))
Given this model, the residual plot and QQ plot don't look all too good in my opinion. Specifically, residuals seem larger for smaller fitted values, and the tails of the QQ plot deviate from normality. The code to obtain the plots:
# Get residuals and fitted values into 1 tibble.
residuals <-
residuals(model, type="normalized") %>%
tibble(.) %>%
rename("log_residuals"=".") %>%
mutate(log_residuals=as.numeric(log_residuals))
fitted <-
predict(model) %>%
tibble(.) %>%
rename("log_fitted"=".") %>%
mutate(log_fitted=as.numeric(log_fitted))
residuals_and_fitted <-
cbind(residuals, fitted)
rm(residuals, fitted)
# Make a residual plot.
residuals_and_fitted %>%
ggplot(aes(x=log_fitted, y=log_residuals)) + geom_point() + theme_classic() +
geom_smooth(method="loess", formula=y~x, se=FALSE) +
xlab("Fitted") + ylab("Normalized residuals") +
labs(title="Residual plot")
# Make a quantile-quantile plot.
residuals_and_fitted %>%
ggplot(aes(sample=log_residuals)) + stat_qq() + theme_classic() +
labs(title="QQ plot") +
ylab("Normalized residuals") + xlab("Theoretical")
Which give the following two plots:
The diagonal line that is present in the residual plot are patients with observed outcomes of 0. Therefore I thought the model fit might improve by specifying a hurdle model that includes a logistic regression for the dichotomous indicator that the outcome is zero or not, using GLMMadaptive::mixed_model. However, this model will not converge (and I don't understand the statistics well enough to undestand why). I tried making the model more simple by removing some fixed and/or random effects but it still wouldn't converge:
zi_model <-
mixed_model(data=mydata,
fixed=outcome_log ~ age + sex*age + smoking*age +
obesity*age + diab*age + hypt*age + hyperchol*age +
ckd*age,
random= ~ 1 + age|pat_id,
family=hurdle.lognormal(),
zi_fixed= ~ sex + smoking + obesity + diab + hypt +
hyperchol + ckd,
n_phis=1,
zi_random= ~1|pat_id,
control=list(optimizer="optim"))
Error in mixed_fit(y, X, Z, X_zi, Z_zi, id, offset, offset_zi,
family, :
A large coefficient value has been detected during the
optimization.
Please re-scale you covariates and/or try setting the control
argument
'iter_EM = 0'. Alternatively, this may due to a
divergence of the optimization algorithm, indicating that an overly
complex model is fitted to the data. For example, this could be
caused when including random-effects terms (e.g., in the
zero-inflated part) that you do not need. Otherwise, adjust the
'max_coef_value' control argument.
Any thought on improving both the normality of residuals and/or how to further model the excess zeroes are greatly appreciated!
Best Answer
If you're willing to use a Bayesian approach instead, you could try
brms
. The model seems to converge then:Input
Output
This appears to identify some of the problem. In particular, it looks like there is a (quasi-) separation problem with
diab
in the hurdle equation. It's coefficient of -26 on the logic scale is really far away from zero. My guess is that this is one of the reasons that the frequentist GLMM is not converging withdiab
in the model. You can see the same, though to a lesser degree, withhyperchol
.Edit - diagnosing the problem
Essentially, the hurdle model is estimating a login on the 0 vs. not zero on the outcome. Then estimating a different model (in this case, a log-normal GLM) on the non-zero observations. One potential problem in logistic regression modes (or any model for binary dependent variables) is separation. The simplest example of this problem is when there is no variation in y for a particular category in a categorical x. Consider the cross-tabulation between zero/not-zero on the outcome and the
diab
variable.If you think about what's happening here. The model is trying to recover the log of the odds ratio for Yes vs No observations:
If we substitute the probabilities in from the cross-tab, we would get:
The odds ratio would be (0/1)/(.375/.625) = 0. When we take the log of that value, it's negative infinity. So, the model is trying to send the coefficient out toward negative infinity. In Frequentist models, the telltale sign of this is coefficients very far away from zero (for the scale of the dependent variable) with very large standard errors. This is essentially what is happening here. In the Bayesian case, the prior may provide enough information for the model to converge.
In the frequentist world, these problems are often solved with regularization (e.g., Firth login, a penalized-likelihood solution). In the Bayesian setting, these results can be approximated. Normal priors with smaller variances would do something like an L-2 penalty while using Laplace priors would generate something akin to the L-1 penalty.