How do I draw a line over the Poisson curve? - r

How do I draw a line over my Poisson curve in R?
This is the code I used for my plot;
plot(dogbites$daily.dogbites, dpois(dogbites$daily.dogbites, dogbites_lambda),ylab="prob(x)", main="Poisson dog bites")
and this is the plot I got:
I'm hoping to get something like this:
May I know what code can I use for this?
Edit: I tried lines function and type = "o" but I got this instead
> dput(dogbites)
structure(list(daily.dogbites = c(1L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 1L, 3L, 0L, 6L, 9L, 15L, 3L, 4L, 3L,
7L, 6L, 1L, 2L, 3L, 4L, 2L, 5L, 3L, 1L, 6L, 2L, 0L, 0L, 3L, 3L,
6L, 1L, 3L, 2L, 2L, 5L, 6L, 7L, 4L, 10L, 4L, 18L, 4L, 3L, 2L,
5L, 4L, 3L, 2L, 6L, 4L, 6L, 6L, 1L, 2L, 5L, 10L, 4L, 4L, 3L,
0L, 3L, 4L, 2L, 3L, 3L, 5L, 5L, 5L, 8L, 13L, 10L, 12L, 4L, 5L,
3L, 3L, 5L, 4L, 2L, 6L, 4L, 2L, 1L, 3L, 3L, 7L, 5L, 3L, 2L, 5L,
6L, 5L, 3L, 6L, 5L, 3L, 6L, 5L, 9L, 7L, 8L, 12L, 5L, 2L, 6L,
8L, 4L, 2L, 3L, 6L, 6L, 7L, 6L, 5L, 3L, 3L, 6L, 4L, 3L, 6L, 2L,
2L, 6L, 2L, 4L, 5L, 3L, 4L, 5L, 9L, 12L, 9L, 16L, 7L, 3L, 2L,
3L, 0L, 1L, 1L, 2L, 2L, 2L, 3L, 1L, 2L, 3L, 6L, 4L, 6L, 2L, 6L,
5L, 8L, 3L, 3L, 6L, 7L, 5L, 9L, 18L, 22L, 0L, 7L, 5L, 7L, 1L,
5L, 2L, 4L, 1L, 4L, 5L, 3L, 9L, 5L, 4L, 2L, 4L, 4L, 0L, 4L, 4L,
5L, 4L, 9L, 8L, 9L, 7L, 4L, 13L, 12L, 24L, 7L, 4L, 5L, 10L, 2L,
2L, 3L, 8L, 8L, 4L, 6L, 6L, 3L, 7L, 6L, 2L, 6L, 5L, 2L, 1L, 7L,
0L, 8L, 11L, 2L, 10L, 3L, 7L, 9L, 10L, 7L, 2L, 2L, 5L, 2L, 1L,
8L, 4L, 4L, 5L, 3L, 3L, 2L, 4L, 7L, 3L, 2L, 1L, 3L, 7L, 9L, 8L,
2L, 4L, 8L, 7L, 4L, 9L, 21L, 3L, 2L, 1L, 5L, 3L, 4L, 3L, 3L,
4L, 4L, 2L, 5L, 5L, 2L, 3L, 1L, 4L, 4L, 0L, 1L, 7L, 4L, 2L, 2L,
1L, 5L, 6L, 3L, 7L, 7L, 14L, 4L, 1L, 4L, 6L, 6L, 1L, 2L, 3L,
2L, 0L, 8L, 3L, 1L, 5L, 1L, 4L, 3L, 5L, 7L, 0L, 3L, 3L, 5L, 2L,
4L, 7L, 6L, 7L, 9L, 19L, 5L, 0L, 3L, 0L, 1L, 3L, 4L, 1L, 5L,
2L, 4L, 3L, 6L, 3L, 4L, 7L, 5L, 9L, 3L, 7L, 6L, 5L, 3L, 6L, 5L,
3L, 5L, 8L, 12L, 5L, 17L, 3L, 3L, 2L, 4L, 5L, 4L, 2L, 2L, 1L,
3L, 5L, 4L, 3L, 2L, 1L, 2L, 4L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L
)), class = "data.frame", row.names = c(NA, -378L))
> dput(dogbites_lambda)
4.50529100529101

You need to sort the data by the x axis values
set.seed(42)
x = sample(1:25)
y = dpois(x, 5)
graphics.off()
plot(sort(x), y[order(x)], type = "o")

Related

warning when running clmm model

