使用 R 确定错误是否服从正态分布:
Using R to determine if errors are normally distributed:
假设我有一个名为 wage 的数据集,如下所示:
wage
# A tibble: 935 x 17
wage hours iq kww educ exper tenure age married black south urban sibs brthord meduc
<int> <int> <int> <int> <int> <int> <int> <int> <fctr> <fctr> <fctr> <fctr> <int> <int> <int>
1 769 40 93 35 12 11 2 31 1 0 0 1 1 2 8
2 808 50 119 41 18 11 16 37 1 0 0 1 1 NA 14
3 825 40 108 46 14 11 9 33 1 0 0 1 1 2 14
4 650 40 96 32 12 13 7 32 1 0 0 1 4 3 12
5 562 40 74 27 11 14 5 34 1 0 0 1 10 6 6
6 1400 40 116 43 16 14 2 35 1 1 0 1 1 2 8
7 600 40 91 24 10 13 0 30 0 0 0 1 1 2 8
8 1081 40 114 50 18 8 14 38 1 0 0 1 2 3 8
9 1154 45 111 37 15 13 1 36 1 0 0 0 2 3 14
10 1000 40 95 44 12 16 16 36 1 0 0 1 1 1 12
# ... with 925 more rows, and 2 more variables: feduc <int>, lwage <dbl>
说我然后看一个简单的线性回归 btw 工资和智商:
m_wage_iq = lm(wage ~ iq, data = wage)
m_wage_iq$coefficients
这给了我:
## (Intercept) iq
## 116.991565 8.303064
我想检查错误是:
ϵi∼N(0,σ2)
我如何使用 R 检查这个?
您可以尝试多种方法。
一种方法是 shapiro.test
来测试正态性。 p.value
大于您的 alpha 水平(通常高达 10%)意味着不能拒绝原假设(即错误呈正态分布)。但是,该测试因样本量而存在偏差,因此您可能希望通过查看 QQ 图来强化您的结果。
您可以通过绘制 m_wage_iq
(plot(m_wage_iq )
) 并查看第二张图来了解这一点。如果您的点大致位于 x=y 线上,则表明误差服从正态分布。
假设我有一个名为 wage 的数据集,如下所示:
wage
# A tibble: 935 x 17
wage hours iq kww educ exper tenure age married black south urban sibs brthord meduc
<int> <int> <int> <int> <int> <int> <int> <int> <fctr> <fctr> <fctr> <fctr> <int> <int> <int>
1 769 40 93 35 12 11 2 31 1 0 0 1 1 2 8
2 808 50 119 41 18 11 16 37 1 0 0 1 1 NA 14
3 825 40 108 46 14 11 9 33 1 0 0 1 1 2 14
4 650 40 96 32 12 13 7 32 1 0 0 1 4 3 12
5 562 40 74 27 11 14 5 34 1 0 0 1 10 6 6
6 1400 40 116 43 16 14 2 35 1 1 0 1 1 2 8
7 600 40 91 24 10 13 0 30 0 0 0 1 1 2 8
8 1081 40 114 50 18 8 14 38 1 0 0 1 2 3 8
9 1154 45 111 37 15 13 1 36 1 0 0 0 2 3 14
10 1000 40 95 44 12 16 16 36 1 0 0 1 1 1 12
# ... with 925 more rows, and 2 more variables: feduc <int>, lwage <dbl>
说我然后看一个简单的线性回归 btw 工资和智商:
m_wage_iq = lm(wage ~ iq, data = wage)
m_wage_iq$coefficients
这给了我:
## (Intercept) iq
## 116.991565 8.303064
我想检查错误是:
ϵi∼N(0,σ2)
我如何使用 R 检查这个?
您可以尝试多种方法。
一种方法是 shapiro.test
来测试正态性。 p.value
大于您的 alpha 水平(通常高达 10%)意味着不能拒绝原假设(即错误呈正态分布)。但是,该测试因样本量而存在偏差,因此您可能希望通过查看 QQ 图来强化您的结果。
您可以通过绘制 m_wage_iq
(plot(m_wage_iq )
) 并查看第二张图来了解这一点。如果您的点大致位于 x=y 线上,则表明误差服从正态分布。