Вы находитесь на странице: 1из 3

MAT2001 R LAB

RLAB ASSIGNMENT

Z TEST
18BCE1213

TARUN A H

Write a R code to take decision on the given data by using Z test.

TEST 1 :

A random sample of 200 tins of coconut oil gave an average weight of 4.95 kgs. With
a standard deviation of 0.21 kg.

(a) Do we accept that the net weight is 5 kgs per tin at 5% level?
CODE :
n=200
> xbar=4.95
> sigma=0.21
> mu0=5
> alpha=0.05
> zalpha=qnorm(1-(alpha/2))
> zalpha
[1] 1.959964
> z=abs((xbar-mu0)/(sigma/sqrt(n)))
> z
[1] 3.367175
> if(z<zalpha){
+ print("H0 accepted");
+ }
> if(z>zalpha){
+ print("H0 rejected");
+ }
[1] "H0 rejected"

TEST 2:

The average marks scored by 32 boys is 72 with a S.D of 8, while that for 36 girls is 70
with a S.D. of 6. Test at 1% level of significance whether the boys perform better than
girls.
n1=32
> x1bar=72
> sigma1=8
> n2=36
> x2bar=70
> sigma2=6
> alpha=0.01
> zalpha=qnorm(1-(alpha))
> zalpha
[1] 2.326348
> z=abs((x1bar-x2bar)/sqrt((sigma1/n1)+(sigma2/n2)))
> z
[1] 3.098387
> if(z<zalpha){
+ print("H0 accepted;Boys dont perform better than the girls");
+ }
> if(z>zalpha){
+ print("H0 rejected ; Boys perform greater than the girls");
+ }
[1] "H0 rejected ; Boys perform greater than the girls"

TEST 3 :
Experience has shown that 20% of a manufactured product is of top quality. In one d
ay’s production of 400 articles, only 50 are of top quality. Show that either the produc
tion of the day chosen was not a representative sample or the hypothesis of 20% was
wrong.

P=0.2
> n=400
> p=50/400
> q=1-p
> alpha=0.05
> zalpha=qnorm(1-(alpha/2))
> zalpha
[1] 1.959964
> z=abs((p-P)/sqrt(p*q/n))
> z
[1] 4.535574
> if(z<zalpha){
+ print("H0 accepted");
+ }
> if(z>zalpha){
+ print("H0 rejected");
+ }
[1] "H0 rejected"

TEST 4 :

In a large city A, 20% of a random sample of 900 schools boys had a slight physical
defect. In another large city B, 18.5% of a random sample of 1600 school boys had
the same defect. Is the difference between the proportions significant?
p1=0.2
> n1=900
> p2=0.185
> n2=1600
> P=(n1*p1+n1*p2)/(n1+n2)
> Q=1-P
> alpha=0.05
> zalpha=qnorm(1-(alpha/2))
> zalpha
[1] 1.959964
> x=P*Q
> y=(1/n1)+(1/n2)
> z=abs((p1-p2)/sqrt(x*y))
> z
[1] 1.041882
> if(z<zalpha){
+ print("H0 accepted ; There is no significant difference between the proportions");
+ }
> if(z>zalpha){
+ print("H0 rejected ; there is significant difference between the proportions");
+ }
[1] "H0 accepted ; There is no significant difference between the proportions"

Вам также может понравиться