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

36 ratings

Johns Hopkins University

36 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

[SOUND]

Â Okay, so now let's switch gears and talk about goodness of fit testing.

Â Now, this is the one instance I'm going to talk about where the degrees

Â of freedom for the Chi-squared is not rows minus 1 times columns minus 1.

Â Okay.

Â So imagine if you wanted to test R's uniform random number generators.

Â So remember, a uniform is a number that's continuous number that's between zero and

Â one, that's in essense, kind of each, every value is equally likely.

Â What that means on the continuum scale is that the density is

Â a brick that starts at zero, ends at one, is hype one.

Â So, R simulates uniform numbers.

Â And why don't we you know, test it

Â out to see, using the Chi-squared distribution to see

Â whether or not we're getting kind of what we would expect.

Â So, I simulated 1,000 random uniforms.

Â And how many uniforms would I expect to see between zero and 0.25?

Â Between 0.25 and 0.5.

Â Between 0.5 and 0.75 and 0.75 and 1. Well, because it's uniform, it says that

Â about 25% of them should be from there. eh, eh, because it's uniform,

Â it says that 25% should be between 0.25 and 0.5 and so on.

Â Okay.

Â So what we could do is simulate these thousand, we have 254, 235, 267, 244, and

Â we could calculate the the you know, how many we would expect to see under the The

Â true probability density function that, or the assumed probability density function.

Â So here, our null hypothesis is that this

Â first probability is exactly 0.25, the second probability

Â is exactly 0.25, the third probability is exactly

Â 0.25, and the fourth probability is exact, exactly

Â 0.25.

Â And the alternative is that any one of

Â these probabilities is different from its hypothesized value.

Â Okay?

Â And so that is, that would be our tests, and that would be a

Â [UNKNOWN],

Â comparing the observe counts, the expected counts.

Â In this case would be a, you know, not unreasonable

Â way to check R's random number gen, random number generator.

Â Okay, so we observed 254

Â [SOUND]

Â from the overserve, from the in reality when we

Â simulated it the expected would be a 1,000 times 0.25.

Â Which is 250, and you can carry through the calculations.

Â They're all 250 in this case, of course.

Â And so are observe minus expected squared over

Â expected sum works out to be about 2.3.

Â This is 3 degrees of freedom.

Â The P value is 0.52.

Â And it shouldn't surprise you that we get a large P value

Â in this case because we're checking

Â whether R's uniform random number generator.

Â Which we know is a probability of

Â pretty good u, u, uniform random number generator.

Â Whether or not it, it generates reasonably uniform

Â numbers where we've broken the intervals up into 4.

Â You know, the, the test applies regardless of how we break up the intervals.

Â We could have made some of them small, some of them large, and so on.

Â and there's maybe, you know, you could pick

Â what's the most appropriate way to break up the intervals, but either way, this

Â you know, the, the, the logic behind doing this goodness of fit testing applies.

Â I would note that the degrees of freedom is, the,

Â Is the, just the number of, of cells minus 1.

Â And the reason, in this case is because we don't, you know,

Â we're not estimating anything, under the

Â null hypothesis we're actually specifying the probabilities.

Â So we don't

Â that, that's what changes the, that's what changes the degrees of freedom.

Â so, so let me also comment a little about testing random number generator.

Â you know, if, if, if you were going to do this you, you know,

Â you'd be concerned, you know, you would

Â want to generate thousands and thousands of variables.

Â You'd probably want very fine intervals that you were looking at.

Â and then the other thing is that This is

Â only testing one aspect of the random number generation.

Â It's only testing the uniformity, how uniform on the range it is.

Â But there's other aspects of randomness that, that

Â you would like to test, like whether or not.

Â You can detect whether the next value is it's,

Â it's somehow related to the previous, or something like that.

Â It's like some sort of auto-correlation or, or, or runs behavior.

Â and, and, and those sorts of things are what people do to

Â stress random number generators, which by

Â the way, are actually perfectly deterministic,

Â there's no randomness built into the computer.

Â Isn't, you know, picking off the clock,

Â or something like that, some, somehow generating randomness.

Â It's a deterministic sequence of numbers.

Â It's, they do those deterministic sequence of numbers

Â in such a way that it's, that it's very

Â hard to develop a statistical test that will

Â tell you that it's not exactly uniform in IID.

Â There's a whole discipline to this.

Â It's quite interesting.

Â let's see.

Â the other thing I would say about random number, number generators.

Â I can't do this obviously in this class.

