R语言实验报告4

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验目的根据教科书上数据,作图,以及实现关于分布的假设检验,要求选择的数据除了服从正态分布外,还应选择一些其它类型的数据实验内容(一)根据教科书上数据,作图基本图形:直方图、条形图、点图和箱线图(参考书本例题mtcars)、饼图和扇形图(书本例题:国别数据)attach(mtcars)opar-par(no.readonly=TRUE)par(mfrow=c(3,1))hist(wt)hist(mpg)hist(disp)par(opar)detach(mtcars)attach(mtcars)layout(matrix(c(1,1,2,3),2,2,byrow=TRUE))hist(wt)hist(mpg)hist(disp)detach(mtcars)attach(mtcars)plot(wt,mpg)abline(lm(mpg~wt))title(RegressionofMPGonWeight)detach(mtcars)pdf(mygraph.pdf)attach(mtcars)plot(wt,mpg)abline(lm(mpg~wt))title(RegressionofMPGonWeight)detach(mtcars)attach(mtcars)opar-par(no.readonly=TRUE)par(mfrow=c(2,2))plot(wt,mpg,main=Scatterplotofwtvs.mpg)plot(wt,disp,main=Scatterplotofwtvs.disp)hist(wt,main=Histogramofwt)boxplot(wt,main=Boxplotofwt)par(opar)detach(mtcars)饼图和扇形图(书本例题:国别数据)par(mfrow=c(2,2))slices-c(10,12,4,16,8)lbls-c(US,UK,Australia,Germany,France)pie(slices,labels=lbls,main=SimplePieChart)pct-round(slices/sum(slices)*100)lbls-paste(lbls,pct)lbls-paste(lbls,%,sep=)pie(slices,labels=lbls,col=rainbow(length(lbls)),main=PieChartwithPercentages)library(plotrix)slices-c(10,12,4,16,8)lbls-c(US,UK,Australia,Germany,France)fan.plot(slices,labels=lbls,main=FanPlot)核密度图d-density(mtcars$mpg)#returnsthedensitydataplot(d)#plotstheresultsd-density(mtcars$mpg)plot(d,main=KernelDensityofMilesPerGallon)polygon(d,col=red,border=blue)rug(mtcars$mpg,col=brown)(二)关于分布的假设检验(来自书本数据男女老少体重)fit-lm(weight~height,data=women)summary(fit)Call:lm(formula=weight~height,data=women)Residuals:Min1QMedian3QMax-1.7333-1.1333-0.38330.74173.1167Coefficients:EstimateStd.ErrortvaluePr(|t|)(Intercept)-87.516675.93694-14.741.71e-09***height3.450000.0911437.851.09e-14***---Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1Residualstandarderror:1.525on13degreesoffreedomMultipleR-squared:0.991,AdjustedR-squared:0.9903F-statistic:1433on1and13DF,p-value:1.091e-14women$weight[1]115117120123126129132135139142146150154159164fitted(fit)12345678112.5833116.0333119.4833122.9333126.3833129.8333133.2833136.73339101112131415140.1833143.6333147.0833150.5333153.9833157.4333160.8833residuals(fit)1234562.416666670.966666670.516666670.06666667-0.38333333-0.83333333789101112-1.28333333-1.73333333-1.18333333-1.63333333-1.08333333-0.533333331314150.016666671.566666673.11666667plot(women$height,women$weight,+main=WomenAge30-39,+xlab=Height(ininches),+ylab=Weight(inpounds))通过结果可知^y=-87.52+3.45x(^y为体重的估计量,x为身高)fit-lm(weight~height,data=women)par(mfrow=c(2,2))plot(fit)newfit-lm(weight~height+I(height^2),data=women)par(opar)par(mfrow=c(2,2))plot(newfit)线性模型的假设检验:由于globalstatp=0.0023251,因此不通过假设检验,从而我们考虑多项式线性模型:新的回归模型是^y=261.87818-7.35*x+0.083*x^2,且通过了ols回归模型所有的统计假设。

1 / 8
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功