Wednesday, November 11, 2009

test ignore

test

Ten Statisticians and their Impacts for Psychologists

Dan Wright has written an article about Ten statisticians and their impacts for psychologists, which is well worth reading. As psychologists, we learn about, and use statistics, but we don't learn enough (in my opinion) about the historical and philosophical underpinnings - which are linked to the individuals - how many psychologists know that Fisher and Pearson did not get on, for example.

As well as describing these statisticians early work, he gives some snippets of details about their lives - I didn't know, for example, that Jerzy Neyman had ever been imprisoned by the Bolsheviks after the Russian revolution (it's Neyman that we can thank for people using 0.05 as a stringent cutoff).

Two snippets he didn't mention - perhaps for lack of space. He mentions that there are only four females in a list of 100 prominent statisticians - but one of these (F N David) is named after one of the others (Florence Nightingale). In addition, he mentions Ronald Fisher (obviously), George Box, and Fisher's daughter, Joan Fisher Box (who wrote Fisher's biography), but does not mention that Joan Fisher Box acquired her name (you know where this is going, don't you) by marrying George Box.

I've also heard it said that George Box and David Cox knew each other for a long time, and thought it would be cool to publish a paper together - but they worked in very different areas. Eventually they did publish one on a method for transformations, now known as Box-Cox transformations, and sometimes just called Box-Coxing, as in "Have you tried Box-Coxing that dataset?" If anyone had any confirmation that it was true, I'd be interested.

Friday, November 6, 2009

No, REALLY don't do statistics with Excel

There was a query on the SAS mailing list today - someone got inconsistent results for confidence intervals between Excel and SAS. In Excel, they were using the confidence() function, which I'd not come across before. And I'm glad about that.

See, to calculate a confidence interval, you multiply the standard error of the distribution for the critical value from the t-distribution.

You can find that value using (say) R, with the qt() function or Excel, with the tinv() function. The t-distribution approximates the normal distribution as the sample size increases - you need a sample size of infinity for them to be exactly the same, but if the same size is large enough, then it's close. With the normal distribution, if you want a 95% confidence interval, the critical value is 1.96, which is so close to 2 that you can pretty much us 2 and get away with it. (Around 95% of cases lie within 2 SDs of the mean in a normal distribution).

If you have a sample of 500, then the critical value for t is 1.96 - the same as for the normal distribution. But even if your sample is as low as 50, the critical value is 2.0, which is close enough for almost anything (if you're using a computer it will work it out, and use it, to 16 decimal places, and we don't need to worry anyway).

However, this person had a sample size of 6. With a sample size of 6, the critical value is 2.6, that's a pretty long way off. Well, it turns out that Excel doesn't use the t distribution, it uses the normal distribution. If you have a large sample, this is going to cause you no problems, but if you've got a small sample, you are going to be off - off by almost 30%, which is quite a long way for a confidence interval to be off.

I googled (not Binged, of course) around this a bit, because I don't believe I'm the only person to have noticed, and I found this web page. Which is called "Function Consistency Improvements in Excel 2010", and renames the confidence() function to confidence.t(), and says: "Consistent definition with industry best practices. Confidence function assuming a Student’s t distribution."

Oh, that's great. It wasn't wrong or a cock up or a mistake. It was just inconsistent with best industry practices. Well, I'll try that at home next time I tread dog turd into the living room / spill tomato soup on the sofa / allow the children to play with the rat poison. That wasn't wrong, or a mistake, I will claim, as I am reprimanded. In the future I will eat tomato soup at the table, in order to ensure that my eating behavior is consistent with best dining practice .

Wednesday, February 18, 2009

SAS Macro for Standard Error of Skewness and Standard Error of Kurtosis

For reasons that are too dull to go into, I wanted to calculate the standard error of skew and standard error of kurtosis in SAS. I did a bit of trawling on the interwebz, and failed to find anything. So I wrote my own, and put it here, in case anyone needs the same thing.

In the last line, change dataset and variable to match your dataset and variable.

%macro seskewkurt(data, variable);

proc means data = &data n skew kurtosis;
var &variable;
output out=outmeans n=n skew=skew kurtosis=kurtosis;
proc print data = outmeans;
data _null_; set outmeans;
call symput('getn', n);
call symput('getkurtosis', kurtosis);
call symput('getskew', skew);
run;

