Related
I would like to make an interactive graphs based on user input. However I'm struggle to make more than one graphs using R plotly. Suppose I have following data and codes,
dput(norwd5)
structure(list(LENGTH_OF_STAY = c(57L, 28L, 15L, 28L, 14L, 49L,
15L, 22L, 17L, 81L, 34L, 24L, 31L, 38L, 33L, 22L, 21L, 49L, 188L,
21L, 21L, 36L, 24L, 23L, 48L, 54L, 42L, 62L, 13L, 139L, 29L,
49L, 15L, 7L, 43L, 28L, 31L, 22L, 23L, 26L, 33L, 30L, 127L, 22L,
22L, 15L, 28L, 26L, 15L, 31L, 22L, 89L, 28L, 60L, 54L, 37L, 20L,
135L, 155L, 51L, 15L, 8L, 38L, 16L, 16L, 22L, 30L, 14L, 16L,
18L, 14L, 272L, 25L, 22L, 18L, 21L, 188L, 264L, 34L, 34L, 136L,
23L, 142L, 25L, 32L, 58L, 163L, 16L, 35L, 23L, 50L, 71L, 10L,
19L, 22L, 24L, 45L, 29L, 15L, 82L), PRE_OPERATIVE_LOS = c(2L,
2L, 3L, 1L, 3L, 6L, 3L, 7L, 2L, 2L, 11L, 2L, 6L, 3L, 6L, 3L,
5L, 3L, 179L, 2L, 5L, 3L, 4L, 2L, 5L, 6L, 2L, 4L, 2L, 6L, 3L,
2L, 2L, 6L, 6L, 1L, 4L, 5L, 6L, 5L, 0L, 4L, 6L, 2L, 4L, 4L, 7L,
4L, 4L, 6L, 2L, 4L, 3L, 3L, 2L, 6L, 4L, 110L, 63L, 6L, 4L, 7L,
5L, 1L, 6L, 1L, 4L, 2L, 6L, 3L, 2L, 8L, 2L, 2L, 4L, 3L, 6L, 171L,
5L, 4L, 116L, 6L, 47L, 3L, 7L, 3L, 60L, 1L, 3L, 20L, 31L, 49L,
9L, 8L, 3L, 4L, 35L, 7L, 4L, 9L), POST_OPERATIVE_LOS = c(55L,
26L, 12L, 27L, 11L, 43L, 12L, 15L, 15L, 79L, 23L, 22L, 25L, 35L,
27L, 19L, 16L, 46L, 9L, 19L, 16L, 33L, 20L, 21L, 43L, 48L, 40L,
58L, 11L, 133L, 26L, 47L, 13L, 1L, 37L, 27L, 27L, 17L, 17L, 21L,
33L, 26L, 121L, 20L, 18L, 11L, 21L, 22L, 11L, 25L, 20L, 85L,
25L, 57L, 52L, 31L, 16L, 25L, 92L, 45L, 11L, 1L, 33L, 15L, 10L,
21L, 26L, 12L, 10L, 15L, 12L, 264L, 23L, 20L, 14L, 18L, 182L,
93L, 29L, 30L, 20L, 17L, 95L, 22L, 25L, 55L, 103L, 15L, 32L,
3L, 19L, 22L, 1L, 11L, 19L, 20L, 10L, 22L, 11L, 73L), digoxin_any = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
2L, 1L, 2L), .Label = c("0:No", "1.Yes"), class = "factor")), row.names = c(NA,
-100L), class = c("data.table", "data.frame"), .internal.selfref = <pointer: 0x0000012f36b61ef0>)
num <- c('PRE_OPERATIVE_LOS','POST_OPERATIVE_LOS')
plist <- scan(text=num,what = "",quiet = T)
groups <- 'digoxin_any'
bygrp <- scan(text=groups,what="",quiet=T)
norwd5[, (bygrp) := lapply(.SD, as.factor), .SDcols = bygrp]
plotList = list()
for(i in length(plist)){
gplot <- ggplot(norwd5,aes_string(x=plist[i],group=bygrp,color=bygrp))+geom_histogram(aes(y=..density..),position = "dodge")+geom_density(alpha=.5) +theme(legend.position = "left")
plotList[[i]] <- plotly_build(gplot)
}
for(i in length(plist)){
print(plotList[[i]])
}
The goal is to show both graphs for PRE_OPERATIVE_LOS and POST_OPERATIVE_LOS. However, the codes above only show histogram for POST_OPERATIVE_LOS.
I checked maybe subplot is the way to go but how to make subplot work in a loop? Any hints?
Thanks!
There is an error in your first loop and calling each subplot won't make both appear at the same time.
First-- the issue with your first for call- when you wrote
for(i in length(plist))
You wrote for i in 2 or i == 2, meaning that you never looped. If you modify it to a range of values, now it's written: for i in 1 to 2.
for(i in 1:length(plist))
So you're aware, if you had written for(i in plist) it would have done both loops, but instead of a value, i would be the strings.
Okay, so now there are two graphs. From the plotly library, you can use the function subplot. You will want to turn the legend off for one of them, though.
subplot(plotList[[1]],
style(plotList[[2]], showlegend = FALSE))
If you wanted the outline color, that's more than okay! However, if you wanted to bars to be filled, you need to assign fill instead of color.
If you change color = bygrp to fill = bygrp, this is how this would change:
If you leave the color assignment and add fill = bygrp (so you have both), this is how this would change:
Data:
structure(list(ID = c(19903L, 28185L, 28207L, 28429L, 28522L,
29092L, 29127L, 29219L, 29304L, 30981L, 31166L, 31411L, 32010L,
33231L, 33640L, 33714L, 34093L, 34193L, 34385L, 35054L, 35337L,
35377L, 35608L, 35881L, 35940L, 37112L, 37122L, 37125L, 37170L,
37198L, 37266L, 37378L, 37589L, 37725L, 37877L, 38519L, 38522L,
38605L, 38623L, 38806L, 39040L, 39083L, 39159L, 39218L, 39593L,
39636L, 39657L, 39686L, 39700L, 39819L, 39820L, 39951L, 40151L,
40152L, 40181L, 40226L, 40248L, 40286L, 40382L, 40556L, 40623L,
40628L, 40798L, 40800L, 40815L, 40915L, 43282L, 43299L, 43450L,
43466L, 43509L, 43677L, 43740L, 43762L, 43998L, 44068L, 44130L,
44131L, 44307L, 44408L, 50679L, 50848L, 51064L, 51455L, 51690L,
51726L, 51727L, 51796L, 52126L, 52183L, 52461L, 52500L, 52502L,
52577L, 52614L, 53202L, 53320L, 53390L, 53456L, 53473L, 53474L,
53475L, 53577L, 53626L, 53851L, 53873L, 54153L, 54206L, 54532L,
54581L, 54913L, 55122L, 55267L, 55332L, 55462L, 55542L, 55612L,
55728L, 55867L, 55903L, 55920L, 55991L, 56022L, 56098L, 56307L,
56420L, 56679L, 56703L, 56746L, 56919L, 57005L, 57035L, 57405L,
57445L, 57480L, 57725L, 57808L, 57809L, 57863L, 58004L, 58060L,
58130L, 58145L, 58215L, 58229L, 58503L, 58515L, 58667L, 58999L,
59326L, 59327L, 59344L, 59361L, 59428L, 59756L, 59865L, 60099L,
60100L, 60169L, 60252L, 60280L, 60306L, 60384L, 60429L, 60472L,
60493L, 60503L, 60575L, 60603L, 60662L, 60664L, 60806L, 60846L,
60925L, 61274L, 61415L, 61727L, 61749L, 61882L, 61883L, 62081L,
62144L, 62210L, 62285L, 62411L, 62809L, 62917L, 62934L, 62937L,
62983L, 62989L, 63327L, 63329L, 63383L, 63458L, 63470L, 63589L,
64081L, 64328L, 64418L, 64507L, 64596L, 65178L, 65250L, 65302L,
65478L, 65480L, 65487L, 65565L, 65572L, 65574L, 65617L, 65802L,
65865L, 65934L, 65935L, 65974L, 65975L, 65978L, 65991L, 65995L,
66013L, 66154L, 66232L, 66237L, 66245L, 66314L, 66389L, 66396L,
66460L, 66572L, 66589L, 66735L, 67174L, 73230L, 73525L, 73539L,
73677L, 73705L, 73942L, 73953L, 74034L, 74113L, 74114L, 74425L,
74427L, 74439L, 74607L, 74618L, 74641L, 74657L, 74794L, 74800L,
74836L, 74942L, 74952L, 74962L, 74969L, 74975L, 74977L, 74985L,
74989L, 75220L, 75229L, 75377L, 75407L, 75432L, 75653L, 75732L,
75735L, 75737L, 75757L, 75895L, 75898L, 76381L, 76559L, 76574L,
76594L, 76595L, 76746L, 76751L, 76755L, 76759L, 76775L, 77088L,
77091L, 77099L, 77109L, 77134L, 77182L, 77188L, 77203L, 77204L,
77252L, 77304L, 77453L, 77528L, 77556L, 77585L, 77668L, 77733L,
77758L, 78262L, 79724L, 79730L, 79747L, 79850L, 79977L, 80052L,
80819L, 80901L, 80932L, 81064L, 81065L, 81071L, 81098L, 81112L,
81142L, 81175L, 81727L, 81938L, 82554L, 83744L, 83949L), Age = c(83L,
26L, 26L, 20L, 84L, 20L, 23L, 77L, 32L, 14L, 21L, 9L, 76L, 18L,
21L, 15L, 75L, 27L, 34L, 81L, 81L, 15L, 24L, 24L, 16L, 35L, 27L,
7L, 30L, 31L, 24L, 24L, 79L, 30L, 19L, 78L, 25L, 20L, 42L, 62L,
83L, 79L, 18L, 26L, 66L, 23L, 83L, 21L, 77L, 24L, 57L, 42L, 32L,
76L, 85L, 29L, 77L, 65L, 79L, 9L, 34L, 20L, 11L, 16L, 9L, 21L,
16L, 34L, 22L, 19L, 23L, 25L, 14L, 53L, 28L, 79L, 22L, 22L, 21L,
82L, 81L, 16L, 19L, 77L, 15L, 18L, 15L, 78L, 24L, 16L, 14L, 29L,
18L, 50L, 17L, 43L, 8L, 14L, 85L, 31L, 20L, 30L, 23L, 78L, 29L,
6L, 61L, 14L, 22L, 10L, 83L, 15L, 13L, 15L, 15L, 29L, 8L, 9L,
15L, 8L, 9L, 15L, 9L, 34L, 8L, 9L, 9L, 16L, 8L, 25L, 21L, 23L,
13L, 56L, 10L, 7L, 27L, 8L, 8L, 8L, 8L, 80L, 80L, 6L, 15L, 42L,
25L, 23L, 21L, 8L, 11L, 43L, 69L, 34L, 34L, 14L, 12L, 10L, 22L,
78L, 16L, 76L, 12L, 10L, 16L, 6L, 13L, 66L, 11L, 26L, 12L, 16L,
13L, 24L, 76L, 10L, 20L, 13L, 25L, 14L, 12L, 15L, 43L, 51L, 27L,
15L, 24L, 34L, 63L, 17L, 15L, 9L, 12L, 17L, 82L, 75L, 24L, 44L,
69L, 11L, 10L, 12L, 10L, 10L, 70L, 54L, 45L, 42L, 84L, 54L, 23L,
23L, 14L, 81L, 17L, 42L, 44L, 16L, 15L, 43L, 45L, 50L, 53L, 23L,
53L, 49L, 13L, 69L, 14L, 65L, 14L, 13L, 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2L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L,
1L, 2L, 2L), .Label = c("Male", "Female"), class = "factor"),
mean_FA_scaled = c(-1.52160414281774, -1.30073487609629,
-1.39164271432334, -1.83373601712535, -2.19478262184568,
-0.47769168350816, -1.66624867866514, -0.36061779499817,
-1.10976759821506, -2.01706489349897, -1.21708170925372,
-0.68001882107227, -0.770347444019124, -1.21756680205088,
-1.04908755742334, -0.654272701867476, 0.791455877697352,
0.0263414533200063, -1.48353521852673, -1.48465744813212,
0.885781086077571, 0.937258844105155, -1.76609091258925,
-1.40930154017838, -1.42620014597815, -0.395529996012095,
-1.79188771313106, -1.6968602062236, -1.6213377738768, -1.26578647412735,
-1.3364652186935, -1.52114801078458, 0.587760344033774, -1.4860765255686,
-1.41824317606643, -1.08076339305916, -1.84290933912549,
-1.42950167307528, -0.186882171702826, 0.94192876730175,
-1.96157606965602, -0.668579319288362, -1.2972378638421,
-2.10201405453099, 0.593407693015703, -1.87521507137852,
-0.399874110613579, -2.16173114991939, -1.71213049306692,
-2.03230549555918, 0.864393561856266, 1.66450706953957, -1.76062456838238,
-1.42625806750617, -0.635317881823001, -1.05738481631217,
-0.905876579394418, 0.0731565283419971, -1.15139145628828,
-0.742407546940581, -1.69348627721645, 0.153573329806466,
-1.09929828202549, -0.982123030841461, 0.725678742439884,
-0.850887328730634, -0.99078229928042, 0.215368360012574,
-0.402661584149531, 0.0241114744912448, -0.71105027970887,
0.366463906043185, 0.957024565541906, 0.669292134912623,
1.05465854121026, 1.82844671440856, -0.181835758574102, 0.736386984932541,
-1.09078381740658, 0.0590019549321627, -1.02109697900777,
0.321350275906775, -0.0449237467173357, 0.0239956314352051,
0.117669222625202, -0.725516181331811, 0.387590783388401,
0.829691326381412, 1.37355999410519, -0.459526044282955,
-0.460235583001197, -0.311304854080326, 0.578796987572713,
0.997164184459617, 0.18257029477137, 0.291839257380694, -0.863007408468775,
-1.87780705975741, 2.29568520056216, 0.00319456268509986,
0.881190804982003, 0.930713711438919, -0.525093214001351,
2.54459572703618, 0.166620153992923, 1.20602921449896, -0.289055747129726,
1.46280982859267, -0.391909900510859, 2.11139337878521, 1.59105533181948,
-0.209203680563451, -0.763585105622814, -0.373635658420616,
0.6654186327263, -1.62880965099135, -0.961003393687248, 0.201720599972912,
-0.335957704443747, 0.757593504378786, -0.162251041912412,
0.141221563956246, 0.0760670851249914, -2.24164331007099,
0.424957409152164, -0.0769326311392693, -0.0363368801884033,
0.30505984615121, -0.551628514025415, 0.33740901955026, -0.31017538428394,
0.966704700912213, -1.19032920349958, 0.711567610176064,
0.67279638735782, -0.599819225337876, 0.0996845881750585,
0.656310472445189, -0.0716472917074639, -0.483100106187007,
-0.511691620455773, 2.1239406297925, 1.29844301245453, 0.101559797644699,
-1.35720112572458, 0.307058138867893, -0.0785544339238233,
0.27531714151305, -0.660383423073563, -0.957274695320974,
-1.47069111968835, -0.526229923988739, -0.645664114765535,
-0.887580616731169, 0.119110020634694, -0.368379279752821,
-1.37513507883771, 0.756384392481372, 0.0675019391690662,
1.18129672203451, 0.788168830982229, 0.780204620879509, 0.283447876008828,
0.146224535938955, -0.389296191558966, 0.807326376374772,
0.590410253940679, -0.41226207741881, -1.02024263646948,
0.0042805913354707, -0.217414057160255, 0.302561980255357,
-0.0445038156391923, -0.782909175408415, 0.298159944125853,
0.0170233274998232, -0.0487465675666421, -0.456839933421037,
0.310127979852941, -0.787615299560023, -0.21877521306872,
-0.395986128045251, -0.266386709100983, 0.372589107631277,
-0.47845190356342, 0.546216128061583, -0.483150787524024,
-0.638590448156119, 2.21420409102033, 0.550980173741211,
0.781797462900053, 0.0321553266949922, 0.224223113608598,
0.45913835087484, 0.924827436153908, 2.19646562306427, -0.622017650951458,
0.554498906568413, -0.0470089217260485, -0.401307668432068,
-0.588777934059104, 0.462266113387909, 0.263008816808847,
-0.162403085923465, -0.062640494100388, 0.660965915259779,
0.113397509933743, 0.191685695243484, 1.14629763872856, 0.407899519150338,
0.473039517599588, 0.589070818605222, 1.07992680780889, 0.0233440142449823,
0.303792812725778, 0.560066613449315, -0.401387310533095,
-0.286101749200717, -0.673299923821975, 1.66157479218356,
1.44751130500445, 0.402802424684597, 1.46472123901732, -0.397311082998703,
-0.641768892006205, 0.839031172774602, -0.603272796446055,
1.48020076738061, -0.550643848049078, 0.299513859843316,
0.739782634512702, 0.517841819522891, 0.240976915588321,
0.407841597622318, 1.04632508136641, 0.140700270204069, 0.320249766874399,
-0.0720093012575883, 0.191207842637321, 1.89043722977174,
1.44823532410469, -0.403472485541808, 1.81747058484881, 0.510261339543303,
0.874862878045841, -0.274271277102676, 1.60814942277632,
-0.625188854610541, 0.262176194843562, 0.546426093600656,
-0.0371912227266948, -0.0447861830882888, 1.43379838324576,
-0.0424331210124857, 1.86971580312266, -0.228122299652913,
0.731789463645971, 0.0910470403091081, 0.618791802670374,
0.267229848163289, 0.199251694841068, 0.246957313356364,
1.87125072361518, -1.40312565725327, -0.190900477709198,
0.257180463051856, 1.48421907338698, 0.0556569866890196,
-0.667601893503029, 0.247688572647614, 0.188977863808559,
0.91364858124609, 1.5448556730327, 0.930329981315788, 0.312119032378622,
1.15772266013046, -0.0360834735033167, 1.78212397237474,
-0.861407326257228, 0.476608931763807, 1.38366006055364,
0.803771442592559, 0.145174708243597, -1.13023561817905,
0.570130478942752, 0.862605234678655, -0.328963679935357,
0.654840713671687, 0.852222800781108, 0.304538552399032,
0.652132882236762, -0.639712677761503, 0.046078213992748,
-0.171257839519489, 0.349420496423362, 0.184018332971865,
0.149583984564103, 1.29365724620189, 0.621419992004272, -0.866656464734021,
1.09066401106555, 0.810541021179871, 1.62963106948065, 1.03406743799922,
-0.118969180099629, -0.372665472826285, 1.40028353909531,
0.381002209576151, 0.508378889882659, 0.667424165633985,
0.4092534348678, 0.813183690895774, 1.08099111588625, 0.708867018932142,
0.0693192271106869, 1.26885235182742, -0.117571823236151,
0.174801569825717, 0.584835306868775, -0.84211945742664,
1.05460061968224, 1.61507104537468, -1.62830066556388, 0.0799550676933195
), RAVLT_DELAY = c(NA, 12L, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 5L, NA, NA, NA, NA, NA, NA, NA,
7L, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 5L, 12L,
NA, NA, NA, NA, 14L, NA, NA, NA, NA, NA, 6L, 7L, NA, NA,
NA, NA, 7L, 1L, 1L, 11L, 4L, 12L, 7L, 9L, 9L, 8L, 14L, 12L,
7L, 12L, 7L, 6L, 13L, 10L, 13L, NA, 11L, 14L, 8L, 0L, 11L,
15L, 13L, 6L, 9L, 9L, 12L, 5L, 14L, 15L, 12L, 4L, 15L, 8L,
15L, 14L, 5L, 12L, 8L, 9L, 9L, 13L, 6L, 4L, 10L, NA, 4L,
13L, 9L, 14L, 8L, 15L, 14L, 9L, 15L, 14L, 11L, 11L, 15L,
12L, 9L, 13L, 14L, 7L, 13L, 9L, 12L, 10L, 6L, 9L, 10L, 11L,
15L, 11L, 11L, NA, 9L, 12L, 10L, 9L, 11L, 2L, 12L, NA, 6L,
12L, 12L, 10L, 11L, 4L, 13L, 4L, 5L, 6L, 12L, 15L, 11L, 11L,
14L, 2L, 11L, 5L, 10L, 12L, 10L, NA, 12L, 8L, 12L, 12L, 8L,
7L, 14L, 14L, 7L, 8L, NA, 9L, 6L, 15L, 7L, 14L, 8L, 14L,
11L, 13L, 6L, 12L, 11L, 14L, 15L, 10L, 6L, 13L, 7L, 4L, 12L,
14L, 7L, 13L, 3L, 13L, 7L, 10L, 6L, 8L, 3L, 15L, 11L, 15L,
11L, 11L, 8L, 4L, 7L, 10L, 5L, 7L, 8L, 9L, 14L, 12L, 14L,
12L, NA, NA, 11L, 10L, 13L, 7L, 12L, 12L, 14L, 8L, 13L, 2L,
11L, 8L, 7L, 4L, 7L, 9L, 4L, 12L, 14L, 15L, 12L, 13L, 9L,
7L, 11L, 10L, 14L, 6L, 5L, 5L, 10L, 8L, 5L, 12L, 2L, 11L,
8L, NA, 9L, 7L, 8L, 12L, 10L, 7L, 13L, 15L, 9L, 6L, 4L, 10L,
8L, 13L, 10L, 9L, 7L, 7L, 15L, 8L, 12L, 9L, 10L, 12L, 6L,
13L, 8L, 11L, 9L, 1L, 13L, 12L, NA, 8L, 2L, 11L, 9L, 7L,
6L, 10L, 13L, 15L, 6L, 5L, 7L, 5L, 5L, 11L, 11L, 13L, 9L,
4L, 10L, 2L, NA, 12L, 10L, 15L, NA, 6L)), row.names = c(NA,
-324L), class = c("tbl_df", "tbl", "data.frame"))
I am using the following model in mgcv::gam:
m1 <- gam(mean_FA_scaled ~ s(Age, bs = 'ad', k = -1) + Sex +
te(Age, by = Sex, bs ='fs') +
te(RAVLT_DELAY, by = Sex, bs = 'fs') + s(RAVLT_DELAY),
data = DF,
method = 'REML', family = gaussian)
I would like to reproduce the gam plot:
But in ggplot. However, When I use predict_gam my plot is very jagged. This doesn't happen when I try to plot the smooth term effect on age.
# Plot
m1_p <- predict_gam(m1)
m1_p %>%
ggplot(aes(x = RAVLT_DELAY, y = fit)) +
geom_line(aes(color = Sex))
geom_smooth_ci(Sex, size = 1, alpha = 1) +
theme_classic(base_size = 24)
Your fit object has predictions for each age and each sex along the length of RAVLY_DELAY. With your existing code, each series tries to plot all the values from these various lines as one series, hence the jaggies.
If we tell ggplot to treat each Age,Sex combination as a different series (aka group), we get:
m1_p %>%
ggplot(aes(x = RAVLT_DELAY, y = fit)) +
geom_line(aes(color = Sex, group = interaction(Age,Sex)))
There are a lot of age groups here, which we could see separately with:
m1_p %>%
mutate(Age = round(Age, 1)) %>%
ggplot(aes(x = RAVLT_DELAY, y = fit)) +
geom_line(aes(color = Sex)) +
facet_wrap(~Age, ncol = 10)
While wrong, I liked the aesthetic qualities that arose when I grouped by Age only:
I had the same problem and I finally managed to fix it, or that's what I think. I am a beginner, not an expert, so sorry for my dummy language in this field.
This is happening because you have more variables in your model, apart from the ones you are plotting, that cause variance.
So, what you have to do is to create a new database with all the variables you are not plotting fixed somehow, the numeric you can use means, the factors, choose one, etc.
Then run the model with the function predict.gam (not "_"), that let you add a new database, that will be the one with your variables fixed.
Then predict.gam has to be turned into a database to plot it, so you bind it (the result) with your new data, and then you can use ggplot2 and geom_smooth_ci with no problem.
EXAMPLE:
model<-x~gam(s(v4, by=v3) + s(v2, by=v1)
#I want to plot the first smooth, first create the data:
new=expand.grid(v1=levels(circ$v1)[1], v2=mean(circ$v2), v3=levels(circ$v3), v4=seq(0,23, 0.1))
# see that I maintain the levels and the numbers of v3 and v4, and I fix the other ones randomly.
predict<-predict.gam(model, newdata = new, se.fit = TRUE)
mew=cbind(new,preddist2n)
mew %>%
ggplot(aes(v4, fit)) +
geom_smooth_ci(v3, ci_z = 1.96, ci_alpha = 0.05 )
If after you need to plot the second smooth, you should create another database to fix the variables out of the second smooth...
Tell me if it worked for you :)
I have the following data set:
structure(list(Age = c(83L, 26L, 26L, 20L, 20L, 77L, 32L, 21L,
15L, 75L, 27L, 81L, 81L, 15L, 24L, 16L, 35L, 27L, 30L, 31L, 24L,
24L, 31L, 79L, 30L, 19L, 20L, 42L, 62L, 83L, 79L, 18L, 26L, 66L,
23L, 83L, 77L, 80L, 57L, 42L, 32L, 76L, 85L, 29L, 65L, 79L, 9L,
34L, 20L, 16L, 34L, 22L, 19L, 23L, 25L, 14L, 53L, 28L, 79L, 22L,
22L, 21L, 82L, 81L, 16L, 19L, 77L, 15L, 18L, 15L, 78L, 24L, 16L,
14L, 29L, 18L, 50L, 17L, 43L, 8L, 14L, 85L, 31L, 20L, 30L, 23L,
78L, 29L, 6L, 61L, 14L, 22L, 10L, 83L, 15L, 13L, 15L, 15L, 29L,
8L, 9L, 15L, 8L, 9L, 15L, 9L, 34L, 8L, 9L, 9L, 16L, 8L, 25L,
21L, 23L, 13L, 56L, 10L, 7L, 27L, 8L, 8L, 8L, 8L, 80L, 80L, 6L,
15L, 42L, 25L, 23L, 21L, 8L, 11L, 43L, 69L, 34L, 34L, 14L, 12L,
10L, 22L, 78L, 16L, 76L, 12L, 10L, 16L, 6L, 13L, 66L, 11L, 26L,
12L, 16L, 13L, 24L, 76L, 10L, 65L, 20L, 13L, 25L, 14L, 12L, 15L,
43L, 51L, 27L, 15L, 24L, 34L, 63L, 17L, 15L, 9L, 12L, 17L, 82L,
75L, 24L, 44L, 69L, 11L, 10L, 12L, 10L, 10L, 70L, 54L, 45L, 42L,
84L, 54L, 23L, 23L, 14L, 81L, 17L, 42L, 44L, 16L, 15L, 43L, 45L,
50L, 53L, 23L, 53L, 49L, 13L, 69L, 14L, 65L, 14L, 13L, 22L, 67L,
59L, 52L, 54L, 44L, 78L, 62L, 69L, 10L, 63L, 57L, 22L, 12L, 62L,
9L, 82L, 53L, 54L, 66L, 49L, 63L, 51L, 9L, 45L, 49L, 77L, 49L,
61L, 62L, 57L, 67L, 16L, 65L, 75L, 45L, 16L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, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L,
2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L,
1L, 2L, 2L), .Label = c("Male", "Female"), class = "factor"),
mean_AD_scaled = c(3.15891332561581, -0.0551328105526693,
0.582747640515478, 1.94179165777054, 1.7064645993306, 2.37250948563045,
1.015775832203, 1.36189033704266, -1.05640048650493, 0.184814975542474,
-0.143366705302007, 1.81560178585347, 2.06325078470728, -0.473088628698217,
0.414641167726219, 0.199887349084444, -0.60620959209809,
-0.17879228399189, -1.03483709078065, -1.43497010225613,
-0.958595084469815, 1.0203965598582, -1.44731404613503, -1.17191867788498,
-2.02547709312595, -1.22395687266857, -1.09952727795348,
-1.0830246791849, 1.21072653232248, 1.69997357714829, 1.53648783201423,
0.208688735094353, 0.0862394522314924, 1.08662698958276,
-0.731299290763917, 2.29307697689102, -0.660008064083659,
-1.21425334459264, 1.10191939777498, -2.0957781638801, -1.14947514355972,
0.248845058764562, 2.6526135953958, 0.197907037232212, -0.222469162066061,
1.92880961340592, 1.23328008397287, -1.17288683034607, -0.308282675662673,
-1.02603570477074, -1.32647101621898, -1.58316343919798,
-0.0440210607151585, -0.388375288352846, -0.935491446193807,
-0.63789458173376, 0.454577456746182, -1.77391147749773,
0.709267564407921, 0.125735671950958, -0.821073428064989,
-0.126534054558056, 0.519597695894384, 0.188005477971066,
0.212319306823438, -1.45807374053215, 1.5856655763446, -1.25641198358011,
-0.910847565366061, -1.1191763722206, 0.25300371365424, -0.750772357310844,
0.37932560636146, -0.871791414947088, -1.92771569802088,
-1.1752191976387, 0.210449012296334, -0.347778895382139,
-0.132254955464496, 0.953616043508016, -0.0862677135627232,
0.838977990728951, -1.8993092246739, -0.0254281327692267,
0.298022803094927, -1.21559555595915, 0.0134079829994995,
-0.763094297724715, 0.334768589686298, -1.12568939786794,
-2.11786964276497, -0.0434709740895377, 0.388237009696492,
1.30050066962355, -0.260645173884043, -0.60620959209809,
1.05945271027717, -0.275717547426008, -0.0238878902174922,
0.496604074943496, 0.534009965485611, -0.692903244295693,
-0.566933407028871, 0.125625654625835, -0.518305749324122,
1.79381835547894, -0.790708646330802, -0.227860010997131,
0.347420582075538, 0.784189362817269, -0.660118081408782,
1.29962053102256, -0.561652575422924, -0.710395998990384,
-1.29315777017148, -0.457356151205503, -1.01756437073621,
0.146528946399368, -1.07136284272178, -1.42968927065019,
0.798601632408495, -0.799730066990963, -0.431348055546223,
0.569545561500617, 2.32168148142323, 0.472070211440872, 1.65145593676866,
-0.814142336582189, -0.544489872703603, -0.315433801795725,
0.382626126115175, -0.623812364117908, 0.216279930527897,
-0.606099574772967, -0.367207954999011, 0.719829227619811,
-0.749122097433987, 0.934693063586709, -0.79026857703031,
-0.371872689584264, 0.0769979969210905, -0.793899148759394,
1.50414273842782, 0.730280873506577, -0.290569886317732,
0.303743704001367, 0.390877425499463, -1.00359217044547,
-0.534918365417827, 0.325967203676389, 0.129036191704673,
0.34434009697207, -0.141386393449775, -0.363401355549725,
-0.395416397160769, -0.0235578382421178, -1.13583299524436,
1.16781977552417, -1.31890182425046, 0.139377820266317, 0.0160483988024708,
0.481311666751279, -1.05475022662807, 0.839858129329941,
0.652498624644007, -0.350199276534864, -0.262075399110649,
0.178543988010412, -1.13198238886502, -0.05117218684821,
-1.29678834190056, 0.429603523943066, 1.05098137624263, -0.956504755292464,
0.502765045150433, -0.81678275238516, -1.50263075720731,
-0.826684311646306, 2.40100397283753, 2.06633126981075, -0.470558230220369,
0.484942238480364, 0.822035322659877, 0.143888530596397,
0.384056351341786, -0.63580425255641, 0.358422314587926,
-0.372422776209885, 0.0607154328027556, -0.113221958218067,
1.02710761669075, -0.349649189909243, 2.27195365046724, -0.507634068787109,
-0.326105482332738, -1.0396778530861, 1.06484355920824, 1.32151397872221,
-0.185173288849074, -0.651888785489516, -0.171311105883464,
-0.104200537557911, -0.693673365571561, -1.26609350819101,
0.411230630647381, -0.929770545287362, -0.481009876107135,
0.386146680519137, 0.0482834750637615, -0.198265350538812,
0.790020281048832, 0.926001694901924, -1.08918564939184,
0.50298507980068, -0.0694350628187722, 1.04966116834114,
0.00878725534429612, 1.48742010500899, 0.750194009353997,
0.423772605711498, -0.596418050162068, -0.652636903300361,
-0.308942779613417, 0.314437388003408, 0.679562886624478,
-1.24312189070515, -0.432712270377761, 0.00427654501421597,
-0.197935298563442, 0.228821905592019, 1.06957430418856,
-1.61612462980509, 1.9499329398297, -0.263285589687014, 0.156430505660519,
-0.322254875953402, -0.451085163673446, -0.35526007349056,
0.10780284795577, 0.408700232169533, -0.957604928543701,
-1.05662052115517, 1.00345389178912, -0.238751726184391,
0.300003114947154, -0.397946795638617, -0.0802167606809086,
0.943714484246865, 1.10973062785877, 1.76279346979401, 1.62087112038423,
0.25533608094687, 0.226841593739787, 0.869672824438507, -1.44960240649761,
-0.450315042397579, -0.199629565370345, 0.29813282042005,
0.760425620590513, 1.87391096816911, -0.454275666102039,
-0.0559029318285365, -0.343048150401812, -1.01371376435687,
0.68880434193488, -0.29222014619459, 1.16132875334186, -1.95715633422403,
-0.534368278792206, -0.560112332871189, 1.84508642898666,
-1.19150176175703, -0.772203732244971, -0.3443683583033,
-1.45684154649076, -0.633823940704178, -1.77454957798344,
0.279539892474118, -0.875532004001301, 1.26001429397797,
-0.536590628759707, 2.1869102581465, 0.211109116247078, 0.130246382281038,
-0.355810160116181, -0.898085555651692, -0.429741802599415,
1.13360438741065, 1.61338994227581, 0.588688576072169, 0.454137387445685,
0.747113524250528, 0.460848444278238, -0.38177424884541,
-0.169990897981981, -0.747361820232001, -0.760123829946369,
0.208028631143609, -1.28748087619509, 2.33950428809329, -0.973029357526068,
-1.06091119683501, 0.917530360867389, -0.35041931118511,
-1.90613029883158, -1.15057531681095, 0.65348878057012, 0.43147381847017
)), row.names = c(NA, -308L), class = c("tbl_df", "tbl",
"data.frame"))
I am using this gam model:
m1 <- gam(mean_AD_scaled ~ s(Age, bs = 'ad', k = -1) + Sex + ti(Age, by = Sex, bs ='fs'),
data = DF,
method = 'REML',
family = gaussian)
Output:
Family: gaussian
Link function: identity
Formula:
mean_AD_scaled ~ s(Age, bs = "ad", k = -1) + Sex + ti(Age,
by = Sex, bs = "fs")
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.04691 0.06976 0.672 0.502
SexFemale -0.12950 0.09428 -1.374 0.171
Approximate significance of smooth terms:
edf Ref.df F p-value
s(Age) 2.980 3.959 8.72 2.24e-06 ***
ti(Age):SexMale 2.391 2.873 23.47 < 2e-16 ***
ti(Age):SexFemale 1.000 1.000 43.40 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Rank: 48/49
R-sq.(adj) = 0.34 Deviance explained = 35.6%
-REML = 375.4 Scale est. = 0.63867 n = 308
But when I use gtsummary, I get a repeated value for each gender 'interaction':
tbl_regression(m1, tidy_fun = tidy_gam)
I see the following in a publication, which I am trying to replicate with gender and age:
I am not sure how to fix this. My goal is to print a table for a manuscript so any other gam-related information that can be added like edf and R^2.
I think you've found a bug in the handling of these types of interactions. While we work on a fix to the bug, this code should get you what you need. Thanks
library(gtsummary)
#> #BlackLivesMatter
library(mgcv)
packageVersion("gtsummary")
#> [1] ‘1.5.2’
m1 <- gam(marker ~ s(age, bs = 'ad', k = -1) + grade + ti(age, by = grade, bs ='fs'),
data = gtsummary::trial,
method = 'REML',
family = gaussian)
tbl_regression(m1, tidy_fun = gtsummary::tidy_gam) %>%
modify_table_body(
~ .x %>%
dplyr::select(-n_obs) %>%
dplyr::distinct()
) %>%
as_kable() # convert to kable to display on SO
Characteristic
Beta
95% CI
p-value
Grade
I
—
—
II
-0.39
-0.70, -0.08
0.014
III
-0.13
-0.43, 0.18
0.4
s(age)
>0.9
ti(age):gradeI
0.6
ti(age):gradeII
>0.9
ti(age):gradeIII
0.6
Created on 2022-02-21 by the reprex package (v2.0.1)
I am trying to run lme4 package in R. I have 10 Lines in total with four plants for each line in each of the two replications. But some of the plants died and there are some missing values. Weight is the response variable. Here are some lines from the data:
Line Rep Weight PLANT
Line 1 1 NA 1
Line 1 1 NA 2
Line 1 1 NA 3
Line 1 1 NA 4
Line 2 1 26 1
Line 2 1 26 2
Line 2 1 26 3
Line 2 1 27 4
Line 1 2 26 1
Line 1 2 28 2
Line 1 2 26 3
Line 1 2 25 4
Line 2 2 24 1
Line 2 2 26 2
Line 2 2 25 3
Line 2 2 NA 4
I want to run linear mixed model using lme4 package so I tried running:
lme4 <- lmer(Weight ~ 1 + (1|Rep:Plant), data=Data)
But I got an error:
boundary (singular) fit: see ?isSingular
> dput(Data)
structure(list(Line = c("Line 1", "Line 1", "Line 1", "Line 1",
"Line 2", "Line 2", "Line 2", "Line 2", "Line 1", "Line 1", "Line 1",
"Line 1", "Line 2", "Line 2", "Line 2", "Line 2"), Rep = c(1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2), Weight = c(NA,
NA, NA, NA, 26, 26, 26, 27, 26, 28, 26, 25, 24, 26, 25, NA),
PLANT = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)), row.names = c(NA,
-16L), class = c("tbl_df", "tbl", "data.frame"))
I am using it for the first time and I am not sure about the error. I will appreciate any help!
Your model did fit, but it generated that warning because your random effects are very small. You can read more about this in this post or the help page
Let us look at your data:
ggplot(Data,aes(x=PLANT,y=Weight,col=Rep)) + geom_jitter() + geom_boxplot(alpha=0.2) + facet_wrap(~Rep)
The effects of PLANT and in combination with Rep is extremely small. Let's look at the fitted model:
fit = lmer(Weight ~ 1 + (1|PLANT:Rep),data=Data)
boundary (singular) fit: see ?isSingular
ranef(fit)
$`PLANT:Rep`
(Intercept)
1:1 0
1:2 0
2:1 0
2:2 0
3:1 0
3:2 0
4:1 0
4:2 0
This is exactly what happened. So we can try to account for some other effects and we still see very small coefficients:
fit = lmer(Weight ~ Line + (1|Rep:PLANT),data=Data)
ranef(fit)
$`Rep:PLANT`
(Intercept)
1:1 1.397563e-19
1:2 2.811371e-19
1:3 8.112169e-20
1:4 1.813251e-19
2:1 -1.725964e-19
2:2 -2.463986e-20
2:3 -2.027357e-19
2:4 -2.833681e-19
The takehome message is, there's no really systematic effect coming from PLANT, so you don't need to specify a highly complicated model, do something like:
fit = lmer(Weight ~ Line + (1|Rep),data=Data)
The data in case anyone is interested:
Data = structure(list(Line = structure(c(1L, 1L, 1L, 1L, 12L, 12L, 12L,
12L, 23L, 23L, 23L, 23L, 34L, 34L, 34L, 34L, 45L, 45L, 45L, 45L,
56L, 56L, 56L, 56L, 65L, 65L, 65L, 65L, 66L, 66L, 66L, 66L, 67L,
67L, 67L, 67L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L,
9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 13L,
13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L,
16L, 16L, 8L, 8L, 8L, 8L, 66L, 66L, 66L, 66L, 17L, 17L, 17L,
17L, 18L, 18L, 18L, 18L, 9L, 9L, 9L, 9L, 19L, 19L, 19L, 19L,
20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 24L,
24L, 24L, 24L, 25L, 25L, 25L, 25L, 2L, 2L, 2L, 2L, 26L, 26L,
26L, 26L, 27L, 27L, 27L, 27L, 10L, 10L, 10L, 10L, 28L, 28L, 28L,
28L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L,
67L, 67L, 67L, 67L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L,
33L, 33L, 33L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 37L, 37L,
37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 40L, 40L, 40L,
40L, 25L, 25L, 25L, 25L, 19L, 19L, 19L, 19L, 24L, 24L, 24L, 24L,
41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 30L, 30L, 30L, 30L, 43L,
43L, 43L, 43L, 44L, 44L, 44L, 44L, 22L, 22L, 22L, 22L, 46L, 46L,
46L, 46L, 47L, 47L, 47L, 47L, 17L, 17L, 17L, 17L, 48L, 48L, 48L,
48L, 49L, 49L, 49L, 49L, 27L, 27L, 27L, 27L, 23L, 23L, 23L, 23L,
50L, 50L, 50L, 50L, 51L, 51L, 51L, 51L, 52L, 52L, 52L, 52L, 41L,
41L, 41L, 41L, 7L, 7L, 7L, 7L, 46L, 46L, 46L, 46L, 11L, 11L,
11L, 11L, 33L, 33L, 33L, 33L, 53L, 53L, 53L, 53L, 54L, 54L, 54L,
54L, 13L, 13L, 13L, 13L, 38L, 38L, 38L, 38L, 4L, 4L, 4L, 4L,
37L, 37L, 37L, 37L, 55L, 55L, 55L, 55L, 57L, 57L, 57L, 57L, 44L,
44L, 44L, 44L, 58L, 58L, 58L, 58L, 59L, 59L, 59L, 59L, 12L, 12L,
12L, 12L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 60L, 60L, 60L,
60L, 21L, 21L, 21L, 21L, 18L, 18L, 18L, 18L, 28L, 28L, 28L, 28L,
26L, 26L, 26L, 26L, 61L, 61L, 61L, 61L, 31L, 31L, 31L, 31L, 59L,
59L, 59L, 59L, 52L, 52L, 52L, 52L, 29L, 29L, 29L, 29L, 62L, 62L,
62L, 62L, 63L, 63L, 63L, 63L, 54L, 54L, 54L, 54L, 55L, 55L, 55L,
55L, 53L, 53L, 53L, 53L, 51L, 51L, 51L, 51L, 50L, 50L, 50L, 50L,
64L, 64L, 64L, 64L, 20L, 20L, 20L, 20L, 58L, 58L, 58L, 58L, 16L,
16L, 16L, 16L, 57L, 57L, 57L, 57L, 14L, 14L, 14L, 14L, 63L, 63L,
63L, 63L, 64L, 64L, 64L, 64L, 61L, 61L, 61L, 61L, 36L, 36L, 36L,
36L, 40L, 40L, 40L, 40L, 6L, 6L, 6L, 6L, 39L, 39L, 39L, 39L,
45L, 45L, 45L, 45L, 15L, 15L, 15L, 15L, 1L, 1L, 1L, 1L, 42L,
42L, 42L, 42L, 43L, 43L, 43L, 43L, 65L, 65L, 65L, 65L, 49L, 49L,
49L, 49L, 56L, 56L, 56L, 56L, 3L, 3L, 3L, 3L, 62L, 62L, 62L,
62L, 35L, 35L, 35L, 35L, 5L, 5L, 5L, 5L, 60L, 60L, 60L, 60L,
34L, 34L, 34L, 34L), .Label = c("Line1", "Line10", "Line11",
"Line12", "Line13", "Line14", "Line15", "Line16", "Line17", "Line18",
"Line19", "Line2", "Line20", "Line21", "Line22", "Line23", "Line24",
"Line25", "Line26", "Line27", "Line28", "Line29", "Line3", "Line30",
"Line31", "Line32", "Line33", "Line34", "Line35", "Line36", "Line37",
"Line38", "Line39", "Line4", "Line40", "Line41", "Line42", "Line43",
"Line44", "Line45", "Line46", "Line47", "Line48", "Line49", "Line5",
"Line50", "Line51", "Line52", "Line53", "Line54", "Line55", "Line56",
"Line57", "Line58", "Line59", "Line6", "Line60", "Line61", "Line62",
"Line63", "Line64", "Line65", "Line66", "Line67", "Line7", "Line8",
"Line9"), class = "factor"), Rep = structure(c(1L,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 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), Weight = c(NA,
NA, NA, NA, 26L, 26L, 26L, 27L, NA, NA, NA, NA, 26L, 28L, 26L,
25L, 22L, 17L, 20L, 20L, 28L, 20L, 27L, 26L, 22L, 25L, 21L, 25L,
18L, 18L, 19L, 18L, 24L, 28L, 23L, 30L, 29L, 25L, 26L, 27L, NA,
NA, NA, NA, 29L, 30L, 29L, 30L, NA, NA, NA, NA, 33L, NA, NA,
NA, 21L, 23L, 18L, 23L, 32L, 29L, 30L, 30L, 18L, 19L, 21L, 21L,
25L, 25L, 25L, 26L, 26L, 27L, NA, NA, 29L, 29L, 27L, 29L, 26L,
NA, NA, NA, 26L, 20L, 23L, 27L, NA, NA, NA, NA, 32L, 32L, 30L,
30L, 20L, 20L, 20L, 19L, 22L, 21L, 22L, 22L, 24L, 23L, 23L, 25L,
20L, 25L, NA, NA, 27L, 26L, NA, NA, NA, NA, NA, NA, 30L, 28L,
NA, NA, 25L, 26L, 27L, 26L, NA, NA, NA, NA, 20L, 19L, NA, NA,
19L, 27L, 26L, 29L, 26L, 29L, 31L, 29L, 25L, 25L, 24L, 25L, 26L,
25L, 26L, 26L, 25L, 24L, 24L, 28L, 22L, 26L, 24L, 28L, 29L, 30L,
26L, NA, NA, NA, NA, NA, 26L, 24L, 24L, 24L, NA, NA, NA, NA,
NA, NA, NA, NA, 30L, 30L, 30L, 31L, 24L, 25L, 28L, 22L, 28L,
31L, 30L, NA, 31L, 30L, 29L, 25L, 25L, 22L, 24L, 20L, 30L, 30L,
30L, 29L, 26L, 32L, 28L, 29L, 20L, 15L, 15L, 11L, 25L, 24L, 24L,
24L, 26L, 29L, 31L, 30L, 24L, 28L, 20L, 22L, 29L, 26L, 26L, 28L,
27L, 27L, 27L, 26L, 21L, 22L, 21L, NA, 28L, 29L, 24L, 24L, 28L,
29L, 28L, 27L, 28L, 29L, 27L, 29L, NA, NA, NA, NA, 22L, 26L,
21L, 21L, 26L, 30L, 28L, 30L, 27L, 26L, 28L, 26L, 25L, 25L, 26L,
26L, 27L, 26L, 23L, 29L, NA, NA, NA, NA, 27L, 23L, 29L, 23L,
28L, 29L, 28L, 26L, 20L, NA, NA, NA, 28L, 23L, 26L, 21L, 28L,
26L, 26L, 29L, 20L, 27L, 20L, 26L, 29L, 26L, 28L, 28L, 30L, 27L,
NA, NA, 26L, 21L, 26L, 25L, 27L, 26L, 27L, 24L, 25L, 20L, 21L,
20L, 25L, 25L, 31L, 24L, 29L, 28L, 31L, 27L, 25L, 28L, 26L, 26L,
NA, NA, NA, NA, 24L, 25L, 23L, 27L, 20L, 26L, 25L, 25L, 29L,
28L, 29L, 29L, 26L, 27L, 25L, 28L, NA, NA, NA, NA, 26L, 28L,
NA, NA, 21L, 20L, 31L, 25L, 31L, 28L, 30L, 29L, 23L, 25L, 24L,
28L, 25L, 22L, 25L, 25L, 28L, 29L, 28L, 29L, 26L, 24L, 25L, 26L,
29L, 27L, NA, NA, 26L, 29L, 29L, 30L, 25L, 24L, 25L, 24L, 28L,
25L, 29L, 28L, 24L, 24L, 24L, 24L, 28L, 30L, 27L, 27L, 26L, 25L,
25L, 25L, 25L, 25L, 28L, 25L, 25L, 30L, 28L, 25L, 22L, 24L, 25L,
24L, NA, NA, NA, NA, 5L, 7L, 4L, 5L, 21L, 20L, 22L, 24L, 25L,
27L, 25L, 28L, 32L, 31L, NA, NA, 19L, 26L, 20L, NA, 26L, 26L,
30L, 25L, 28L, 31L, 30L, 26L, 5L, 8L, 4L, 8L, 25L, 25L, 28L,
25L, 28L, 28L, 27L, 26L, 30L, 27L, 27L, 24L, 32L, 29L, 31L, 25L,
30L, 30L, 27L, 28L, 16L, 20L, 16L, 21L, 25L, 22L, 25L, 20L, 24L,
25L, 18L, 25L, 25L, 26L, 29L, 29L, 21L, 20L, 22L, 21L, 19L, 22L,
19L, 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, 6L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L,
7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L,
3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L,
1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L,
8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L,
7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L, 3L, 7L, 8L, 1L
), .Label = c("24", "12", "21", "11", "13", "14", "22", "23"
), class = "factor")), row.names = c(NA, -536L), class = "data.frame")
My dataset looks like this:
> head(GLM_df)
hour Feeding Foraging Standing ID Area Feeding_Foraging
1 0 0.119 0.789 0.0339 41361 Seronera 0.908
2 1 0.0920 0.819 0.0339 41361 Seronera 0.911
3 2 0.0847 0.824 0.0678 41361 Seronera 0.909
4 3 0.233 0.632 0.132 41361 Seronera 0.866
5 4 0.254 0.597 0.124 41361 Seronera 0.852
6 5 0.245 0.664 0.0832 41361 Seronera 0.909
And I'm trying to run a glmer() model as such to verify an interaction, the error associated is found below:
> m <- glmer(cbind(Feeding_Foraging,Standing) ~ poly(hour,2)*Area+(1|ID) , data=GLM_df , family=binomial)
Error in length(value <- as.numeric(value)) == 1L :
(maxstephalfit) PIRLS step-halvings failed to reduce deviance in pwrssUpdate
In addition: Warning message:
In eval(family$initialize, rho) : non-integer counts in a binomial glm!
I apologize if I'm not asking on the right forum, but does somebody know what is the cause of this error? I've been using this dataset to run other glmer() models not having such issue, so I hope somebody can help me.
I can provide a dput() sample of the data below:
> dput(GLM_df)
structure(list(hour = c(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L,
23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L), Feeding = c(0.118579234700529,
0.0919594065024507, 0.0846994533575204, 0.233092895639896, 0.254098360072561,
0.244523639258233, 0.238513660654777, 0.245289616923379, 0.211748633393801,
0.253514225911475, 0.275555554923133, 0.222477230819087, 0.232641165221989,
0.238368461591879, 0.30265937999754, 0.433661201190504, 0.178745053292422,
0.12125395428024, 0.10605844594333, 0.163238946470857, 0.174611180767811,
0.22483854891269, 0.177868852050793, 0.183918813004901, 0.241998438164344,
0.161698956409812, 0.158105646267371, 0.36138433432542, 0.468670308578279,
0.333151183206247, 0.32072859671381, 0.301413227120555, 0.295571885509692,
0.313952640445209, 0.343315117609149, 0.309435336266141, 0.345573769698683,
0.307176684176607, 0.322987248803344, 0.303788706042306, 0.266520946564997,
0.179710144515087, 0.151781420416677, 0.272293057460473, 0.384777516681307,
0.358157688483229, 0.370418942683556, 0.295571885509692, 0.194038747691774,
0.0980730512560762, 0.104719324151116, 0.287394007254483, 0.360255008280653,
0.356867030146353, 0.303788706042306, 0.297908422154037, 0.295883423728938,
0.309435336266141, 0.335409835295781, 0.294754097684171, 0.329763205071946,
0.311693988355675, 0.252969034027794, 0.320554854245385, 0.269908924699298,
0.114670029160951, 0.145400728263743, 0.208925318281884, 0.252065573191981,
0.343637782193368, 0.234552332374672, 0.25071038193826, 0.139938227286338,
0.127049180036281, 0.0779234970889187, 0.271038250744065, 0.37923497180722,
0.365027321566604, 0.313661201465914, 0.342076501947147, 0.292896174191167,
0.283060108639971, 0.271038250744065, 0.238251365573412, 0.196721311023918,
0.191256830162143, 0.16601092858074, 0.0626775954845651, 0.134426229199678,
0.105704917790185, 0.11195058182907, 0.140192198660723, 0.14806719253611,
0.21262483463543, 0.226733921295516, 0.21891551021636, 0.120612021581109,
0.140939890386914, 0.0931693986932724, 0.2142076497816, 0.228415300022216,
0.194244079699913, 0.181821493207477, 0.186922931547631, 0.153588342088304,
0.15187488188245, 0.135519125372033, 0.171657558804575, 0.144302772386887,
0.113322027250751, 0.0931693986932724, 0.0657666343717217, 0.126775955993192,
0.0912147959234835, 0.0966201171633936, 0.143219075677262, 0.127049180036281,
0.145683059774935, 0.171657558804575, 0.140731399424803, 0.238570126957016,
0.109339294334254, 0.14013909555517, 0.190856101565613, 0.175240248325904,
0.217486338298665, 0.251366119641673, 0.295081966535877, 0.278688523950551,
0.268852458399355, 0.349726775153633, 0.328961747878886, 0.351912567498343,
0.284153004812326, 0.220218578729553, 0.179437360446302, 0.283460837236502,
0.156693988711413, 0.114187411193102, 0.207187893597627, 0.198761383878981,
0.22134790477432, 0.199890709923748, 0.218466176246294), Foraging = c(0.78939890529209,
0.81876138245603, 0.824408012679865, 0.632422585069486, 0.59741347768171,
0.66404371432296, 0.599672129771244, 0.632422585069486, 0.629034606935185,
0.575956282831139, 0.525136610816626, 0.588378869323575, 0.577085608875906,
0.574826956786372, 0.482222221115483, 0.336377829048438, 0.677595626860163,
0.811985426187429, 0.797304187605459, 0.744225863501412, 0.727285972829908,
0.702440799845036, 0.721639342606074, 0.744225863501412, 0.593480307663729,
0.692276865442133, 0.705828777979336, 0.29136611954987, 0.178520386307389,
0.320647930567756, 0.343470886718772, 0.422913132626516, 0.393706424572198,
0.350480496651808, 0.350091073877751, 0.339966081752254, 0.289107467460336,
0.294403617187519, 0.226644054501503, 0.185602280400827, 0.465282330443979,
0.671948996636328, 0.677595626860163, 0.525136610816626, 0.359125682235886,
0.398652093802729, 0.407725644438271, 0.496903459697453, 0.519489980592792,
0.647103823651456, 0.618870672532282, 0.247583017506598, 0.159987856341983,
0.170810564270999, 0.290898812221001, 0.315807961804469, 0.2952380945605,
0.274543055710583, 0.21405861848537, 0.274947456283643, 0.241067674940635,
0.254098360072561, 0.192437158028286, 0.1589743586095, 0.334732239668921,
0.591766847457876, 0.587638966052866, 0.500018841889913, 0.436807180886641,
0.401884302827407, 0.44922080447396, 0.438017173077463, 0.748633878063245,
0.820765025438681, 0.896174861331183, 0.336612021085371, 0.116546447819948,
0.204633879311769, 0.282720933965792, 0.313952640445209, 0.293235348865346,
0.217959926640019, 0.244687309699503, 0.267759562227, 0.256357012162095,
0.20666666619235, 0.110109289364776, 0.0532396563961557, 0.284590163281268,
0.810928959887485, 0.790163932612739, 0.619999998577049, 0.523384208333367,
0.47682655223493, 0.493009231956877, 0.637874503906291, 0.632422585069486,
0.726775954616143, 0.817486336921616, 0.340983605774792, 0.142779078516963,
0.193598750531475, 0.256357012162095, 0.254682494233647, 0.206783493024567,
0.19198542761038, 0.221428570920375, 0.213793102957603, 0.203278688058049,
0.194157208465701, 0.112932604476694, 0.0948633877604228, 0.380582877086458,
0.787978140268028, 0.810928959887485, 0.719125681409657, 0.625136610587118,
0.562404370293935, 0.366120217738959, 0.535519124454, 0.655009105964824,
0.782513659406253, 0.757377047442085, 0.18996877395901, 0.158105646267371,
0.182574377237322, 0.24367381196702, 0.248087431124608, 0.269869982421893,
0.283586317908142, 0.23846153791425, 0.29272131080359, 0.220218578729553,
0.13834244048395, 0.101639344029024, 0.0846994533575204, 0.23846153791425,
0.745355189546179, 0.686338796239004, 0.605318759995079, 0.500936767000192,
0.414375787195254, 0.393442622047837, 0.509364988467295), Standing = c(0.0338797813430082,
0.0338797813430082, 0.0677595626860163, 0.131754705222809, 0.124225864924363,
0.0831594632964746, 0.162622950446439, 0.101639344029024, 0.112932604476694,
0.0931693986932724, 0.0975737702678635, 0.101639344029024, 0.12046144477514,
0.128743169103431, 0.137059115433078, 0.14761904728025, 0.0677595626860163,
0.0338797813430082, 0.0338797813430082, 0.0639951425367932, 0.0423497266787602,
0.0677595626860163, 0.107285974252859, 0.054207650148813, 0.0790528231336857,
0.0609836064174147, 0.0451730417906775, 0.195749847759603, 0.229629629102611,
0.225865208953388, 0.198259461192418, 0.160928961379289, 0.183201780595526,
0.203278688058049, 0.149321999252517, 0.198605614769358, 0.212958625584623,
0.281462798849606, 0.306128024277895, 0.398379497860889, 0.111677797760286,
0.0677595626860163, 0.0547288775540901, 0.0931693986932724, 0.145830363172079,
0.153350589236774, 0.105403764178248, 0.149071037909236, 0.152459016043537,
0.135519125372033, 0.119882303213721, 0.254098360072561, 0.296740153831865,
0.255227686117328, 0.178182553729895, 0.206102003169966, 0.186338797386545,
0.175045536938875, 0.264028640811029, 0.235903662684649, 0.235855400887864,
0.189259468191977, 0.333151183206247, 0.403169397981797, 0.203278688058049,
0.0884638735067435, 0.116461748366591, 0.127819175066803, 0.183918813004901,
0.155538996165628, 0.179710144515087, 0.15951730382333, 0.190573770054421,
0.167140254625507, 0.11067395238716, 0.392349725875482, 0.526775955075159,
0.469945354112694, 0.421857922529069, 0.365901638504488, 0.43278688425262,
0.506010927800412, 0.515846993351608, 0.493989069904506, 0.555191255556392,
0.608743168001792, 0.768306009165636, 0.947540981431873, 0.590163933071755,
0.169398906715041, 0.163752276491206, 0.297658078942143, 0.42228727459678,
0.412398717726961, 0.432306009936784, 0.283743168747693, 0.300400727908006,
0.183201780595526, 0.132573057429162, 0.444808742148526, 0.6426229493448,
0.637158468483024, 0.575956282831139, 0.58688524455469, 0.657923495757771,
0.690710380928424, 0.664480872791902, 0.633879779965959, 0.690710380928424,
0.731147539305563, 0.828415298645167, 0.933333331191257, 0.504918031628057,
0.161580495635885, 0.141411261257773, 0.231511839177222, 0.389617485444594,
0.325245900892878, 0.467759561767984, 0.370341058128744, 0.244523639258233,
0.255094824229708, 0.184927139830586, 0.643715845517155, 0.774863386199767,
0.676502730687808, 0.544262293832841, 0.456830600044432, 0.468852457940339,
0.48415300435331, 0.450273223010302, 0.43497267659733, 0.449180326837947,
0.608743168001792, 0.724590162271432, 0.816393440749261, 0.525683058902804,
0.196825396373666, 0.2766848809679, 0.298142075818472, 0.393247462017059,
0.468475597191251, 0.426885244921903, 0.380496005852245), ID = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("41361",
"41365", "41366", "41366bis", "41367", "41368"), class = "factor"),
Area = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Loliondo",
"Seronera"), class = "factor"), Feeding_Foraging = c(0.907978139992619,
0.910720788958481, 0.909107466037385, 0.865515480709382,
0.851511837754272, 0.908567353581193, 0.838185790426022,
0.877712201992865, 0.840783240328986, 0.829470508742613,
0.800692165739759, 0.810856100142662, 0.809726774097895,
0.81319541837825, 0.784881601113022, 0.770039030238942, 0.856340680152585,
0.933239380467668, 0.903362633548788, 0.90746480997227, 0.901897153597719,
0.927279348757726, 0.899508194656866, 0.928144676506314,
0.835478745828073, 0.853975821851945, 0.863934424246708,
0.65275045387529, 0.647190694885669, 0.653799113774003, 0.664199483432583,
0.724326359747071, 0.68927831008189, 0.664433137097017, 0.6934061914869,
0.649401418018395, 0.634681237159019, 0.601580301364126,
0.549631303304847, 0.489390986443134, 0.731803277008976,
0.851659141151415, 0.82937704727684, 0.797429668277099, 0.743903198917193,
0.756809782285958, 0.778144587121826, 0.792475345207145,
0.713528728284566, 0.745176874907532, 0.723589996683398,
0.534977024761081, 0.520242864622636, 0.527677594417352,
0.594687518263307, 0.613716383958506, 0.591121518289437,
0.583978391976724, 0.54946845378115, 0.569701553967814, 0.570830880012581,
0.565792348428236, 0.44540619205608, 0.479529212854885, 0.604641164368219,
0.706436876618826, 0.733039694316609, 0.708944160171797,
0.688872754078621, 0.745522085020775, 0.683773136848632,
0.688727555015723, 0.888572105349583, 0.947814205474962,
0.974098358420102, 0.607650271829437, 0.495781419627168,
0.569661200878373, 0.596382135431706, 0.656029142392356,
0.586131523056514, 0.501020035279991, 0.515725560443569,
0.506010927800412, 0.453078323186013, 0.397923496354493,
0.276120217945516, 0.115917251880721, 0.419016392480946,
0.916633877677671, 0.902114514441809, 0.760192197237773,
0.671451400869477, 0.68945138687036, 0.719743153252393, 0.856790014122652,
0.753034606650595, 0.867715845003057, 0.910655735614888,
0.555191255556392, 0.371194378539179, 0.387842830231389,
0.438178505369572, 0.441605425781279, 0.360371835112871,
0.34386030949283, 0.356947696292407, 0.385450661762178, 0.347581460444935,
0.307479235716452, 0.206102003169966, 0.160630022132145,
0.50735883307965, 0.879192936191512, 0.907549077050879, 0.862344757086919,
0.752185790623399, 0.70808743006887, 0.537777776543534, 0.676250523878803,
0.89357923292184, 0.891852953740506, 0.897516142997256, 0.380824875524623,
0.333345894593276, 0.400060715535987, 0.495039931608694,
0.543169397660485, 0.548558506372443, 0.552438776307497,
0.588188313067882, 0.621683058682476, 0.572131146227896,
0.422495445296276, 0.321857922758577, 0.264136813803823,
0.521922375150751, 0.902049178257592, 0.800526207432105,
0.812506653592706, 0.699698150879173, 0.635723691969573,
0.593333331971585, 0.727831164713589)), row.names = c(NA,
-144L), vars = "hour", indices = list(c(0L, 24L, 48L, 72L, 96L,
120L), c(1L, 25L, 49L, 73L, 97L, 121L), c(2L, 26L, 50L, 74L,
98L, 122L), c(3L, 27L, 51L, 75L, 99L, 123L), c(4L, 28L, 52L,
76L, 100L, 124L), c(5L, 29L, 53L, 77L, 101L, 125L), c(6L, 30L,
54L, 78L, 102L, 126L), c(7L, 31L, 55L, 79L, 103L, 127L), c(8L,
32L, 56L, 80L, 104L, 128L), c(9L, 33L, 57L, 81L, 105L, 129L),
c(10L, 34L, 58L, 82L, 106L, 130L), c(11L, 35L, 59L, 83L,
107L, 131L), c(12L, 36L, 60L, 84L, 108L, 132L), c(13L, 37L,
61L, 85L, 109L, 133L), c(14L, 38L, 62L, 86L, 110L, 134L),
c(15L, 39L, 63L, 87L, 111L, 135L), c(16L, 40L, 64L, 88L,
112L, 136L), c(17L, 41L, 65L, 89L, 113L, 137L), c(18L, 42L,
66L, 90L, 114L, 138L), c(19L, 43L, 67L, 91L, 115L, 139L),
c(20L, 44L, 68L, 92L, 116L, 140L), c(21L, 45L, 69L, 93L,
117L, 141L), c(22L, 46L, 70L, 94L, 118L, 142L), c(23L, 47L,
71L, 95L, 119L, 143L)), group_sizes = c(6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L), biggest_group_size = 6L, labels = structure(list(
hour = 0:23), row.names = c(NA, -24L), class = "data.frame", vars = "hour"), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
Any input is appreciated!