I am trying to run a clmm to examine the effects of average_Mg, average_Mn, and average_ZN on the response variable (Spawn_ID)
I have two random effects that are added into the model "(1|Time/ID)" (time is nested into ID and each ID has a different number of time because some ID's have more observations than other IDs) (see picture)
BLA14 has time 1-8 while BLA2 has time 1-11
here is my data:
data1 <- structure(list(Spawn_ID = structure(c(1L, 1L, 1L, 2L, 2L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L,
1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L), .Label = c("1",
"2", "3"), class = c("ordered", "factor")), average_Mg = c(0.0841567034686979,
0.00262726492114602, 0.353259164624795, -0.0364882169624394,
0.355390763410209, -0.151476304441742, -0.0936982567875358, 0.162382425722223,
-1.42681140542971, -1.07244649331608, -0.781118702245109, -1.21952099438996,
-1.38524008095868, -0.898983285649544, -1.01088138645042, -1.56153946055641,
-1.21949786511762, -0.887755361220044, -1.28496187594515, -1.82368718501736,
-1.44293956646485, -1.55766693069354, -1.58965315500885, -1.44731801677922,
-1.90014469879122, -1.39433781118039, -1.3954911611769, -0.866262522744268,
-0.893780676281797, -1.13725619637354, -1.50364564206296, -0.845596282408769,
-0.911535321390588, -1.41202503488084, -1.16477711028459, -0.928588557438047,
-1.0717825099406, -1.27071094552779, -0.102981887484371, -0.419552015986426,
0.207549199784127, -0.26688619247063, -0.0285388879140084, -0.104483586190019,
-0.374343912017509, -0.079286617457435, 0.502081027554914, 0.617397464912897,
0.658216645632926, 0.426442596169416, 0.437015933595451, -1.09407187513834,
-0.289722984650423, 0.189585827711078, 0.388488397202216, -0.814972632964376,
0.0191088328270176, -0.0788536189757766, -1.01469763732677, -0.532896761096259,
-0.319455285766885, 0.32814415425849, -1.10320849618017, -0.802227061565149,
-0.540984260212337, -1.14703007008055, -0.482835715257794, -1.23114539323637,
-0.881874890913403, -0.479104993907372, 0.722375571708869, 0.890893182481924,
1.1899980340988, 0.784338248057351, 0.6979419698913, 1.10833467622332,
0.749554401158789, 0.761841531876783, 1.38243732271989, 1.38537086804658,
0.686397638698291, 1.38660240844063, 1.90358175564482, 1.30513882860368,
0.9706833889022, 2.02786238069347, 0.633278771850179, 0.773554195390702,
1.26407209402018, 0.711780226990467, 1.12404623953355, 0.772411304871684,
0.746907192859431, 1.26546029276059, 0.754582077531832, 0.97865102792368,
1.25739249978455, 1.00030371910859, 1.20251423376581, 0.508886239812359,
1.0614400765502, 1.15560112394629, 0.810899892639843, 0.864356170995008,
1.0722853284304, 0.459017471399662, 0.622305015414975, 0.654778017554924,
0.630012469467092, 1.66357555743707, 1.51486425579301, 0.468256912570358,
1.46986769298999, 0.842853031161864, 0.527443923164085, 0.878231897515369,
1.01564664723517, 0.548373164352724, -1.54705977070176, -1.7628880927376,
-1.93886600741023, -1.75280825324115, -1.06329603003556, -1.76583856532739,
-2.03620478132805, -1.37852741943318, 0.491445103158986, 0.579237889782203,
0.581147814257234, 0.587993370694159, 0.673660535135936, 0.773224639425602,
0.472056000685565, 0.803037596940575, 0.686349802316703, 0.67297390357697,
0.877084884098423, 0.116853127650954, 0.633207695175741, 0.475407810726902,
0.410454398351338, 0.761825383439366, 0.049981065597767, 0.352528868363907,
1.08494544768163), average_Mn = c(0.550041395336084, 0.106013801445048,
0.195501740474326, 0.443055327801251, 0.166039412117922, 0.306826485641131,
0.0779488541952551, 0.253041943200378, -0.398175664467298, -0.248653116953824,
1.62701418452763, 2.12294900204613, -0.653505561079324, 1.18649551151282,
1.73706605332464, -0.663237964024895, -0.502022515338005, 1.37488148179862,
1.52730443891077, -1.02791508823558, -0.912000741847277, -1.13836183212639,
-1.0203769070181, -0.944729930532721, -1.08022080193656, -0.798637523498975,
-0.892966674264699, -0.106867747759299, -0.446077807686831, 0.260985129778798,
0.34207999245625, -0.256052324398952, -0.455901687059591, -0.124589605852459,
-0.330899017708168, -0.155941754430574, 0.179724557145222, -0.13333037309261,
-0.467033378092841, -1.02354293597083, -0.324678510862249, -0.780338971498965,
-0.638323663037884, -0.833876759864611, -1.23290374823043, -0.791651926017789,
-0.507461130613381, -0.8368428812325, -0.0557361418099642, -0.804531913988396,
-0.704346938462444, -0.483778753666885, 0.393712753506288, 0.427715184816051,
0.479775271348421, -0.28130811769396, 0.485295306906789, 0.29873238753337,
-0.32311305698219, -0.153688760742991, 0.566586154995381, 0.432231338528875,
1.06596225482086, 1.35634853919191, 3.80694326707882, 0.810475117293976,
3.0387608847462, 0.633718464176746, 1.1751890651466, 3.9845446592986,
-1.37297875557724, -1.09420268685371, -0.962614525736854, -1.29805138281804,
-1.31055976157738, -0.925719147858883, -1.23243978183704, -1.33945462492742,
-0.733417598434015, -0.930363022530595, -1.27774840900127, -0.551645520494324,
1.07748304807901, -0.396816101914801, -0.619403529151145, 0.904015824338447,
-0.287220128038401, -0.413048098445259, 0.612345039773056, 0.12520419272066,
0.144889119165393, -0.376872327860885, -0.371321461123647, 0.713414294431202,
-0.220319649249486, 1.91457944140036, 1.96765430981412, -0.121347747943895,
1.83594114293694, -0.874846076775421, 1.57970089137696, 1.93625153606136,
0.346364402583701, 1.77363591575721, 0.715776292044604, -0.11504600156397,
0.957194866002839, -0.887101387136546, -0.780049232064872, -0.336706490132965,
-0.70438883179631, -0.873817482659086, -0.284434200328209, -0.568305044660584,
-0.775993306095371, -0.771770658609636, -0.383838373137703, -0.811970593682299,
-0.73465457432939, 0.0911351344017551, 1.2707682140586, -0.777318831552788,
1.11134230637355, -0.783796841885501, 0.259370669933754, 1.73241147006831,
-0.725970777900951, -0.438118569726494, -0.278337133147783, -0.493758812846972,
-0.518179622331699, -0.389789488287258, -0.298381997017347, -0.612423478602631,
-0.429659970678406, -0.292999247051666, -0.435183828919258, -0.897633859213429,
0.507974413224703, 1.43201049921323, -0.66047577071763, 0.786340467145023,
-0.95656045144662, -0.132752976801546, 1.18466694854915), average_Zn = c(0.199618761426643,
0.591792310386536, 1.3751346661716, 0.332582639073901, 0.560402369414685,
0.11570820588524, 0.192150397195304, 1.39288706671957, -0.394083581015067,
-0.0798076017654593, 1.17669193020793, 0.607211261125105, -0.452359206037806,
0.771410079352111, 0.494544784665782, -0.625267178823271, -0.39226745167263,
1.16595745311139, 0.395578830413474, -1.34293822466577, -0.742961944779728,
-1.55476909975203, -1.21117698813619, -0.705958753206111, -1.37118754349972,
-0.917928244368175, -0.974434964905969, -1.01929394953207, -1.12532371386981,
-1.22700631035692, -1.46133511017614, -0.952449170432, -1.21027641358059,
-1.3226625940125, -1.16430485224588, -1.08770522025381, -1.18121144700268,
-1.40033431712296, -0.618587673725525, -0.91706750820117, 0.41088121270189,
-0.78430313474907, -0.409059258341318, -0.975516971079657, -1.27140585793008,
-0.198796133331597, -0.429336908924874, -0.0174222425394045,
-0.161004481467468, -0.405810552877399, -0.370285632509627, -0.89866639987887,
1.10645284167993, 1.8809570525936, 1.92254222169752, -0.0950224222539316,
1.58853988090432, 1.78386607934181, -0.817728723571643, 0.459412598781715,
1.423493404365, 1.7768774695448, -1.12006569075839, -0.751966514798299,
-0.488043380249217, -1.11596293893295, 0.273653921626916, -1.30713710349688,
-0.886375551803829, 0.0239199838971528, -1.3593629685693, -0.643843217883837,
-0.281272478019681, -1.30622537314287, -1.33112371265123, -0.909101703993645,
-1.12755493783614, -1.40003719660867, -0.290337728601771, -0.28987232858238,
-1.19056584307422, -0.193624949117038, 0.975332436429838, -0.218160046225909,
-0.132462974128803, 1.39468641578899, -0.302150834825655, -0.107400685186729,
1.125970810338, -0.256092735038377, 0.158506693687128, -0.378339394736207,
-0.349357413758689, 0.803679188551612, -0.146048595417096, -0.286845588476566,
0.158259418849209, -0.323113138916157, 0.108646496285904, -0.771878347558138,
0.0273033684358348, 0.0453235133932348, 1.28361673646552, 1.29073622845612,
1.24630790251793, 0.944986804400661, 0.981991016697687, 1.3473053430083,
0.827378725150942, 2.48208427225106, 2.69830294706435, 1.03039606923181,
2.27492560926846, 1.10744827135352, 1.35324680735362, 1.84388638700427,
1.52873550347441, 1.40071898822651, 0.260928795100606, -1.16734754082697,
-0.878145608518404, -0.00331768573206932, -0.910939824808822,
0.125144947309071, -1.67327192782442, -0.531813491778335, -0.546522958404239,
-0.0196439100156154, 0.0745476695275746, 0.794370508556172, -0.210218336601184,
0.445705743628815, 0.0718198426307307, -0.122444182892431, 0.184211311538213,
0.183194361394073, 1.12410771197491, -0.741883323524288, 0.716760255429898,
1.76025647136123, -0.00419702451761512, 1.25254232235371, -0.880576082155036,
-0.00114985682377106, 1.78721959263295), ID = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L), .Label = c("BLA14",
"BLA2", "BLA20", "BLA209", "BLA21", "BLA211", "BLA238", "BLA24",
"BLA25", "BLA283", "BLA307", "BLA31", "BLA42", "BLA47", "BLA5",
"BLA79", "BLA80"), class = "factor"), Time = structure(c(2L,
5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L,
4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L,
3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L,
2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 11L, 3L, 6L, 8L, 1L, 4L, 7L,
10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 5L, 8L, 11L, 2L, 3L, 6L,
9L, 4L, 7L, 10L, 1L, 2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 3L, 6L,
1L, 4L, 7L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 3L, 1L, 4L,
2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L,
6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L,
2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11"), class = c("ordered", "factor"
))), class = "data.frame", row.names = c(NA, -145L))
here is my model:
#model
clmm(Spawn_ID ~ average_Mg + average_Mn + average_Zn + (1|ID/Time), data = data1)
warning message
Warning messages:
1: Using formula(x) is deprecated when x is a character vector of length > 1.
Consider formula(paste(x, collapse = " ")) instead.
2: no. random effects (=161) >= no. observations (=145)

Putting nested random effects in polr function

I am trying to run an ordinal logistic regression mixed model with nested random effects using the polr function from package MASS.
average_Mg, average_Mn, and average_Zn are the predictor variables. the response variable is (Spawn_ID)
I have two random effects that are added into the model "(1|Time/ID)" (time is nested into ID and each ID has a different number of time because some ID's have more observations than other IDs) (see picture)
enter image description here
data:
data1 <- structure(list(Spawn_ID = structure(c(1L, 1L, 1L, 2L, 2L, 3L,
3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L,
2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 2L, 3L, 3L,
1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L,
1L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L), .Label = c("1",
"2", "3"), class = c("ordered", "factor")), average_Mg = c(0.0841567034686979,
0.00262726492114602, 0.353259164624795, -0.0364882169624394,
0.355390763410209, -0.151476304441742, -0.0936982567875358, 0.162382425722223,
-1.42681140542971, -1.07244649331608, -0.781118702245109, -1.21952099438996,
-1.38524008095868, -0.898983285649544, -1.01088138645042, -1.56153946055641,
-1.21949786511762, -0.887755361220044, -1.28496187594515, -1.82368718501736,
-1.44293956646485, -1.55766693069354, -1.58965315500885, -1.44731801677922,
-1.90014469879122, -1.39433781118039, -1.3954911611769, -0.866262522744268,
-0.893780676281797, -1.13725619637354, -1.50364564206296, -0.845596282408769,
-0.911535321390588, -1.41202503488084, -1.16477711028459, -0.928588557438047,
-1.0717825099406, -1.27071094552779, -0.102981887484371, -0.419552015986426,
0.207549199784127, -0.26688619247063, -0.0285388879140084, -0.104483586190019,
-0.374343912017509, -0.079286617457435, 0.502081027554914, 0.617397464912897,
0.658216645632926, 0.426442596169416, 0.437015933595451, -1.09407187513834,
-0.289722984650423, 0.189585827711078, 0.388488397202216, -0.814972632964376,
0.0191088328270176, -0.0788536189757766, -1.01469763732677, -0.532896761096259,
-0.319455285766885, 0.32814415425849, -1.10320849618017, -0.802227061565149,
-0.540984260212337, -1.14703007008055, -0.482835715257794, -1.23114539323637,
-0.881874890913403, -0.479104993907372, 0.722375571708869, 0.890893182481924,
1.1899980340988, 0.784338248057351, 0.6979419698913, 1.10833467622332,
0.749554401158789, 0.761841531876783, 1.38243732271989, 1.38537086804658,
0.686397638698291, 1.38660240844063, 1.90358175564482, 1.30513882860368,
0.9706833889022, 2.02786238069347, 0.633278771850179, 0.773554195390702,
1.26407209402018, 0.711780226990467, 1.12404623953355, 0.772411304871684,
0.746907192859431, 1.26546029276059, 0.754582077531832, 0.97865102792368,
1.25739249978455, 1.00030371910859, 1.20251423376581, 0.508886239812359,
1.0614400765502, 1.15560112394629, 0.810899892639843, 0.864356170995008,
1.0722853284304, 0.459017471399662, 0.622305015414975, 0.654778017554924,
0.630012469467092, 1.66357555743707, 1.51486425579301, 0.468256912570358,
1.46986769298999, 0.842853031161864, 0.527443923164085, 0.878231897515369,
1.01564664723517, 0.548373164352724, -1.54705977070176, -1.7628880927376,
-1.93886600741023, -1.75280825324115, -1.06329603003556, -1.76583856532739,
-2.03620478132805, -1.37852741943318, 0.491445103158986, 0.579237889782203,
0.581147814257234, 0.587993370694159, 0.673660535135936, 0.773224639425602,
0.472056000685565, 0.803037596940575, 0.686349802316703, 0.67297390357697,
0.877084884098423, 0.116853127650954, 0.633207695175741, 0.475407810726902,
0.410454398351338, 0.761825383439366, 0.049981065597767, 0.352528868363907,
1.08494544768163), average_Mn = c(0.550041395336084, 0.106013801445048,
0.195501740474326, 0.443055327801251, 0.166039412117922, 0.306826485641131,
0.0779488541952551, 0.253041943200378, -0.398175664467298, -0.248653116953824,
1.62701418452763, 2.12294900204613, -0.653505561079324, 1.18649551151282,
1.73706605332464, -0.663237964024895, -0.502022515338005, 1.37488148179862,
1.52730443891077, -1.02791508823558, -0.912000741847277, -1.13836183212639,
-1.0203769070181, -0.944729930532721, -1.08022080193656, -0.798637523498975,
-0.892966674264699, -0.106867747759299, -0.446077807686831, 0.260985129778798,
0.34207999245625, -0.256052324398952, -0.455901687059591, -0.124589605852459,
-0.330899017708168, -0.155941754430574, 0.179724557145222, -0.13333037309261,
-0.467033378092841, -1.02354293597083, -0.324678510862249, -0.780338971498965,
-0.638323663037884, -0.833876759864611, -1.23290374823043, -0.791651926017789,
-0.507461130613381, -0.8368428812325, -0.0557361418099642, -0.804531913988396,
-0.704346938462444, -0.483778753666885, 0.393712753506288, 0.427715184816051,
0.479775271348421, -0.28130811769396, 0.485295306906789, 0.29873238753337,
-0.32311305698219, -0.153688760742991, 0.566586154995381, 0.432231338528875,
1.06596225482086, 1.35634853919191, 3.80694326707882, 0.810475117293976,
3.0387608847462, 0.633718464176746, 1.1751890651466, 3.9845446592986,
-1.37297875557724, -1.09420268685371, -0.962614525736854, -1.29805138281804,
-1.31055976157738, -0.925719147858883, -1.23243978183704, -1.33945462492742,
-0.733417598434015, -0.930363022530595, -1.27774840900127, -0.551645520494324,
1.07748304807901, -0.396816101914801, -0.619403529151145, 0.904015824338447,
-0.287220128038401, -0.413048098445259, 0.612345039773056, 0.12520419272066,
0.144889119165393, -0.376872327860885, -0.371321461123647, 0.713414294431202,
-0.220319649249486, 1.91457944140036, 1.96765430981412, -0.121347747943895,
1.83594114293694, -0.874846076775421, 1.57970089137696, 1.93625153606136,
0.346364402583701, 1.77363591575721, 0.715776292044604, -0.11504600156397,
0.957194866002839, -0.887101387136546, -0.780049232064872, -0.336706490132965,
-0.70438883179631, -0.873817482659086, -0.284434200328209, -0.568305044660584,
-0.775993306095371, -0.771770658609636, -0.383838373137703, -0.811970593682299,
-0.73465457432939, 0.0911351344017551, 1.2707682140586, -0.777318831552788,
1.11134230637355, -0.783796841885501, 0.259370669933754, 1.73241147006831,
-0.725970777900951, -0.438118569726494, -0.278337133147783, -0.493758812846972,
-0.518179622331699, -0.389789488287258, -0.298381997017347, -0.612423478602631,
-0.429659970678406, -0.292999247051666, -0.435183828919258, -0.897633859213429,
0.507974413224703, 1.43201049921323, -0.66047577071763, 0.786340467145023,
-0.95656045144662, -0.132752976801546, 1.18466694854915), average_Zn = c(0.199618761426643,
0.591792310386536, 1.3751346661716, 0.332582639073901, 0.560402369414685,
0.11570820588524, 0.192150397195304, 1.39288706671957, -0.394083581015067,
-0.0798076017654593, 1.17669193020793, 0.607211261125105, -0.452359206037806,
0.771410079352111, 0.494544784665782, -0.625267178823271, -0.39226745167263,
1.16595745311139, 0.395578830413474, -1.34293822466577, -0.742961944779728,
-1.55476909975203, -1.21117698813619, -0.705958753206111, -1.37118754349972,
-0.917928244368175, -0.974434964905969, -1.01929394953207, -1.12532371386981,
-1.22700631035692, -1.46133511017614, -0.952449170432, -1.21027641358059,
-1.3226625940125, -1.16430485224588, -1.08770522025381, -1.18121144700268,
-1.40033431712296, -0.618587673725525, -0.91706750820117, 0.41088121270189,
-0.78430313474907, -0.409059258341318, -0.975516971079657, -1.27140585793008,
-0.198796133331597, -0.429336908924874, -0.0174222425394045,
-0.161004481467468, -0.405810552877399, -0.370285632509627, -0.89866639987887,
1.10645284167993, 1.8809570525936, 1.92254222169752, -0.0950224222539316,
1.58853988090432, 1.78386607934181, -0.817728723571643, 0.459412598781715,
1.423493404365, 1.7768774695448, -1.12006569075839, -0.751966514798299,
-0.488043380249217, -1.11596293893295, 0.273653921626916, -1.30713710349688,
-0.886375551803829, 0.0239199838971528, -1.3593629685693, -0.643843217883837,
-0.281272478019681, -1.30622537314287, -1.33112371265123, -0.909101703993645,
-1.12755493783614, -1.40003719660867, -0.290337728601771, -0.28987232858238,
-1.19056584307422, -0.193624949117038, 0.975332436429838, -0.218160046225909,
-0.132462974128803, 1.39468641578899, -0.302150834825655, -0.107400685186729,
1.125970810338, -0.256092735038377, 0.158506693687128, -0.378339394736207,
-0.349357413758689, 0.803679188551612, -0.146048595417096, -0.286845588476566,
0.158259418849209, -0.323113138916157, 0.108646496285904, -0.771878347558138,
0.0273033684358348, 0.0453235133932348, 1.28361673646552, 1.29073622845612,
1.24630790251793, 0.944986804400661, 0.981991016697687, 1.3473053430083,
0.827378725150942, 2.48208427225106, 2.69830294706435, 1.03039606923181,
2.27492560926846, 1.10744827135352, 1.35324680735362, 1.84388638700427,
1.52873550347441, 1.40071898822651, 0.260928795100606, -1.16734754082697,
-0.878145608518404, -0.00331768573206932, -0.910939824808822,
0.125144947309071, -1.67327192782442, -0.531813491778335, -0.546522958404239,
-0.0196439100156154, 0.0745476695275746, 0.794370508556172, -0.210218336601184,
0.445705743628815, 0.0718198426307307, -0.122444182892431, 0.184211311538213,
0.183194361394073, 1.12410771197491, -0.741883323524288, 0.716760255429898,
1.76025647136123, -0.00419702451761512, 1.25254232235371, -0.880576082155036,
-0.00114985682377106, 1.78721959263295), ID = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L,
6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L), .Label = c("BLA14",
"BLA2", "BLA20", "BLA209", "BLA21", "BLA211", "BLA238", "BLA24",
"BLA25", "BLA283", "BLA307", "BLA31", "BLA42", "BLA47", "BLA5",
"BLA79", "BLA80"), class = "factor"), Time = structure(c(2L,
5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L,
4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L,
3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L,
2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 11L, 3L, 6L, 8L, 1L, 4L, 7L,
10L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 5L, 8L, 11L, 2L, 3L, 6L,
9L, 4L, 7L, 10L, 1L, 2L, 5L, 3L, 1L, 4L, 2L, 5L, 8L, 3L, 6L,
1L, 4L, 7L, 2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L, 2L, 5L, 3L, 1L, 4L,
2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L, 2L, 5L, 8L, 3L,
6L, 1L, 4L, 7L, 2L, 5L, 8L, 11L, 3L, 6L, 9L, 1L, 4L, 7L, 10L,
2L, 5L, 8L, 3L, 6L, 1L, 4L, 7L), .Label = c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10", "11"), class = c("ordered", "factor"
))), class = "data.frame", row.names = c(NA, -145L))
Current code for model
model2<- polr(Spawn_ID ~ average_Mg + average_Mn + average_Zn + (1| ID/Time), data = data1, method = "logistic", Hess = TRUE)
error message
Error in family$linkfun(mustart) :
Argument mu must be a nonempty numeric vector
In addition: Warning messages:
1: In eval(predvars, data, env) :
Incompatible methods ("Ops.factor", "Ops.ordered") for "/"
2: In Ops.factor(1, ID/Time) : ‘|’ not meaningful for factors

Eliminating Predictor Variables and Comparing Classification methods to find the best model

I am currently working with a dataset with a binary response variable with 2 levels. I have approx 32 predictor variables - some factors and some numeric. I used glm and based on the p values removed some of the predictor variables that I thought were insignificant. However, when I run the deviance test I always get zero and my ROC curve is upside down - this can be corrected by putting the TPR on the x axis but I think this is incorrect.
Can anyone provide any suggestions on what I could potentially be doing wrong?
Thanks a million!
The code below represents the categories I think are significant. They are all categorical.
data_analysis <- glm(PainDiagnosis~PainLocation+Criterion2+Criterion6+Criterion8+
Criterion9+Criterion13, data=dat, family="binomial") summary(data_analysis) coef(data_analysis) anova(data_analysis, test="Chisq")
resDev_glm <- residuals(fit_glm, type = "deviance")
testDev_glm <- sum(resDev_glm^2)
modMat_glm <- model.matrix(fit_glm) # model matrix
NO_glm <- nrow(unique(modMat_glm)) # number of unique observations
m_glm <- length(fit_glm$coefficients) # number of parameters
nrow(dat)
NO_glm
testDev_glm
1 - pchisq(testDev_glm, NO_glm-m_glm)
library(ROCR)
predObj <- prediction(fitted(fit_glm), dat$PainDiagnosis)
perf <- performance(predObj, "tpr", "fpr")
plot(perf)
abline(0,1, col = "darkorange2", lty = 2) # add bisect line
2L, 2L, 1L, 1L, 1L, 1L), .Label = c("Female", "Male"), class = "factor"),
DurationCurrent = structure(c(5L, 4L, 5L, 6L, 2L, 3L, 6L,
6L, 6L, 2L, 3L, 6L, 2L, 4L, 1L, 4L, 3L, 2L, 4L, 6L, 6L, 6L,
6L, 4L, 6L, 6L, 3L, 5L, 3L, 3L, 4L, 5L, 6L, 6L, 2L, 3L, 5L,
4L, 6L, 5L, 4L, 5L, 6L, 6L, 5L, 6L, 3L, 6L, 4L, 6L, 2L, 4L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, 6L, 6L, 6L, 4L, 6L, 6L, 6L, 6L, 6L, 3L, 5L, 6L, 5L, 4L,
6L, 6L, 6L, 6L, 5L, 4L, 5L, 6L, 2L, 2L, 4L, 6L, 6L, 4L, 6L,
4L, 6L, 4L, 6L, 6L, 3L, 4L, 2L, 3L, 5L, 6L, 2L, 6L, 2L, 3L,
2L, 2L, 4L, 2L, 5L, 4L, 4L, 5L, 6L, 3L, 5L, 3L, 1L, 6L, 6L,
4L, 2L, 4L, 4L, 6L, 6L, 5L, 1L, 6L, 2L, 6L, 2L, 1L), .Label = c("0-3 weeks",
"4-6 weeks", "7-12 weeks", "4-6 months", "7-12 months", "> 1 year"

Sankey diagram, alluvial, ggalluvial in R – Three data blocks: Baseline-Flow (many time points)-Outcome

We would like to present the change in muscle mass due to the exercise of different age group and the final performance/outcome at the competition at the end of the study.
We have several time points at which the muscle mass was measured. In this example I only show three time points, however, the study compromises 12 time points.
To present the change in muscle mass and deviation from the average I was able to use geom_flow(). However, it becomes very tricky to add the age groups on the left of the chart as well as the performance on the right side. These data are located in different variables.
Please help us to find a great way to present the data. Thanks.
Data Structure:
ID Age_at_start Month Deviation_muscle Performance
1 36 3 59 Outstanding
1 36 6 104 Outstanding
1 36 9 200 Outstanding
2 29 3 -40 average
2 29 6 -109 average
2 29 9 -30 average
3 22 3 310 above average
library(ggplot2)
library(ggalluvial)
df.san$age<-factor(df.san$age)
df.san$age<-factor(df.san$age, levels=c(1,2,3,4), labels=c("20 to 24 years","25 to 29 years","30 to 34 years","35 to 39 years"))
df.san$dev_group <-factor(df.san$dev_group,levels=c(1,2,3,4,5,6,7),labels=c("≥250g","≥150 to <250g","≥50 to <150g","> -50 to <50g","> -150 to ≤ -50","> -250 to ≤ -150", "≤ -250g"))
df.san$month <- factor(df.san$month,labels=c("1mo","2mo","3mo"))
df.san$perform<-factor(df.san$perform,levels=c(1,2,3,4),labels=c("outstanding "," above average "," average "," below average"))
ggplot(df.san,aes(x = month,stratum = dev_group, alluvium = ID, fill = dev_group,label = dev_group)) +
scale_fill_brewer(type = "qual", palette = "Set2") +
geom_flow(stat = "alluvium", lode.guidance = "rightleft", color = "darkgray") +
geom_stratum() +
theme(legend.position = "bottom") +
ggtitle("Effect of Exercice on Muscle Growth on Performance in 4 Different Age Groups ")
Data for df.san:
structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 15L, 15L, 15L), age = c(2L, 3L, 3L, 1L, 3L, 1L, 2L, 3L, 4L, 1L, 1L, 3L, 1L, 4L, 4L, 3L, 4L, 3L, 4L, 2L, 2L, 1L, 2L, 4L, 1L, 1L, 4L, 1L, 3L, 1L, 2L, 3L, 4L, 4L, 2L, 2L, 2L, 2L, 4L, 2L, 2L, 4L, 3L, 3L, 2L), month = c(2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L, 2L, 4L, 6L), dev_muscle = c(-109.3, -236.2, -275.4, -44.5, -202.6, -436, 3, -115.8, -136.2, -142.1, -429, -561.4, -49, -248.8, -232.6, -15.9, -171.5, -391.6, -5.8, -21.7, -104.1, 12.6, -33.4, -25.4, -57.3, -50.7, -103.6, -124, -221.4, -457.2, 22.1, -126.9, -79.5, -76.8, -113.2, -129.7, -86.1, -126, -82.9, -10.8, -2.8, 88.3, 41.6, 0.2, 184.7), perform = c(1L, 2L, 1L, 2L, 4L, 1L, 1L, 4L, 3L, 4L, 2L, 4L, 4L, 4L, 2L, 2L, 4L, 3L, 3L, 4L, 1L, 2L, 1L, 1L, 2L, 3L, 2L, 2L, 2L, 1L, 2L, 3L, 2L, 1L, 2L, 4L, 3L, 2L, 1L, 3L, 2L, 1L, 1L, 4L, 4L), dev_group = c(5L, 6L, 7L, 4L, 6L, 7L, 4L, 5L, 5L, 5L, 7L, 7L, 4L, 6L, 6L, 4L, 6L, 7L, 4L, 4L, 5L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 7L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 3L, 4L, 4L, 2L)), class = "data.frame", row.names = c(NA, -45L))

