Logit regression with WinBUGS/R2WinBUGS not converging to likelihood estimates - r

I am a Win-7 user with R 2.15.2
Can someone help me why is the following model not converging well close to simple logit model estimates?
Edited
Mydata <- structure(list(gg = c(13.659955, 6.621436486, 3.017166776, 2.516795069,
3.928538296, 4.211960532, 3.235445955, 5.152860411, 18.96466673,
5.904678823, 4.987622293, 1.170687541, 3.088224149, 4.738065529,
3.263022593, 6.050017999, 5.650762257, 2.058924721, 3.138591919,
7.169083435, 11.30381738, 3.036991188, 4.559013218, 3.978760664,
3.617455798, 2.430111184, 4.440319959, 2.200267742, 6.003166495,
3.114161526, 3.812363457, 11.12816724, 15.6564348, 13.50562576,
5.154056904, 6.26451889, 1.849669635, 1.816757851, 3.861868285,
2.884542233, 2.993444924, 2.724235493, 2.694159089, 1.973597356,
4.371300647, 3.559035718, 3.59124243, 6.587196681, 10.03402072,
4.805158339, 4.491460392, 1.627936721, 1.278291553, 0.978710462,
3.08635052, 2.58594947, 2.354973563, 1.657519171, 2.946994656,
2.110549733, 6.095182338, 6.000660354, 6.691960157, 1.796172588,
2.531234555, 2.992017156, 2.882403206, 6.066420081, 5.930524609,
5.972280022, 0.915755208, 2.398369176, 2.614677323, 3.904309459,
2.120045842, 2.643895472, 4.756728133, 4.420426549, 5.787620043,
10.14764507, 10.17993063, 4.529582451, 2.132173713, 3.573017249,
2.749427487, 5.79057317, 3.30235352, 2.248377801, 3.37704153,
3.270636543, 8.070781663, 10.63482235, 11.91206431, 2.030994094,
3.843890691, 11.08130402, 10.56164432, 2.476733196, 2.672953595,
4.73313584, 2.577761507, 4.397950314, 16.02648073, 1.979318271,
4.124346958, 18.95385675, 5.364182526, 3.964093091, 4.985103684,
5.887163026, 6.302977032, 3.594056904, 2.1592159, 2.506654073,
2.739740977, 5.840023906, 14.66431143, 1.453209431, 1.405915159,
6.133806412, 14.46294647, 15.7475232, 13.91882816, 3.667160495,
2.472826568, 2.208138746, 2.313856848, 6.677046217, 5.960024468,
2.647365332, 1.960115215, 2.392076123, 2.796502016, 2.147861348,
3.825593606, 2.427949377, 3.111598763, 5.248771445, 3.333653698,
3.937363645, 1.98551364, 4.090444736, 1.897938127, 3.772878129,
1.708975251, 2.149179807, 1.985344614, 3.445809412, 1.537484672,
3.210425705, 3.635236243, 3.340757476, 2.426647042, 16.65453923,
2.207695228, 17.05735446, 9.148235024, 3.289077716, 2.534469392,
1.827870535, 2.952377144, 2.218054092, 3.787767414, 1.862731602,
6.699397675, 2.572247774, 2.42783988, 3.429506609, 2.152120465,
6.651671979, 3.389825443, 1.787049217, 2.368181588, 2.358737508,
3.470515609, 1.693830224, 4.124049967, 2.894483735, 1.90612459,
3.447950783, 11.73691853, 12.78330833, 3.860448673, 2.571402925,
2.66582863, 3.206179619, 2.546483922, 3.047299616, 2.052597638,
4.894592388, 2.869309084, 2.851843536, 1.729619574, 2.276794788,
12.68354926, 3.318892896, 10.71333438, 3.318892896, 10.71333438,
1.908315292, 3.111350542, 1.847059969, 1.835544656, 2.618919198,
2.341098688, 2.920079188, 1.830521448, 4.95152276, 10.18359208,
11.37645094, 3.44132725, 11.51865833, 14.45180625, 12.61570573,
10.80784104, 7.814012406, 14.48656688, 1.019333021, 2.816970615,
7.101350458, 1.764183823, 4.821036885, 2.251823823, 1.569206635,
1.791906542, 3.114256927, 2.496611198, 2.776086885, 2.477500021,
4.801364906, 3.642995521, 4.279315979, 4.956759854, 3.710843927,
15.75846719, 3.032181385, 11.60129177, 3.443892792, 2.642908469,
5.329881656, 2.303688396, 2.681312552, 2.12796449, 2.773085833,
4.189449094, 3.521328188, 1.761418094, 2.455309406, 2.526749219,
10.27017188, 11.70942021, 6.537176688, 3.665906281, 4.212212875,
7.625210531, 10.74009115, 10.74009115, 10.58339073, 11.77831083,
2.604995813, 4.744413865, 7.29975851, 1.740470719, 1.112195677,
2.604728, 2.58798274, 1.059064521, 4.349711208, 2.392650167,
2.699035417, 2.153652521, 3.151369396, 3.414949031, 2.581368219,
2.234642333, 2.392818135, 6.51472726, 2.648815969, 15.47915854,
3.258030083, 1.990451802, 2.6811855, 2.440177469, 2.925240396,
3.668138604, 2.917453344, 1.9656045, 2.452494323, 4.299348479,
4.765304604, 16.62252406, 12.88866406, 2.488524583, 1.916951229,
1.714486281, 2.816999552, 1.784181771, 2.585827844, 2.720170823,
2.186287625, 3.07640024, 4.327105385, 4.086370688, 4.592656531,
2.571516719, 6.396392573, 18.74246573, 14.24556208), ss = c(-7.707850005,
-15.40300834, -49.84338333, -50.96595763, -33.57927065, -29.26871379,
-31.13757476, -38.9446836, -18.60621918, -12.25557326, -17.3340105,
-49.04469485, -33.97249836, -24.13226024, -23.37858067, -24.07898472,
-32.68854786, -35.16417362, -30.17502297, -38.58802006, -13.44056998,
-45.62119153, -30.10387457, -21.92073966, -30.01274679, -30.10716134,
-29.60556014, -33.1849011, -24.07374895, -36.78247492, -34.72067685,
-41.96947502, -9.624331958, -10.03069504, -41.01141746, -35.72784007,
-50.94674135, -49.91973751, -51.05524609, -50.47122434, -46.90646667,
-42.70813537, -50.7377332, -51.01120184, -51.0932699, -35.37166589,
-39.92974313, -29.5446461, -8.1278036, -24.74676854, -36.47346677,
-40.92182994, -49.92750914, -49.02615356, -35.42230149, -38.96690541,
-35.20704603, -39.31404894, -31.98014625, -38.22213743, -25.34981719,
-14.02261648, -20.16701322, -48.09641042, -34.72517484, -50.17069654,
-40.66006187, -44.93973938, -43.63455705, -50.96538014, -49.74130308,
-34.21321834, -43.03926971, -26.14166307, -51.01781663, -46.38799194,
-51.07775476, -51.09319771, -44.82805756, -40.02547202, -15.16109778,
-23.15247117, -41.51283866, -39.06283772, -43.02607856, -38.197886,
-45.18138933, -50.9752189, -50.55407144, -49.39313584, -33.4766776,
-13.54483547, -12.00068998, -33.6073029, -20.23229774, -32.90792069,
-16.32554139, -25.90690728, -43.18838286, -51.0203703, -45.17489885,
-50.00289866, -29.7772429, -36.57372832, -51.02230524, -50.7863748,
-24.23635605, -44.15949002, -39.39035061, -36.81914971, -26.99636543,
-18.03405081, -49.68132933, -32.0432924, -21.71221224, -45.80810068,
-33.70033655, -41.01746977, -44.9545008, -40.45390925, -33.26664292,
-9.718327927, -9.277726352, -31.89539233, -50.26845505, -50.90332052,
-50.55203806, -49.13701041, -36.73852817, -35.43596888, -38.08838755,
-41.12237836, -40.41028312, -37.69615075, -35.55166964, -36.72707884,
-29.55487485, -46.23696728, -21.60602981, -47.63092247, -47.00620137,
-42.59296241, -50.71814475, -45.10917784, -51.02946189, -20.89401331,
-48.86575795, -36.89427487, -40.16853942, -51.00840255, -51.0075457,
-45.30865098, -46.05110903, -35.31902034, -44.80360176, -37.35104715,
-13.84902784, -39.74186369, -31.01123746, -35.21037218, -35.0202728,
-48.39866317, -32.74663729, -50.90494703, -41.74675073, -27.83560326,
-37.14191338, -39.24284429, -50.24699166, -41.91108934, -44.47568388,
-35.2452714, -34.49466485, -31.56238493, -33.86060467, -39.88969345,
-50.92874004, -50.61210368, -33.35654261, -49.73027655, -25.53924159,
-8.408177651, -44.11358958, -42.78740696, -38.98041905, -50.93700572,
-50.78977219, -47.03148495, -48.05189369, -36.41525546, -41.82258554,
-48.0012309, -50.65991657, -34.58154214, -35.59513453, -51.08074135,
-50.85366938, -51.08074135, -50.85366938, -50.69545917, -22.14701885,
-43.04649469, -40.17308802, -42.42595479, -39.31338521, -40.29414865,
-46.82535656, -38.09278958, -35.71546021, -38.48812479, -40.15711031,
-41.26210979, -25.71862146, -26.0133424, -26.7382999, -27.87618542,
-17.20437385, -50.21773375, -50.43229958, -51.10613073, -44.76030594,
-24.495235, -40.8543576, -49.56576271, -50.8176775, -33.32086031,
-34.70547198, -36.75163896, -50.58161188, -35.58172323, -50.78794125,
-40.18822771, -34.27604302, -48.19352396, -51.01194635, -43.13363927,
-45.60329094, -27.14570313, -39.71587979, -35.66745896, -49.72861292,
-50.98749646, -36.75274792, -51.06588781, -50.65578125, -50.87232552,
-51.08351406, -51.10034323, -30.78426354, -51.11306302, -19.71852042,
-18.5394999, -51.0472551, -51.0868051, -47.5098225, -17.50247563,
-17.50247563, -17.86539229, -16.16612115, -30.19224563, -28.90203208,
-48.59109542, -50.87648281, -47.88816083, -28.53676927, -48.9707774,
-50.57288479, -51.07964656, -37.37621177, -49.56755563, -50.76012125,
-47.20241073, -51.01347313, -50.82764219, -50.78897458, -50.83598677,
-51.11415594, -49.00892, -33.5060326, -28.38547938, -48.05074729,
-50.29370125, -50.83504219, -50.80333563, -51.03403729, -51.0421874,
-50.76831146, -50.87043604, -51.08487479, -51.01771458, -36.0702924,
-20.78084771, -49.44148479, -39.28489156, -50.94829448, -51.01100906,
-50.76106125, -50.92056417, -51.04772927, -37.12336448, -50.6384801,
-31.84211313, -49.48543917, -51.05363948, -28.35589769, -40.21823813,
-51.0574976, -39.4211176), dd = c(154.4236993, 149.5832755, 220.5376676,
188.1301303, 193.4423268, 180.786566, 147.6809975, 294.3175776,
517.5095247, 106.0196438, 126.7522827, 84.12371801, 153.8300366,
167.6862942, 111.8452798, 213.6434143, 270.8933346, 105.7571576,
138.8542046, 405.7345177, 222.8295022, 203.1856754, 201.2825818,
127.8993813, 159.2263148, 107.2677566, 192.7990438, 107.0794478,
211.9558545, 167.9804162, 194.1213087, 684.9904472, 220.9984063,
198.6784757, 310.0050436, 328.2581513, 138.2133496, 132.9782976,
289.1817849, 213.5229493, 205.9192931, 170.6115496, 200.483163,
147.652789, 327.5662511, 184.6250023, 210.3079779, 285.4338146,
119.6048186, 174.3630449, 240.233224, 97.64322396, 93.5913059,
70.31214681, 160.2304584, 147.7143808, 121.5668885, 95.49747258,
138.205053, 118.2084279, 226.6079498, 123.4014062, 197.9286116,
126.6151589, 128.7066092, 220.1513453, 171.8320615, 399.8383894,
379.5150089, 446.4220118, 66.78233993, 120.2137058, 165.0139027,
149.6845692, 158.637227, 179.8320709, 356.3473798, 331.2533515,
380.5121027, 595.6989688, 226.3574763, 153.7853848, 129.7965126,
204.6755039, 173.477482, 324.3927627, 218.8154401, 168.0964657,
250.3859192, 236.9220868, 396.2428049, 211.2501547, 209.6575701,
100.0337171, 114.0287522, 534.8363364, 252.8850567, 93.47141464,
169.2018281, 354.1812225, 167.0160495, 322.5169401, 699.927721,
106.0177501, 308.6366926, 1411.84738, 190.5941033, 256.7291835,
287.9890035, 317.9030093, 249.5487016, 94.82178213, 157.3068154,
117.7808006, 85.46573263, 392.3572701, 724.8147089, 87.31754945,
92.59793475, 363.9298959, 705.6552358, 224.452264, 189.3891441,
171.4922284, 182.3002062, 164.8533233, 171.5477266, 481.1937846,
321.1358114, 137.5508765, 109.432054, 144.223193, 165.7262492,
118.6953876, 199.4566326, 130.7380613, 134.8405831, 355.9356426,
105.5132727, 275.0446049, 136.8457579, 255.506731, 141.1784194,
249.5957908, 127.9098903, 65.54666729, 142.2750164, 186.4378832,
90.52911409, 240.1828537, 271.9479516, 221.9813631, 163.8951252,
862.7211025, 145.0432736, 934.4263336, 185.813134, 191.6960064,
115.1740602, 94.3482938, 151.5457861, 157.4328115, 181.8996531,
139.0691666, 410.1901284, 104.873104, 132.2095716, 197.3701322,
158.5931377, 408.8709478, 221.1149527, 92.28489547, 119.7748008,
109.1577013, 172.347586, 99.0082713, 308.0480454, 214.8575513,
93.23180651, 251.3186275, 439.633449, 157.6421674, 249.7593794,
161.3505953, 152.2448205, 239.5266898, 189.6886754, 210.1612637,
144.5761132, 261.4069935, 175.9787194, 200.7477829, 128.5085872,
115.4151402, 662.1582919, 248.6459146, 799.002826, 248.6459146,
799.002826, 141.8859927, 100.0343638, 116.5021167, 108.026373,
162.9137625, 134.8998615, 172.545199, 125.597699, 276.6302083,
533.4431354, 642.188624, 202.6657, 697.0803198, 545.1278615,
481.3199646, 423.8338427, 319.4693844, 365.5350729, 75.06200271,
208.3551844, 532.2892583, 115.6034833, 173.1313906, 134.4010906,
114.0157948, 133.5525719, 152.0830708, 126.9199573, 149.5574833,
183.7883156, 250.5106854, 271.3588146, 252.2147146, 249.1717438,
262.2825646, 1178.945583, 191.7794198, 775.945224, 137.0065938,
153.8710573, 278.8008677, 167.9884, 200.5136229, 114.6238458,
207.6997042, 311.252324, 262.7331438, 131.9810083, 184.0258792,
112.6623184, 770.1853177, 338.6306063, 177.741876, 274.4640479,
315.6091333, 531.3221333, 275.6941573, 275.6941573, 277.3068708,
279.2577229, 114.9657708, 201.0928177, 520.2239594, 129.8706885,
77.96273083, 108.235849, 185.6859594, 78.54580635, 325.8620802,
130.7865177, 196.174249, 160.3316583, 218.100225, 255.507301,
192.4301396, 166.4553438, 178.4062406, 488.3921406, 190.3591188,
760.6767625, 135.469474, 140.0819813, 197.7584458, 181.9313792,
217.9605552, 274.5590406, 218.4073167, 146.3560396, 182.9803677,
322.1222083, 356.5695281, 879.3790313, 392.8225521, 180.428799,
110.1808227, 128.1094563, 210.7529375, 132.8284542, 193.1165542,
203.6622229, 118.8509177, 228.4791198, 202.0587625, 296.5748396,
343.8937052, 102.326891, 377.2940917, 1403.520031, 823.6412771
), OutCome = c(1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L)), .Names = c("gg", "ss", "dd",
"OutCome"), class = "data.frame", row.names = c(1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L,
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L,
71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L,
84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L, 95L, 96L,
97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L,
108L, 109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L,
119L, 120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L,
130L, 131L, 132L, 133L, 134L, 135L, 136L, 137L, 138L, 139L, 140L,
141L, 142L, 143L, 144L, 145L, 146L, 147L, 148L, 149L, 150L, 151L,
152L, 153L, 154L, 155L, 156L, 157L, 158L, 159L, 160L, 161L, 162L,
163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L, 171L, 172L, 173L,
174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 182L, 183L, 184L,
185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 193L, 194L, 195L,
196L, 197L, 198L, 199L, 200L, 201L, 202L, 203L, 204L, 205L, 206L,
207L, 208L, 209L, 210L, 211L, 212L, 233L, 234L, 235L, 236L, 237L,
238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
260L, 261L, 262L, 263L, 264L, 265L, 266L, 267L, 268L, 269L, 270L,
271L, 272L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L,
282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L, 291L, 292L,
293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L, 302L, 303L,
304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L, 313L, 314L,
315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L, 324L, 325L,
326L, 349L, 350L))
Model code for likelihood estimates:
Simplelogit <- glm(OutCome ~ gg+ss+dd, data = Mydata, family = "binomial")
Model code using R2WinBUGS: (EDITED)
model1 ="
model
{
# likelihood
for(i in 1:N)
{
Y[i] ~ dbin(p[i],N)
logit(p[i])<- beta1[1]+beta1[2]*X[1]+beta1[3]*X[2]+beta1[4]*X[3]
}
#prior
beta1[1]~dnorm(1,1.0E-02)
beta1[2]~dnorm(1,1.0E-02)
beta1[3]~dnorm(1,1.0E-02)
beta1[4]~dnorm(1,1.0E-02)
}
"
writeLines(model1,con='Model.txt')
x1 <- unlist(Mydata$gg)
x2 <- unlist(Mydata$ss)
x3 <- unlist(Mydata$dd)
N=c(nrow(Mydata))
datalist <- list(N=N,Y=c(Mydata$OutCome),X=c(x1,x2,x3))
inits <- function() list(beta1=c((Simplelogit$coefficients[,1])))
MyPara <- c("beta1")
require(R2WinBUGS)
BayesianModel <- bugs(datalist,inits,MyPara,model.file='Model.txt',n.chains=1,n.iter=54000,n.burnin=4000,n.sim=50000,program=c('WinBUGS'),debug=FALSE,codaPkg=FALSE,save.history=TRUE,bugs.directory='C:/Program Files/WinBUGS14/',working.directory = getwd()) #,over.relax=TRUE
as.numeric(BayesianModel$summary[c(1:4)),1])
#results:
-48.63550 3.47384 -0.69866 0.09043
And then with Traditional method / without using bayesian method
Simplelogit <- glm(OutCome ~ gg+ss+dd, data = Mydata, family = "binomial")
c(as.matrix(Simplelogit$coefficients[c(1:4),1]))
# result is:
-20.71281 3.47408 -0.31233 -0.03906
Please suggest if I need to use different model of change the prior or the syntax...

