I've created the following list models
models_list_1 <- data_long %>%
group_by(group) %>%
do(fit = lmerTest::lmer(values ~ group1*group2 + (1 |variable), data = .)) %>%
pull(fit) %>%
lapply(., function(x) summary(x))
If I'm interested to report iteratively each **model coefficients (i.e. models_lists[[1]]$coefficients
)**contained in each of the model into the list in a table that could be readible into a word/pdf doc created via RMarkdown, which package should I use? How could I set command lines?
I'm keeping on trying with this code, but I have no success at all:
models_list_1 %>%
+ map(~.x %>% map( ~broom::tidy(.x) %>% flextable::flextable()))
Since I get this error back
Error: No tidy method for objects of class character
Here is the dataset
dput(head(dt, 300))
structure(list(A = c("51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"51", "51", "51", "51", "51", "51", "51", "51", "51", "51", "51",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "52", "52", "52", "52", "52", "52", "52", "52", "52", "52",
"52", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54", "54", "54", "54", "54",
"54", "54", "54", "54", "54", "54", "54"), group = c("ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss", "ss",
"ss"), group1 = c("first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "first", "first",
"first", "first", "first", "first", "first", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "second", "second", "second", "second", "second",
"second", "second", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third", "third", "third", "third", "third", "third", "third",
"third"), group2 = c("first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2", "third2", "third2",
"third2", "third2", "third2", "third2", "third2", "third2", "third2",
"third2", "third2", "third2", "first1", "first1", "first1", "first1",
"first1", "first1", "first1", "first1", "first1", "first1", "first1",
"first1", "first1", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "second2", "second2", "second2",
"second2", "second2", "second2", "third2"), levels = c("A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A", "B",
"C", "D", "E", "F", "G", "H", "J", "K", "I", "I", "L", "A"),
values = c(36.266249143999, 40.2497537510374, 52.6562615613563,
38.7854251322917, 41.8513814372223, 53.4315211013568, 42.225202818289,
44.9620363291554, 54.6720061653301, 49.6027499123275, 52.9191393648181,
58.3814192488233, 59.6145521319282, 38.9293323082768, 41.5757255288692,
53.3736061956125, 36.0518342676228, 38.2354241992837, 48.4482007745706,
41.5912793982389, 43.6313444719817, 51.7588844293636, 51.0151975537306,
51.8548999820214, 54.8884285852803, 57.2129901191072, 41.5280797996481,
44.3811350572493, 55.4043480635031, 37.9952376316217, 40.832737550847,
51.1350902010486, 42.9676462342307, 45.4532980664456, 52.4927647695136,
48.8269996663362, 50.6943936069545, 55.0594399581601, 56.1861244061312,
44.9568184734022, 50.7315267276801, 69.5226358864568, 45.7562786082321,
50.9187514233206, 66.3120391015512, 49.3498917825026, 54.0549385078639,
63.8997702651793, 50.6631153700143, 53.956945721607, 53.8883136457125,
56.4672381399526, 43.7462412459985, 51.1145305899379, 68.5017390789352,
42.6158553432131, 49.3256274310641, 64.1694182774958, 46.7564973631716,
52.6751630316937, 63.2135623121441, 48.2783983450653, 52.3664955738113,
55.8320107655818, 57.2596263549935, 42.9525031865941, 47.7489527922653,
61.7844254386573, 43.3877828150891, 47.5257406450944, 59.0478140922635,
47.1516762040958, 51.0247930281068, 59.5147976810139, 50.0540027107377,
52.7129219634566, 53.6511318926034, 57.929523421786, 38.3687848283076,
44.8347560099386, 61.8802266972569, 38.2214957027207, 44.0357096847423,
58.2398159771844, 44.3270420302871, 49.2255382686988, 59.9938557975616,
49.8012637450363, 52.9643729492277, 56.2802731293203, 57.9146894232084,
38.8561586714065, 44.4688750982456, 62.1053426662461, 40.850727928741,
44.890815628412, 59.5126148464873, 45.6081709919223, 49.3499905372386,
61.1212652173052, 46.8389895823356, 47.8708676929109, 55.2453523096677,
59.948388157362, 46.0040852905529, 50.6215021234154, 62.955441582096,
42.4180949146223, 47.1826777037403, 59.4236740992582, 47.0334703934123,
51.1401025064492, 60.6989716871958, 50.8959922798314, 52.9461903511562,
57.6816228533581, 60.2186482048953, 58.7161852308419, 60.0972150696175,
63.9718285231429, 64.2438131545118, 68.1277616996079, 70.6284861844249,
62.5228696634748, 65.0856583318757, 65.4011622649207, 59.2124834739149,
60.0673617448764, 58.5582749119015, 55.769014460168, 53.1567164130045,
53.2967167211879, 56.3771036171033, 60.3728637305957, 64.0324104861749,
67.1194345279475, 60.1688421767607, 62.7218688256241, 63.5845965959489,
54.2029104966206, 55.2803284495835, 54.3739004527491, 51.6341165373444,
50.1177900590382, 50.5273147797447, 53.5204028349014, 54.7155546750593,
57.8890130760117, 59.7498137589838, 54.948916530508, 57.0492948365652,
57.6214525086291, 55.2926047469278, 55.7631788386843, 54.2756796701815,
52.1404406962007, 56.2230923800622, 57.4801396946797, 63.9681839573434,
58.1626338138437, 60.9263261999576, 65.5578942384162, 58.2923447452358,
59.7194448456873, 62.4214977980377, 54.4353878740955, 54.5479006397154,
56.0470280306929, 54.0909107826167, 50.5450397233114, 52.2429700813803,
58.6495542889789, 52.5475427078802, 55.4007038937184, 60.3425870381822,
52.8998920931005, 55.1981591776072, 58.9473117496695, 51.2834602731708,
52.1656959276459, 55.2945800728906, 55.3259337818231, 49.6163949639344,
49.9476494207853, 52.8084738089855, 48.9853666128655, 50.139150314055,
53.419327088264, 51.699168728332, 52.2051320695233, 54.1095355776162,
51.170034510232, 51.3382471693845, 51.2123481287535, 49.9412935668464,
47.8906361654274, 50.0473343786951, 60.1644392609445, 43.5783763523731,
45.3895778876135, 54.0527420726564, 48.8666703751771, 49.7969413341886,
55.8037374266818, 53.218816657787, 52.5842683296341, 56.3088759867162,
56.8649046807896, 51.8106493401599, 52.7824009345564, 63.2788201390174,
45.9162542362245, 46.4437448871286, 53.767844291789, 50.6498572804291,
51.0105359441602, 55.7463921593046, 55.926045915516, 55.077230852852,
55.9614279900414, 55.2628099655258, 50.754416368133, 52.6005799397852,
60.5077997492971, 41.5325770962378, 43.1434830625967, 50.3261106575348,
45.5631565277737, 47.0375831423404, 51.487626606131, 47.2444464557277,
48.4030082283098, 49.3906181732595, 50.9813007346846, 48.7628763185683,
51.4302038359579, 63.4030666728381, 43.6909169916252, 47.8276204284005,
56.6583986527968, 47.6842545649077, 51.2648003671509, 56.0401855384134,
52.1800664086532, 56.6187285539854, 53.6664615799653, 55.0384350436334,
47.2314761012372, 49.3492021621468, 54.7401434682908, 43.2733885719763,
43.8113276231576, 51.1700388369216, 47.2664045061793, 47.9948715800227,
51.9050381096835, 49.7744661856655, 48.7830347342135, 50.2409562222778,
50.3616701199615, 55.5414435577812, 57.8124899386777, 61.9003140352528,
46.6726350995775, 48.2206106900028, 55.4063001308578, 49.61263548544,
49.5768944348476, 56.3721122874941, 50.9864672664597, 49.4927921073265,
51.1505332511655, 50.3937914109181, 49.6858443246175, 52.2310074124104,
65.0981004360619, 45.9848416398862, 48.5644263351238, 55.0633265321648,
50.1591836526911, 51.5140374120639, 53.7899021820967, 53.1104206811284,
53.4484460701452, 51.0824297346564, 51.0745588992281, 50.2388856489597,
53.9699071086295, 65.4046229884164, 43.398346143465, 46.8512784208735,
55.0261915939541, 48.2163881506462, 50.2557183555402, 54.5941383032222,
52.2780009055847, 53.0240343383564, 52.9989631400021, 51.6591785051503,
55.0374994689839)), row.names = c(NA, -300L), class = c("tbl_df",
"tbl", "data.frame"))
There is a function in the gtsummary package that will build and summarize regression models stratified by the signals
column. The resulting tables can either be merged to have a wide summary of the results, or stacked to have a long summary table. The example below shows the first few rows of stacked results.
I've used modify_column_unhide()
to show the SE and t-statistic, which are hidden by default. You can similarly hide the ci column if needed with modify_column_hide()
.
data_long %>%
tbl_strata(
strata = signals,
~ lmerTest::lmer(value ~ COND*SES + (1 |ID), data = .x) %>%
tbl_regression(),
.combine_with = "tbl_stack"
) %>%
modify_column_unhide(c(std.error, statistic)) %>%
as_flex_table()