Why do dogs like being patted?

Why do dogs like being patted?

Not all dogs like this, but some do. It made me wonder today about it, I mean, they wouldn't do it in the wild.. how would they be patted with no people?

After a lot of research, and digging through forums, dog websites, yahoo questions, etc. I have come to the conclusion it is for attention. Based on this, the dog is more likely to enjoy being patted from its "Master" than from others.
I tried this with the dog in the house, and my girlfriends dog, seems to fit the attention thing.

Just a random thing.

And I thought I would share it.