Сообщение о погрешности линейной модели диаграммы рассеяния - PullRequest
0 голосов
/ 26 июня 2019

Я имею дело с совокупным набором данных (AggregateSS), основанным на свойствах района с рядом непрерывных переменных с разбивкой по районам.Я пытаюсь построить линию наилучшего соответствия через точки данных на моей диаграмме рассеяния, но получаю следующее сообщение об ошибке: Ошибка в data.frame (x = x, y = y, grp = grp): аргументы подразумевают различное количество строк: 32, 0

У меня 32 строки данных, и нигде нет пропущенных данных.Может ли кто-нибудь помочь мне исправить это?

dput(AggregateSS)
structure(list(borough = structure(c("Barking and Dagenham", 
"Barnet", "Bexley", "Brent", "Bromley", "Camden", "Croydon", 
"Ealing", "Enfield", "Greenwich", "Hackney", "Hammersmith and Fulham", 
"Haringey", "Harrow", "Havering", "Hillingdon", "Hounslow", 
"Islington", 
"Kensington and Chelsea", "Kingston upon Thames", "Lambeth", 
"Lewisham", "Merton", "Newham", "Redbridge", "Richmond upon Thames", 
"Southwark", "Sutton", "Tower Hamlets", "Waltham Forest", "Wandsworth", 
"Westminster"), format.spss = "A30", display_width = 20L), riskcateg = 
structure(c("low risk", 
"high risk", "medium risk", "high risk", "high risk", "medium risk", 
"high risk", "high risk", "high risk", "medium risk", "medium risk", 
"low risk", "medium risk", "medium risk", "medium risk", "medium risk", 
"medium risk", "medium risk", "low risk", "low risk", "high risk", 
"high risk", "medium risk", "high risk", "high risk", "low risk", 
"high risk", "low risk", "medium risk", "medium risk", "high risk", 
"medium risk"), format.spss = "A20"), perwhite = structure(c(49.5, 
68.7, 79.4, 37.4, 78.4, 62.4, 55.8, 46.4, 64.6, 63.6, 54.5, 67.4, 
66.9, 44.8, 85.8, 55.9, 44.4, 64.5, 63.5, 71.9, 67.5, 63.2, 64.6, 
31.9, 37.6, 83.5, 57.9, 68.6, 40.8, 55.9, 71.6, 55.8), format.spss = 
"F8.1"), 
perBME = structure(c(50.5, 31.3, 20.6, 62.6, 31.6, 37.6, 
44.2, 53.6, 35.4, 36.4, 45.5, 32.6, 33.1, 55.2, 14.2, 44.1, 
55.6, 35.5, 36.5, 28.1, 32.5, 36.8, 35.4, 68.1, 62.4, 16.5, 
42.1, 31.4, 59.2, 44.1, 28.4, 44.2), format.spss = "F8.1"), 
unemprate = structure(c(31.1, 27.9, 23.6, 28.5, 22.7, 27.4, 
23.7, 26.6, 30.4, 28.9, 30, 23.1, 26.4, 22, 21.1, 24.8, 24.3, 
24.8, 40.8, 28, 23.6, 21.2, 18.1, 31.3, 31, 22.2, 22.7, 19.9, 
27.1, 21.8, 19.4, 31.8), format.spss = "F8.1"), crimerate = 
structure(c(2.3, 
4.3, 2.9, 3.6, 3.9, 2.8, 4.5, 4.1, 3.8, 3.1, 3.1, 2.4, 3, 
2.7, 3, 3.3, 2.9, 2.7, 2.2, 1.9, 3.8, 3.6, 2.5, 3.5, 3.3, 
2.3, 3.6, 2.4, 3.1, 3, 3.7, 2.7), format.spss = "F8.1"), 
knifetotal = structure(c(109, 186, 128, 166, 168, 122, 201, 
186, 176, 142, 141, 111, 138, 113, 131, 143, 134, 122, 100, 
74, 175, 167, 103, 161, 150, 95, 159, 105, 136, 139, 161, 
118), format.spss = "F8.0"), kniferateborough = structure(c(3.9, 
3.6, 3.7, 3.8, 3.5, 3.6, 3.7, 3.7, 3.8, 3.7, 3.8, 3.7, 3.7, 
3.4, 3.6, 3.6, 3.8, 3.8, 3.8, 3.1, 3.8, 3.8, 3.4, 3.8, 3.7, 
3.4, 3.7, 3.6, 3.7, 3.8, 3.6, 3.6), format.spss = "F8.1"), 
kniferatetotal = structure(c(2.4, 4.2, 2.9, 3.7, 3.7, 2.7, 
4.5, 4.2, 3.9, 3.2, 3.2, 2.5, 3.1, 2.5, 2.9, 3.2, 3, 2.7, 
2.2, 1.7, 3.9, 3.7, 2.3, 3.6, 3.4, 2.1, 3.6, 2.4, 3, 3.1, 
3.6, 2.6), format.spss = "F8.1"), SStotal = structure(c(5548, 
3986, 4021, 14719, 7182, 12075, 10281, 9347, 7018, 7529, 
11383, 8142, 13173, 4362, 3554, 7393, 8298, 11162, 15519, 
3870, 25014, 10797, 3930, 15499, 4967, 2587, 18329, 2668, 
15411, 11005, 5452, 20612), format.spss = "F8.0"), SSoffethn_asian = 
structure(c(1092, 
618, 128, 2201, 249, 1525, 1080, 2744, 412, 699, 1721, 581, 
657, 948, 261, 1652, 2248, 1199, 1280, 497, 968, 566, 754, 
5037, 1940, 304, 1021, 168, 9636, 2880, 637, 2020), format.spss = "F8.0"), 
SSoffethn_black = structure(c(1623, 1417, 657, 8169, 2309, 
4825, 5055, 3685, 3312, 3206, 5940, 3533, 6759, 1660, 874, 
2107, 2106, 4339, 6045, 799, 16633, 6344, 1095, 5805, 1175, 
431, 10685, 629, 2344, 4061, 2643, 7868), format.spss = "F8.0"), 
SSoffethn_white = structure(c(2707, 1668, 3052, 3391, 4419, 
5157, 3557, 2334, 3056, 3392, 3350, 3182, 5310, 1478, 2358, 
3256, 3526, 5176, 6421, 2366, 6731, 3584, 1979, 4280, 1693, 
1755, 6180, 1796, 3020, 3715, 1978, 8017), format.spss = "F8.0"), 
SSoffethn_other = structure(c(33, 219, 23, 790, 85, 397, 
439, 478, 122, 95, 218, 708, 241, 198, 26, 190, 300, 264, 
1626, 123, 377, 141, 48, 156, 95, 53, 244, 24, 147, 128, 
95, 2495), format.spss = "F8.0"), SSselfethn_asian = structure(c(995, 
569, 86, 2040, 190, 1182, 957, 2515, 343, 512, 1453, 432, 
533, 870, 201, 1520, 1970, 895, 1193, 418, 756, 487, 586, 
4491, 1745, 246, 789, 140, 9094, 2413, 498, 1881), format.spss = "F8.0"), 
SSselfethn_black = structure(c(1352, 1057, 523, 6629, 1846, 
3510, 3734, 2970, 2775, 2488, 4801, 2385, 5335, 1306, 671, 
1807, 1614, 3121, 4206, 584, 12421, 5145, 779, 4851, 974, 
259, 8357, 445, 1839, 3189, 1767, 5695), format.spss = "F8.0"), 
SSselfethn_white = structure(c(2522, 1506, 2934, 2963, 4177, 
4514, 3091, 2127, 2566, 3150, 2925, 2760, 4322, 1342, 2165, 
3128, 3256, 4494, 5577, 2240, 5533, 3243, 1803, 3935, 1554, 
1638, 5243, 1734, 2850, 3243, 1748, 6778), format.spss = "F8.0"), 
SSselfethn_mixed = structure(c(176, 209, 83, 578, 293, 523, 
530, 343, 333, 260, 525, 372, 519, 185, 137, 215, 296, 607, 
871, 175, 1203, 396, 154, 480, 169, 132, 701, 123, 379, 419, 
339, 978), format.spss = "F8.0"), SSselfethn_other = structure(c(87, 
103, 38, 412, 93, 280, 206, 240, 239, 147, 260, 322, 363, 
95, 42, 150, 214, 286, 744, 97, 330, 172, 78, 282, 81, 42, 
387, 27, 164, 195, 76, 1201), format.spss = "F8.0"), SSobj_weap = structure(c(248, 
140, 206, 927, 630, 697, 856, 533, 604, 796, 1264, 396, 1175, 
318, 290, 380, 404, 812, 579, 120, 2608, 872, 144, 1040, 
203, 94, 2241, 107, 1362, 150, 476, 914), format.spss = "F8.0"), 
SSobj_weap_boroughrate = structure(c(4.5, 3.5, 5.1, 6.3, 
8.8, 5.8, 8.3, 5.7, 8.6, 10.6, 11.1, 4.9, 9, 7.3, 8.2, 5.1, 
4.9, 7.3, 3.7, 3.1, 10.4, 8.1, 3.7, 6.7, 4.1, 3.6, 12.2, 
4, 8.8, 1.4, 8.7, 4.4), format.spss = "F8.1"), SSobj_stolen = structure(c(186, 
179, 194, 507, 556, 532, 380, 273, 245, 344, 522, 406, 580, 
193, 186, 431, 315, 534, 466, 134, 927, 365, 225, 683, 204, 
126, 747, 190, 429, 477, 267, 1404), format.spss = "F8.0"), 
SSobj_stolen_boroughrate = structure(c(3.4, 4.5, 4.8, 3.4, 
7.7, 4.4, 3.7, 2.9, 3.5, 4.6, 4.6, 5, 4.4, 4.4, 5.2, 5.8, 
3.8, 4.8, 3, 3.5, 3.7, 3.4, 5.7, 4.4, 4.1, 4.9, 4.1, 7.1, 
2.8, 4.3, 4.9, 6.9), format.spss = "F8.1"), SSobj_drugs = structure(c(3877, 
2498, 2517, 9511, 3166, 8324, 6459, 6454, 4396, 4402, 6098, 
4706, 7432, 2631, 2104, 4800, 5629, 6383, 8171, 2419, 14165, 
6102, 2115, 10249, 3370, 1145, 9999, 1607, 10964, 6595, 2737, 
10700), format.spss = "F8.0"), SSobj_drugs_boroughrate = structure(c(69.9, 
62.7, 62.6, 64.6, 44.1, 68.9, 62.8, 69, 62.6, 58.5, 53.6, 
57.8, 56.4, 60.3, 59.2, 64.9, 66.6, 57.2, 52.7, 62.5, 56.6, 
56.5, 53.9, 66.1, 67.9, 44.3, 54.6, 60.2, 71.1, 59.9, 50.2, 
51.9), format.spss = "F8.1"), SSobj_crimdam = structure(c(1016, 
994, 870, 2973, 2227, 2085, 2120, 1781, 1439, 1592, 2712, 
2282, 3313, 982, 791, 1464, 1572, 2971, 3880, 1057, 6324, 
2913, 1241, 2563, 992, 1069, 4564, 633, 2112, 1822, 1623, 
4943), format.spss = "F8.0"), SSobj_crimdam_boroughrate = structure(c(18.3, 
24.9, 21.6, 20.2, 31, 17.3, 20.6, 19.1, 20.5, 21.1, 23.8, 
28, 25.2, 22.5, 22.3, 19.8, 18.9, 26.6, 25, 27.3, 25.3, 27, 
31.6, 16.5, 20, 41.3, 24.9, 23.7, 13.7, 16.6, 29.8, 24), format.spss = "F8.1"), 
SSarrestrate = structure(c(15.5, 19.5, 17.9, 17, 22.2, 16.2, 
21.5, 17.6, 20.1, 19.3, 22, 19, 19.3, 16.3, 16.8, 19.1, 20.9, 
16.7, 15.4, 21, 17.9, 22.9, 23.1, 19.4, 18.7, 21.7, 17.9, 
23.7, 16.1, 14, 21.4, 14.6), format.spss = "F8.1"), SSnfoundnfarate = structure(c(39.6, 
47.9, 39.6, 43.6, 37.6, 40.1, 38, 43.8, 41.6, 39.7, 36.3, 
48.8, 42.2, 42.5, 42.9, 39.6, 39.8, 45.1, 42.1, 48.3, 45.3, 
44.7, 43.7, 37.2, 44.3, 52.4, 41.5, 43.1, 35.1, 38.1, 43.3, 
43.9), format.spss = "F8.1")), row.names = c(NA, -32L), class = 
c("tbl_df", 
"tbl", "data.frame"))

Сначала я создал диаграмму рассеяния для переменных 'perwhite', 'SStotal':

plot_scatter(AggregateSS, perwhite, SStotal)

Это сработало,а затем я хотел уместить линию и обозначить точки:

plot_scatter(AggregateSS, perwhite, SStoal, dot.labels = AggregateSS$borough, fit.line = lm)

Ошибка в data.frame (x = x, y = y, grp = grp): аргументы подразумевают различное количество строк: 32, 0

Я попытался без меток, но появилось то же сообщение об ошибке.

...