1 / 26
文档名称:

R语言线性回归案例数据分析可视化报告(附代码数据).docx

格式:docx   大小:387KB   页数:26页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

R语言线性回归案例数据分析可视化报告(附代码数据).docx

上传人:碎碎念的折木 2023/1/23 文件大小:387 KB

下载得到文件列表

R语言线性回归案例数据分析可视化报告(附代码数据).docx

文档介绍

文档介绍:该【R语言线性回归案例数据分析可视化报告(附代码数据) 】是由【碎碎念的折木】上传分享,文档一共【26】页,该文档可以免费在线阅读,需要了解更多关于【R语言线性回归案例数据分析可视化报告(附代码数据) 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
R语言线性回归案例数据分析可视化报告
在本试验中,我们将查看来自全部30个职业棒球大联盟球队的数据,并检查一个赛季的得分
与其他球员统计数据之间的线性关系。我们的目标是通过图表和数字总结这些关系,以便找出
哪个变量〔假设有的话〕可以帮助我们最好地推想一个赛季中球队的得分状况。
数据
load(“more/“)
用变量at_bats绘制这种关系作为推想。关系看起来是线性的吗?假设你知道一个团队的
at_bats,你会****惯使用线性模型来推想运行次数吗?
散点图
plot(mlb11$at_bat,mlb11$runs,xlab=“at_b
at“,ylab=“runs“,main=“at_bat“,=TRUE,col=“red“)
abline(lm(mlb11$runs~mlb11$at_bat))
.假设关系看起来是线性的,我们可以用相关系数来量化关系的强度。
cor(mlb11$runs,mlb11$at_bats)
##[1]
.残差平方和
回想一下我们描述单个变量分布的方式。回想一下,我们争论了中心,传播和外形等特征。能
够描述两个数值变量〔例如上面的runandat_bats〕的关系也是有用的。
从前面的练****中查看你的情节,描述这两个变量之间的关系。确保争论关系的形式,方向和强
度以及任何不寻常的观看。
正如我们用均值和标准差来总结单个变量一样,我们可以通过找出最符合其关联的线来总结这两
个变量之间的关系。使用下面的交互功能来选择您认为通过点云的最正确工作的线路。
plot_ss(x=mlb11$at_bats,y=mlb11$runs)
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
#Clicktwopointstomakealine.
##Call:
##lm(formula=y~x,data=pts)##
##
##
Coefficients:
(Intercept)
x
##
-

##
##
SumofSquares:

【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
Afterrunningthiscommand,you’llbepromptedtoclicktwopointsontheplottodefinealine.
Onceyou’vedonethat,thelineyouspecifiedwillbeshowninblackandtheresidualsinblue.
Notethatthereare30residuals,
arethedifferencebetweentheobservedvaluesandthevaluespredictedbytheline:
ei=yiy^iei=yiy^i
Themostcommonwaytodolinearregressionistoselectthelinethatminimizesthesumof
,youcanreruntheplotcommandand
addtheargumentshowSquares=TRUE.
plot_ss(x=mlb11$at_bats,y=mlb11$runs,showSquares=TRUE)
##Clicktwopointstomakealine.
##Call:
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
##lm(formula=y~x,data=pts)
##
##
##
Coefficients:
(Intercept)
x
##
-

##
##
SumofSquares:

Notethattheoutputfromtheplot_ssfunctionprovidesyouwiththeslopeandinterceptof
yourlineaswellasthesumofsquares.
3. Usingplot_ss,choosealinethatdoesagoodjobofminimizingthesumofsquares.
?How
doesitcomparetoyourneighbors?
Answer:.
Thelinearmodel
Itisrathercumbersometotrytogetthecorrectleastsquaresline,,
tofitthelinearmodel().
m1<-lm(runs~at_bats,data=mlb11)
Thefirstargumentinthefunctionlmisaformulathattakestheformy~

specifiesthatRshouldlookinthemlb11dataframetofindtherunsandat_batsvariables.
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
Theoutputoflmisanobjectthatcontainsalloftheinformationweneedaboutthelinear
.
summary(m1)##
##Call:
##lm(formula=runs~at_bats,data=mlb11)
##
##Residuals:
##
Min
1Q
Median
3Q
Max
##
##
-
-
-


##Coefficients:
## (>|t|)
##(Intercept)- -
**
##at_bats
***##---
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
##:
0”***””**””
*””.”””1
##
##Residualstandarderror:
eesoffreedom
##MultipleR-squared:
,AdjustedR-s
quared:

##F-statistic:,
ue:
p-val
Let’,theformulausedtodescribethemodelis
-
“Coefficients”tableshownnextiskey;itsfirstcolumndisplaysthelinearmodel’sy-intercept
,wecanwritedowntheleastsquares
regressionlineforthelinearmodel:
y^=+∗atbatsy^=−+∗atbats
OnelastpieceofinformationwewilldiscussfromthesummaryoutputistheMultiple
R-squared,ormoresimply,,%of
thevariabilityinrunsisexplainedbyat-bats.
4.
output,
contextoftherelationshipbetweensuccessofateamanditshomeruns?
Answer:homerunshaspositiverelationshipwithruns,whichmeans1homerunsincrease
.
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
<-lm(runs~homeruns,data=mlb1
1)

##
##Call:
##lm(formula=runs~homeruns,data=mlb1
1)
##
##
##
Coefficients:
(Intercept)
homeruns
##


Predictionandpredictionerrors
Let’screateascatterplotwiththeleastsquareslinelaidontop.
plot(mlb11$runs~mlb11$at_bats)
abline(m1)
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
,weusedashortcutbyprovidingthemodelm1,,itisreferredtoasextrapolationandisnotusuallyrecommended.
However,’realsousedto
computetheresiduals.
5. Ifateammanagersawtheleastsquaresregressionlineandnottheactualdata,how
manyrunswouldheorshepredictforateamwith5,578at-bats?Isthisanoverestimate
oranunderestimate,andbyhowmuch?Inotherwords,whatistheresidualforthis
prediction?
pred=-+*(5578)
pred
##[1]
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了
residual=*(5578)
residual
##[1]
Modeldiagnostics
Toassesswhetherthelinearmodelisreliable,weneedtocheckfor(1)linearity,(2)nearly
normalresiduals,and(3)constantvariability.
Linearity:Youalreadycheckediftherelationshipbetweenrunsandat--#isintendedtobeacommentthathelpsunderstandthecodebutis
ignoredbyR.
plot(m1$residuals~mlb11$at_bats)
abline(h=0,lty=3)
ashedlineaty=0
#addsahorizontald
【原创】R语言案例数据分析报告论文〔附代码数据〕
有问题到淘宝找“大数据部落”就可以了