Quick p-values for publication

I’m afraid this is just from a lecture from the school of the totally obvious, but for some unfathomable reason I’ve never got round to doing it. I’m not even telling you the code so much as just saying “you should definitely do this, it’s very easy”. I got the time back after writing one paper and I constantly have to fiddle around with p-values so I imagine I shall save many hours each year.

So if you’re writing for publication you often want to turn p-values such as 3.7-e18 into something more like “p<.0001". Sometimes you have whole tables of them. Don't do it by hand as I have been doing. Do this: [code language="R"] pValueFunction = function(pValue) { if(pValue < .0001) return ("p<.0001") if(pValue < .001) return ("p<.001") if(pValue < .01) return ("p<.01") if(pValue < .05) return ("p<.05") if(pValue < .1) return ("p<.1") if(pValue >= .1) return ("p>.1") } [/code] This is most useful, of course, if you're using Sweave, or knitr or something like that. If you’re not doing that you should start, but that’s a different post.

Or you may just be outputting tables with p-values in as plain text as I wrote about in this post.

Boom! You’ll save enough hours in your life to read the wonderful Don Quixote.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.