I have not run the code, but I can spot two errors:
There is no Mydata$yy, so the vector is too short (only 616, should be 3*308). Should be x3<-unlist(Mydata$dd).
And you did not notice the error, because the indexing in the logit line is wrong. Should be something like
logit(p[i])<- beta1[1]+beta1[2]*X[i]+beta1[3]*X[i+2*N]+beta1[4]*X[i+3*N]

The jags version (I hate installing RWinBugs)
# Assuming your data have been saved in mydata.rdata
load("mydata.rdata")
library("rjags")
model1 ="
model
{
# likelihood
for(i in 1:N)
{
logit(p[i])<- beta0+betagg*gg[i]+betass*ss[i]+betadd*dd[i];
Y[i] ~ dbin(p[i],N); # Should be dbern probably
}
#prior
beta0~dnorm(1,1.0E-02);
betagg~dnorm(1,1.0E-02);
betass~dnorm(1,1.0E-02);
betadd~dnorm(1,1.0E-02);
}
"
writeLines(model1,con='Model.txt')
datalist <- with(Mydata, list(N=nrow(Mydata),Y=as.numeric(OutCome),gg=gg,ss=ss,dd=dd))
# A bit of cheating: initial values adapted after first run
inits <- list(beta0=-8,betagg=0.2,betass=0.05,betadd=0.002)
m <- jags.model("Model.txt",datalist,init=inits)
update(m, 1000)
x <- coda.samples(m, c("beta0","betagg","betass","betadd"), n.iter=10000)
plot(x) # Well, not prettty, but acceptable

Another solution using stan
load("mydata.rdata")
library(rstan)
library(ggmcmc)
library(coda)
model1 ="
data {
int<lower=0> N;
int<lower=0,upper=1> Y[N];
real gg[N];
real ss[N];
real dd[N];
}
parameters{
real beta0;
real betagg;
real betass;
real betadd;
}
model
{
#prior
beta0 ~ normal(-2,30);
betagg ~ normal(20,30);
betass ~ normal(-3,30);
betadd ~ normal(-10,40);
# likelihood
for(i in 1:N)
{
Y[i] ~ bernoulli(inv_logit(beta0+betagg*gg[i]+betass*ss[i]+betadd*dd[i]));
}
}
"
MyPar = scale(Mydata[,-4])
datalist <- list(N=nrow(Mydata),
Y=as.numeric(Mydata$OutCome),
gg=MyPar[,"gg"],ss=MyPar[,"ss"],dd=MyPar[,"dd"])
m <- stan(model_code=model1,iter=20000,data= datalist,n.chains=4)
ggmcmc(ggs(m))
print(m)

Related

Why I having problem on assigning data for NMDS in R?

