0% found this document useful (0 votes)
211 views45 pages

Z - TEST and T Test

The document provides information on performing one-sample and two-sample t-tests and z-tests in R. It includes the procedures, formulas, and R functions for the tests. Examples are provided for one-proportion z-test, two-proportions z-test, one-sample t-test, and two-sample t-test. Notes are included on continuity corrections and outputs from the R functions.

Uploaded by

Shil Shambharkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
211 views45 pages

Z - TEST and T Test

The document provides information on performing one-sample and two-sample t-tests and z-tests in R. It includes the procedures, formulas, and R functions for the tests. Examples are provided for one-proportion z-test, two-proportions z-test, one-sample t-test, and two-sample t-test. Notes are included on continuity corrections and outputs from the R functions.

Uploaded by

Shil Shambharkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

Z –TEST

Test for single (or one) proportion


Procedure:
P=P0 P≠P0 or P>P0 or P<P0
If sample proportion is p then test statistic is Z=
CONCULSION:
If Z lies in (-1.96, 1.96) at 5% level of
significance, then accept
Otherwise reject
OR If p value < 0.05 R , other wise Accept
Example:
The personal manager claims that 80% of single woman
quits the job after they got married within a year. A sample
of 60 single women are selected, out of which 35 quits the
job after they got married within a year. Test the claim of a
personal manger.
Personal manager’s claim is true. P=80%=0.8
Personal manager’s claim is not true. P≠80%≠0.8
Given: Sample proportion is p=x/n=35/60=0.5833
and Z= (0.5833-0.8)/root(0.8x0.2/60)= -4.19
-4.19 lies out of (-1.96,1.96) at 5% level of significance.
Reject
Conclusion: Personal manager’s claim is not true.
IN R
The R functions binom.test() and prop.test() can be used to perform one-
proportion test:
• binom.test(): compute exact binomial test. Recommended when sample size is
small
• prop.test(): can be used when sample size is large ( n > 30). It uses a normal
approximation to binomial
The syntax of the two functions are exactly the same. The simplified format is as
follow:
binom.test(x, n, p = 0.5, alternative = )
prop.test(x, n, p = NULL, alternative = , correct = )
• x: the number of of successes
• n: the total number of trials
• p: the population proportion.
• correct: a logical indicating whether Yates’ continuity correction should
be applied or not by taking TRUE or FLASE
• alterative=“two.sided or less or greater”
NOTE
1) By default, the function prop.test() used the Yates continuity
correction, which is really important if either the expected
successes or failures is < 5. If you don’t want the correction,
use the additional argument correct = FALSE in prop.test()
function. The default value is TRUE. (This option must be set
to FALSE to make the test mathematically equivalent to the
uncorrected z-test of a proportion.)
2) The function returns:
• the value of Pearson’s chi-squared test statistic.
• a p-value
• a 95% confidence intervals
• an estimated probability of success 
Example in R
The personal manager claims that 80% of single woman
quits the job after they got married within a year. A
sample of 60 single women are selected, out of which 35
quits the job after they got married within a year. Test
the claim of a personal manger.
Personal manager’s claim is true. P=80%=0.8
Personal manager’s claim is not true. P≠80%≠0.8

result <- prop.test(x = 35, n = 60, p = 0.8, correct = FALSE)


# Printing the results
result
OUT PUT
1-sample proportions test with continuity correction
data: 35 out of 60, null probability 0.8
X-squared = 16.276, df = 1, p-value = 5.475e-05
alternative hypothesis: true p is not equal to 0.8
95 percent confidence interval:
0.4491411 0.7068480
sample estimates:
p
0.5833333
CONCULSION: p.value<0.05(level of significance),Accept
Example 2
In a population male and female suffering with cancer are equal.
To test this ,the sample of 160 people are selected and it is
observed that 95 males are suffering with cancer.
Proportion of male and female suffers of cancer are equal.ie
P=50%
Proportion of male and female suffers of cancer are equal.ie
P≠50%
IN R
result <- prop.test(x = 95, n = 160, p = 0.5, correct = FALSE)
# Printing the results
result
Example 3
In a sample of 1,000 people in Maharashtra, 540
are rice eaters and the ,rest are wheat eaters.
Can we assume that both rice and wheat are
equally popular in this State at 1% level of
significance?
Example 4
Twenty COVID 19 patients were selected and
only 18 survived. Will you reject the hypothesis
that the survival rate of COVID 19 patients is
more than 85%
Test for difference of proportions

