image function in R - r

I'm trying to do something a little bit complicated for a beginner in programming.
I have a matrix 16x16 and I want to plot the values as a heatmap using image() in R.
How can I plot the "0" (zeros) in blue when the sum (row index + column index) is <= 15? Is that possible?
example matrix:
x <- c(3045, 893, 692, 830, 617, 155, 246, 657, 105, 60, 18, 7, 7, 4, 2, 11234,
2985, 2242, 2471, 1575, 366, 503, 1283, 170, 79, 32, 6, 4, 1, 3, 19475, 4756,
3233, 3251, 1810, 409, 575, 1210, 139, 41, 11, 4, 2, 0, 0, 20830, 4739, 2990,
2531, 1346, 298, 325, 612, 60, 17, 1, 0, 1, 0, 0, 15304, 3196, 1885, 1440, 610,
117, 115, 185, 14, 2, 0, 0, 0, 0, 0, 8026, 1535, 806, 539, 223, 33, 37, 39, 0,
0, 0, 0, 0, 0, 0, 3300, 562, 286, 141, 45, 14, 5, 12, 0, 0, 0, 0, 0, 0, 0, 1067,
160, 65, 40, 14, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 277, 47, 6, 2, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 72, 6, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
xmat <- matrix(x, ncol = 12)
xmat <- cbind(xmat, rep(0,16), rep(0,16), rep(0,16), rep(0,16))
xmat <- rbind(xmat, rep(0,16))
dimnames(xmat) = list(0:15, 0:15)
xmat
Thanks!
Vitor

Plot the cases meeting the criteria as blue.
xmat.new <- xmat
xmat.new[!((row(xmat) + col(xmat) <= 15) & xmat==0)] <- NA
image(xmat.new,col="blue")
Plot the cases not meeting the criteria as normal. Notice the add=TRUE
xmat.new <- xmat
xmat.new[((row(xmat) + col(xmat) <= 15) & xmat==0)] <- NA
image(xmat.new,add=TRUE)
Result:
Edited to include #Marek's suggestion to simplify the statements.

Related

How to present survival curves with event variable with more than 2 categories in R?

I have patients who can have two types of outcomes.
structure(list(time = c(45.7, 2, 98.4, 87.3, 104.5, 78.2, 78.2,
9.2, 14.2, 109.6, 39.6, 109.6, 55.8, 53.8, 6, 76.1, 118.7, 4,
2, 94.4, 41.6, 7.1, 115.7, 24.4, 97.4, 15.2, 26.4, 118.7, 69,
102.5, 116.7, 58.8, 109.6, 2, 67, 70, 22.3, 87.3, 82.2, 109.6,
58.8, 33.5, 57.9, 9.2, 90.3, 23.3, 37.5, 3, 17.3, 49.7, 111.6,
84.2, 116.7, 111.6, 8.1, 30.5, 30.5, 27.4, 94.4, 6.1, 81.2, 44.7,
70, 14.2, 70, 78.2, 41.6, 4.1, 25.4, 33.5, 104.5, 17.3, 77.1,
1, 31.5, 87.3, 80.2, 116.7, 9.2, 84.2, 1, 36.5, 85.2, 99.4, 111.6,
4.1, 37.5, 4.1, 80.2, 39.5, 104.5, 6.1, 81.2, 56.8, 47.7, 66,
6.1, 44.7, 36.5, 34.5, 95.3, 92.4, 14.2, 15.2, 114.7, 68, 120.7,
2, 3, 33.5, 32.5, 55.8, 1, 54.8, 15.2, 29.5, 18.3, 29.5, 3.1,
3, 4.1, 2, 10.2, 10.1, 19.3, 49.7, 27.4, 89.3, 93.4, 59.8, 1,
61.9, 64.9, 47.7, 19.3, 8.2, 4.1, 94.4, 1, 95.3, 13.2, 79.2,
61.9, 11.1, 0, 69, 48.7, 34.5, 1, 103.5, 18.3, 72, 97.4, 97.4,
46.6, 22.3, 80.2, 34.5, 60.9, 114.7, 109.6, 2, 47.7, 98.4, 77.1,
1, 43.7, 0, 93.4, 117.7, 14.2, 37.5, 83.2, 77.1, 78.2, 8.1, 49.7,
31.4, 103.5, 30.5, 90.3, 22.3, 13.2, 37.5, 2, 107.5, 112.6, 8.1,
103.5, 19.3, 3, 35.5, 5.1, 97.4, 1, 61.9, 1, 13.1, 27.4, 12.2,
19.3, 91.3, 112.6, 109.6, 41.6, 97.4, 54.8, 99.4, 3, 114.7, 32.5,
3, 9.2, 2.1, 59.8, 112.6, 35.5, 66, 103.5, 117.7, 66.9, 55.8,
69, 3, 4, 109.6, 4.1, 81.2, 93.4, 113.6, 0, 57.9, 86.2, 11.2,
20.3, 2, 5.1, 3.1, 54.8, 55.8, 110.6, 50.7, 91.3, 45.7, 6.1,
75.1, 58.8, 2.1, 13.2, 99.4, 83.2, 16.2, 40.6, 22.3, 18.3, 100.4,
63.9, 2, 17.3, 1, 84.2, 3.1, 5, 23.3, 78.2, 40.6, 114.7, 2, 74.1,
1, 95.3, 80.2, 56.8, 94.4, 58.8, 107.5, 80.2, 5.1, 36.5, 79.2,
51.7, 115.7, 17.3, 4, 4.1, 5.1, 55.8, 79.2, 8.1, 80.2, 102.5,
86.2, 41.6, 1, 15.2, 48.7, 53.8, 82.2, 79.2, 35.5, 23.3, 32.5,
2, 40.6, 11.1, 1, 80.2, 27.4, 93.4, 78.2, 30.5, 112.6, 5.1, 2,
2, 14.2, 8.1, 2, 18.3, 64.9, 42.6, 36.5, 103.5, 55.8, 18.3, 1,
2.1, 55.8, 106.6, 2, 84.2, 6.1, 8.1, 14.2, 3, 52.8, 57.9, 1,
81.2, 50.7, 86.2, 17.3, 56.8, 1, 11.1, 8.1, 1, 94.4, 85.2, 43.7,
105.5, 78.2, 114.7, 80.1, 2, 82.2, 87.3, 90.3, 111.6, 94.4, 63.9,
85.2, 32.5, 29.5, 14.2, 75.1, 8.1, 45.7, 70, 74.1, 43.7, 40.6,
22.3, 64.9, 2, 4, 9.1, 117.7, 6.1, 12.2, 105.5, 26.4, 8.1, 32.5,
46.6, 114.7, 1, 71, 80.2, 52.8, 2, 2, 73.1, 63.9, 74.1, 85.2,
116.7, 0.9, 115.7, 66, 16.2, 54.8, 92.4, 85.2, 31.5, 2, 74.1,
9.2, 104.5, 106.6, 5.1, 29.5, 97.4, 95.3, 38.6, 105.5, 75.1,
54.8, 75.1, 100.4, 48.7, 83.2, 113.6, 75.1, 54.8, 60.9, 16.2,
44.7, 46.6, 40.6, 2, 29.5, 45.7, 116.7, 0, 4.1, 1, 85.2, 27.4,
55.8, 2, 86.2, 10.2, 77.1, 52.8, 44.7, 45.7, 80.2, 19.3, 9.2,
64.9, 116.7, 69, 22.3, 5.1, 4, 29.5, 2, 3, 4.1, 55.8, 72, 22.3,
1, 49.7, 61.9, 52.8, 42.6, 97.4, 88.3, 79.2, 48.7, 90.3, 10.1,
103.5, 16.2, 63.9, 37.5, 6.1, 99.4, 112.6, 20.2, 119.7, 90.3,
77.1, 2.1, 89.3, 88.3, 96.4, 11.1, 10.1, 53.8, 30.5, 87.3, 45.7,
41.6, 84.2, 27.4, 2.1, 24.4, 37.5, 106.6, 13.2, 84.2, 106.6,
36.5, 102.5, 0, 104.5, 24.4, 11.1, 5.1, 107.5, 2.1, 100.4, 70,
98.4, 103.5, 7.1, 1, 4.1, 22.3, 7.1, 11.1, 84.2, 101.5, 15.2,
10.1, 31.5, 2, 1, 56.8, 77.1, 10.1, 32.5, 1, 100.4, 21.3, 2,
62.9, 0, 1, 24.4, 57.9, 8.1, 3, 114.7, 0, 5.1, 15.2, 61.9, 52.8,
17.3, 104.5, 47.7, 67, 33.5, 53.8, 114.7, 115.7, 31.5, 13.2,
11.1, 0, 58.8, 1, 36.5, 1, 53.8, 11.1, 94.4, 93.4, 111.6, 108.5,
38.6, 2, 50.7, 1, 105.5, 41.6, 113.6, 45.7, 50.7, 37.5, 23.3,
99.4, 36.5, 44.6, 103.5, 20.3, 102.5, 117.7, 4.1, 4, 1, 40.6,
3.1, 49.7, 33.5, 55.8, 1, 30.5, 29.5, 119.7, 114.7, 9.2, 107.5,
9.2, 40.6, 77.1, 104.5, 72, 99.4, 84.2, 31.5, 80.2, 46.6, 64.9,
99.4, 1, 0, 3.1, 72, 27.4, 73.1, 116.7, 54.8, 2, 1, 69, 49.7,
96.4, 39.6, 30.5, 110.6, 17.3, 92.4, 32.5, 79.2, 43.7, 72, 91.3,
26.3, 5.1, 88.3, 46.6, 21.3, 113.6, 1, 37.5, 98.4, 90.3, 109.6,
62.9, 99.4, 36.5, 28.4, 120.7, 54.8, 17.3, 49.7, 76.1, 40.6,
111.6, 36.5, 33.5, 16.2, 62.9, 1, 102.5, 11.2, 14.2, 106.6, 29.5,
24.4, 84.2, 59.8, 26.4, 57.9, 0, 105.5, 22.3, 31.5, 31.5, 66,
46.6, 103.5, 91.3, 91.3, 25.4, 42.6, 51.7, 41.6, 13.2, 119.7,
3, 14.2, 10.2, 116.7, 90.3, 109.6, 1, 28.4, 113.6, 3.1, 53.8,
15.2, 9.2, 114.7, 1, 38.6, 29.5, 21.3, 2, 99.4, 82.2, 90.3, 62.9,
13.2, 90.3, 1, 51.7, 2, 40.6, 44.7, 92.4, 96.4, 4.1, 88.3, 68,
107.5, 88.3, 25.4, 120.7, 30.5, 103.5, 83.2, 89.3, 105.5, 108.5,
3.1, 0, 105.5, 99.4, 0, 108.5, 17.3, 94.4, 108.5, 4.1, 115.7,
43.7, 34.5, 55.8, 115.7, 17.3, 91.3, 90.3, 114.7, 73.1, 99.4,
56.8, 93.4, 62.9, 78.2, 0, 103.5, 2, 12.2, 101.5, 42.6, 1, 2,
111.6, 76.1, 4.1, 4.1, 35.5, 41.6, 30.5, 115.7, 38.6, 5.1, 7.1,
47.7, 31.4, 32.5, 53.8, 23.3, 38.6, 63.9, 27.4, 41.6, 13.2, 0,
56.8, 44.7, 91.3, 29.5, 97.4, 90.3, 4, 29.5, 84.2, 108.5, 51.7,
34.5, 98.4, 2, 2, 48.7, 118.7, 49.7, 73.1, 36.5, 112.6, 1, 111.6,
5.1, 62.9, 90.3, 83.2, 86.2, 12.2, 62.9, 14.2, 57.9, 53.8, 40.6,
48.7, 10.1, 28.4, 9.2, 68, 97.4, 54.8, 84.2, 105.5, 74.1, 1,
47.7, 71, 116.7, 81.2, 1, 58.8, 80.2, 78.2, 14.1, 39.6, 1, 4.1,
1, 86.2, 58.8, 0, 103.5, 82.2, 87.3, 107.5, 98.4, 3.1, 39.6,
8.1, 68, 100.4, 3.1, 18.3, 104.5, 75.1, 68, 39.6, 1, 108.5, 74.1,
84.2, 23.3, 118.7, 106.6, 7.1, 55.8, 105.5, 0, 7.1, 2, 50.7,
90.3, 76.1, 95.3, 2.1, 74.1, 119.7, 1, 77.1, 1, 10.1, 22.3, 28.4,
2, 3, 78.2, 33.5, 3, 3, 27.4, 2, 47.7, 15.2, 13.2, 20.3, 97.4,
40.6, 76.1, 58.8, 2, 50.7, 11.2, 78.2, 75.1, 100.4, 21.3, 28.4,
4.1, 59.8, 86.2, 39.6, 9.2, 92.4, 5.1, 0, 102.5, 70, 26.4, 89.3,
118.7, 8.1, 2, 92.4, 20.3, 75.1, 115.7, 31.5, 96.4, 66, 64.9,
79.2, 4.1, 0, 114.7, 2, 3.1, 30.5, 106.6, 117.7, 1, 20.3, 35.5,
38.6, 32.5, 1, 6.1, 10.1, 96.4, 8.1, 7.1, 115.7, 2, 66, 42.6,
69, 114.7, 10.1, 111.6, 5.1, 83.2, 78.2, 8.1, 30.5, 5, 13.2,
41.6, 85.2, 45.7, 92.4, 91.3, 9.1, 109.6, 31.5, 31.5, 28.4, 63.9,
72, 0.9, 31.5, 101.5, 76.1, 99.4, 81.2, 69, 75.1, 4.1, 5.1, 55.8,
64.9, 68, 4.1, 47.7, 78.2, 109.6, 8.1, 66, 19.3, 9.2, 67, 71,
55.8, 92.4, 3.1, 52.8, 55.8, 62.9, 6.1, 113.6, 90.3, 72, 5, 35.5,
115.7, 46.6, 15.2, 28.4, 9.2, 102.5, 4, 53.8, 97.4, 56.8, 102.5,
74.1, 14.2, 17.3, 117.7, 4, 2.1, 77.1, 3.1, 102.5, 13.2, 66,
3, 60.9, 1, 26.4, 114.7, 111.6, 60.9, 9.1, 18.3, 59.8, 11.1,
19.3, 71, 50.7, 64.9, 4, 6.1, 120.7, 29.5, 88.3, 66, 72, 59.8,
16.3, 93.4, 50.7, 114.7, 19.3, 87.3, 2, 22.3, 70, 52.8, 32.5,
33.5, 2, 18.3, 74.1, 3.1, 0, 118.7, 111.6, 82.2, 1, 42.6, 4.1,
72, 98.4, 58.8, 91.3, 66, 48.7, 75.1, 41.6, 34.5, 14.2, 116.7,
13.2, 75.1, 118.7, 45.7, 50.7, 120.7, 95.3, 12.2, 69, 63.9, 6,
62.9, 0, 49.7, 90.3, 74.1, 1, 14.2, 116.7, 70, 54.8, 14.2, 33.5,
47.7, 79.2, 115.7, 2, 1, 3, 113.6, 45.7, 88.3, 13.2, 53.8, 63.9,
95.3, 18.3, 31.5, 102.5, 68, 37.5, 106.6, 76.1, 74.1, 9.1, 43.7,
8.1, 117.7, 48.7, 94.4, 19.3, 2, 6.1, 26.4, 30.5, 97.4, 39.6,
103.5, 68, 96.4, 2, 111.6, 59.8, 79.2, 62.9, 51.7, 112.6, 1,
107.5, 3, 37.5, 58.8, 12.2, 59.8, 61.9, 25.3, 106.6, 71, 35.5,
8.1, 71, 12.2, 31.5, 3, 87.3, 116.7, 52.8, 78.2, 102.5, 97.4,
2, 41.6, 53.8, 67, 119.7, 93.4, 20.3, 4.1, 117.7, 42.7, 20.3,
29.5, 48.7, 107.5, 30.5, 36.5, 63.9, 80.2, 1, 6.1, 5.1, 67, 81.2,
97.4, 8.1, 0, 6.1, 57.9, 1, 1, 5.1, 99.4, 8.1, 41.6, 78.2, 44.7,
48.7, 38.6, 67, 103.5, 91.3, 106.6, 58.8, 20.3, 16.2, 62.9, 36.5,
15.2, 13.2, 115.7, 10.1, 15.2, 58.8, 47.7, 6.1, 4.1, 95.3, 17.3,
4.1, 2.1, 90.3, 13.2, 27.4, 54.8, 61.9, 68, 10.1, 70, 23.3, 25.4,
11.1, 83.2, 50.7, 29.5, 58.8, 31.5, 84.2, 61.9, 84.2, 110.6,
68, 17.3, 16.2, 11.1, 97.4, 28.4, 81.2, 62.9, 14.2, 80.2, 66,
116.7, 55.8, 9.2, 8.1, 32.5, 1, 15.2, 41.6, 85.2, 1, 84.2, 2,
1, 97.4, 74.1, 119.7, 57.9, 8.1, 0, 41.6, 18.3, 4.1, 2, 3, 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1,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1,
1, 0, 0, 0, 0)), row.names = c(NA, -1329L), class = "data.frame")
Does it make sense to present survival curves for two different type of events at the same time? If so is it possible to do it with R (ggplot) ?
survie_cmd_test<-survfit(Surv(time,status)~1, data=mydata)
ggsurvplot(
survie_cmd_test,
data = mydata,
size = 0.5, # change line size
palette =
c("#E7B800", "#2E9FDF"),# custom color palettes
conf.int = TRUE, # Add confidence interval
pval = TRUE, # Add p-value
legend.labs =
c("Patients"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups
ggtheme = theme_bw(),# Change ggplot2 theme
xlab="Time (months)",
ylab="Survival probability"
)
These codes give me only one curve while i am expecting two curves (one for the category 1 and another for the category 2)
You have three categories for "ss_tp" ("0", "1", "2"), so you can plot the three groups, or only "ss_tp == 1" and "ss_tp == 2", i.e.
library(tidyverse)
library(survival)
library(survminer)
df <- mydata
survie_cmd_test<-survfit(Surv(time,status)~1, data=df)
ggsurvplot(
survie_cmd_test,
data = df,
size = 0.5, # change line size
palette =
c("#E7B800", "#2E9FDF"),# custom color palettes
conf.int = TRUE, # Add confidence interval
pval = TRUE, # Add p-value
legend.labs =
c("Patients"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups
ggtheme = theme_bw(),# Change ggplot2 theme
xlab="Time (months)",
ylab="Survival probability"
)
#> Warning in .pvalue(fit, data = data, method = method, pval = pval, pval.coord = pval.coord, : There are no survival curves to be compared.
#> This is a null model.
(problematic plot)
survie_cmd_test<-survfit(Surv(time,status)~ss_tp, data=df)
ggsurvplot(
survie_cmd_test,
data = df,
size = 0.5, # change line size
# palette =
# c("#E7B800", "#2E9FDF"),# custom color palettes
conf.int = TRUE, # Add confidence interval
pval = TRUE, # Add p-value
# legend.labs =
# c("Patients"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups
ggtheme = theme_bw(),# Change ggplot2 theme
xlab="Time (months)",
ylab="Survival probability"
)
# for only ss_tp = 1 verses ss+tp = 2
survie_cmd_test<-survfit(Surv(time,status)~ss_tp, data=df[df$ss_tp != 0,])
ggsurvplot(
survie_cmd_test,
data = df,
size = 0.5, # change line size
# palette =
# c("#E7B800", "#2E9FDF"),# custom color palettes
conf.int = TRUE, # Add confidence interval
pval = TRUE, # Add p-value
# legend.labs =
# c("Patients"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups
ggtheme = theme_bw(),# Change ggplot2 theme
xlab="Time (months)",
ylab="Survival probability"
)

How would I chart three percent columns into a stacked percent barplot using R?

I have the raw totals for three values that I was looking to display over time in a stacked bar chart, but I don't know how to display this.
I have the percentage values (.22, et cetera), and the raw numbers.
How would I create a stacked bar chart using ggplot2 considering I have three proportions I am trying to graph. Do I need to melt the data?
I would like to do something like:
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar( stat="identity", position="fill")
But I do not know how to do this as my data isn't formatted right. Should I use dplyr?
Here is my df:
structure(list(date = structure(c(17405, 17406, 17407, 17408,
17409, 17410, 17411, 17412, 17413, 17414), class = "Date"), total_membership = c(1,
1, 1, 1, 1, 188, 284, 324, 354, 390), full_members = c(1, 1,
1, 1, 1, 188, 284, 324, 354, 390), guests = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0), daily_active_members = c(1, 1, 1, 1, 1, 169,
225, 214, 203, 254), daily_members_posting_messages = c(1, 0,
1, 0, 1, 111, 110, 96, 67, 70), weekly_active_members = c(1,
1, 1, 1, 1, 169, 270, 309, 337, 378), weekly_members_posting_messages = c(1,
1, 1, 1, 1, 111, 183, 218, 234, 255), messages_in_public_channels = c(4,
0, 0, 0, 1, 252, 326, 204, 155, 135), messages_in_private_channels = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), messages_in_shared_channels = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), messages_in_d_ms = c(1, 0, 0, 0,
0, 119, 46, 71, 70, 122), percent_of_messages_public_channels = c(0.8,
0, 0, 0, 1, 0.6792, 0.8763, 0.7418, 0.6889, 0.5253), percent_of_messages_private_channels = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), percent_of_messages_d_ms = c(0.2,
0, 0, 0, 0, 0.3208, 0.1237, 0.2582, 0.3111, 0.4747), percent_of_views_public_channels = c(0.2857,
1, 1, 1, 1, 0.8809, 0.9607, 0.945, 0.9431, 0.9211), percent_of_views_private_channels = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), percent_of_views_d_ms = c(0.7143,
0, 0, 0, 0, 0.1191, 0.0393, 0.055, 0.0569, 0.0789), name = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0), public_channels_single_workspace = c(10,
10, 11, 11, 12, 12, 12, 13, 13, 13), messages_posted = c(35,
35, 37, 38, 66, 1101, 1797, 2265, 2631, 3055)), row.names = c(NA,
-10L), class = c("tbl_df", "tbl", "data.frame"))
Here is an example using a toy data set, where the original data are first grouped and summarised to get the 'proportions', then piped to ggplot, which will automatically create a stacked bar plot
df <- data.frame(group=sample(letters[1:10],1000,T),
species=sample(1:4,1000,T),
amount=sample(10:30,1000,T))
df %>% group_by(group,species) %>% summarise(perc=mean(amount)) %>%
ggplot(aes(group,perc,fill=factor(species))) +
geom_bar(stat='identity')
UPDATE
This will calculate the proportion that 'species' occurs within each 'group'.
df %>% group_by(group,species) %>% summarise(n=n()) %>%
group_by(group) %>% mutate(perc=n/sum(n)) %>%
ggplot(aes(group,perc,fill=factor(species))) +
geom_bar(stat='identity')

