首页 > 其他 > 详细

R 分析回归(一元回归)

时间:2019-11-27 09:57:40      阅读:63      评论:0      收藏:0      [点我收藏+]
x <- c(18,23,25,35,65,54,34,56,72,19) # build X(predictor)
y <- c(202,168,180,156,169,174,172,153,199,193) # build Y(dependent variable)
mode(x) # view the type of x
plot(x,y) # plot the graph
model <- lm(y ~ x) # build the linear model
abline(model) # add the line in graph

技术分享图片

 

数据是自己编的,所以图有点假。

summary(model)

技术分享图片

 

 上图为各种参数,还有各种检验。

 

如果想要输出建好的模型的方程的话,可以以下面的方式,当然还可以用predict()函数

pridict <- model$coefficients[1] + model$coefficients[1]*100 # we can pridict 100 in model through this way
print(pridict) # print result

 

 

R 分析回归(一元回归)

原文:https://www.cnblogs.com/zijidefengge/p/11939428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!