Dealing with x-bar (x̄) and p-hat (p̂) in Statistics

Revised Oct 23, 2012

A common question I get (at least common in Unicode terms) is what the code is for the p-hat (p̂) symbol and x-bar (x̄) symbols in statistics. Although these are common symbols, they haven't made it as a single character into Unicode (much like there thermodynamic dot symbols are half missing unless they are also in Old Irish or another foreign language's spelling system.

The good news is that they can be created in Unicode, but it's quirky. The trick here is to forget math and think phonetics. There is a mechanism to place any diacritic/accent mark over any letter using one of the combining diacritics These are accents, but with a spacing specification that basically says to go backwards over the previous letter.

HTML

For HTML, I recommend inputting the base letter (x or p) then the appropriate numeric escape code for the combining diacritic. See code examples below:

View the HTML Code

x-bar = x&#772; or x&#x0304; (hex)

p-hat = x&#770; or x&#x0302; (hex)

View Results

x-bar = x̄ or x̄ (hex)

p-hat = p̂ or p̂ (hex)

Font Notes

If the result of your code is something like p^or ^p rather than p̂, the problem is usually the font. Relatively few fonts support combining diacritics well (not even math fonts support diacritics well). Those that do are phonetics oriented and these include include:

The first two fonts come from Microsoft/Apple, are commonly installed, and also include math symbols...but they are sans-serif fonts. If you want a serif font, you may want to specify one of the other serif phonetics fonts, then point users to it (but specify Arial Unicode/Lucida Grande as backups). Not a very pretty solution at the moment.

Word, etc

And now the fun really begins. You can input these characters in other programs (see below), but editing them will be odd (see below). Here's the procedure:

Switch to a font which supports combining diacritics and type the base letter (x or p in this case).

Type a space and move your cursor back (you'll thank me for this tip):

When you edit, you will discover that sometimes you will delete the accent, and sometimes you will delete the letter beneath the accent (very entertaining). You may need to undo your delete move your cursor with your arrow keys when that happens. It doesn't always look like the cursor is moving, but it is in Unicode text land. When you are trying to type a nasalized open-o /ɔ̃/, you do get some practice....