研究生R语言考题_免费下载.doc

上传人:椰子壳 文档编号:5115821 上传时间:2020-02-04 格式:DOC 页数:20 大小:239.51KB
返回 下载 相关 举报
研究生R语言考题_免费下载.doc_第1页
第1页 / 共20页
研究生R语言考题_免费下载.doc_第2页
第2页 / 共20页
研究生R语言考题_免费下载.doc_第3页
第3页 / 共20页
研究生R语言考题_免费下载.doc_第4页
第4页 / 共20页
研究生R语言考题_免费下载.doc_第5页
第5页 / 共20页
亲,该文档总共20页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《研究生R语言考题_免费下载.doc》由会员分享,可在线阅读,更多相关《研究生R语言考题_免费下载.doc(20页珍藏版)》请在三一文库上搜索。

1、暨南大学数据分析与R语言应用试卷 考生姓名、学号:暨 南 大 学 考 试 试 卷教师填写2010 - 2011_ 学年度第_2_学期课程名称: 数据分析与R语言应用 授课教师姓名:_王斌会_ 考试时间:_2011_年_11_月_8_日课程类别必修 选修 考试方式开卷 闭卷 试卷类别(A、B) A 共 4 页考生填写 经济学院 学院(校) 数量经济学 专业 班(级)姓名 刘伟 学号 1130111008 内招 外招 题 号一二三四五六七八九十总 分得 分得分评阅人一、统计图表(共1小题,共20分)1应用R图表对各类产品供货走势图分析类别月份123456789101112彩电A1冰箱A2空调A3洗

2、衣机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=销售量,xl

3、ab=月份,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)绘制各类产品的季度的柱形图。解:首先对数据进行整理,得出各自的季度数据。柱状图如下代码如下:d

4、at=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,

5、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)

6、,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

7、),洗衣机(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 an

8、d 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)Welc

9、h 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

10、,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个,请分别按方差已知和未

11、知检验三台产品的深度是否不同(=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)/

12、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, den

13、om 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

14、 -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.3

15、1682 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.6726

16、0 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.34

17、635 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

18、-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.7

19、555194 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

20、 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

21、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.984

22、86 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

23、.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

24、) 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 medal

25、s 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 whic

26、h 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 d

27、epend 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 pr

28、oposed 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

29、 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 m

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程管理


经营许可证编号:宁ICP备18001539号-1