查询R绘图代码拷贝到R控制台中,查看R绘制的图形。

require(grDevices)
plot(weight ~ group, data = PlantGrowth)           # numeric vector ~ factor

plot(cut(weight, 2) ~ group, data = PlantGrowth)   # factor ~ factor

passing “…” to spineplot() eventually:

plot(cut(weight, 3) ~ group, data = PlantGrowth,
     col = hcl(c(0, 120, 240), 50, 70))

plot(PlantGrowth$group, axes = FALSE, main = "no axes")  # extremely silly

对例进行回归分析,并绘制散点图,并为散点图添加回归直线。

rate<-c(20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 
40, 42)
impurity <-c(8.4, 9.5, 11.8, 10.4, 13.3, 14.8, 
13.2, 14.7, 16.4, 16.5, 18.9, 18.5)
plot(impurity~rate)
reg<-lm(impurity~rate)
abline(reg,col="red")

summary(reg)
## 
## Call:
## lm(formula = impurity ~ rate)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.1834 -0.5432 -0.3233  0.8333  1.3900 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.28928    1.22079  -0.237    0.817    
## rate         0.45664    0.03844  11.880 3.21e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9193 on 10 degrees of freedom
## Multiple R-squared:  0.9338, Adjusted R-squared:  0.9272 
## F-statistic: 141.1 on 1 and 10 DF,  p-value: 3.211e-07

结论:

###模型有效性: 从截距项和斜率项的标准误差可以看出,它们都非常小,远小于其估计值,这表明模型能够很好地解释因变量与自变量之间的关系。此外,F统计量的p值为3.21e-07,远远小于通常的显著性水平(如0.05),这意味着我们的模型在统计学上是显著的,即自变量确实对因变量有显著影响。

###自变量的重要性: 斜率项的估计值为0.4566,且其标准误差很小,这表明“rate”这个自变量对于因变量“impurity”具有显著的正向影响。换句话说,随着“rate”的增加,“impurity”也会相应地增加。

###残差分析: 残差的均值、中位数和标准差都接近于0,且残差的标准误差也很小,这表明模型没有明显的系统性偏差,即模型预测值与实际观测值之间的差异是随机的。同时,残差的峰度和偏度也都接近于0,这说明残差分布是对称的,没有出现严重的异常值或极端值情况。

###综上所述,这个线性回归模型有效地捕捉了“rate”对“impurity”的影响,并且模型本身具有良好的统计特性和稳健性。