Â but if you were to ask students in a class to generate random uniforms or random

Â integers, and you could of course you know,

Â create a goodness of fit test to evaluate it.

Â it's unbelievable how quickly you can determine that your people

Â aren't good at generating random numbers, in the sense of being equally distributed.

Â People can't distribute, you know, just ask a room full of

Â people to write out digits between one and ten, collect' em up.

Â And you will be able to diagnose immediately that that was not generated.

Â uniformly and IID from the digits one to ten.

Â It is an interesting experiment. You might want to try it sometime.

Â One of the easiest

Â ways to do it is that people don't give enough runs of specific numbers.

Â So, you know.

Â If you collect enough random digits, there should be one

Â to ten, there should be some instances of three consecutive 7s.

Â But if you ask people to write out a bunch of random

Â digits, they'll never write out three consecutive 7s, for whatever the reason.

Â Just goes to show, our intuition about what randomness is is not very accurate.

Â We, we have to have the mathematics,

Â because our intuition's flawed. Any way, let's move on to another

Â example of goodness of fit testing.

Â Okay, here's a famous example of goodness of fit testing.

Â so in, in, Mendel's P plant

Â experiment if you do out the Punnett square you,

Â you get under the what is it called? The Law of Independent Assortment.

Â You should get about 75% of the of the Yellow and, and 25% of the Green plants.

Â and so here's the observed data 6,022, 2,001, total 8,023.

Â And here is the expected data. how would you get the expected data?

Â Well, the true positive, not true positive.

Â the, true probabilities hypothesized true probabilities, let

Â me put it to you that way.

Â if the independent assortment laws were correct, you would get 0.75 and 0.25.

Â So you're multiplying 0.75 times 8,023 you

Â get 6,017.25, 0.25 times 8,023 you get 2,005.7

Â [UNKNOWN]

Â 0.75.

Â S, using the observed minus expected squared over expected statistic, you get a

Â A very small Chi squared statistic. And

Â co, continuing on to the next slide.

Â you know, this is a 1 degree of freedom test because it's,

Â you know, cells minus 1, 2 minus 1, 1 degree of freedom.

Â The P value works out to be 0.90.

Â In other words, the probabilities fit the hypothesis, the, expected,

Â the observed cell counts fit the expected probabilities quite well.

Â and any rate there, there was a, there's an interesting kind

Â of famous discussion that occurred over this is that the, the,

Â the well know statistician Fisher combined several of Mendel's tables, used

Â the fact the sums of independent chi squareds should be chi squared.

Â He got his, you know, with the degrees of freedom adding up that he got a, You

Â know an associated P value of, you know, perhaps exactly,

Â almost exactly one. And his accusation was then that maybe

Â this the data fit the Mendel's hospital ha, ha, hypothesized

Â probabilities to, too well, that maybe something fishy was going on.

Â So I don't know, you can, you can read

Â about that It's kind of an interesting little study.

Â Okay, so for the final slide on

Â goodness of fit testing, let's just summarize.

Â it tests whether not observed counts are

Â consistent with theoretical values, theoretical hypothesized probabilities.

Â The test statistic remains the same chi-squared test statistic.

Â It follows a chi-squared distribution minus 1, the degrees

Â of freedom are the number of cells minus 1

Â [UNKNOWN]

Â this is especially useful for testing random number.

Â Generators I, I, I, the you know,

Â this is all for discrete discrete data.

Â We had to discretize the uniform distribution to

Â use the chi squared goodness of fit test.

Â There's a test called Kolmogorov.

Â sm, Smirnoff test, that's an alternative that doesn't require discretization.

Â you know?

Â It's often accused of having low power but, you know?

Â It, it's depends on what alternatives you're

Â searching for, and that sort of thing.

Â but it is another test for, very well known test for goodness of fit testing.

Â So that, today's lecture covers a

Â lot of chi squared testing in a nutshell.

Â And if you want to just remember a couple

Â of things make sure you remember that the observed

Â [UNKNOWN]

Â minus expected squared over expected.

Â Some of those guys is the statistic you know, remember the, the way in

Â which you got the expected cell counts

Â using independence that, that applies regardless of the,

Â of the, applies across all the settings that we consider today remember that the,

Â the degrees of freedom for the goodness of fit testing was a little bit different.

Â And the way in which you set up a goodness of fit

Â test was a little bit different.

Â but still uses the same, observed minus expected squared, over expected statistic.

Â Okay? And

Â we'll see you next time.

Â for the let's see what is this a I think the last lecture in this module.

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