5
$\begingroup$

I have the following data frame

structure(list(Chi = structure(c(1L, 1L, 5L, 5L, 6L, 9L, 9L, 
12L, 13L, 14L, 14L, 16L, 16L, 19L, 19L, 20L, 20L, 23L, 24L, 24L, 
26L, 26L, 31L, 31L, 33L, 33L, 36L, 37L, 37L, 40L, 40L, 43L, 43L, 
44L, 44L, 45L, 46L, 47L, 47L, 48L, 48L, 52L, 52L, 54L, 54L, 55L, 
55L, 56L, 59L, 59L, 61L, 61L, 63L, 63L, 64L, 64L, 65L, 65L, 69L, 
69L, 70L, 70L, 71L, 71L, 72L, 72L, 75L, 75L, 76L, 76L, 77L, 77L, 
79L, 79L, 86L, 86L, 87L, 87L, 88L, 88L, 91L, 91L, 92L, 92L, 93L, 
95L, 96L, 96L, 97L, 97L, 98L, 98L, 99L, 99L, 100L, 100L, 101L, 
101L, 103L, 103L, 104L, 104L, 107L, 108L, 108L, 112L, 112L, 113L, 
116L, 116L, 117L, 120L, 125L, 125L, 127L, 127L, 129L, 129L, 130L, 
131L, 131L, 132L, 132L, 134L, 134L, 135L, 135L, 136L, 136L, 139L, 
141L, 141L, 143L, 144L, 144L, 145L, 145L, 146L, 150L, 150L, 151L, 
151L, 153L, 153L, 155L, 155L, 157L, 162L, 162L, 163L, 163L, 164L, 
164L, 167L, 167L, 168L, 169L, 169L, 171L, 171L, 172L, 172L, 174L, 
174L, 175L, 175L, 177L, 177L, 180L, 180L, 183L, 187L, 27L, 83L, 
83L, 165L, 165L, 85L, 85L, 156L, 156L, 17L, 17L, 123L, 123L, 
124L, 124L, 57L, 57L, 42L, 42L, 159L, 159L, 38L, 38L, 82L, 82L, 
41L, 41L, 142L, 142L), .Label = c("0106610856", "0107470802", 
"0108490513", "0108590534", "0109480651", "0111290260", "0111410339", 
"0201390418", "0207570604", "0208360352", "0212323105", "0212380362", 
"0301310432", "0302705635", "0303450495", "0304260266", "0304440574", 
"0305280546", "0305380338", "0305381393", "0305510576", "0305542214", 
"0308610733", "0309370345", "0309665035", "0310380545", "0403320259", 
"0403360374", "0404360343", "0406270198", "0501451137", "0504460676", 
"0511310366", "0605270511", "0605340560", "0605410461", "0605410585", 
"0606260684", "0606270353", "0609360507", "0702520535", "0702570818", 
"0705430421", "0710380364", "0801330378", "0801430275", "0802320430", 
"0803510802", "0805390383", "0806560533", "0809430460", "0902380354", 
"0904340252", "0904370445", "0906340403", "0907380379", "0909415420", 
"0910300100", "0911430253", "1001270460", "1001360389", "1002455294", 
"1005280487", "1006330445", "1009350447", "1010375156", "1011270447", 
"1012350312", "1012400441", "1102570648", "1105450589", "1106230566", 
"1106330587", "1204530475", "1206350342", "1208330373", "1209280345", 
"1209400502", "1209400561", "1210380536", "1302240455", "1305751256", 
"1306370353", "1307260470", "1310340250", "1312430613", "1312440597", 
"1312690593", "1404430512", "1404530479", "1405330376", "1406310360", 
"1406350419", "1406430439", "1408460602", "1412360366", "1502385236", 
"1503370488", "1503470628", "1503660400", "1506390447", "1508340196", 
"1510340688", "1510440453", "1603310622", "1604440376", "1606370014", 
"1609650549", "1610345304", "1610345304x", "1612300367", "1702330397", 
"1704330181", "1706330316", "1712560522", "1802340270", "1804310336", 
"1808430417", "1810400244", "1902340299", "1902610679", "1905360355", 
"1906320438", "1906390525", "1909310514", "1912460408", "2002440204", 
"2004350288", "2007350203", "2009400364", "2009460669", "2011410428", 
"2011500524", "2103335236", "2109370262", "2112290355", "2201330484", 
"2201600686", "2203290471", "2203406259", "2205430513", "2207340473", 
"2208340396", "2303430410", "2303530717", "2308290390", "2309420506", 
"2310370398", "2310370398.0", "2312280310", "2404436295", "2406640663", 
"2411420404", "2501520858", "2505330239", "2505380376", "2511320428", 
"2511320436", "2511360306", "2601490470", "2601520566", "2608450598", 
"2611400237", "2701470625", "2702230407", "2702340342", "2703470916", 
"2704380538", "2709250586", "2712350545", "2712541146", "2805310438", 
"2805350472", "2807360475", "2807480594", "2809325316", "2809470634", 
"2902400411", "2903350442", "2905330376", "2906450480", "2910240363", 
"3004510529", "3007230195", "3012410333", "3107440299", "3108350420"
), class = "factor"), Sex = structure(c(2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 
1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L), .Label = c("F", "M"), class = "factor"), Age = c(50L, 
50L, 63L, 63L, 83L, 55L, 55L, 72L, 81L, 42L, 42L, 86L, 86L, 74L, 
74L, 74L, 74L, 50L, 74L, 74L, 73L, 73L, 67L, 67L, 79L, 79L, 71L, 
70L, 70L, 75L, 75L, 68L, 68L, 73L, 73L, 79L, 69L, 79L, 79L, 61L, 
61L, 74L, 74L, 74L, 74L, 77L, 77L, 73L, 68L, 68L, 76L, 76L, 84L, 
84L, 78L, 78L, 77L, 77L, 71L, 71L, 55L, 55L, 67L, 67L, 88L, 88L, 
77L, 77L, 78L, 78L, 84L, 84L, 71L, 71L, 69L, 69L, 67L, 67L, 41L, 
41L, 78L, 78L, 80L, 80L, 76L, 66L, 76L, 76L, 73L, 73L, 74L, 74L, 
64L, 64L, 46L, 46L, 72L, 72L, 78L, 78L, 67L, 67L, 74L, 47L, 47L, 
79L, 79L, 79L, 78L, 78L, 81L, 77L, 79L, 79L, 67L, 67L, 76L, 76L, 
70L, 64L, 64L, 70L, 70L, 79L, 79L, 74L, 74L, 82L, 82L, 83L, 69L, 
69L, 76L, 69L, 69L, 58L, 58L, 83L, 83L, 83L, 68L, 68L, 69L, 69L, 
79L, 79L, 79L, 66L, 66L, 70L, 70L, 65L, 65L, 65L, 65L, 72L, 87L, 
87L, 57L, 57L, 80L, 80L, 76L, 76L, 63L, 63L, 64L, 64L, 78L, 78L, 
60L, 76L, 80L, 75L, 75L, 90L, 90L, 78L, 78L, 74L, 74L, 69L, 69L, 
80L, 80L, 73L, 73L, 71L, 71L, 56L, 56L, 76L, 76L, 87L, 87L, 38L, 
38L, 61L, 61L, 78L, 78L), SBR = c(12.061, 11.447, 9.403, 9.136, 
9.747, 8.648, 7.934, 7.914, 9.349, 11.224, 10.433, 4.897, 5.823, 
8.683, 8.692, 13.018, 13.386, 7.817, 7.384, 7.518, 11.091, 11.028, 
8.372, 8.497, 10.751, 10.488, 4.347, 2.593, 2.203, 6.461, 7.272, 
4.581, 4.593, 10.31, 9.004, 10.362, 10.307, 9.266, 10.163, 9.24, 
8.732, 8.449, 7.823, 10.427, 10.669, 8.695, 8.729, 8.653, 12.299, 
12.158, 11.748, 11.19, 8.431, 8.717, 8.253, 8.412, 6.911, 6.805, 
9.468, 11.413, 6.603, 7.697, 7.762, 7.097, 10.607, 8.162, 5.419, 
5.575, 7.007, 6.974, 8.708, 8.419, 9.47, 8.42, 8.229, 8.027, 
5.294, 4.628, 11.475, 10.328, 7.905, 8.491, 10.724, 9.02, 9.095, 
5.754, 9.805, 7.332, 6.669, 5.118, 12.443, 11.972, 13.309, 13.906, 
14.963, 15.119, 6.465, 6.38, 6.949, 6.064, 6.541, 6.648, 3.542, 
11.148, 11.918, 9.743, 9.795, 6.103, 6.025, 3.917, 7.304, 7.628, 
8.092, 7.347, 9.051, 8.206, 10.697, 10.286, 4.564, 10.62, 9.84, 
9.105, 7.998, 6.437, 5.707, 6.949, 6.315, 6.165, 6.68, 8.86, 
8.326, 8.6, 7.776, 5.193, 5.456, 11.864, 11.381, 6.385, 10.972, 
9.87, 9.645, 7.738, 10.096, 9.667, 9.687, 8.255, 4.606, 8.738, 
8.519, 7.002, 6.288, 10.425, 10.303, 8.278, 8.342, 6.657, 6.111, 
5.928, 13.06, 12.747, 5.545, 5.845, 9.338, 9.534, 9.635, 8.716, 
7.765, 7.254, 7.517, 7.317, 7.335, 5.628, 4.864, 7.1, 7.02, 6.734, 
5.622, 7.167, 7.391, 6.443, 6.874, 8.373, 7.573, 5.701, 6.355, 
6.884, 6.296, 9.097, 9.645, 7.068, 7.252, 6, 5.794, 8.074, 9.267, 
12.584, 10.723, 9.39, 9.165, 9.635, 8.814), Diagnosis = structure(c(2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "N"), class = "factor"), 
    fit = c(10.1654358296645, 10.1654358296645, 9.07109655193284, 
    9.07109655193284, 7.38749766311491, 9.74453610746002, 9.74453610746002, 
    8.31347705196477, 7.5558575519967, 10.8388753851917, 10.8388753851917, 
    7.13495782979222, 7.13495782979222, 8.14511716308298, 8.14511716308298, 
    8.14511716308298, 8.14511716308298, 10.1654358296645, 8.14511716308298, 
    8.14511716308298, 8.22929710752388, 8.22929710752388, 8.73437677416926, 
    8.73437677416926, 7.7242174408785, 7.7242174408785, 8.39765699640567, 
    8.48183694084657, 8.48183694084657, 8.06093721864208, 8.06093721864208, 
    8.65019682972836, 8.65019682972836, 8.22929710752388, 8.22929710752388, 
    7.7242174408785, 8.56601688528746, 7.7242174408785, 7.7242174408785, 
    9.23945644081464, 9.23945644081464, 8.14511716308298, 8.14511716308298, 
    8.14511716308298, 8.14511716308298, 7.89257732976029, 7.89257732976029, 
    8.22929710752388, 8.65019682972836, 8.65019682972836, 7.97675727420119, 
    7.97675727420119, 7.30331771867401, 7.30331771867401, 7.80839738531939, 
    7.80839738531939, 7.89257732976029, 7.89257732976029, 8.39765699640567, 
    8.39765699640567, 9.74453610746002, 9.74453610746002, 8.73437677416926, 
    8.73437677416926, 6.96659794091043, 6.96659794091043, 7.89257732976029, 
    7.89257732976029, 7.80839738531939, 7.80839738531939, 7.30331771867401, 
    7.30331771867401, 8.39765699640567, 8.39765699640567, 8.56601688528746, 
    8.56601688528746, 8.73437677416926, 8.73437677416926, 10.9230553296326, 
    10.9230553296326, 7.80839738531939, 7.80839738531939, 7.6400374964376, 
    7.6400374964376, 7.97675727420119, 8.81855671861015, 7.97675727420119, 
    7.97675727420119, 8.22929710752388, 8.22929710752388, 8.14511716308298, 
    8.14511716308298, 8.98691660749195, 8.98691660749195, 10.5021556074281, 
    10.5021556074281, 8.31347705196477, 8.31347705196477, 7.80839738531939, 
    7.80839738531939, 8.73437677416926, 8.73437677416926, 8.14511716308298, 
    10.4179756629872, 10.4179756629872, 7.7242174408785, 7.7242174408785, 
    7.7242174408785, 7.80839738531939, 7.80839738531939, 7.5558575519967, 
    7.89257732976029, 7.7242174408785, 7.7242174408785, 8.73437677416926, 
    8.73437677416926, 7.97675727420119, 7.97675727420119, 8.48183694084657, 
    8.98691660749195, 8.98691660749195, 8.48183694084657, 8.48183694084657, 
    7.7242174408785, 7.7242174408785, 8.14511716308298, 8.14511716308298, 
    7.47167760755581, 7.47167760755581, 7.38749766311491, 8.56601688528746, 
    8.56601688528746, 7.97675727420119, 8.56601688528746, 8.56601688528746, 
    9.49199627413733, 9.49199627413733, 7.38749766311491, 7.38749766311491, 
    7.38749766311491, 8.65019682972836, 8.65019682972836, 8.56601688528746, 
    8.56601688528746, 7.7242174408785, 7.7242174408785, 7.7242174408785, 
    8.81855671861015, 8.81855671861015, 8.48183694084657, 8.48183694084657, 
    8.90273666305105, 8.90273666305105, 8.90273666305105, 8.90273666305105, 
    8.31347705196477, 7.05077788535132, 7.05077788535132, 9.57617621857822, 
    9.57617621857822, 7.6400374964376, 7.6400374964376, 7.97675727420119, 
    7.97675727420119, 9.07109655193284, 9.07109655193284, 8.98691660749195, 
    8.98691660749195, 7.80839738531939, 7.80839738531939, 9.32363638525553, 
    7.97675727420119, 7.6400374964376, 8.06093721864208, 8.06093721864208, 
    6.79823805202863, 6.79823805202863, 7.80839738531939, 7.80839738531939, 
    8.14511716308298, 8.14511716308298, 8.56601688528746, 8.56601688528746, 
    7.6400374964376, 7.6400374964376, 8.22929710752388, 8.22929710752388, 
    8.39765699640567, 8.39765699640567, 9.66035616301912, 9.66035616301912, 
    7.97675727420119, 7.97675727420119, 7.05077788535132, 7.05077788535132, 
    11.1755951629553, 11.1755951629553, 9.23945644081464, 9.23945644081464, 
    7.80839738531939, 7.80839738531939), lwr = c(5.90999794584117, 
    5.90999794584117, 4.85411038352648, 4.85411038352648, 3.16383967274129, 
    5.5078318233643, 5.5078318233643, 4.10340735387365, 3.33646831235876, 
    6.54339594841324, 6.54339594841324, 2.90340734886211, 2.90340734886211, 
    3.93437871118446, 3.93437871118446, 3.93437871118446, 3.93437871118446, 
    5.90999794584117, 3.93437871118446, 3.93437871118446, 4.01899333351728, 
    4.01899333351728, 4.52246825860982, 4.52246825860982, 3.50829974380329, 
    3.50829974380329, 4.18762073879345, 4.27163348349591, 4.27163348349591, 
    3.84956354899072, 3.84956354899072, 4.43905717652239, 4.43905717652239, 
    4.01899333351728, 4.01899333351728, 3.50829974380329, 4.35544561188301, 
    3.50829974380329, 3.50829974380329, 5.0187327527967, 5.0187327527967, 
    3.93437871118446, 3.93437871118446, 3.93437871118446, 3.93437871118446, 
    3.67933199647321, 3.67933199647321, 4.01899333351728, 4.43905717652239, 
    4.43905717652239, 3.76454793766266, 3.76454793766266, 3.07722713717148, 
    3.07722713717148, 3.59391587315661, 3.59391587315661, 3.67933199647321, 
    3.67933199647321, 4.18762073879345, 4.18762073879345, 5.5078318233643, 
    5.5078318233643, 4.52246825860982, 4.52246825860982, 2.72879720476565, 
    2.72879720476565, 3.67933199647321, 3.67933199647321, 3.59391587315661, 
    3.59391587315661, 3.07722713717148, 3.07722713717148, 4.18762073879345, 
    4.18762073879345, 4.35544561188301, 4.35544561188301, 4.52246825860982, 
    4.52246825860982, 6.62171309179384, 6.62171309179384, 3.59391587315661, 
    3.59391587315661, 3.42248381273475, 3.42248381273475, 3.76454793766266, 
    4.60567896791123, 3.76454793766266, 3.76454793766266, 4.01899333351728, 
    4.01899333351728, 3.93437871118446, 3.93437871118446, 4.77149984958079, 
    4.77149984958079, 6.22823093408572, 6.22823093408572, 4.10340735387365, 
    4.10340735387365, 3.59391587315661, 3.59391587315661, 4.52246825860982, 
    4.52246825860982, 3.93437871118446, 6.14896197954192, 6.14896197954192, 
    3.50829974380329, 3.50829974380329, 3.50829974380329, 3.59391587315661, 
    3.59391587315661, 3.33646831235876, 3.67933199647321, 3.50829974380329, 
    3.50829974380329, 4.52246825860982, 4.52246825860982, 3.76454793766266, 
    3.76454793766266, 4.27163348349591, 4.77149984958079, 4.77149984958079, 
    4.27163348349591, 4.27163348349591, 3.50829974380329, 3.50829974380329, 
    3.93437871118446, 3.93437871118446, 3.25025350300496, 3.25025350300496, 
    3.16383967274129, 4.35544561188301, 4.35544561188301, 3.76454793766266, 
    4.35544561188301, 4.35544561188301, 5.26417374160422, 5.26417374160422, 
    3.16383967274129, 3.16383967274129, 3.16383967274129, 4.43905717652239, 
    4.43905717652239, 4.35544561188301, 4.35544561188301, 3.50829974380329, 
    3.50829974380329, 3.50829974380329, 4.60567896791123, 4.60567896791123, 
    4.27163348349591, 4.27163348349591, 4.68868944268447, 4.68868944268447, 
    4.68868944268447, 4.68868944268447, 4.10340735387365, 2.81620086292774, 
    2.81620086292774, 5.34559069482765, 5.34559069482765, 3.42248381273475, 
    3.42248381273475, 3.76454793766266, 3.76454793766266, 4.85411038352648, 
    4.85411038352648, 4.77149984958079, 4.77149984958079, 3.59391587315661, 
    3.59391587315661, 5.10074511800645, 3.76454793766266, 3.42248381273475, 
    3.84956354899072, 3.84956354899072, 2.55340019612735, 2.55340019612735, 
    3.59391587315661, 3.59391587315661, 3.93437871118446, 3.93437871118446, 
    4.35544561188301, 4.35544561188301, 3.42248381273475, 3.42248381273475, 
    4.01899333351728, 4.01899333351728, 4.18762073879345, 4.18762073879345, 
    5.42680991723477, 5.42680991723477, 3.76454793766266, 3.76454793766266, 
    2.81620086292774, 2.81620086292774, 6.85553891121225, 6.85553891121225, 
    5.0187327527967, 5.0187327527967, 3.59391587315661, 3.59391587315661
    ), upr = c(14.4208737134878, 14.4208737134878, 13.2880827203392, 
    13.2880827203392, 11.6111556534885, 13.9812403915557, 13.9812403915557, 
    12.5235467500559, 11.7752467916346, 15.1343548219701, 15.1343548219701, 
    11.3665083107223, 11.3665083107223, 12.3558556149815, 12.3558556149815, 
    12.3558556149815, 12.3558556149815, 14.4208737134878, 12.3558556149815, 
    12.3558556149815, 12.4396008815305, 12.4396008815305, 12.9462852897287, 
    12.9462852897287, 11.9401351379537, 11.9401351379537, 12.6076932540179, 
    12.6920403981972, 12.6920403981972, 12.2723108882934, 12.2723108882934, 
    12.8613364829343, 12.8613364829343, 12.4396008815305, 12.4396008815305, 
    11.9401351379537, 12.7765881586919, 11.9401351379537, 11.9401351379537, 
    13.4601801288326, 13.4601801288326, 12.3558556149815, 12.3558556149815, 
    12.3558556149815, 12.3558556149815, 12.1058226630474, 12.1058226630474, 
    12.4396008815305, 12.8613364829343, 12.8613364829343, 12.1889666107397, 
    12.1889666107397, 11.5294083001765, 11.5294083001765, 12.0228788974822, 
    12.0228788974822, 12.1058226630474, 12.1058226630474, 12.6076932540179, 
    12.6076932540179, 13.9812403915557, 13.9812403915557, 12.9462852897287, 
    12.9462852897287, 11.2043986770552, 11.2043986770552, 12.1058226630474, 
    12.1058226630474, 12.0228788974822, 12.0228788974822, 11.5294083001765, 
    11.5294083001765, 12.6076932540179, 12.6076932540179, 12.7765881586919, 
    12.7765881586919, 12.9462852897287, 12.9462852897287, 15.2243975674713, 
    15.2243975674713, 12.0228788974822, 12.0228788974822, 11.8575911801404, 
    11.8575911801404, 12.1889666107397, 13.0314344693091, 12.1889666107397, 
    12.1889666107397, 12.4396008815305, 12.4396008815305, 12.3558556149815, 
    12.3558556149815, 13.2023333654031, 13.2023333654031, 14.7760802807705, 
    14.7760802807705, 12.5235467500559, 12.5235467500559, 12.0228788974822, 
    12.0228788974822, 12.9462852897287, 12.9462852897287, 12.3558556149815, 
    14.6869893464325, 14.6869893464325, 11.9401351379537, 11.9401351379537, 
    11.9401351379537, 12.0228788974822, 12.0228788974822, 11.7752467916346, 
    12.1058226630474, 11.9401351379537, 11.9401351379537, 12.9462852897287, 
    12.9462852897287, 12.1889666107397, 12.1889666107397, 12.6920403981972, 
    13.2023333654031, 13.2023333654031, 12.6920403981972, 12.6920403981972, 
    11.9401351379537, 11.9401351379537, 12.3558556149815, 12.3558556149815, 
    11.6931017121067, 11.6931017121067, 11.6111556534885, 12.7765881586919, 
    12.7765881586919, 12.1889666107397, 12.7765881586919, 12.7765881586919, 
    13.7198188066704, 13.7198188066704, 11.6111556534885, 11.6111556534885, 
    11.6111556534885, 12.8613364829343, 12.8613364829343, 12.7765881586919, 
    12.7765881586919, 11.9401351379537, 11.9401351379537, 11.9401351379537, 
    13.0314344693091, 13.0314344693091, 12.6920403981972, 12.6920403981972, 
    13.1167838834176, 13.1167838834176, 13.1167838834176, 13.1167838834176, 
    12.5235467500559, 11.2853549077749, 11.2853549077749, 13.8067617423288, 
    13.8067617423288, 11.8575911801404, 11.8575911801404, 12.1889666107397, 
    12.1889666107397, 13.2880827203392, 13.2880827203392, 13.2023333654031, 
    13.2023333654031, 12.0228788974822, 12.0228788974822, 13.5465276525046, 
    12.1889666107397, 11.8575911801404, 12.2723108882934, 12.2723108882934, 
    11.0430759079299, 11.0430759079299, 12.0228788974822, 12.0228788974822, 
    12.3558556149815, 12.3558556149815, 12.7765881586919, 12.7765881586919, 
    11.8575911801404, 11.8575911801404, 12.4396008815305, 12.4396008815305, 
    12.6076932540179, 12.6076932540179, 13.8939024088035, 13.8939024088035, 
    12.1889666107397, 12.1889666107397, 11.2853549077749, 11.2853549077749, 
    15.4956514146983, 15.4956514146983, 13.4601801288326, 13.4601801288326, 
    12.0228788974822, 12.0228788974822)), .Names = c("Chi", "Sex", 
"Age", "SBR", "Diagnosis", "fit", "lwr", "upr"), row.names = c(NA, 
201L), class = "data.frame")

I plot SBR v Age for each Sex using ggplot2

p <- ggplot(sbr_with_pred, aes(x=Age, y=SBR)) + geom_point(aes(col=Sex), 
                                                           shape=19, alpha=0.4) + 
            geom_smooth(aes(col=Sex),method = 'lm', se=FALSE,linetype=2) + 
            geom_ribbon(aes(y = fit, ymin = lwr, ymax = upr, fill = 'prediction'), 
                        linetype =2,alpha = 0.1) + 
            scale_fill_manual('Interval', values = c('blue')) + theme_bw() + 
            theme(legend.position = "right") + 
            scale_y_continuous(limits = c(-3,15.5),breaks = c(0,5,10,15)) + 
            scale_color_manual("Sex", values = c('red','blue'))

which gives the following

enter image description here

I can get the equation of each regression fit easy enough

lm(formula = SBR ~ Age, data = subset(sbr_with_pred, Sex == "F"))
lm(formula = SBR ~ Age, data = subset(sbr_with_pred, Sex == "M"))

However how do I test whether or not they are significantly different (which they are not). I think analysis of covariance is the appropriate test but I do not know how to implement this in R

$\endgroup$
2
  • $\begingroup$ "analysis of covariance" is not a test. $\endgroup$
    – PAC
    Aug 1, 2013 at 14:58
  • $\begingroup$ For wannabe econometricians who ended up here, you may find this thread useful! stats.stackexchange.com/questions/33013/… $\endgroup$
    – lomper
    Dec 20, 2021 at 10:57