Procedure:
P1=P2 P1≠P2 OR P1>P2 OR P1<P2
If sample proportions are p1 and p2 then test
statistic is
Where P= Q=1-P
If Z lies in (-1.96, 1.96) at 5% level of
significance, then accept
Otherwise reject
OR If p value < 0.05 R , other wise Accept
Example:
A company is introducing a new plan of work in their
two branches at Mumbai and Kolkata. In Mumbai out of
40 workers 35 are in favour of new plan. In Kolkata out of
35 workers 10 are against the new plan. Test whether
workers in both the branches are in favour of new plan.
Workers in both the branches are in favour of new plan.
Workers in both the branches are not in favour of new
plan.
Given: , ,P= =0.8,Q=0.2 and Z== 1.74
1.74 lies in (-1.96,1.96) at 5% level of significance. Accept
Conclusion: Workers at both the branches are in favour
of new plan.
two-proportions z-test in R
The R functions prop.test() can be used as follow:
prop.test(x, n, p = NULL, alternative = , correct =)
• x: a vector of counts of successes
• n: a vector of count trials
• correct: a logical indicating whether Yates’ continuity
correction should be applied or not by taking TRUE
or FLASE
• alterative=“two.sided or less or greater”
NOTE
1) The formula of z-statistic is valid only when sample size (n) is large
enough.  should be ≥ 5.
2) By default, the function prop.test() used the Yates continuity
correction, which is really important if either the expected
successes or failures is < 5. If you don’t want the correction, use
the additional argument correct = FALSE in prop.test() function. The
default value is TRUE. (This option must be set to FALSE to make
the test mathematically equivalent to the uncorrected z-test of a
proportion.)
3) The function returns:
• the value of Pearson’s chi-squared test statistic.
• a p-value
• a 95% confidence intervals
• an estimated probability of success 
Example in R

A company is introducing a new plan of work in their two


branches at Mumbai and Kolkata. In Mumbai out of 40
workers 35 are in favour of new plan. In Kolkata out of 35
workers 10 are against the new plan. Test whether workers
in both the branches are in favour of new plan.
Workers in both the branches are in favour of new plan.
Workers in both the branches are not in favour of new
plan.
result <- prop.test(x = c(35,25), n = c(40,35),correct =
FALSE,alternative = "two.sided")
# Printing the results
result
OUT PUT
2-sample test for equality of proportions without continuity
correction

data: c(35, 25) out of c(40, 35)


X-squared = 3.0134, df = 1, p-value = 0.08258
alternative hypothesis: two.sided
95 percent confidence interval:
-0.02067801 0.34210658
sample estimates:
prop 1 prop 2
0.8750000 0.7142857
CONCLUSION: p value>0.05,level of significance, Accept Therefore
two branches workers are in favour of new plan.
Example 2
Two groups of individuals:
In Group A there are 500 people with lung cancer, out of which
490 are smokers. In Group B out of 500 lung cancer
patients,400 are smokers. whether the proportions of smokers
are the same in the two groups of individuals?
The proportions of smokers are the same in the two groups
The proportions of smokers are the not same in the two groups

