我的logit模型适用于具有二元结果以及连续和二元预测变量组合的数据。该模型的目标是模拟二元结果变量的概率。
structure(list(age = c(25, 49, 41, 19, 55, 37, 30, 31, 52, 37,
27, 61, 39, 30, 22, 50, 42, 58, 33, 43, 44, 48, 43, 48, 18, 39,
31, 46, 32, 48, 18, 52, 42, 30, 26, 27, 35, 55, 39, 32, 27, 41,
33, 59, 19, 22, 26, 45, 45, 27, 32, 44, 34, 27, 48, 37, 23, 45,
19, 62, 45, 28, 55, 26, 45, 22, 40, 25, 52, 36, 36, 32, 37, 19,
35, 44, 43, 21, 49, 54, 30, 20, 45, 25, 42, 20, 34, 52, 20, 32,
35, 49, 49, 34, 38, 41, 38, 44, 56, 20, 47, 29, 49, 32, 34, 37,
31, 49, 37, 44, 44, 42, 42, 63, 48, 40, 26, 28, 42, 60, 26, 55,
30, 35, 45, 56, 32, 24, 21, 58, 58, 24, 57, 57, 27, 57, 23, 56,
44, 35, 57, 44, 28, 26, 56, 47, 34, 61, 40, 52, 47, 30, 34, 49,
37, 48, 40, 60, 61, 26, 23, 25, 27, 43, 56, 31, 65, 47, 51, 36,
58, 49, 29, 30, 34, 48, 54, 26, 51, 22, 58, 38, 58, 63, 71, 27,
63, 63, 29, 48, 56, 23, 37, 59, 61, 44, 35, 38, 41, 52, 56, 35,
64, 40, 56, 63, 28, 41, 57, 37, 28, 46, 59, 50, 63, 57, 50, 58,
49, 46, 50, 38, 40, 34, 33, 46, 42, 33, 63, 61, 57, 59, 63, 49,
39, 57, 54, 51, 39, 27, 55, 44, 61, 57, 70, 19, 40, 39, 43, 48,
25, 52, 61, 49, 56, 59, 63, 53, 39, 50, 34, 47, 25, 47, 56, 18,
43, 22, 42, 55, 62, 57, 54, 41, 58, 58, 54, 25, 47, 22, 26, 53,
40, 29, 40, 32, 56, 40, 39, 22, 31, 24, 28, 49, 42, 50, 55, 42,
54, 63, 35, 44, 54, 52, 52, 25, 51, 33, 33, 39, 34, 44, 32, 38,
40, 26, 58, 35, 53, 46, 27, 29, 23, 39, 54, 48, 65, 29, 41, 60,
16, 50, 22, 64, 50, 56, 24, 53, 43, 58, 42, 20, 56, 56, 54, 36,
38, 37, 38, 44, 30, 48, 29, 59, 29, 29, 66, 41, 34, 34, 49, 48,
42, 54, 65, 31, 50, 30, 54, 55, 44, 63, 45, 50, 37, 42, 44, 62,
24, 23, 55, 46, 28, 52, 34, 50, 65, 62, 42, 52, 51, 67, 59, 52,
52, 40, 64, 26, 54, 30, 41, 32, 62, 59, 26, 42, 62, 63, 43, 56,
48, 59, 28, 46, 46, 40, 61, 46, 42, 27, 26, 64, 33, 52, 54, 59,
64, 49, 47, 25, 49, 38, 67, 53, 32, 61, 19, 50, 28, 52, 47, 38,
33, 56, 21, 38, 40, 38, 36, 59, 41, 65, 60, 58, 57, 53, 25, 35,
21, 46, 34, 34, 33, 31, 47, 36, 57, 42, 58, 37, 47, 32, 65, 36,
48, 42, 29, 46, 29, 62, 51, 56, 54, 54, 51, 28, 30, 64, 32, 63,
54, 31, 63, 72, 35, 46, 51, 46, 55, 44, 30, 62, 56, 48, 46, 61,
67, 58, 59, 62, 45, 21, 53, 57, 61, 41, 50, 59, 43, 44, 38, 42,
39, 34, 36, 47, 72, 33, 46, 66, 63, 56, 61, 41, 60, 59, 52, 37,
46, 55, 43, 26, 60, 30, 46, 62, 26, 33, 21, 54, 63, 69, 49, 60,
21, 47, 55, 62, 65, 61, 50, 26, 58, 54, 28, 64, 28, 48, 62, 23,
55, 61, 34, 51, 33, 62, 59, 61, 40, 63, 42, 29, 55, 48, 55, 25,
38, 55, 26, 60, 55, 63, 53, 57, 66, 48, 43, 58, 58, 21, 29, 19,
55, 38, 35, 55, 62, 58, 63, 42, 62, 28, 22, 47, 42, 19, 49, 44,
40, 52, 48, 37, 52, 36, 48, 31, 54, 42, 38, 40, 39, 37, 53, 51,
33, 45, 64, 50, 54, 54, 41, 45, 29, 58, 61, 52, 26, 27, 50, 46,
66, 37, 49, 54, 54, 57, 39, 64, 41, 53, 56, 55, 52, 44, 67, 62,
63, 41, 53, 68, 49, 46, 52, 22, 55, 59, 39, 70, 43, 27, 49, 18,
30, 41, 55, 59, 25, 33, 60, 48, 60, 45, 46, 54, 63, 20, 45, 34,
38, 33, 60, 42, 54, 51, 59, 47, 35, 40, 65, 48, 46, 61, 66, 53,
53, 52, 66, 47, 69, 42, 57, 59, 58, 29, 26, 49, 38, 35, 53, 47,
44, 36, 52, 52, 24, 45, 37, 46, 33, 48, 33, 21, 36, 48, 62, 46,
64, 45, 24, 56, 20, 39, 30, 25, 35, 59, 31, 43, 40, 54, 22, 46,
38, 17, 45, 50, 50, 63, 43, 59, 70, 33, 66, 29, 47, 48, 59, 54,
49, 51, 18, 63, 59, 58, 23, 65, 39, 66, 53, 44, 59, 50, 61, 40,
59, 49, 33, 47, 33, 31, 55, 31, 38, 39, 75, 63, 17, 65, 67, 52,
28, 46, 36, 44, 65, 44, 46, 61, 64, 54, 41, 71, 62, 40, 37, 60,
40, 44, 62, 66, 55, 50, 58, 57, 18, 57, 33, 60, 51, 59, 60, 51,
49, 63, 31, 58, 42, 34, 53, 56, 61, 42, 43, 65, 56, 58, 51, 28,
40, 19, 42, 36, 60, 47, 63, 52, 32, 62, 23, 54, 52, 62, 69, 42,
29, 57, 48, 43, 66, 56, 46, 50, 44, 64, 35, 60, 26, 54, 54, 63,
51, 44, 33, 58, 54, 60, 54, 62, 68, 30, 62, 48, 68, 53, 56, 28,
59, 51, 39, 21, 50, 50, 53, 57, 59, 51, 64, 55, 58, 53, 74, 26,
45, 63, 58, 55, 49, 58, 38, 41, 45, 60, 52, 46, 68, 50, 60, 63,
41, 19, 28, 58, 43, 69, 24, 53, 58, 59, 40, 64, 68, 66, 66, 65,
32, 42, 58, 57, 26, 45, 24, 57, 45, 28, 64, 54, 74, 66, 50, 69,
61, 59, 49, 25, 28, 45, 55, 64, 61, 67, 55, 60, 34, 62, 65, 51,
26, 33, 58, 49, 62, 62, 61, 47, 76, 60, 49, 59, 55, 62, 55, 52,
40, 49, 64, 45, 50, 71, 52, 53, 23, 21, 49, 57, 52, 72, 42, 66,
54, 57, 37, 40, 23, 53, 64, 61, 69, 37, 40, 63, 47, 44, 39, 39,
42, 66, 60, 50, 62, 44, 64, 69, 63, 51, 61, 46, 34, 45, 48, 59,
60, 23, 24, 57, 64, 30, 59, 58, 59, 62, 70, 23, 48, 49, 46, 48,
62, 30, 51, 28, 64, 57, 51, 42, 53, 64, 54, 29, 50, 47, 62, 58,
67, 37, 42, 30, 22, 66, 65, 48, 48, 44, 63, 67, 48, 15, 48, 43,
46, 35, 51, 67, 68, 58, 36, 67, 60, 62, 64, 54, 51, 52, 61, 49,
63, 66, 65, 59, 27, 55, 37, 25, 75, 36, 35, 47, 58, 63, 67, 51,
68, 55, 40, 45, 53, 57, 72, 63, 51, 36, 49, 43, 39, 49, 50, 48,
44, 30, 44, 36, 54, 32, 56, 54, 56, 45, 55, 68), male = c(1,
1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0,
1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0,
0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0,
0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1,
0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1,
0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0,
0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1,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 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), HC = c(26, 33,
25, 30, 28, 20, 28, 21, 17, 25, 36, 25, 17, 21, 29, 26, 22, 30,
21, 21, 32, 16, 24, 34, 19, 24, 27, 30, 40, 18, 21, 24, 25, 20,
14, 28, 23, 19, 22, 22, 17, 21, 21, 20, 29, 24, 22, 15, 33, 16,
32, 22, 27, 23, 30, 30, 26, 23, 29, 40, 33, 24, 24, 28, 25, 22,
26, 28, 23, 21, 41, 31, 24, 18, 22, 18, 23, 26, 34, 30, 30, 20,
29, 24, 33, 34, 16, 31, 19, 26, 20, 19, 26, 25, 37, 20, 25, 28,
28, 16, 42, 27, 35, 28, 27, 27, 35, 19, 30, 28, 27, 39, 18, 30,
22, 26, 23, 23, 24, 30, 24, 44, 24, 24, 28, 28, 30, 24, 25, 27,
19, 24, 26, 26, 26, 31, 26, 28, 41, 24, 21, 17, 23, 14, 24, 34,
22, 29, 23, 21, 27, 33, 24, 26, 21, 21, 30, 24, 22, 19, 22, 25,
30, 22, 20, 26, 26, 32, 33, 36, 22, 24, 33, 40, 21, 40, 25, 26,
17, 17, 23, 31, 23, 28, 25, 25, 39, 27, 26, 20, 28, 25, 23, 29,
24, 16, 22, 25, 26, 26, 23, 29, 21, 27, 32, 38, 42, 23, 39, 27,
30, 15, 36, 18, 28, 23, 35, 34, 25, 23, 31, 28, 24, 35, 19, 24,
25, 30, 18, 23, 26, 28, 24, 20, 29, 29, 35, 26, 26, 29, 27, 22,
28, 34, 33, 31, 27, 24, 31, 32, 29, 45, 41, 28, 26, 34, 26, 24,
22, 29, 31, 22, 24, 27, 29, 30, 24, 40, 26, 29, 28, 22, 24, 23,
32, 30, 25, 27, 31, 28, 20, 24, 31, 35, 21, 27, 27, 24, 44, 42,
20, 18, 20, 33, 38, 33, 24, 25, 24, 37, 32, 28, 33, 35, 28, 34,
34, 28, 31, 36, 27, 33, 26, 34, 39, 39, 42, 33, 34, 40, 20, 29,
32, 38, 27, 25, 28, 34, 26, 38, 30, 26, 38, 37, 37, 42, 33, 27,
43, 36, 35, 32, 35, 36, 28, 39, 28, 38, 35, 35, 39, 41, 33, 38,
38, 29, 30, 31, 37, 31, 34, 32, 31, 43, 36, 40, 29, 28, 28, 35,
35, 31, 32, 32, 35, 31, 35, 35, 28, 34, 33, 30, 31, 36, 42, 27,
34, 30, 35, 35, 31, 37, 45, 38, 39, 35, 35, 31, 25, 35, 38, 30,
37, 36, 22, 33, 37, 32, 33, 30, 33, 33, 37, 40, 31, 37, 35, 35,
33, 29, 31, 38, 33, 34, 35, 43, 33, 30, 38, 28, 35, 35, 38, 32,
31, 36, 30, 38, 30, 27, 32, 38, 24, 36, 31, 33, 36, 31, 26, 36,
34, 27, 33, 35, 37, 30, 27, 36, 27, 24, 29, 33, 33, 35, 39, 37,
26, 35, 29, 31, 36, 31, 36, 30, 32, 33, 26, 34, 25, 27, 31, 24,
31, 36, 31, 32, 34, 27, 43, 35, 36, 37, 26, 26, 35, 25, 32, 26,
41, 36, 30, 34, 32, 25, 25, 30, 32, 34, 29, 32, 34, 30, 31, 31,
30, 30, 25, 34, 31, 36, 39, 36, 30, 32, 33, 32, 34, 39, 46, 32,
39, 33, 33, 26, 29, 24, 22, 31, 31, 28, 37, 25, 37, 33, 37, 29,
35, 36, 31, 34, 25, 41, 29, 31, 28, 33, 27, 24, 41, 28, 30, 35,
35, 36, 29, 41, 32, 30, 29, 30, 33, 31, 33, 30, 30, 33, 32, 34,
29, 29, 30, 25, 36, 34, 37, 35, 28, 27, 30, 30, 34, 32, 30, 37,
33, 35, 39, 33, 38, 28, 30, 33, 35, 38, 36, 32, 32, 25, 30, 34,
34, 30, 31, 31, 31, 25, 33, 41, 60, 29, 34, 37, 31, 34, 26, 26,
25, 30, 29, 37, 32, 26, 36, 36, 31, 33, 24, 39, 33, 39, 34, 32,
26, 32, 31, 37, 33, 30, 34, 28, 32, 30, 41, 29, 37, 33, 39, 30,
30, 30, 28, 44, 34, 40, 32, 34, 27, 38, 27, 38, 32, 36, 41, 24,
24, 30, 33, 34, 40, 39, 33, 39, 37, 31, 40, 37, 29, 30, 32, 32,
31, 27, 27, 35, 39, 37, 32, 31, 41, 29, 31, 32, 37, 32, 37, 37,
42, 33, 36, 32, 37, 28, 40, 23, 38, 34, 29, 29, 30, 30, 37, 32,
29, 36, 27, 33, 31, 35, 41, 30, 34, 35, 41, 33, 33, 34, 31, 37,
31, 27, 37, 34, 33, 38, 54, 29, 30, 33, 31, 34, 29, 28, 33, 26,
25, 32, 33, 34, 30, 32, 29, 40, 35, 40, 45, 39, 25, 37, 27, 37,
33, 37, 37, 33, 34, 35, 35, 36, 31, 34, 30, 34, 40, 34, 34, 36,
33, 31, 38, 36, 43, 43, 44, 26, 24, 40, 33, 32, 36, 36, 35, 40,
32, 37, 36, 42, 43, 39, 42, 36, 32, 38, 30, 40, 31, 35, 35, 33,
35, 34, 40, 36, 32, 30, 36, 41, 45, 37, 43, 33, 38, 37, 37, 40,
37, 35, 28, 32, 42, 38, 39, 47, 35, 37, 34, 33, 32, 30, 37, 30,
37, 32, 36, 39, 37, 26, 50, 32, 37, 33, 38, 35, 25, 34, 44, 31,
46, 36, 32, 41, 36, 34, 33, 31, 46, 33, 40, 38, 40, 29, 32, 35,
38, 35, 39, 40, 39, 25, 32, 28, 31, 35, 39, 30, 30, 31, 29, 31,
34, 38, 30, 31, 35, 32, 33, 33, 31, 36, 38, 33, 35, 35, 38, 38,
41, 31, 29, 30, 35, 30, 33, 35, 37, 36, 31, 32, 35, 29, 28, 31,
37, 30, 30, 30, 29, 38, 43, 29, 36, 27, 33, 36, 38, 36, 35, 26,
32, 35, 26, 35, 29, 44, 29, 37, 33, 35, 33, 34, 33, 32, 31, 32,
38, 32, 34, 37, 37, 35, 37, 28, 33, 41, 26, 28, 28, 36, 35, 32,
33, 40, 28, 35, 38, 34, 25, 27, 38, 38, 26, 35, 26, 41, 32, 28,
35, 37, 28, 36, 35, 38, 32, 39, 43, 39, 32, 33, 32, 31, 34, 36,
29, 31, 41, 31, 31, 34, 25, 30, 39, 28, 38, 38, 33, 35, 39, 31,
34, 28, 30, 35, 35, 39, 35, 36, 35, 38, 25, 31, 38, 17, 35, 40,
35, 35, 27, 35, 33, 33, 41, 30, 43, 32, 36, 37, 26, 25, 33, 41,
34, 35, 43, 28, 30, 31, 36, 38, 32, 27, 39, 41, 37, 39, 40, 34,
28, 29, 37, 33, 30, 40, 37, 38, 36, 35, 39, 29, 33, 31, 33, 40,
34, 30, 39, 33, 26, 39, 40, 42, 45, 38, 31, 39, 33, 42, 35, 41,
35, 44, 40, 36, 28, 36, 39, 33, 43, 37, 32, 40, 38, 31, 28, 26,
33, 31, 40, 30, 40, 34, 37, 31, 27, 38, 35, 36, 34, 39, 40, 46,
37, 39, 45, 38, 33, 31, 31, 34, 34, 34, 36, 33, 42, 37, 41, 42,
34, 46, 47, 40)), .Names = c("age", "male", "cardio", "reject",
"HC"), row.names = c(NA, -1158L), class = c("tbl_df", "tbl",
"data.frame"))
Call:
glm(formula = reject ~ age + male, family = binomial(link = logit),
data = renal_reduced)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.2720 -0.8767 -0.7359 1.3006 1.9346
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.787319 0.238605 3.300 0.000968 ***
age -0.031540 0.004882 -6.461 1.04e-10 ***
male -0.220705 0.129800 -1.700 0.089065 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 1444.1 on 1156 degrees of freedom
Residual deviance: 1397.9 on 1154 degrees of freedom
AIC: 1403.9
Number of Fisher Scoring iterations: 4
在变量选择过程之后,我检查了使用Hosmer.Lemeshow测试正确指定了模型。没有证据表明配合不合适,并且模型已正确指定。
> hosmerlem = function(y, yhat, g=10)
+ {cutyhat = cut(yhat,breaks = quantile(yhat, probs=seq(0,1, 1/g)),
+ include.lowest=TRUE)
+ obs = xtabs(cbind(1 - y, y) ~ cutyhat)
+ expect = xtabs(cbind(1 - yhat, yhat) ~ cutyhat)
+ chisq = sum((obs - expect)^2/expect)
+ P = 1 - pchisq(chisq, g - 2)
+ return(list(chisq=chisq,p.value=P))}
>
> hosmerlem(y=reject, yhat=fitted(final_logit))
$chisq
[1] 8.603617
$p.value
[1] 0.3768288
然后,我使用NagelkerkeR2
评估了预测质量。这表明该模型不适合预测。只有5%的病例被正确预测。
> NagelkerkeR2(final_logit)
$N
[1] 1157
$R2
[1] 0.054879
最后,我根据一致或不一致的对评估了一致性度量:
OptimisedConc=function(final_logit)
{
Data = cbind(final_logit$y, final_logit$fitted.values)
ones = Data[Data[,1] == 1,]
zeros = Data[Data[,1] == 0,]
conc=matrix(0, dim(zeros)[1], dim(ones)[1])
disc=matrix(0, dim(zeros)[1], dim(ones)[1])
ties=matrix(0, dim(zeros)[1], dim(ones)[1])
for (j in 1:dim(zeros)[1])
{
for (i in 1:dim(ones)[1])
{
if (ones[i,2]>zeros[j,2])
{conc[j,i]=1}
else if (ones[i,2]<zeros[j,2])
{disc[j,i]=1}
else if (ones[i,2]==zeros[j,2])
{ties[j,i]=1}
}
}
Pairs=dim(zeros)[1]*dim(ones)[1]
PercentConcordance=(sum(conc)/Pairs)*100
PercentDiscordance=(sum(disc)/Pairs)*100
PercentTied=(sum(ties)/Pairs)*100
return(list("Percent Concordance"=PercentConcordance,"Percent Discordance"=PercentDiscordance,"Percent Tied"=PercentTied,"Pairs"=Pairs))
}
OptimisedConc(final_logit)
$`Percent Concordance`
[1] 61.65572
$`Percent Discordance`
[1] 37.3367
$`Percent Tied`
[1] 1.007578
$Pairs
[1] 289506
如果我正确地解释它说我的预测只有0.616对与观察结果的方向相同。这是通过以下方式计算的:
C = 61.65572 /(61.65572 + 1.007578 + 289506)
为什么我的模型被正确指定但预测质量如此糟糕?
答案 0 :(得分:4)
这个问题与编程或R没有任何关系,所以它是stackoverflow的主题。但是,这是一个具有相同行为的非常简单的示例:
set.seed(23)
X <- runif(100)
Y <- rbinom(100, 1, X)
mod <- glm(Y ~ X, family = binomial)
summary(mod)
table(Y, X > 0.5) # pick a cut-off
在glm
模型中,我们正在测试假设,“Y=1
取决于自变量的概率是否存在差异?”答案显然是肯定的 - 它是这样设计的!
对于预测,我们会问“我们如何使用Y
预测X
?”这是一个更高的标准 - 不仅需要有差异,而且需要足够大,以至于两组之间没有太多重叠。在我的小例子中(显然你的设置要复杂得多),你没有那个。两组之间仍有很多重叠。