0:17

Here whether in A B testing or in randomized trial,

Â you are performing the randomization in order to balance unobserved

Â co-variats that may contaminate your results.

Â Because you've performed this randomization,

Â it's reasonable to just compare the two groups with a t confidence interval or

Â a t test, which we'll cover later on.

Â But we can't use a paired t test,

Â because there is no matching of the subjects between the two groups.

Â So we now present methods from com, comparing across independent groups.

Â 0:54

The standard confidence interval in this case is Y bar minus X bar,

Â the average in one group minus the average in another group,

Â times the relevant t quantile.

Â Where here the degrees of freedom are a little bit hard.

Â The degrees of freedom are nx plus ny minus 2,

Â where nx is the number of observations going into the X group,

Â and y is the number of observations going into the Y group.

Â 1:25

Here this is the standard error of the difference.

Â This S sub p right here I'll talk about in a minute.

Â But it is multiplied times this factor here,

Â 1 over nx plus 1 over ny, raised to the one-half power.

Â You'll notice that as we collect more data, 1 over nx,

Â gets very small and 1 over ny gets very small.

Â The S sub p squared is the so-called pooled standard deviation.

Â Or, I'm sorry, S sub p squared is the so-called pooled variance.

Â Its square root is the pooled standard deviation.

Â If we're willing to assume that the variance is the same in the two groups,

Â which would be reasonable if we had performed randomization,

Â then our estimate of the variance should at some level be an average of

Â the variance estimate from group one and the variance estimate from group two.

Â However, if we have different sample sizes,

Â we'd like to weight the variance estimate from group one more than we weight

Â the variance estimate from group two.

Â And that is exactly what the pooled variance estimate does.

Â If in fact you have equal numbers of observations in both groups,

Â nx is equal to ny, then the pooled variance is the simple average

Â of the variance from the X group and the variance from the Y group.

Â But remember, this interval assumes a constant variance across the two groups.

Â If that assumption is violated,

Â then this interval won't give you the proper coverage.

Â 3:13

Here I go through an example from Rosner's Fundamentals of Biostatistics book.

Â This is a very good reference book.

Â I quite like it.

Â However, you don't want to put it in your backpack, because it's pretty heavy.

Â It's a very thorough book about couple hundred pages,

Â and weighing over five pounds is my guess.

Â In one of the examples from this book, they're comparing 8

Â oral contraceptive users to 21 controls with respect to blood pressure.

Â For the oral contraceptive users, they got a average systolic blood pressure

Â of 133 milligrams of mercury, with a standard deviation of 15,

Â a control blood pressure of 127 with a standard deviation of 18.

Â Let's go ahead and manually construct the independent group interval once,

Â just to churn through the calculation.

Â When you tend to do this on your own you tend to use t.test or

Â something like that because you have the raw data.

Â So the pooled standard deviation estimate is going to be

Â the square root of the pooled variance estimate.

Â There we need to take 15.34,

Â the standard deviation from the oral contraceptive users, square it, 18.23.

Â The standard deviation from the controls and square it.

Â And take their weighted average, weighted by their sample sizes.

Â So 7, which is 8 minus 1, and 20, which is 21 minus 1,

Â from the two sample sizes minus 1.

Â Then divided by the sum of the sample sizes minus 2.

Â That gives us a weighted average of the variances,

Â where the group, the control group with 21,

Â gets more impact than the oral contraceptive users with 8.

Â Then I square root the whole things, because I want the standard deviation.

Â Then my interval is the difference in the means.

Â And then you always, whenever you're doing an independent group interval,

Â you always want to kind of mentally think, which one of my su,

Â which one is the first part of the sub, subtraction.

Â In this case my oral contraceptive users are the first part,

Â so I want to just remember that.

Â Because you don't want to look silly and

Â suggest the controls have a higher blood pressure than oral

Â contraceptive users when the empirical averages are exactly the reverse,

Â just because you reverse the order in which you were subtracting things.

Â Then I want to add and subtract the relevant t quantile,

Â 27 degrees of freedom, which is 8 plus 21 minus 2.

Â The pooled standard deviation estimate times 1 over n1 plus 1 over n2,

Â raised to the one-half power.

Â I get about negative 10 to 20.

Â In this case my interval contains 0, so I cannot rule out 0 as the possibility for

Â the population difference between the two groups.

Â 6:04

Let's move on to another example.

Â Let's revisit the example where we were looking at the sleep patients

Â on the two drugs, but let's tr, pretend that the subjects weren't matched.

Â Okay, so I have n1 is from group 1, n2 is from group 2.

Â Remember in this case both of those would be 10.

Â I go through the construction of the pooled standard deviation estimate.

Â I get the mean difference.

Â And I get the standard error of the mean difference, which is the pooled standard

Â deviation est, estimate times square root 1 over n1 plus 1 over n2.

Â Then I collect together my manual construction of the confidence interval,

Â which takes the mean difference and

Â subtracts the t quantile times the standard error of the mean.

Â And then I do t.test.

Â And I give it the first vector and the second vector.

Â I tell it paired equals FALSE.

Â And then because I want the interval, where I'm treating

Â the variance in the two groups as equal, I do var equal, equals TRUE.

Â And then I grab the confidence interval part.

Â And then I want to compare it, where the instance where paired equals TRUE,

Â just to remind us that ignoring pairing can, can really mess things up.

Â And I want to grab the confidence interval.

Â So here we get the interval.

Â And my manual calculation of course exactly agrees with the standard t

Â calculation.

Â And you see that you get a very different interval than when you do the paired.

Â If you take into account of the pairing, actually the interval is entirely above 0,

Â where if you disregard the pairing, the interval actually contains 0.

Â And I think when you actually look at the plot it seems quite clear to me why

Â that's the case.

Â If you're comparing this variation to that variation,

Â that's a lot variability in the two groups.

Â However, when you're matching up the subjects and

Â looking at the variability in the difference,

Â there's a lot of that variability is explained by inter-subject variability.

Â 8:08

The ChickWeight data in R contains

Â weights of chicks from birth to a couple of weeks later.

Â So to get it you can do, library datasets, data ChickWeight.

Â And then I need to work with the data and I highly recommend the package reshape2.

Â And I'll go through a little bit about some of the reshape commands and

Â what they're doing.

Â So, the ChickWeight data comes in a formate,

Â format that is a long format.

Â So, it's the chicks lined up in a long vector.

Â So, if you want to take that long vector and make it a wide vector, so

Â that there's one column saved for each time point that we measure the chick, then

Â you want to do something like dcast, which is a function in the reshape package.

Â So we want to dcast this ChickWeight data frame.

Â And the variables Diet and Chick are the things that are staying the same,

Â and the Time variable is the one that's going to get sort of

Â converted from a long format to a short ver, format.

Â So, and then I don't, I didn't like the names that it was giving it, so

Â I renamed the latter couple of columns.

Â Then I wanted to create a specific variable that

Â is simply total weight gain from time zero.

Â So I use the package dplyr.

Â Which then I take my data frame and I do the command mutate.

Â And I want to give it my data frame again.

Â And I want to create a new variable which is just the final

Â time point minus the baseline time point, so the change in weight.

Â And the change in weight is what I'm going to analyze from here on out.

Â But let's actually look at the data first before we run our test.

Â 10:19

Here's the data for each of the four diets plotted as a so-called spaghetti plot.

Â And again the command for this plot, I used g g plot two.

Â I've been trying throughout the lectures to convert all the graphics

Â to g g plot two, since we teach g g plot earlier on in the specialization.

Â Here, we show each of the diets

Â from baseline here to the final

Â time point here for each case.

Â So you'll notice there are some things that are potentially suspect, though

Â they're a little bit hard to ascertain because of the varying sample sizes.

Â For example, there appears to be a lot more end

Â variation in the first diet than in the fourth diet.

Â Though again,

Â there's a greater number of chicks in the first diet than in the fourth diet, so

Â it's maybe actually a little bit hard to actually compare the variability.

Â I put a reference line here that is the mean for each of the groups.

Â And I think, at least without any formal statistical test,

Â it does appear that the average weight gain for the first diet does

Â appear to be a little bit slower than the average weight gain for the fourth diet.

Â Well let's actually look at it, using a formal confidence interval.

Â 11:52

Here I just show, rather than plotting the individual measurements,

Â I show the en, end weight minus the baseline weight by each of the diets,

Â using a so-called violin plot.

Â We're going to look at diets one and four, and so

Â we're going to be comparing this violin plot,

Â basically verses that violin plot.

Â So our assumption of equal variances appears suspect here.

Â In order to do the t test notation, where you take an outcome variable like gain,

Â weight gain, and use tilde times the explanatory variable of interest,

Â for the t test function, for that to work,

Â it needs to only have two levels for the explanatory variable.

Â 12:46

So that's what this subset command does, is that I merely take those records for

Â which diet is in the variables one or four.

Â So omitting diets two and three.

Â And again, when you repeat this analysis on your own,

Â you might want to compare one to two, one to three, one to four,

Â two to three, two to four, and three to four, and do all possible comparisons.

Â If you were to do that, I might add,

Â you would also want to account for multiplicity,

Â which later on in the inference class we're going to discuss how to do.

Â 13:23

Here, I show the interval.

Â Again I'm collecting the results with an rbind statement.

Â Here I show the interval.

Â I want paired equals FALSE.

Â Which in this case paired equal TRUE isn't even an option because the variables

Â are of different, the vectors of, are of different length.

Â But what I do compare here is assumption that the variances are equal

Â versus the assumptions that the variances are unequal.

Â And you do get difference, different intervals.

Â Both cases I'm grabbing the confidence interval.

Â 13:55

In the first one I get negative 108 to negative 14.

Â In the second I get negative 104 to negative18.

Â Both cases the intervals are entirely below zero,

Â suggesting less weight gain on diet one than on diet four.

Â However, the specific interval does change depending on whether or

Â not you have the variances are equal and the variances are false.

Â Now I don't know enough about the specific dataset to ascertain whether that's

Â a substantive change or not.

Â