I want learn Non-matric multidimensional scale, I have these data downloaded from https://cougrstats.wordpress.com/2019/12/11/non-metric-multidimensional-scaling-nmds-in-r/
data are
library(vegan)
dput(orders)
structure(list(Amphipoda = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 39L, 0L, 0L, 0L, 0L, 0L,
8L, 10L, 52L, 11L, 51L, 14L, 96L, 7L, 93L, 0L, 29L, 4L, 0L, 0L,
0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 36L, 10L, 5L, 15L, 14L, 3L, 11L,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 0L), Coleoptera = c(42L, 5L, 7L, 14L,
2L, 43L, 7L, 2L, 15L, 5L, 6L, 23L, 25L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 1L, 0L, 0L, 2L, 0L, 1L, 0L, 0L, 0L, 142L, 96L, 202L, 306L,
917L, 748L, 139L, 148L, 115L, 216L, 0L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 12L, 36L, 48L, 30L, 10L, 12L, 11L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 0L, 0L,
0L, 0L, 381L, 397L, 229L, 51L, 266L, 102L, 201L, 189L, 80L, 292L,
271L, 583L, 641L, 318L, 729L, 520L, 582L, 262L, 59L, 209L, 134L,
139L, 108L, 79L, 99L, 96L, 13L, 60L, 22L, 15L, 27L, 1L, 11L,
2L, 3L, 3L, 6L, 1L, 1L, 0L, 20L, 48L, 129L, 82L, 16L, 70L, 114L,
77L, 190L, 27L, 163L, 125L, 244L, 43L, 70L, 88L, 202L, 52L, 39L,
70L, 10L, 5L, 26L, 108L, 37L, 38L, 81L, 5L, 52L, 14L, 33L, 0L,
26L, 12L, 41L, 3L, 5L, 15L, 1L, 10L, 18L, 31L, 40L, 22L, 23L,
21L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 4L, 17L, 7L, 59L, 21L, 0L, 84L,
41L, 95L, 83L, 52L, 100L, 90L, 34L, 31L, 19L, 27L, 51L, 62L,
7L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 4L, 6L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 6L, 0L, 6L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L,
0L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 29L, 68L, 119L, 156L,
114L, 73L, 81L, 115L, 5L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 4L, 131L, 135L, 102L, 219L, 165L, 207L, 149L, 105L, 147L,
195L, 332L, 316L, 22L, 55L, 17L, 12L, 50L, 49L), Diptera = c(210L,
54L, 336L, 80L, 210L, 647L, 171L, 948L, 1495L, 751L, 877L, 912L,
1130L, 170L, 105L, 72L, 26L, 190L, 138L, 91L, 46L, 96L, 39L,
49L, 66L, 87L, 82L, 69L, 29L, 548L, 1240L, 810L, 999L, 521L,
784L, 504L, 800L, 1190L, 360L, 539L, 331L, 742L, 1041L, 742L,
154L, 787L, 479L, 411L, 1181L, 1350L, 1423L, 747L, 1827L, 1758L,
2L, 172L, 1L, 278L, 145L, 250L, 121L, 294L, 121L, 219L, 254L,
278L, 305L, 269L, 212L, 248L, 229L, 229L, 225L, 311L, 236L, 209L,
257L, 226L, 655L, 440L, 416L, 39L, 398L, 323L, 461L, 670L, 934L,
401L, 686L, 619L, 1043L, 1578L, 767L, 432L, 1754L, 1228L, 2164L,
585L, 1336L, 933L, 928L, 454L, 833L, 928L, 745L, 604L, 69L, 1052L,
1228L, 15L, 1835L, 1459L, 1408L, 170L, 1367L, 146L, 14L, 164L,
101L, 780L, 779L, 259L, 537L, 576L, 480L, 1076L, 577L, 119L,
58L, 853L, 529L, 724L, 1329L, 381L, 194L, 428L, 1240L, 1349L,
29L, 42L, 249L, 881L, 1122L, 456L, 837L, 162L, 751L, 281L, 421L,
36L, 803L, 553L, 562L, 1769L, 151L, 1019L, 34L, 158L, 736L, 472L,
254L, 666L, 853L, 1175L, 795L, 1627L, 1229L, 960L, 1659L, 1719L,
713L, 0L, 5L, 216L, 199L, 335L, 64L, 466L, 98L, 1385L, 1162L,
1545L, 1457L, 1215L, 614L, 1247L, 1697L, 620L, 895L, 1297L, 902L,
12L, 264L, 76L, 4L, 2L, 36L, 44L, 2L, 326L, 6L, 66L, 9L, 70L,
13L, 2L, 8L, 0L, 0L, 11L, 42L, 2L, 2L, 4L, 2L, 70L, 4L, 120L,
138L, 126L, 14L, 1L, 93L, 10L, 40L, 3L, 15L, 186L, 54L, 304L,
12L, 34L, 34L, 8L, 296L, 80L, 50L, 36L, 0L, 0L, 10L, 40L, 4L,
0L, 0L, 98L, 68L, 2L, 0L, 7L, 8L, 6L, 186L, 148L, 0L, 6L, 14L,
106L, 0L, 0L, 2L, 2L, 62L, 4L, 4L, 318L, 742L, 1099L, 298L, 553L,
867L, 716L, 556L, 91L, 154L, 89L, 16L, 114L, 21L, 49L, 130L,
46L, 94L, 58L, 349L, 967L, 828L, 857L, 765L, 847L, 459L, 725L,
731L, 409L, 432L, 805L, 565L, 967L, 953L, 1398L, 999L, 1081L,
1104L), Ephemeroptera = c(27L, 9L, 2L, 1L, 0L, 38L, 11L, 4L,
234L, 3L, 1L, 218L, 44L, 0L, 0L, 0L, 0L, 1L, 8L, 1L, 2L, 3L,
23L, 5L, 7L, 6L, 8L, 3L, 3L, 173L, 718L, 1264L, 825L, 464L, 478L,
456L, 816L, 481L, 811L, 652L, 146L, 686L, 563L, 372L, 190L, 419L,
158L, 63L, 244L, 141L, 267L, 236L, 100L, 99L, 0L, 0L, 0L, 10L,
3L, 1L, 0L, 3L, 0L, 14L, 9L, 0L, 5L, 5L, 1L, 29L, 21L, 0L, 45L,
29L, 1L, 14L, 9L, 1L, 134L, 300L, 15L, 46L, 170L, 272L, 100L,
325L, 146L, 436L, 544L, 27L, 9L, 40L, 41L, 103L, 63L, 84L, 103L,
629L, 133L, 584L, 74L, 25L, 191L, 489L, 212L, 304L, 118L, 78L,
76L, 0L, 20L, 238L, 373L, 4L, 69L, 3L, 0L, 0L, 121L, 266L, 273L,
104L, 209L, 356L, 203L, 461L, 53L, 60L, 5L, 130L, 25L, 135L,
163L, 56L, 81L, 884L, 358L, 432L, 32L, 98L, 1L, 26L, 18L, 10L,
11L, 1L, 68L, 3L, 9L, 0L, 32L, 5L, 41L, 106L, 85L, 240L, 27L,
15L, 113L, 613L, 786L, 572L, 394L, 306L, 84L, 0L, 76L, 11L, 11L,
261L, 192L, 40L, 35L, 30L, 266L, 34L, 7L, 293L, 41L, 167L, 253L,
103L, 93L, 233L, 362L, 408L, 173L, 440L, 145L, 162L, 11L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 8L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 467L, 430L, 177L, 291L, 392L,
231L, 82L, 361L, 29L, 0L, 31L, 0L, 16L, 0L, 3L, 17L, 8L, 15L,
27L, 45L, 111L, 82L, 133L, 163L, 96L, 85L, 76L, 72L, 121L, 127L,
69L, 109L, 443L, 221L, 114L, 421L, 183L, 156L), Hemiptera = c(27L,
2L, 1L, 1L, 0L, 3L, 1L, 0L, 10L, 6L, 0L, 8L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 3L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 1L, 2L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 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17L, 35L, 30L, 33L, 17L, 13L, 33L, 10L, 8L, 0L,
0L, 0L, 26L, 4L, 3L, 4L, 7L, 1L, 22L, 7L, 6L, 11L, 4L, 10L, 35L,
11L, 4L, 61L, 21L, 6L, 19L, 17L, 16L, 417L, 250L, 225L, 34L,
375L, 396L, 84L, 188L, 55L, 55L, 98L, 1145L, 713L, 342L, 2387L,
1404L, 908L, 685L, 44L, 692L, 691L, 101L, 35L, 14L, 296L, 145L,
44L, 274L, 62L, 31L, 49L, 1L, 135L, 24L, 219L, 2L, 60L, 6L, 0L,
0L, 120L, 31L, 126L, 68L, 62L, 182L, 153L, 27L, 61L, 31L, 51L,
153L, 185L, 190L, 174L, 372L, 170L, 81L, 180L, 218L, 3L, 22L,
5L, 161L, 23L, 10L, 54L, 1L, 22L, 11L, 17L, 0L, 19L, 12L, 74L,
13L, 29L, 64L, 1L, 1L, 1L, 193L, 561L, 97L, 112L, 241L, 19L,
9L, 14L, 16L, 5L, 5L, 5L, 71L, 22L, 75L, 239L, 44L, 16L, 346L,
31L, 169L, 353L, 120L, 117L, 187L, 361L, 210L, 28L, 181L, 53L,
19L, 3L, 0L, 0L, 0L, 0L, 3L, 0L, 10L, 26L, 4L, 0L, 18L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 1L, 20L, 0L, 0L, 0L, 22L, 11L, 8L, 10L, 4L,
0L, 0L, 5L, 2L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 8L,
4L, 13L, 0L, 0L, 2L, 0L, 4L, 0L, 1L, 0L, 0L, 0L, 4L, 0L, 0L,
0L, 0L, 0L, 24L, 0L, 0L, 0L, 2L, 0L, 1L, 0L, 0L, 2L, 0L, 0L,
107L, 230L, 52L, 14L, 46L, 44L, 29L, 85L, 7L, 0L, 11L, 0L, 2L,
0L, 0L, 5L, 3L, 4L, 0L, 7L, 90L, 97L, 166L, 243L, 160L, 62L,
122L, 72L, 297L, 139L, 102L, 145L, 40L, 19L, 16L, 12L, 3L, 7L
), Trombidiformes = c(6L, 1L, 59L, 1L, 4L, 16L, 3L, 1L, 3L, 2L,
2L, 49L, 12L, 0L, 0L, 0L, 1L, 2L, 3L, 8L, 1L, 8L, 10L, 11L, 0L,
15L, 1L, 5L, 8L, 31L, 31L, 59L, 48L, 111L, 155L, 153L, 116L,
102L, 210L, 4L, 3L, 2L, 2L, 4L, 0L, 6L, 5L, 52L, 215L, 76L, 107L,
103L, 116L, 100L, 0L, 0L, 0L, 0L, 0L, 2L, 3L, 0L, 0L, 1L, 0L,
2L, 1L, 0L, 2L, 1L, 0L, 4L, 1L, 5L, 10L, 3L, 0L, 1L, 5L, 19L,
7L, 5L, 13L, 7L, 8L, 2L, 2L, 6L, 0L, 1L, 0L, 0L, 0L, 3L, 1L,
2L, 0L, 0L, 0L, 50L, 21L, 22L, 41L, 26L, 4L, 70L, 2L, 8L, 16L,
0L, 48L, 35L, 6L, 3L, 16L, 6L, 2L, 0L, 7L, 8L, 43L, 17L, 9L,
26L, 32L, 24L, 52L, 16L, 39L, 34L, 26L, 29L, 6L, 51L, 53L, 75L,
198L, 93L, 49L, 29L, 37L, 59L, 92L, 45L, 66L, 4L, 38L, 33L, 36L,
2L, 116L, 31L, 70L, 9L, 32L, 8L, 2L, 8L, 8L, 80L, 92L, 51L, 187L,
75L, 130L, 143L, 128L, 83L, 80L, 67L, 76L, 0L, 2L, 1L, 47L, 14L,
0L, 105L, 14L, 52L, 50L, 54L, 20L, 54L, 48L, 34L, 6L, 47L, 23L,
10L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 16L, 2L, 8L, 0L, 13L, 8L, 0L, 0L, 29L, 12L, 2L, 2L, 3L, 1L,
0L, 44L, 23L, 1L, 12L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 0L, 0L, 0L, 8L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L,
36L, 0L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L,
23L, 93L, 26L, 257L, 61L, 36L, 179L, 56L, 20L, 0L, 61L, 0L, 66L,
0L, 3L, 0L, 3L, 0L, 0L, 27L, 66L, 76L, 113L, 44L, 30L, 15L, 16L,
18L, 23L, 39L, 95L, 41L, 37L, 28L, 45L, 22L, 21L, 9L), Tubificida = c(20L,
0L, 13L, 1L, 34L, 77L, 11L, 379L, 147L, 184L, 267L, 197L, 313L,
2L, 1L, 10L, 1L, 2L, 9L, 15L, 25L, 9L, 4L, 7L, 21L, 20L, 4L,
30L, 3L, 17L, 11L, 15L, 0L, 2L, 8L, 139L, 133L, 292L, 158L, 94L,
13L, 42L, 73L, 53L, 81L, 79L, 277L, 15L, 2L, 14L, 42L, 54L, 41L,
59L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 15L, 112L, 0L, 7L, 18L,
1L, 15L, 18L, 4L, 5L, 67L, 0L, 9L, 41L, 4L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 0L, 0L, 0L, 0L, 2L, 34L, 5L, 33L, 5L, 22L, 25L, 48L,
0L, 3L, 16L, 9L, 0L, 152L, 10L, 1L, 13L, 4L, 0L, 25L, 1L, 65L,
3L, 10L, 18L, 11L, 33L, 13L, 38L, 0L, 29L, 36L, 21L, 10L, 11L,
16L, 16L, 73L, 2L, 0L, 538L, 773L, 88L, 347L, 58L, 54L, 0L, 2L,
14L, 0L, 0L, 5L, 23L, 12L, 60L, 10L, 13L, 21L, 14L, 8L, 2L, 29L,
4L, 5L, 23L, 11L, 21L, 41L, 196L, 128L, 0L, 0L, 0L, 0L, 0L, 9L,
5L, 3L, 67L, 19L, 3L, 7L, 0L, 0L, 3L, 3L, 4L, 0L, 14L, 3L, 77L,
188L, 73L, 78L, 163L, 13L, 73L, 13L, 20L, 61L, 33L, 2L, 0L, 0L,
0L, 0L, 0L, 12L, 410L, 124L, 80L, 0L, 42L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 116L, 0L, 0L, 1L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 14L,
8L, 2L, 0L, 0L, 0L, 0L, 0L, 6L, 2L, 3L, 96L, 0L, 10L, 148L, 12L,
17L, 2L, 0L, 0L, 18L, 0L, 0L, 0L, 2L, 2L, 0L, 2L, 3L, 2L, 0L,
34L, 16L, 0L, 24L, 0L, 82L, 0L, 0L, 0L, 0L, 18L, 0L, 0L, 6L,
18L, 39L, 41L, 16L, 27L, 31L, 27L, 44L, 0L, 136L, 5L, 32L, 0L,
256L, 164L, 305L, 224L, 244L, 160L, 63L, 63L, 68L, 37L, 209L,
52L, 47L, 51L, 81L, 12L, 45L, 49L, 1L, 28L, 0L, 0L, 22L, 1L),
aquaticSiteType = c("stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "lake", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "lake", "lake", "lake", "lake", "lake", "lake",
"lake", "lake", "lake", "lake", "lake", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream", "stream",
"stream", "stream", "stream", "stream", "stream")), class = "data.frame", row.names = c(NA,
-303L))
I run the NMDS code using the code below
set.seed(1)
metaMDS(comm = orders[,1:8], # Define the community data
distance = "bray", # Specify a bray-curtis distance
try = 100) # Number of iterations
It worked properly, when i assign it to another object, there is no solution
set.seed(1)
nmds = metaMDS(comm = orders[,1:8], # Define the community data
distance = "bray", # Specify a bray-curtis distance
try = 100) # Number of iterations
Best solution was not repeated -- monoMDS stopping criteria:
2: no. of iterations >= maxit
16: stress ratio > sratmax
2: scale factor of the gradient < sfgrmin
why is this happenning? i also tried with several seeds and without seeds also, but the problem is the same.
and then when i tried the score value to data frame
data_scores = as.data.frame(scores(nmds))
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 303, 8
Why I am getting this error?
metaMDS worked OK and gave you results. No problem.
Your problem was that you assumed that scores gives you a simple matrix-like object that can be converted to a data.frame. It does not, but it gives you a list of sample scores and species scores:
> str(scores(nmds))
List of 2
$ sites : num [1:303, 1:2] -0.051 0.426 0.129 0.385 0.127 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:303] "1" "2" "3" "4" ...
.. ..$ : chr [1:2] "NMDS1" "NMDS2"
$ species: num [1:8, 1:2] -1.178 0.351 0.269 0.339 -1.177 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:8] "Amphipoda" "Coleoptera" "Diptera" "Ephemeroptera" ...
.. ..$ : chr [1:2] "NMDS1" "NMDS2"
You have two alternatives:
Request only one kind of scores. For instance this gives you only sample scores.
> str(scores(nmds, display="sites"))
num [1:303, 1:2] -0.051 0.426 0.129 0.385 0.127 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:303] "1" "2" "3" "4" ...
..$ : chr [1:2] "NMDS1" "NMDS2"
Request "tidy" scores that pack species and site scores in one data frame and add a variable that identifies the type of scores:
> str(scores(nmds, tidy=TRUE))
'data.frame': 311 obs. of 4 variables:
$ NMDS1: num -0.051 0.426 0.129 0.385 0.127 ...
$ NMDS2: num -0.2518 -0.1687 -0.0795 0.069 0.2453 ...
$ score: chr "sites" "sites" "sites" "sites" ...
$ label: chr "1" "2" "3" "4" ...
There are two issues here. The first is the notice that "best solution was not repeated" and the second is the error trying to coerce the scores to a data.frame.
As noted in the answer by Jari Oksanen, the latter error is a consequence of trying to force an object to be a data.frame when it has dimensions that do not allow it to be coerced to a data.frame.
However, the much bigger issue is that you should not trust the scores in the first place because the model has not converged. From the metaMDS documentation:
Non-linear optimization is a hard task, and the best possible solution
(“global optimum”) may not be found from a random starting
configuration. Most software solve this by starting from the result of
metric scaling (cmdscale). This will probably give a good result, but
not necessarily the “global optimum”. Vegan does the same, but metaMDS
tries to verify or improve this first solution (“try 0”) using several
random starts and seeing if the result can be repeated or improved and
the improved solution repeated. If this does not succeed, you get a
message that the result could not be repeated. However, the result
will be at least as good as the usual standard strategy of starting
from metric scaling or it may be improved. You may not need to do
anything after such a message, but you can be satisfied with the
result. If you want to be sure that you probably have a “global
optimum” you may try the following instructions.
That different starting points (a) produce a solution but (b) the solution differs based on initial starts means the optimizer has found a local solution that can be arbitrarily far from the global solution. In other words, the results you obtain can be arbitrarily wrong and shouldn't be trusted. In other software, this would throw and not provide you the results because it wouldn't trust you not to use the known-to-be-unreliable results.
For some reason, the authors of this don't do that but you should not let their decision to make this a warning instead of an error be a reason to ignore the fundamental issues with the results.
You can follow the steps discussed in the documentation linked above to address this.

