noc21- ma35 - lec11

IIT Kanpur July 201
20 followers
1 Video View·Dec 3, 2023
[Music]
[Music]
hello friends
welcome to the course essentials of data
science with r software
one in which we are going to handle the
topics of
probability theory and statistical
inference so you can recall that in the
earlier lecture i have
given you the basic elements which are
required to define the probability of an
event
now in this lecture i will take up the
issue and based
on those concepts i will try to define
the
probability probability is such a thing
which you
are learning right from an elementary
classes
this elementary class means like class
10 or class 11 12
etcetera one of the basic definition
which you have learnt in probability
theory is something like
m upon n type of definition that you try
to
count the total number of favorable
and you try to divide it by the total
number of possible cases
but now in this definition i personally
believe that there is a
problem in understanding it sometime
people ask
us that okay the probability of getting
a head or a tail in the toss of a coin
is one by two
what does this mean in case if i try to
toss the coin two times
do you expect that one time i will get
head and one time i will get
tail or in case if i roll out
dice where where the point one two three
four five and
six may come they ask us okay what do
you
think if i try to roll a die for the six
times then you
believe that one time it will be one
then two
three four five and six and they will
occur only once
and if you try to see it does not really
happen in practice
even if you try to toss a coin
say four times there is a possibility
that there may be
three head or one tail there may be one
head and
three tail there may be two head and two
tails also
so what does this mean
you are saying that the probability is
one by two
but when you are trying to conduct this
experiment
the total number of favorable cases
divided by the total number of cases
that is not exactly coming out to be
always one by two
so now this is the question which i am
trying to
explain you here well i am not saying
that
this definition is wrong this definition
is correct
but possibly it requires a better
understanding
so what i will try to do in this lecture
that i will try to introduce this
concept and i will try to
explain you that how you have to
interpret it
and well it is not possible here to
toss a coin say 500 times or 1000 times
but definitely i will try to take the
help of our software to show you
that when you are trying to compute such
probabilities or when you try to say
that the probability of
occurring of a head or tail is 1 by 2
what does this really actually mean
so ok so let us begin our lecture and
try to understand
the probability theory from the relative
frequency
point of view now the question is what
is relative frequency that you know
relative frequency is simply
if you try to repeat and experiment for
some number of times
you try to see that how many times an
event is occurring
for example if you try to roll a dice
say this hundred times and you try to
count the number of times
the number one is occurring number two
is occurring three
four five and six are occurring and you
try to divide it by hundred
so that is your actually relative
frequency so now i will try to connect
this relative frequency with the
probability theory and i will try to
give you a better interpretation that
how you should interpret the
probability so let us begin our lecture
ok so now one thing i can tell you here
that there is a close connection between
the relative frequency and the
probability of an
event we know that whenever we are
conducting an experiment we really mean
that
our experiment is actually random random
means because
for example if you are tossing a coin
then yes you know the possible outcomes
that either there will be head or tail
but unless and until you have cost the
coin you do not know whether you are
really going to head
or a tail from that point of view we
call this experiment as a random
experiment
so this random experiment is described
by its possible outcomes for example
when you are trying to roll a die means
say you will getting a number between
one to six means one two three four five
or six
and similarly suppose there is an
experiment which has not only two
outcome
and possible outcomes so obviously these
outcomes are
going to be called as events right so
let this a 1
a 2 am they are our events
and suppose the experiment is repeated
for example we assume that suppose the
experiment is repeated
small and number of times what does this
mean for example when you are trying to
roll a die then there are possibilities
that you may get one
two three four five or six so these are
your here
6 events a1 a2 a3 a4
a5 and a6 now you try to repeat this
experiment
say suppose i roll a die say 100 times
so in this case your m is going to be 6
and n is going to be hundred so this is
what i mean
when i say that the experiment is
repeated small
number of times now once you have
repeated the
experiment you can count that how many
times
each of the possible outcome has
occurred
right and in case if you try to
think in terms of the tools of
descriptive statistics
then we are essentially trying to find
out the absolute and
relative frequencies of this experiment
or the outcomes of this events
so we simply try to calculate the
absolute frequencies
right means absolute frequencies mean
suppose if you try to
toss a coin say five times you get here
head head
tail head and here tail so now the
number of times
head is occurring this is here three so
this is the absolute frequency of the
occurrence of head and the number of
times
the tail is occurring this is here two
so the absolute frequency of occurrence
of tail here is two
so this is what we mean by absolute
frequency
so this is v i am trying to denote here
is n i which is a function of here
a i so for example in this case i can
write down here
n 1 is equal to 3 and it is a function
of here
h and similarly in this case i can write
down here n 2 is equal to here 2
which is a function of here tail right
and so this n a i is going to indicate
the
number of times an event a i occurs
out of this a 1 a 2 am now from this
definition i can
also find the relative frequency for
example in this
example if i try to find out the
relative
frequency of occurring of head
so this is going to be number of times
the head is occurring divided by the
total number of times
the event has been repeated 5 times and
similarly
the relative frequency of tail is
going to be 2 upon 5 that is the number
of times the
event happens that is the two number of
times we are getting a tail
and divided by the total number of times
the experiment is repeated which is here
5.
so similarly i can make it more general
and i can define the relative frequency
which is denoted here as say f i you can
see here i am using here
2 here f what is here is in italics
f i and one here is here f which means
here function
[Music]
so this f i is a function of a i
and a i is a random event and we have
repeated
the whole experiment a small n number of
times
so in this case this relative frequency
of a a i
is computed as say n i upon small
n so ni is the number of times the event
occurs so ni is the
or i can say here this is simply your
here absolute frequency
and n is the total number of
repetitions
right so this is going to be denoted by
say f i
so now in case if an experiment is a
consisting
of the events a 1 a 2 a m so we can
compute here
something like here f 1 f 2 up to here
f m right so this is how we try to
compute the absolute and relative
frequencies
now in case if you assume
that the experiment is repeated for a
large number of times
and if you okay the same thing in terms
of
mathematical language we say that the
experiment is repeated infinite number
of times or we say that as
n goes to infinity
and the second condition is this this
experiment is being repeated
under the same conditions that means the
experimental
conditions remains the same
right at least approximately i would say
whenever we are trying to repeat the
experiment so this experimental
condition remain the same over
all the repetitions in that case
we say that the relative frequency
converges
to a limiting value for a so if i try to
take an
event here a then the relative frequency
of this event
will be converging to a value
a right what does this actually mean
that in case if you are trying to
repeat the experiment for a large number
of times you will be computing the
relative frequency for these times and
as you are trying to increase the number
of times of repetition
the relative frequency will stabilize
at some point so this limiting value is
interpreted as the probability of a
and it is denoted by p a p a means
p means probability
and a is an event so this is the
probability of an event a
so this will be something like here
limit n tending to infinity
and a upon n where n
a is indicating the number of times an
event a
occurs out of a small number of times
so now you can see this is the
probability
what we always say whenever we say that
some event has a probability
this that means if you try to repeat the
experiment for a large number of times
and if you try to compute this relative
frequency
then in case if you increase the number
of repetition
then this relative frequency will be
converging to this particular
value and if you try to see this
part which i am writing here is say n a
upon n
this is the same thing where you have
studied
that the probability is indicated by m
upon n that if then
experiment is repeated small n number of
times then
small m is the number of favorable
events that is the same definition but
now you can see
that what does this mean when you are
trying to
say using the definition of the m upon n
and if you try to say that the
probability of head is equal to one by
two
or the probability of tail is equal to
one by two what does this mean
that in case if you keep on continuing
the
crossing of the experiment for a large
number of time
then the value of the probability which
is computed as the total number
of heads divided by total number of
times the experiment is repeated
this value will be converging to 1 by 2
as n goes to infinity this is what you
mean
right so now this i try to first explain
you the same example by
considering some numerical values and
then i will try to show you using the r
software that if you try to conduct such
experiment or if you try to
actually simulate such an experiment
then you can see how the probability is
converging to value
one by two right so suppose if i say
suppose of sphere coin is toss
and equal to ten times when i am trying
to say here
fair coin means that the coin is really
fair in the sense that
there is no impurity in the structure of
the coin so that a particular
side head or tail comes more frequently
right
so now in case if you try to repeat this
experiment 10 times
then suppose we observe the number of
heads
which is here event a1 so the number of
times
the event even occurs is supposed three
times
and then obviously the number of times
the tail will occur
that is n of a2 which is the absolute
frequency
that will become here seven that means
if you try to
toss a coin ten times then out of this
three times you get head and seven times
you get tail
right and yeah as i said the meaning of
the fair coin is that the probabilities
of head and tail
are the same that is zero point five or
say one by two
now in this case if you try to compute
the relative frequencies of the events
a1 and a2
they will come out to be like this f of
a1 will become here
the number of times you are getting hit
divided by the total number of times
the experiment is repeated that is 10.
so this will become here 3 upon 10 which
is equal to 0.3
and similarly the
relative frequency of a2 that is
observing the tail will become here 7
upon 10
which is here 0.7 so you can see here
this is 0.3 and 0.7 but you always
assume
or you have been told that the
probability of getting a head or a tail
is simply 0.5
but now we have understood what is the
meaning of this
the meaning of this is this that when
the coin is tossed for a large number of
time and
goes to infinity then both f of a1
and f of a2 will converge to a value and
this value
or the limiting value is going to be 0.5
and this is the probability of getting a
head or a tail
when we are trying to cross a
fair coin this is what we mean right now
suppose we want to compute this
probability so definitely we are working
here only with here two symbols here
head and tail
so with the head and tail we cannot make
any computation so
let us try to give them a mathematical
representation suppose whenever the head
occurs
i can indicate it by zero and suppose if
the tail is occurring i can denote it by
here one suppose if i try to
repeat the even say five times and
suppose i get here h s t
s t so this thing can be represented by
head is occurring that means zero
zero tail is occurring that means one
then head is occurring zero and tail is
occurring
one so sequence like zero zero
one zero one will indicate that in the
first
toss you get head second toss you get
head third toss you get tail
four toss you get zero that is head and
fifth toss
you get one that means tail right so
this is what i have written here exactly
that if you get here head head tail head
tail this is expressible as zero zero
one zero one
now in case if you try to count the
relative frequency of your head or tail
then for example if you want to compute
the relative frequency of tail
which is actually the probability of
tail that can be counted as number of
ones
which is here one and one two times
which is here two
divided by the total number of
repetitions which are here
5 right now
in case if you try to repeat this
experiment for a
large number of times you will see that
this value
2 upon 5 will be practically converging
to 1 by
2 as n goes to infinity
now i would like to show you here and in
order to
show it i will try to use the
r software and in the beginning when i
introduce you the basic concepts of
our software that we are going to use in
the course i
i had explained you the command here
sample
i had introduced you the topic of simple
random sampling in which you
i explain you that if you want to draw a
sample by simple random
sampling then i can use the command here
the sample and you see
when you are trying to repeat an
experiment you always said this is a
random experiment so you know
that whatever be the outcome that is not
going to be known unless and until the
experiment is conducted right
so when we are trying to conduct this
experiment by
indicating the head and tail by 0 and 1
then we can draw different number of
zeros and ones from the
r software using the sample command
right and if you try to
see here in this case itself if you try
to
see here what are we trying to do i am
simply trying to find out the
sample mean of
of this 0 0 1 0 1.
if you try to see the mean is going to
be simply here
0 plus 0 plus 1 plus 0 plus 1 upon here
5. so this is 2 upon 5. so that is
another way by which you can think that
if you simply trying to compute the
arithmetic mean of the random number
drawn
then possibly this will give you the
relative frequency but anyway
let us try to use it suppose i try to
first show you the outcome that
that experiment i already had conducted
and i have prepared here the slides and
after that i will show you the same
thing in the r
console also so in case if i try to take
two numbers here 0 and
1 and suppose i want to draw here or i
want to repeat this experiment of
drawing head and tail or equality 0 and
1
say 10 times and for that i can use here
simple random sampling with replacement
that is
replace equal to true so this command
that sample c 0 1 size equal to 10
replace equal to t
will draw a sample of size 10 and stores
the value in the data vector
say here coin 10 and in case if you opt
another approach that you can always
find out the
relative frequency of this outcome
so that can be obtained by the command
table
the name of the variable divided by the
length of the variable so my variable
here is coin 10
so this will give us the relative
frequencies of this
10 values which we are trying to observe
so this way you can
you can opt any of the approach to find
out the arithmetic mean or the relative
frequency so we try to repeat
this experiment say 10 times 100 times
1000 times 10 000 times and so on and we
try to see the outcome
you see when i am trying to repeat this
experiment 10 times
then there are going to be 0 1 0 1 say
10 times and the relative frequency of
those zeros and ones comes out to be
here 0.7 and 0.3
and if i try to repeat this experiment
once again
then in the second repetition i am
getting here the
relative frequency is 0.3 and 0.7 so
what is happening that in the first draw
the heads are coming out to be 7 and the
number of kills
they are coming out to be three but in
but when i try to repeat it
this is just getting interchained that
we get here three heads and
seven tails but here if you try to see
we have repeated the experiment only
ten number of times now i try to repeat
it and i try to conduct the experiment
hundred times that we get the hundred
values of
heads and tails right so in this case
you can see here
that we use the same command here that
table coin hundred divided by
length coin 100 but in this case the
number of heads are coming out to be
55 and number of tails are coming out to
be here
45 right so you can see here this
probability which was earlier
something like 0.7.3 that is now
converging to 0.55 and
0.45 and if i try to repeat the same
experiment here once again
i am getting here the value 0.45 and
0.55
well means i can show you that here it
is only by chance that these two
outcomes and these two outcomes are
getting interchanged but that is just by
chance actually i have not done it and i
will show you the screenshot also
right but you can see here as we are
trying to increase the number of
times the experiment is being conducted
the value of relative frequency is
converging towards 0.5
and now in case if you try to repeat
this experiment say
1000 time so here i'm trying to get here
1000
values of head and tails in terms of
zeros and ones and if i try to compute
the relative frequency this is coming
out to be
0.519 and 0.481 and similarly if i try
to repeat this
this is again coming out to be 0.516 and
0.484 but now you can see that as you
are trying to increase the number
of times of repetition of the experiment
these values are converging towards
point five
right and this is here the screenshot of
the same outcome which i have shown you
but now i will try to show you these
things on the r
console also right so let us try to come
to the r console
and we try to do the same thing over
here right
so let me try to just copy this command
on the r console over here
and i try to execute it so that we save
some
time also and you can see here that if
you try to do it
that it is coming out to be 0.4 and 0.6
that means if you do you are getting 4
heads and 6 tails
and if you try to repeat this experiment
you can
see here that this time it is coming out
to be 0.7 and 0.3
but now let me try to increase the
number of observations to suppose here
100
and let me try to put it here say coin
hundred so you can actually
see here this is how you will get the
values here 0 1 0 1 and so on but if i
try to compute here this
relative frequency of this coin 100 data
vector
you can see here that it is coming out
to be 0.53 and 0.047
which is closer to 0.5 compared to 0.7
and 0.3
and if you try to repeat this experiment
value will change
and it is coming out to be 0.5 and 0.5
in the case of hundred but this is only
a matter of
constantly that it is exactly coming out
to be 0.5 and 0.5
but now in case if i try to make it here
the sample size to be
1000 that means we are trying to draw
1000 values of heads and tail that means
we are repeating it 1000 time
then this relative frequency will come
out to be here
like this of the relative frequency of
coin 1000
data vector and you can see here this is
coming out to be
closer to 0.485 and 0.515 and if you try
to repeat this experiment
then you will see here that this
probability is approaching towards
0.5 right so now if you try to repeat
this experiment
for say ten thousand time one million
times you will see that their relative
frequency is approaching towards zero
point five
and this is what i mean when we say that
the probability of getting a head or a
tail is
one by two so now we come to an end to
this lecture and i have
taken a very simple example to convince
you
that what is the definition what you
have done earlier and what is the
interpretation what is the correct
meaning of this thing
now i would say you try to take some
more example try to compute
the probability by hand manually and try
to execute it on the r software and try
to see what happens
the more you practice this will give you
a better insight
that how the probability is interpreted
and computed
so you try to practice it and i will see
you in the next lecture
with one more example till then good bye
[Music]
[Music]
[Music]
you