IN R
result <- prop.test(x = c(490, 400), n = c(500, 500))
# Printing the results
result
Example 3
Random samples of 400 men and 600 women
were asked whether they would like to have a
flyover near their residence. 200 men and 325
women were in favour of the proposal. Test the
hypothesis that proportions of men and women
in favour of the proposal are same .
Example 4
Before an increase in excise duty on tea, 800 out
of a sample of 1 ,000 persons were found to be
tea drinkers. After increase in excise duty 800
people were tea drinkers in a sample of 1200
people. whether there is a significant decrease
in the consumption of tea after the increase in
excise duty .
Example 5
A company is considering two different television
advertisements for promotion of a new product.
Management believed that the advertisement A is more
effective than advertisement B.
Two test market areas with, virtually identical consumer
characteristics are selected; A is used in one area and B in
other area. In a random sample of 60 customers who saw A,
18 tried the product. In another random sample of 100
customers who saw B, 22 tried the product. Does this
indicate that advertisement A is more effective than
advertisement
t – TEST(Student’s t test)
Test for single mean
Procedure: µ=µ0
H1 µ≠µ0 is two tailed test
H1 µ<µ0 is one tailed test(lower tailed test)
H1 µ>µ0 is one tailed test(upper tailed test)
If sample mean is then test statistic is t=
Conclusion:
If t< critical value at 5% level of significance with n-1 df, then
accept
Otherwise reject .
OR
If p< α (level of significant ) then reject H 0 ,otherwise accept H0
IN R

t.test(x, y = NULL,alternative = c("two.sided", "less", "greater"),mu = 0, paired =


FALSE, var.equal = FALSE, conf.level = 0.95, ...)
Arguments
x: a (non-empty) numeric vector of data values.
y: an optional (non-empty) numeric vector of data values.
alternative: a character string specifying the alternative hypothesis, must be
one of "two.sided" (default), "greater" or "less". You can specify just the initial
letter.
mu: a number indicating the true value of the mean (or difference in means if
you are performing a two sample test).
Paired: a logical indicating whether you want a paired t-test.
var.equal: a logical variable indicating whether to treat the two variances as
being equal. If TRUE then the pooled variance is used to estimate the variance
otherwise the Welch (or Satterthwaite) approximation to the degrees of
freedom is used.
conf.level: confidence level of the interval.
calculation of a p-value
For, H1 µ≠µ0
p=Prob(T≤ - |t|)+Prob(T≥ |t|)
In R is obtained as
2(1-pt(t,df))
For, H1 µ<µ0
p=Prob (T≤ t)
In R is obtained as
1-pt(t,df)
For, H1 µ>µ0
p = Prob(T≥ t)
In R is obtained as
pt(t,df)
Conclusion:
If p< α (level of significant ) then reject H0 ,otherwise accept H0
Example:
A institute claims that, they pay more than Rs 80000 salary to their
employees. To check this claim salary of 10 employees are as follows—
84250,65800,68900,78900,62000,59870,72900,80200,79350,71260
Test whether claim is true.
Mean salary paid to employees is Rs 80000
Mean salary paid to employees is ≥Rs 80000
Given: µ=Rs 80000,, s=8261.71, n=10
and t=-2.79
Critical value of t with n-1=9 degrees of freedom at 5% level of
significance=2.262
=2.79>2.262, Reject
Conclusion: Mean salary paid to employees is ≥Rs 80000
In R studio
1) Two tailed test
x <-
c(84250,65800,68900,78900,62000,59870,7290
0,80200,79350,71260 )
# Two tailed t test
t.test(x,mu=80000)
# calculation p value for Two tailed t test
2*(1-pt(2.9308,9))
2) lower tailed test
# lower tailed t test
t.test(x,mu=80000,alternative = "less",paired =
F,var.equal = T)
# calculation p value for lower tailed t test
1-pt(2.9308,9)
3) Upper tailed test
# upper tailed t test
t.test(x,mu=80000,alternative = "greater")
# calculation p value for upper tailed t test
pt(2.9308,9)
Example 2

We have the potato yield (in kg) from 12 different farms are 21.5,
24.5, 18.5, 17.2, 14.5, 23.2, 22.1, 20.5, 19.4, 18.1, 24.1, 18.5. We
know that the standard potato yield for the given variety is µ=20.Test
if the potato yield from these farms is significantly better than the
standard yield.
The potato yield from these farms is same as the standard yield.
The potato yield from these farms is significantly better than the
standard yield.
IN R
x=c(21.5, 24.5, 18.5, 17.2, 14.5, 23.2, 22.1, 20.5, 19.4, 18.1, 24.1,
18.5)
t.test(x,mu=20,altrnative=“greater”)
CONCLUSION: p value=0.4223>0.05,Accept .Therefore ,the potato
yield from these farms is same as the standard yield.
Example 3

