




已阅读5页,还剩15页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
暨南大学数据分析与r语言应用试卷 考生姓名、学号:暨 南 大 学 考 试 试 卷教师填写2010 - 2011_ 学年度第_2_学期课程名称: 数据分析与r语言应用 授课教师姓名:_王斌会_ 考试时间:_2011_年_11_月_8_日课程类别必修 选修 考试方式开卷 闭卷 试卷类别(a、b) a 共 4 页考生填写 经济学院 学院(校) 数量经济学 专业 班(级)姓名 刘伟 学号 1130111008 内招 外招 题 号一二三四五六七八九十总 分得 分得分评阅人一、统计图表(共1小题,共20分)1应用r图表对各类产品供货走势图分析类别月份123456789101112彩电a1冰箱a2空调a3洗衣机a4(1) 要求:数据由r随机数函数生成,产生20,50间的均匀随机数。解:首先对r进行初始化,设定参数,再生成随机数,代码如下:rm(list=ls()options(digits=4)par(mar=c(4,4,2,1)+0.1,cex=0.75)a1=runif(12,20,50);a1a2=runif(12,20,50);a2a3=runif(12,20,50);a3a4=runif(12,20,50);a4(2)分析(图形要进行一定修饰):1)绘制各类产品的月份趋势线图。解:趋势线图如下代码如下:par(mfrow=c(2,2)plot(a1,type=l,ylab=销售量,xlab=月份,main=彩电(a1),xlim=c(1,12),ylim=c(0,50)plot(a2,type=l,ylab=销售量,xlab=月份,main=冰箱(a2),xlim=c(1,12),ylim=c(0,50)plot(a3,type=l,ylab=销售量,xlab=月份,main=空调(a3),xlim=c(1,12),ylim=c(0,50)plot(a4,type=l,ylab=销售量,xlab=月份,main=洗衣机(a4),xlim=c(1,12),ylim=c(0,50)2)绘制各类产品的季度的柱形图。解:首先对数据进行整理,得出各自的季度数据。柱状图如下代码如下:dat=data.frame(a1,a2,a3,a4)q1=c(dat1,1+dat2,1+dat3,1,dat4,1+dat5,1+dat6,1,dat7,1+dat8,1+dat9,1,dat10,1+dat11,1+dat12,1)q2=c(dat1,2+dat2,2+dat3,2,dat4,2+dat5,2+dat6,2,dat7,2+dat8,2+dat9,2,dat10,2+dat11,2+dat12,2)q3=c(dat1,3+dat2,1+dat3,3,dat4,3+dat5,1+dat6,3,dat7,3+dat8,3+dat9,3,dat10,3+dat11,3+dat12,3)q4=c(dat1,4+dat2,4+dat3,4,dat4,4+dat5,4+dat6,4,dat7,4+dat8,4+dat9,4,dat10,4+dat11,4+dat12,4)dat1=data.frame(q1,q2,q3,q4);dat1par(mfrow=c(2,2)barplot(dat1,1,xlab=季度,ylab=销售量,main=彩电(a1),ylim=c(0,150)barplot(dat1,2,xlab=季度,ylab=销售量,main=冰箱(a2),ylim=c(0,150)barplot(dat1,3,xlab=季度,ylab=销售量,main=空调(a3),ylim=c(0,150)barplot(dat1,4,xlab=季度,ylab=销售量,main=洗衣机(a4),ylim=c(0,150)3)绘制各类产品的年度的饼图。解:饼图如下代码如下:par(mfrow=c(1,1)y1=dat11,1+dat12,1+dat13,1+dat14,1y2=dat11,2+dat12,2+dat13,2+dat14,2y3=dat11,3+dat12,3+dat13,3+dat14,3y4=dat11,4+dat12,4+dat13,4+dat14,4x=c(y1,y2,y3,y4)pie(x,labels=c(彩电(a1),冰箱(a2),空调(a3),洗衣机(a4),col=c(red,green,purple,blue)得分评阅人二、统计检验(共2小题,每题10分,共20分)1. 两台铣床生产同一种型号的套管,平日两台铣床加工的套管内槽深度都服从正态分布n(10,0.32)和n(8,0.22),从这两台铣床的产品中分别抽出13个和15个,请分别按方差已知和未知检验两台产品的深度是否不同(=0.05)?(1)两台铣床的产品内槽精度(方差)有无显著差别?解: x=rnorm(13,10,0.3)y =rnorm(15,8,0.2)var.test(x,y) f test to compare two variancesdata: x and y f = 3.899, num df = 12, denom df = 14, p-value =0.01785alternative hypothesis: true ratio of variances is not equal to 1 95 percent confidence interval: 1.278 12.502 sample estimates:ratio of variances 3.899由于 p-value =0.017850.05,故两台铣床的产品内槽精度(方差)有显著差别。(2) 两台产品的的深度是否不同? 解:1、方差未知时 t.test(x,y)welch two sample t-testdata: x and y t = 17.61, df = 17.2, p-value = 1.934e-12alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 1.605 2.042 sample estimates:mean of x mean of y 9.982 8.159 由于p-value = 1.934e-120.05,故两台产品的的深度是不同的。 2、方差已知时 u.test=function(x,y,sigmax,sigmay) nx=length(x) ny=length(y) xbar=mean(x) ybar=mean(y) u=(xbar-ybar)/sqrt(sigmax2/nx+sigmay2/ny) p=pnorm(u,lower.tail=f) c(u=u,p=p) u.test(x,y,0.3,.02) u p 2.187e+01 2.332e-106由于p=2.332e-1060.05, 故两台产品的的深度是不同的。2. 如果还有一台铣床生产同一种型号的套管,其加工的套管内槽深度都服从正态分布n(12,0.42),从这台铣床的产品中抽出18个,请分别按方差已知和未知检验三台产品的深度是否不同(=0.05)?(1)、方差已知的情况 x1=rnorm(13,10,0.3)x2 =rnorm(15,8,0.2)x3=sample(rnorm(1000,12,0.4),18)n1=length(x1)n2=length(x2)n3=length(x3)se1=sqrt(0.32/n1+0.22/n2)se2=sqrt(0.32/n1+0.42/n3)se3=sqrt(0.22/n2+0.42/n3)x1bar=mean(x1) x2bar=mean(x2)x3bar=mean(x3) u1=(x1bar-x2bar)/se1 u2=(x1bar-x3bar)/se3 u3=(x2bar-x3bar)/se3chi=u12+u22+u32 p=2*pchisq(chi,3,lower.tail = f);p p a=0.05,所以拒绝三台产品的的深度相等的假设,三台台产品的深度不等。 (2)、方差未知的情况y=c(x1,x2,x3) group=c(rep(1,13),rep(2,15),rep(3,18) oneway.test(ygroup) one-way analysis of means (not assuming equal variances)data: y and group f = 564.7, num df = 2.00, denom df = 28.28, p-value 2.2e-16 p=t1j)/1000 #计算矩阵u每行中的数据大于t1中对应t值绝对值的概率,并将值赋予p_permutations数组id=c(1:100) # 构造row number result=data.frame(id,t, p_theoretical, p_permutations) #输出结果 id t p_theoretical p_permutations1 1 -2.8853207 0.02034 0.0152 2 -1.3143173 0.22517 0.2273 3 -2.6940739 0.02732 0.0064 4 -1.3802458 0.20485 0.2285 5 0.0473332 0.96341 0.9776 6 0.9959910 0.34842 0.2917 7 -0.4321985 0.67701 0.7228 8 -0.4268158 0.68077 0.6789 9 -0.1412908 0.89113 0.89910 10 1.3169132 0.22434 0.25411 11 -0.0489858 0.96213 0.98812 12 1.4028308 0.19826 0.16913 13 1.1741980 0.27408 0.25614 14 -1.0676853 0.31682 0.31715 15 2.6462644 0.02943 0.01216 16 -1.9388080 0.08851 0.06117 17 -0.6731468 0.51982 0.53618 18 -0.3519451 0.73397 0.75519 19 0.5819389 0.57663 0.57720 20 0.6656648 0.52435 0.57721 21 -0.1460266 0.88751 0.74822 22 -2.7035412 0.02693 0.02323 23 -0.7900807 0.45226 0.47224 24 -0.4385279 0.67260 0.62925 25 0.3676752 0.72265 0.74226 26 2.2177703 0.05738 0.03527 27 -0.1415220 0.89096 0.91828 28 -0.0004833 0.99963 1.00029 29 -0.4102665 0.69238 0.68730 30 0.0448795 0.96530 0.94431 31 1.4521009 0.18454 0.19332 32 0.2854683 0.78254 0.79333 33 0.1298656 0.89988 0.89634 34 -0.9887282 0.35175 0.34635 35 -1.4024164 0.19838 0.15836 36 0.1285964 0.90085 0.85037 37 3.0086702 0.01685 0.03238 38 0.6787512 0.51645 0.50339 39 1.0937833 0.30589 0.33140 40 1.9842917 0.08250 0.10241 41 -0.0968299 0.92524 0.96942 42 -3.1236870 0.01415 0.01643 43 0.6596542 0.52801 0.50144 44 1.2064446 0.26211 0.26745 45 -0.2720078 0.79250 0.81246 46 -0.1762814 0.86445 0.86047 47 -0.2106570 0.83842 0.87548 48 1.9866318 0.08220 0.07249 49 -0.0020090 0.99845 1.00050 50 -2.0646728 0.07283 0.03151 51 -0.2564763 0.80406 0.79752 52 2.8462192 0.02160 0.02853 53 -0.0657272 0.94921 0.96654 54 0.6318659 0.54510 0.58955 55 0.7555194 0.47159 0.42556 56 1.5005975 0.17185 0.17957 57 1.2630394 0.24214 0.24358 58 -0.6921399 0.50844 0.53959 59 -1.3837198 0.20382 0.19160 60 0.4838255 0.64148 0.63961 61 -0.1140807 0.91198 0.94462 62 1.1902273 0.26808 0.25863 63 0.2112508 0.83797 0.83664 64 0.8978211 0.39550 0.37365 65 -0.4111239 0.69177 0.71266 66 3.1668091 0.01326 0.01667 67 1.6002204 0.14822 0.14268 68 0.8488613 0.42063 0.39769 69 0.7102140 0.49775 0.49370 70 0.0780357 0.93972 0.93071 71 1.2471030 0.24763 0.25972 72 0.9615742 0.36442 0.33073 73 1.2386493 0.25059 0.27274 74 -0.6696054 0.52196 0.53775 75 1.2152901 0.25890 0.25476 76 -0.1259623 0.90287 0.92477 77 -0.0791718 0.93884 0.96478 78 -3.6579469 0.00642 0.01679 79 0.2499050 0.80896 0.78080 80 -2.3661564 0.04552 0.05281 81 0.0254582 0.98031 0.98882 82 -1.9755606 0.08362 0.08583 83 0.0015678 0.99879 1.00084 84 0.1471918 0.88662 0.87185 85 0.0295263 0.97717 0.98486 86 0.2628059 0.79934 0.80987 87 0.0846366 0.93463 0.92888 88 -0.5474582 0.59900 0.63589 89 -2.7182033 0.02632 0.01390 90 0.5733288 0.58218 0.67891 91 2.3551061 0.04631 0.04892 92 0.7709098 0.46292 0.43593 93 -0.4178680 0.68703 0.63494 94 0.2916059 0.77801 0.73695 95 0.2728228 0.79190 0.76296 96 1.5964084 0.14906 0.15597 97 1.3246252 0.22188 0.26698 98 0.6856973 0.51228 0.51199 99 -1.2272690 0.25461 0.248100 100 0.5488290 0.59810 0.5912.) plot the distribution (see hist) of the resulting vector of t-scores obtained at step 1a) after excluding the first element (corresponding to the first row) and on the same graph show a vertical line for the t-value of the first row. 解:t2=t2:100hist(t2,main=t值分布的直方图)abline(v=t1)2. olympic medalsduring both summer and winter olympic games the medal table is often of interest to spectators and the media. the medal table is a tally of the number of medals which have been won by each participating country during the games. a good performance on the medal table is often a source of pride for a country. however, it is to be expected that large countries will win more medals than smaller countries, due to the fact that they have a larger pool from which to recruit athletes. thus smaller countries often argue that a better measure of performance would be medals per capita. however, it is possible that medal tally shouldnt be expected to increase in direct proportion to population. further, it is reasonable to think that the medal tally will also depend on the resources available to athletes in a country, or on the climate (for example, access to snow).the objective of this analysis is to explore the relationship between a countrys medal tally, population size, wealth (measured by gdp) and climate (approximated by latitude). further, it is proposed that in future a standardised measure of a countrys medal tally should be developed which corrects for population size, climate and wealth. your should investigate the feasibility of this proposal, and discuss your finndings.the file medals.rdataload(medals.rdata) in r is an r data frame with one row for every country that has won at least one olympic medal in the previous four olympic games.the variable descriptions are as follows:country name of the competing country (only countries which have won at least one medal since 2004 are included).latitude latitude of the capital city.summer2004 total number of medals (gold, silver and bronze) won at the summer olympics in 2004.summer2008 total number of medals won at the summer olympics in 2008.winter2006 total number of medals won at the winter olympics in 2006.winter2010 total number of medals won at the winter olympics in 2010.population2007 the population in 2007 (source: world fact book).gdp2009 gross domestic product in billions of us dollars (source: world fact book).一、引言众所周知,历届奥运会都以获得的奖牌的总数来衡量一个国家的体育发展水平,同时获得更多的奖牌也成为一个国家的骄傲。然而,不同的国家所处气候纬度、人口规模、gdp总量等因素是不同的,而仅仅靠奖牌的总量来衡量一国的体育水平显然不够全面,也不太公正。本文旨在找出与影响获得奖牌数的一些因素,如:气候(用纬度表示)、人口规模、gdp总量,通过相关分析和回归分析研究它们的内在关系,并在此基础上提出更加全面的衡量一国体育发展水平的新指标。二、相关性分析 为了分析各个国家的金牌数与其气候(纬度表示)、人口规模和收入(gdp)的关系,首先对其进行相关分析。以下就通过相关系数矩阵和散点图考察它们之间的关系。1、2008年夏季奥运会奖牌数及其影响因素相关分析fix(medals) #对原始数据进行适当编辑,用负数表示南纬,朝鲜的gdp为280亿美元,以此填充nall值x1=medals$summer2008;x1x2=medals$winter2010;x2x3=medals$winter2006;x3x4=medals$sumer2004;x4y1=medals$latitude;y1y2=medals$population;y2y3=medals$gdp;y3a=data.frame(x1,y1,y2,y3);acor(a) x1 y1 y2 y3x1 1.0000000 0.16387884 0.48614648 0.6624589y1 0.1638788 1.00000000 0.01097671 0.1246518y2 0.4861465 0.01097671 1.00000000 0.1685161y3 0.6624589 0.12465175 0.16851611 1.0000000 par(mfrow=c(1,3)plot(y1,x1)plot(y2,x1)plot(y3,x1)由相关系数矩阵可知,2008年各个国家的金牌数与其所处的维度、人口规模和gdp存在正相关性,它们的相关系数分别为0.164、 0.486、 0.662,并且奖牌数与人口规模和gdp中度相关,与维度轻度相关。从三点图可以发现以下几个现象。第一,获得奖牌的国家基本上分布于北纬0到北纬60之间,只有11个获得奖牌的国家位于南半球,且获得奖牌较多的国家基本上位于北纬30到北纬50,即亚热带和温带地区,这与现实所表现出来的是一致的,这是因为分布在南半球的参与奥运会的国家相对较少,自然获得的金牌也少。第二,获得奖牌数与人口规模显然正相关。人口规模越大,获得奖牌数越多,中国和美国是典型,但印度除外。第三,获得奖牌数与gdp也是正相关的,gdp规模越大,获得奖牌数越多。2、2010年冬季奥运会奖牌数及其影响因素相关分析cor(b) x2 y1 y2 y3x2 1.0000000 0.31292367 0.17071234 0.6459346y1 0.3129237 1.00000000 0.01097671 0.1246518y2 0.1707123 0.01097671 1.00000000 0.1685161y3 0.6459346 0.12465175 0.16851611 1.0000000plot(y1,x2)plot(y2,x2)plot(y3,x2)从相关系数矩阵来看,2010年冬季奥运会奖牌数与纬度、人口规模和gdp有这正相关性,相关系数分别为0.3129、0.1707、0.6459。从散点图来看,2010年冬季奥运会获得奖牌的国家出澳大利亚外都位于北纬40与北纬65之间。这与2008年夏季运动会获奖牌国家的纬度相比更加偏北。这是因为冬季奥运会时,南半球国家正值夏季,很多冬季运动项目不宜开展。就奖牌数与人口规模和gdp的关系,与2008年夏季运动会相比变化不大。3、2006年冬季奥运会奖牌数及其影响因素相关分析cor(c) x3 y1 y2 y3x3 1.0000000 0.33983286 0.15271725 0.4910002y1 0.3398329 1.00000000 0.01097671 0.1246518y2 0.1527172 0.01097671 1.00000000 0.1685161y3 0.4910002 0.12465175 0.16851611 1.0000000 plot(y1,x3)plot(y2,x3)plot(y3,x3) 从相关系数矩阵和散点图可以看到,2006年冬季奥运会奖牌数与纬度、人口规模和gdp的关系与2010年冬季奥运会相似。4、2004年夏季奥运会奖牌数及其影响因素相关分析cor(d) x4 y1 y2 y3x4 1.00000000 0.05056714 0.29117180 0.5879380y1 0.05056714 1.00000000 0.01097671 0.1246518y2 0.29117180 0.01097671 1.00000000 0.1685161y3 0.58793800 0.12465175 0.16851611 1.0000000 plot(y1,x4)plot(y2,x4)plot(y3,x4) 由相关系数矩阵可以看到,2004年夏季奥运会奖牌数与纬度、人口规模和gdp的关系与2008年夏季奥运会相似。 通过相关分析我们可以知道,一个国家在奥运会中获得奖牌的数量和这个国家所处的纬度、人口规模、gdp总量都是有关系的,并且与人口规模和gdp总量的还有较为密切的关系。而冬奥会与夏奥会的奖牌数分布于纬度(也就是气候)有密切联系,冬奥会获得奖牌的除个别的国家外都是处在北半球,而夏奥会有十多个国家分布在南半球。这与我们现实看到的现象是相符合的,也是可以解释的。这是因为,冬奥会的气候和冬奥会的项目都是有利于北半球的国家;夏奥会获得奖牌的国家比冬奥会多,但又比北半球的国家少得多,这是因为,参加奥运会的大多数国家都处于北半球,自然获得的奖牌数就多。我们还可以看到一个有趣的现象是:获得奖牌国家有大约75%都分布在北纬20到北纬60,也就是亚热带和温带地区;有大约50%分布在北纬40到北纬60,也就是温带地区。因此地处气候不适很严酷的地区的国家的更可能获得更多的奖牌。还可以看出的是,不论是冬奥会还
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高级离婚协议书模板:房产、股权与子女抚养协议
- 离婚后财产重新分配及子女成长费用承担合同
- 离婚协议书中关于共同子女抚养权转移协议书五
- 绿色建筑物业权益转让与节能减排合同
- 离婚协议中共同债务处理与子女抚养责任专题合同
- 智能建筑垃圾清运与环保科技研发合作协议
- 经典离婚协议范本:财产分割与子女抚养详细规定
- 离婚子女轮流抚养期间生活照料协议
- 2025年疼痛科疼痛评估与镇痛方案设计考核答案及解析
- 口语交际应对课件
- 人教版(2024)八年级上册数学全册教案
- (高清版)DB11∕T 2440-2025 学校食堂病媒生物防制规范
- GB/T 7324-2010通用锂基润滑脂
- 品管圈提高痰培养标本留取率
- 护理管理学第五章 人力资源管理
- TSG11-2020 锅炉安全技术规程
- 物业小区绿化服务程序
- 土地管理法(1986年版)
- 动物遗传学第十章遗传病的传递方式.ppt
- 延期缴纳税款申请报告申请延期缴纳税款报告2p.doc
- 高压燃气管道带压不停输封堵改管技术
评论
0/150
提交评论