An introduction to the statistics behind the most popular genomic data science projects. This is the sixth course in the Genomic Big Data Science Specialization from Johns Hopkins University.

Loading...

From the course by Johns Hopkins University

Statistics for Genomic Data Science

118 ratings

An introduction to the statistics behind the most popular genomic data science projects. This is the sixth course in the Genomic Big Data Science Specialization from Johns Hopkins University.

From the lesson

Module 1

This course is structured to hit the key conceptual ideas of normalization, exploratory analysis, linear modeling, testing, and multiple testing that arise over and over in genomic studies.

- Jeff Leek, PhDAssociate Professor, Biostatistics

Bloomberg School of Public Health

So this is the second lecture on exploratory data analysis.

Â And so I'm going to go through a little bit more quickly this time the set up just

Â to get up and going.

Â But I'm going to set up the colors like I did in the previous lecture.

Â I'm going to set the parameter for

Â the plotting parameter so that it looks like I'd want it to as well.

Â And then I'm going to load all the packages that we need to load.

Â And then after I do that I'm going to load in the data set and get us up to speed.

Â Okay.

Â So if you want to see more about how I did all that and what I'm doing there,

Â you can watch the first lecture on exploratory data analysis.

Â So, after we check sort of to make sure that all the certain dimensions match, and

Â that we're not missing any values or anything like that,

Â the next thing I do is I make lots of plots.

Â So the first kind of plot that you can make is a box plot.

Â And so if I make a box plot of say the first set of values, I'm going to look at

Â the expression data, the first column of that data set and I make a box plot.

Â You can see that most of the values are down here at zero, so

Â I might do some kind of transform to the data.

Â I might try to take the log transform of the data.

Â And then here I'm going to add one so that the values won't be messed up.

Â And so it didn't really help me this time, but you, in general,

Â can sort of make different transforms to try to see if the data look good.

Â You can also plot more than one value at once, so here I'm going to do that

Â same box plot, but now instead of just selecting out the first column,

Â I'm going to box plot apply to the entire matrix.

Â And so when I do that, I actually get one box plot per sample, so

Â one box plot per column of that data set.

Â And then I can set the color to be a color that I like.

Â And then, in order to not have all those outlying points,

Â I can set range equal to zero, and so then it will make this sort of whisker extend

Â all the way out to the most extreme outlying point.

Â So here I can already see again that the data is pretty skewed for

Â all these different samples.

Â And you can see it because most of the values are squished down here near zero.

Â The other thing that you can do is you can make histograms.

Â So I'm actually going to show two histograms.

Â And if I want to show plot side by side, I can use the par(mfrow=c(1,2)).

Â This is basically saying set up the screen so

Â that it has one row and two columns of plots.

Â So it's side by side plots.

Â So I can make a histogram of the values from the first sample.

Â So again I'm going to do this transform here because I

Â think it makes it a little easier to see.

Â And then I'm going to set the color equal to two, so

Â this is going to make this nice blue histogram.

Â And so you can see here right away that almost all the values are equal to zero.

Â And then you see some values out to the right there.

Â And so, then, I can make that same plot.

Â But for the second sample, and so, when I do that,

Â you can see that it has a very similar distribution.

Â It also has many zero values, and then some values out the side, there.

Â So, that's one way you can start looking sample by sample, but

Â sometimes it's hard to see a lot of samples that way.

Â So if you wanted to see a bunch of samples,

Â you want to be able to overlay the plots on top of each other.

Â So here I'm going to set it to be back to just a one by one plot so

Â it's a little bit easier to see.

Â And so, the first thing I could do, is I could make a density plot.

Â And so the density plot is going to basically show the distribution of

Â values sort of similar to a histogram but with a line plot.

Â And so one way that I can do that is I'm going to

Â apply the density function to that first sample.

Â So here I've got the first sample, I'm going to take the log transform of

Â the first sample, then I'm going to calculate a density of that sample.

Â And then I'm going to make the color to here.

Â So here I can see that density so it looks a little bit like

Â the histogram I've got the X values here and then I've got like how frequently

Â they appear on the Y axis and so you can kind of see this distribution here.

Â And so the next thing that you could do is you could add on top of that and

Â you could start layering other values on top so if I just plotted the next value,

Â like if I just typed plot the same plot.

Â So I pressed up to get the command back and I pressed plot.

Â The second column of that data set it would just overwrite the plot.

Â So instead of doing that,

Â what I'm going to do is I'm going to use the lines command.

Â So the lines command will let me overlay

Â another plot on top of the plot that I just had there.

Â So I'm going to do the second sample now, and

Â I'm going to give it a different color.

Â So now I can see, you know, plot one is in blue.

