# R语言 泊松回归

2020-09-25 14:40 更新

```log(y) = a + b1x1 + b2x2 + bnxn.....
```

• `y`是响应变量。

• `a``b`是数字系数。

• `x`是预测变量。

## 语法

```glm(formula,data,family)
```

• `formula`是表示变量之间的关系的符号。

• `data`是给出这些变量的值的数据集。

• `family`是 R 语言对象来指定模型的细节。 它的值是“泊松”的逻辑回归。

## 例

### 输入数据

```input <- warpbreaks
```

```      breaks   wool  tension
1     26       A     L
2     30       A     L
3     54       A     L
4     25       A     L
5     70       A     L
6     52       A     L
```

## 创建回归模型

```output <-glm(formula = breaks ~ wool+tension,
data = warpbreaks,
family = poisson)
print(summary(output))
```

```Call:
glm(formula = breaks ~ wool + tension, family = poisson, data = warpbreaks)

Deviance Residuals:
Min       1Q     Median       3Q      Max
-3.6871  -1.6503  -0.4269     1.1902   4.2616

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)  3.69196    0.04541  81.302  < 2e-16 ***
woolB       -0.20599    0.05157  -3.994 6.49e-05 ***
tensionM    -0.32132    0.06027  -5.332 9.73e-08 ***
tensionH    -0.51849    0.06396  -8.107 5.21e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 297.37  on 53  degrees of freedom
Residual deviance: 210.39  on 50  degrees of freedom
AIC: 493.06

Number of Fisher Scoring iterations: 4
```

App下载