okay so when last we met we had been working our way through inferential statistics and uh let me open up Excel because we're going to be using Excel today and we're going to do some examples so let's see we went through and we covered the basics of all of the things that are in the first section under inferential statistics so uh along the side there's a tab uh by the way all of these topics are growing and expanding uh so every week I put in some new different sections not all of them are relevant to this course I commented on that before but that's a reminder that uh there are things that are more than what we will cover but it's also the idea is that this is kind of a universal resource on these things that I'm trying to develop so we're going to go to inferential statistics the main Tab and uh then if you scroll all the way down to the bottom uh that is going to be where we're going to start to uh go into the second part which is guide to inferential statistics now the difference between the top one is that this is probably should rename it so the top one is uh an introductive guide so I called it comprehensive but it was supposed to be and this one correctly says introduction uh but when we get down to here this is where then as we each of the parts there's actually then a data set associated with the second component and that means that we then have the ability to actually compute some things which is what we want so we're going to do some computations today on the things that are in each of these sections so for starters the first thing that we have is that we have what we would reference as the formal steps of hypothesis testing now there is a separate tab over here that explains hypothesis testing and we're going to after we see one example we're going to bounce over to the hypothesis testing Tab and once we start talking about P values more we're going to bounce over to the P values tab where there's more information on each of those subjects but so we're at this part and we're going to go through what hypothesis testing is so hypothesis testing yes oh absolutely so if you go to uh along the side inferential statistics and we're on the one that's that's the top level tab which is inferential statistics and then we'll bounce around to the sub tabs then and I'll and if at any point you lose where the heck I am just let me know so yeah so we're on this one and you scroll scroll scroll scroll scroll scroll scroll and we're down to the uh second part there I think there might also be yeah there's also a bunch of different uh graphic demo things that we may get to uh but I don't know if we'll get to them today we'll see um okay so we're right here and there's four main portions to the idea of hypothesis testing so as we said hypothesis testing is the idea of making an argumentation just like what a lawyer would do and the formal process of H hypothesis testing for uh business analytics as well as then for in general the quantitative methods and quantitative fields are that the first thing that you do is that you state the null hypothesis and the alternative hypothesis now let's give a breakdown of what these two components are so this is more details than what I Pro provided before when I gave an overview of these conversations so the null hypothesis is the thing that you assume to be true so something being null means that it's another another term for something being null is vacuous it's the thing that is true without any additional information now in the American court system the null hypothesis is innocence that's the Assumption of our court system so that would be our the equivalent of a null hypothesis so if there is no evidence of the you know if there's no evidence of the person being guilty or at least not enough evidence of the person being guilty their presumed state is innocent well in statistics the version of that the thing that is like that is what we call the null hypothesis so our entire task is that we're attempting to get enough evidence to indicate that the null hypothesis does not happen that's what we're trying to do we're trying to have so much evidence that the null hypothesis doesn't happen that we're then able to say we believe that to be false now if you have that something which is the assumed uh the assumed claim is not true then you need an alternative and that's what we call the alternative hypothesis so for instance suppose that I said that the average height of individuals in this room was 510 suppose that I said that well and then suppose that I then started collecting evidence of recording the heights of individuals in this room and then I would then say okay well it looks like that's not true well then what's the alternative from the average being 510 was that the average is not not 510 which is the opposite of being 510 the next thing that you have to do is that you have to choose a significance level the significance level is what you can kind of think of like the accuracy of your testing how accurate are you going to be in your testing and in particular how confident do you want to be that you're going to get the right answer the third thing that you need is that you have to compute what's referred to as a test statistic the test statistic is the thing that you're going to use to attempt to reach a conclusion so for instance if I wanted to make a a statement about the average height of individuals at seatan Hill a test statistic could be that I could take the height of all of the the average height of all the individuals in this room and I could use that as a test statistic meaning that I'm going to test what the average height of individuals at seatan Hill is by using the people in this room as a test and then finally we compare the test statistic to what we call a critical value or we use what's referred to as a P value to decide whether to reject h0 okay so we're going to start by running through an example right here okay so we have a sample data set so we are going to bring up good old trusty Excel and we're going to write in those values as we see them in Excel and then eventually do some analysis on this so we're going to walk through the example of the procedure now I will tell you the thing about hypothesis testing is is that it's extremely patterned so the reality is is that most people don't actually understand what's going on but if you follow the pattern you will always get the correct answer now when I say most people don't actually understand what's going on that's not what our goal is our goal is to actually understand what it means but what I'm indicating for you is is that how you answer these questions is so repetitive and so patterned that if you learn the pattern you'll always get the right response so does that make sense what I mean by that so let's start to go through the first example of this that we'll see so we have apparently Apple weight and these are in GRS and what are the various Apple weights that we have 145 152 148 151 149 153 150 147 151 149 okay now let's go back read the question a little bit more detail and then we're going to then continue to proceed through the question so we want to test if the average weight of apples in a farm is 150 gram now the thing is is that presumably this Farm has a ton of apples so we we are not going to measure every single Apple at the farm that doesn't sound like a fun time we might measure the total weight of the of all of the apples because like if we put a ton of apples like a you know a couple hundred apples into a truck we can weigh the truck and we know exactly how heavy the truck is right and then if we then subtract the weight of the truck off of the weight of the truck with apples then we find just the weight of the apples so we could do that that's not what the question is we want to know what the average size of an individual apple is and the only way to do that would be to measure each individual apple and that doesn't sound like a fun thing to have to do all day long and so instead of actually measuring every Apple at the farm we collect 10 apples and we're going to see what's the average weight of these 10 apples and does that tell us anything about the average weight of the apples across the entire Farm okay so that means then we now come to Step One what is our hypothesis now we label them as two separate things h0 and ha it looks like it's ha like ha but it's not standing for like ha like haaha so the way that it's sometimes written as that it would be written as an H Subzero and an H sub a and what I mean is that it uses subscripts but we're just going to Simply write it as h0 and ha and that because it doesn't really matter what kind of script and font and stuff we use so h0 is what we refer to as the null hypothesis it's the thing that we are going to assume to be true so the thing that we're going to assume to be true is that the average weight of apples is 150 g well why why would we do that well because when we look at these values right here what value seems really close to all of them 150 150 would be a pretty good guess for maybe not necessarily that it's the average exactly of these but we kind of notice that the pattern is is that the weight of the apples from the farm seems like it's 150 so maybe the average weight of at the farm is 150 that's why we have that kind of reasonable conclusion okay and now we then have ha stands for the alternative hypothesis and as a reminder a hypothesis is just something that we claim is true well one of these and only one of these can be true in actuality agreed so it's either that the weight the actual average weight of the apples is 15 50 g or it's that it's not 150 g but one of those two must actually be true for this farm so now we move to the significance level so the significance level is something that we reach and the opposite percentage of it is the amount of confidence we have in the problem so if we have 5% significant ific an that means that we have what's referred to as 95% confidence because that's what's left so if for instance we had 3% significance we would have 97% confidence so the significance is you can think of as how much error you're allowed in the problem that's the way to think of it how much error are you allowed in the problem well for this problem we're going to do it with 5% significance level which is that we're ing like a 5% error 5% is not that much then we come to this part which is that we're going to measure the test statistic okay so to do this test statistic we're going to go to our Excel and we're going to type pest stat and then beside it we're going to type the formula as it appears right there that's the thing that we're supposed to type so now I could literally type it or I could realize that somebody has written this in such a way as to guide me through doing it now I will tell you I did do a little bit of a change here and the reason why I did a little bit of a change is because when I now click on this there is a bit of a problem with one part of it which is that it's not really A1 through A10 as the values that I'm interested in it's really A2 through a11 and you can see now it's correctly picking all the numbers and it's no longer selecting the word at well the words Apple weight in trying to do this calculation so I'm now going to click okay it didn't like that either so let me go copy and then I'm going to go command shift V it didn't like that either I don't know why it's not liking any of this okay so I'm just going to type it from scratch since it apparently doesn't like this has to do with pasting something so t do test A2 colon a11 Tails uh oh uh two and let's go ahead and go look hold on I don't know why it's yelling at this okay why oh okay I see what it did 150 okay hold [Music] up I typed the wrong stuff I made a typo in my notes that's fun did I make my typo over here as well let's find out no I didn't okay e yeah interesting okay so I have to change the notes on this uh so they used to call it a different thing in Excel you used to be able to shift it on that cool okay so here's what we're going to do so I'm going to put a pause on doing this one so that I can change all the notes so that I'm not telling you something different from the notes so instead we're going to move to this one and we're going to move to this one and I do believe I also have and if I scroll down yeah that's correct and that's correct and that's correct okay so we're going to temporarily we're going to temporarily skip over the test one that is up here which is under hypothesis testing one so do we understand what I'm going to do so I copied down the wrong formula so I want to make sure I change it in all of my notes before I have us go through that so my apologies but that's what happens when you do things late at night so a good lesson to everybody don't work on things late at night okay so let's instead go down to here and we're going to start with Ki squar and then we're going to work up so a Kai squared test is used to test relationships between categorical variables so if we're talking about Apple still which I was in an apple mood when I wrote this if we're talking about Apple still there's options on when you have red and green apples for whether they are sweet or not sweet as shown right here and when you then are considerate because we're still going to be talking about hypothesis testing it's just that I happened to copy for the first part the wrong formula so when we want to test whether there is a relationship between Apple color and the sweetness or nons sweetness then we can perform what's referred to as a Ki squar test now to perform Kai squ test you need a table of values such as this one so we're going to go to our Excel file and I'm going to create a new tab down here at the bottom if it will let me do that and I'm going to call this Kai Square and then I'm going to move this in and then I'm going to say red green sweet not sweet we're going to say 30 20 35 15 so all I did was is I just put into Excel that exact same stuff okay now similar to the other one we have to have uh we have to have it so where there is a null hypothesis and an alternative hypothesis now for these two things that we just were examining What's the total amount of values between these two things between between if I add up all the red apples how many red apples are there 50 but add up all the green apples how many apples are there okay if I add up all the not sweet apples how many are there if I add up all of the sweet apples how many are there 45 okay so so if I put a sum in for each of these things like so we get this and one thing that is sometimes helpful is is that to be able to help to distinguish things as you move through a problem it's sometimes good to provide some just like shading or something so that kind of blocks that off so it's easier to read the table so you just go to this little Paint Bucket like so and you add that there now here I'm going to add the word observed and that's because this is the stuff we actually saw happen now right here if we are examining these values we want to then say okay what would happen if there was no difference between for instance the red and green apples for sweetness if there was no difference between the red and green apples for sweetness then we would expect that there would be an even split between sweet and not sweet for the red apples correct does that sound about right so in other words if we go up to here and we say if this right here if there was no difference between if in other words if the the color of Apple had no determination on sweetness then it shouldn't be 3020 it should be what and what 2525 right that should be what actually occurs well how about for the green apples there's 50 green apples what should it be if there's if if sweetness has nothing to do with what type of apple you are then what should be the amount of sweet and what should be the amount of unsweet 2525 right it shouldn't be varying in that way and so that means then that we could come up with an expected table e that's what we would expect to happen right if truly it didn't matter in terms of you know color etc etc there's the same number of red apples as there are of green apples and so if it doesn't matter the color for sweetness then it should be a completely even split now that's not what happened okay so then we then say now we come to here so our hypothesis was and this is the null hypothesis that we're going to take there's no relationship between color and sweetness now what's the alternative the alternative hypothesis is there is a relationship between color and sweetness so we're now going to perform a Ki squar test now before I do let's just briefly comment that if we do some right here we get that if we do sum right here we get that but there's two quantities that are no longer the same no longer the same not the same as they were before okay so when we go through and do a Ki squar test there's two things that we have to input we have to input The observed range and we have to input the expected range now if I click right here there's two different versions of this if you start to type it that will come up so if you can read off what that is so there's this one and there's this one so why are there two things that look almost exactly the same in Excel well the reason is is that Excel is one of the oldest existing tools that has been rather consistently used in business so as a result there are things that have to do with what we refer to as Legacy issues so a legacy issue is where when you want to use older versions of a software it runs into a problem of where you can get two different answers for an older version versus a newer version because newer versions tend to update notations and things like that and so in a lot of instances Excel lives with the option of having you be able to use older versions of some of their formulas so for instance right here this is what's referred to as a compatibility function and what that is is that it will work with older versions of excel so for instance uh if I go up here this will only work with newer versions of excel this one that I'm starting to type out it will not work with older versions and if I click on the function I was doing this before by the way but I didn't tell you what I was doing if you click on the function what it does is is that it brings up a little bit of text that walks you through how to interpret the results okay and what you then are able to put in is that you're able to put in what we would refer to as a range of values or really it's that we would put in an array of values so if I close out that little helper I'm going to select my data values then I'm going to press comma then I'm going to select my data values and I'm going to press enter and I now have a value that value then is something that I test against what's referred to as the P value and if we get less than 0.05 which is the result of this test then we would reject the null hypothesis well the null hypothesis for us was that there was no if we go back up to what it was no relationship between color and sweetness well we are rejecting that there's no relationship between color and sweetness so then what is it then that we're left with if it's the opposite of no relationship between color and sweetness then that means that there's what we could say that there's a correlation between sweetness and color or we would just simply say sweetness and color must be related cool okay so let's now go to Let's click on the tab because we just used the phrase P value let's click on this tab which will give us a much more written out version of an explanation on P values so when we perform hypothesis testing with which we just did so we by the by the way we are now able to say apparently hypothesis testing doesn't require hours and hours to do because we just did it that quickly so to do hypothesis testing we use statistics to make decisions about data there are three three con there are three key Concepts that help us in that there's what's referred to as the P value the alpha value and the beta value so the P value is the probability of getting a result as Extreme as The observed one so if everything were even between color and Sweetness in that example we would expect things to be very even but they weren't and so as a result then we would then say well how extreme are the things that we're looking at that are observed values in other words how odd are they and that's one of the things that we look for is that we look for the P value which tells us the likelihood of getting something that odd then we have the alpha value and the alpha value is the threshold for rejecting the null hypothesis and it's probability it is the probability of making what we refer to as a type one error a type one error is when we mistake a l reject the null hypothesis when in fact it was true now there are two principal mistakes that you can make when we're referencing the idea of hypothesis testing so let me write this in Excel just like in a court of law there are four options of what can happen so up here any statement you make is either true or false correct but that's different than concluding it's true and concluding it's false its actual truth value is different than what you're saying about it so for instance if someone is tried for theft can they be found guilty but they were actually innocent the answer is yes that can happen can somebody be tried tried and found guilty and they were actually guilty the answer is yes can somebody be tried found innocent and they were actually innocent the answer is yes and can somebody be tried found innocent and in fact they were actually guilty and the answer is yes okay so that means that there are two things that are completely okay those two things perfectly fine we'd be very happy if those happened in both a court of law as well as when we do statistics those two things are fine when things are actually true and we conclude that they're true perfect when things are actually false and we conclude that they're false that's okay that's great we like that but there are two things that seem pretty bad so there are two things that we would label as errors the one is where the statement is actually false and we concluded that it was true and the second is where the statement was actually true and we concluded that it was false okay now for us to be able to figure out which one we're going to label as a type one error and which one we're going to label as a type two error there's actually a way of coming up with a scenario okay so when we consider things in terms of a null hypothesis which is what we're claiming is true that's the same thing as in our court of law as a innocence statement and in our court of law we have innocent until proven guilty now in a court system there are two mistakes that can be made by the court the first is the person is Innocent but they're found guilty and the second is they're guilty but they're found innocent can we see how those are two mistakes now one of them is much worse than the other okay so we have the two options innocent and they're found guilty and G guilty and they're found innocent which one seems like the worst of the two discuss this is actually important to statistics that we identify this discuss so get to summarize I'm asking which one's worse to declare an innocent person guilty or to declare a guilty person innocent that's what it is okay so continue to discuss okay so which one sounds like the worst of those two things it's a tough one it's a real tough one but going to tell you there's a way of yes letting a guilty person go free okay now between those two you have to there's two ways you can look at it and this is why it provides a difficulty one is worse for society and the other is worse for the morality of the law and there's a difference between those okay which one is worse for society declaring the guilty person innocent because what do we know is probably going to happen if you let a guilty person out they're going to do it again okay that's what we know okay but the other one is much worse for the morality of the law which is to declare an innocent person guilty when that is done well we have these things that are called consequences and they're consequences of the law correct so one of the things that's illegal is to kidnap and unjustly detain a person correct now we know that that sometimes happens but it's unjust and it's against the law and so that means that when it court of law finds someone guilty and punishes them either financially unjustly or through detaining them and jailing them unjustly then the law has technically committed a crime but we never label it that way it should be labeled that way and that's much much worse because who's accountable then for having committed the crime not just one person a bunch of people and so that's why we would say the worst of those two actions is for an innocent person to be found guilty and understanding that helps us to know which one we're going to call a type one error type one error is where innocent is found guilty and for us that's the same thing as saying that the null hypothesis when in actuality true is found found to be false and that's what we call a type one error and then a type two error is when the null hypothesis is in actuality false but we found it to be true so next time we're going to continue from here see more examples we're going to go back to that test stuff because I'll fix the I'll fix it it was you know I'll make it the right formula and then we'll go back and'll do that so we had almost done it and I typed the wrong formula so my apologies have a good one an innocent per an innocent found guilty that's correct but we but