1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
p_value<-function(cdf,x,parament=numeric(0),side=0)
{
n<-length(parament)
p<- switch (n+1,
cdf(x),
cdf(x,parament),
cdf(x,parament[1],parament[2]),
cdf(x,parament[1],parament[2],parament[3])
)
if (side<0) p
else
if (side>0) 1-p
else
if (p<0.5) 2*p
else
2*(1-p)
}
mean.test1<-function(x,mu=0,sigma=-1,side=0)
{
n<-length(x)
xb<-mean(x)
if (sigma>0)
{
z<-(xb-mu)/(sigma/sqrt(n))
p<-p_value(pnorm,z,side=side)
data.frame(mean=xb,df=n,Z=z,p_value=p)
}
else
{
t<-(xb-mu)/(sd(x)/sqrt(n))
p<-p_value(pt,t,parament=n-1,side=side)
data.frame(mean=xb,df=n-1,T=t,p_value=p)
}
}
|