A time study engineer developed a new sequence of operation


elements that he hopes will reduce the mean cycle time of a certain
production process.
The results of a time (in minutes) of 20 cycles are
12·25 ,11·97 ,12·15, 12·08 ,12·31, 12·28 ,11.94 ,11·89 ,12·16, 12·04,
12·09 ,12·15 ,12·14, 12·47 11·98 ,12·04 ,12·11, 12·25, 12·15, 12·34
If the present mean cycle time is 12·5 minutes. should he adopt the
new sequence?
IN R
time=c(12·25 ,11·97 ,12·15, 12·08 ,12·31,
12·28 ,11.94 ,11·89 ,12·16, 12·04, 12·09 ,12·15 ,12·14, 12·47
11·98 ,12·04 ,12·11, 12·25, 12·15, 12·34)
t.test(time,mu=12.5,alternative=“less”)
Example 4
A manufacturer of gunpowder has developed a
new powder which is designed to produce a
muzzle velocity equal to 3000 ft/sec.
Seven sheIls are loaded with the charge and the
muzzle velocities measured.
The resulting velocities are as follows: 3005,
2935,2965,2995,3905,2935and 2905. Do these
data present sufficient evidence to indicate that
the average velocity differs from 3.000 ft/sec.
Test for difference of means
Unpaired t test.
Procedure:
µ1=µ2 and
µ1≠µ2 is two tailed test
µ1< µ2 is lower tailed test
µ1> µ2 is upper tailed test
If sample means are and then test statistic is

If t< critical value at 5% level of significance with df, then accept .


Otherwise reject .
OR
If p< α (level of significant ) then reject H0 ,otherwise accept H0
Example:
Running capacity of two horses (in hours) on track for 8 days given
as follows-Horse A: 10,12,8,9,10,11,9,10 and Horse B:
12,10,9,10,11,12,10,11
Is two horses have same running capacity.
Two horses have same running capacity
Two horses have different running capacity
Given: = 9.875,
=10.625,= = 1.5305,
and t= 1.21
Critical value of t with =14 degrees of freedom at 5% level of
significance=2.145
1.21<2.145, Accept
Conclusion: Two horses have same running capacity
In R studio
1) Two tailed test
A <- c(10,12,8,9,10,11,9,10)
B<- c(12,10,9,10,11,12,10,11)
# Two tailed t test
t.test(A,B,paired=F,var.equal = T)
2) lower tailed test
#lower tailed test
t.test(A,B,alternative = "less",paired = F,var.equal
= T)
3) Upper tailed test
# upper tailed t test
t.test(A,B,alternative = "greater",paired =
F,var.equal = T)
Example 2

A group of 5 patients treated with medicine A is of weight 42,39,38,60


&41 kgs. Second group of 7 patients from the same hospital treated
with medicine B is of weight 38, 42, 56, 64, 68, 69, & 62 kgs. Find
whether there is any difference between medicines?
There is no significant difference between two medicines.
There is significant difference between two medicines.
IN R
Medicine_A=c(42,39,38,60 ,41 )
Medicine_B=c(38, 42, 56, 64, 68, 69, 62 )
t.test(Medicine_A,Medicine_B,paired=F,alternative=“two.sided”,var.eq
ual=T)
CONCLUSION: p value=0.07574>0.05,accept null
hypothesis.Therefore , there is no significant difference between two
medicines.
Example 3

The following data related the rubber