3 Answers 3

4
$\begingroup$

You have to use a Chow test (wikipedia). It's an application of the Fisher test to test the equality of coefficients among two groups of individuals. You can compute it easily using the sum of squared residuals of each model.

See my gist file to see how I compute the Chow test. In your case, the null hypothesis of equality of coefficients among the two groups cannot be rejected.

$\endgroup$
2
  • 2
    $\begingroup$ The gist file link in this answer is no longer accessible. Is it possible to have the code for the answer here? $\endgroup$
    – lomper
    Dec 20, 2021 at 10:49
  • $\begingroup$ @lomper I saw this related link for Chow test ( link). $\endgroup$ Jun 29, 2022 at 17:27
9
$\begingroup$

You would do best to test for a difference in slopes by including sex and a sex:Age interaction in a multiple regression analysis. The t-test of the interaction term will assess whether or not the slopes differ significantly. The R code for your situation would be (I'm guessing):

lm(formula = SBR ~ Sex + Age + Sex:Age, data = sbr_with_pred)
$\endgroup$
1
  • 2
    $\begingroup$ For clarification, the difference between this solution and mine (see below), is that I test the equality of all coefficients (intercept + slope) whereas @gung test only equality in slope. $\endgroup$
    – PAC
    Aug 1, 2013 at 15:24
4
$\begingroup$

In R you can use anova for an analysis of covariance. I tried quickly with the anova command to run a test with your data but the sample size for the two models are different which gives problems at the moment. Code by PAC also works nicely. Based on gung's answer you can also do an anova test using the following code (also guessing):

library(car)
Anova(lm(SBR~Age*Sex,data=sbr_with_pred))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.