Need help in ggplot doing multiple factor barplot with error bar

I have a data for which I like to plot a barplot with error bar.
My data is as below:
dput(level6.top35)
structure(list(patient = structure(c(3L, 3L, 3L, 1L, 1L, 1L,
4L, 4L, 4L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L,
9L, 10L, 10L, 10L, 11L, 11L, 11L, 2L, 2L, 2L), .Label = c("P1",
"P10", "P11", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9"), class = "factor"),
visit = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("V1", "V2", "V3"), class = "factor"),
Bacteroides = c(11095L, 9981L, 2426L, 6107L, 14806L, 785L,
34127L, 27590L, 4699L, 42464L, 32146L, 321L, 611L, 402L,
455L, 5597L, 475L, 2842L, 481L, 11508L, 2125L, 842L, 960L,
3215L, 12118L, 10526L, 517L, 67434L, 82449L, 419L, 25643L,
4455L), Clostridium = c(53693L, 51961L, 89862L, 1122L, 3987L,
3095L, 3083L, 372L, 1628L, 4L, 13L, 11346L, 47803L, 10120L,
939L, 2280L, 11355L, 18642L, 4358L, 53L, 47L, 22L, 44L, 1897L,
9328L, 4394L, 4886L, 7025L, 175L, 1522L, 14776L, 30405L),
Turicibacter = c(25L, 0L, 10L, 9L, 0L, 0L, 4428L, 382L, 827L,
18L, 0L, 370L, 106L, 2180L, 5789L, 422L, 4355L, 1585L, 21205L,
567L, 131028L, 32389L, 14953L, 50692L, 3666L, 9811L, 1694L,
123L, 103L, 475L, 1038L, 0L), Haemophilus = c(31L, 27L, 13L,
2693L, 530L, 908L, 103L, 217L, 22L, 21743L, 7413L, 40763L,
1303L, 40182L, 52L, 67L, 18501L, 7547L, 28384L, 756L, 19L,
43928L, 19930L, 433L, 70L, 952L, 16796L, 4415L, 88L, 0L,
4607L, 507L), Streptococcus = c(303L, 160L, 168L, 1205L,
8360L, 12927L, 8380L, 1341L, 306L, 865L, 3490L, 137L, 428L,
427L, 5215L, 861L, 11635L, 15341L, 7306L, 12963L, 192L, 1646L,
2311L, 645L, 9880L, 9314L, 9091L, 6649L, 7283L, 26253L, 21089L,
39463L), Intestinibacter = c(14L, 16L, 0L, 17L, 11L, 32L,
4991L, 17L, 76L, 13L, 0L, 8182L, 14976L, 8062L, 7529L, 917L,
6612L, 14714L, 23287L, 26558L, 32L, 10L, 46L, 18307L, 7201L,
11970L, 6983L, 2963L, 2172L, 1812L, 0L, 1115L), Ruminococcus = c(3237L,
7853L, 95L, 4209L, 380L, 105L, 4141L, 18344L, 16L, 4000L,
2374L, 17L, 690L, 33L, 3393L, 7285L, 259L, 11344L, 69L, 5175L,
46L, 13L, 64L, 156L, 8923L, 19573L, 60L, 6626L, 7614L, 188L,
998L, 109L), Veillonella = c(630L, 318L, 512L, 302L, 1739L,
420L, 779L, 495L, 11L, 538L, 2857L, 338L, 466L, 1777L, 37L,
423L, 2597L, 1330L, 457L, 1720L, 239L, 4659L, 1864L, 188L,
1062L, 4061L, 279L, 723L, 291L, 11009L, 14337L, 7129L), Sutterella = c(65L,
46L, 25L, 27L, 0L, 62L, 20L, 16L, 38L, 8499L, 7987L, 35L,
78L, 37L, 21L, 84L, 12L, 238L, 39L, 1746L, 26L, 31L, 65L,
383L, 11200L, 565L, 50L, 40L, 17L, 14L, 1407L, 353L), Epulopiscium = c(0L,
0L, 0L, 0L, 0L, 12L, 0L, 0L, 0L, 0L, 0L, 14447L, 8925L, 7733L,
0L, 6L, 20L, 823L, 158L, 84L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L), Faecalibacterium = c(184L, 203L, 154L,
113L, 92L, 135L, 111L, 144L, 102L, 1297L, 21410L, 132L, 185L,
138L, 127L, 151L, 135L, 204L, 173L, 128L, 203L, 148L, 191L,
177L, 169L, 171L, 193L, 150L, 133L, 169L, 4444L, 404L), Bifidobacterium = c(2288L,
8161L, 63L, 605L, 169L, 95L, 46L, 71L, 72L, 876L, 2540L,
60L, 467L, 73L, 578L, 1537L, 79L, 5413L, 73L, 543L, 127L,
86L, 144L, 76L, 775L, 71L, 84L, 80L, 64L, 47L, 49L, 70L),
Tyzzerella = c(18L, 0L, 0L, 559L, 0L, 0L, 1408L, 1666L, 0L,
86L, 373L, 0L, 373L, 0L, 439L, 235L, 107L, 21L, 0L, 0L, 0L,
0L, 25L, 134L, 4126L, 12034L, 4L, 0L, 0L, 0L, 47L, 0L), Lactobacillus = c(0L,
0L, 0L, 0L, 0L, 14L, 0L, 0L, 0L, 0L, 0L, 5L, 11L, 4L, 39L,
25L, 321L, 56L, 0L, 36L, 0L, 5L, 0L, 5L, 848L, 63L, 0L, 138L,
538L, 3801L, 122L, 4373L), Serratia = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 128L, 69L, 0L, 0L, 0L, 0L, 0L, 226L, 0L,
0L, 0L, 0L, 0L, 7828L, 0L, 0L, 0L, 0L, 70L, 0L, 0L, 0L, 0L
), Rothia = c(0L, 0L, 11L, 6L, 16L, 24L, 0L, 0L, 5L, 0L,
0L, 0L, 0L, 10L, 0L, 9L, 11L, 140L, 267L, 175L, 0L, 190L,
4617L, 0L, 0L, 0L, 1362L, 19L, 47L, 518L, 21L, 34L), Anaerosporobacter = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 256L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 31L, 3239L, 3546L, 0L, 0L,
0L, 0L, 0L, 0L), Erysipelatoclostridium = c(19L, 0L, 7L,
184L, 194L, 23L, 320L, 129L, 7L, 1151L, 436L, 20L, 52L, 0L,
862L, 1365L, 88L, 20L, 0L, 263L, 9L, 6L, 71L, 46L, 1175L,
217L, 0L, 190L, 98L, 0L, 72L, 26L), Paeniclostridium = c(0L,
0L, 0L, 0L, 303L, 0L, 0L, 0L, 0L, 0L, 0L, 129L, 9L, 339L,
0L, 0L, 66L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5167L, 228L,
221L, 0L, 0L, 0L), Blautia = c(526L, 132L, 101L, 87L, 19L,
97L, 93L, 118L, 71L, 204L, 1356L, 70L, 105L, 84L, 71L, 144L,
88L, 649L, 136L, 627L, 156L, 88L, 142L, 83L, 139L, 138L,
134L, 122L, 81L, 99L, 98L, 125L), Anaerostipes = c(27L, 38L,
25L, 20L, 10L, 24L, 17L, 21L, 0L, 709L, 4603L, 23L, 24L,
20L, 0L, 178L, 18L, 30L, 42L, 24L, 29L, 16L, 37L, 23L, 57L,
39L, 29L, 29L, 16L, 26L, 25L, 27L), Enterococcus = c(31L,
32L, 26L, 126L, 68L, 2498L, 70L, 31L, 26L, 0L, 15L, 59L,
57L, 23L, 395L, 758L, 133L, 0L, 0L, 27L, 50L, 36L, 56L, 21L,
39L, 0L, 422L, 159L, 20L, 24L, 96L, 95L), Citrobacter = c(0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 3583L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 37L, 0L, 0L, 0L, 1088L, 0L, 0L, 0L, 0L, 0L, 144L,
0L, 0L, 0L, 0L), Prevotella = c(155L, 168L, 87L, 153L, 95L,
121L, 100L, 125L, 152L, 307L, 124L, 100L, 84L, 117L, 91L,
168L, 128L, 137L, 130L, 98L, 139L, 114L, 252L, 84L, 159L,
106L, 140L, 201L, 114L, 126L, 160L, 125L), Roseburia = c(621L,
19L, 0L, 0L, 0L, 0L, 0L, 18L, 0L, 46L, 32L, 17L, 13L, 0L,
0L, 36L, 17L, 160L, 0L, 109L, 18L, 15L, 22L, 77L, 1505L,
559L, 38L, 26L, 12L, 22L, 849L, 90L), Parabacteroides = c(60L,
18L, 12L, 114L, 9L, 49L, 349L, 593L, 60L, 158L, 162L, 46L,
53L, 42L, 17L, 33L, 29L, 197L, 49L, 458L, 42L, 45L, 83L,
271L, 479L, 429L, 51L, 63L, 76L, 0L, 85L, 47L), Neisseria = c(0L,
0L, 0L, 77L, 0L, 0L, 0L, 12L, 0L, 9L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 454L, 2L, 0L, 0L, 771L, 2662L, 4L, 0L, 11L, 10L,
0L, 0L, 0L, 0L, 0L), Actinobacillus = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 2670L, 149L, 0L, 0L, 0L, 0L, 0L, 0L, 130L,
0L, 0L, 0L, 0L, 0L, 10L, 0L, 60L, 0L, 0L, 0L, 0L, 0L, 0L),
Granulicatella = c(59L, 27L, 22L, 18L, 22L, 14L, 19L, 36L,
76L, 37L, 0L, 0L, 0L, 61L, 60L, 24L, 93L, 90L, 457L, 60L,
52L, 42L, 215L, 0L, 40L, 45L, 665L, 14L, 27L, 260L, 34L,
46L), Actinomyces = c(52L, 27L, 12L, 8L, 8L, 16L, 36L, 16L,
89L, 12L, 23L, 13L, 0L, 53L, 18L, 0L, 30L, 112L, 624L, 89L,
12L, 45L, 116L, 11L, 58L, 12L, 587L, 65L, 47L, 135L, 18L,
35L), Lachnoclostridium = c(21L, 19L, 17L, 37L, 0L, 0L, 211L,
337L, 13L, 361L, 184L, 0L, 12L, 12L, 19L, 91L, 0L, 66L, 0L,
228L, 44L, 9L, 0L, 77L, 293L, 257L, 0L, 0L, 0L, 0L, 28L,
20L), Pediococcus = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2101L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 9L, 0L, 0L, 0L, 0L, 0L, 0L), Fusobacterium = c(84L,
51L, 55L, 551L, 12L, 19L, 22L, 54L, 23L, 41L, 40L, 21L, 17L,
14L, 14L, 78L, 18L, 228L, 88L, 35L, 75L, 43L, 162L, 24L,
39L, 25L, 90L, 15L, 21L, 56L, 24L, 36L), Alistipes = c(68L,
81L, 24L, 69L, 35L, 66L, 40L, 57L, 60L, 86L, 72L, 48L, 47L,
60L, 51L, 92L, 48L, 67L, 72L, 36L, 40L, 65L, 137L, 21L, 31L,
65L, 84L, 100L, 93L, 42L, 81L, 41L), Eubacterium = c(0L,
7L, 0L, 0L, 0L, 0L, 0L, 0L, 8L, 12L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L)), .Names = c("patient", "visit", "Bacteroides", "Clostridium",
"Turicibacter", "Haemophilus", "Streptococcus", "Intestinibacter",
"Ruminococcus", "Veillonella", "Sutterella", "Epulopiscium",
"Faecalibacterium", "Bifidobacterium", "Tyzzerella", "Lactobacillus",
"Serratia", "Rothia", "Anaerosporobacter", "Erysipelatoclostridium",
"Paeniclostridium", "Blautia", "Anaerostipes", "Enterococcus",
"Citrobacter", "Prevotella", "Roseburia", "Parabacteroides",
"Neisseria", "Actinobacillus", "Granulicatella", "Actinomyces",
"Lachnoclostridium", "Pediococcus", "Fusobacterium", "Alistipes",
"Eubacterium"), class = "data.frame", row.names = c("AA_001_20-4-16",
"AA_001-V2", "AA_001_19-5-16", "AA_ISS-01-V1", "AA_ISS-01-V2",
"AA_ISS-01-V3", "AA_ISS-02-V1", "AA_ISS-02-V2", "AA_ISS-02-V3",
"AA_ISS-03-V1", "AA_ISS-03-V2", "AA_ISS-04-V1", "AA_ISS-04-V2",
"AA_ISS-04-V3", "AA_ISS-05-V1", "AA_ISS-05-V2", "AA_ISS-05-V3",
"AA_ISS-06-V1", "AA_ISS-06-V2", "AA_ISS-06-V3", "AA_ISS-07-V1",
"AA_ISS-07-V2", "AA_ISS-07-V3", "AA_ISS-08-V1", "AA_ISS-08-V2",
"AA_ISS-08-V3", "AA_ISS-09-V1", "AA_ISS-09-V2", "AA_ISS-09-V3",
"AA_ISS-10-V1", "AA_ISS-10-V2", "AA_ISS-10-V3"))
So far I have tried to reshape the data and few tries to plot them properly. But in vain.
library(reshape2)
df1<-melt(level6.top35, id.vars = c("patient","visit"))
ggplot(data=df1,aes(x=variable,y=value, fill=visit))+geom_bar(position="dodge",stat="identity")
+geom_errorbar( aes(x=variable, ymin=value-sd, ymax=value+sd), width=0.4, colour="orange", alpha=0.9, size=1.3)
I have managed to do the plot but not the errorbar. Ideally I like to have a barplot with the error bar.
You need to summarise the data and then add the error bars, e.g. like this:
df1 <- melt(level6.top35, id.vars = c("patient","visit"))
df1 %>% group_by(visit, variable) %>%
summarise(SD = sd(value), value = mean(value)) %>% ungroup() %>%
ggplot(., aes(x=variable, y=value, fill = visit)) +
geom_bar(stat="identity", position = "dodge") +
geom_errorbar(aes(ymin= value - SD, ymax = value + SD, width=0.2),
position=position_dodge(width=0.90)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
labs(x="Species")
It is still up to you to decide whether you want to just plot the positive bars, limit the y axis to avoid negative values, etc..

Subset, or reclassify, spatial data in R

I have the following data that indicates how many points occur within each rectangle (spatial data generated with quadratcount() from the spatstat package):
structure(c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 14L, 2L, 62L, 164L, 0L, 34L, 16L, 219L,
16L, 5L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L,
5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 106L, 334L, 359L, 587L,
375L, 381L, 66L, 40L, 106L, 0L, 4L, 4L, 2L, 3L, 0L, 0L, 1L, 6L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 5L, 124L, 47L, 60L, 4L, 0L, 0L, 0L, 0L, 105L, 117L, 0L,
0L, 0L, 123L, 587L, 341L, 338L, 222L, 231L, 46L, 0L, 27L, 64L,
0L, 15L, 0L, 1L, 0L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 140L, 282L, 395L, 112L,
184L, 194L, 244L, 0L, 0L, 14L, 136L, 217L, 11L, 20L, 40L, 114L,
597L, 227L, 146L, 55L, 7L, 12L, 5L, 0L, 6L, 16L, 252L, 201L,
9L, 5L, 0L, 55L, 0L, 17L, 9L, 20L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 98L, 480L, 270L, 0L, 109L, 298L,
385L, 9L, 0L, 0L, 8L, 196L, 247L, 86L, 184L, 422L, 628L, 357L,
0L, 0L, 0L, 9L, 0L, 0L, 11L, 0L, 255L, 206L, 88L, 0L, 41L, 224L,
4L, 0L, 106L, 2L, 0L, 2L, 1L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 7L, 21L, 8L, 3L, 0L, 0L, 85L, 0L, 0L, 0L, 0L, 42L,
319L, 141L, 351L, 421L, 810L, 331L, 0L, 0L, 0L, 216L, 67L, 18L,
0L, 96L, 313L, 2L, 41L, 17L, 17L, 45L, 0L, 0L, 0L, 2L, 2L, 0L,
0L, 68L, 353L, 122L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 65L,
141L, 72L, 32L, 49L, 34L, 0L, 6L, 5L, 0L, 82L, 309L, 343L, 0L,
253L, 473L, 22L, 0L, 0L, 0L, 0L, 187L, 163L, 2L, 270L, 4L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 9L, 7L, 0L, 0L, 38L, 10L, 151L, 117L,
25L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 28L, 14L, 416L, 29L, 164L, 93L,
120L, 202L, 203L, 6L, 0L, 0L, 210L, 538L, 178L, 183L, 416L, 51L,
0L, 0L, 0L, 0L, 98L, 152L, 115L, 289L, 18L, 81L, 3L, 0L, 0L,
0L, 35L, 7L, 0L, 2L, 29L, 0L, 0L, 14L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 40L, 0L, 0L, 107L, 312L, 322L, 192L, 361L, 694L,
555L, 17L, 0L, 0L, 12L, 319L, 131L, 920L, 394L, 48L, 230L, 0L,
0L, 0L, 0L, 19L, 154L, 146L, 9L, 8L, 32L, 20L, 4L, 48L, 0L, 0L,
16L, 0L, 345L, 68L, 0L, 0L, 0L, 12L, 2L, 0L, 0L, 0L, 0L, 15L,
0L, 5L, 0L, 0L, 0L, 208L, 131L, 332L, 419L, 117L, 448L, 144L,
0L, 75L, 83L, 53L, 360L, 8L, 29L, 685L, 749L, 134L, 8L, 0L, 33L,
0L, 0L, 86L, 38L, 7L, 0L, 170L, 202L, 118L, 94L, 238L, 326L,
115L, 244L, 62L, 0L, 0L, 5L, 0L, 1L, 0L, 7L, 0L, 1L, 0L, 0L,
26L, 6L, 0L, 0L, 5L, 183L, 396L, 45L, 0L, 80L, 0L, 0L, 172L,
629L, 143L, 418L, 51L, 36L, 603L, 834L, 549L, 91L, 156L, 12L,
0L, 0L, 0L, 0L, 5L, 129L, 17L, 108L, 299L, 161L, 177L, 30L, 0L,
64L, 57L, 0L, 0L, 0L, 0L, 0L, 0L, 59L, 5L, 62L, 111L, 36L, 2L,
24L, 0L, 0L, 98L, 26L, 140L, 0L, 12L, 0L, 24L, 0L, 53L, 199L,
406L, 413L, 107L, 678L, 1066L, 960L, 575L, 391L, 622L, 372L,
76L, 0L, 0L, 0L, 0L, 0L, 208L, 171L, 16L, 17L, 22L, 0L, 15L,
0L, 0L, 4L, 2L, 0L, 11L, 0L, 17L, 45L, 0L, 0L, 67L, 0L, 0L, 66L,
9L, 0L, 0L, 0L, 9L, 0L, 0L, 50L, 110L, 33L, 0L, 2L, 247L, 647L,
375L, 696L, 466L, 1367L, 1066L, 442L, 664L, 636L, 467L, 32L,
0L, 0L, 0L, 17L, 10L, 30L, 55L, 71L, 177L, 149L, 44L, 5L, 0L,
3L, 2L, 2L, 2L, 7L, 0L, 135L, 0L, 46L, 47L, 240L, 228L, 20L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 598L, 379L, 0L, 0L, 79L, 696L,
510L, 83L, 203L, 351L, 1030L, 900L, 646L, 610L, 635L, 347L, 18L,
1L, 0L, 59L, 0L, 0L, 0L, 0L, 9L, 26L, 31L, 11L, 2L, 0L, 3L, 0L,
0L, 0L, 0L, 0L, 0L, 234L, 8L, 147L, 51L, 0L, 0L, 0L, 0L, 0L,
7L, 66L, 0L, 0L, 376L, 953L, 366L, 236L, 217L, 228L, 518L, 509L,
112L, 140L, 437L, 562L, 354L, 763L, 697L, 408L, 310L, 54L, 28L,
0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 10L, 0L, 0L,
0L, 0L, 25L, 69L, 171L, 315L, 12L, 4L, 0L, 0L, 7L, 0L, 0L, 0L,
0L, 35L, 406L, 394L, 802L, 469L, 852L, 6L, 371L, 451L, 742L,
245L, 728L, 1115L, 544L, 681L, 901L, 645L, 457L, 517L, 161L,
0L, 0L, 0L, 0L, 4L, 0L, 77L, 0L, 0L, 0L, 32L, 0L, 0L, 61L, 0L,
0L, 0L, 18L, 235L, 280L, 35L, 0L, 42L, 0L, 4L, 12L, 0L, 3L, 12L,
12L, 70L, 215L, 53L, 402L, 544L, 0L, 55L, 105L, 543L, 875L, 687L,
459L, 1110L, 1732L, 1411L, 725L, 771L, 587L, 829L, 69L, 0L, 0L,
23L, 334L, 387L, 416L, 355L, 367L, 160L, 0L, 0L, 4L, 0L, 0L,
0L, 0L, 0L, 19L, 326L, 69L, 0L, 9L, 165L, 43L, 110L, 44L, 67L,
0L, 37L, 0L, 0L, 310L, 0L, 83L, 408L, 183L, 8L, 169L, 560L, 625L,
916L, 345L, 758L, 1118L, 1258L, 1133L, 819L, 922L, 226L, 0L,
43L, 86L, 153L, 188L, 22L, 93L, 411L, 434L, 255L, 238L, 278L,
282L, 161L, 1L, 0L, 0L, 0L, 17L, 10L, 0L, 0L, 49L, 21L, 97L,
531L, 436L, 271L, 28L, 1L, 12L, 0L, 0L, 2L, 317L, 667L, 396L,
9L, 3L, 719L, 1070L, 768L, 1496L, 938L, 1135L, 1432L, 367L, 703L,
824L, 557L, 517L, 426L, 476L, 530L, 517L, 184L, 759L, 124L, 178L,
477L, 499L, 155L, 197L, 257L, 35L, 8L, 77L, 21L, 1L, 0L, 0L,
0L, 0L, 0L, 1L, 248L, 480L, 26L, 19L, 128L, 9L, 220L, 364L, 183L,
490L, 669L, 656L, 447L, 589L, 682L, 893L, 693L, 861L, 1117L,
1142L, 1403L, 1256L, 1185L, 680L, 232L, 268L, 520L, 586L, 325L,
520L, 278L, 648L, 10L, 317L, 409L, 290L, 234L, 50L, 166L, 50L,
22L, 140L, 192L, 75L, 0L, 0L, 0L, 0L, 0L, 0L, 65L, 10L, 43L,
0L, 6L, 138L, 645L, 632L, 372L, 739L, 720L, 552L, 256L, 637L,
705L, 896L, 981L, 711L, 820L, 1486L, 1377L, 1028L, 106L, 556L,
0L, 0L, 0L, 22L, 124L, 344L, 456L, 197L, 125L, 214L, 348L, 58L,
46L, 8L, 9L, 144L, 546L, 259L, 177L, 20L, 0L, 10L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 6L, 0L, 60L, 679L, 438L, 707L, 1002L, 846L, 832L,
834L, 262L, 561L, 499L, 768L, 877L, 1185L, 1597L, 1041L, 876L,
680L, 186L, 0L, 0L, 0L, 0L, 0L, 18L, 282L, 312L, 384L, 391L,
61L, 244L, 213L, 129L, 9L, 0L, 111L, 333L, 181L, 0L, 0L, 0L,
0L, 0L, 31L, 0L, 0L, 0L, 0L, 18L, 0L, 153L, 475L, 633L, 197L,
561L, 555L, 529L, 691L, 456L, 40L, 71L, 286L, 660L, 624L, 438L,
673L, 524L, 1055L, 957L, 492L, 77L, 0L, 0L, 0L, 0L, 0L, 0L, 218L,
383L, 317L, 239L, 298L, 110L, 163L, 55L, 64L, 176L, 184L, 0L,
4L, 0L, 4L, 0L, 0L, 0L, 158L, 194L, 0L, 73L, 607L, 786L, 575L,
570L, 125L, 564L, 635L, 632L, 515L, 0L, 0L, 0L, 15L, 371L, 513L,
589L, 804L, 808L, 916L, 645L, 944L, 260L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 2L, 56L, 231L, 260L, 255L, 287L, 330L, 267L, 72L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 430L, 717L, 0L, 169L, 713L, 597L,
621L, 402L, 40L, 201L, 458L, 615L, 438L, 0L, 0L, 0L, 0L, 52L,
274L, 352L, 334L, 622L, 720L, 596L, 167L, 406L, 318L, 54L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 102L, 706L, 517L, 636L, 85L,
0L, 0L, 0L, 0L, 0L, 5L, 0L, 60L, 18L, 109L, 338L, 577L, 178L,
307L, 310L, 237L, 3L, 182L, 84L, 502L, 499L, 79L, 0L, 0L, 0L,
189L, 233L, 31L, 162L, 87L, 350L, 422L, 370L, 357L, 208L, 239L,
207L, 158L, 19L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 212L, 266L,
0L, 0L, 0L, 0L, 18L, 66L, 247L, 163L, 211L, 798L, 199L, 619L,
55L, 0L, 249L, 264L, 399L, 44L, 453L, 78L, 844L, 652L, 24L, 0L,
0L, 112L, 129L, 55L, 69L, 43L, 64L, 93L, 193L, 322L, 510L, 399L,
358L, 333L, 208L, 103L, 371L, 138L, 60L, 10L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 2L, 136L, 122L, 209L, 300L, 556L, 365L,
212L, 107L, 0L, 0L, 0L, 93L, 270L, 450L, 223L, 723L, 651L, 428L,
50L, 0L, 0L, 23L, 0L, 77L, 0L, 0L, 0L, 485L, 103L, 140L, 224L,
121L, 163L, 93L, 197L, 186L, 272L, 575L, 337L, 107L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 312L, 572L, 389L,
541L, 0L, 0L, 0L, 0L, 18L, 285L, 454L, 542L, 224L, 463L, 688L,
120L, 58L, 0L, 114L, 0L, 22L, 0L, 2L, 111L, 629L, 210L, 0L, 172L,
0L, 0L, 0L, 0L, 112L, 160L, 180L, 275L, 498L, 240L, 72L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 92L, 186L, 216L, 41L,
0L, 0L, 0L, 0L, 186L, 572L, 333L, 401L, 492L, 124L, 175L, 318L,
74L, 35L, 345L, 38L, 0L, 0L, 0L, 255L, 422L, 358L, 85L, 214L,
216L, 0L, 0L, 3L, 87L, 49L, 72L, 114L, 117L, 184L, 4L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 3L, 0L, 237L, 19L, 0L, 0L,
0L, 0L, 135L, 198L, 358L, 373L, 231L, 146L, 421L, 428L, 4L, 0L,
118L, 77L, 0L, 0L, 0L, 26L, 304L, 457L, 129L, 285L, 198L, 28L,
0L, 229L, 227L, 114L, 0L, 83L, 16L, 232L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 6L, 183L, 91L, 0L, 0L, 0L, 2L,
111L, 4L, 76L, 238L, 132L, 460L, 435L, 777L, 194L, 0L, 10L, 121L,
128L, 0L, 0L, 0L, 0L, 24L, 9L, 265L, 263L, 1L, 0L, 35L, 170L,
30L, 0L, 0L, 30L, 59L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 11L, 208L, 16L, 0L, 1L, 188L, 449L, 311L, 243L,
203L, 64L, 457L, 493L, 615L, 361L, 94L, 1L, 78L, 0L, 0L, 0L,
44L, 0L, 0L, 0L, 83L, 18L, 167L, 184L, 116L, 0L, 0L, 0L, 0L,
0L, 15L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
10L, 244L, 442L, 225L, 45L, 39L, 362L, 206L, 403L, 348L, 118L,
21L, 356L, 515L, 547L, 194L, 181L, 0L, 0L, 0L, 0L, 89L, 224L,
61L, 0L, 0L, 46L, 6L, 200L, 225L, 103L, 92L, 20L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 50L,
343L, 408L, 0L, 14L, 68L, 547L, 472L, 139L, 40L, 312L, 280L,
634L, 380L, 125L, 19L, 0L, 39L, 2L, 54L, 92L, 27L, 316L, 150L,
0L, 0L, 0L, 7L, 90L, 320L, 62L, 0L, 5L, 6L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 178L, 529L, 44L,
0L, 71L, 276L, 170L, 186L, 0L, 17L, 0L, 14L, 185L, 185L, 34L,
21L, 0L, 132L, 75L, 46L, 18L, 178L, 49L, 12L, 2L, 0L, 0L, 50L,
178L, 89L, 3L, 4L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 201L, 42L, 51L, 227L, 37L, 72L,
71L, 140L, 169L, 0L, 0L, 163L, 41L, 3L, 0L, 0L, 264L, 387L, 8L,
246L, 289L, 149L, 293L, 107L, 0L, 0L, 61L, 32L, 39L, 18L, 21L,
4L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 152L, 124L, 0L, 0L, 31L, 356L, 121L, 46L,
0L, 145L, 119L, 0L, 23L, 146L, 69L, 298L, 220L, 0L, 93L, 249L,
227L, 55L, 0L, 0L, 0L, 0L, 134L, 4L, 0L, 3L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 14L, 28L, 163L, 19L, 3L, 56L, 2L, 153L, 332L,
81L, 0L, 0L, 0L, 13L, 108L, 3L, 0L, 0L, 25L, 16L, 51L, 127L,
92L, 26L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 126L, 36L, 536L, 727L, 70L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 30L, 3L, 51L, 190L, 228L, 49L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 62L, 180L, 476L, 442L, 65L, 4L,
0L, 0L, 0L, 0L, 17L, 0L, 0L, 64L, 28L, 0L, 0L, 23L, 158L, 4L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 116L,
257L, 354L, 125L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 24L, 244L, 188L,
9L, 0L, 1L, 33L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 90L, 93L, 301L, 151L, 160L, 228L, 151L, 18L,
0L, 0L, 0L, 0L, 18L, 114L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 45L, 90L,
117L, 483L, 340L, 6L, 0L, 0L, 0L, 0L, 0L, 7L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 117L, 156L, 98L, 10L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), .Dim = c(50L,
50L), .Dimnames = list(y = c("[1.2588e+06,1.2593e+06]", "[1.2584e+06,1.2588e+06)",
"[1.2579e+06,1.2584e+06)", "[1.2575e+06,1.2579e+06)", "[1.257e+06,1.2575e+06)",
"[1.2566e+06,1.257e+06)", "[1.2561e+06,1.2566e+06)", "[1.2557e+06,1.2561e+06)",
"[1.2552e+06,1.2557e+06)", "[1.2548e+06,1.2552e+06)", "[1.2543e+06,1.2548e+06)",
"[1.2539e+06,1.2543e+06)", "[1.2534e+06,1.2539e+06)", "[1.253e+06,1.2534e+06)",
"[1.2525e+06,1.253e+06)", "[1.2521e+06,1.2525e+06)", "[1.2516e+06,1.2521e+06)",
"[1.2512e+06,1.2516e+06)", "[1.2507e+06,1.2512e+06)", "[1.2503e+06,1.2507e+06)",
"[1.2498e+06,1.2503e+06)", "[1.2494e+06,1.2498e+06)", "[1.2489e+06,1.2494e+06)",
"[1.2485e+06,1.2489e+06)", "[1.248e+06,1.2485e+06)", "[1.2476e+06,1.248e+06)",
"[1.2471e+06,1.2476e+06)", "[1.2467e+06,1.2471e+06)", "[1.2462e+06,1.2467e+06)",
"[1.2458e+06,1.2462e+06)", "[1.2453e+06,1.2458e+06)", "[1.2449e+06,1.2453e+06)",
"[1.2444e+06,1.2449e+06)", "[1.244e+06,1.2444e+06)", "[1.2435e+06,1.244e+06)",
"[1.2431e+06,1.2435e+06)", "[1.2426e+06,1.2431e+06)", "[1.2422e+06,1.2426e+06)",
"[1.2417e+06,1.2422e+06)", "[1.2413e+06,1.2417e+06)", "[1.2408e+06,1.2413e+06)",
"[1.2404e+06,1.2408e+06)", "[1.2399e+06,1.2404e+06)", "[1.2395e+06,1.2399e+06)",
"[1.239e+06,1.2395e+06)", "[1.2386e+06,1.239e+06)", "[1.2381e+06,1.2386e+06)",
"[1.2377e+06,1.2381e+06)", "[1.2372e+06,1.2377e+06)", "[1.2368e+06,1.2372e+06)"
), x = c("[2.6713e+06,2.6718e+06)", "[2.6718e+06,2.6722e+06)",
"[2.6722e+06,2.6727e+06)", "[2.6727e+06,2.6732e+06)", "[2.6732e+06,2.6736e+06)",
"[2.6736e+06,2.6741e+06)", "[2.6741e+06,2.6746e+06)", "[2.6746e+06,2.675e+06)",
"[2.675e+06,2.6755e+06)", "[2.6755e+06,2.676e+06)", "[2.676e+06,2.6764e+06)",
"[2.6764e+06,2.6769e+06)", "[2.6769e+06,2.6774e+06)", "[2.6774e+06,2.6778e+06)",
"[2.6778e+06,2.6783e+06)", "[2.6783e+06,2.6788e+06)", "[2.6788e+06,2.6792e+06)",
"[2.6792e+06,2.6797e+06)", "[2.6797e+06,2.6802e+06)", "[2.6802e+06,2.6806e+06)",
"[2.6806e+06,2.6811e+06)", "[2.6811e+06,2.6816e+06)", "[2.6816e+06,2.682e+06)",
"[2.682e+06,2.6825e+06)", "[2.6825e+06,2.683e+06)", "[2.683e+06,2.6834e+06)",
"[2.6834e+06,2.6839e+06)", "[2.6839e+06,2.6844e+06)", "[2.6844e+06,2.6848e+06)",
"[2.6848e+06,2.6853e+06)", "[2.6853e+06,2.6858e+06)", "[2.6858e+06,2.6862e+06)",
"[2.6862e+06,2.6867e+06)", "[2.6867e+06,2.6872e+06)", "[2.6872e+06,2.6876e+06)",
"[2.6876e+06,2.6881e+06)", "[2.6881e+06,2.6886e+06)", "[2.6886e+06,2.689e+06)",
"[2.689e+06,2.6895e+06)", "[2.6895e+06,2.6899e+06)", "[2.6899e+06,2.6904e+06)",
"[2.6904e+06,2.6909e+06)", "[2.6909e+06,2.6913e+06)", "[2.6913e+06,2.6918e+06)",
"[2.6918e+06,2.6923e+06)", "[2.6923e+06,2.6927e+06)", "[2.6927e+06,2.6932e+06)",
"[2.6932e+06,2.6937e+06)", "[2.6937e+06,2.6941e+06)", "[2.6941e+06,2.6946e+06]"
)), class = c("quadratcount", "table"), xbreaks = c(2671317,
2671782.76, 2672248.52, 2672714.28, 2673180.04, 2673645.8, 2674111.56,
2674577.32, 2675043.08, 2675508.84, 2675974.6, 2676440.36, 2676906.12,
2677371.88, 2677837.64, 2678303.4, 2678769.16, 2679234.92, 2679700.68,
2680166.44, 2680632.2, 2681097.96, 2681563.72, 2682029.48, 2682495.24,
2682961, 2683426.76, 2683892.52, 2684358.28, 2684824.04, 2685289.8,
2685755.56, 2686221.32, 2686687.08, 2687152.84, 2687618.6, 2688084.36,
2688550.12, 2689015.88, 2689481.64, 2689947.4, 2690413.16, 2690878.92,
2691344.68, 2691810.44, 2692276.2, 2692741.96, 2693207.72, 2693673.48,
2694139.24, 2694605), ybreaks = c(1236783, 1237233.14, 1237683.28,
1238133.42, 1238583.56, 1239033.7, 1239483.84, 1239933.98, 1240384.12,
1240834.26, 1241284.4, 1241734.54, 1242184.68, 1242634.82, 1243084.96,
1243535.1, 1243985.24, 1244435.38, 1244885.52, 1245335.66, 1245785.8,
1246235.94, 1246686.08, 1247136.22, 1247586.36, 1248036.5, 1248486.64,
1248936.78, 1249386.92, 1249837.06, 1250287.2, 1250737.34, 1251187.48,
1251637.62, 1252087.76, 1252537.9, 1252988.04, 1253438.18, 1253888.32,
1254338.46, 1254788.6, 1255238.74, 1255688.88, 1256139.02, 1256589.16,
1257039.3, 1257489.44, 1257939.58, 1258389.72, 1258839.86, 1259290
), tess = structure(list(type = "rect", window = structure(list(
type = "rectangle", xrange = c(2671317, 2694605), yrange = c(1236783,
1259290), units = structure(list(singular = "unit", plural = "units",
multiplier = 1), class = "unitname")), class = "owin"),
xgrid = c(2671317, 2671782.76, 2672248.52, 2672714.28, 2673180.04,
2673645.8, 2674111.56, 2674577.32, 2675043.08, 2675508.84,
2675974.6, 2676440.36, 2676906.12, 2677371.88, 2677837.64,
2678303.4, 2678769.16, 2679234.92, 2679700.68, 2680166.44,
2680632.2, 2681097.96, 2681563.72, 2682029.48, 2682495.24,
2682961, 2683426.76, 2683892.52, 2684358.28, 2684824.04,
2685289.8, 2685755.56, 2686221.32, 2686687.08, 2687152.84,
2687618.6, 2688084.36, 2688550.12, 2689015.88, 2689481.64,
2689947.4, 2690413.16, 2690878.92, 2691344.68, 2691810.44,
2692276.2, 2692741.96, 2693207.72, 2693673.48, 2694139.24,
2694605), ygrid = c(1236783, 1237233.14, 1237683.28, 1238133.42,
1238583.56, 1239033.7, 1239483.84, 1239933.98, 1240384.12,
1240834.26, 1241284.4, 1241734.54, 1242184.68, 1242634.82,
1243084.96, 1243535.1, 1243985.24, 1244435.38, 1244885.52,
1245335.66, 1245785.8, 1246235.94, 1246686.08, 1247136.22,
1247586.36, 1248036.5, 1248486.64, 1248936.78, 1249386.92,
1249837.06, 1250287.2, 1250737.34, 1251187.48, 1251637.62,
1252087.76, 1252537.9, 1252988.04, 1253438.18, 1253888.32,
1254338.46, 1254788.6, 1255238.74, 1255688.88, 1256139.02,
1256589.16, 1257039.3, 1257489.44, 1257939.58, 1258389.72,
1258839.86, 1259290), n = 2500), class = c("tess", "list"
)))
My goal is to either create a subset of all the rectangles that have a Freq above 100, or add a separate column with a binary classification if the row has a Freq above 100 or not.
My approach was to create a data.frame first and then the idea would be to change it back to a spatial data format. This is my unsuccessful approach:
Qdf <- as.data.frame(Q)
Qdf <- subset(Qdf, Qdf$Freq>100)
From here on I am unable to further display the data on a map.
Your help is very appreciated!
Did you start with a planar point pattern (ppp) and then create the
quadratcount from there? In that case I recommend you use pixellate to get
the counts directly in a raster format (im class in spatstat):
library(spatstat)
X <- bei
plot(X, main = "")
nx <- 10
ny <- 5
Xqc <- quadratcount(bei, nx = nx, ny = ny)
plot(Xqc, main = "")
Xim <- pixellate(X, dimyx = c(ny, nx))
plot(Xim , main = "")
plot(Xqc, add = TRUE)
Xim2 <- Xim[Xim>100, drop=FALSE] # If drop=TRUE vector of values is returned
plot(Xim2, main = "")
I'm not familiar with spatstat package. But, since your data are basically in a spatial raster grid, you could convert them to raster format and uselibrary(raster) for spatial operations like subsetting, reclassifying, and displaying on maps:
xr = attributes(Q)$xbreaks[c(1, dim(Q)[1]+1L)]
yr = attributes(Q)$ybreaks[c(1, dim(Q)[2]+1L)]
r = raster(matrix(Q, nrow(Q)), xmn=xr[1], xmx=xr[2], ymn=yr[1], ymx=yr[2])
plot(r)
Now we can see where the count is greater than 100
plot(r>100)
Or, see the values, only where they are greater than 100.
r100 = reclassify(r, cbind(-Inf, 100, NA), right=FALSE)
plot(r100)