percentage of two types of rubber plants, where
the sample have been drawn independently.
Test for their mean difference.
Type I:6.21 ,5.70, 6.04, 4.47, 5.22,
4.45 ,4.84 ,5.84, 5.88 ,5.82, 6.09 ,5.59, 6.06,
5.59, 6.74 ,5.55
Type II :4.28 ,7.71,6.48,
7.71 ,7.37 ,7.20 ,7.06 ,6.40 ,8.93 ,5.91, 5.51 ,6.36
Example 4
In certain food experiment to compare two
types of baby foods A and B, the
following results of increase in weight (lbs) we
observed in 8 children as follows.
Food A: 49, 53 ,51 ,52, 47 ,50 ,52 ,53
Food B:52, 55 ,52 ,53, 50 ,54 ,54, 53
Examine the significance of increase in weight of
children due to food B
Paired t test
Procedure:
µ1=µ2
µ1≠µ2 is two tailed test
µ1< µ2 is lower tailed test
µ1> µ2 is upper tailed test
If sample means are and then test statistic is
t= where
, and d=difference of paired values
If t< critical value at 5% level of significance with n-1 df, then
accept . Otherwise reject
OR
If p< α (level of significant ) then reject H0 ,otherwise accept H0
Example:
Following data is regarding number of units produced by 10
workers before and after training of one month.
Before: 10,15,20,14,10,12,18,20,16,20 and
After: 12,14,20,15,12,10,20,21,18,18
Test whether training proves the production.
There is no improvement in the production after training.
There is improvement in the production after training.
d=after-before,= 0.5 , S=1.6499 , n= 10 and t=0.91
Critical value of t with =9 degrees of freedom at 5% level of
significance=2.262
0.91<2.262, Accept
Conclusion: There is no improvement in the production after
training
In R studio
1) Two tailed test
Before<-c(10,15,20,14,10,12,18,20,16,20)
After<-c(12,14,20,15,12,10,20,21,18,18)
# Two tailed t test
t.test(Before,After,paired=T,var.equal = T)
2) lower tailed test
# lower tailed t test
t.test(Before,After,alternative = "less",paired
=T,var.equal = T)
3) Upper tailed test
# upper tailed t test
t.test(Before,After,alternative = "greater",paired
= T,var.equal = T)
Example 2
The iron contents of fruits before and after applying farm yard manure were observed
as follows.
Before Applying :7.7 ,8.5, 7.2 ,6.3 ,8.1 ,5.2, 6.5, 9.4, 8.3 ,7.5
After Applying :8.1 ,8.9 ,7.0 ,6.1, 8.2, 8.0 ,5.8, 8.9, 8.7 ,8.0
Is there any Significant difference between the mean iron contents in the fruits before
& after the farm yarn manure?
There is no Significant difference between the mean iron contents in the fruits before
& after the farm yarn manure?
There is Significant difference between the mean iron contents in the fruits before &
after the farm yarn manure?
IN R
Before =c(7.7 ,8.5, 7.2 ,6.3 ,8.1 ,5.2, 6.5, 9.4, 8.3 ,7.5)
After =c(8.1 ,8.9 ,7.0 ,6.1, 8.2, 8.0,5.8, 8.9, 8.7 ,8.0)
t.test(Before,After,paired=T,aternative=“two.sided”)
CONCULSION: p value =0.3545>0.05,accept .Therefore , there is no Significant
difference between the mean iron contents in the fruits before & after the farm yarn
manure?
t test for correlation coefficient

The t value as follow:

If the p-value is < 5%, then the correlation between x


and y is significant.
Example1:
x: 10,12,15,4,16,20,15,18,21
Y: 8,10,14,3,18,20,12,15,20
r=0.96,t=9.07
t test for correlation coefficient in R
cor.test() test for association/correlation between paired
samples. It returns both the correlation coefficient and
the significance level(or p-value) of the correlation .
cor.test(x, y, method=c("pearson", "kendall", "spearman"),
alternative = c("two.sided", "less", "greater"), conf.level=0.95)
The results are :
• t is the t-test statistic value
• df is the degrees of freedom
• p-value is the significance level of the t-test 
• conf.int is the confidence interval of the correlation
coefficient
• sample estimates is the correlation coefficient
Example in R
x=c(10,12,15,4,16,20,15,18,21)
y=c(8,10,14,3,18,20,12,15,20)
# Two sided test
cor.test(x,y,method = "pearson")
#lower tailed test
cor.test(x,y,method = "pearson“,alternative=“less”)
#Upper tailed test
cor.test(x,y,method =
“pearson“,alternative=“greater”)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy