非参数统计第二版习题测验R程序Word格式.docx

上传人:b****2 文档编号:15060236 上传时间:2022-10-27 格式:DOCX 页数:24 大小:22.68KB
下载 相关 举报
非参数统计第二版习题测验R程序Word格式.docx_第1页
第1页 / 共24页
非参数统计第二版习题测验R程序Word格式.docx_第2页
第2页 / 共24页
非参数统计第二版习题测验R程序Word格式.docx_第3页
第3页 / 共24页
非参数统计第二版习题测验R程序Word格式.docx_第4页
第4页 / 共24页
非参数统计第二版习题测验R程序Word格式.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

非参数统计第二版习题测验R程序Word格式.docx

《非参数统计第二版习题测验R程序Word格式.docx》由会员分享,可在线阅读,更多相关《非参数统计第二版习题测验R程序Word格式.docx(24页珍藏版)》请在冰豆网上搜索。

非参数统计第二版习题测验R程序Word格式.docx

P

[1]0.04999579

P1<

-2*(1-pnorm(0.7906,0,1));

P1

[1]0.4291774

>

例2.4

p<

-2*(pnorm(-1.96,0,1));

p

p1<

-2*(pnorm(-0.9487,0,1));

p1

[1]0.3427732

 

例2.5(P45)

scores<

-c(95,89,68,90,88,60,81,67,60,60,60,63,60,92,

60,88,88,87,60,73,60,97,91,60,83,87,81,90);

length(scores)#输入向量求长度

ss<

-c(scores-80);

ss

t<

-0

t1<

for(iin1:

length(ss)){

if(ss[i]<

0)t<

-t+1#求小于80的个数

elset1<

-t1+1求大于80的个数

}

t;

t1

t;

[1]13

[1]15

binom.test(sum(scores<

80),length(scores),0.75)

p-value=0.001436<

0.01

Cox-Staut趋势存在性检验P47

例2.6

year<

-1971:

2002;

year

length(year)

rain<

-c(206,223,235,264,229,217,188,204,182,230,223,

227,242,238,207,208,216,233,233,274,234,227,221,214,

226,228,235,237,243,240,231,210)

length(rain)

#

(1)该地区前10年降雨量是否变化?

t1=0

for(iin1:

5){

if(rain[i]<

rain[i+5])t1<

-t1+1

k<

-0:

t1-1

sum(dbinom(k,5,0.5))#=0.1875

y<

-6/(2^5);

y#=0.1875

#

(2)该地区前32年降雨量是否变化?

t=0

16){

rain[i+16])t<

-t+1

t

k1<

min(t,16-t)-1

sum(dbinom(k1,16,0.5))#=0.0002593994

pbinom(max(k1),16,0.5)#=0.0002593994

y1<

-(1+16)/(2^16);

y1#=0.0002593994

plot(year,rain)

abline(v=(1971+2002)/2,col=2)

lines(year,rain)

anova(lm(rain~(year)))

随机游程检验(P50)

例2.8

client<

-c("

F"

"

M"

"

);

client

n<

-length(client);

n

n1<

-sum(client=="

n1

n0<

-n-n1;

n0

(length(client)-1)){

if(client[i]==client[i+1])t1<

-t1

R<

-t1+1;

R#=12

#findrejectionregion(不写)

rl<

-1+2*n1*n0/(n1+n0)*(1-1.96/sqrt(n1+n0));

rl

ru<

-2*n1*n0/(n1+n0)*(1+1.96/sqrt(n1+n0));

ru#=15.33476(课本为ru=17)

例2.9

shuju39<

-data.frame(read.table

("

SHUJU39.txt"

header=TRUE));

shuju39

attach(shuju39)

sum.a=0

sum.b=0

sum.c=0

length(id)){

if(pinzhong[i]=="

A"

)sum.a<

-sum.a+chanliang[i]

elseif(pinzhong[i]=="

B"

)sum.b<

-sum.b+chanliang[i]

elsefuhao<

-sum.c<

-sum.c+chanliang[i]

sum.a;

sum.b;

sum.c

ma<

-sum.a/4

mb<

-sum.b/4

mc<

-sum.c/4

ma;

mb;

mc

fuhao<

-rep("

a"

12);

fuhao

&

((chanliang[i]-ma)>

0))fuhao[i]<

-"

+"

((chanliang[i]-mb)>

C"

((chanliang[i]-mc)>

elsefuhao[i]<

#利用上题编程解决检验的随机性

-length(fuhao);

-sum(fuhao=="

(length(fuhao)-1)){

if(fuhao[i]==fuhao[i+1])t1<

R

#findrejectionregion

ru

例2.10(P52)library(quadprog)#不存在叫‘quadprog’这个名字的程辑包

library(zoo)#不存在叫‘zoo’这个名字的程辑包

library(tseries)#不存在叫‘tseries’这个名字的程辑包

run1=factor(c(1,1,1,0,rep(1,7),0,1,1,0,0,rep(1,6),0,rep(1,4),

0,rep(1,5),rep(0,4),rep(1,13)));

run1

y=factor(run1)

runs.test(y)#错误:

没有"

runs.test"

这个函数

Wilcoxon符号秩检验

W+在零假设下的精确分布

#下面的函数dwilxonfun用来计算W+分布密度函数,

即P(W+=x)的一个参考程序!

dwilxonfun=function(N){

a=c(1,1)#whenn=1frequencyofW+=1oro

n=1

pp=NULL#distributeofallsizefrom2toN

aa=NULL#frequencyofallsizefrom2toN

for(iin2:

N){

t=c(rep(0,i),a)

a=c(a,rep(0,i))+t

p=a/(2^i)#densityofWilcoxdistributwhensize=N

}

p

N=19#samplesizeofexpecteddistributionofW+

-dwilxonfun(N);

y

#计算P(W+=x)中的x取值的R参考程序!

a

length(y)-1

hist(y,freq=FALSE)

lines(density(y),col="

例2.12(P59)

ceo<

-c(310,350,370,377,389,400,415,425,440,295,

325,296,250,340,298,365,375,360,385);

length(ceo)

#方法一

wilcox.test(ceo-320)

#方法二

ceo.num<

-sum(ceo>

320);

ceo.num

n=length(ceo)

binom.test(ceo.num,n,0.5)

例2.13(P61)

a<

-c(62,70,74,75,77,80,83,85,88)

walsh<

-NULL

(length(a)-1)){

for(jin(i+1):

length(a)){

walsh<

-c(walsh,(a[i]+a[j])/2)

walsh=c(walsh,a)

NW=length(walsh);

NW

median(walsh)

2.5单组数据的位置参数置信区间估计(P61)

例2.14‘

stu<

-c(82,53,70,73,103,71,69,

80,54,38,87,91,62,75,65,77);

stu

alpha=0.05

rstu<

-sort(stu);

rstu

conff<

-NULL;

conff

n=length(stu);

(n-1)){

n){

conf=pbinom(j,n,0.5)-pbinom(i,n,0.5)

if(conf>

1-alpha){conff<

-c(conff,i,j,conf)}

length(conff)

min<

-103-38;

min

c<

-seq(1,(length(conff)-1),3);

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

当前位置:首页 > 小学教育 > 英语

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1