我们没有你的数据,所以让我们做一个显示类似结果的玩具示例。
假设有一个基因有两个等位基因“A”和“B”。等位基因“A”有 20% 的几率患上某种疾病,等位基因“B”有 5% 的几率患上相同的疾病。我们选取了 200 人,其中一半具有等位基因“A”,一半具有等位基因“B”:
set.seed(1)
df <- data.frame(gene = rep(c("A", "B"), each = 100),
disease = c(rbinom(100, 1, 0.2), rbinom(100, 1, 0.05)))
接下来,我们进行逻辑回归以查看两个等位基因之间的发病率是否确实存在差异:
model <- glm(disease ~ gene, data = df, family = binomial)
summary(model)
#>
#> Call:
#> glm(formula = disease ~ gene, family = binomial, data = df)
#>
#> Deviance Residuals:
#> Min 1Q Median 3Q Max
#> -0.6105 -0.6105 -0.2857 -0.2857 2.5373
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|)
#> (Intercept) -1.5856 0.2662 -5.956 2.58e-09 ***
#> geneB -1.5924 0.5756 -2.767 0.00566 **
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for binomial family taken to be 1)
#>
#> Null deviance: 134.37 on 199 degrees of freedom
#> Residual deviance: 124.77 on 198 degrees of freedom
#> AIC: 128.77
#>
#> Number of Fisher Scoring iterations: 6
到目前为止一切顺利。
如果我们使用该模型进行预测,我们会根据每个人的基因型得到预期的患病概率:
predictions <- predict(model, type = "response")
predictions
#> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17
#> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17
#> 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17
#> 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17
#> 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17
#> 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
#> 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.17 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#> 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
#> 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
#> 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
#> 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
#> 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
#> 199 200
#> 0.04 0.04
我们看到,等位基因“A”的人患病的预测概率为 0.17,而等位基因“B”的人患病的预测概率为 0.04。
请注意,由于该疾病在两组中的患病率均低于 50%,大多数预测将高于其实际结果(因为大多数结果为 0,并且所有预测概率都大于零)。
在逻辑回归中,我们试图找到最小化每个数据点与其预测值的平方偏差的概率。因此,没有患病的人会有负残差。所以在这个例子中,就像在你自己的数据中一样,你会得到大量小的负残差,以及少量的大正残差(毕竟残差需要加到零)。
hist(model$residuals)
请注意,如果大多数结果是 1 而不是 0,您会看到大量小的正残差和少量大的负残差的相反模式。
简而言之,根据您的结果数据的分布,预计残差的分布。