%let seskew=%sysevalf((((6*&getn)*(&getn-1))/((&getn-2)*(&getn+1)*(&getn+3)))**0.5);
%let sekurt=%sysevalf(2*&seskew*((&getn**2*(2-1))/((&getn-3)*(&getn+5)))**0.5) ;
%let zkurt = %sysevalf(&getkurtosis/&sekurt);
%let zskew = %sysevalf(&getskew/&seskew);
%put N is &getn ;
%put Skew is &getskew;
%put SE of skew is &seskew ;
%put Z score of skew is &zskew ;
%put Kurtosis is &getkurtosis ;
%put SE of kurtosis is &sekurt ;
%put Z score of Kurtosis is &zkurt ;

%mend;


%seskewkurt(dataset, variable);

Monday, December 22, 2008

Prediction vs Explanation in Regression

One issue in using regression analysis is to determine whether you are developing a model to predict an outcome, or to explain an outcome. It's often a little bit hazy which one you are actually doing - in science, we like to say that we are explaining, but it's difficult (not impossible) to argue that we're doing much more than predicting.

However, one place where prediction is all that matters is in finance. Credit card companies like to lend people money, but they only like to lend people money who are going to give it back. And they don't care why people don't give them their money back, they just want to predict who will give them their money back.

But this policy often leads to confusion, as in Amex lowers your credit limit if you shop where deadbeats shop. At the moment, credit card companies are feeling kind of nervous - they think that a lot of people might not be giving them their money back, and so they are running regression models to predict who those people might be. They find that people who shop in some stores are less likely to pay them back, and so if you look like one of those people, they might lower your credit limit - this is pure prediction.

In science, it's common to mistake prediction for explanation - I've found a correlation, and so you think I've found the reason something happens. But in this credit card example, it's the other way around - all they have is a prediction. It doesn't mean anything, but people interpret it as some sort of slight against them.

Sunday, August 3, 2008

Running out of adjectives

One of the problems that we have when trying to measure things like trauma or depression is that we run out of adjectives very fast.

For example, we might ask:
How upset were you that your computer crashed?
- Very upset.
How upset were you that your dog died?
- Very, very upset.
How upset were you that your spouse and children were killed in the volcano?
- Very, very, very upset.
How upset are you that a large asteroid is going to wipe out all of life on earth next week?

Banyard and Shevlin wrote a short paper a few years ago which reported high levels of psychological distress in supporters of football (soccer) teams that were demoted. I've always suspected that this effect is simply one of people using extremes - they were very, very upset that that goal was disallowed.

My favorite blog written by an anonymous ER doctor is WhiteCoatRants, and in this post he describes a similar problem when trying to get a patient to describe how much pain they are in:

The one [description] I use is that 10 out of 10 pain is pain that is bad enough that you are “on the ground wailing and pounding your fists on the floor because the pain is so bad.” This gives me an objective way to follow up the subjective ratings of “10.”

“So using my description, how bad is your pain from 1-10?”
The patient, sitting on the bed munching Doritos and watching TV, says “Oh, it’s definitely a 10.”
I reply, “That’s funny, because you’re still sitting on the bed, you’re not pounding your fists on the floor, and you’re not wailing. In fact, you appear to be rather comfortable.”
The usual response?

“Oh, then it’s a nine and a half.”

Some interesting discussion about this problem followed.

Google for Statistics

I like to use Google to conduct little surveys on how things are done, or what people think. For example, I was thinking about what the relative popularity of SPSS and SAS were for teaching statistics to psychologists, in UK and US universities. So I searched for
[SAS psychology anova site:edu] and got (about) 10,000 hits.
[SPSS psychology anova site:edu] 6,000 hits.
(I added anova to make sure it didn't pick up other meanings for SAS). Conclusion: SPSS is a little more popular than SAS, in US university psychology departments. (I also ran it with 'regression' instead of 'anova', with a similar result, but SPSS's lead was a lot smaller).

Do it again for the UK and we find:
[SAS psychology anova site:ac.uk] 607 hits.
[SPSS psychology anova site:ac.uk] 1,930 hits.

So SPSS has the lead in both, but it's got a bigger lead in the UK than the US. (For regression, it's also got about three times more).

However, here's a comic from xkcd which uses the same approach in a much more interesting way: