 So in this video, we're going to show how to show that the negative binomial is a member of the natural exponential family of distributions. So we start with the form of the negative binomial, so it's y plus or minus 1 choose y times 1 minus p to the power of y times p to the power of r, where r is a known constant. y can take any value from 0 to infinity and p is a probability, so it's fixed as being between 0 and 1. To show some things in the natural exponential family of distributions, we want the form to be equal to the exponential of theta y minus b of theta over a of phi plus c of y and phi. So you want to be able to write this in terms similar to that. So as with all of our previous videos, we start with taking logs and then exponentiation. I'm going to do that in one step here. So we have p of y is exactly equal to y is equal to the exponential. Sensibly rearranging so that my term that is dependent on y but not a function of y is first. So y times 1 minus p log of 1 minus p. Don't forget to take your natural logs in here. y plus or times log of p plus log of y minus or or y plus or minus 1 choose y. You can see you don't want to have to deal with this. So let theta equal log of 1 minus p that take care of this bit. We say e to the theta is 1 minus p. p is equal to 1 minus e to the theta. So log of p is equal to log of 1 minus e to the theta. So we can then write p of y is equal to y is equal to the exponential of theta y. That's that bit. We have to do minus because we want it in terms of minus. So minus minus r times log of 1 minus e to the theta. That's my b of theta term plus log y plus 1 minus r choose y. And remember r is a known constant. So that's actually sufficient to show that it's a member of the natural exponential family. Note with b of theta is equal to minus or log of 1 minus e to the theta. a of phi equal to phi equal to 1. c of y and phi equals log of y plus or minus 1 choose y. Given that we've shown it in the natural exponential family of distributions, it's obvious that we would then wish to find the expected value in the variance. So the expected value of y is the first differential with respect to theta of b of theta, which is d d theta of minus or log of 1 minus e to the theta. So it's equal to minus or times. And then we differentiate that which we get a minus e to the theta numerator and 1 minus e to the theta on the denominator, which when we do that, it's or e to the theta 1 minus e to the theta, which then corresponds to or times 1 minus p over p. The variance of y is a of phi and the second differential with respect to theta of b of theta. So in this case, it's the differential with respect to theta of or e to the theta over 1 minus e to the theta. The basic application of the quotient rule here will give you equal to or e to the theta over 1 minus e to the theta to be squared, which is or 1 minus p p squared, which matches with what you're expecting. Remains to show then the canonical link. So the canonical link is the function that takes g of the expected value of y, the function g that takes the expected value to theta. This is much, much simpler if you give the expected value. So we let gamma equal the expected value of y, which is equal to e to the theta over 1 minus e to the theta. Let's say it's equal to or times that. So the first thing we want to do is to have this in terms of 1 theta and only 1 theta. And we do that by a nice little trick. So we multiply above and below the line by e to the minus theta. So this becomes e to the theta times e to the minus theta times 1. This becomes e to the minus theta and we get a minus 1 here. Doing this makes life a whole lot easier when you're dealing with these. So you want to have only 1 theta here. That's your big trick with showing your canonical links. So the first thing you would want to do is invert this. So you get gamma inverse is equal to e to the minus theta minus 1 over or. We multiply it by or to get rid of this term on the bottom. So we say or gamma inverse is equal to e to the minus theta minus 1. Our next stage is, well, we need to get rid of this minus 1. So we have or gamma inverse plus 1 is equal to e to the minus theta. We take the natural log. So we would say the log of or gamma to the minus 1 plus 1 is equal to minus theta. And then we negate that side. So negate that side. So it becomes log of 1 over or gamma to the minus 1 plus 1 is equal to theta. So that's your function given that gamma is your expected value. We can do some minor simplification of this. We would say so we've gone log of 1 divided by or over e of y plus 1 is equal to theta. So now let's put this denominator on the bottom term. We let or e of y plus 1 is equal to or plus the expected value of y divided by the expected value of y. So theta is equal to log and we would flip this over the expected value of y divided by or plus the expected value of y. And that gives you the function that takes the expected value of y to theta which is required for the canonical link.