Welcome!

Welcome to my blog, a place to explore and learn about the experience of running a psychiatric practice. I post about things that I find useful to know or think about. So, enjoy, and let me know what you think.


Showing posts with label statistics. Show all posts
Showing posts with label statistics. Show all posts

Sunday, October 27, 2013

Statistically Writing: Normal Distribution

I know it's been a while, but it's time to pick up again with our statistics education.

Last time, we learned about standard deviation and variance. Let's review.
Note: we're going to talk about population and not sample in this post:

Variance is denoted by Sigma Squared:

Variance, Mu=mean


You'll hopefully recall that variance is a measure of distance from the mean, in a collection of data. But it's a little awkward because of the squared element, which leads us to:

Standard Deviation, denoted by sigma:  

Standard Deviation

Standard Deviation is the square root of Variance, which yields a measure of distance from the mean that's not squared, and therefore has the same units as the mean.

So if you're considering the number of cockroaches in NYC apartments, let's say the mean is 50 (probably more, but yuck). The Variance would be in units of cockroaches squared, while the Standard Deviation would be in units of cockroaches.

Normal Distribution

This graph depicts a Normal Distribution, with the center line equal to the mean:

Normal Distribution
And this is the function that describes the graph:



Notice that the function is described as "p of x". Normal Distribution starts with an "N". It's sometimes referred to as a bell curve, because of the shape, and bell starts with a "b". So why a "p"?

"P" is for probability.

A watermelon can weigh anywhere from a few pounds to 20 pounds, but say that, on average, watermelons weigh 10 pounds. If you look at a graph of the weights of watermelons, it will look like the graph above, and the center line will be 10 pounds, the mean. In other words, the vast majority of watermelons will weigh 10 pounds, plus or minus maybe 5 pounds. And a few crazy melons will weigh 20 pounds, or 1 pound.

So that graph is the likelihood, or probability, that a given watermelon will have a certain weight. If I go to Whole Foods and pick up an average sized watermelon, the chance, or probability that it weighs around 10 pounds is very high.

However, the chance that it weighs exactly 10 pounds is not high. In fact, it's zero. Why? Because it's impossible to be that precise. It could weigh 10.00000001 pounds, for example.

The way you need to think about it is, what is the probability that a given melon will weigh between 9.5 pounds and 11.5 pounds? A range. And the probability is given by the area under the curve in that range, which, if you recall your calculus, is the integral of p(x) from 9.5 to 11.5.

The fact that the probability is the area under the curve helps clarify why the chance that a watermelon weighs exactly 10 pounds is zero. Because the area under the curve at 10 pounds, or at any individual point, is the area of a line, which is zero. A line has no width.

A note on probability:

The probability of ANYTHING is between zero and one, which is the same as 0% and 100%. It's important to know this because the graph of a normal distribution extends to plus and minus infinity, so the total area under the graph, which is the integral of that scary looking function, p(x), from minus infinity to plus infinity, is one.

Many real-life statistics are normally distributed (that is, they can be described by a symmetric bell-shaped curve). For example, heights of 3rd graders, or weights of watermelons. But not all statistics are normally distributed. There can be sets of data with many outliers. Or there can be sets of data that follow different distributions. But most of the data we look at in medical studies are normally distributed, and the statistical analysis tools we're used to reading about, ANOVA, t-test, paired t-test, are all designed for use with a normal distribution.

These are some of the defining features of a normal distribution:

* Mean = Median = Mode
* Symmetry-the left side of the graph mirrors the right side of the graph, and because of this:
* 50% of the graph is to the right of the mean, and 50% of the graph is to the left of the mean.

Let's do an example.

I rolled 2 (virtual) dice 100 times, and these are the totals:

7 4 2 2 6 7 8 7 6 5
4 7 12 7 4 8 11 7 6 6
6 4 10 10 6 7 7 11 7 2
5 4 2 8 7 12 6 12 8 4
6 4 7 3 6 5 12 5 12 6
8 7 9 7 2 7 5 6 6 6
7 11 12 12 7 6 8 9 3 5
7 7 4 10 5 7 7 6 8 9
9 7 11 8 5 8 5 6 8 7 9
6 8 11 4 11 7 5 3 6 6

The average total = 6.8.
And the standard deviation = 2.5
(I let my spreadsheet compute these for me)

Now, we probably all know that the most likely total of two dice will be a 7, but let's just check:

#2's:    5
#3's:    3
#4's:    9
#5's:    9
#6's:   19
#7's:   23
#8's:   11
#9's:    5
#10's:  3
#11's:  6
#12's:  7

Yes, there are twenty three 7's, making 7 the most frequent result. What we're looking at here, then, are frequencies, how often an individual total was rolled. And remember, these frequencies represent probabilities. So the probability, or likelihood of rolling a 7 is 23/100 or 23%, and the probability or likelihood of rolling a 4 is 9/100 or 9%. In the future, if I choose to bet on a pair of dice, based on the data above, I'd have a 9% chance of rolling a 4. (There are better and simpler ways to compute the odds on dice, BTW).

If we graph these frequencies, we get:




Notice, this doesn't quite look like a normal distribution, even if you draw in the curve along the tops of the bars and smooth it out. There are several reasons for this.

1. There are only 100 data points. That's not bad, but the larger the sample size  the more the graph will look like a perfect bell curve, and we're not quite there with this one.

2. It's not really a normal distribution. The result of a dice roll is an integer between 2 and 12. These are discrete results (discrete like individual, not discrete like secret). And for a normal distribution, you really need continuous results, like average weight of a watermelon.  But since I didn't want to buy and measure 100 watermelons, this will have to do. And it does approximate what we're talking about. But how well?

Let's check it against our requirements for a normal distribution:

1. The mean = 6.8. The mode would be 7, because that's the most common result. And the median is also 7, the middle value. So the mean is off a little. If I rolled the dice 1000 times, the mean would move closer to 7, and if I rolled the dice infinitely many times, the mean would be exactly 7. But I don't have that kind of free time, so this will have to do.

2. Symmetry: Are the left and right sides mirror images of each other? Not really, but if we rolled infinitely many times, they would be.

3. Are 50% of the values to the right of the mean, and 50% to the left? No.

But overall it's not a terrible approximation of a normal distribution.

Let's consider another property of normal distributions. the standard deviation is 2.5, and the mean is 6.8. This implies that anything that falls between 4.3 and 9.3 (6.8 +/- 2.5) is within 1 standard deviation of the mean. If we count up the data, there are 9 fives, 19 sixes, 23 sevens, and 11 eights, and five, six, seven, and eight all fall between 4.3 and 9.3, So there are 62 data points within one standard deviation of the mean, or 62% of all data is within one s.d. of the mean.
Two standard deviations would be between 1.8 and 11.8, and all but 7 data points are in that range (everything but the twelves, of which there are 7). So 93% of the data lies within two standard deviations of the mean.

These figures approximate something called The Empirical Rule, which is another property of a normal distribution, and which states that:

68% of the data lies within 1 s.d. of the mean
95% of the data lies within 2 s.d.'s of the mean, and
99.7% of the data lies within 3 s.d.s of the mean

The empirical rule is useful, because the integral of that nasty looking p(x) that represents the normal distribution is quite difficult to solve, so it's generally determined numerically, using something called the cumulative distribution function, which we won't get into, but which tells us the area under the curve to the left of any given point. But in the absence of the ability to solve that integral, or access to the cumulative distribution function, we can learn a lot from the empirical rule, because we know the whole, 68-95-99.7 thing.

And the values we computed above, 62% for 1 s.d. from the mean, and 93% for 2 s.d.'s from the mean, are pretty close, especially considering the limitations of our example (not enough data points, not really a normal distribution).

Pictorially, it looks like this:

I'll wrap up now, but keep in mind, a real normal distribution goes on forever, so there will always be points way, way to the right and left of the mean. But even so, the vast majority of the data lies within 3 s.d.'s of the mean. And importantly, 95% of the data is within 2 s.d.'s, so that only 5% of the data lies outside 2 s.d.'s. Meaning that the probability, p, that a data point lies further than 2 s.d.'s from the mean, in either direction, is < 0.05.














Wednesday, October 2, 2013

Another Plug

Just a brief reminder to take our survey about whether and how you'd like to participate in an online journal club.

CLICK HERE

And here's a list of some upcoming posts:

1. Journal article review

2. Apps for writing process notes.

3. More on Statistics

Sunday, July 28, 2013

Statistically Writing-Variance and Standard Deviation

I hope people weren't too annoyed by my previous statistics post about measures of central tendency. But it's important to really understand the concept of a mean, and its implications for research, before moving on to bigger and better things. This time around, we're going to look at measures of dispersion.


Say you have a set of data points, and you've figured out the mean for that set. You might, then, want to know how far from the mean each of your data points is. So if you subtract each data point from the mean, and take the absolute value, you would know that information, for each point.

Consider teenagers. You have a group of 5 teens, and each spends a certain number of hours per day on Facebook:

T1=3; T2= 5; T3=2; T4=6; T5=2

If you calculate the mean here, you get: 3.6. So, on average, each teen spends 3.6 hours per day on Facebook.

Now suppose you want to know how close or far from average each kid's time on Facebook is (Why? To see if your kid is a freak):

T1: |3-3.6|= 0.6
T2: |5-3.6|= 1.4
T3: |2-3.6|= 1.6
T3: |6-3.6|= 2.4
T5: |2-3.6|= 1.6

Well, that's nice, but notice, you have another data set here, for which you can also find the mean. This is called the Mean Absolute Deviation. In this case, it's equal to 1.52 hours.


But Mean Absolute Deviation is not Variance. Variance, denoted by sigma squared, is actually the sum of the squares of each of these numbers, averaged out:




So here, the Variance = (0.62 + 1.42 + 1.62 + 2.42 + 1.62)/5 = 5.72.


You may recall from my last stats post that I wrote about the distinction between the sample mean and the population mean. In the above example, the 5 teens constitute our entire population, and the formula above is for population variance, denoted by sigma squared. (Also note that population mean is denoted by mu.)

