Learn fundamental concepts in data analysis and statistical inference, focusing on one and two independent samples.

Loading...

From the course by Johns Hopkins University

Mathematical Biostatistics Boot Camp 2

41 ratings

Learn fundamental concepts in data analysis and statistical inference, focusing on one and two independent samples.

From the lesson

Discrete Data Settings

In this module, we'll discuss testing in discrete data settings. This includes the famous Fisher's exact test, as well as the many forms of tests for contingency table data. You'll learn the famous observed minus expected squared over the expected formula, that is broadly applicable.

- Brian Caffo, PhDProfessor, Biostatistics

Bloomberg School of Public Health

Ok, so let's discuss it a little bit.

Â so in this case we have more tumours under the treated than the controls, so

Â we at least have an indication, but we'd

Â like some sort of inference associated with that.

Â So let's see if we can get a p value.

Â So but we're going to want to calculate an exact p value.

Â And our exact p value is going to use this conditional distribution.

Â the, the conditional distribution fixes both the row and the column

Â totals and we talked about when Fisher originally devloped this test.

Â He developed it wanting to fix the margins because he had

Â assumed that the lady, who was guessing would would have known.

Â That he would have randomized equal numbers to to t first

Â and milk first so he assumed that she would have fixed

Â those margins as well. So that went into why he thought that way.

Â and you know we talked about how this yields the

Â same test regardless of whether the rows or the columns are.

Â And that the hyper-geometric distribution, which

Â we derived as a conditional distribution, is

Â identical to the permutation distribution that we

Â discussed, randomly permuting treatment and control labels.

Â if we were to string the data out as the

Â full data set, not just as the two by two table.

Â And so, let's actually, and, and, and so all, kind of versions

Â of, all one-sided versions of Fisher's exact test yield the same inference.

Â For two-sided the, the way in which, this, you know, so

Â we have the null distribution but we need the test statistic.

Â And it turns out that, you know, all test statistics.

Â Are not equal in two sided tests but I'm going to give you the easiest one but

Â it doesn't exactly much, say for example, what r does or exactly what was

Â in Fisher's original version so I just want you to be aware of that.

Â OK, so let's consider our example from before where now we're testing that.

Â the tumour probability for the treated mice is

Â higher than the tumor probability for the control mice.

Â So, so this would, the p value would just require tables

Â as or more extreme under the alternative than the one observed.

Â Well and recall we're fixing the margin totals and the observed table was 4213.

Â A more

Â extreme table would be if not just four mice

Â got tumours from the treated group but if five did.

Â Right?

Â So if we plug in five then we know this cell has to be zero, this

Â cell to be one and this cell has to be four because we're fixing the margins.

Â And we can't find another more extreme table, because it we were to, say, put a

Â 6 in there, then that would have to

Â be negative 1 instead of 0, which can't happen.

Â So, so there's only one table that's more extreme that honors the margin.

Â Okay, so plugging into the hypergeometric distribution we get 0.238 for the

Â observed table. And 0.024 for the for the other table.

Â And so the p value, the probability. The conditional probability of obtaining

Â a table as or more extreme in favour of the alternative then was observed is 0.238

Â plus 0.024 which works out to be 0.262.

Â So as you can see and you probably guessed is in this data set.

Â The only way we could have gotten a

Â 5% significant test, is with the most extreme table.

Â And that's, you know, part of the consequence of you know, exact testing.

Â Of, of, of you know, these tests, and

Â it can be shown that these tests will guarantee

Â the error rate. That, but only guarantee

Â that the err rate is at most 5%, so let's say you compare this p value to 5%.

Â it does not guarantee that the err rate is exactly 5%.

Â You can't do that because the data's discreet

Â and there's only so many probabilities available to.

Â To the p value.

Â there was an effort at one point to

Â introduce supplemental randomization, to try and get truly exact

Â p values that not only honoured the 5%

Â level, but gave you exactly a 5% error rate.

Â But no one is willing, very few people are willing to accept that is a solution.

Â where things not in your data yield the, the info,

Â have important consequences to the inference.

Â So I think what you wind up having to do is, if you

Â want, if you demand, your analysis de, demands an exact small sample task.

Â Then you just have to deal with the fact that

Â these Small sample tests tend to be a little bit conservative.

Â I would say there is also another, there's

Â another strategy that comes up too, that's pretty good.

Â What some people will do is they'll calculate the so called mid p-value.

Â So,

Â they'll only attach half weight to the observed table.

Â and that p-value is somewhere in between, of course, the observed table and the,

Â the, the strictly conservative p value, and other strategies.

Â but of course it's not, it's no longer exact.

Â So, I figure if you want an exact test, do an exact test

Â and, in this data test for example, the only way you could reject.

Â Is if you got the most extreme table.

Â Okay, so let me just show you briefly how to do

Â this in our matrix c, 4, 1, 2, 3 comma 2.

Â We'll just create the matrix, type it in, and you'll see.

Â Type.

Â fisher.test, and you just do fisher.test on the little two by two matrix, in this

Â case we say alternative is greater.

Â Let's see we get 0.2619 which is what we calculated when we did it directly.

Â And it gives you all the information.

Â It gives you an odds ratio estimate and a, confidence interval.

Â Which, in a, in a subsequent lecture, we'll show you

Â exactly how to calculate, how they calculate this confidence interval.

Â Or at least we'll give you the intuition behind it.

Â It uses the so-called non-central hyper-geometric distribution.

Â okay. So that's pretty easy to do.

Â Okay, so the two sided p value is a little bit hard.

Â there's other ways to do it and r uses another way and well

Â I'll describe it, but right now I'm saying for the easy thing is calculate.

Â Double the, the one sided p value.

Â The smaller of the two one sided p values.

Â You have to double, you know?

Â [INAUDIBLE]

Â makes.

Â I mean, it's easier to remember which p value, which

Â of the two one sided p values you double, you know?

Â Because if you double the larger of the two one sided p

Â values, you wind up with a, a p value bigger than one, usually.

Â Or always, I think.

Â And, So, so you, you know you've done something wrong.

Â So, to two side a p value, you double the smaller of the one sided p values.

Â That mirrors exactly what we do in normal

Â tests, and t tests, and that sort of thing.

Â So what Fisher did initially was he, so, the other

Â strategy for creating a two sided test is you need a two sided test statistic.

Â A test statistic that measures.

Â Whether you're, whether a table is as or more extreme than the observed table.

Â So one example would you could, you could do the chi squared statistics.

Â So you could calculate the chi squared statistic.

Â Of your observed data.

Â And then calculate the, the, hyper jet geometric probability

Â for every two by two table satisfying the margins.

Â And then calculate, add up the probabilities associated

Â with those tables with the chi squared statistic.

Â Bigger I more favour of the alternative in the observed table that's

Â one example.

Â and that's fine that you could do that, right so you could

Â given the information I'd given you you should be able to do that.

Â Am, you should be able to do it with any statistic.

Â that any statistic that measures the direction of the alternative.

Â Of course.

Â So you might say, well, how do, how do you pick

Â a statistic in this case, since you can do any one, right.

Â Because you can calculate the associated hyper-geometric

Â probabilities for every table, you can calculate the associated statistics.

Â Then summing up the probabilities for those tables with statistics more

Â extreme than the observed in favour of the alternative is easy.

Â But what's conceptually hard is them paying this statistic.

Â The problem being that there is

Â no uniformly optimal statistic in this setting.

Â There is no so called uniformly most powerful statistic.

Â So there's a trade off

Â of power for when you do statistics and

Â for which statistic you choose and its property.

Â which is too bad but it is what it is.

Â There's no solution you can work out for a given data set, what constitutes

Â you, you can, you can work out basically every statistic for a given data set.

Â And convince yourself that there is no uniform and most powerful solution.

Â There's merely tradeoffs.

Â I should talk a little bit about what Fisher did in this case.

Â So Fisher's statistic was really interesting.

Â Fisher's statistic was the hyper-geometric probabilities

Â themselves, okay, so when he did the test, he would calculate the probability,

Â the hyper-geometric probability.

Â were both the statistics and the probabilities.

Â So he would add up, you know, he would calculate all

Â tables that satisfied the margins,

Â and calculate every hyper geometric probability.

Â And every table that had a hyper geometric probability smaller.

Â Then the observed hyper-geometric probability, he added all those

Â up plus, plus the hyper-geometric probability of the observed table.

Â And that was his p value.

Â So what he's doing then is he's

Â using the hyper-geometric probability as the test statistic.

Â because as we just talked about you could use anything as

Â a test statistic, any function of the table is a test statistic.

Â And certainly the hyper-geometric. Probabilities are a function of the table.

Â His logic went something like this.

Â if something came, arose out of not the

Â null distribution, but out of the alternative distribution.

Â Then those tables.

Â Would be, would have a low probability

Â under the null distribution, so he used that

Â logic to say well okay the probability under

Â the null distribution, is a reasonable test statistic.

Â And that was his logic. Fisher was, Fisher was a smart guy.

Â Okay, so p values

Â are, are, are usually large for small n is the second point.

Â what do I mean by that? I wrote that.

Â Oh, so, yeah, that's a poor way to put it, but, but what I, what I

Â mean is the discreteness of the problem usually

Â dictates that you wind up with a large P-value.

Â For example, here we have the second most extreme

Â table we could possibly obtain, and our p-value is 26%.

Â That's a consequence of a, the discreteness, and b, demanding a

Â demanding a exact test. It is what it is.

Â so the Fisher's exact test doesn't distinguish between rows and the

Â columns, transpose the table, you get the same p value out.

Â the common p under the null hypothesis is called a nuisance parameter.

Â So the procedure that we're doing.

Â To get rid of it is, is called eliminating nuisance parameters.

Â And,

Â conditioning on the total number of successes eliminates

Â the nuisance parameters, and we're going to go through a

Â couple more examples of this throughout the class

Â of conditioning on a sum or something like that.

Â To get rid of a Nuisance Parameter, and

Â then Fisher's exact test guarantees the type 1

Â error rate but it doesn't guarantees its obtained

Â exactly only guarantees that its obtained as a bond.

Â And here is, there was another great fight that accord in Statistics, you might

Â not think that Statistics nerd fights are fine but I do.

Â And um,there was a extremely hard

Â fought series of papers between Fisher and several other people about this procedure.

Â And there was another procedure called an Exact Unconditional test

Â and this, inventor of this Binard who later I think

Â came around to Fisher's way of thinking about things.

Â Said, well why don't we calculate, say, for

Â example, the probability of getting a proportion in,

Â of the, of tumours in the treated, bigger

Â than the proportion of tumours in the control.

Â We can calculate that.

Â It does depend on this,on the null, we can calculate that

Â under the null hypothesis if we knew this common proportion, right?

Â Then it's just a bunch of binomials.

Â And, sure you know, maybe it's tedious but we could do it.

Â And he

Â says, okay, well you know, we have this

Â probability for any given p, that's our p value.

Â Why not, then, just take the worst case version of p, right,

Â the largest version of the p value, and call it a day?

Â Super, super simple to describe.

Â And that procedure, in some cases, has better power than Fisher's exact test.

Â [INAUDIBLE]

Â , you know? I think the maths step.

Â People find it conceptually maybe a little,

Â a little, I think, conceptually, people tend to like Fisher's exact test.

Â But I like the unconditional test, too.

Â It had a lot of logic to it, I think, in terms of

Â [INAUDIBLE]

Â . It's very simple right?

Â It's a lot easier to describe.

Â And yet conditioning's very hard. I would say, however, the the

Â randomization idea, and permutation idea of Fisher's exact test is very compelling.

Â And, you know, so, so, why don't we actually, at any rate,

Â [UNKNOWN]

Â test is interesting. You can read up about it.

Â You can read about how they.

Â They fought over for decades, very fun literature, if you go

Â back to the biggest names in statistics, from before the say 50s or 60s.

Â They all weighed in on this problem, and if you get far

Â enough into the world of statistics, it's an incredibly fun literature to read.

Â Okay, last slide. you know?

Â I want to just ex-, ex-, expand on this idea of how you can.

Â Especially because we can generalize this idea to, to not just 2 by 2 tables.

Â And in the observed table, x equals 4. And the observed treatment

Â was T,T,T,T, 5 ts and then 5 cs, and the observed tumours were

Â like that; you could do this little collection of 2 by 2 tables.

Â And say for example an r if you have the data coded in this

Â way you could do table and it would just give you the observed data.

Â Okay, so one thing you could do is, you could permute

Â the treatment labels and that is exactly the hyper geometric distribution.

Â So you could do a Monte Carlo version of calculating this

Â hyper geometric p value, of course we don't need to, but

Â I'm introducing it because later on in the class we'll do

Â it in cases where it's hard to calculate the p value.

Â Analogically and you could in this case you, we simulated a table we got

Â x equals 3 and we just do this over and over and over again.

Â And calculate the proportion of tables for which the simulated tables have an X

Â bigger than or equal to 4.

Â I have evidence as and more extreme in favour of the alternative

Â and this is just a Monte Carlo estimate for Fisher's exact p-value.

Â This is exactly.

Â a simulation process, to, to give us this

Â hyper-geometric probability that we could calculate by hand.

Â In the future, we're going to have harder problems where

Â we'll need to do Monte Carlo to do it.

Â Because there's no way to do it, by hand.

Â And that's the end of the,

Â today's lecture.

Â And, next time we'll, we'll keep working on contingency tables.

Â Coursera provides universal access to the worldâ€™s best education,
partnering with top universities and organizations to offer courses online.