Lecture 30

IIT Kanpur July 201
20 followers
Mar 1, 2024
[Music]
hello friend welcome to the course
multivariate procedure with r so you can
recall that in the last lecture we have
understood that what is the concept of
test of hypothesis which is related to
the testing the value of some parameter
on the basis of given sample of
data now from this lecture we are going
to consider the case of normal dist
distribution which has two parameters mu
and sigma square and primarily we are
more interested in developing a test of
hypothesis for the
mean now this can be done under two
conditions when the variance Sigma
square is known or
unknown so in this lecture we are going
to consider the case when Sigma square
is known and in the next lecture we will
discuss the case when Sigma square is
unknown which is also estimated on the
basis of given sample of
data gradually we will move forward and
I will try to
develop the similar test of hypothesis
for the two samples as well as for
multivariate case well when I am saying
here that we are going to develop the
test of hypothesis for the mean in the
case of normal distribution it does not
mean at all that the test of hypothesis
for other parameters from other type of
probability density functions and
probability Mass function cannot be
done but as I have said several times
our job here is not to learn the test of
hypothesis but I want to give you here
an exposure or some knowledge about
those tools which I'm going to use in
the future lectures so in this lecture
we are going to consider the univariate
random variable and we will try to
construct the test of hypothesis when
Sigma square is known also we had
understood in the last lecture that
there is a close connection between uh
this confidence interval estimation and
the decisions on
guest of hypothesis and earlier we had
talked about what are the confidence
interval estimation so in this lecture
we will also consider uh the
construction of confidence interval
estimation under the same setup that is
confidence interval for the mean when
Sigma square is known and then I will
try to show you that how you can compute
these things in the our software so let
us begin our lecture so now we are going
to consider here the test and confidence
interval for mean in one sample with
known variance in univariate data right
so I already have explained you the
concept of test of hypothesis right and
we are going to Now work on it so as we
discuss that we need uh some assumption
for every test of hypothesis so when we
are trying to test
or or develop our test of hypothesis for
the mean when Sigma is know then it is
popularly called as Z test or gaus
test right
GS and in order to execute this test or
use this test there are certain
assumption uh which are known to us for
example the null hypothesis is going to
be specified by the statement H not mu
is equal to Mu not where this mu not is
some known value pre-sp specified value
Sigma is known to us from some outside
sample sources for example someone can
tell me okay in this case the value of
Sigma square is supposed 25 we assume
that the population is normal that means
the sample which we are dry from here
belongs to a normal population or the
second option is this if we don't know
about the normality or in case if the
sample size is here large which is more
than 30 the reason for it is that when
we try to consider the case when Sigma
square is unknown and is estimated from
the sample then in that case the
decision rule for both the case becomes
almost the same right so if you want to
test this hypothesis s not mual to Mu
right then the test statistics is like
this z c is equal to xar minus mu upon
Sigma by root n right so xar is the
sample mean which is obtained from the
given set of data and mu will be coming
from here mu is equal to Mu not and
Sigma Here is known and small n here is
the sample
size right you have to be careful in the
further lectures that where the N is
going to indicate the degrees of freedom
but here in this case this n is the
sample size and now we have to fix the
level of significance that is the value
of alpha say 0.05 or
0.10 and uh now the critical values that
whether we are going to accept or reject
the hypothesis on the computed value of
zc that is what we have to decide on the
basis of distribution of test statistics
z c which is which has got a normal
distribution with mean zero and variance
one when s not is true so that is why
these critical values for this test they
are obtained from the probabilities of
normal 01 right so I can say in general
that z c follows normal
01 under h not right that is what I told
you in the last lecture that we need to
find out the probability distribution of
the test statistics which is here zc
right so now how are we going to conduct
that test of hypothesis we are we have
to State our null and alternative
hypothesis H not and H1 then we need to
compute the value of the test statistics
zc on the basis of given set of data and
then we have to obtain the critical
value for a fixed value of alpha
according to the hypothesis whether it
is right tail left tail or two tail test
then we have to compare the computed
value of z c with the critical value and
then we have to make the decision
accordingly alternate alternatively if
you want to use the P value also then
you can use the P value to make the
decision about the acceptance or
rejection of the null hypothesis right
so how to compute this P value we have
discussed in the last lecture just for
your quick revision that here in this
case z c is the value of the test
statistics which is computed on the
basis of given sample of data and this
follows a normal 01 so the P value is
given by this following probabilities
when we are trying to consider a two
tail test then it is comped the twice
the probability of Z greater than
absolute value of z c for right tail
test it is computed as probability of Z
greater than z c and for left tail test
it is commuted by here probability Z
less than z c and uh in in case if you
want to use it then the decision is like
this that H not is rejected in favor of
H1 at 100 Alpha per level of
significance if P value is less than
Alpha and this P value is the smallest
level of significance at which s not
would be rejected so if you try to see
when you are trying to work for the test
of hypothesis that becomes very simple
right so now we see how to conduct this
test of hypothesis in the art software
so this test is available in the our
software in a package composition c o m
p o s i t i o NS which means
compositional data analysis for this
package is to be installed first using
the command install. packages and then
you have to upload the library
compositions now this test is available
by the command here gus. test
gs. T but you have to be careful that g
here is uppercase right so from this
test we can have one sample test two
sample test with equal mean of normal
variates and known variant of what is
this mean initially I'm going to
consider here only the one sample test
but later on I will extend it to two
sample test right so in that case you
will see the same package same command
is going to work there only small
modification will be needed so the
command to conduct this test here is
like this gaus do test and then you have
to see here X which is the data on the
on which we want to conduct that test of
hypothesis X Y here is actually null
because as I said this the same command
can be used to test the equality of the
means from the two population which is a
two sample test but here we are using it
only in the case of one sample test so
that is why we are writing here Y is
equal to capital n u l so if you
remember once in the lecture we had
discussed the concept of n and n that
null is something which does not exist
now we have to give here the value of
mean me a an then we have to give here
the value of a standard deviation which
is the value of Sigma right and then now
this alternative hypothesis can be of
three type two-sided less than greater
than so that has to be indicated here by
the option alternative is equal to
two-sided less or greater and you have
to choose only one whatever you are
going all these values are given here so
that you can understand that that there
are three possible values and then you
have to choose one value right so you
have to choose one option depending on
your requirement right so as I said that
X is a numeric Vector providing the
first data set Y is the optional second
data set which will be used when we try
to conduct the two sample test of
hypothesis mean is the mean and to
compare with LD is the standard
deviation which is known and alternative
is that the nature of the alternative
hypothesis so now let me try to show you
this with an example uh suppose if we
have a random sample of size 20 on the
day temperature in a city and we have
collected 20 observation and suppose the
temperature in the population follows a
normal distribution whose mean mu is
unknown but Sigma square is 36 it is
known so the sample values of
temperature in degrees celsius they are
reported here like this and based on
that we estimate the MU had as sample
mean that is
esate of me right so on an average I can
say that the temperature in the city at
this time is
[Music]
you will see that I will be using this
example and the same data set in
different lectures so that you can
compare that how the things are changing
right now if I want to test that the
null hypothesis is mual to 30 versus
alternative hypothesis mu is not equal
to 30 what does this mean I am trying to
make a statement here that the value of
the mean in the population is 30°
C and my alternative statement against
which we want to T the null hypothesis
is that the MU is not equal to 30 that
means the population temperature is not
equal to 30° C so I try to give here the
data using the command gs. test xal to
Temp now y equal to here n mean is equal
to here 30 this is coming from here mu0
30 and SD you can see here this variance
was given to be here 36 you can see here
so this Sigma becomes here 6 Sigma
square is here 36 now alternative here
is two-sided how if you try to see here
the structure of mu not equal to 30 from
there I'm trying to say that it is
two-sided just of hypothesis and this is
here the outcome so you can see here
this is here T so this is the value of
here zc mean here is this equal to 30
this is the value of here mu0 SD here
equal to 6 this is the value of your
Sigma and now you can see here P value
is coming out to be like this 1 into 10
power of your - 6 which is very small
very close to zero and the alternative
hypothesis is here two-sided so now you
can see here your rule was H not is
rejected if P value is less than Alpha
so if you try to choose here Alpha is
equal to 0.05 which is 5% level of
significance and your P value here is 1
into 10^ of minus 6 what do You observe
that P value is much lower than the
value of alpha so I can say that here H
not is rejected what does this mean h
not is rejected mean h not is mual to 30
is rejected that means mu is not equal
to 30 and if you try to see this also
makes sense if you try to see here that
you had obtained the sample mean to be
that means the data is saying that the
average temperature is close to
42° and we are saying that the
temperature here is Mu equal to
30 so definitely there is a huge
difference between the two value and
that is the same thing it is is implied
by saying that s not is rejected so s
not is rejected
means H1 is
accepted H1 is accepted mean mean is not
equal to
30 right and that makes sense now it is
not telling you that what is the correct
value of mean remember one thing test of
hypothesis cannot tell you that what is
the correct value of mean it can only
tell you whether the value you have
chosen is correct or not so now we try
to change the alternative hypothesis and
other things remain the same s not will
remain as Mu equal to 30 and H1 is Mu
less than 30 so the same data set i'm
going to use here so this the command
here will remain the same x value y
value mean SD they will remain the same
only alternative is going to be changed
as less so yeah I'm just trying to show
you that if your null hypothesis remain
the same and alternative hypothesis is
changed then how are you going to
control it right so now if you try to
conduct this test the our software
outcome has this type of values so you
can see here this is data here is the
same temp t value will remain the same
as earlier mean SD that is given now P
value here is one so you can see here as
you try to change the alternative
hypothesis this P value is changing
right so if you try to see here p is
equal to here one and Alpha suppose if
you try to take here
0.05 so your rule
was reject H if p is less than
Alpha right so in this case you can see
here P value here is one and Alpha is
here
0.05 right so you can see here now the
decision is changed right so and this is
here the screenshot of the same outcome
right so let me try to show you these
things on the our software so that you
get here more confidence right so let me
try to just uh copy this data over here
and upload the Library command so
Library composition command so you can
see here now here we have the
temperature is here like this and now if
I try to use here this command here G do
test on the temperature data it is going
go to here like this you can see here
this is the same value which is changed
right and if you try to use here the
same data set but if you try to say here
use here can see here in this slide
there were two options I will try to
show you here both these
options less and greater right you can
see here this is here less and this is
here greater so if I try to use here the
command here greater you can see here
this P value is here like this and if I
try to change here this here
less so then you can see here the P
value here is now changed so depending
on your alternative hypothesis this P
value is going to change
and uh yeah in the first case when I'm
trying to take two-sided alternative
that means H is mual to Mu 0 and H1 is
Mu is not equal to Mu whereas when I'm
trying to take it here greater than so
it is alternative here is Mu greater
than mu and when I try to say here less
then the alternative is Mu less than
mu right so this is how we can conduct
such hypothesis or we can test such a
hypothesis right now I come to the
confidence interval estimation under the
same setup so now we have got here a
random sample X1 X2 X1 from a normal
population with unknown mean mu and
known variance Sigma not a square so we
have already used the point estimator
say this sample mean Capital xar to
estimate the MU and now we want to
construct the interval estimate right
this xar equal to 1 upon n summ x I was
the maximum likel estimate of mu so now
I'm not going into that much detail but
there is a central limit theorem which C
us that xar follows distribution normal
which is the mean mu and variance Sigma
squ upon n so here the variance is Sigma
not a squ so xar will follow a normal
distribution with mean mu and variance
Sigma Square upon n well this is the job
of the statistician who are working in
theory to derive such distribution and
based on that if I try to create here a
statistic square root of n xar minus mu
upon Sigma then it will follow a normal
distribution with mean zero and variance
one right well you need not to worry
those who are not from the statistics
background that is the job of the statis
to find out the probability distribution
of such statistics so but now I know
that because it is following a normal
distribution so what I can do here that
I would like to see for example if this
is my here normal so I know that there
will be some values on the left hand
side and some value on the right hand
side of this mean zero so this value on
the left hand side can be minus Alpha by
2 then the value on the right hand side
at the same distance that will be plus z
alpha by 2 right so now I want to find
out the probability that my here this
statistic Zed s otk of n xar minus mu
upon Sigma what uh is the probability
that it will lie between minus z alpha
by 2 and plus Z alha by 2 and I fix this
probability as 1 minus Alpha what is
this probability here I'm trying to take
here this area as a alpha by 2 this area
as say here Alpha by 2 now this area
will become here 1 minus Alpha so now
I'm trying to write down Qui equation
that uh what will be the value of mu
such that the probability that s root of
n xarus mu upon Sigma is lying betweenus
z alpha by 2 and plus by 2 whose
probability is 1 minus Alpha right and
if you simply try to solve this equation
this will come out to be like this that
mu should lie between xar minus z alpha
by 2 Sigma upon root n and xar + z alpha
by 2 Sigma by root n right so yeah as I
told told you that square Alpha by 2 is
the 100 Alpha by 2% points on the normal
01 distribution or in terms of quantiles
this is the alpha by 2th quantile on the
normal 01 so now I can see here that
this is the lower
limit of the confidence interval and
this xar plus Alpha by2 Sig 0 by root n
this is the upper
limit of confidence interval and if you
try to recall that when we introduce the
concept of confidence interval
estimation while introducing the
estimation right or statal
inference then we had indicated this
lower limit to be head head Theta head
L and this upper limit was indicated
here as the Theta h u so now using the
same terminology I can write down here
that 1001 minus Alpha per confidence
interval for Mu is is this interval
Theta hat L Theta hat u based on the
sample X which is here like this xar
minus Alpha by 2 Sigma by root n and xar
+ Alpha by 2 Sigma by root n so you can
see here if you get here some sample
values so if you try to see here this is
depending on xar this is depending on z
alpha by 2 this is depending upon Sigma
0 and this is depending on here n so X
this can be computed on the basis of
given sample of data this alha by2 is
known from the
table Sigma 0 is already
known and N is also known which is the
sample size so you can compute this
interval and then you can see that okay
that with the for example if I say take
Alpha is equal to 0.05 then I can say
that there is a 95% confidence interval
for new is that mu is lying between
these two values so that is the same if
you try to recall once I take an example
that when uh you want to compute the
time taken from your home to your
college then there are two option that
you try to collect some data that for
cutter number of days you record the
values of time taken and then you try to
take the sample mean and then sample
mean will come out to be some value that
will be the point estimator and if you
um suppose sample mean comes out to be
suppose you 20 minutes then it is a
point estimate but if you want to know
the other alternative is that okay it
will that you will take between 15
minutes to 25 minutes this was the cont
confidence interval so now I have shown
you here how are you going to construct
this confidence interval based on the
given sample of data so this is the
confidence interval for mean whose
confidence coefficient is 100 1 minus
Alpha perc right so this 100 1us Alpha
perc this is called
as confidence
coefficient
right so and if you try to understand
this thing through this graphic so as I
said suppose if you try to consider here
the distribution of normal 01 so the
mean is here zero so this area here in
the green color which I am shown you
this is the area Alpha by two so
corresponding value at on the xaxis
there will be z alpha by 2 on the right
hand side and minus Alpha by 2 on the
left hand side and on these two side
there will be somewhere minus infinity
and plus infinity but when you are
trying to compute the confidence
interval now this will also follow on
the normal contribution but now mean
here is Mu and this is lying between
these two limits so the limit on the
left hand side is xarus z alpha by 2
Sigma 0 upon root and this area here is
Alpha by by 2 and on the right hand side
the the area is the same Alpha by 2 but
this limit is now here xar + z alpha by
2 Sigma 0 by root n so this is the basic
idea and this area in say red this is 1
minus Alpha right so this is the
interpretation and the same
interpretation will continue in all the
cases whenever we want to do it now I
would like to show you that how are you
going to construct the confidence
interval well in the case of confidence
interval for Mu uh when Sigma square is
known this is not available in the
outcome of the art software but uh this
will be available when in the software
outcome when Sigma square is known so in
this case I'm going to take the same
example of the temperature where we have
collected the data on say 20 days n
equal to 20 and we have the data on the
temperature and uh we are going to
construct this confidence interval by
writing our own program which is is not
very difficult right so if you try to
see here now the temperature data is
here now you can compute here the if you
try to see this confidence interval is
depending on here mean and standard
deviation right so so simply have to
write down here xar which is obtained
here by mean of Temp and then you have
to obtain the value of z alpha by 2
which is here Norm 0.975 how if you try
to see here uh this normal distribution
this area here is
95% and so this area is here 5x
2% and this area on the right hand side
is 5 by 2% so this is here uh means if
you try to see here it is here I will
use here a different color pen it is
here 0 point means if you try to see
here this is here 1 minus Alpha by two
and this area here is Alpha by 2 like
this so this comes out to be here 1us
Alpha by which is here
0.975 and now Sigma 0 is given to us and
then square root of length of
temperature which is the number of
observation and if you and similarly you
can compute here the upper limit by just
by replacing minus by here plus sign
that is xar + Alpha by 2 Sigma by root
10 so it is not difficult and if you try
to compute it you can see here that um
it will here come like this so now you
you can see here Sigma 0 is here six as
given and uh this qor can be obtained
directly from the r software and square
root of length of temperature that can
be obtained directly from the uh data
Vector Temp and then Sigma 0 is given so
this value comes out to be 39.3 and
similarly if you try to compute the
upper uh confidence limit this will be
come out to be like this just by
replacing minus by plus sign
right this will come out to be 44. here
59 so I can say here that uh you can see
here now if you try to consider this
thing the point estimate was here
41.979747
n so yeah close to the point estimate
was close to 42 so now the
interpretation is that on the basis of
given sample of data I can say that the
point estimator is 42° and the
confidence interval is a 39.33621
[Music]
and now I try to write down here the
lower
limit which is here like this and and
upper limit if you want you have to
Simply make it here uh see here plus
sign as you can see here it is here like
this okay so now we come to an end to
this here uh lecture and you can see
here that we have considered here a very
simple test of
hypothesis my objective was to
illustrate you how are we going to
conduct such test of
hypothesis so we have considered the
case when we want to test a hypothesis
about the mean from a normal population
and we want to test s not me is equal to
mu0 in a univariate case in a single
Sample When Sigma square is known now
similarly what will happen in the case
when Sigma square is unknown that is the
actually more realistic case so that we
are are going to consider in the next
lecture but the process is going to be
the
same as we have seen that the statistics
square root of n xar minus mu upon Sigma
that is following normal
distribution similarly when Sigma square
is unknown and that is estimated from
the
sample then we would try to replace
Sigma
by this estimated value and then we will
try to see that the distribution of the
statistics will become T distribution
what was T if you try to recall sometime
back you have done the sampling
distribution Kai sare T and
F so then we will see that how are we
going to conduct the test of hypothesis
but this steps and the way we have taken
the decision for conducting the test of
hypothesis and construction of the
confidence interval that will remain the
same so it is very important important
for you that if you want to understand
the further couple of
lectures all the steps whatever I have
explained you here they should be
crystal clear in your
mind what are we do uh doing why are we
doing what are the different steps yes
some steps will be varying in comparison
to what I told you in the last
lecture because now since we are using
the P value so that the test of
hypothesis through simple uh in the case
of this software becomes easier for us
and it is pretty
simple in comparison to you try to look
into the Z value from the table or
similarly the mean other type of
critical values from the table then then
you try to compare it manually right so
this is how we are going to proceed
further so my request is once again that
you please try to look into this lecture
try to revise
it so that you are well prepared for the
next lecture and I will see you in the
next lecture till then
[Music]
[Music]
[Music]
goodbye