Bootstrapping with glm model

I have a negative binomial regression model where I predict Twitter messages' retweet count based on their use of certain word types (ME words, Moral words, and Emotional words):
M1 <- glm.nb(retweetCount ~ ME_words + Moral_words + Emo_words, data = Tweets)
I now want to sample with bootstrapping (for instance, samples of 1,000 with replacement from the dataframe's original 500,000 messages) from the large dataset, Tweets, to run iterations of the model and analyse the variance of the coefficients. What is the best approach to doing this? I am assuming I need to use the boot package, but I am a bit lost with where to start.
Ideally, I would like to create a for loop that can run a number of iterations, and then store the coefficients of each model iteration in a new dataframe. This would be extremely useful for future analyses.
Here is some reproducible data from the much much large dataframe Tweets:
>dput((head(Tweets, 100)))
structure(list(retweetCount = c(1388, 762, 748, 436, 342, 320,
312, 295, 264, 251, 196, 190, 175, 167, 165, 163, 149, 148, 148,
146, 133, 132, 126, 124, 122, 122, 121, 120, 118, 118, 114, 113,
112, 110, 108, 107, 104, 101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0, 1, 0, 0, 1, 0, 0, 1, 2, 2, 1, 0, 0, 0, 0, 2, 1, 0, 0,
1, 0, 0, 1, 2, 2, 0, 0, 0)), row.names = c(NA, -100L), class = c("tbl_df",
"tbl", "data.frame"))
You can use the boot package, but for simple versions of the bootstrap it's almost simpler to roll your own.
fit initial model
library(MASS)
M1 <- glm.nb(retweetCount ~ ME_words + Moral_words +
Emo_words, data = Tweets)
set up data structure for results
nboot <- 1000
bres <- matrix(NA,nrow=nboot,
ncol=length(coef(M1)),
dimnames=list(rep=seq(nboot),
coef=names(coef(M1))))
bootstrap
set.seed(101)
bootsize <- 200
for (i in seq(nboot)) {
bdat <- Tweets[sample(nrow(Tweets),size=bootsize,replace=TRUE),]
bfit <- update(M1, data=bdat) ## refit with new data
bres[i,] <- coef(bfit)
}
structure output
data.frame(mean_est=colMeans(bres),
t(apply(bres,2,quantile,c(0.025,0.975))))

cross product calcuation by store level in r

I have the following data (Which is a slight adaptation of an earlier question):
The dimensions are: [1] 131 46
I am trying to create a list of chain by chain product sales.
# A tibble: 6 x 46
L5 ` Chain100` ` Chain103` ` Chain104` ` Chain106` ` Chain109` ` Chain15 ` ` Chain17 ` ` Chain19 ` ` Chain20 `
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 ABBE~ 0 0 0 0 0 0 0 0 0
2 ANHE~ 0 0 0 0 0 0 0 0 0
3 ANHE~ 0 0 0 0 0 0 0 0 0
4 B E 0 0 0 0 0 0 0 0 0
5 BACA~ 124 339 16 32 0 0 0 0 0
6 BACA~ 0 0 0 0 0 0 0 0 0
# ... with 36 more variables: ` Chain23 ` <dbl>, ` Chain25 ` <dbl>, ` Chain42 ` <dbl>, ` Chain43 ` <dbl>, ` Chain44
# ` <dbl>, ` Chain47 ` <dbl>, ` Chain48 ` <dbl>, ` Chain49 ` <dbl>, ` Chain50 ` <dbl>, ` Chain52 ` <dbl>, `
# Chain54 ` <dbl>, ` Chain57 ` <dbl>, ` Chain60 ` <dbl>, ` Chain61 ` <dbl>, ` Chain62 ` <dbl>, ` Chain65 ` <dbl>,
# ` Chain66 ` <dbl>, ` Chain67 ` <dbl>, ` Chain68 ` <dbl>, ` Chain70 ` <dbl>, ` Chain71 ` <dbl>, ` Chain72
# ` <dbl>, ` Chain75 ` <dbl>, ` Chain8 ` <dbl>, ` Chain80 ` <dbl>, ` Chain82 ` <dbl>, ` Chain83 ` <dbl>, ` Chain84
# ` <dbl>, ` Chain87 ` <dbl>, ` Chain88 ` <dbl>, ` Chain89 ` <dbl>, ` Chain90 ` <dbl>, ` Chain91 ` <dbl>, `
# Chain93 ` <dbl>, ` Chain96 ` <dbl>, ` Chain99 ` <dbl>
The data looks like the above. So I am interested in trying to create multiple lists for each product. That is chain100 and chain103 both sold BACARDI SILVER (along with a few other chains).
What I am trying to do is to make multiple lists which look like the following:
Chain1 Chain2 Chain3 Chain4
Chain1 -
BACARDI SILVER Chain2 234 -
Chain3 72 541 -
Chain4 0 231 0 -
So for each row or product there will be multiple lists (comparing the cross product purchases in each "chain").
Data:
structure(list(L5 = structure(1:131, .Label = c("ABBEY DE LEFFE BLONDE PALE AL",
"ANHEUSER WORLD LAGER", "ANHEUSER WORLD SELECT", "B E", "BACARDI SILVER",
"BACARDI SILVER LIMON", "BACARDI SILVER MOJITO", "BACARDI SILVER MOJITO PARTY P",
"BACARDI SILVER O3", "BACARDI SILVER RAZ", "BACARDI SILVER SAMPLER",
"BACARDI SILVER SIGNATURE", "BASS PALE ALE", "BEACH BUM BLONDE ALE",
"BECKS", "BECKS DARK", "BECKS OKTOBERFEST", "BECKS PREMIER LIGHT",
"BEST OF BELGIUM", "BODDINGTONS PUB CREAM ALE", "BREWMASTERS PRIVATE RESERVE",
"BUD ICE", "BUD ICE LIGHT", "BUD LIGHT", "BUD LIGHT CHELADA",
"BUD LIGHT GOLDEN WHEAT", "BUD LIGHT LIME", "BUD LIGHT LIME LIME A RITA",
"BUD LIGHT PARTY PACK", "BUD LIGHT PLATINUM LAGER", "BUDWEISER",
"BUDWEISER AMERICAN ALE", "BUDWEISER BREWMASTERS PROJECT", "BUDWEISER CHELADA",
"BUDWEISER DRY", "BUDWEISER HAPPY HOLIDAYS", "BUDWEISER ICE DRAFT",
"BUDWEISER MILLENNIUM", "BUDWEISER SELECT", "BUDWEISER SELECT 55",
"BUSCH", "BUSCH ICE", "BUSCH LIGHT", "BUSCH NA", "CZECHVAR",
"DOC OTIS HARD LEMON", "GOOSE ISLAND 312 URBAN WHEAT", "GOOSE ISLAND CHRISTMAS ALE",
"GOOSE ISLAND HONKERS ALE", "GOOSE ISLAND IPA", "GOOSE ISLAND SEASONAL",
"GROLSCH AMBER ALE", "GROLSCH LAGER", "GROLSCH LIGHT LAGER",
"GROLSCH SUMMER BLONDE", "HAAKE BECK NA", "HARBIN LAGER", "HOEGAARDEN WHITE ALE",
"HURRICANE HIGH GRAVITY", "HURRICANE HIGH GRAVITY LAGER", "HURRICANE MALT LIQUOR",
"JACKS PUMPKIN SPICE ALE", "KILLARNEYS RED LAGER", "KING COBRA",
"KIRIN ICHIBAN", "KIRIN ICHIBAN LAGER", "KIRIN LAGER", "KIRIN LIGHT",
"LANDSHARK LAGER", "LOWENBRAU", "MARGARITAVILLE", "MARGARITAVILLE 5 O CLOCK",
"MICHELOB", "MICHELOB AMBER BOCK", "MICHELOB BLACK AND TAN",
"MICHELOB DRY", "MICHELOB DUNKEL WEISSE", "MICHELOB GOLDEN DRAFT",
"MICHELOB GOLDEN DRAFT LIGHT", "MICHELOB HEFEWEIZEN", "MICHELOB HONEY LAGER",
"MICHELOB IRISH RED ALE", "MICHELOB LIGHT", "MICHELOB MARZEN",
"MICHELOB PALE ALE", "MICHELOB SEASONAL", "MICHELOB SPCLTY ALES & LGRS W",
"MICHELOB SPECIALTY ALES & LAG", "MICHELOB ULTR POMEGRANAT RSPB",
"MICHELOB ULTR TUSCN ORNG GRAP", "MICHELOB ULTRA", "MICHELOB ULTRA AMBER",
"MICHELOB ULTRA DRAGON FRUIT P", "MICHELOB ULTRA FRUIT SAMPLER",
"MICHELOB ULTRA LIGHT", "MICHELOB ULTRA LIME CACTUS", "NATTY DADDY LAGER",
"NATURAL ICE", "NATURAL LIGHT", "ODOULS", "ODOULS AMBER", "PEELS",
"RED WOLF", "REDBRIDGE", "ROCK GREEN LIGHT", "ROCK LIGHT", "ROLLING ROCK EXTRA PALE",
"ROLLING ROCK LIGHT", "SAINT PAULI GIRL", "SAINT PAULI GIRL DARK",
"SAINT PAULI N A", "SHADOWS WILD BLACK LAGER", "SHOCK TOP BELGIAN WHITE ALE",
"SHOCK TOP PUMPKIN WHEAT", "SHOCK TOP RASPBERRY WHEAT ALE", "SHOCK TOP SEASONAL",
"SHOCK TOP VARIETY PACK", "SHOCK TOP WHEAT IPA", "SPRING HEAT SPICED WHEAT",
"STELLA ARTOIS LAGER", "STONE MILL", "TAKE 6 HOME", "TEQUIZA",
"TIGER LAGER", "TILT", "TILT 8 PERCENT", "ULTRA 19TH HOLE", "WHITBREAD TRADITIONAL PALE AL",
"WILD BLUE", "WILD HOP", "WILD HOP ORGANIC LAGER"), class = "factor"),
` Chain100` = c(0, 0, 0, 0, 124, 0, 0, 0, 45, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 208, 154, 1053, 0, 0, 0, 0, 0, 0,
1046, 0, 0, 0, 0, 0, 0, 0, 0, 0, 661, 1, 585, 64, 0, 41,
0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0,
0, 0, 0, 0, 0, 0, 0, 180, 127, 27, 0, 0, 0, 0, 31, 63, 0,
361, 0, 0, 0, 9, 0, 0, 0, 241, 0, 0, 0, 0, 0, 0, 233, 508,
146, 45, 0, 0, 0, 0, 0, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain103` = c(0,
0, 0, 0, 339, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 530, 284, 2309, 0, 0, 0, 0, 0, 0, 2252, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1464, 3, 1391, 171, 0, 157, 0, 0, 0, 0, 0, 3,
47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 85, 0, 0, 0, 0, 0, 0,
0, 0, 422, 249, 91, 0, 0, 1, 6, 43, 131, 0, 853, 0, 0, 0,
18, 0, 0, 0, 138, 0, 0, 0, 0, 0, 0, 401, 1188, 375, 113,
0, 0, 0, 0, 0, 587, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 158, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain104` = c(0, 0,
0, 0, 16, 0, 0, 0, 33, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 91, 17, 336, 0, 0, 0, 0, 0, 0, 312, 0, 0, 0, 0, 0, 0,
0, 0, 0, 238, 5, 295, 38, 0, 3, 0, 0, 0, 0, 0, 0, 4, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 25,
14, 0, 0, 0, 0, 0, 3, 0, 104, 0, 0, 0, 0, 0, 0, 0, 99, 0,
0, 0, 0, 0, 0, 16, 154, 16, 0, 0, 0, 0, 0, 0, 49, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), ` Chain106` = c(0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 633, 266, 2230, 0, 0, 0, 0,
0, 0, 2115, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1540, 103, 1561, 190,
0, 194, 0, 0, 0, 0, 0, 7, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 83, 0, 0, 0, 0, 0, 0, 0, 0, 528, 225, 112, 0, 0, 74,
168, 43, 113, 0, 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 0,
3382, 87, 0, 147, 0, 2, 0, 0, 1620, 0, 1513, 98, 1655, 319,
12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 5, 157, 0, 37, 0, 6,
0, 52, 65, 0, 0, 12, 489, 66, 0, 0, 393, 650, 0, 0, 19, 0,
0, 0, 52, 0, 990, 96, 23, 150, 51, 20, 286, 105, 1430, 537,
0, 25, 0, 326, 0, 821, 1697, 471, 181, 0, 0, 77, 322, 70,
744, 0, 0, 0, 0, 0, 156, 0, 0, 0, 0, 0, 0, 482, 2, 0, 68,
0, 32, 45, 0, 0, 0, 0, 5), ` Chain43 ` = c(37, 0, 0, 0, 4,
0, 0, 0, 0, 24, 0, 101, 252, 0, 602, 225, 35, 107, 0, 210,
0, 1343, 0, 6191, 279, 244, 2003, 242, 0, 642, 5266, 64,
16, 20, 0, 0, 0, 0, 2755, 2284, 2598, 59, 2992, 566, 30,
0, 205, 6, 36, 96, 39, 0, 0, 0, 0, 31, 0, 327, 18, 43, 0,
0, 0, 188, 15, 6, 0, 14, 1061, 0, 30, 0, 121, 1175, 0, 0,
0, 0, 0, 0, 35, 0, 1069, 3, 0, 54, 21, 0, 424, 0, 2972, 535,
144, 9, 78, 457, 0, 2064, 3224, 845, 431, 0, 0, 455, 0, 29,
1180, 0, 261, 111, 36, 0, 539, 37, 390, 193, 15, 34, 0, 1400,
0, 103, 0, 0, 327, 14, 6, 0, 219, 0, 0), ` Chain44 ` = c(45,
0, 0, 0, 27, 0, 62, 6, 0, 104, 0, 113, 167, 0, 359, 209,
15, 62, 0, 139, 0, 694, 59, 3604, 207, 495, 1092, 0, 24,
0, 3085, 273, 0, 46, 0, 0, 0, 0, 1609, 969, 1377, 81, 1580,
337, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 166, 0, 52,
0, 0, 0, 98, 35, 0, 0, 11, 618, 1, 0, 0, 174, 566, 0, 0,
29, 0, 0, 0, 55, 0, 820, 29, 3, 120, 55, 0, 285, 65, 1430,
371, 138, 0, 0, 284, 0, 909, 1683, 455, 177, 0, 0, 177, 2,
120, 722, 0, 0, 0, 0, 0, 209, 0, 0, 0, 0, 0, 0, 503, 0, 0,
0, 0, 9, 62, 0, 0, 89, 0, 0), ` Chain47 ` = c(48, 0, 0, 0,
117, 0, 314, 20, 0, 247, 0, 29, 261, 0, 477, 276, 8, 108,
0, 145, 0, 698, 219, 3641, 231, 167, 1108, 0, 0, 0, 3272,
368, 0, 89, 0, 0, 0, 0, 1647, 163, 1453, 79, 1662, 343, 23,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 1, 154, 0, 51, 0, 0, 0,
62, 36, 0, 0, 4, 613, 33, 0, 0, 239, 632, 0, 0, 100, 0, 0,
0, 126, 32, 921, 87, 69, 135, 185, 0, 298, 173, 1440, 496,
0, 65, 0, 320, 0, 843, 1715, 457, 185, 0, 0, 73, 2, 271,
737, 0, 0, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 455, 0, 0, 1,
0, 24, 77, 0, 0, 0, 0, 0), ` Chain48 ` = c(46, 38, 0, 71,
631, 0, 137, 0, 287, 476, 0, 0, 315, 44, 473, 280, 29, 180,
12, 137, 0, 1241, 838, 5938, 0, 0, 0, 0, 0, 0, 5550, 0, 0,
0, 47, 28, 0, 0, 3154, 0, 2664, 69, 2973, 602, 8, 0, 0, 0,
0, 0, 0, 0, 484, 15, 38, 45, 27, 133, 0, 0, 0, 54, 0, 105,
70, 0, 0, 19, 0, 141, 0, 0, 917, 1129, 0, 0, 0, 0, 0, 0,
102, 0, 1883, 22, 0, 0, 0, 63, 33, 25, 2355, 958, 0, 0, 0,
58, 0, 1243, 2922, 877, 349, 374, 0, 61, 401, 0, 1251, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 333, 102, 0, 163, 39, 158,
11, 0, 0, 0, 96, 0), ` Chain49 ` = c(4, 30, 37, 67, 721,
0, 29, 0, 376, 452, 2, 0, 44, 8, 25, 39, 0, 0, 0, 13, 0,
853, 490, 3820, 0, 0, 0, 0, 0, 0, 3716, 0, 0, 0, 67, 11,
0, 0, 1632, 0, 1974, 0, 2066, 390, 0, 0, 0, 0, 0, 0, 0, 0,
252, 0, 8, 0, 0, 18, 0, 0, 0, 1, 0, 52, 5, 0, 0, 0, 0, 0,
0, 0, 710, 792, 0, 0, 0, 0, 0, 0, 95, 0, 1363, 0, 0, 0, 0,
22, 0, 0, 1717, 95, 0, 0, 0, 0, 0, 874, 1979, 606, 180, 143,
0, 6, 41, 0, 833, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 46,
13, 0, 90, 0, 17, 0, 0, 0, 0, 19, 0), ` Chain50 ` = c(0,
0, 126, 0, 357, 133, 0, 0, 453, 415, 25, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 732, 523, 2985, 0, 0, 0, 0, 0, 0, 2927, 0, 0,
0, 83, 0, 1, 0, 0, 0, 1722, 0, 1767, 413, 0, 14, 0, 0, 0,
0, 0, 0, 188, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 28, 0, 3,
0, 0, 0, 0, 0, 687, 629, 6, 0, 0, 0, 0, 8, 139, 0, 1106,
0, 0, 0, 0, 15, 0, 0, 1387, 0, 0, 0, 0, 0, 0, 706, 1660,
475, 221, 0, 0, 0, 0, 0, 667, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 182, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain52 ` = c(0,
0, 0, 0, 450, 0, 0, 0, 440, 122, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 699, 518, 2710, 0, 0, 0, 0, 0, 0, 2670, 0, 0, 0,
67, 0, 0, 0, 0, 0, 1650, 8, 1686, 417, 0, 186, 0, 0, 0, 0,
0, 0, 155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 14, 0, 21, 0,
0, 0, 0, 0, 726, 572, 194, 0, 0, 0, 0, 99, 199, 0, 1032,
0, 0, 0, 17, 24, 0, 0, 932, 0, 0, 0, 0, 0, 0, 729, 1550,
459, 215, 0, 6, 0, 0, 0, 685, 4, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 244, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain54 ` = c(0,
0, 0, 0, 418, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 672, 484, 2349, 0, 0, 0, 0, 0, 0, 2232, 0, 0, 0, 72, 0,
0, 0, 0, 0, 1411, 38, 1381, 399, 0, 241, 0, 0, 0, 0, 0, 15,
151, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 52, 3, 0, 27, 0, 0, 0,
0, 0, 648, 405, 172, 1, 0, 7, 27, 139, 194, 0, 966, 0, 0,
0, 42, 0, 0, 0, 177, 0, 0, 0, 0, 0, 0, 639, 1293, 432, 264,
0, 52, 0, 0, 0, 633, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 307, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain57 ` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 552, 346, 1586, 0, 0, 0, 0, 0, 0, 1627, 0, 0, 0, 74, 0,
0, 1, 0, 0, 1037, 37, 1060, 311, 0, 191, 0, 0, 0, 0, 0, 29,
168, 0, 0, 0, 0, 0, 0, 0, 13, 0, 116, 49, 0, 0, 37, 0, 0,
0, 0, 0, 482, 310, 111, 0, 0, 75, 304, 96, 151, 0, 685, 0,
0, 0, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 424, 899, 296, 199,
0, 50, 0, 0, 0, 457, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 258, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain60 ` = c(21,
0, 0, 0, 9, 0, 359, 7, 0, 169, 13, 0, 236, 0, 327, 205, 8,
75, 0, 86, 0, 296, 70, 1707, 71, 0, 333, 0, 0, 0, 1649, 61,
0, 55, 0, 0, 0, 0, 954, 0, 700, 0, 873, 239, 12, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 389, 0, 0, 0, 184, 468, 0, 0, 26, 0, 0, 0, 0, 0, 549,
26, 14, 64, 28, 1, 120, 0, 1066, 420, 0, 0, 0, 121, 0, 319,
662, 419, 41, 1, 0, 41, 147, 51, 483, 0, 0, 0, 0, 0, 94,
0, 0, 0, 0, 0, 0, 247, 42, 0, 0, 0, 49, 0, 0, 0, 116, 0,
11), ` Chain61 ` = c(0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, 22,
135, 0, 262, 98, 0, 58, 0, 113, 0, 426, 3, 1695, 0, 79, 641,
50, 0, 152, 1564, 47, 0, 0, 0, 0, 0, 0, 858, 794, 796, 0,
911, 203, 0, 0, 66, 0, 31, 48, 23, 0, 0, 0, 0, 0, 0, 106,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 354, 0, 49, 11, 125, 347, 0,
0, 0, 0, 0, 0, 0, 0, 456, 0, 0, 5, 6, 0, 192, 0, 909, 286,
0, 0, 51, 185, 0, 460, 672, 378, 178, 0, 0, 139, 0, 23, 264,
7, 92, 31, 0, 23, 198, 0, 138, 48, 13, 0, 0, 395, 0, 0, 0,
0, 0, 0, 0, 0, 89, 0, 0), ` Chain62 ` = c(41, 0, 0, 0, 35,
0, 176, 7, 0, 23, 0, 35, 167, 0, 232, 143, 0, 92, 0, 85,
0, 254, 21, 1464, 25, 245, 596, 0, 25, 0, 1348, 196, 0, 23,
0, 0, 0, 0, 788, 537, 608, 0, 703, 212, 11, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 358,
0, 0, 0, 141, 362, 0, 0, 7, 0, 0, 0, 0, 0, 392, 23, 6, 45,
40, 0, 183, 0, 822, 279, 0, 0, 0, 179, 0, 282, 562, 353,
101, 0, 0, 46, 0, 72, 367, 0, 0, 0, 0, 0, 181, 0, 0, 0, 0,
0, 0, 264, 8, 0, 0, 0, 5, 0, 0, 0, 170, 0, 0), ` Chain65 ` = c(58,
0, 0, 3, 7, 0, 382, 20, 18, 258, 0, 0, 530, 0, 691, 473,
0, 138, 0, 184, 0, 984, 280, 5247, 60, 58, 682, 0, 0, 0,
5073, 307, 0, 63, 0, 6, 0, 0, 2635, 95, 2176, 1, 2711, 734,
23, 0, 0, 0, 0, 0, 0, 0, 381, 0, 0, 0, 0, 164, 0, 0, 0, 5,
0, 0, 0, 0, 0, 0, 453, 0, 0, 0, 588, 1419, 0, 0, 40, 0, 0,
0, 27, 0, 1623, 70, 35, 75, 109, 58, 230, 0, 2989, 1200,
0, 0, 0, 229, 0, 1028, 2053, 1278, 130, 546, 0, 96, 180,
124, 1404, 0, 0, 0, 0, 0, 207, 0, 0, 0, 0, 0, 0, 520, 64,
0, 0, 0, 90, 0, 0, 0, 213, 28, 0), ` Chain66 ` = c(0, 0,
0, 48, 193, 0, 43, 1, 121, 290, 9, 13, 5, 0, 4, 9, 0, 0,
0, 0, 5, 647, 258, 2806, 54, 8, 188, 0, 0, 0, 2638, 20, 0,
0, 1, 1, 0, 0, 691, 61, 1478, 42, 1653, 322, 0, 0, 0, 0,
0, 0, 0, 0, 242, 0, 0, 0, 0, 0, 0, 83, 0, 0, 0, 10, 0, 0,
0, 2, 113, 0, 26, 0, 427, 573, 0, 0, 0, 0, 0, 0, 87, 0, 767,
0, 0, 4, 0, 27, 49, 0, 1236, 31, 18, 4, 0, 63, 0, 560, 1041,
470, 48, 0, 0, 0, 13, 0, 564, 0, 0, 0, 0, 0, 12, 12, 14,
0, 0, 0, 0, 29, 0, 0, 0, 0, 2, 45, 0, 13, 13, 0, 0), ` Chain67 ` = c(0,
0, 0, 0, 180, 0, 0, 0, 336, 224, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 617, 308, 2310, 0, 0, 100, 44, 0, 80, 2135, 0, 0,
0, 1, 0, 0, 0, 64, 48, 1227, 23, 1354, 261, 0, 8, 2, 3, 1,
1, 0, 0, 221, 0, 0, 1, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0,
0, 33, 0, 8, 0, 514, 512, 6, 0, 0, 5, 0, 0, 62, 0, 753, 0,
0, 0, 0, 4, 21, 0, 1091, 0, 4, 0, 14, 25, 0, 433, 921, 458,
46, 0, 0, 0, 0, 0, 509, 0, 0, 0, 0, 0, 9, 0, 1, 31, 7, 0,
0, 18, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain68 ` = c(0,
0, 0, 0, 25, 0, 18, 7, 3, 27, 0, 22, 0, 0, 0, 0, 0, 0, 0,
0, 0, 68, 10, 470, 33, 23, 132, 0, 2, 0, 387, 19, 0, 0, 0,
0, 0, 0, 65, 64, 282, 18, 298, 75, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 41, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0,
0, 0, 33, 0, 0, 2, 0, 0, 0, 0, 0, 58, 5, 0, 18, 0, 0, 21,
1, 173, 0, 16, 0, 0, 35, 0, 58, 126, 24, 0, 0, 0, 0, 0, 3,
52, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 2,
34, 0, 0, 0, 0, 0), ` Chain70 ` = c(0, 0, 0, 0, 356, 0, 0,
0, 303, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 422, 319, 1508,
0, 0, 0, 0, 0, 0, 1429, 0, 0, 0, 1, 0, 0, 0, 0, 0, 884, 0,
943, 192, 0, 123, 0, 0, 0, 0, 0, 0, 126, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 548, 387, 122, 0,
0, 0, 0, 0, 103, 0, 673, 0, 0, 0, 3, 0, 0, 0, 551, 0, 0,
0, 0, 0, 0, 251, 716, 393, 123, 0, 0, 0, 0, 0, 390, 35, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191, 0, 0, 0, 0, 0,
0, 0, 0), ` Chain71 ` = c(0, 0, 0, 0, 54, 0, 20, 2, 14, 26,
0, 6, 0, 0, 0, 0, 3, 5, 0, 0, 0, 80, 26, 474, 30, 9, 111,
0, 0, 0, 377, 39, 0, 0, 0, 0, 0, 0, 64, 10, 277, 27, 285,
56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 0, 0,
0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 2, 5, 0, 0, 15, 0, 0, 0, 0,
11, 54, 13, 3, 20, 0, 4, 17, 9, 155, 2, 0, 10, 0, 32, 0,
80, 127, 26, 0, 0, 0, 0, 0, 12, 49, 0, 0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 12, 35, 0, 0, 1, 0, 0), ` Chain72 ` = c(0,
0, 0, 0, 244, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 315, 243, 1039, 0, 0, 0, 0, 0, 0, 1020, 0, 0, 0, 0, 0,
0, 0, 0, 0, 688, 0, 781, 155, 0, 135, 0, 0, 0, 0, 0, 0, 81,
0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0,
429, 257, 93, 0, 0, 14, 13, 0, 84, 0, 491, 0, 0, 0, 16, 0,
0, 0, 72, 0, 0, 0, 0, 0, 0, 169, 659, 297, 136, 0, 0, 0,
0, 0, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196,
0, 0, 0, 0, 0, 0, 0, 0), ` Chain75 ` = c(0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 332, 230, 818,
0, 0, 0, 0, 0, 0, 805, 0, 0, 0, 0, 0, 0, 0, 0, 0, 731, 0,
708, 152, 0, 173, 0, 0, 0, 0, 0, 0, 114, 0, 0, 0, 0, 0, 0,
0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 423, 241, 123, 0,
0, 92, 139, 0, 121, 0, 467, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 150, 643, 262, 127, 0, 0, 0, 0, 0, 264, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0,
0, 0, 0), ` Chain8 ` = c(0, 0, 0, 11, 72, 15, 0, 0, 97,
43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 202, 131, 959, 0, 0,
0, 0, 0, 0, 919, 0, 0, 0, 0, 0, 0, 0, 55, 0, 519, 0, 495,
78, 0, 44, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 219, 124, 41, 0, 0, 0, 0,
0, 46, 0, 414, 0, 0, 0, 3, 4, 0, 0, 428, 0, 0, 0, 0, 0, 0,
247, 482, 167, 75, 0, 0, 0, 0, 0, 243, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain80 ` = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,
0, 53, 0, 573, 0, 2, 58, 0, 0, 0, 312, 0, 0, 0, 0, 0, 0,
0, 3, 1, 201, 0, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
0, 0, 0, 0, 12, 128, 0,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ` Chain99 ` = c(0,
0, 0, 4, 73, 0, 25, 0, 20, 42, 17, 0, 3, 0, 7, 15, 0, 0,
0, 0, 3, 118, 27, 695, 0, 0, 0, 0, 0, 0, 732, 0, 0, 0, 0,
4, 0, 0, 85, 0, 385, 28, 333, 43, 0, 4, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 0, 0, 0, 41, 5, 0, 3, 84, 2, 0, 0, 0, 0, 0,
0, 0, 68, 59, 0, 0, 0, 0, 0, 0, 0, 0, 171, 0, 0, 0, 0, 3,
0, 13, 132, 40, 0, 0, 0, 7, 0, 108, 214, 17, 0, 1, 0, 3,
29, 0, 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 1, 0, 0,
0, 0, 34, 0, 0, 0, 1, 0)), row.names = c(NA, -131L), class = c("tbl_df",
"tbl", "data.frame"))

HistogramTools package usage in R

I am generating two histograms based on the script below, they are not equal on the x axis and as I wish to compare them I can not do so. Therefore, what can I do to run the script properly, any ideas how to approach this issue?
Thanks
x<-c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3,
2, 6, 5, 13, 12, 15, 27, 34, 37, 58, 85, 90, 111, 131, 161, 164,
191, 211, 267, 293, 288, 320, 364, 370, 379, 413, 429, 473, 546,
539, 551, 593, 614, 594, 644, 617, 599, 605, 531, 591, 524, 482,
470, 437, 446, 428, 384, 368, 331, 332, 320, 317, 295, 266, 286,
284, 342, 360, 394, 480, 502, 600, 547, 610, 524, 545, 497, 414,
381, 345, 351, 371, 326, 336, 341, 336, 324, 346, 360, 386, 368,
396, 428, 432, 434, 438, 513, 498, 452, 452, 403, 397, 407, 405,
460, 515, 541, 608, 522, 542, 514, 517, 551, 661, 669, 739, 805,
847, 921, 1031, 965, 973, 1030, 1043, 815, 818, 648, 520, 433,
338, 295, 162, 106, 70, 44, 15, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
y<-c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
1, 1, 6, 4, 11, 4, 9, 15, 12, 34, 40, 49, 75, 65, 107, 132, 136,
157, 178, 189, 217, 278, 276, 296, 323, 435, 464, 473, 581, 613,
705, 820, 925, 1025, 1061, 1080, 1176, 1236, 1166, 1075, 1027,
976, 935, 807, 697, 658, 593, 440, 408, 347, 312, 296, 242, 284,
260, 243, 254, 283, 291, 371, 444, 470, 607, 719, 676, 722, 644,
678, 650, 662, 666, 607, 621, 558, 623, 634, 634, 699, 756, 771,
790, 852, 893, 1011, 1048, 1010, 966, 936, 860, 791, 681, 686,
752, 850, 952, 1049, 1094, 1134, 1156, 1198, 1351, 1342, 1533,
1461, 1271, 1065, 865, 739, 534, 459, 359, 275, 169, 124, 108,
80, 74, 64, 69, 61, 59, 56, 60, 76, 113, 102, 132, 101, 79, 92,
55, 41, 26, 17, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0)
h1 <- hist(x)
h2 <- hist(y)
require(HistogramTools)
minkowski.dist(h1, h2, 1)
minkowski.dist(h1, h2, 2)
minkowski.dist(h1, h2, 3)
intersect.dist(h1, h2)
kl.divergence(h1, h2)
jeffrey.divergence(h1, h2)
Both vectors (x and y) have 256 observations. Are these observations paired, i.e., for each x there is a corresponding y, and they have the same unit of measurement?
If yes, you can subtract one vector from the other and just plot the histogram of their differences to compare each other. Something like below:
length(x) #check number os observations in x
length(y) #check number os observations in y
diff = x-y #difference between x and y
hist(diff, xlab="x-y", main="Difference of vectors x and y")
If the x and y cannot be paired, but they have the same unit of measument there is the option provided by Hav0k.
Set the axis on both histograms with the same length and breaks to visually compare each other.
par(mfrow=c(1,2)) #stacks hisotgrams in one row and two columns
hist(x, xlim=c(0,1600), ylim=c(0,200), breaks=seq(0,1600,100),main="")
hist(y, xlim=c(0,1600), ylim=c(0,200), breaks=seq(0,1600,100),main="")
It is also possible to calculate the dissimilarity metrics with these:
h1 = hist(x, xlim=c(0,1600), ylim=c(0,200), breaks=seq(0,1600,100),main="")
h2 = hist(y, xlim=c(0,1600), ylim=c(0,200), breaks=seq(0,1600,100),main="")
minkowski.dist(h1, h2, 1) #116
minkowski.dist(h1, h2, 2) #38.88
minkowski.dist(h1, h2, 3) #29.81
intersect.dist(h1, h2) #0.22
If x and y have different units of measurements there is the option of standardizing the data before computing the dissimilarities.
x_standardized = (x-mean(x))/(sd(x))
y_standardized = (y-mean(y))/(sd(y))
h1=hist(x_standardized)
h2=hist(y_standardized)
minkowski.dist(h1, h2, 1) #58
minkowski.dist(h1, h2, 2)#26.57
minkowski.dist(h1, h2, 3) #22.1
intersect.dist(h1, h2) # 0.11
kl.divergence(h1, h2) # 0.07
jeffrey.divergence(h1, h2) #0.03

Resources