R: Ggvis - add_tooltip for bar chart

i'm having troubles using the add_tooltip from ggvis.
I just want to put a tool tip for the sessions by source to my plot.
I'm having troubles understanding the html function that needs to be created for add_tooltip()
I understand i need an "ID" within my data (you can see my data at the bottom). Please, may someone explane this part. I don't understand how ggvis uses the ID for the plot.
Visitas_Por_Fuente$id <- 1:nrow(Visitas_Por_Fuente) #Create the ID column.
Visitas_Por_Fuente %>%
ggvis(~Fuentes, ~sessions) %>%
layer_bars(width = 0.8, fill = ~Fuentes) %>%
add_tooltip(mysessions ,"hover")
mysessions <- function(x) {
if(is.null(x)) return(NULL)
#notice below the id column is how ggvis can understand which session to show
row <- Visitas_Por_Fuente[Visitas_Por_Fuente$id == x$id, ]
#prettyNum shows the number with thousand-comma separator
paste0("Sessions:", " ",prettyNum(row$sessions, big.mark=",",scientific=F))
}
The graph is shown, but when hovering says:
Warning: Unhandled error in observer: non-character argument
observe({
value <- session$input[[id]]
if (is.null(value))
return()
if (!is.list(value$data))
return()
df <- value$data
class(df) <- "data.frame"
attr(df, "row.names") <- .set_row_names(1L)
fun(data = df, location = list(x = value$pagex, y = value$pagey),
session = session)
})
My data:
structure(list(Fuentes = structure(c(3L, 5L, 6L, 6L, 4L, 5L,
5L, 5L, 5L, 7L, 7L, 1L, 6L, 7L, 5L, 5L, 4L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 7L, 3L, 5L, 6L, 6L, 5L, 6L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 21L, 101L, 2L, 1L, 4L, 1L, 1L, 1L, 1L, 1L,
85L, 1L, 1L, 1L, 2L, 2L, 4L, 1L, 1L, 4L, 278L, 10L, 67L,
2L, 54L, 15L, 1L, 1L, 1L, 1L, 1L, 98L, 1L, 6L, 3L, 2L, 1L,
315L, 1L, 1L, 6L, 13L, 1L, 59L, 2L, 3L, 1L, 1L, 1L, 1L, 1L,
4L, 2L, 90L, 1L, 4L, 1L, 1L, 1L, 1L, 2L, 7L, 1L, 235L, 1L,
1L, 1L, 2L, 53L, 72L, 18L, 3L, 2L, 1L, 1L, 68L, 1L, 1L, 4L,
2L, 1L, 2L, 1L, 1L, 241L, 1L, 1L, 4L, 9L, 37L, 1L, 1L, 66L,
1L, 1L, 7L, 5L, 4L, 2L, 1L, 2L, 197L, 47L, 39L, 19L, 1L)), .Names = c("Fuentes",
"sessions"), class = "data.frame", row.names = c(NA, -1724L))
In general, you need to give the layer a "key" to be returned when hovering or clicking it which is then used as input for the tooltip function.
A problem I see here is that you are producing a bar chart (i.e. values are summed up per "Fuente" type) but you want to use a tooltip for each single observation (row) in your data. So the problem is that in your chart you don't display each data point (observation) separated and hence it will be difficult, when hovering over a bar, to know what specific data point (observation) you want to return for the tooltip.
In order to show how it might work for layer_points with observation-specific tooltips, I adapted your code like this:
Visitas_Por_Fuente$id <- 1:nrow(Visitas_Por_Fuente) #Create the ID column.
mysessions <- function(x) {
if(is.null(x)) return(NULL)
# get the current session info, based on "id" that is hovered over:
current_session <- Visitas_Por_Fuente[Visitas_Por_Fuente$id == x$id, "sessions"]
# format the value with prettyNum if you like:
paste0("Sessions:", " ",prettyNum(current_session, big.mark=",",scientific=F))
}
Visitas_Por_Fuente %>%
ggvis(~Fuentes, ~sessions) %>%
layer_points(fill = ~Fuentes, key := ~id) %>% # define a key
add_tooltip(mysessions ,"hover")
Here's another version with tool tips for a bar chart showing the total number of sessions per "Fuente" type when hovering over a bar (this is possible because it doesn't require to know what single data point is used - instead we use "Fuente" as key):
mysessions <- function(x) {
if(is.null(x)) return(NULL)
# compute the total number of sessions of the "Fuente" type that is hovered over
total_sessions <-
sum(Visitas_Por_Fuente[Visitas_Por_Fuente$Fuentes == x$Fuentes, "sessions"])
# format the value with prettyNum if you like:
paste0("Total number of Sessions:", " ",
prettyNum(total_sessions, big.mark=",",scientific=F))
}
Visitas_Por_Fuente %>%
ggvis(~Fuentes, ~sessions) %>%
layer_bars(width = 0.8, fill = ~Fuentes, key := ~Fuentes) %>%
add_tooltip(mysessions ,"hover")

Resources