1.
#### work1
x<-runif(20,-5,5)
e1<-rnorm(20,0,1)
e2<-rt(20,3)
e3<-rchisq(20,3)
y1 <-2+10*x+abs(x)*e1
y2 <-2+10*x+abs(x)*e2
y3 <-2+10*x+abs(x)*e3
lm.model1<-lm(y1~x)
lm.model2<-lm(y2~x)
lm.model3<-lm(y3~x)
summary(lm.model1)
summary(lm.model2)
summary(lm.model3)
Call:
lm(formula = y1 ~ x)
Residuals:
Min 1Q Median 3Q Max
-5.0595 -1.1556 -0.4359 0.4008 5.7312
Coefficients:
Estimate Std. Error t value
(Intercept) 2.8672 0.5511 5.203
x 10.1605 0.2261 44.940
Pr(>|t|)
(Intercept) 6e-05 ***
x <2e-16 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 2.463 on 18 degrees of freedom
Multiple R-squared: 0.9912, Adjusted R-squared: 0.9907
F-statistic: 2020 on 1 and 18 DF, p-value: < 2.2e-16
> summary(lm.model2)
Call:
lm(formula = y2 ~ x)
Residuals:
Min 1Q Median 3Q Max
-12.9291 -2.5543 -1.9397 0.1668 20.9329
Coefficients:
Estimate Std. Error t value
(Intercept) 3.9634 1.6763 2.364
x 10.4164 0.6877 15.146
Pr(>|t|)
(Intercept) 0.0295 *
x 1.1e-11 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 7.492 on 18 degrees of freedom
Multiple R-squared: 0.9272, Adjusted R-squared: 0.9232
F-statistic: 229.4 on 1 and 18 DF, p-value: 1.096e-11
> summary(lm.model3)
Call:
lm(formula = y3 ~ x)
Residuals:
Min 1Q Median 3Q Max
-6.0275 -3.8411 0.1872 2.0643 10.8477
Coefficients:
Estimate Std. Error t value
(Intercept) 7.7555 1.0674 7.266
x 9.0369 0.4379 20.635
Pr(>|t|)
(Intercept) 9.39e-07 ***
x 5.61e-14 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.771 on 18 degrees of freedom
Multiple R-squared: 0.9594, Adjusted R-squared: 0.9572
F-statistic: 425.8 on 1 and 18 DF, p-value: 5.609e-14
通过 summary 函数,可以详细地显示 lm.model 对象中的信息,包括∶第一,模型结构;第二,残差的概述;第三,回归系数及其检验;第四,方程整体效果检验与指标。
可以看出,当随机项服从正态分布时,R-Square达到0.99,效果最好,说明模型的线性效果最强。当随机项服从卡方分布时模型效果较好,达到0.959,当随机项服从t分布时,模型效果最差,但也达到了0.927,可以说模型都取得了较好的效果。
2.
请编程求解图中"红虚线,与水平虚线、垂直虚线"各自相交处的横坐标、纵坐标的具体数值。
ts<-1e-5
x<-0
pextreme <- function(x) 1-exp(-exp(x))
while(pextreme(x)>0.5){
x<-x-ts}
paste("x = ",x)
paste("y = ",pextreme(0))
[1] "x = -0.366520000000226"
> paste("y = ",pextreme(0))
[1] "y = 0.632120558828558"
网友评论