1. Home
  2. Explore
  3. Statistics
  4. Introduction to Bayesian Inference

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Introduction to Bayesian Inference

Transcript

Welcome back. So this is lecture 16 in  this course on basian modeling. Um my   name is Himmansu and today in this  lecture we are going to talk about   uh basian inference. So this is an introductory  lecture to basian inference. So how exactly we   apply b theorem in practice for drawing inference  about the underlying generative process given   some data. Okay. So in the previous lecture uh  we talked about base theorem and we also saw a

quick abstract example of how base theorem  can be applied in statistical inference.   we will see it in more practical sense how  exactly we do it and we will uh discuss each   term in the in the base theorem. Okay. So  just to recap and the base theorem was this that if you have let's say mutually  exclusive and exhaustive events A1 A2   A3 A N right then probability of event  A1 given B can be given by probability

of B given A1 into probability of A1  divided by summation of this term. Okay,   summation of the numerator term across all  mutually exclusive and exhaustive events. Okay,   so across all AIS from I is equal to 1  to N. So this was base theorem, right?   Now in order to apply it in the context of a  statistical inference right so let us say in   an experiment you have observed some data uh maybe  let's call the data x so this is the observed data

in some experiment right now there is some true  generative process that has produced this data   right so this data must be coming from some true  generative process. But you cannot know what is   exactly this true generative process. Only thing  you can do is that you can infer the properties of   this true generative process. And how do we make  that inference? Well, we go through this route. We make some assumption that the observed data should  be coming from a probability density function or   mass function f of x theta. Right? So this x is  coming from f of x theta. Right? Now given the   data what we want to do we want to infer that  given the data what is the true value of theta. Okay. Once we know the true value  of theta we can extend it to know   what this true generative process might look like.   Okay. That is actually the first step  in inference that we want to estimate

true value of parameters of your probability  density function, probability mass function that   you assumed that you assumed had generated your  data. Right? So given this data, what is the true   value of theta that might have generated this  data? Right? And by extension then you can try   to infer the true generative process. Of course  there is second step in inference without that   inference is not complete that someone else can  make a competing assumption that this data comes

from g of x lambda. Right? Now given the data  you will also estimate true value of lambda. So   let's say the true value of theta is theta hat  and true value of lambda is lambda hat. Right?   So the true generative process you are saying  behind this data is either f of x theta hat   or g of x lambda hat. So either of these two is  the true generative process. Okay. Then you will   compare these two that which one is better  at explaining future data or unseen data.

Okay. So we will put these competing assumptions  to some test that which one of these assumption   is better at explaining some future data or some  unseen data and that would so let's say if this   one turns out to be better at explaining  some unseen or future data then we'll say   that this process is closer to true generative  process. Okay. So that is the whole workflow of   inference. Right? Now where does B and B theorem  comes into picture in all this? Right? It comes

into picture at this point. So the assumption  we have made about our data that our data comes   from f of x theta. So x is the observed data. It  comes from this underlying probability density   function. Right? Now you need to estimate true  value of theta that might have generated this   data. Okay. So this is where base theorem um comes  in. So point here is this that it is not necessary   that theta would have only a single point value.  Okay, theta could have its own distribution. Okay,

and that's a theoretically different position  we are taking here. So in frequentist inference,   you often assume theta is a point value.  But here theta is itself a random variable. So of course we still want to go towards that  point value. We still want to know exactly what   point value theta would have. But there will  always be some uncertaintity in estimating the   true value of theta. And that uncertaintity can be  captured if you assume theta is a random variable.

We do not want to throw away that uncertaintity  because every time when you have some data,   data is just a limited sample from the  population, right? Every time you have   some limited sample from the population, it  would tell you something about the theta,   but it may not tell you everything about theta. So  there will always be some uncertaintity about the   true value of theta and we do not want to throw  away that uncertaintity because that uncertaintity is used for us right. So for example you collected  some data x and x tells you that well theta could   be equal to 0.6. It seems to be most likely value.  But theta= to 0.5 is also a likely value. So the   data could also very well come from this. The  data could very well come from this as well.   Right? So it's very difficult to find a point  value given a limited sample from the population.   Right? This is always going to happen that the  same data can be generated by this as well as

