Lecture 24 : Univariate Normal Distribution: Application in R Software

IIT Kanpur July 201
20 followers
Jun 5, 2024
[Music]
hello friend welcome to the course
multivariate procedure with r so you can
recall that in the last lecture we
considered the univariate normal
distribution and we had uh discussed
different types of properties
and one important aspect was that how
are you going to compute different types
of
probabilities the rule which I had
explained you in the last lecture to
compute different types of probabilities
in the normal distribution they are
going to be useful when we are trying to
uh consider different types of
application like as test of hypothesis
and other
things so now we have understood that uh
how one can
manipulate different types of
probabilities under the normal
distribution what do I mean by
manipulate manipulate doesn't mean we
are going to do anything wrong but for
example if I want to know the value of
the CDF at minus a then it is going to
be computed by 1 minus CDF at a so this
type of manipulations and different
types of rule uh we had understood and
you can uh derive them very easily if
you try to look at the curve and and
they can be brought uh and understood
very easily by understanding the rules
of integration so now in this lecture we
are going to show you the implementation
of uh this uh normal distribution in the
art
software implementation mean we would
like to see how we can generate the
random numbers how we can uh compute
different types of probabilities Etc in
the our software
so and for this thing you will not need
any special package this I'm telling you
because in the case of univariate you
don't need any special type of package
but when we were considering the
multivariate then you will need a
special package so let us begin our
lecture and try to understand it right
so you can see here that we had
discussed the normal probability density
function that uh random variable X is
set to follow normal distribution with
parameters mu and sigma square if its
probability density function is given by
this function which is 1 upon Sigma <
tk2 Pi exponential of -1 upon 2x - mu
upon Sigma s and we always write it in
this way that X follows normal mu Sigma
Square where mu is the mean and sigma
square is the
variance so obviously the sigma is going
to be the standard deviation
right okay so now in the r software
there are various
possibilities so we can compute the
density distribution function quantile
function as well as we can generate the
random generation for the normal
distribution and the two parameters the
mean and variance they are specified by
the parameters here me and mean that
means it is something like here you can
write down here mean is equal to Mu
whatever is the value of mu which you
want to
specify and you have to remember one
thing that this command does not use
variance but it uses the standard
deviation which is specified by the
command SD so you will write down here
SD equal to what would be the value for
example here the value of Sigma right so
many times you will see that in
different problems you are given the
variance so then you have to be careful
that you use the square root of various
there right right so now we will
consider here four possible commands for
example the First Command dorm dorm
gives the
density so X is here the data vector and
then you have to specify here the value
of mean and standard deviation similarly
there is another function here pomm so
pom gives us the distribution function
so you have to assign here a value Q
then mean standard deviation and there
is one option here lower tail is equal
to true well I will try to explain you
all this uh things are here for example
if you see here Q here is the vector of
quiles right and similarly if you want
to use here this term here Q so this qom
is going to give you here the uh cotile
function so here you have to specify
here the p mean standard deviation SD
and lower do tail is equal to true so
you can see here this P here is the
vector of
probabilities right and then we have
here another function here RN so RN
generates the random numbers from this
normal distribution so n is the number
of random numbers which you want to
generate and then mean is standard
division that you have to specify that
from which distribution you want to
generate the uh random numbers right so
you can see here any the number of
observation mean is the vector of means
SD is the standard deviation and lower
do till if this is true this is the
default actually then the probabilities
are computed like this probability X
less than equal to X which is something
like your cumulative function and in
case if you take lower dot tail is equal
to false then this probability of X
greater than x is computed you see in
this normal distribution this part this
part here is called as lower
tail and this part here is called as
upper
tail right so if you want to compute
here this probability this will be your
here something if this is here some zero
then if this will be your here
probability of minus Z then this will
become here probability of Zed so you
want to specify whether you want to
compute the probability on the left hand
side of the normal distribution or on on
the right hand side of the normal
distribution and in case if the values
of mean and variance are not as
specified then mu that is mean is
assumed to be zero and standard
deviation is assumed to be one that they
are the default
values all right so now let me try to
take here some very simple examples to
explain you that how you can compute
different types of probabilities and how
they are useful so suppose an apple
formal says the Apple in the boxes and
the weight of the boxes vary and we and
are assumed to be normally distributed
with mean 20 and variance four that
means mu is equal to 20 kg and the
variance is 4 kilg Square you know that
when the farmer is trying to pack the
apples in the boxes means the apples
have got different weights and you
cannot ensure that every box had exactly
they said 20 kilogram of apples sometime
there will be some variation maybe some
grams so this is reflected by the value
Sigma square and the farmer wants to
avoid customer being unsatisfied because
the boxes are those are too low in
weight customers will not be happy so
therefore the farmer wants to know the
probability that a box with a weight of
less than 18 kg is
sold that's a very genuine question
because the farmer is trying to uh fill
the the apples in the Box based on the
approximate weight and if the weight is
less than the far then the customers may
not feel happy and and so the farmer
wants to know its probability so if you
try to translate this problem in the
statistical term then I can say that
farmer wants to know the probability
that a box with a weight of less than 18
kg sold that means if I say that X is
the weight of the box or the Apple then
we want to compute the probability
probability that X less than 18 right so
this probability can be computed by the
command
pm and basically if you try to see when
you try to compute that probability X
less than 18 this is actually here f of
x at X = to 18 this is the value of the
CDF at X = to 18 right so then we try to
give here the command here pom Q is
equal to 18 then mean is equal to 20 and
then SD is equal to squ root of 4 which
is here the VAR variance and if you try
to execute it on the r console this will
come out to be 0.158
6553 so you can see here it is very easy
to compute such probability right and if
I want to show you hit it on the r
console so that you can be confident you
can see here it is like this I try to
copy and paste this command over here
and if I give it here in the r console
it will give you here the same value so
now means you can be confident that
these values are very easy to obtain
right and on the other hand if you want
to use here the option here lower dot
till is equal to True means you can put
it here and then what will happen the
same value will be obtained here right
because lower do tail equal to True is
the default right you can see here the
screenshot that both the values are
going to be the same now I try to modify
this question yeah I just want to show
you how to compute different types of
probabilities now suppose the farmer
wants to know the probability that a box
with a weight of more than 22 kg is sold
right so that means the farmer wants to
compute the probability that probability
X greater than 22 now this is the place
where you have to use the rules which I
explained you to compute different types
of probabilities it is just like when I
shown you that X probability X greater
than 22 is less than 1 minus the area
under the curve which is probability X
less than equal to
22 right if you try to see on the curve
this will be like this if somewhere it
is here
22 suppose here and you want to compute
here this probability right so this is
going to be the 1
minus this remaining probability which
is here written here like this this one
so and this quantity here is actually
F22 so if you try to see the trick the
trick is this I want to convert the
given probability in the form of this is
CDF although in case if you try to use
here the command lower do
till correctly then also then you don't
need to make this transformation so both
the approaches can be used and uh they
will give you the correct answer so now
if you want to compute this probability
that the first option is that you try to
use the uh function here 1 minus
P which is coming from here like this
1 minus pom and then you try to write
down here qal to 20 which is coming here
from this 22 and then you have to
specify the mean is equal to 20 and SD
is equal to root of 4 which is and do
tril is equal to true this is the
default even if you don't write there
will be no problem and you get here this
value or equivalently if you don't want
to make it something like 1 - F22 then
you can directly use this command to
compute this probability that X get than
22 is p Norm Q is equal to 22 mean 20 SD
uh squ root of 4 and after that you have
to use the command here lower do tail is
equal to false and if you try to use
this command you will get the same
values so now it depends on you
whichever way you feel convenient and
comfortable you can use it there is
absolutely no
issue right now I try to give about some
idea about a different command this is a
q Norm what this qor does it gives you
the cotile function and it calculates
the cotile which is defined by the
smallest value of x such that FX is
greater than or equal to P FX is the CDF
of X it is here like this at any point a
small X well you will see that when we
try to conduct the test of hypothesis
and and various other application this
type of probability is is required to be
computed right so suppose if you want to
know the value of the 90th quantile or
say 90% quantile suppose the the value
here is Q then it is described by
probability that X less than equal to Q
is should be greater than or equal to
0.9 so this can be obtained by the
command here Q Norm so you simply have
to write down here p is equal to 0.9
which is coming from
here and then you have to specify here
the mean equal to 20 and D is equal to
root of 4 right and if you try to
execute this command here you will see
here this is coming out to be 22. 5631
right and in case if you just use here
the command option here lower do T is
equal to true this is the default then
again both the values are going to be
the same and that you can see here in
the screenshot right so let me try to
show you these values on the r console
before I try to move forward right so in
this case if you want to see that uh how
I am Computing this quantity probability
that X greater than equal to 22 this is
here like this and if you want to use
here the other
command that uh not by subtracting from
one but by using the option lower dot
tail is equal to false then you can see
here both are giving you the same value
so this is about P Norm now similarly if
you try to use here this Q Norm New Q
Norm so you can see here that this is
here like this so this is the giving you
the value of the 90th conti and
similarly if you try to use here the
default part then it will be you here
the same value that lower do tail is
equal to True will give you again the
same value
here right so let me come back to our
slide now I would like to give you the
idea about this random number generation
you see whenever we are trying to
compute different types of simulation or
we want to experiment with something
where we want to have a data which is
originating from the normal distribution
so this R Norm function helps us in the
generation of the random numbers from
the normal distribution with a given
mean and a given variance it is very
helpful when we try to conduct different
types of simulation studies monteo
simulation
etc for the command to generate the
random number here is R Norm r n o RM
and inside the parenthesis we write here
the N which is the number of random
numbers to be generated then the value
of the mean and then the value of
standard deviation right for example if
you want to generate four random numbers
from a normal distribution whose mean is
20 and variance is
four so this can be obtained by the
command here R Norm n is equal to 4 mean
is equal to 20 and SD is equal to squ <
TK of 4 so it will give you here this
four values 1 2 3 and here four so these
values have been generated from the
normal distribution whose mean is 20 and
variance is four the mean is 20 that is
why you can see here most of the values
are concentrated around 20 right and
this is the screenshot but when I try to
execute this command in the r console
now then these values will not be
obtained because these are random
numbers every time you try to generate
the set of random numbers they will be
different unless and until you uh use a
command like uh set seed right so that
is why I wanted to handle it separately
and that is why I had shown you the
earlier commands now I will try try to
show you here these commands on the r
console so if you try to see here let me
clear the screen and you can see here
our nor will give you here these four
values and in case if you try to repeat
it you can see here that that this is
going to give you different values and
in case if you try to change here the
number of observations you can see here
now you're getting here 10 values and
now if you try to suppose if I want to
show you that what is the effect of
variance suppose I try to make this
variance High suppose I make it here 100
now if you try to compare the four
values from this normal distribution you
can see that although the mean is here
20 but the values are varying a lot 15
17 30
14 right and uh in case if you want to
make this standard division to be very
high I have made it suppose uh 1,000
that means the the SD square root of
1,000 you can see here it is giving you
the value like 52 - 3.3 15 45 lots of
varation is there among the values now
if you try to make it very small suppose
I now make it here say square root of 1
you can see here the values are very
close to 20 so by conducting this type
of this experiment you can very easily
means identify and understand different
statistical properties of different
different probability density
functions right so now let me come to an
end to our uh this lecture and now you
can see here in this uh short lecture we
have understood that how are we going to
generate the random numbers and how we
can compute different types of
probabilities using the art
software be it the generation of random
numbers computation of the
CDF competition of the quantiles
anything that is possible well it
depends on the problem that what you
want to
solve that suppose if you want to
compute some probability the probability
can be computed as a difference of the
cdfs now how to adjust those cdfs and
how to take them for example in the last
lecture we had discussed that if x is
following normal mu Sigma Square so then
you can always make a transformation
like x - mu upon Sigma and then they
will be following a normal 01 that is
also possible otherwise in the r
software now if you want to do it you
don't need to do anything but you can
simply use the uh same mean mu and uh
Sigma directly over here you don't need
any transformation
also so this is how you can uh compute
various types of probabilities without
any problem and the problem of going
into the tables and and choosing the
value that is also also
solved but my request to you all is here
that now you try to take different types
of
examples try to create different uh say
portions in the curve of normal
distribution and try to compute various
areas they are simply your probabilities
for example if the areas on the left
hand side areas on the right hand side
areas in the center so how can you
compute different different types of
probabilities using the
CDF because we have understood that
probability that X lying between A and B
is the same as FB minus fa f is here the
CDF so now all those things you can
verify
here although I have explained you here
only about the normal
distribution but these types of uh
activities can be done for all type of
probability distributions and
probability Mass function
be it binomial be it potion be it
geometric be it uh uh say gamma
distribution but my objective in the
course was to introduce you with the
normal distribution because we are going
to use them in the forthcoming
lectures so my request to you is that
you please try to take up some problems
you can consult the books you can create
your own problems but try to practice
them on the art software so you try to
practice it and I see you in the next
lecture with by variate and multivariate
normal distribution till then
[Music]
[Music]
goodbye
[Music]