But let's say you want to use this group of 5 teens to estimate the average number of hours on Facebook for all teens in the US. Then the group of 5 teens is a sample. And weird as this may sound, a better way to estimate the variance of a population based on a sample is to calculate the "unbiased sample variance", denoted by s squared, where the result is computed by dividing by n-1 rather than by n.



In this case, the unbiased sample variance = 7.15.

Variance is a useful measure of how far from the mean the data points are. But notice, it's a squared value. This implies that the distance from the mean is exaggeratedly large. Just looking at the variance, without units, you can see that 7.15 is bigger than the greatest amount of time spent on Facebook, 6 hours.

And if you have outliers, say some weird kid was on Facebook 20 hours a day, the variance will be huge. For those readers who thought my last statistics post was overly simplistic, this is where it starts to be important to know which measures are good for data with outliers, and which aren't.

Also, if your data is measured in hours, it's unintuitive to think about distance from the mean in hours squared. This is where Standard Deviation comes in handy.

Standard Deviation is nothing but the square root of variance:

For an entire population,



And for a sample,



In this case, the Population Standard Deviation = 2.39,

and the Sample Standard Deviation = 2.67.


Visually, it looks something like this:



The mean is in blue, the data points in green, and the purple lines represent one standard deviation in each direction from the mean.

Wednesday, July 10, 2013

Statistically Writing

I took a Statistics class my sophomore year in college. Got an A, didn't learn anything. I subsequently learned some probability and combinatorics, which I find immensely useful (not being facetious), but I still don't know any stats. And it seems to me that if I'm going to try to intelligently  read papers, I should know, really know, what ANOVA is, and how to compute number needed to treat, and all that other jazz.

Since this is the kind of information that is useful to most or all clinicians, I thought I'd break the topics up into individual posts, and share my understanding, or lack thereof. Now, most of you probably already know all of it. You haven't forgotten anything you learned about statistics in medical school, and you read through the minutiae of the statistical analyses in all studies you peruse. So you probably don't need it. But for the minority who don't remember so well, here's a refresher.

And please let me know if this is overly simplistic. Maybe I'm the only one, but honestly, I didn't really get the implications of this stuff until I wrote this post.

Let's start with the basic basics, measures of central tendency. These are the mean, median, and mode. The definitions are pretty simple. The mean is the average, the median is the middle value, and the mode is the most common value. But the important question, when it comes to understanding the results of a study, for instance, is why would you use one rather than the other?

For the record, what's referred to as the "mean" is generally the "sample mean", i.e. the average value of all the data points in a given sample. This stands in contradistinction to the "population mean", the average value of all the data points in an entire population.

Say you wanted to know what percentage of redheads in the US are left-handed. One way to determine this would be to find every last redhead in the country, and count the number of lefties. In this case, you'd be looking at the entire population, which, practically speaking, is impossible to do on a limited grant. So instead, you'd pick a sample of redheads, maybe all the redheads in your town who were willing to sign up for the study. This is a more do-able project, and you hope that the sample you're looking at is representative of the entire population. But if for some reason your town had an unusually high number of lefties, then the sample would not be representative of the general population in the US.

If you think about it this way, you can see how a perfectly conducted study can draw erroneous conclusions, because it can't look at the entire population, just a sample of it.

The function of any measure of central tendency is to give you a handle on a collection of data points, a sense of what the data is "telling" you. But it's important to note that there is no best measure of central tendency. The one we see the most is the mean, but it has it's limitations.

The mean is useful for including all data points, even in very large sets. And it's easy to incorporate new data.

Where it starts to falter is with outliers. Suppose you want to know the typical number of marbles owned by each of five children.  And suppose the numbers are as follows:

3; 7; 4; 5; 100

The mean value here is 23.8. But it would be misleading to say that on average, each child has 24 marbles. This is where the median is useful. If you put the numbers in order:

3; 4; 5; 7; 100,

you can see that the median is 5, which is much closer to the number of marbles owned by most children in this group.

This is something to keep in mind when reading a study. If a new antidepressant, Happyzac, caused massive improvement in 2 out of 30 subjects, but poor to moderate improvement in the other 28 subjects, the mean improvement might be misleading.

On the other hand, the median can be difficult to use if there is a very large data set, since it has to be put in order.

Also, if some data points are very close together, and others spread out, the middle number may not be the most useful way to think about the data set. Consider the following sequence:

1; 2; 3; 30; 70; 200; 554

The median here is 30, which really doesn't tell you much about the nature of this set. Unlike the example above, there are no outliers, just one small cluster, and a bunch of other numbers all over the place.

The mode is good for categories, particularly non-numerical ones. Say you wanted to find out the most common hair color of lefties. The mean isn't useful because how do you average hair color? And the median isn't useful because how do you put hair color in order, so you can determine the middle value?

The problem with the mode is that it can be very far from the middle value. Also, there can be more than one mode, e.g. if it turned out that there are the same number of blonde lefties as red-headed lefties.

To summarize:



Click HERE to read the next Statistics post on Variance and Standard Deviation.