this. Right? If we just estimate a point value,  let's say maximum likelihood estimate of theta,   that's a point value, right? If you just estimate  a point value of theta, then we are throwing away   this possibility that this data can be generated  by this as well. Right? We do not want to do that.   We do not want to throw away this information  that the same data can be generated by different values of theta. But some values of theta can be  more likely and some values of theta can be less   likely. How do we capture this? We can capture  this if we assume that theta is a random variable.   Theta does not have a point value but theta is  a random variable. That's a much more reasonable   assumption to make. So once we say theta is a  random variable, then we are not interested in   a point value of theta. Let's say some value like  theta kne or something. We are not interested in

point value of theta. What we are interested in  is the underlying true distribution of theta.   Okay. So rather than saving saying that you want  to estimate true value of theta, what you would   say now that you want to estimate true probability  distribution. This is a probability distribution.   You want to estimate true probability distribution  of theta. Okay. So rather than estimating a point

value, we are interested in a true distribution  of theta. So theta would have a true distribution   which would tell us that some values of theta  would be more likely and some values of theta   would be less likely. Okay. So assuming that this  data x was generated by this generative process f   of x theta what is the true distribution of  theta that would produce this observed data   x obs or this x right that is our goal that we  want to estimate this true distribution of theta

how do we estimate the true distribution of theta  that's where base theorem becomes very important   Now this true distribution of theta that you want  to estimate okay this is actually conditional on   the data that you observed right because you  already collected this data X right we want to   estimate what is the true distribution of theta  given that you have observed this data X if you   would observe some different data let's say Y  then the true distribution could look slightly

different right so we retrieving information from  this data to infer the true distribution of theta.   Right? So that's why what we are going to estimate  here because we are estimating it based on data.   Right? So we cannot obtain exactly what is this  true distribution of theta. What we are going to   obtain is a conditional distribution of theta  given the data. So basically we are obtaining what is the conditional probability distribution  of theta given the data has already occurred or we   have already observed this data x. So that's  why we are estimating probability density or   probability distribution of theta given the  data. Okay. So it's a conditional probability   density. Now this can be calculated using base  theorem. So base theorem would say that P of   theta given X would be P of X given theta  into prior probability of theta divided by

total probability of X which will be basically  if theta is a continuous random variable which   would be the case in most cases most examples. So  this thing would be P of X given theta. Remember   we sum this numerator term multiple times. across  all values of theta. So here we will integrate it   across all possible values of theta. Right? So  in the range of possible values of theta. This   is what we can use to estimate true distribution  of theta given this data. So it's a conditional

true distribution of theta given the data.  Okay. But let me explain what are the terms   here because you might be confused by this as  well. This looks like a true distribution but   that is not the case. So let us see what it is.  Right. This first term P of X given theta. Okay,   you can call it probability density of of  observing this data given a particular value of   theta. But what actually happens here is this that  this is not exactly uh so this this is exactly the

same term that is uh in your function, right? So  you assumed a probability density function for   theta. So in order to calculate probability  density of x given some particular value of   theta you will use this function f of x theta  right. So what you are calculating here is the   value of this function the probability density  function you're calculating probability density   of X given theta right but interestingly the  values that you're going to calculate here

are um will vary with respect to theta right  because you're going to calculate probability   densities for example when you calculate this  posterior distribution you will calculate the   distribution like this right so this would be a  distribution P of theta given X I'm talking about   this LHS term right so this is a distribution of  theta right so for different values of theta how   different values of theta are likely to generate  this data so it's a distribution so on x-axis you

have theta okay so how this particular probability  density varies for different values of theta.   Right? In order to calculate this, okay, you will  calculate these quantities both P of X theta and   P of theta for different values of theta, right?  So you will estimate this quantity for different   values of theta. Let's say theta_1. This will  be f ofx theta_1. You will also calculate it for

theta_2. That will be f of x theta_2. Right? and  so on. Okay, so you're calculating this quantity   for different values of theta. Okay, because  data is fixed, data is known. So data does   not vary. Okay, so data is or let's say X or the  value of the random variable is known and fixed.   Okay. So under that condition if you want to draw  a graph of P of X given theta with respect to   theta you can get a graph because X is fixed and  known. So theta is the only thing that varies. So