Plot visreg over an boxplot (GLM with binominal predictor)

I fitted some GLMs with a binominal predictor and would like to plot them with visreg. I usually plot the raw data with par(new=T) as well for better clarity. I don't really like the normal outcome here (x-axis 0-1 in 0.2 steps, a lot of data points just at 0 and 1) and was thinking about plotting the visreg over boxplot since they look much better with binominal data. However, I can't get the two plots to align since there are always two different "starts" and "ends" in the plot. How can I make it so that the visreg line starts at the "No" and ends at the "Yes" of the boxplot?
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
boxplot(data$Cov.herb ~ data$Fire, ylim=c(0,100), axes=F, ylab="Herb cover [%]", xlab="Fire")
axis(1, xaxp=c(1,2,1), xaxt="n")
mtext(text=c("No","Yes"),side=1,line=0.5,at=c(1,2))
axis(2, las=1)
box()
par(new=T)
visreg(fit, scale = "response", type="conditional",line=list(col="red", lwd=1), ylim=c(0,100), xlim=c(0,1), rug=F, axes=F, ann=F)
example plot
Cheers,
Alex
data:
structure(list(Cov.herb = c(40L, 80L, 30L, 2L, 40L, 8L, 5L, 5L,
20L, 45L, 55L, 55L, 35L, 40L, 65L, 70L, 2L, 15L, 1L, 1L, 1L,
25L, 10L, 1L, 10L, 5L, 5L, 15L, 10L, 5L, 15L, 5L, 5L, 35L, 1L,
1L, 35L, 1L, 10L, 5L, 5L, 10L, 5L, 10L, 10L, 20L, 10L, 0L, 3L,
1L, 2L, 4L, 1L, 10L, 30L, 10L, 1L, 2L, 0L, 15L, 25L, 50L, 15L,
35L, 30L, 5L, 5L, 1L, 1L, 1L, 10L, 0L, 0L, 5L, 2L, 1L, 10L, 0L,
2L, 1L, 1L, 5L, 1L, 15L, 1L, 1L, 1L, 0L, 5L, 25L, 3L, 0L, 0L,
1L, 0L, 0L, 0L, 0L, 3L, 1L, 1L, 0L, 5L, 1L, 1L, 1L, 1L, 7L, 1L,
1L, 1L, 1L, 5L, 0L, 2L, 3L, 5L, 3L, 1L, 1L, 2L, 0L, 2L, 0L, 10L,
1L, 20L, 3L, 5L, 20L, 3L, 20L, 5L, 10L, 15L, 30L, 0L, 20L, 45L,
1L, 1L, 2L, 1L, 3L, 0L, 5L, 0L, 35L, 1L, 5L, 25L, 0L, 0L, 40L,
3L, 15L, 10L, 3L, 50L, 30L, 10L, 1L, 0L, 5L, 10L, 10L, 2L, 2L,
5L, 1L, 2L, 1L, 1L, 0L, 0L, 1L, 2L, 5L, 15L, 0L, 1L, 1L, 1L,
1L, 0L, 1L, 5L, 1L, 5L, 35L, 1L, 0L, 1L, 0L, 5L, 1L, 1L, 3L,
15L, 1L, 3L, 1L, 0L, 0L, 0L, 15L, 0L, 1L, 1L, 3L, 35L, 80L, 10L,
2L, 10L, 3L, 3L, 2L, 10L, 50L, 20L, 40L, 2L, 40L, 45L, 25L, 5L,
25L, 50L, 35L, 15L, 45L, 10L, 5L, 15L, 2L, 30L, 2L, 3L, 15L,
5L, 45L, 35L, 20L, 70L, 20L, 10L, 30L, 25L, 8L, 4L, 45L, 60L,
35L, 5L, 40L, 30L, 0L, 30L, 3L, 4L, 25L, 15L, 10L, 15L, 25L,
20L, 7L, 25L, 25L, 40L, 35L, 30L, 40L, 25L, 50L, 30L, 25L, 60L,
15L, 25L, 25L, 50L, 30L, 20L, 2L, 3L, 20L, 25L, 35L, 30L, 10L,
15L, 65L, 10L, 20L, 20L, 2L, 7L, 20L, 25L, 30L, 30L, 9L, 20L,
40L, 7L, 20L, 15L, 15L, 30L, 20L, 35L, 8L, 40L, 20L, 3L, 55L,
35L, 10L, 10L, 65L, 20L, 35L, 60L, 45L, 20L, 10L, 35L, 15L, 20L,
15L, 40L, 10L, 10L, 60L, 60L, 40L, 10L, 10L, 25L, 8L, 20L, 40L,
15L, 25L, 5L, 20L, 20L, 20L, 25L, 30L, 35L, 20L, 110L, 50L, 20L,
20L, 10L, 45L, 25L, 20L, 55L, 10L, 5L, 15L, 15L, 1L, 10L, 15L,
15L, 10L, 30L, 20L, 40L, 55L, 55L, 20L, 30L, 10L, 50L, 40L, 5L,
15L, 10L, 30L, 15L, 20L, 5L, 45L, 50L, 25L, 45L, 30L, 7L, 25L,
30L, 5L, 7L, 50L, 60L, 50L, 10L, 30L, 50L, 15L, 15L, 30L, 15L,
25L, 40L, 10L, 2L, 60L, 20L, 65L, 5L, 15L, 3L, 15L, 40L, 50L,
45L, 30L, 5L, 45L, 15L, 25L, 65L, 15L, 50L, 55L, 30L, 10L, 35L,
15L, 20L, 20L, 10L, 20L, 15L, 45L, 40L, 10L, 7L, 25L, 20L, 60L,
4L, 7L, 40L, 60L, 50L, 50L, 10L, 50L, 5L, 10L, 50L, 20L, 40L,
20L, 25L, 25L, 35L, 10L, 2L, 15L, 60L, 25L, 30L, 20L, 25L, 10L,
10L, 20L, 40L, 40L, 45L, 10L, 35L, 60L, 50L, 10L, 40L, 50L, 25L,
20L, 25L, 25L, 45L, 20L, 30L, 65L, 30L, 35L, 40L, 25L, 15L, 10L,
50L, 25L, 45L, 40L, 20L, 5L, 65L, 5L, 10L, 15L, 7L, 20L, 45L,
15L, 5L, 20L, 20L, 20L, 50L, 15L, 20L, 30L, 25L, 45L, 45L, 35L,
40L, 45L, 4L, 10L, 20L, 20L, 30L, 15L, 30L, 50L, 35L, 45L, 25L,
25L, 10L, 5L, 30L, 30L, 10L, 70L, 25L, 25L, 7L, 20L, 5L, 20L,
8L, 15L, 10L, 20L, 10L, 7L, 15L, 15L, 40L, 50L, 15L, 20L, 8L,
45L, 40L, 15L, 25L, 40L, 20L, 35L, 40L, 70L, 20L, 20L, 40L, 5L,
20L, 7L, 40L, 10L, 5L, 45L, 20L, 10L, 20L, 20L, 45L, 15L, 7L,
30L, 30L, 35L, 10L, 20L, 5L, 15L, 35L, 40L, 40L, 10L, 5L, 15L,
70L, 20L, 85L, 15L, 7L, 55L, 55L, 5L, 20L, 25L, 5L, 30L, 20L,
8L, 30L, 40L, 25L, 10L, 5L, 30L, 10L, 5L, 10L, 35L, 2L, 10L,
10L, 10L, 90L, 45L, 60L, 7L, 1L, 15L), Fire = c(0L, 1L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("Cov.herb",
"Fire"), class = "data.frame", row.names = c(2L, 3L, 4L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 43L, 44L, 45L, 46L, 47L,
48L, 49L, 50L, 51L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 74L, 75L, 76L,
77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 87L, 88L, 89L, 90L,
91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L,
103L, 104L, 105L, 106L, 107L, 108L, 109L, 110L, 111L, 112L, 113L,
114L, 115L, 116L, 117L, 118L, 119L, 120L, 121L, 122L, 123L, 124L,
125L, 126L, 153L, 154L, 155L, 161L, 162L, 163L, 164L, 165L, 166L,
167L, 169L, 170L, 171L, 173L, 174L, 175L, 176L, 177L, 178L, 179L,
180L, 181L, 182L, 183L, 184L, 185L, 186L, 187L, 188L, 189L, 190L,
191L, 192L, 193L, 194L, 195L, 196L, 197L, 198L, 199L, 200L, 201L,
202L, 203L, 204L, 205L, 206L, 207L, 209L, 211L, 213L, 214L, 215L,
216L, 217L, 218L, 219L, 220L, 221L, 222L, 223L, 224L, 225L, 226L,
227L, 228L, 229L, 230L, 231L, 232L, 233L, 234L, 235L, 236L, 237L,
238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 246L, 247L, 248L,
249L, 250L, 251L, 252L, 253L, 254L, 255L, 256L, 257L, 258L, 259L,
260L, 261L, 262L, 263L, 269L, 270L, 274L, 275L, 276L, 277L, 279L,
280L, 281L, 282L, 283L, 284L, 285L, 286L, 287L, 288L, 289L, 290L,
291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L, 301L,
302L, 303L, 304L, 305L, 306L, 307L, 308L, 309L, 310L, 311L, 312L,
313L, 314L, 315L, 316L, 317L, 318L, 319L, 320L, 321L, 322L, 323L,
324L, 325L, 326L, 327L, 328L, 329L, 330L, 331L, 332L, 333L, 334L,
335L, 336L, 337L, 338L, 339L, 340L, 341L, 342L, 343L, 344L, 345L,
346L, 347L, 349L, 350L, 351L, 352L, 353L, 354L, 355L, 356L, 357L,
358L, 359L, 360L, 361L, 362L, 363L, 364L, 365L, 366L, 367L, 368L,
369L, 370L, 371L, 372L, 373L, 374L, 375L, 376L, 377L, 378L, 380L,
381L, 382L, 383L, 384L, 385L, 386L, 387L, 388L, 389L, 390L, 391L,
392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L, 401L, 402L,
403L, 404L, 405L, 406L, 407L, 408L, 409L, 410L, 411L, 412L, 413L,
414L, 415L, 416L, 417L, 418L, 419L, 420L, 421L, 422L, 423L, 424L,
425L, 426L, 427L, 428L, 429L, 430L, 431L, 432L, 433L, 434L, 435L,
436L, 437L, 438L, 439L, 440L, 441L, 443L, 444L, 445L, 446L, 447L,
448L, 449L, 450L, 451L, 453L, 454L, 455L, 457L, 458L, 459L, 460L,
461L, 463L, 464L, 465L, 466L, 467L, 468L, 469L, 470L, 471L, 472L,
473L, 474L, 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L,
484L, 485L, 486L, 487L, 488L, 489L, 490L, 491L, 492L, 493L, 494L,
495L, 496L, 497L, 498L, 499L, 500L, 501L, 502L, 503L, 504L, 505L,
506L, 507L, 508L, 509L, 510L, 511L, 512L, 513L, 514L, 515L, 516L,
517L, 518L, 519L, 520L, 521L, 522L, 523L, 524L, 525L, 526L, 527L,
528L, 529L, 530L, 531L, 532L, 533L, 534L, 535L, 536L, 537L, 538L,
539L, 540L, 541L, 542L, 543L, 544L, 545L, 546L, 547L, 548L, 549L,
551L, 552L, 553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L,
562L, 563L, 564L, 565L, 566L, 567L, 568L, 569L, 570L, 571L, 572L,
573L, 574L, 575L, 576L, 577L, 578L, 579L, 580L, 581L, 582L, 583L,
584L, 585L, 587L, 588L, 589L, 590L, 591L, 592L, 593L, 594L, 595L,
596L, 597L, 598L, 599L, 600L, 601L, 602L, 603L, 604L, 605L, 606L,
607L, 608L, 609L, 610L, 611L, 612L, 613L, 614L, 615L, 616L, 617L,
618L, 619L, 620L, 621L, 622L, 623L, 624L, 625L, 626L, 628L, 629L,
631L, 632L, 633L, 634L, 635L, 636L, 637L, 638L, 639L, 640L, 641L,
642L, 643L, 644L, 645L, 646L, 648L, 649L, 650L, 651L, 652L, 653L,
654L, 655L, 656L, 657L, 658L, 659L, 660L, 661L, 662L, 663L, 664L,
665L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 675L,
676L, 677L, 678L, 679L, 680L, 682L, 683L, 684L, 685L, 686L, 687L,
689L, 690L, 691L, 692L, 693L, 694L, 697L, 698L, 699L, 700L, 701L,
702L, 704L, 705L, 706L, 707L))
So, my point was that doing it this way would give you more flexibility with your plotting. For example,
# Fit model
fit <- glm (Cov.herb ~ Fire, family=gaussian, data=data)
# Get model data for plotting
vis.out <- visreg(fit, scale = "response", plot = FALSE)
# Load library
library(ggplot2)
# Create plot
p <- ggplot(data = data)
p <- p + geom_boxplot(aes(x = as.factor(Fire), y = Cov.herb, fill = as.factor(Fire)), alpha = 0.3, outlier.alpha = 1)
p <- p + xlab("Fire") + ylab("Herb cover [%]")
p <- p + geom_ribbon(data = vis.out$fit, aes(x = Fire + 1, ymin = visregLwr, ymax = visregUpr), fill = "lightgrey")
p <- p + geom_line(data = vis.out$fit, aes(x = Fire + 1, y = visregFit), colour = "salmon", size = 1.25)
p <- p + scale_x_discrete(labels = c("No", "Yes"))
p <- p + theme(legend.position = "none")
print(p)
gives,
Is that the sort of thing you're looking for? (You could also add all the data points using geom_point to plot on top of the boxes. I think that usually looks pretty cool.)

How can I visualize 1D numeric data with R / tikz?

I have a text file with 166898 lines where each line has a single non-negative number. I would like to visualize it in the following way:
The x-axis should range from minimum_in_file to maximum_in_file.
The y-axis should range from 1 to 166898
The graph / bar plot should be increasing and visualize how many numbers are equal to the x-value or lower.
Create data
#!/usr/bin/env python
import random
minimum_in_file = 0
maximum_in_file = 378864471
numbers = []
for i in range(166898):
numbers.append(random.randint(minimum_in_file, maximum_in_file))
numbers = sorted(numbers)
with open("times-sorted.txt", 'a') as f:
for number in numbers:
f.write(str(number) + "\n")
Real data
When I execute dput(head(mydata,20)) I get:
structure(list(X0 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = "X0", row.names = c(NA,
20L), class = "data.frame")
and
> dput(head(mydata,1000))
structure(list(X0 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 2L, 2L, 3L, 3L, 5L, 6L, 7L, 8L, 8L,
8L, 8L, 11L, 12L, 13L, 13L, 13L, 16L, 18L, 19L, 20L, 20L, 23L,
25L, 26L, 27L, 35L, 37L, 37L, 39L, 41L, 41L, 45L, 46L, 47L, 48L,
48L, 48L, 50L, 52L, 53L, 55L, 56L, 62L, 65L, 66L, 67L, 67L, 70L,
79L, 79L, 80L, 83L, 85L, 86L, 88L, 88L, 89L, 91L, 96L, 97L, 99L,
100L, 101L, 101L, 101L, 102L, 103L, 104L, 104L, 107L, 109L, 109L,
109L, 109L, 111L, 111L, 111L, 111L, 112L, 112L, 112L, 112L, 113L,
113L, 114L, 114L, 114L, 115L, 115L, 115L, 116L, 117L, 118L, 119L,
120L, 120L, 124L, 124L, 124L, 124L, 125L, 125L, 127L, 127L, 128L,
128L, 128L, 129L, 129L, 129L, 130L, 130L, 131L, 132L, 132L, 132L,
133L, 133L, 134L, 134L, 134L, 134L, 136L, 136L, 137L, 137L, 138L,
139L, 140L, 141L, 141L, 142L, 143L, 143L, 143L, 144L, 144L, 144L,
145L, 145L, 146L, 147L, 147L, 149L, 149L, 150L, 150L, 150L, 150L,
150L, 151L, 151L, 151L, 151L, 151L, 152L, 152L, 153L, 154L, 154L,
154L, 154L, 155L, 156L, 157L, 157L, 158L, 158L, 158L, 158L, 159L,
160L, 160L, 160L, 160L, 161L, 161L, 163L, 163L, 163L, 164L, 164L,
164L, 164L, 164L, 165L, 165L, 166L, 166L, 167L, 167L, 167L, 167L,
168L, 168L, 168L, 169L, 169L, 170L, 170L, 171L, 171L, 172L, 172L,
172L, 172L, 173L, 173L, 173L, 174L, 174L, 175L, 175L, 175L, 176L,
176L, 176L, 176L, 177L, 177L, 177L, 177L, 177L, 179L, 179L, 179L,
180L, 180L, 180L, 180L, 181L, 181L, 182L, 182L, 182L, 182L, 183L,
183L, 184L, 184L, 184L, 184L, 185L, 185L, 185L, 186L, 187L, 187L,
187L, 187L, 188L, 188L, 188L, 188L, 189L, 189L, 189L, 189L, 190L,
190L, 190L, 190L, 191L, 191L, 191L, 191L, 191L, 191L, 191L, 191L,
191L, 192L, 192L, 193L, 193L, 194L, 194L, 195L, 195L, 195L, 197L,
197L, 197L, 197L, 197L, 198L, 198L, 198L, 198L, 198L, 198L, 199L,
199L, 199L, 199L, 199L, 199L, 199L, 200L, 200L, 200L, 200L, 200L,
200L, 200L, 200L, 200L, 201L, 201L, 203L, 203L, 203L, 204L, 204L,
204L, 205L, 205L, 206L, 206L, 206L, 206L, 206L, 206L, 206L, 207L,
207L, 207L, 207L, 207L, 207L, 208L, 208L, 209L, 209L, 209L, 209L,
209L, 209L, 210L, 210L, 210L, 210L, 210L, 211L, 211L, 212L, 213L,
213L, 213L, 213L, 215L, 215L, 215L, 215L, 215L, 215L, 215L, 215L,
215L)), .Names = "X0", row.names = c(NA, 1000L), class = "data.frame")
What I've tried
I sorted the data with the unix tool sort and tried the following with R version 3.0.1 (2013-05-16):
> mydata = read.csv("times-sorted.txt")
> accumulated_sum<-cumsum(mydata)
Warning message:
In lapply(X = x, FUN = .Generic, ...) :
integer overflow in 'cumsum'; use 'cumsum(as.numeric(.))'
> plot(accumulated_sum)
But I don't understand how to fix the warning and the result is crappy:
How can I visualize it in a nice way?
See this source code here (https://svn.r-project.org/R/trunk/src/main/cum.c), and the statement
if(sum > INT_MAX || sum < 1 + INT_MIN) where INT_MAX is .Machine$integer.max ,possibly this limit is being exceeded since you are applying cumsum to the entire dataset and not the variable of interest.
Since you have not posted your dataset structure, I think the row indices are being passed to cumsum and hence the warning,
N=166898
vec=1:N
#produces warning "Warning message: integer overflow in 'cumsum'; use 'cumsum(as.numeric(.))'"
cumsum(vec)
You need a cumulative frequency plot. Following is sample example adapted from
(http://www.r-tutor.com/elementary-statistics/quantitative-data/cumulative-frequency-graph)
Sample Example
#For reproducibility
set.seed(100)
N=166898
vec=1:N
#Assuming min_val, max_val
min_val = 0
max_val = 378864471
min_break = 1e8
max_break = 4e8
seq_by = 1e8
#Create random values dataset
random_values = sample(min_val:max_val,N,replace = T)
DF=data.frame(vec,random_values)
#Compute Cumulative Frequency
#You can control the buckets by appropriate inputs to breaks
breaks = seq(min_break, max_break, by=seq_by)
#Creates buckets [x,y), [y,z) etc.
DF.cut = cut( DF$random_values, breaks, right=FALSE)
#Computes count of observations in various buckets and cumulative frequency
DF.freq=table(DF.cut)
DF.cumfreq = c(0, cumsum(DF.freq))
#Plot Data
plot(breaks, DF.cumfreq,main="Cumulative Frequency of XYZ",xlab="Range of Values",ylab="# of Observations < X")
lines(breaks, DF.cumfreq)
Your data
I have plotted the below plot using the data sample you provided, but the following should work for your file(s) now.
#Replace the appropriate filename here
mydata = read.table("times-sorted.txt")
min_val_new = min(mydata)
max_val_new = max(mydata)
breaks_new = seq(from=min_val_new,to=max_val_new,length.out=5)
#Creates buckets [x,y), [y,z) etc.
DF.cut_new = cut(mydata[,1], breaks_new, right=FALSE)
#Computes count of observations in various buckets and cumulative frequency
DF.freq_new=table(DF.cut_new)
DF.cumfreq_new = c(0, cumsum(DF.freq_new))
#Plot Data
plot(breaks_new, DF.cumfreq_new,main="Cumulative Frequency of ABC",xlab="Range of Values",ylab="# of Observations < X")
lines(breaks_new, DF.cumfreq_new)
Exponential Plot
Define your breakpoints cutoff1=10000 and cutoff2=60000 and include them in 'breaks' calculation and plotting using ggplot2 with log axis
set.seed(100)
require(ggplot2)
N=166898
vec=1:N
#Assuming min_val, max_val
min_val = 0
max_val = 378864471
min_break=0
max_break=4e8
#Create random values dataset
random_values = sample(min_val:max_val,N,replace = T)
DF=data.frame(vec,random_values)
#Define your data breakpoints
cutoff1=10000
cutoff2=60000
#Compute Cumulative Frequency
#You can control the buckets by appropriate inputs to breaks
breaks = c(min_break,cutoff1,seq(cutoff2, max_break, length.out=30))
#Creates buckets [x,y), [y,z) etc.
DF.cut = cut( DF$random_values, breaks, right=FALSE)
#Computes count of observations in various buckets and cumulative frequency
DF.freq=table(DF.cut)
DF.cumfreq = c(0, cumsum(DF.freq))
#Plot Data
#plot(breaks, DF.cumfreq,main="Cumulative Frequency of XYZ",xlab="Range of Values",ylab="# of Observations < X")
#lines(breaks, DF.cumfreq)
gg.df=data.frame(breaks,DF.cumfreq)
ggplot(gg.df, aes(x = breaks,y=DF.cumfreq)) + geom_line() + scale_x_log10() +
xlab("Range of Values: Log Axis") +
ylab("# of Observations < X") +
ggtitle("Cumulative Frequency of Variable")

Resources