Â Sorry, sample one is in blue, sample two is in pink, and

Â I can overlay a bunch of samples this way so I can see if the distributions are all

Â similar or if I see any kind of bulk changes in the distributions.

Â That can be a sign that there's an artifact going on.

Â So that's a plot that I usually make to check.

Â The other thing that I do to check to make sure the samples are sort

Â of consistent is, I make what's called a q-q plot.

Â So, if I do a qq plot of the first sample, so here, doing this transform again.

Â I'm going to do the same thing for the second sample.

Â I can see a bunch of data points here and so one thing to keep in mind is that

Â when you make it this plot now, this q-q plot is making one dot for every gene.

Â And so, or, sorry, for every quantile of these two distributions.

Â And so

Â it depends on the number of quantiles that it has to calculate how long that'll take.

Â And so for example this dot right here this says this is say the 5th percentile

Â so this is the 5th percentile for the second sample is on the Y axis.

Â And the fifth percentile for first samples on the x axis.

Â So we can see that it's above the 45 degree line here and so

Â you can see that the second sample has a higher fifth percentile

Â than the first sample so it has higher values for low values.

Â If you want to be able to see that a little more clearly you can

Â add a 45 degree line.

Â And one way you can do that is with this abline command, abline.

Â And you can tell it, you use this intercept and this slope and

Â so you can see here this has an intercept of zero and a slope of one.

Â That's the 45 degree line.

Â And so, if I add that on top so there's the 45 degree line,

Â you can see here the quantiles are a little bit larger for

Â the second sample down low and they're a little bit lower up high.

Â And so you can kind of see how the two distributions compare to each other.

Â The other thing you can do when comparing samples,

Â is you can make what's called an MA or a Bland-Altman plot.

Â So here I'm going to take the difference between the two samples and

Â I'm going to make that the Y axis so

Â I'm going to take the difference between sample one and sample two and

Â then I'm going to add the two samples up.

Â I'm going to make that the X axis.

Â So I'll explain that in a minute.

Â So now if I plot on the X axis the sum of the two samples and

Â on the Y axis the difference of the two samples.

Â Again, now it's going to have to plot 52,000 data points, so

Â this might take a little while.

Â So on the X axis we have the sum of the two samples.

Â So basically moving from left to right you get lower expression or

Â lower counts to higher counts.

Â And on that Y axis, you're to take the difference.

Â So if it's at zero, that means there's no difference between the two samples.

Â So you can see for example trends here.

Â You can see as you get higher and higher accounts there's sort of a trend that

Â appears to be that the samples get closer and closer together so

Â each dot here is one gene and so

Â I'm just taking the difference between the two samples for that gene.

Â So this MA kind of plot people make very often you want to see that it's,

Â especially for technical replicates,

Â there's some kind of replicates that should be similar.

Â You want to see it centered on the zero line, and

Â you'd like to see it with low variability and

Â no trends that are dependent on the total number of counts for those samples.

Â And so, that's a way that you can sort of make those plots to compare them.

Â Now, the next thing that you can do is,

Â is if you want to be able to make the plots for.

Â We saw these sort of box plots, and many of these plots are very skewed.

Â And so, one thing that you can often do to make the plots a little bit better,

Â especially for count-based data.

Â You often need to remove the low expression or the low count

Â features to be able to really be able to see the distribution of the data.

Â So to do that I'm going to make the data set a data frame so

Â that I can use the dplyr filtering commands.

Â And I'm going to filter the data set.

Â So I'm going to take that data print here,

Â I'm going to apply the filter command to it, and I'm going to say filter out,

Â keep only the rows that have a mean greater than one.

Â So what is this doing?

Â It's taking the mean for each row of the data set.

Â It's going to say is that mean greater than one.

Â If it is greater than one it's going to keep it after I filter it here, so

Â now the dimensions of this new data set are smaller.

Â I've removed a large number of the features.

Â I only have about 12,000 left, and

Â now I can make that same box plot that I did before.

Â So again, I converted it to a data frame so I could do the filtering.

Â Now I have to convert it back to a matrix so I can do the plotting,

Â there's a little bit of a difficulty with this filtering approach.

Â But now you can see, oops.

Â What did I do here?

Â Oh, I've got edata here instead of a data, there we go.

Â So now I've got the box plot one for every sample and so

Â you can see the distribution a lot better now, so basically I removed

Â all those like they were a ton of values that were just equal to zero.

Â I removed all of those, and said this is the distribution of the remaining values.

Â The values that for the genes that have an average greater than one on this scale.

Â And so you can do these sorts of transforms and these sorts of filtering to

Â basically get an idea of what the real distribution of the data will look like.

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