you can get a graph. What graph is this? What  is this then? So what quantity we are getting   exactly because it's a function of theta. This is  exactly the likelihood function. We discussed this   couple of lectures ago. So basically this is your  likelihood function. So the first term you see in   this base theorem formula here in the numerator.  It's the likelihood function P of X given theta. It's basically the likelihood function. It's it's  not necessarily proper probability distribution   because uh you're not getting any distribution  with respect to different values of X. X here   is data. So it is fixed you are getting different  probability densities corresponding to different   values of theta. So actually you are getting  likelihood of theta. So every time you are   computing this quantity you are calculating  likelihood that theta1 would generate this

observed data x. Likelihood that theta_2 would  generate this observed data x. Right? So this is   the likelihood function. Okay. So that's the first  term in the numerator on the RHS on the right hand   side. What is the second term P of theta? See P  of theta does not have any conditional component.   It's looks like it's just the probability  density of theta. It does not have any data term.   What it is called is prior probability  distribution or prior distribution of theta

before seeing any data or before seeing uh the  given data X. Okay, this is actually your belief,   your assumption or your prior information about  the true distribution of theta. So although you do   not know what is the true distribution of theta,  but before seeing any data, you can make a prior   assumption that well I think that this parameter  theta might be distributed like this. So let's

say most of the values would be between 0.6 and 1.  Okay. So you can make that assumption. Let's say   when it is a word recognition experiment, you can  say that most of the times the participant will   be accurate in in judging in recognizing words  against non-words. Right? So for that kind of   experiment you can say that theta the underlying  probability producing a correct response could   be somewhere between 0.6 and 1. Okay? That will  actually depend on the context. I just gave an example. But you can have some prior assumption,  prior belief or some prior information. Let's say   from previous studies on the same phenomena,  you can have some prior information that what   the true distribution of theta might look  like. So this is our assumption about the   distribution of theta about true values of theta.  Okay. So this is called prior distribution of   theta. You've already seen P of X given theta  which we are calling the likelihood function.

Okay, there is more common way of writing this  likelihood function which makes this much more   clear and straightforward that this is actually  a likelihood function not PDF which is this that   rather than writing it as px given theta  p stands for probability density you can   write it like this likelihood of theta given x  that's it you can write it like this so it's a   likelihood for any particular value of theta.  So how likely is a particular value of theta

to generate the data. So likelihood of theta  given x. This is just another way of writing   the same term. This is much more transparent. It  directly tells you that you are dealing with the   likelihood function here. Right? So this is the  likelihood function. The term in the denominator   which is you can say the total probability of  data or the marginal likelihood. Uh it's given by this. Basically you are integrating  the numerator term with respect to theta. So across all values of theta  this is called marginal likelihood.   Okay. This is actually coming  from law of total probability.

marginal likelihood would be just some numeric  value. So let's say it could be 18 or something.   Okay, it's a it's going to be a constant.  The function of the marginal likelihood is   to ensure that this term okay so in right hand  side you are multiplying this likelihood and   prior density. So this thing if you do it across  multiple values of theta and it becomes a proper   probability distribution. So that the output that  you will get out of this okay it becomes a proper

probability distribution because we want that our  posterior distribution is a proper probability   distribution. Okay so this marginal likelihood  which is just a constant. So we're dividing it   by a constant. It ensures that the area under the  curve is equal to one. Okay. And we discussed one   interpretation of this which is that it is giving  you in a way total likelihood of generating this   observed data X given all possible combinations  of your parameter values. Right? Now the final

the left hand side term is then P of theta given  X. So we are trying to estimate true distribution   of theta conditional on the data the observed  data. So given that we have already seen the   data what is the true distribution of theta. So  this is called posterior distribution of theta. Okay. So P of theta was prior distribution  of theta. So this is before seeing any data   and this is posterior distribution of  theta. Basically after seeing the data.

