:(数据出自何晓群--应用回归分析)
x y
36
24
#-------------------------------------------------------------#数据准备
fire <- ('D:/', head = T)
#-------------------------------------------------------------#回归分析
plot(fire$y ~ fire$x)
<- lm(fire$y ~ fire$x, data = fire) #回归拟合
summary() #回归分析表
anova() #方差分析表
abline(, col = 2, lty = 2) #拟合直线
#-------------------------------------------------------------#残差分析
<- residuals() #残差
<- rstandard() #学生化残差
plot()
abline(h = 0)
text(11, [11], label = 11, adj = (-), col = 2) #标注点
#-------------------------------------------------------------#预测与控制
attach(fire) #连接
<- lm(y ~ x) #这种回归拟合简单
<- (x = c(, 4))
<- predict(, , interval = 'prediction', level = ) #预测:置信区间
detach(fire) #取消连接
--------------------------------------------------------------------------------------------------
#附自编的过程程序:(R最大的好处是可以自己编想要的程序和函数,尤其没有内置函数的时候)
fire <- ('D:/', head = T)
attach(fire)
--------------------------------------------
lxy <- function(x){
sum <- 0
sum0 <- 0
for(i in 1:length(x)){
sum0 <- (x[i] - mean(x))
用r语言进行简单线性回归分析 来自淘豆网m.daumloan.com转载请标明出处.