R 逻辑回归
[zhaosl@Linuxmg 20180354]$ cat data
gc 1/1 1/2 2/2
case 356 443 136
contrl 158 128 37
R 怎么做逻辑回归
a = read.table("data", header= T, sep = "\t", stringsAsFactors = F)
tt1 <- glm(as.matrix(a[2:3])~c(1,0), family=binomial(link=logit))
> summary(tt1)
Call:
glm(formula = as.matrix(a[2:3]) ~ c(1, 0), family = binomial(link = logit))
Deviance Residuals:
[1] 0 0
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.2106 0.1189 1.771 0.07662 .
c(1, 0) -0.4292 0.1386 -3.097 0.00196 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 9.6487e+00 on 1 degrees of freedom
Residual deviance: -1.5810e-13 on 0 degrees of freedom
AIC: 17.222
Number of Fisher Scoring iterations: 2
#P值
> summary(tt1)$coefficients
Estimate Std. Error z value Pr(>|z|)
(Intercept) 0.2105648 0.1189185 1.770664 0.076616549
c(1, 0) -0.4292038 0.1385927 -3.096871 0.001955746
> summary(tt1)$coefficients[2,4] == summary(tt1)$coefficients[8]
[1] TRUE
#OR值
> exp(coef(tt1))
(Intercept) c(1, 0)
1.2343750 0.6510272
> exp(coef(tt1))[2]
c(1, 0)
0.6510272
#置信区间CI
exp(confint(tt1))
Waiting for profiling to be done...
2.5 % 97.5 %
(Intercept) 0.9784116 1.5602708
c(1, 0) 0.4956864 0.8536914
> exp(confint(tt1))[2,]
Waiting for profiling to be done...
2.5 % 97.5 %
0.4956864 0.8536914