Econometrics/Spring 2017/Linear regression model / Powered by R / Doctors example: bad model / R_LMM.sagews
231 viewsПостроение и анализ ЛММ с помощью R
Подготовка данных
'data.frame': 53 obs. of 4 variables:
$ Index : int 1 2 3 4 5 6 7 8 9 10 ...
$ Retardation.Index : num 2.8 3.1 2.59 3.36 2.8 3.35 2.99 2.99 2.92 3.23 ...
$ Distrust.Index : num 6.1 5.1 6 6.9 7 5.6 6.3 7.2 6.9 6.5 ...
$ Degree.of.Illness.after.6.Months: int 44 25 10 28 25 72 45 25 12 24 ...
Построение ЛММ
Call:
lm(formula = y ~ x1 + x2)
Residuals:
Min 1Q Median 3Q Max
-22.166 -9.484 -2.016 6.412 40.366
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.8253 21.0440 -0.039 0.96887
x1 23.4913 6.8632 3.423 0.00124 **
x2 -7.0591 3.0218 -2.336 0.02354 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 14.91 on 50 degrees of freedom
Multiple R-squared: 0.1989, Adjusted R-squared: 0.1668
F-statistic: 6.206 on 2 and 50 DF, p-value: 0.003913
Проверка нормальности
Shapiro-Wilk normality test
data: y
W = 0.84579, p-value = 7.176e-06
Shapiro-Wilk normality test
data: x1
W = 0.96178, p-value = 0.08797
Shapiro-Wilk normality test
data: x2
W = 0.95222, p-value = 0.03355
Min. 1st Qu. Median Mean 3rd Qu. Max.
-22.170 -9.484 -2.016 0.000 6.412 40.370
Shapiro-Wilk normality test
data: u
W = 0.93689, p-value = 0.007625
One-sample Kolmogorov-Smirnov test
data: u
D = 0.49473, p-value = 1.678e-12
alternative hypothesis: two-sided


Оценка качества модели
[1] "Дисперсия остатков: 213.789820845966"
[1] "MSE = 209.756050641326"
[1] "MAPE = 75.8067348907951"