Okay. So actually it tells you what what  are the true values of theta given this   data and your prior assumptions. So what values  of theta might have generated the data and gives   you distribution which values of theta would be  more likely which values would be less likely.   Okay. So this is the posterior distribution.  Okay. So in short you can write that the the   base theorem can be written like this that  the posterior distribution of your parameter

let's say theta is likelihood of theta into prior  density of theta divided by marginal likelihood. Okay that's how the base theorem works.  Right? So our goal is to estimate the   posterior distribution of theta. So we want to  estimate posterior distribution of theta given   the data. Right? We want to estimate the true  distribution of theta given this data. Right? So   that is our goal. And how do we do this? We first  calculate likelihood function. So given the data,

you can calculate the likelihood function. Given  the data and the assumption the basically the PDF   you can calculate the likelihood function.  We have seen this in one previous example   in a previous lecture. Right? Then you  multiply likelihood function with the prior   distribution of theta and then you divide it by  the marginal likelihood which is a constant term. Okay. Even if you ignore this constant term, you  would get an approximate posterior distribution

of theta. It would be just unnormalized. The  area under the curve won't be equal to one,   but it would contain almost same information.  Okay, so this is how you can write   um the formula for or basically you can  calculate the posterior distribution of   parameter theta given the data x. Okay. So  in order to calculate this it requires us   to step by step inference process would  be like this that first make assumption

about the true generative process.  Okay. So you need to make two kind of   assumptions here. First is assumption  about the true generative process. Okay. So what is the generative process underlying  generative process that might have generated your   experimental data X right so we used to write it  like this okay let's say you assume that it is   uh X comes from a normal distribution then you  would like it like this X comes from normal mu

sigma okay so that's your assumption about the  true generative process right Um in practice   we will be calling it the likelihood assumption  because the purpose of this assumption is exactly   to calculate the likelihood function. We will see  in practice. So we will be calling it likelihood   assumption. So that's the first kind of assumption  you need to make. So what is the underlying   distribution of the outcome of your random  variable or outcome of your experiment? Second, you need to make prior assumption. So what is  the prior distribution of theta before seeing any   data right? So let's say you assumed X comes from  normal mu sigma right what are the parameters here   mu and sigma there are two parameters so you need  to make prior assumptions about both mu and sigma   let's say mu comes from p of mu you can assume  any distribution for this let's say you assumed

mu comes from normal 350 okay so that's the prior  assumption of mu what you are saying here is that   that the mean parameter mu lies somewhere  between 200 and 400. So that's your prior   assumption. You can also make some assumption  about sigma. Let's say it comes from truncated   normal distribution between 0 and 50. What we are  saying is that likely value of sigma is between 0   and 100. Okay. Uh it it cannot be negative. It  always has to be positive between 0 and 100.

Right. So the first thing you need to do is make  assumptions. That's a step one. Once you have made   assumptions, then you will of course collect data.  So second is basically get data or collect data. And let's say the observed data is y OBS. Okay.  So let's say this is the observed data. Then you   can go to step three because now we have data. So  now what you can do you can draw your likelihood   function or you can calculate likelihood for  different values of theta given the data. So

you can draw a likelihood function. So let's say  this is your likelihood function. Then you can   calculate your prior density of theta. Okay.  So you know prior densities of mu and sigma.   So you can calculate the prior density of theta  in this case mu and sigma. So you can write mu   sigma here. So prior density of mu and sigma. So  you can separately calculate it for let's say mu   and sigma. Okay. So once you have likelihood  and prior then you just need to multiply them

and you can approximate marginal likelihood or  calculate marginal likelihood using some method.   Then your posterior of let's say mu sigma given  the data is just that it is the likelihood of mu   sigma given the data prior density of mu prior  density of sigma divided by margin likelihood.   Even if you ignore this, you will get unnormalized  posterior distribution if you just multiply them   for each value of mu and sigma. Right? So that's  how you can calculate posterior distribution step

by step. In the next lecture, we will implement  all these steps in R so that we know in practice   how to calculate posterior distribution of  any parameter given our likelihood and prior   assumptions and the data. All right, thank  you so much. Um, so this is um, this was an   intro to basian inference and how to implement  it in practice. In the next lecture, we will   see model building uh, in the Bayian framework  step by step. All right, thank you very much.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent