Lecture 32

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 two lectures we
have considered the test of hypothesis
for the mean from a normal population
normal mu Sigma Square under two uh
situations when the population variance
Sigma square is known and when it is
unknown and we had considered there one
sample test that means we had only one
variable on which we are trying to
obtain the data in practice there are
many situation where we want to compare
for example I want to compare whether
the population mean of two different
population is the same or not on the
basis of given sample of data
for example if I say there is some
medicine and Suppose there are two
medicines to control the body
temperature now both these medicines are
given to uh to a group of patient
suppose I have group one to whom I have
given the medicine number one I have
group number two where I have given the
patient uh the medicine number two to
the patients now I want to
see whether these two medicine they have
a different effect or they have the same
effect or also whether medicine one is
giving a better outcome in the sense
that it can control the body temperature
for a it can maintain the or it can
bring down the body temperature in a uh
lower time Etc different questions can
Beed about the comparison of the
different uh type of body temperature in
the two groups of the patient so now
suppose if I want to address these types
of issue in simple way I can say I want
to know whether medicine one is more
effective or medicine two is more
effective or whether medicine one and
Medicine two both are equally effective
or they are they have different effects
so in this case we have two
samples so under this type of
situation when we want to make a
comparison using the test of
hypothesis then how to do it
so I have here two
condition that I have here two samples
which are drawn from two different
normal populations and these populations
are differing with respect to the mean
yes they can differ with respect to the
variance also but in order to understand
this concept over here I'm considering
that they are differing with respect to
the mean mean only and they have got the
same population variance now this
population variance which is common to
both the population in the sense that
they are they have got the same value
that can be known or that can be unknown
so when it is known then in the case of
one sample test we have uh used the gaus
test and we had used the command gaus
dos test in our software and when this
Sigma Square was unknown then we had
computed it we had estimated it on the
basis of given sample of data and we had
used the T do test command that was
built in in the base package if you
recall at that time I had told you that
in these commands I had two options X
comma Y where I had asked you to use y
equal to null because we were
considering only the one sample test but
now we are in a position where we are
going to use both X and
Y so in this lecture we will consider
both type of test of H
hypothesis when Sigma square is known
and when Sigma square is unknown and we
would like to compare the population
means of two normal population so let us
begin our lecture and try to understand
so now in this lecture we are going to
consider the test for mean in the two
samples with the univariate data right
so first we try to consider the case
when the population variances are known
so we have got here two populations
which are differing with respect to the
means and they have got variances but
they are known to us right so we are
interested in testing the hypothesis for
the difference of mean difference of
means means for example if I try to
write H not mu1 equal to mu2 then this
can also be written as H1 mu1 minus mu2
is equal to Z or in more general
statement I can write in mu1 minus mu2
equal to Delta right so and both this
sample they have been drawn
independently from the two population
which are normal mu1 Sigma 1 square and
normal mu2 Sigma 2 squ right so now we
have now these two samples from normal
mu1 Sigma 1 a squ and normal mu2 sigma2
square and uh the first sample is of
size N1
and it is drawn from a population whose
mean is mu1 and variance is Sigma 1 squ
which is
known and then we try to compute or
estimate the sample mean which is here
X1 bar then we try to consider the
second sample of size N2 which is drawn
from a population which has population
mean mu2 and population variance Sigma 2
s which is also known and then we try to
estimate Mewtwo by the sample mean xar 2
and we wish to examine if two population
mean mu1 and mu2 are the same or they
are different right so now uh the null
hypothesis is going to be H mu1 equal to
mu2 right and then we have here three uh
possibilities to construct the
alternative hypothesis so one option is
that I can consider the two-sided
hypothesis that is H1 mu1 is not equal
to mu2
right or other alternative is that I can
consider one-sided hypothesis H1 mu1 is
greater than mu2 which is your here
right tail test or H1 mu1 is less than
mu2 which is a left tail
test and this two sided it is a two-tail
test right now because population mean
mu1 and mu2 are
unknown then we try to use the
statistics X1 bar - x by2 to make some
conclusion about mu1 minus mu2 right so
we are assuming here that Sigma 1 and
sigma 2 both are known both the parent
population are normal uh or I can assume
that sample size N1 and N2 are large if
you try to see these assumption are
similar to the test or say is test that
we have considered in the earlier
lecture right now we know that sample
mean X1 bar will be following a normal
distribution with mean mu1 and variant
Sigma 1 s upon N1 the second sample mean
X bar2 will be following a normal
distribution with mean mu2 and variance
Sigma 2 s upon N2 So based on that I can
write down the expected value of X1
barus X bar2 is mu1 minus mu2 and
variance of X1 bar - x by2 is uh Sigma 1
s upon N1 + Sigma 2 sare upon N2 and the
co-variance between xar 1 and xar 2 will
be zero because they are drawn
independently based on that we try to
create here a test
statistic see here z c so if you try to
see here this hypothesis H mu1 = to mu2
I'm trying to consider here as say H1 H
mu1 minus mu2 is equal zero right so now
if you try to look at this Statistics
say X1 bar - x 2 - 0 then the zero is
coming here because of this
zero right in case if that is something
else say Delta then the zero will be
converted to Delta so now I try to
divide it by the standard deviation
Sigma 1 sare upon N1 plus Sigma 2 sare
upon N2 and a square root so this is the
test statistics and when H not is true
then this zc follows a normal 01
distribution and so we try to use the
probabilities from the normal 01
distribution to compute the critical
values and the P values right so now if
you want to implement this test in the r
software then as we have discussed
earlier that we are going to use the uh
command gaus do test which is available
in the library compositions right
compositional data analysis so this has
to be installed first and then this has
to be uploaded so this can be done by
using the command install. packages and
Library
compositions and uh we have used it
earlier in the one sample test case now
the same command I'm going to use it in
the this two sample case also so the
command here will be gaus do test G here
is in uppercase
alphabets now you can see here this x is
indicating the sample value from the
population one so this is sample one and
Y is the
value which is in the sample two right
then mean here is zero this zero is
indicating this value H not mu1 - mu2 is
equal to 0 this Zer is this zero
here
right and standard dation well it is
here one but that you can give here any
value right and uh yeah on the other
hand I can also say that if if you are
trying to consider H not mu1 minus mu2
is equal to some Delta then this zero
will be replaced by this Delta value the
alternative will remain the same as per
your choice and the requirement as
two-sided less or greater as we have
done in the earlier Command right so
yeah this is the same thing that I just
explained you so now we try to consider
an example and we try to implement it in
the our software right uh suppose we
have two samples which are about the
gain in the weights in grams of Fes
which are given two different types of
dietes say call As A and B so ises are
given two types of dietes A and B with
an objective to understand whether which
of the diet is going to increase more
weight right so the increase in the
weights of these fishes they are
recorded here as a in the diet a as like
this in grams and in diet B they are
recorded here as say in grams and
suppose the standard deviation is known
to be here two right and we want to test
if the two dietes differ significantly
as regards their effect on the increase
in the weight right this standard
deviation two it is actually the value
of Sigma 1 s upon N1 plus Sigma 2 s upon
N2 right so I'm just assuming it to be
no known so now if you try to see I try
to give this data in two data Vector x a
and XB right now I try to use here the
command ga. test and the first data set
XA from here second data set XB from
here mean is equal to zero because H mu1
minus mu2 is equal to0 standard devation
is equal to 2 this is known this is
given to us and alternative I'm trying
to take say two-sided
H or say H1 mu1 is not equal to mu2 and
this is here the outcome you can see
here so you can see here the data here
is used here like this and T here comes
out to be here minus 2 this is the value
of the test statistics and P value comes
out to be here 0.
9823 right so now the rule here is that
if P value is equal to
0.0098 and suppose you have chosen the
level of significance Alpha to be 5%
level of significance then the rule here
is
reject H if p is less than Alpha so P
here is
0.0
098 and Alpha is at
0.05 so what do you think this is
correct so in this case this H mu1 = to
mu2 is rejected
that means gaining the weights from this
D A and diet B they are not equal or
alternatively H1 mu1 is not equal to mu2
is
accepted that is correct that both the
dietes are giving on an average
difference increase in the gain in the
weights right okay so now this is here
the screenshot and now I try to show you
this thing in the AR console also so
that you can be more confident about it
right so first let me try to load this
package although so now this here is
Library composition as I said I already
had uh uh uploaded this thing in my
computer now I try to give here the the
data here and we try to execute this
command here so you can see here this is
here like this now if you want to change
the alternative you can make it here
less or if you want to make it here
greater greater you can see here here
like this
right so you can see here that the P
values in the three alternative that is
coming out to be
different right okay so now let me come
back to my here slides and try to
consider the other test so now we move
forward and our problem or the statement
of problem is the same that we want
toess the hypothesis about the equality
of two means from two different
populations which are the normal
population whose means are different and
their variances are not known so up to
now we have assumed that Sigma 1 and
sigma 2 both are known and for that we
have used the statistic zc which used to
follow not Al 01 under H not now we are
going to assume that both Sigma 1 and
sigma 2 or Sigma 1 square and sigma 2
sare they are unknown and in this case
we are going to use the T distribution
that means whatever be our statistic
that is going to follow a t distribution
now this is a similar case if you try to
recall that in the last lecture we have
considered this setup in a single sample
and uh we have used the command t. test
so in order to now extend it to two
sample the same assumptions are going to
continue but then there is small
variation we are assuming that both
populations are normal that mean the
samples are drawn from a normal
population and we are assuming that both
Sigma 1 and sigma 2 are equivalent to
Sigma 1 square or and sigma 2 square
they are unknown but they are equal
there can be other case also that they
are not equal but the test statistics
for that case is different than what we
are going to do here that is called as
Fisher bar problem and that is handled
in a different way and that is
applicable when uh Sigma 1 square and
sigma 2 square they are unknown as well
as unequal right and in the two sample
case also if the sample size is large
enough say greater than equal to 30 then
we can approximate the T probabilities
by the normal 01 also and the reason is
the same what we have discussed earlier
in the case of one sample test so now we
have here the same set of hypothesis
that my null hypothesis is H mu1 equal
to mu2 and my alternative can be mu1 not
equal to mu2 mu1 is greater than mu2 or
H1 mu1 is less than mu2 now we are
observing a sample of size M from normal
mu1 Sigma square and another sample of
size small n y1 Y2 YN from normal me2
Sigma 2 s right and both mu1 and mu2 are
unknown so we try to estimate mu1 by say
xar and mu2 by y bar so I can uh use
this xar minus y bar to make conclusion
about mu1 minus mu2 why because if you
try to see this null hypothesis can also
be written as H not mu1 - mu2 is equal
to Z so now we have here both Sigma 1
and sigma 2 both are unknown but they
are assumed to be equal so now we try to
create here the test statistics so we
know that xar will follow a normal
distribution with mean mu1 and V Sigma 1
s upon M the sample mean Y Bar will
follow a normal distribution with mean
mu2 and variance Sigma 2 s upon n and
expected value of xar minus y bar will
be equal to mu1 minus mu2 and now we try
to compute or estimate the VAR
as cooled variance how to do it we try
to estimate the variance Sigma Square by
this
expression 1 upon m + n minus 2 and then
inside the backet summation x i - xar S
Plus summation y i - Y Bar s right now
based on that we try to construct here
the test statistics which is here like
this DC so once again if you try to see
I had the null hypothesis mu1 minus mu2
equal to Z so we try to write down TC
here as say xar minus y bar minus 0 this
zero is coming from here right and
divided by the standard error which is
here like
this right so this is my T statistics TC
which follows our T distribution with M
plus and minus 2 degrees of freedom when
H is
true so in case if uh sample is large
then we can use the normal distribution
to get the critical values or when we
are trying to use the software then we
can use the P values to get the uh to
get the conclusion or the decision about
the test of hypothesis so now let me try
to take here the same example about the
diet a and diet B which are given to FES
and we want to test whether the effect
of these two dietes in increasing the
weights of the fishes is the same or
different
all right so this is the same example
the only difference is that earlier I
had assumed the standard deviation to be
known as to but now I don't know and I
would like to estimate it on the basis
of given sample of data so this is here
the data on D A and D B which is stored
in say two data Vector X and XB but now
suppose the standard deviation is
unknown right so we will estimate it
from the sample and now we want to test
the same hypothesis s not mu1 equal to
mu2 versus S1 mu1 is not equal to mu2
now if you try to see the command here
the command here is the same what we
used head earlier exactly the same
command now the only difference here is
this now I am giving here x as x a and
data on y in the one sample case it was
null but now it is here given as here
say XB that we already have understood
in the earlier uh lecture and in the
earlier command also the alternative
here is two sided mu is equal to here
Zer it is coming from here mu1 minus mu2
is equal 0 and paired is equal to false
why because it is not a paired test
because we are getting uh the samples
independently to samples are
independent if you recall if I in the
earlier lecture I had explained you that
under what type of condition the
observations are going to be paired and
then we try to use the paired T test
right now the next option is variance do
is equal to true so now you can see here
I have assumed that the two samples are
coming from two different normal
population which are differing with
respect to only means mu1 and mu2 but
their variances are unknown but equal so
now I have to give here true V are DOT
equal that is variance equal is equal to
true the level of significance Alpha
here is uh suppose I take 5% to conf dot
level will be 1us Alpha which is here 1
minus 05 which is 0.95 now if you try to
see here this is the outcome so this is
the two sample test data used here is XA
and XB and this is here the value of
T right and this is here the value of
degrees of freedom m + nus 2 and this is
here the P
value alternative hypothesis is is
two-sided so the two difference in the
mean is not equal to zero right is H1
mu1 minus mu2 is not equal to Zer and
the 95% confidence interval here is
obtained like
this right and the sample mean of X and
Y they are obtained here like this 28
and
30 right so if you try to see that if I
try to conduct it on the this R console
also this is screen shot here which I
would like to show you now right so if
you try to see we already had stored the
data on say XA and XB when we conducted
the test when Sigma 1 s and sigma 2 s
are known so XA is here like this XB
here is like this and if you want to
consider here this T Test you can see
here this is here the outcome right so
you can see here that it is the same
outcome which I shown you on the our
console now if you want to change here
the alternative hypothesis suppose if I
want to take it here Le than type left
tail
test so in the left tail test it is
coming out to be here like this the
confidence interval is changing the P
value is changing and if I want to make
it here for greater than means H1 is mu1
greater than mew2 so for that you can
see here I simply have to change the
alternative and you can see here that
the T value will remain the same in all
the cases the confidence interval is
changing and the P value here is
changing right right so now we come to
an end to this lecture and uh you can
see here that in this case what we have
done whatever we have done in the last
two lectures they have been extended
from one sample to two
samples but if you try to see the way
they have worked that is the same the
methodology is the same the only
difference is
coming because now we are using
different test statistics when Sigma 1
square and sigma 2 square are known or
in general when the variances are known
then the test statistics is following a
normal 01 distribution and when the
variances are unknown then it is
following a t distribution you have to
be careful that when you are going for
the case when uh variances are unknown
then there are two possibilities that
the two variances of the population they
are equal or say unequal based on that
you have to choose different statistics
well when they are unequal uh we try to
that problem is actually called as
Fisher bam problem but now you see in
the software you need not to worry you
simply have to just uh change with
where do equal is equal to false and you
are
done and after that you have to Simply
look into the value of p and then you
have to compare it with Alpha so that is
the advantage that when you are trying
to conduct the test of
hypothesis in a software then many
things become easy but it is important
for you to understand that what is
happening in the background that is why
this theory is
important so now uh we have couple of
jobs first we consider one sample test
then we consider then we extended a two
sample
test now would you like
to extend it to a general setup when
when you want to or would you like to
compare more than two population
means the next option will be you are
considering here a univariate random
variable
but would you like to consider it in a
multivariate
data then whatever you have done one
sample test two sample test Etc would
you like to extend it to a multivariate
setup yes that is our objective what we
are going to achieve in the next
lectures but in order to understand them
it is very important that by this time
you have uh completely understood the
philosophy behind the one sample test
two sample test and the different type
type of conditions and what are the
different methodologies as uh as well as
steps which are involved in the conduct
of test of hypothesis so for that I
would request you you try to create two
data set yourself in one data set you
try to maintain lower variability and in
other data set try to maintain higher
variability and then try to see try to
compare them what happens or try to take
the two data set which is are of the
similar nature similar values and try to
compare them try to create different
types of hypothesis try to interpret
them the interpretation is very
important but one thing I would like to
explain you here before I leave that all
these tests of hypothesis they are based
on certain rules of the statistical
inference whatever Z statistics T
statistic either in one sample or two
sample you have used they are derived
using the Nan Pearson
LMA and neon Pearson LMA gives us a
methodology to derive such good test
under the
assumption that the null hypothesis has
been constructed in such a way such that
type 1 error is more serious than type
two well both are serious type one and
type two
both but the way this Z test and T Test
whatever we have considered and whatever
we are going to consider in the further
lectures
also they are also constructed on the
same assumption that the null hypothesis
has been constructed in such a way such
that type 1 error is considered to be
more serious than the type two errors
that mean the consequences arriving
arising by the violation of the type one
error are more serious in nature than
the type two
errors well the reason is that it is not
possible mathematically to minimize both
the errors simultaneously if you try to
minimize one the other goes up and vice
versa so that is why one is kept fixed
the alpha is kept fixed at 5% 1% level
and the second error is minimized in the
best with the best
level yes you can also uh also ask me
what if if the type two error is more
serious then yes you can derive
different test statistics
and then you can conduct the test of
hypothesis but definitely this is not
the objective in this course I'm not
going to tell you how to do this thing
so better is to use this existing test
of off of hypothesis statistics and try
to frame your null hypothesis in such a
way such that type 1 errors is comes out
to be more serious than the type two
error so you try to practice it try to
take some data try to expose them to the
art software try to understand the
theory behind these test of hypothesis
from the books and I will see you in the
next lecture till then
[Music]
[Music]
[Music]
goodbye
[Music]
